diff options
-rw-r--r-- | qt-ui/diveplanner.cpp | 18 | ||||
-rw-r--r-- | qt-ui/diveplanner.h | 3 | ||||
-rw-r--r-- | qt-ui/modeldelegates.cpp | 2 | ||||
-rw-r--r-- | qt-ui/models.cpp | 16 | ||||
-rw-r--r-- | qt-ui/models.h | 10 |
5 files changed, 36 insertions, 13 deletions
diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index b0f3e901e..9bbce05f4 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -32,13 +32,6 @@ #define M_OR_FT(_m,_f) ((prefs.units.length == units::METERS) ? ((_m) * 1000) : ((_f) * 304.8)) -QStringListModel *gasSelectionModel() { - static QStringListModel *self = new QStringListModel(QStringList() - << QObject::tr("AIR")); - self->setStringList(DivePlannerPointsModel::instance()->getGasList()); - return self; -} - QString gasToStr(const int o2Permille, const int hePermille) { uint o2 = (o2Permille + 5) / 10, he = (hePermille + 5) / 10; QString result = is_air(o2Permille, hePermille) ? QObject::tr("AIR") @@ -175,7 +168,7 @@ DivePlannerGraphics::DivePlannerGraphics(QWidget* parent): QGraphicsView(parent) // Prepare the stuff for the gas-choices. gasListView = new QListView(); gasListView->setWindowFlags(Qt::Popup); - gasListView->setModel(gasSelectionModel()); + gasListView->setModel(GasSelectionModel::instance()); gasListView->hide(); gasListView->installEventFilter(this); @@ -490,7 +483,6 @@ void DivePlannerGraphics::prepareSelectGas() currentGasChoice = static_cast<Button*>(sender()); QPoint c = QCursor::pos(); gasListView->setGeometry(c.x(), c.y(), 150, 100); - model->setStringList(DivePlannerPointsModel::instance()->getGasList()); gasListView->show(); } @@ -931,6 +923,14 @@ DivePlannerWidget::DivePlannerWidget(QWidget* parent, Qt::WindowFlags f): QWidge view->setItemDelegateForColumn(CylindersModel::TYPE, new TankInfoDelegate()); connect(ui.cylinderTableWidget, SIGNAL(addButtonClicked()), DivePlannerPointsModel::instance(), SLOT(addCylinder_clicked())); connect(ui.tableWidget, SIGNAL(addButtonClicked()), DivePlannerPointsModel::instance(), SLOT(addStop())); + + connect(CylindersModel::instance(), SIGNAL(dataChanged(QModelIndex,QModelIndex)), + GasSelectionModel::instance(), SLOT(repopulate())); + connect(CylindersModel::instance(), SIGNAL(rowsInserted(QModelIndex,int,int)), + GasSelectionModel::instance(), SLOT(repopulate())); + connect(CylindersModel::instance(), SIGNAL(rowsRemoved(QModelIndex,int,int)), + GasSelectionModel::instance(), SLOT(repopulate())); + ui.tableWidget->setBtnToolTip(tr("add dive data point")); connect(ui.startTime, SIGNAL(timeChanged(QTime)), plannerModel, SLOT(setStartTime(QTime))); connect(ui.ATMPressure, SIGNAL(textChanged(QString)), this, SLOT(atmPressureChanged(QString))); diff --git a/qt-ui/diveplanner.h b/qt-ui/diveplanner.h index 139c3abb8..232b8f0fe 100644 --- a/qt-ui/diveplanner.h +++ b/qt-ui/diveplanner.h @@ -13,9 +13,6 @@ class QListView; class QStringListModel; class QModelIndex; -// Return a Model containing the air types. -QStringListModel *gasSelectionModel(); - class DivePlannerPointsModel : public QAbstractTableModel{ Q_OBJECT public: diff --git a/qt-ui/modeldelegates.cpp b/qt-ui/modeldelegates.cpp index e7399117c..cb1af8706 100644 --- a/qt-ui/modeldelegates.cpp +++ b/qt-ui/modeldelegates.cpp @@ -307,7 +307,7 @@ void AirTypesDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, model->setData(index, QVariant(combo->currentText())); } -AirTypesDelegate::AirTypesDelegate(QObject* parent) : ComboBoxDelegate(gasSelectionModel(), parent) +AirTypesDelegate::AirTypesDelegate(QObject* parent) : ComboBoxDelegate(GasSelectionModel::instance(), parent) { } diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp index dcc16d8d6..bb623243e 100644 --- a/qt-ui/models.cpp +++ b/qt-ui/models.cpp @@ -1667,3 +1667,19 @@ QVariant ProfilePrintModel::data(const QModelIndex &index, int role) const } // switch (role) return QVariant(); } + +Qt::ItemFlags GasSelectionModel::flags(const QModelIndex& index) const +{ + return Qt::ItemIsEnabled | Qt::ItemIsSelectable; +} + +GasSelectionModel* GasSelectionModel::instance() +{ + static GasSelectionModel* self = new GasSelectionModel(); + return self; +} + +void GasSelectionModel::repopulate() +{ + setStringList(DivePlannerPointsModel::instance()->getGasList()); +} diff --git a/qt-ui/models.h b/qt-ui/models.h index 8302acefa..88e76a46f 100644 --- a/qt-ui/models.h +++ b/qt-ui/models.h @@ -10,6 +10,7 @@ #include <QAbstractTableModel> #include <QCoreApplication> #include <QStringList> +#include <QStringListModel> #include "../dive.h" #include "../divelist.h" @@ -298,4 +299,13 @@ public: void setDive(struct dive *divePtr); }; +class GasSelectionModel : public QStringListModel{ + Q_OBJECT +public: + static GasSelectionModel* instance(); + Qt::ItemFlags flags(const QModelIndex& index) const; +public slots: + void repopulate(); +}; + #endif |