diff options
Diffstat (limited to 'qt-ui/modeldelegates.cpp')
-rw-r--r-- | qt-ui/modeldelegates.cpp | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/qt-ui/modeldelegates.cpp b/qt-ui/modeldelegates.cpp index 998c246b8..13201e436 100644 --- a/qt-ui/modeldelegates.cpp +++ b/qt-ui/modeldelegates.cpp @@ -3,6 +3,7 @@ #include "../divelist.h" #include "starwidget.h" #include "models.h" +#include "diveplanner.h" #include <QtDebug> #include <QPainter> @@ -14,6 +15,7 @@ #include <QLineEdit> #include <QKeyEvent> #include <QAbstractItemView> +#include <QStringListModel> // Gets the index of the model in the currentRow and column. // currCombo is defined below. @@ -106,7 +108,7 @@ void ComboBoxDelegate::testActivation(const QString& s) bool ComboBoxDelegate::eventFilter(QObject* object, QEvent* event) { // Reacts on Key_UP and Key_DOWN to show the QComboBox - list of choices. - if (event->type() == QEvent::KeyPress){ + if (event->type() == QEvent::KeyPress || event->type() == QEvent::ShortcutOverride){ if (object == currCombo.comboEditor){ // the 'LineEdit' part QKeyEvent *ev = static_cast<QKeyEvent*>(event); if(ev->key() == Qt::Key_Up || ev->key() == Qt::Key_Down){ @@ -199,17 +201,17 @@ QWidget* TankInfoDelegate::createEditor(QWidget* parent, const QStyleOptionViewI return delegate; } -struct RevertWeigthData { +struct RevertWeightData { QString type; - int weigth; -} currWeigth; + int weight; +} currWeight; 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); + mymodel->setData(IDX(WeightModel::TYPE), currWeight.type, Qt::EditRole); + mymodel->passInData(IDX(WeightModel::WEIGHT), currWeight.weight); } } @@ -236,7 +238,6 @@ void WSInfoDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, co } mymodel->setData(IDX(WeightModel::TYPE), v, Qt::EditRole); mymodel->passInData(IDX(WeightModel::WEIGHT), grams); - qDebug() << "Fixme, every weigth is 0.0 grams. see:" << grams; } WSInfoDelegate::WSInfoDelegate(QObject* parent): ComboBoxDelegate(WSInfoModel::instance(), parent) @@ -249,7 +250,23 @@ QWidget* WSInfoDelegate::createEditor(QWidget* parent, const QStyleOptionViewIte 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; + currWeight.type = ws->description; + currWeight.weight = ws->weight.grams; return editor; } + +void AirTypesDelegate::revertModelData(QWidget* widget, QAbstractItemDelegate::EndEditHint hint) +{ +} + +void AirTypesDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const +{ + if (!index.isValid()) + return; + QComboBox *combo = qobject_cast<QComboBox*>(editor); + model->setData(index, QVariant(combo->currentText())); +} + +AirTypesDelegate::AirTypesDelegate(QObject* parent) : ComboBoxDelegate(airTypes(), parent) +{ +} |