Skip to content
Snippets Groups Projects
Commit 98fdbcad authored by Pospelov, Gennady's avatar Pospelov, Gennady
Browse files

Special trick to make ComboBoxEditor working with QDataWidget mapper.

parent a4f87408
No related branches found
No related tags found
No related merge requests found
...@@ -73,8 +73,8 @@ void ComponentFlatView::onDataChanged(const QModelIndex& topLeft, const QModelIn ...@@ -73,8 +73,8 @@ void ComponentFlatView::onDataChanged(const QModelIndex& topLeft, const QModelIn
{ {
SessionItem *item = m_model->itemForIndex(topLeft); SessionItem *item = m_model->itemForIndex(topLeft);
Q_ASSERT(item); Q_ASSERT(item);
if (item->modelType() == Constants::GroupItemType) // if (item->modelType() == Constants::GroupItemType)
updateItemProperties(m_currentItem); // updateItemProperties(m_currentItem);
} }
void ComponentFlatView::updateItemProperties(SessionItem* item) void ComponentFlatView::updateItemProperties(SessionItem* item)
......
...@@ -221,7 +221,7 @@ void CustomComboEditor::setConnected(bool isConnected) ...@@ -221,7 +221,7 @@ void CustomComboEditor::setConnected(bool isConnected)
this, &CustomComboEditor::onIndexChanged, Qt::UniqueConnection); this, &CustomComboEditor::onIndexChanged, Qt::UniqueConnection);
else else
disconnect(m_box, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), disconnect(m_box, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
this, &CustomComboEditor::onIndexChanged); this, &CustomComboEditor::onIndexChanged);
} }
// --- GroupPropertyEditor --- // --- GroupPropertyEditor ---
...@@ -269,6 +269,7 @@ void ComboPropertyEditor::onIndexChanged(int index) ...@@ -269,6 +269,7 @@ void ComboPropertyEditor::onIndexChanged(int index)
if (comboProperty.currentIndex() != index) { if (comboProperty.currentIndex() != index) {
comboProperty.setCurrentIndex(index); comboProperty.setCurrentIndex(index);
setDataIntern(QVariant::fromValue<ComboProperty>(comboProperty)); setDataIntern(QVariant::fromValue<ComboProperty>(comboProperty));
currentIndexChanged(index);
} }
} }
......
...@@ -89,7 +89,7 @@ private: ...@@ -89,7 +89,7 @@ private:
LostFocusFilter* m_focusFilter; LostFocusFilter* m_focusFilter;
}; };
//! Common editor for QComboBox-like cystim editors. //! Common editor for QComboBox-like custom editors.
class BA_CORE_API_ CustomComboEditor : public CustomEditor class BA_CORE_API_ CustomComboEditor : public CustomEditor
{ {
...@@ -109,7 +109,7 @@ protected: ...@@ -109,7 +109,7 @@ protected:
virtual int internIndex(); virtual int internIndex();
void setConnected(bool isConnected); void setConnected(bool isConnected);
QComboBox* m_box; QComboBox* m_box;
}; };
//! Editor for GroupProperty variant. //! Editor for GroupProperty variant.
...@@ -132,10 +132,15 @@ protected: ...@@ -132,10 +132,15 @@ protected:
class BA_CORE_API_ ComboPropertyEditor : public CustomComboEditor class BA_CORE_API_ ComboPropertyEditor : public CustomComboEditor
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit ComboPropertyEditor(QWidget *parent = nullptr); explicit ComboPropertyEditor(QWidget *parent = nullptr);
signals:
//! Signal which is used only in the context of ComponentFlatView
void currentIndexChanged(int);
protected slots: protected slots:
void onIndexChanged(int index); void onIndexChanged(int index);
......
...@@ -19,10 +19,13 @@ ...@@ -19,10 +19,13 @@
#include "SessionModel.h" #include "SessionModel.h"
#include "SessionItemUtils.h" #include "SessionItemUtils.h"
#include "SessionModelDelegate.h" #include "SessionModelDelegate.h"
#include "CustomEditors.h"
#include <QLabel> #include <QLabel>
#include <QWidget> #include <QWidget>
#include <QDataWidgetMapper> #include <QDataWidgetMapper>
#include <QGridLayout> #include <QGridLayout>
#include <QComboBox>
#include <QDebug>
PropertyWidgetItem::PropertyWidgetItem(QWidget* parent) PropertyWidgetItem::PropertyWidgetItem(QWidget* parent)
: QObject(parent) : QObject(parent)
...@@ -56,6 +59,10 @@ void PropertyWidgetItem::setItemEditor(SessionItem* item, QWidget* editor) ...@@ -56,6 +59,10 @@ void PropertyWidgetItem::setItemEditor(SessionItem* item, QWidget* editor)
m_dataMapper->addMapping(m_editor, 1); m_dataMapper->addMapping(m_editor, 1);
m_dataMapper->setItemDelegate(m_delegate); m_dataMapper->setItemDelegate(m_delegate);
// Hack: QDataWidgetMapper doesn't listen for the widget (QComboBox is somewhat special).
if (auto combo = dynamic_cast<ComboPropertyEditor*>(editor))
connect(combo, &ComboPropertyEditor::currentIndexChanged, [=]{m_delegate->commitData(combo);});
m_label->setEnabled(item->isEnabled()); m_label->setEnabled(item->isEnabled());
m_editor->setEnabled(item->isEnabled()); m_editor->setEnabled(item->isEnabled());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment