From 8a6003752e5865fcfcf52b6f34269baae0c54060 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Wed, 4 Nov 2020 10:53:49 +0200 Subject: [PATCH] Fix property value update. Default handler doesn't work in our cases. --- .../vpropertyexplorer/plugins/vlabelproperty.cpp | 11 +++++++++++ .../vpropertyexplorer/plugins/vlabelproperty.h | 3 +++ .../vpropertyexplorer/plugins/vstringproperty.cpp | 14 ++++++++++++++ .../vpropertyexplorer/plugins/vstringproperty.h | 3 +++ .../vpropertyexplorer/plugins/vtextproperty.cpp | 11 +++++++++++ src/libs/vpropertyexplorer/plugins/vtextproperty.h | 3 +++ 6 files changed, 45 insertions(+) diff --git a/src/libs/vpropertyexplorer/plugins/vlabelproperty.cpp b/src/libs/vpropertyexplorer/plugins/vlabelproperty.cpp index c295809bc..976f0bfb2 100644 --- a/src/libs/vpropertyexplorer/plugins/vlabelproperty.cpp +++ b/src/libs/vpropertyexplorer/plugins/vlabelproperty.cpp @@ -70,6 +70,17 @@ QWidget *VPE::VLabelProperty::createEditor(QWidget *parent, const QStyleOptionVi return d_ptr->editor; } +bool VPE::VLabelProperty::setEditorData(QWidget *editor) +{ + if (QLabel* tmpWidget = qobject_cast(editor)) + { + tmpWidget->setText(d_ptr->VariantValue.toString()); + return true; + } + + return false; +} + QVariant VPE::VLabelProperty::getEditorData(const QWidget *editor) const { const QLabel* tmpEditor = qobject_cast(editor); diff --git a/src/libs/vpropertyexplorer/plugins/vlabelproperty.h b/src/libs/vpropertyexplorer/plugins/vlabelproperty.h index c4385793e..f67c63316 100644 --- a/src/libs/vpropertyexplorer/plugins/vlabelproperty.h +++ b/src/libs/vpropertyexplorer/plugins/vlabelproperty.h @@ -63,6 +63,9 @@ public: virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& options, const QAbstractItemDelegate* delegate) override; + //! Sets the property's data to the editor (returns false, if the standard delegate should do that) + virtual bool setEditorData(QWidget* editor) override; + //! Gets the data from the widget virtual QVariant getEditorData(const QWidget* editor) const override; diff --git a/src/libs/vpropertyexplorer/plugins/vstringproperty.cpp b/src/libs/vpropertyexplorer/plugins/vstringproperty.cpp index 9c843a7ef..72bf5e6d1 100644 --- a/src/libs/vpropertyexplorer/plugins/vstringproperty.cpp +++ b/src/libs/vpropertyexplorer/plugins/vstringproperty.cpp @@ -65,6 +65,20 @@ QWidget *VPE::VStringProperty::createEditor(QWidget *parent, const QStyleOptionV return d_ptr->editor; } +bool VPE::VStringProperty::setEditorData(QWidget *editor) +{ + if (QLineEdit* tmpWidget = qobject_cast(editor)) + { + if (not readOnly) + { + tmpWidget->setText(d_ptr->VariantValue.toString()); + } + return true; + } + + return false; +} + QVariant VPE::VStringProperty::getEditorData(const QWidget *editor) const { const QLineEdit* tmpEditor = qobject_cast(editor); diff --git a/src/libs/vpropertyexplorer/plugins/vstringproperty.h b/src/libs/vpropertyexplorer/plugins/vstringproperty.h index ad0959ce1..794eddff0 100644 --- a/src/libs/vpropertyexplorer/plugins/vstringproperty.h +++ b/src/libs/vpropertyexplorer/plugins/vstringproperty.h @@ -55,6 +55,9 @@ public: virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& options, const QAbstractItemDelegate* delegate) override; + //! Sets the property's data to the editor (returns false, if the standard delegate should do that) + virtual bool setEditorData(QWidget* editor) override; + //! Gets the data from the widget virtual QVariant getEditorData(const QWidget* editor) const override; diff --git a/src/libs/vpropertyexplorer/plugins/vtextproperty.cpp b/src/libs/vpropertyexplorer/plugins/vtextproperty.cpp index 69d1a9781..3e250eff0 100644 --- a/src/libs/vpropertyexplorer/plugins/vtextproperty.cpp +++ b/src/libs/vpropertyexplorer/plugins/vtextproperty.cpp @@ -86,6 +86,17 @@ QWidget *VPE::VTextProperty::createEditor(QWidget *parent, const QStyleOptionVie return d_ptr->editor; } +bool VPE::VTextProperty::setEditorData(QWidget *editor) +{ + if (QPlainTextEdit* tmpWidget = qobject_cast(editor)) + { + tmpWidget->setPlainText(d_ptr->VariantValue.toString()); + return true; + } + + return false; +} + QVariant VPE::VTextProperty::getEditorData(const QWidget *editor) const { const QPlainTextEdit* tmpEditor = qobject_cast(editor); diff --git a/src/libs/vpropertyexplorer/plugins/vtextproperty.h b/src/libs/vpropertyexplorer/plugins/vtextproperty.h index 91ddec63d..2bbdfa57d 100644 --- a/src/libs/vpropertyexplorer/plugins/vtextproperty.h +++ b/src/libs/vpropertyexplorer/plugins/vtextproperty.h @@ -52,6 +52,9 @@ public: virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& options, const QAbstractItemDelegate* delegate) override; + //! Sets the property's data to the editor (returns false, if the standard delegate should do that) + virtual bool setEditorData(QWidget* editor) override; + //! Gets the data from the widget virtual QVariant getEditorData(const QWidget* editor) const override;