summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--backend-shared/plannershared.cpp10
-rw-r--r--desktop-widgets/diveplanner.cpp20
-rw-r--r--desktop-widgets/mainwindow.cpp2
-rw-r--r--qt-models/cylindermodel.cpp6
-rw-r--r--qt-models/cylindermodel.h1
-rw-r--r--qt-models/diveplannermodel.cpp35
-rw-r--r--qt-models/diveplannermodel.h3
7 files changed, 39 insertions, 38 deletions
diff --git a/backend-shared/plannershared.cpp b/backend-shared/plannershared.cpp
index 606dbb9d2..bc2fa58be 100644
--- a/backend-shared/plannershared.cpp
+++ b/backend-shared/plannershared.cpp
@@ -126,7 +126,7 @@ void PlannerShared::set_o2narcotic(bool value)
{
qPrefDivePlanner::set_o2narcotic(value);
DivePlannerPointsModel::instance()->emitDataChanged();
- CylindersModelFiltered::instance()->model()->updateBestMixes();
+ DivePlannerPointsModel::instance()->cylindersModel()->model()->updateBestMixes();
}
double PlannerShared::bottompo2()
@@ -136,7 +136,7 @@ double PlannerShared::bottompo2()
void PlannerShared::set_bottompo2(double value)
{
qPrefDivePlanner::set_bottompo2((int) (value * 1000.0));
- CylindersModelFiltered::instance()->model()->updateBestMixes();
+ DivePlannerPointsModel::instance()->cylindersModel()->model()->updateBestMixes();
}
double PlannerShared::decopo2()
@@ -148,8 +148,8 @@ void PlannerShared::set_decopo2(double value)
pressure_t olddecopo2;
olddecopo2.mbar = prefs.decopo2;
qPrefDivePlanner::instance()->set_decopo2((int) (value * 1000.0));
- CylindersModelFiltered::instance()->model()->updateDecoDepths(olddecopo2);
- CylindersModelFiltered::instance()->model()->updateBestMixes();
+ DivePlannerPointsModel::instance()->cylindersModel()->model()->updateDecoDepths(olddecopo2);
+ DivePlannerPointsModel::instance()->cylindersModel()->model()->updateBestMixes();
}
int PlannerShared::bestmixend()
@@ -159,5 +159,5 @@ int PlannerShared::bestmixend()
void PlannerShared::set_bestmixend(int value)
{
qPrefDivePlanner::set_bestmixend(units_to_depth(value).mm);
- CylindersModelFiltered::instance()->model()->updateBestMixes();
+ DivePlannerPointsModel::instance()->cylindersModel()->model()->updateBestMixes();
}
diff --git a/desktop-widgets/diveplanner.cpp b/desktop-widgets/diveplanner.cpp
index d6fbbeb88..b15a05b85 100644
--- a/desktop-widgets/diveplanner.cpp
+++ b/desktop-widgets/diveplanner.cpp
@@ -110,6 +110,8 @@ void DiveHandler::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
DivePlannerWidget::DivePlannerWidget(QWidget *parent, Qt::WindowFlags f) : QWidget(parent, f)
{
DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance();
+ CylindersModelFiltered *cylinders = DivePlannerPointsModel::instance()->cylindersModel();
+
ui.setupUi(this);
ui.dateEdit->setDisplayFormat(prefs.date_format);
ui.tableWidget->setTitle(tr("Dive planner points"));
@@ -120,8 +122,8 @@ DivePlannerWidget::DivePlannerWidget(QWidget *parent, Qt::WindowFlags f) : QWidg
ui.tableWidget->view()->setItemDelegateForColumn(DivePlannerPointsModel::DIVEMODE, new DiveTypesDelegate(this));
ui.cylinderTableWidget->setTitle(tr("Available gases"));
ui.cylinderTableWidget->setBtnToolTip(tr("Add cylinder"));
- ui.cylinderTableWidget->setModel(CylindersModelFiltered::instance());
- connect(ui.cylinderTableWidget, &TableView::itemClicked, CylindersModelFiltered::instance(), &CylindersModelFiltered::remove);
+ ui.cylinderTableWidget->setModel(cylinders);
+ connect(ui.cylinderTableWidget, &TableView::itemClicked, cylinders, &CylindersModelFiltered::remove);
ui.waterType->setItemData(0, FRESHWATER_SALINITY);
ui.waterType->setItemData(1, SEAWATER_SALINITY);
ui.waterType->setItemData(2, EN13319_SALINITY);
@@ -139,13 +141,13 @@ DivePlannerWidget::DivePlannerWidget(QWidget *parent, Qt::WindowFlags f) : QWidg
// Continue to use old syntax, to avoid problems.
connect(ui.tableWidget, SIGNAL(addButtonClicked()), plannerModel, SLOT(addStop()));
- connect(CylindersModelFiltered::instance(), &CylindersModelFiltered::dataChanged, GasSelectionModel::instance(), &GasSelectionModel::repopulate);
- connect(CylindersModelFiltered::instance(), &CylindersModelFiltered::rowsInserted, GasSelectionModel::instance(), &GasSelectionModel::repopulate);
- connect(CylindersModelFiltered::instance(), &CylindersModelFiltered::rowsRemoved, GasSelectionModel::instance(), &GasSelectionModel::repopulate);
- connect(CylindersModelFiltered::instance(), &CylindersModelFiltered::dataChanged, plannerModel, &DivePlannerPointsModel::emitDataChanged);
- connect(CylindersModelFiltered::instance(), &CylindersModelFiltered::dataChanged, plannerModel, &DivePlannerPointsModel::cylinderModelEdited);
- connect(CylindersModelFiltered::instance(), &CylindersModelFiltered::rowsInserted, plannerModel, &DivePlannerPointsModel::cylinderModelEdited);
- connect(CylindersModelFiltered::instance(), &CylindersModelFiltered::rowsRemoved, plannerModel, &DivePlannerPointsModel::cylinderModelEdited);
+ connect(cylinders, &CylindersModelFiltered::dataChanged, GasSelectionModel::instance(), &GasSelectionModel::repopulate);
+ connect(cylinders, &CylindersModelFiltered::rowsInserted, GasSelectionModel::instance(), &GasSelectionModel::repopulate);
+ connect(cylinders, &CylindersModelFiltered::rowsRemoved, GasSelectionModel::instance(), &GasSelectionModel::repopulate);
+ connect(cylinders, &CylindersModelFiltered::dataChanged, plannerModel, &DivePlannerPointsModel::emitDataChanged);
+ connect(cylinders, &CylindersModelFiltered::dataChanged, plannerModel, &DivePlannerPointsModel::cylinderModelEdited);
+ connect(cylinders, &CylindersModelFiltered::rowsInserted, plannerModel, &DivePlannerPointsModel::cylinderModelEdited);
+ connect(cylinders, &CylindersModelFiltered::rowsRemoved, plannerModel, &DivePlannerPointsModel::cylinderModelEdited);
connect(plannerModel, &DivePlannerPointsModel::calculatedPlanNotes, MainWindow::instance(), &MainWindow::setPlanNotes);
diff --git a/desktop-widgets/mainwindow.cpp b/desktop-widgets/mainwindow.cpp
index 68c267e0d..37df46923 100644
--- a/desktop-widgets/mainwindow.cpp
+++ b/desktop-widgets/mainwindow.cpp
@@ -918,7 +918,7 @@ void MainWindow::on_actionReplanDive_triggered()
divePlannerWidget->setSalinity(current_dive->salinity);
DivePlannerPointsModel::instance()->loadFromDive(current_dive);
reset_cylinders(&displayed_dive, true);
- CylindersModelFiltered::instance()->updateDive();
+ DivePlannerPointsModel::instance()->cylindersModel()->updateDive();
}
void MainWindow::on_actionDivePlanner_triggered()
diff --git a/qt-models/cylindermodel.cpp b/qt-models/cylindermodel.cpp
index c5a0d2272..1dbbc0653 100644
--- a/qt-models/cylindermodel.cpp
+++ b/qt-models/cylindermodel.cpp
@@ -611,12 +611,6 @@ void CylindersModel::cylindersReset(const QVector<dive *> &dives)
updateDive();
}
-CylindersModelFiltered *CylindersModelFiltered::instance()
-{
- static CylindersModelFiltered self;
- return &self;
-}
-
CylindersModelFiltered::CylindersModelFiltered(QObject *parent) : QSortFilterProxyModel(parent)
{
setSourceModel(&source);
diff --git a/qt-models/cylindermodel.h b/qt-models/cylindermodel.h
index 66f51acca..9534af8ad 100644
--- a/qt-models/cylindermodel.h
+++ b/qt-models/cylindermodel.h
@@ -61,7 +61,6 @@ class CylindersModelFiltered : public QSortFilterProxyModel {
Q_OBJECT
public:
CylindersModelFiltered(QObject *parent = 0);
- static CylindersModelFiltered *instance();
CylindersModel *model(); // Access to unfiltered base model
void clear();
diff --git a/qt-models/diveplannermodel.cpp b/qt-models/diveplannermodel.cpp
index 3d3f1d0bc..cf7dd0361 100644
--- a/qt-models/diveplannermodel.cpp
+++ b/qt-models/diveplannermodel.cpp
@@ -21,6 +21,11 @@
#define UNIT_FACTOR ((prefs.units.length == units::METERS) ? 1000.0 / 60.0 : feet_to_mm(1.0) / 60.0)
+CylindersModelFiltered *DivePlannerPointsModel::cylindersModel()
+{
+ return &cylinders;
+}
+
/* TODO: Port this to CleanerTableModel to remove a bit of boilerplate and
* use the signal warningMessage() to communicate errors to the MainWindow.
*/
@@ -37,7 +42,7 @@ void DivePlannerPointsModel::removeSelectedPoints(const QVector<int> &rows)
divepoints.remove(v2[i]);
}
endRemoveRows();
- CylindersModelFiltered::instance()->model()->updateTrashIcon();
+ cylinders.model()->updateTrashIcon();
}
void DivePlannerPointsModel::createSimpleDive()
@@ -89,7 +94,7 @@ void DivePlannerPointsModel::loadFromDive(dive *d)
const struct event *evd = NULL;
enum divemode_t current_divemode = UNDEF_COMP_TYPE;
recalc = false;
- CylindersModelFiltered::instance()->updateDive();
+ cylinders.updateDive();
duration_t lasttime = { 0 };
duration_t lastrecordedtime = {};
duration_t newtime = {};
@@ -162,7 +167,7 @@ void DivePlannerPointsModel::setupCylinders()
reset_cylinders(&displayed_dive, true);
if (displayed_dive.cylinders.nr > 0) {
- CylindersModelFiltered::instance()->updateDive();
+ cylinders.updateDive();
return; // We have at least one cylinder
}
}
@@ -180,7 +185,7 @@ void DivePlannerPointsModel::setupCylinders()
add_to_cylinder_table(&displayed_dive.cylinders, 0, cyl);
}
reset_cylinders(&displayed_dive, false);
- CylindersModelFiltered::instance()->updateDive();
+ cylinders.updateDive();
}
// Update the dive's maximum depth. Returns true if max. depth changed
@@ -209,11 +214,9 @@ void DivePlannerPointsModel::removeDeco()
void DivePlannerPointsModel::addCylinder_clicked()
{
- CylindersModelFiltered::instance()->add();
+ cylinders.add();
}
-
-
void DivePlannerPointsModel::setPlanMode(Mode m)
{
mode = m;
@@ -317,7 +320,7 @@ bool DivePlannerPointsModel::setData(const QModelIndex &index, const QVariant &v
if (value.toInt() >= 0) {
p.depth = units_to_depth(value.toInt());
if (updateMaxDepth())
- CylindersModelFiltered::instance()->model()->updateBestMixes();
+ cylinders.model()->updateBestMixes();
}
break;
case RUNTIME:
@@ -343,8 +346,8 @@ bool DivePlannerPointsModel::setData(const QModelIndex &index, const QVariant &v
p.cylinderid = value.toInt();
/* Did we change the start (dp 0) cylinder to another cylinderid than 0? */
if (value.toInt() != 0 && index.row() == 0)
- CylindersModelFiltered::instance()->model()->moveAtFirst(value.toInt());
- CylindersModelFiltered::instance()->model()->updateTrashIcon();
+ cylinders.model()->moveAtFirst(value.toInt());
+ cylinders.model()->updateTrashIcon();
break;
case DIVEMODE:
if (value.toInt() < FREEDIVE) {
@@ -799,9 +802,9 @@ void DivePlannerPointsModel::editStop(int row, divedatapoint newData)
divepoints[row] = newData;
std::sort(divepoints.begin(), divepoints.end(), divePointsLessThan);
if (updateMaxDepth())
- CylindersModelFiltered::instance()->model()->updateBestMixes();
+ cylinders.model()->updateBestMixes();
if (divepoints[0].cylinderid != old_first_cylid)
- CylindersModelFiltered::instance()->model()->moveAtFirst(divepoints[0].cylinderid);
+ cylinders.model()->moveAtFirst(divepoints[0].cylinderid);
emitDataChanged();
}
@@ -850,9 +853,9 @@ void DivePlannerPointsModel::remove(const QModelIndex &index)
divepoints.remove(index.row());
}
endRemoveRows();
- CylindersModelFiltered::instance()->model()->updateTrashIcon();
+ cylinders.model()->updateTrashIcon();
if (divepoints[0].cylinderid != old_first_cylid)
- CylindersModelFiltered::instance()->model()->moveAtFirst(divepoints[0].cylinderid);
+ cylinders.model()->moveAtFirst(divepoints[0].cylinderid);
}
struct diveplan &DivePlannerPointsModel::getDiveplan()
@@ -907,13 +910,13 @@ void DivePlannerPointsModel::clear()
{
bool oldRecalc = setRecalc(false);
- CylindersModelFiltered::instance()->updateDive();
+ cylinders.updateDive();
if (rowCount() > 0) {
beginRemoveRows(QModelIndex(), 0, rowCount() - 1);
divepoints.clear();
endRemoveRows();
}
- CylindersModelFiltered::instance()->clear();
+ cylinders.clear();
setRecalc(oldRecalc);
}
diff --git a/qt-models/diveplannermodel.h b/qt-models/diveplannermodel.h
index 23d9ada02..4dda5cc6e 100644
--- a/qt-models/diveplannermodel.h
+++ b/qt-models/diveplannermodel.h
@@ -7,6 +7,7 @@
#include "core/deco.h"
#include "core/planner.h"
+#include "qt-models/cylindermodel.h"
class DivePlannerPointsModel : public QAbstractTableModel {
Q_OBJECT
@@ -47,6 +48,7 @@ public:
bool tankInUse(int cylinderid);
void setupCylinders();
bool updateMaxDepth();
+ CylindersModelFiltered *cylindersModel();
int ascrate75Display();
int ascrate50Display();
@@ -127,6 +129,7 @@ private:
void computeVariations(struct diveplan *diveplan, const struct deco_state *ds);
void computeVariationsFreeDeco(struct diveplan *diveplan, struct deco_state *ds);
int analyzeVariations(struct decostop *min, struct decostop *mid, struct decostop *max, const char *unit);
+ CylindersModelFiltered cylinders;
Mode mode;
bool recalc;
QVector<divedatapoint> divepoints;