mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-17 21:06:17 +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))
|
#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) {
|
QString gasToStr(const int o2Permille, const int hePermille) {
|
||||||
uint o2 = (o2Permille + 5) / 10, he = (hePermille + 5) / 10;
|
uint o2 = (o2Permille + 5) / 10, he = (hePermille + 5) / 10;
|
||||||
QString result = is_air(o2Permille, hePermille) ? QObject::tr("AIR")
|
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.
|
// Prepare the stuff for the gas-choices.
|
||||||
gasListView = new QListView();
|
gasListView = new QListView();
|
||||||
gasListView->setWindowFlags(Qt::Popup);
|
gasListView->setWindowFlags(Qt::Popup);
|
||||||
gasListView->setModel(gasSelectionModel());
|
gasListView->setModel(GasSelectionModel::instance());
|
||||||
gasListView->hide();
|
gasListView->hide();
|
||||||
gasListView->installEventFilter(this);
|
gasListView->installEventFilter(this);
|
||||||
|
|
||||||
|
@ -490,7 +483,6 @@ void DivePlannerGraphics::prepareSelectGas()
|
||||||
currentGasChoice = static_cast<Button*>(sender());
|
currentGasChoice = static_cast<Button*>(sender());
|
||||||
QPoint c = QCursor::pos();
|
QPoint c = QCursor::pos();
|
||||||
gasListView->setGeometry(c.x(), c.y(), 150, 100);
|
gasListView->setGeometry(c.x(), c.y(), 150, 100);
|
||||||
model->setStringList(DivePlannerPointsModel::instance()->getGasList());
|
|
||||||
gasListView->show();
|
gasListView->show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -931,6 +923,14 @@ DivePlannerWidget::DivePlannerWidget(QWidget* parent, Qt::WindowFlags f): QWidge
|
||||||
view->setItemDelegateForColumn(CylindersModel::TYPE, new TankInfoDelegate());
|
view->setItemDelegateForColumn(CylindersModel::TYPE, new TankInfoDelegate());
|
||||||
connect(ui.cylinderTableWidget, SIGNAL(addButtonClicked()), DivePlannerPointsModel::instance(), SLOT(addCylinder_clicked()));
|
connect(ui.cylinderTableWidget, SIGNAL(addButtonClicked()), DivePlannerPointsModel::instance(), SLOT(addCylinder_clicked()));
|
||||||
connect(ui.tableWidget, SIGNAL(addButtonClicked()), DivePlannerPointsModel::instance(), SLOT(addStop()));
|
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"));
|
ui.tableWidget->setBtnToolTip(tr("add dive data point"));
|
||||||
connect(ui.startTime, SIGNAL(timeChanged(QTime)), plannerModel, SLOT(setStartTime(QTime)));
|
connect(ui.startTime, SIGNAL(timeChanged(QTime)), plannerModel, SLOT(setStartTime(QTime)));
|
||||||
connect(ui.ATMPressure, SIGNAL(textChanged(QString)), this, SLOT(atmPressureChanged(QString)));
|
connect(ui.ATMPressure, SIGNAL(textChanged(QString)), this, SLOT(atmPressureChanged(QString)));
|
||||||
|
|
|
@ -13,9 +13,6 @@ class QListView;
|
||||||
class QStringListModel;
|
class QStringListModel;
|
||||||
class QModelIndex;
|
class QModelIndex;
|
||||||
|
|
||||||
// Return a Model containing the air types.
|
|
||||||
QStringListModel *gasSelectionModel();
|
|
||||||
|
|
||||||
class DivePlannerPointsModel : public QAbstractTableModel{
|
class DivePlannerPointsModel : public QAbstractTableModel{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -307,7 +307,7 @@ void AirTypesDelegate::setModelData(QWidget* editor, QAbstractItemModel* model,
|
||||||
model->setData(index, QVariant(combo->currentText()));
|
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)
|
} // switch (role)
|
||||||
return QVariant();
|
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 <QAbstractTableModel>
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
|
#include <QStringListModel>
|
||||||
|
|
||||||
#include "../dive.h"
|
#include "../dive.h"
|
||||||
#include "../divelist.h"
|
#include "../divelist.h"
|
||||||
|
@ -298,4 +299,13 @@ public:
|
||||||
void setDive(struct dive *divePtr);
|
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
|
#endif
|
||||||
|
|
Loading…
Add table
Reference in a new issue