summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2014-07-02 22:38:08 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-07-03 09:37:55 -0700
commit6b1b2bc919e311cc7e83f336017f35216c8da538 (patch)
treee7be0074447f2fc0f17d692c61918d99392df909
parenta86aca037843167b26726926dbf2aebe0513afba (diff)
downloadsubsurface-6b1b2bc919e311cc7e83f336017f35216c8da538.tar.gz
UI restructure: get rid of "current" pointer in cylinders and weights
Instead always display the display_dive. Now the only thing left to slay is the stagingDive... Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--qt-ui/diveplanner.cpp32
-rw-r--r--qt-ui/maintab.cpp8
-rw-r--r--qt-ui/models.cpp60
-rw-r--r--qt-ui/models.h8
4 files changed, 59 insertions, 49 deletions
diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp
index 7d8416e88..845961daa 100644
--- a/qt-ui/diveplanner.cpp
+++ b/qt-ui/diveplanner.cpp
@@ -111,7 +111,16 @@ void DivePlannerPointsModel::loadFromDive(dive *d)
copy_samples(&d->dc, &backupDive.dc);
copy_events(&d->dc, &backupDive.dc);
copy_cylinders(d, stagingDive, false); // this way the correct cylinder data is shown
- CylindersModel::instance()->setDive(stagingDive);
+
+
+
+// FIXME -- need to get rid of stagingDIve
+// the following now uses displayed_dive !!!!
+
+
+
+
+ CylindersModel::instance()->updateDive();
int lasttime = 0;
// we start with the first gas and see if it was changed
struct gasmix gas = backupDive.cylinder[0].gasmix;
@@ -768,7 +777,15 @@ bool DivePlannerPointsModel::addGas(struct gasmix mix)
modpO2.mbar = prefs.decopo2;
cyl->depth = gas_mod(&mix, modpO2, M_OR_FT(3,10));
- CylindersModel::instance()->setDive(stagingDive);
+
+
+
+ // FIXME -- need to get rid of stagingDIve
+ // the following now uses displayed_dive !!!!
+
+
+
+ CylindersModel::instance()->updateDive();
return true;
}
if (!gasmix_distance(&cyl->gasmix, &mix))
@@ -995,7 +1012,16 @@ void DivePlannerPointsModel::clear()
stagingDive = alloc_dive();
}
bool oldRecalc = setRecalc(false);
- CylindersModel::instance()->setDive(stagingDive);
+
+
+
+ // FIXME -- need to get rid of stagingDIve
+ // the following now uses displayed_dive !!!!
+
+
+
+
+ CylindersModel::instance()->updateDive();
if (rowCount() > 0) {
beginRemoveRows(QModelIndex(), 0, rowCount() - 1);
divepoints.clear();
diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp
index edbd7d06d..f53a70e6e 100644
--- a/qt-ui/maintab.cpp
+++ b/qt-ui/maintab.cpp
@@ -432,8 +432,8 @@ void MainTab::updateDiveInfo(bool clear)
ui.LocationLabel->setText(tr("Location"));
ui.NotesLabel->setText(tr("Notes"));
ui.equipmentTab->setEnabled(true);
- cylindersModel->setDive(&displayed_dive);
- weightModel->setDive(&displayed_dive);
+ cylindersModel->updateDive();
+ weightModel->updateDive();
taglist_get_tagstring(displayed_dive.tag_list, buf, 1024);
ui.tagWidget->setText(QString(buf));
}
@@ -828,8 +828,8 @@ void MainTab::rejectChanges()
}
if (selected_dive >= 0) {
copy_dive(current_dive, &displayed_dive);
- cylindersModel->setDive(&displayed_dive);
- weightModel->setDive(&displayed_dive);
+ cylindersModel->updateDive();
+ weightModel->updateDive();
} else {
cylindersModel->clear();
weightModel->clear();
diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp
index 1b7f028e7..7d46d0ae4 100644
--- a/qt-ui/models.cpp
+++ b/qt-ui/models.cpp
@@ -63,7 +63,7 @@ void CleanerTableModel::setHeaderDataStrings(const QStringList &newHeaders)
headers = newHeaders;
}
-CylindersModel::CylindersModel(QObject *parent) : current(0), rows(0)
+CylindersModel::CylindersModel(QObject *parent) : rows(0)
{
// enum {REMOVE, TYPE, SIZE, WORKINGPRESS, START, END, O2, HE, DEPTH};
setHeaderDataStrings(QStringList() << "" << tr("Type") << tr("Size") << tr("WorkPress") << tr("StartPress") << tr("EndPress") << trUtf8("O" UTF8_SUBSCRIPT_2 "%") << tr("He%")
@@ -93,7 +93,7 @@ QVariant CylindersModel::data(const QModelIndex &index, int role) const
if (!index.isValid() || index.row() >= MAX_CYLINDERS)
return ret;
- cylinder_t *cyl = &current->cylinder[index.row()];
+ cylinder_t *cyl = &displayed_dive.cylinder[index.row()];
switch (role) {
case Qt::FontRole: {
QFont font = defaultModelFont();
@@ -164,7 +164,7 @@ QVariant CylindersModel::data(const QModelIndex &index, int role) const
cylinder_t *CylindersModel::cylinderAt(const QModelIndex &index)
{
- return &current->cylinder[index.row()];
+ return &displayed_dive.cylinder[index.row()];
}
// this is our magic 'pass data in' function that allows the delegate to get
@@ -285,19 +285,14 @@ void CylindersModel::add()
}
int row = rows;
- fill_default_cylinder(&current->cylinder[row]);
- current->cylinder[row].manually_added = true;
+ fill_default_cylinder(&displayed_dive.cylinder[row]);
+ displayed_dive.cylinder[row].manually_added = true;
beginInsertRows(QModelIndex(), row, row);
rows++;
changed = true;
endInsertRows();
}
-void CylindersModel::update()
-{
- setDive(current);
-}
-
void CylindersModel::clear()
{
if (rows > 0) {
@@ -306,19 +301,19 @@ void CylindersModel::clear()
}
}
-void CylindersModel::setDive(dive *d)
+void CylindersModel::updateDive()
{
- if (current)
- clear();
- if (!d)
+ clear();
+ if (dive_table.nr == 0)
return;
rows = 0;
for (int i = 0; i < MAX_CYLINDERS; i++) {
- if (!cylinder_none(&d->cylinder[i]) &&
- (prefs.display_unused_tanks || cylinder_is_used(d, &d->cylinder[i]) || d->cylinder[i].manually_added))
+ if (!cylinder_none(&displayed_dive.cylinder[i]) &&
+ (prefs.display_unused_tanks ||
+ cylinder_is_used(&displayed_dive, &displayed_dive.cylinder[i]) ||
+ displayed_dive.cylinder[i].manually_added))
rows = i + 1;
}
- current = d;
changed = false;
if (rows > 0) {
beginInsertRows(QModelIndex(), 0, rows - 1);
@@ -354,11 +349,11 @@ void CylindersModel::remove(const QModelIndex &index)
if (index.column() != REMOVE) {
return;
}
- cylinder_t *cyl = &current->cylinder[index.row()];
+ cylinder_t *cyl = &displayed_dive.cylinder[index.row()];
if ((DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING &&
DivePlannerPointsModel::instance()->tankInUse(cyl->gasmix)) ||
(DivePlannerPointsModel::instance()->currentMode() == DivePlannerPointsModel::NOTHING &&
- (cyl->manually_added || (current_dive && cylinder_is_used(current_dive, cyl))))) {
+ (cyl->manually_added || cylinder_is_used(&displayed_dive, cyl)))) {
QMessageBox::warning(MainWindow::instance(), TITLE_OR_TEXT(
tr("Cylinder cannot be removed"),
tr("This gas in use. Only cylinders that are not used in the dive can be removed.")),
@@ -367,12 +362,12 @@ void CylindersModel::remove(const QModelIndex &index)
}
beginRemoveRows(QModelIndex(), index.row(), index.row()); // yah, know, ugly.
rows--;
- remove_cylinder(current, index.row());
+ remove_cylinder(&displayed_dive, index.row());
changed = true;
endRemoveRows();
}
-WeightModel::WeightModel(QObject *parent) : CleanerTableModel(parent), current(0), rows(0)
+WeightModel::WeightModel(QObject *parent) : CleanerTableModel(parent), rows(0)
{
//enum Column {REMOVE, TYPE, WEIGHT};
setHeaderDataStrings(QStringList() << tr("") << tr("Type") << tr("Weight"));
@@ -380,7 +375,7 @@ WeightModel::WeightModel(QObject *parent) : CleanerTableModel(parent), current(0
weightsystem_t *WeightModel::weightSystemAt(const QModelIndex &index)
{
- return &current->weightsystem[index.row()];
+ return &displayed_dive.weightsystem[index.row()];
}
void WeightModel::remove(const QModelIndex &index)
@@ -390,7 +385,7 @@ void WeightModel::remove(const QModelIndex &index)
}
beginRemoveRows(QModelIndex(), index.row(), index.row()); // yah, know, ugly.
rows--;
- remove_weightsystem(current, index.row());
+ remove_weightsystem(&displayed_dive, index.row());
changed = true;
endRemoveRows();
}
@@ -409,7 +404,7 @@ QVariant WeightModel::data(const QModelIndex &index, int role) const
if (!index.isValid() || index.row() >= MAX_WEIGHTSYSTEMS)
return ret;
- weightsystem_t *ws = &current->weightsystem[index.row()];
+ weightsystem_t *ws = &displayed_dive.weightsystem[index.row()];
switch (role) {
case Qt::FontRole:
@@ -446,7 +441,7 @@ QVariant WeightModel::data(const QModelIndex &index, int role) const
// so we only implement the two columns we care about
void WeightModel::passInData(const QModelIndex &index, const QVariant &value)
{
- weightsystem_t *ws = &current->weightsystem[index.row()];
+ weightsystem_t *ws = &displayed_dive.weightsystem[index.row()];
if (index.column() == WEIGHT) {
if (ws->weight.grams != value.toInt()) {
ws->weight.grams = value.toInt();
@@ -574,7 +569,7 @@ fraction_t string_to_fraction(const char *str)
bool WeightModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
QString vString = value.toString();
- weightsystem_t *ws = &current->weightsystem[index.row()];
+ weightsystem_t *ws = &displayed_dive.weightsystem[index.row()];
switch (index.column()) {
case TYPE:
if (!value.isNull()) {
@@ -634,22 +629,15 @@ void WeightModel::add()
endInsertRows();
}
-void WeightModel::update()
-{
- setDive(current);
-}
-
-void WeightModel::setDive(dive *d)
+void WeightModel::updateDive()
{
- if (current)
- clear();
+ clear();
rows = 0;
for (int i = 0; i < MAX_WEIGHTSYSTEMS; i++) {
- if (!weightsystem_none(&d->weightsystem[i])) {
+ if (!weightsystem_none(&displayed_dive.weightsystem[i])) {
rows = i + 1;
}
}
- current = d;
changed = false;
if (rows > 0) {
beginInsertRows(QModelIndex(), 0, rows - 1);
diff --git a/qt-ui/models.h b/qt-ui/models.h
index 17be8cbc9..bb73c4f61 100644
--- a/qt-ui/models.h
+++ b/qt-ui/models.h
@@ -116,8 +116,7 @@ public:
void passInData(const QModelIndex &index, const QVariant &value);
void add();
void clear();
- void update();
- void setDive(struct dive *d);
+ void updateDive();
void copyFromDive(struct dive *d);
cylinder_t *cylinderAt(const QModelIndex &index);
bool changed;
@@ -127,7 +126,6 @@ slots:
void remove(const QModelIndex &index);
private:
- struct dive *current;
int rows;
};
@@ -151,8 +149,7 @@ public:
void passInData(const QModelIndex &index, const QVariant &value);
void add();
void clear();
- void update();
- void setDive(struct dive *d);
+ void updateDive();
weightsystem_t *weightSystemAt(const QModelIndex &index);
bool changed;
@@ -161,7 +158,6 @@ slots:
void remove(const QModelIndex &index);
private:
- struct dive *current;
int rows;
};