diff options
author | Tomaz Canabrava <tcanabrava@kde.org> | 2013-05-23 15:33:20 -0300 |
---|---|---|
committer | Tomaz Canabrava <tcanabrava@kde.org> | 2013-05-23 15:33:20 -0300 |
commit | babbfa9204b45d459227bdde0ff63469244b1c39 (patch) | |
tree | 888bcba51a30c37b608d9c55823fec0571876c82 /qt-ui/models.cpp | |
parent | c917a99eb2973701a79ba8bdb6002bb6ec0ad880 (diff) | |
download | subsurface-babbfa9204b45d459227bdde0ff63469244b1c39.tar.gz |
Added support for Completing on the Cylinder Type delegate
I had to immprove the TankInfoModel with two new methods,
insertRows and setData, because the delegate used this
model to show what kind of Tanks we are offering.
Since the user can enter a new type of Tank, it's important
to add this tank to all lists using the delegates.
I Also added two new methods on the delegate itself,
to correctly shows the data, and set the data on the
model. This also will help dirk with a working example
on how to edit things while using a delegate.
Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Diffstat (limited to 'qt-ui/models.cpp')
-rw-r--r-- | qt-ui/models.cpp | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp index 7ccbe1e49..029a788bf 100644 --- a/qt-ui/models.cpp +++ b/qt-ui/models.cpp @@ -398,10 +398,25 @@ void WeightModel::setDive(dive* d) endInsertRows(); } -void TankInfoModel::add(const QString& description) +TankInfoModel* TankInfoModel::instance() { - // When the user `creates` a new one on the combobox. - // for now, empty till dirk cleans the GTK code. + static TankInfoModel *self = new TankInfoModel(); + return self; +} + +bool TankInfoModel::insertRows(int row, int count, const QModelIndex& parent) +{ + beginInsertRows(parent, rowCount(), rowCount()); + rows += count; + endInsertRows(); + return true; +} + +bool TankInfoModel::setData(const QModelIndex& index, const QVariant& value, int role) +{ + struct tank_info *info = &tank_info[index.row()]; + QByteArray name = value.toByteArray(); + info->name = strdup(name.data()); } void TankInfoModel::clear() @@ -430,7 +445,7 @@ QVariant TankInfoModel::data(const QModelIndex& index, int role) const p.mbar = psi_to_mbar(info->psi); ml = wet_volume(info->cuft, p); } - if (role == Qt::DisplayRole) { + if (role == Qt::DisplayRole || role == Qt::EditRole) { switch(index.column()) { case BAR: ret = bar; @@ -478,7 +493,6 @@ TankInfoModel::TankInfoModel() : QAbstractTableModel(), rows(-1) { struct tank_info *info = tank_info; for (info = tank_info; info->name; info++, rows++); - if (rows > -1) { beginInsertRows(QModelIndex(), 0, rows); endInsertRows(); |