diff options
author | Tomaz Canabrava <tcanabrava@kde.org> | 2013-05-22 12:20:00 -0300 |
---|---|---|
committer | Tomaz Canabrava <tcanabrava@kde.org> | 2013-05-22 12:20:00 -0300 |
commit | 75956f0f9149d7483ce0771df682d90e2fc9b923 (patch) | |
tree | 800d4366e6e7a21bdcb87e2cc3af8aaa7a23f407 | |
parent | 8cfb2aa237ede19d1eb23086905a010c908788f5 (diff) | |
download | subsurface-75956f0f9149d7483ce0771df682d90e2fc9b923.tar.gz |
Added basic editing functionality for Cylinders and Weigthsystems
This patch adds basic editing functionality for Cylinders and Weigthsystems,
it still doesn't use delegates to show the data to the user in a better
way, and it does not take in consideration user preferences yet, but
it's a starting point.
Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
-rw-r--r-- | qt-ui/models.cpp | 60 | ||||
-rw-r--r-- | qt-ui/models.h | 6 |
2 files changed, 62 insertions, 4 deletions
diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp index 6ac320b26..360058dfd 100644 --- a/qt-ui/models.cpp +++ b/qt-ui/models.cpp @@ -113,6 +113,47 @@ QVariant CylindersModel::data(const QModelIndex& index, int role) const return ret; } +bool CylindersModel::setData(const QModelIndex& index, const QVariant& value, int role) +{ + cylinder_t *cyl = ¤t->cylinder[index.row()]; + switch(index.column()){ + case TYPE:{ + QByteArray desc = value.toByteArray(); + cyl->type.description = strdup(desc.data()); + break; + } + case SIZE: + // we can't use get_volume_string because the idiotic imperial tank + // sizes take working pressure into account... + if (cyl->type.size.mliter) { + if (prefs.units.volume == prefs.units.CUFT) { + double liters = cuft_to_l(value.toDouble()); + cyl->type.size.mliter = liters * 1000.0; + } else { + cyl->type.size.mliter = value.toDouble() * 1000.0; + } + } + break; + case MAXPRESS: + cyl->type.workingpressure.mbar = value.toInt(); + break; + case START: + cyl->start.mbar = value.toInt(); + break; + case END: + cyl->end.mbar = value.toInt(); + break; + case O2: + cyl->gasmix.o2.permille = value.toInt() * 10 - 5; + break; + case HE: + cyl->gasmix.he.permille = value.toInt() * 10 - 5; + break; + } + + return QAbstractItemModel::setData(index, value, role); +} + int CylindersModel::rowCount(const QModelIndex& parent) const { return rows; @@ -176,7 +217,7 @@ Qt::ItemFlags CylindersModel::flags(const QModelIndex& index) const { if (index.column() == REMOVE) return Qt::ItemIsEnabled; - return QAbstractItemModel::flags(index); + return QAbstractItemModel::flags(index) | Qt::ItemIsEditable; } void CylindersModel::remove(const QModelIndex& index) @@ -239,11 +280,26 @@ QVariant WeightModel::data(const QModelIndex& index, int role) const return ret; } +bool WeightModel::setData(const QModelIndex& index, const QVariant& value, int role) +{ + weightsystem_t *ws = ¤t_dive->weightsystem[index.row()]; + switch(index.column()) { + case TYPE:{ + QByteArray desc = value.toByteArray(); + ws->description = strdup(desc.data()); + break; + } + case WEIGHT: + ws->weight.grams = value.toInt() *1000; + break; + } +} + Qt::ItemFlags WeightModel::flags(const QModelIndex& index) const { if (index.column() == REMOVE) return Qt::ItemIsEnabled; - return QAbstractItemModel::flags(index); + return QAbstractItemModel::flags(index) | Qt::ItemIsEditable; } int WeightModel::rowCount(const QModelIndex& parent) const diff --git a/qt-ui/models.h b/qt-ui/models.h index 98f955bf6..ded612bb9 100644 --- a/qt-ui/models.h +++ b/qt-ui/models.h @@ -45,7 +45,8 @@ public: /*reimp*/ int columnCount(const QModelIndex& parent = QModelIndex()) const; /*reimp*/ QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const; /*reimp*/ int rowCount(const QModelIndex& parent = QModelIndex()) const; - /*reimp*/ Qt::ItemFlags flags(const QModelIndex& index) const; + /*reimp*/ Qt::ItemFlags flags(const QModelIndex& index) const; + /*reimp*/ bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole); void add(cylinder_t *cyl); void clear(); @@ -69,7 +70,8 @@ public: /*reimp*/ int columnCount(const QModelIndex& parent = QModelIndex()) const; /*reimp*/ QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const; /*reimp*/ int rowCount(const QModelIndex& parent = QModelIndex()) const; - /*reimp*/ Qt::ItemFlags flags(const QModelIndex& index) const; + /*reimp*/ Qt::ItemFlags flags(const QModelIndex& index) const; + /*reimp*/ bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole); void add(weightsystem_t *weight); void clear(); |