Added support for visualization the Weigthssystems on the Equipment Tab.

This patch adds support showing and  for editing weigthsystems in the equipment tab,

so, now the two things that are missing are 'edit' and 'delete', wich are quite easy to do.

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
This commit is contained in:
Tomaz Canabrava 2013-05-21 09:59:41 -03:00
parent 126bc8cfa3
commit be31a53b0d
3 changed files with 35 additions and 13 deletions

View file

@ -203,6 +203,7 @@ void MainTab::updateDiveInfo(int dive)
ui->longestAllText->setText(get_time_string(stats_selection.longest_time.seconds, 0));
ui->shortestAllText->setText(get_time_string(stats_selection.shortest_time.seconds, 0));
cylindersModel->setDive(d);
weightModel->setDive(d);
} else {
/* make the fields read-only */
ui->location->setReadOnly(true);
@ -228,6 +229,7 @@ void MainTab::updateDiveInfo(int dive)
ui->gasUsedText->clear();
ui->airPressureText->clear();
cylindersModel->clear();
weightModel->clear();
}
/* statisticsTab*/
/* we can access the stats_selection struct, but how do we ensure the relevant dives are selected

View file

@ -138,8 +138,7 @@ void CylindersModel::setDive(dive* d)
int amount = 0;
for(int i = 0; i < MAX_CYLINDERS; i++){
cylinder_t& cylinder = current_dive->cylinder[i];
qDebug() << QString(cylinder.type.description);
cylinder_t& cylinder = d->cylinder[i];
if (!cylinder.type.description){
amount = i;
break;
@ -154,9 +153,8 @@ void CylindersModel::setDive(dive* d)
void WeightModel::clear()
{
if (usedRows[current_dive] > 0) {
beginRemoveRows(QModelIndex(), 0, usedRows[current_dive]-1);
usedRows[current_dive] = 0;
if (rows > 0) {
beginRemoveRows(QModelIndex(), 0, rows-1);
endRemoveRows();
}
}
@ -195,7 +193,7 @@ QVariant WeightModel::data(const QModelIndex& index, int role) const
int WeightModel::rowCount(const QModelIndex& parent) const
{
return usedRows[current_dive];
return rows;
}
QVariant WeightModel::headerData(int section, Qt::Orientation orientation, int role) const
@ -219,25 +217,45 @@ QVariant WeightModel::headerData(int section, Qt::Orientation orientation, int r
void WeightModel::add(weightsystem_t* weight)
{
if (usedRows[current_dive] >= MAX_WEIGHTSYSTEMS) {
free(weight);
if (rows >= MAX_WEIGHTSYSTEMS) {
return;
}
int row = usedRows[current_dive];
int row = rows;
weightsystem_t *ws = &current_dive->weightsystem[row];
weightsystem_t *ws = &current->weightsystem[row];
ws->description = weight->description;
ws->weight.grams = weight->weight.grams;
beginInsertRows(QModelIndex(), row, row);
usedRows[current_dive]++;
rows++;
endInsertRows();
}
void WeightModel::update()
{
setDive(current);
}
void WeightModel::setDive(dive* d)
{
if (current)
clear();
int amount = 0;
for(int i = 0; i < MAX_WEIGHTSYSTEMS; i++){
weightsystem_t& weightsystem = d->weightsystem[i];
if (!weightsystem.description){
amount = i;
break;
}
}
beginInsertRows(QModelIndex(), 0, amount-1);
rows = amount;
current = d;
endInsertRows();
}
void TankInfoModel::add(const QString& description)

View file

@ -70,9 +70,11 @@ public:
void add(weightsystem_t *weight);
void clear();
void update();
void setDive(struct dive *d);
private:
/* Remember the number of rows in a dive */
QMap<struct dive *, int> usedRows;
struct dive *current;
int rows;
};
/*! An AbstractItemModel for recording dive trip information such as a list of dives.