mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
Correctly handle changes on the CylinderModel to update the AirModel.
What happened before was that the AirTypes model was only being updated when the user requested to change the air by clicking directly on the Air, in the planner ( but not on the Air Table. ). This fixes it by calling 'repopulate' whenever the cylinder model changes ( by adding, removing and changing something.) Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
b77d990ed6
commit
96d5687ab8
5 changed files with 36 additions and 13 deletions
|
@ -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)));
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue