From 99351b7b734c93eceb739fc26ec47f3f181f6195 Mon Sep 17 00:00:00 2001 From: "Robert C. Helling" Date: Sun, 26 Mar 2017 23:47:21 +0200 Subject: Allow cylinder names to be edited The same ComboBoxDelegate is used for picking a cylinder model and picking a gas in the planner waypoint table. In the former case we want to allow the user to edit the string in the second we don't. The difference is not if we are in the planner but which use of the class. So add a bool allowEdit to the constructor. Fixes #272 Signed-off-by: Robert C. Helling --- desktop-widgets/modeldelegates.cpp | 12 ++++++------ desktop-widgets/modeldelegates.h | 5 +++-- 2 files changed, 9 insertions(+), 8 deletions(-) (limited to 'desktop-widgets') diff --git a/desktop-widgets/modeldelegates.cpp b/desktop-widgets/modeldelegates.cpp index 8255d40c8..d5ba6359b 100644 --- a/desktop-widgets/modeldelegates.cpp +++ b/desktop-widgets/modeldelegates.cpp @@ -80,8 +80,9 @@ const QSize& StarWidgetsDelegate::starSize() const return minStarSize; } -ComboBoxDelegate::ComboBoxDelegate(QAbstractItemModel *model, QObject *parent) : QStyledItemDelegate(parent), model(model) +ComboBoxDelegate::ComboBoxDelegate(QAbstractItemModel *model, QObject *parent, bool allowEdit) : QStyledItemDelegate(parent), model(model) { + editable = allowEdit; connect(this, SIGNAL(closeEditor(QWidget *, QAbstractItemDelegate::EndEditHint)), this, SLOT(revertModelData(QWidget *, QAbstractItemDelegate::EndEditHint))); connect(this, SIGNAL(closeEditor(QWidget *, QAbstractItemDelegate::EndEditHint)), @@ -120,8 +121,7 @@ QWidget *ComboBoxDelegate::createEditor(QWidget *parent, const QStyleOptionViewI comboDelegate->completer()->setCompletionMode(QCompleter::PopupCompletion); comboDelegate->view()->setEditTriggers(QAbstractItemView::AllEditTriggers); comboDelegate->lineEdit()->installEventFilter(const_cast(qobject_cast(this))); - if ((m->graphics()->currentState != ProfileWidget2::PROFILE)) - comboDelegate->lineEdit()->setEnabled(false); + comboDelegate->lineEdit()->setEnabled(editable); comboDelegate->view()->installEventFilter(const_cast(qobject_cast(this))); QAbstractItemView *comboPopup = comboDelegate->lineEdit()->completer()->popup(); comboPopup->setMouseTracking(true); @@ -267,7 +267,7 @@ void TankInfoDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, mymodel->passInData(IDX(CylindersModel::SIZE), tankSize); } -TankInfoDelegate::TankInfoDelegate(QObject *parent) : ComboBoxDelegate(TankInfoModel::instance(), parent) +TankInfoDelegate::TankInfoDelegate(QObject *parent) : ComboBoxDelegate(TankInfoModel::instance(), parent, true) { connect(this, SIGNAL(closeEditor(QWidget *, QAbstractItemDelegate::EndEditHint)), this, SLOT(reenableReplot(QWidget *, QAbstractItemDelegate::EndEditHint))); @@ -377,7 +377,7 @@ void WSInfoDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, co mymodel->passInData(IDX(WeightModel::WEIGHT), grams); } -WSInfoDelegate::WSInfoDelegate(QObject *parent) : ComboBoxDelegate(WSInfoModel::instance(), parent) +WSInfoDelegate::WSInfoDelegate(QObject *parent) : ComboBoxDelegate(WSInfoModel::instance(), parent, false) { } @@ -406,7 +406,7 @@ void AirTypesDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, model->setData(index, QVariant(combo->currentIndex())); } -AirTypesDelegate::AirTypesDelegate(QObject *parent) : ComboBoxDelegate(GasSelectionModel::instance(), parent) +AirTypesDelegate::AirTypesDelegate(QObject *parent) : ComboBoxDelegate(GasSelectionModel::instance(), parent, false) { } diff --git a/desktop-widgets/modeldelegates.h b/desktop-widgets/modeldelegates.h index 34012aa2a..82a5e1c7d 100644 --- a/desktop-widgets/modeldelegates.h +++ b/desktop-widgets/modeldelegates.h @@ -30,7 +30,7 @@ private: class ComboBoxDelegate : public QStyledItemDelegate { Q_OBJECT public: - explicit ComboBoxDelegate(QAbstractItemModel *model, QObject *parent = 0); + explicit ComboBoxDelegate(QAbstractItemModel *model, QObject *parent = 0, bool allowEdit = true); virtual QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const; virtual void setEditorData(QWidget *editor, const QModelIndex &index) const; virtual void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const; @@ -43,7 +43,8 @@ slots: void fakeActivation(); void fixTabBehavior(); virtual void revertModelData(QWidget *widget, QAbstractItemDelegate::EndEditHint hint) = 0; - +private: + bool editable; protected: QAbstractItemModel *model; }; -- cgit v1.2.3-70-g09d2