aboutsummaryrefslogtreecommitdiffstats
path: root/qt-ui/modeldelegates.cpp
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tcanabrava@kde.org>2013-07-18 11:53:47 -0300
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-07-18 12:01:48 -0700
commit3aa55462dc2fc44151962a292f9b7034ec3863b2 (patch)
treea23bb4c4ac539673f59dc2bd0bc11a3b9d1fcc0b /qt-ui/modeldelegates.cpp
parent7e029980b80b176282743fe3b43a3cc49bac9154 (diff)
downloadsubsurface-3aa55462dc2fc44151962a292f9b7034ec3863b2.tar.gz
Added the code to revert Weigths when user cancels edition
This is a follow up commit to the previous one that enabled cancel for cylinders, everything in the commit log for the cylinders also applyes here. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Diffstat (limited to 'qt-ui/modeldelegates.cpp')
-rw-r--r--qt-ui/modeldelegates.cpp26
1 files changed, 23 insertions, 3 deletions
diff --git a/qt-ui/modeldelegates.cpp b/qt-ui/modeldelegates.cpp
index 9ab706c59..998c246b8 100644
--- a/qt-ui/modeldelegates.cpp
+++ b/qt-ui/modeldelegates.cpp
@@ -58,6 +58,8 @@ QSize StarWidgetsDelegate::sizeHint(const QStyleOptionViewItem& option, const QM
ComboBoxDelegate::ComboBoxDelegate(QAbstractItemModel *model, QObject* parent): QStyledItemDelegate(parent), model(model)
{
+ connect(this, SIGNAL(closeEditor(QWidget*,QAbstractItemDelegate::EndEditHint)),
+ this, SLOT(revertModelData(QWidget*, QAbstractItemDelegate::EndEditHint)));
}
void ComboBoxDelegate::setEditorData(QWidget* editor, const QModelIndex& index) const
@@ -172,8 +174,6 @@ void TankInfoDelegate::setModelData(QWidget* editor, QAbstractItemModel* model,
TankInfoDelegate::TankInfoDelegate(QObject* parent): ComboBoxDelegate(TankInfoModel::instance(), parent)
{
- connect(this, SIGNAL(closeEditor(QWidget*,QAbstractItemDelegate::EndEditHint)),
- this, SLOT(revertModelData(QWidget*, QAbstractItemDelegate::EndEditHint)));
}
void TankInfoDelegate::revertModelData(QWidget* widget, QAbstractItemDelegate::EndEditHint hint)
@@ -199,6 +199,20 @@ QWidget* TankInfoDelegate::createEditor(QWidget* parent, const QStyleOptionViewI
return delegate;
}
+struct RevertWeigthData {
+ QString type;
+ int weigth;
+} currWeigth;
+
+void WSInfoDelegate::revertModelData(QWidget* widget, QAbstractItemDelegate::EndEditHint hint)
+{
+ if (hint == QAbstractItemDelegate::NoHint || hint == QAbstractItemDelegate::RevertModelCache){
+ WeightModel *mymodel = qobject_cast<WeightModel *>(currCombo.model);
+ mymodel->setData(IDX(WeightModel::TYPE), currWeigth.type, Qt::EditRole);
+ mymodel->passInData(IDX(WeightModel::WEIGHT), currWeigth.weigth);
+ }
+}
+
void WSInfoDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& thisindex) const
{
WeightModel *mymodel = qobject_cast<WeightModel *>(currCombo.model);
@@ -231,5 +245,11 @@ WSInfoDelegate::WSInfoDelegate(QObject* parent): ComboBoxDelegate(WSInfoModel::i
QWidget* WSInfoDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
- return ComboBoxDelegate::createEditor(parent, option, index);
+ /* First, call the combobox-create editor, it will setup our globals. */
+ QWidget *editor = ComboBoxDelegate::createEditor(parent, option, index);
+ WeightModel *mymodel = qobject_cast<WeightModel *>(currCombo.model);
+ weightsystem_t *ws = mymodel->weightSystemAt(index);
+ currWeigth.type = ws->description;
+ currWeigth.weigth = ws->weight.grams;
+ return editor;
}