From da827ad952b024e6b0d8a1b7805a16fcb6a2333b Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Wed, 9 Dec 2015 13:13:34 +0200 Subject: [PATCH] QComboBox clear button in property browser. --HG-- branch : develop --- src/app/valentina/core/vformulaproperty.cpp | 1 + .../valentina/core/vtooloptionspropertybrowser.cpp | 9 ++++++--- .../vpropertyexplorer/plugins/vstringproperty.cpp | 12 ++++++++++-- src/libs/vpropertyexplorer/plugins/vstringproperty.h | 2 ++ 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/app/valentina/core/vformulaproperty.cpp b/src/app/valentina/core/vformulaproperty.cpp index ec116ae6e..ad5b8dd48 100644 --- a/src/app/valentina/core/vformulaproperty.cpp +++ b/src/app/valentina/core/vformulaproperty.cpp @@ -52,6 +52,7 @@ VFormulaProperty::VFormulaProperty(const QString &name) VStringProperty* tmpFormula = new VStringProperty(tr("Formula")); addChild(tmpFormula); + tmpFormula->setClearButtonEnable(true); tmpFormula->setUpdateBehaviour(true, false); tmpFormula->setTypeForParent(static_cast(ChildType::Formula)); diff --git a/src/app/valentina/core/vtooloptionspropertybrowser.cpp b/src/app/valentina/core/vtooloptionspropertybrowser.cpp index 4d55e4cbf..04b8d253e 100644 --- a/src/app/valentina/core/vtooloptionspropertybrowser.cpp +++ b/src/app/valentina/core/vtooloptionspropertybrowser.cpp @@ -438,7 +438,8 @@ void VToolOptionsPropertyBrowser::AddPropertyFormula(const QString &propertyName template void VToolOptionsPropertyBrowser::AddPropertyPointName(Tool *i, const QString &propertyName) { - VProperty* itemName = new VProperty(propertyName); + VStringProperty *itemName = new VStringProperty(propertyName); + itemName->setClearButtonEnable(true); itemName->setValue(i->name()); AddProperty(itemName, AttrName); } @@ -448,7 +449,8 @@ void VToolOptionsPropertyBrowser::AddPropertyPointName(Tool *i, const QString &p template void VToolOptionsPropertyBrowser::AddPropertyPointName1(Tool *i, const QString &propertyName) { - VProperty* itemName = new VProperty(propertyName); + VStringProperty *itemName = new VStringProperty(propertyName); + itemName->setClearButtonEnable(true); itemName->setValue(i->nameP1()); AddProperty(itemName, AttrName1); } @@ -457,7 +459,8 @@ void VToolOptionsPropertyBrowser::AddPropertyPointName1(Tool *i, const QString & template void VToolOptionsPropertyBrowser::AddPropertyPointName2(Tool *i, const QString &propertyName) { - VProperty* itemName = new VProperty(propertyName); + VStringProperty *itemName = new VStringProperty(propertyName); + itemName->setClearButtonEnable(true); itemName->setValue(i->nameP2()); AddProperty(itemName, AttrName2); } diff --git a/src/libs/vpropertyexplorer/plugins/vstringproperty.cpp b/src/libs/vpropertyexplorer/plugins/vstringproperty.cpp index 4b7af2947..a7e008294 100644 --- a/src/libs/vpropertyexplorer/plugins/vstringproperty.cpp +++ b/src/libs/vpropertyexplorer/plugins/vstringproperty.cpp @@ -29,7 +29,7 @@ using namespace VPE; VPE::VStringProperty::VStringProperty(const QString &name, const QMap &settings) - : VProperty(name, QVariant::String), readOnly(false), typeForParent(0) + : VProperty(name, QVariant::String), readOnly(false), typeForParent(0), clearButton(false) { VProperty::setSettings(settings); d_ptr->VariantValue.setValue(QString()); @@ -37,7 +37,7 @@ VPE::VStringProperty::VStringProperty(const QString &name, const QMapVariantValue.setValue(QString()); d_ptr->VariantValue.convert(QVariant::String); @@ -52,6 +52,9 @@ QWidget *VPE::VStringProperty::createEditor(QWidget *parent, const QStyleOptionV QLineEdit* tmpEditor = new QLineEdit(parent); tmpEditor->setLocale(parent->locale()); tmpEditor->setReadOnly(readOnly); +#if QT_VERSION >= QT_VERSION_CHECK(5, 2, 0) + tmpEditor->setClearButtonEnabled(clearButton); +#endif tmpEditor->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); tmpEditor->setText(d_ptr->VariantValue.toString()); @@ -75,6 +78,11 @@ void VPE::VStringProperty::setReadOnly(bool readOnly) this->readOnly = readOnly; } +void VStringProperty::setClearButtonEnable(bool value) +{ + this->clearButton = value; +} + void VPE::VStringProperty::setSetting(const QString &key, const QVariant &value) { if (key == QLatin1String("ReadOnly")) diff --git a/src/libs/vpropertyexplorer/plugins/vstringproperty.h b/src/libs/vpropertyexplorer/plugins/vstringproperty.h index 10f3bee84..70fba1b24 100644 --- a/src/libs/vpropertyexplorer/plugins/vstringproperty.h +++ b/src/libs/vpropertyexplorer/plugins/vstringproperty.h @@ -49,6 +49,7 @@ public: virtual QVariant getEditorData(const QWidget* editor) const Q_DECL_OVERRIDE; void setReadOnly(bool readOnly); + void setClearButtonEnable(bool value); //! Sets the settings. virtual void setSetting(const QString& key, const QVariant& value) Q_DECL_OVERRIDE; @@ -77,6 +78,7 @@ public: protected: bool readOnly; int typeForParent; + bool clearButton; private: Q_DISABLE_COPY(VStringProperty)