summaryrefslogtreecommitdiffstats
path: root/qt-ui/modeldelegates.cpp
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2013-05-23 18:40:16 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-05-23 21:36:33 -0700
commit01a3bd2cc6dcc035607cce61285ed9cc8d807b9b (patch)
treeb263322c484290a41af33fa74521f03349cf9cca /qt-ui/modeldelegates.cpp
parentecbcd4db4721c9e4a6b4253a5f45f43fa9e80fc7 (diff)
downloadsubsurface-01a3bd2cc6dcc035607cce61285ed9cc8d807b9b.tar.gz
Add weightsystem delegate to enable editing of weightsystem
This is very much analogous to the way cylinders are implemented. That means that just like with cylinders, if the user enters a new type and hits 'tab' before hitting 'enter', Subsurface will crash. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/modeldelegates.cpp')
-rw-r--r--qt-ui/modeldelegates.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/qt-ui/modeldelegates.cpp b/qt-ui/modeldelegates.cpp
index 0cffe98c4..b80e30fcd 100644
--- a/qt-ui/modeldelegates.cpp
+++ b/qt-ui/modeldelegates.cpp
@@ -92,3 +92,43 @@ void TankInfoDelegate::setModelData(QWidget* editor, QAbstractItemModel* model,
TankInfoDelegate::TankInfoDelegate(QObject* parent): QStyledItemDelegate(parent)
{
}
+
+QWidget* WSInfoDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const
+{
+ QComboBox *comboDelegate = new QComboBox(parent);
+ WSInfoModel *model = WSInfoModel::instance();
+ comboDelegate->setModel(model);
+ comboDelegate->setEditable(true);
+ comboDelegate->setAutoCompletion(true);
+ comboDelegate->setAutoCompletionCaseSensitivity(Qt::CaseInsensitive);
+ comboDelegate->completer()->setCompletionMode(QCompleter::PopupCompletion);
+ return comboDelegate;
+}
+
+void WSInfoDelegate::setEditorData(QWidget* editor, const QModelIndex& index) const
+{
+ QComboBox *c = qobject_cast<QComboBox*>(editor);
+ QString data = index.model()->data(index, Qt::DisplayRole).toString();
+ int i = c->findText(data);
+ if (i != -1)
+ c->setCurrentIndex(i);
+ else
+ c->setEditText(data);
+}
+
+void WSInfoDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const
+{
+ QComboBox *c = static_cast<QComboBox*>(editor);
+ WeightModel *mymodel = qobject_cast<WeightModel *>(model);
+ WSInfoModel *ws = WSInfoModel::instance();
+ QModelIndex wsIndex = ws->match(ws->index(0,0), Qt::DisplayRole, c->currentText()).first();
+
+ int grams = ws->data(ws->index(wsIndex.row(), WSInfoModel::GR)).toInt();
+
+ mymodel->setData(index, c->currentText(), Qt::EditRole);
+ mymodel->passInData(model->index(index.row(), WeightModel::WEIGHT), grams);
+}
+
+WSInfoDelegate::WSInfoDelegate(QObject* parent): QStyledItemDelegate(parent)
+{
+}