diff --git a/src/app/widgets/vtooloptionspropertybrowser.cpp b/src/app/widgets/vtooloptionspropertybrowser.cpp index 9ed2b58dd..558cb9024 100644 --- a/src/app/widgets/vtooloptionspropertybrowser.cpp +++ b/src/app/widgets/vtooloptionspropertybrowser.cpp @@ -35,6 +35,7 @@ #include "../libs/vpropertyexplorer/plugins/vnumberproperty.h" #include "../libs/vpropertyexplorer/plugins/vstringproperty.h" #include "../libs/vpropertyexplorer/plugins/vpointfproperty.h" +#include "../libs/vpropertyexplorer/plugins/venumproperty.h" #include #include @@ -138,6 +139,10 @@ void VToolOptionsPropertyBrowser::userChangedData(VProperty *property) { currentItem->setPos(variant.toPointF()); } +// else if (id == QLatin1String("list")) +// { +// qDebug()<data(VProperty::DPC_Data, Qt::DisplayRole); +// } break; } // case VGraphicsSimpleTextItem::Type: @@ -206,6 +211,11 @@ void VToolOptionsPropertyBrowser::ShowItemOptions(QGraphicsItem *item) VPointFProperty* itemPosition = new VPointFProperty(tr("Position")); itemPosition->setValue(i->pos()); AddProperty(itemPosition, QLatin1String("position")); + +// VEnumProperty *enumProperty = new VEnumProperty(tr("list")); +// QStringList list = QStringList()<<"a1"<<"a2"<<"a3"; +// enumProperty->setLiterals(list); +// AddProperty(enumProperty, QLatin1String("list")); break; } case VGraphicsSimpleTextItem::Type: diff --git a/src/libs/vpropertyexplorer/plugins/venumproperty.cpp b/src/libs/vpropertyexplorer/plugins/venumproperty.cpp index b8285235e..e03504bbb 100644 --- a/src/libs/vpropertyexplorer/plugins/venumproperty.cpp +++ b/src/libs/vpropertyexplorer/plugins/venumproperty.cpp @@ -2,14 +2,15 @@ #include "vproperty_p.h" #include +#include using namespace VPE; VEnumProperty::VEnumProperty(const QString& name) - : VProperty(name, QVariant::Int) + : QObject(), VProperty(name, QVariant::Int) { - d_ptr->VariantValue = 0; - d_ptr->VariantValue.convert(QVariant::Int); + VProperty::d_ptr->VariantValue = 0; + VProperty::d_ptr->VariantValue.convert(QVariant::Int); } @@ -19,7 +20,7 @@ QVariant VEnumProperty::data (int column, int role) const if(EnumerationLiterals.empty()) return QVariant(); - int tmpIndex = d_ptr->VariantValue.toInt(); + int tmpIndex = VProperty::d_ptr->VariantValue.toInt(); if(tmpIndex < 0 || tmpIndex >= EnumerationLiterals.count()) tmpIndex = 0; @@ -41,9 +42,12 @@ QWidget* VEnumProperty::createEditor(QWidget * parent, const QStyleOptionViewIte QComboBox* tmpEditor = new QComboBox(parent); tmpEditor->clear(); tmpEditor->addItems(EnumerationLiterals); - tmpEditor->setCurrentIndex(d_ptr->VariantValue.toInt()); + tmpEditor->setCurrentIndex(VProperty::d_ptr->VariantValue.toInt()); + connect(tmpEditor, static_cast(&QComboBox::currentIndexChanged), this, + &VEnumProperty::currentIndexChanged); - return tmpEditor; + VProperty::d_ptr->editor = tmpEditor; + return VProperty::d_ptr->editor; } //! Gets the data from the widget @@ -76,7 +80,13 @@ void VEnumProperty::setValue(const QVariant& value) if(tmpIndex < 0 || tmpIndex >= EnumerationLiterals.count()) tmpIndex = 0; - d_ptr->VariantValue.setValue(tmpIndex); + VProperty::d_ptr->VariantValue = tmpIndex; + VProperty::d_ptr->VariantValue.convert(QVariant::Int); + + if (VProperty::d_ptr->editor != nullptr) + { + setEditorData(VProperty::d_ptr->editor); + } } QString VEnumProperty::type() const @@ -107,3 +117,10 @@ QStringList VEnumProperty::getSettingKeys() const { return QStringList("literals"); } + +void VEnumProperty::currentIndexChanged(int index) +{ + Q_UNUSED(index) + UserChangeEvent *event = new UserChangeEvent(); + QCoreApplication::postEvent ( VProperty::d_ptr->editor, event ); +} diff --git a/src/libs/vpropertyexplorer/plugins/venumproperty.h b/src/libs/vpropertyexplorer/plugins/venumproperty.h index 72748529d..c43761bf2 100644 --- a/src/libs/vpropertyexplorer/plugins/venumproperty.h +++ b/src/libs/vpropertyexplorer/plugins/venumproperty.h @@ -7,8 +7,9 @@ namespace VPE{ -class VPROPERTYEXPLORERSHARED_EXPORT VEnumProperty : public VProperty +class VPROPERTYEXPLORERSHARED_EXPORT VEnumProperty : public QObject, public VProperty { + Q_OBJECT public: //! Constructor VEnumProperty(const QString& name); @@ -57,6 +58,9 @@ public: //! Returns the list of keys of the property's settings virtual QStringList getSettingKeys() const; +public slots: + void currentIndexChanged(int index); + protected: //! The list of possible options to choose frome QStringList EnumerationLiterals; diff --git a/src/libs/vpropertyexplorer/plugins/vnumberproperty.cpp b/src/libs/vpropertyexplorer/plugins/vnumberproperty.cpp index 9ec0e7ccf..07fb5cf65 100644 --- a/src/libs/vpropertyexplorer/plugins/vnumberproperty.cpp +++ b/src/libs/vpropertyexplorer/plugins/vnumberproperty.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include "vproperty_p.h" @@ -13,18 +14,18 @@ const int VIntegerProperty::StandardMin = -1000000; const int VIntegerProperty::StandardMax = 1000000; VIntegerProperty::VIntegerProperty(const QString& name, const QMap& settings) - : VProperty(name, QVariant::Int), Min(StandardMin), Max(StandardMax) + : QObject(), VProperty(name, QVariant::Int), Min(StandardMin), Max(StandardMax) { VProperty::setSettings(settings); - d_ptr->VariantValue.setValue(0); - d_ptr->VariantValue.convert(QVariant::Int); + VProperty::d_ptr->VariantValue.setValue(0); + VProperty::d_ptr->VariantValue.convert(QVariant::Int); } VIntegerProperty::VIntegerProperty(const QString &name) - : VProperty(name), Min(StandardMin), Max(StandardMax) + : QObject(), VProperty(name), Min(StandardMin), Max(StandardMax) { - d_ptr->VariantValue.setValue(0); - d_ptr->VariantValue.convert(QVariant::Int); + VProperty::d_ptr->VariantValue.setValue(0); + VProperty::d_ptr->VariantValue.convert(QVariant::Int); } //! Returns an editor widget, or NULL if it doesn't supply one @@ -37,10 +38,12 @@ QWidget* VIntegerProperty::createEditor(QWidget * parent, const QStyleOptionView tmpEditor->setMinimum(Min); tmpEditor->setMaximum(Max); tmpEditor->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - tmpEditor->setValue(d_ptr->VariantValue.toInt()); + tmpEditor->setValue(VProperty::d_ptr->VariantValue.toInt()); + connect(tmpEditor, static_cast(&QSpinBox::valueChanged), this, + &VIntegerProperty::valueChanged); - d_ptr->editor = tmpEditor; - return d_ptr->editor; + VProperty::d_ptr->editor = tmpEditor; + return VProperty::d_ptr->editor; } //! Gets the data from the widget @@ -92,6 +95,13 @@ VProperty* VIntegerProperty::clone(bool include_children, VProperty* container) return VProperty::clone(include_children, container ? container : new VIntegerProperty(getName())); } +void VIntegerProperty::valueChanged(int i) +{ + Q_UNUSED(i) + UserChangeEvent *event = new UserChangeEvent(); + QCoreApplication::postEvent ( VProperty::d_ptr->editor, event ); +} + @@ -102,17 +112,17 @@ VDoubleProperty::VDoubleProperty(const QString& name, const QMapVariantValue.setValue(0); - d_ptr->VariantValue.convert(QVariant::Double); - d_ptr->PropertyVariantType = QVariant::Double; + VProperty::d_ptr->VariantValue.setValue(0); + VProperty::d_ptr->VariantValue.convert(QVariant::Double); + VProperty::d_ptr->PropertyVariantType = QVariant::Double; } VDoubleProperty::VDoubleProperty(const QString &name) : VIntegerProperty(name), Precision(StandardPrecision) { - d_ptr->VariantValue.setValue(0); - d_ptr->VariantValue.convert(QVariant::Double); - d_ptr->PropertyVariantType = QVariant::Double; + VProperty::d_ptr->VariantValue.setValue(0); + VProperty::d_ptr->VariantValue.convert(QVariant::Double); + VProperty::d_ptr->PropertyVariantType = QVariant::Double; } //! Returns an editor widget, or NULL if it doesn't supply one @@ -125,10 +135,12 @@ QWidget* VDoubleProperty::createEditor(QWidget * parent, const QStyleOptionViewI tmpEditor->setMaximum(Max); tmpEditor->setDecimals(Precision); tmpEditor->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - tmpEditor->setValue(d_ptr->VariantValue.toDouble()); + tmpEditor->setValue(VProperty::d_ptr->VariantValue.toDouble()); + connect(tmpEditor, static_cast(&QDoubleSpinBox::valueChanged), this, + &VIntegerProperty::valueChanged); - d_ptr->editor = tmpEditor; - return d_ptr->editor; + VProperty::d_ptr->editor = tmpEditor; + return VProperty::d_ptr->editor; } //! Gets the data from the widget diff --git a/src/libs/vpropertyexplorer/plugins/vnumberproperty.h b/src/libs/vpropertyexplorer/plugins/vnumberproperty.h index fa4fbcf4b..155357933 100644 --- a/src/libs/vpropertyexplorer/plugins/vnumberproperty.h +++ b/src/libs/vpropertyexplorer/plugins/vnumberproperty.h @@ -8,8 +8,9 @@ namespace VPE { //! Class for holding an integer property -class VPROPERTYEXPLORERSHARED_EXPORT VIntegerProperty : public VProperty +class VPROPERTYEXPLORERSHARED_EXPORT VIntegerProperty : public QObject, public VProperty { + Q_OBJECT public: VIntegerProperty(const QString& name, const QMap& settings); @@ -49,7 +50,8 @@ public: //! \param container If a property is being passed here, no new VProperty is being created but instead it is tried to fill all the data into container. This can also be used when subclassing this function. //! \return Returns the newly created property (or container, if it was not NULL) virtual VProperty* clone(bool include_children = true, VProperty* container = NULL) const; - +public slots: + void valueChanged(int i); protected: int Min, Max; @@ -61,6 +63,7 @@ protected: //! Class for holding a double property class VPROPERTYEXPLORERSHARED_EXPORT VDoubleProperty : public VIntegerProperty { + Q_OBJECT public: VDoubleProperty(const QString& name, const QMap& settings); diff --git a/src/libs/vpropertyexplorer/vpropertyformview.cpp b/src/libs/vpropertyexplorer/vpropertyformview.cpp index a443ee250..2661aec7c 100644 --- a/src/libs/vpropertyexplorer/vpropertyformview.cpp +++ b/src/libs/vpropertyexplorer/vpropertyformview.cpp @@ -122,8 +122,6 @@ void VPropertyFormView::dataSubmitted(VProperty *property) if(tmpModel && d_ptr->UpdateEditors) { static_cast(d_ptr)->IgnoreDataChangedSignal = true; tmpModel->onDataChangedByModel(property); - tmpModel->showDataChangedByEditor(property); - static_cast(d_ptr)->IgnoreDataChangedSignal = false; } } @@ -171,7 +169,8 @@ void VPropertyFormView::connectPropertyFormWidget(VPropertyFormWidget *widget) if(!widget) return; - connect(widget, SIGNAL(propertyDataSubmitted(VProperty*)), this, SLOT(dataSubmitted(VProperty*))); + connect(widget, &VPropertyFormWidget::propertyDataSubmitted, this, &VPropertyFormView::dataSubmitted, + Qt::UniqueConnection); QList tmpList = widget->getChildPropertyFormWidgets(); foreach(VPropertyFormWidget* tmpEditorWidget, tmpList) { diff --git a/src/libs/vpropertyexplorer/vpropertyformwidget.cpp b/src/libs/vpropertyexplorer/vpropertyformwidget.cpp index 45b35f33e..ef0f17937 100644 --- a/src/libs/vpropertyexplorer/vpropertyformwidget.cpp +++ b/src/libs/vpropertyexplorer/vpropertyformwidget.cpp @@ -7,6 +7,7 @@ #include #include #include "vproperty.h" +#include using namespace VPE; @@ -125,10 +126,10 @@ void VPropertyFormWidget::commitData(int row) tmpEditorWidget.FormWidget->commitData(); else if(tmpEditorWidget.Editor && tmpProperty) { QVariant newValue = tmpProperty->getEditorData(tmpEditorWidget.Editor); - QVariant oldValue = tmpProperty->data(VProperty::DPC_Data); + QVariant oldValue = tmpProperty->data(VProperty::DPC_Data, Qt::EditRole); if (oldValue != newValue) { - tmpProperty->setValue(tmpProperty->getEditorData(tmpEditorWidget.Editor)); + tmpProperty->setValue(newValue); emit propertyDataSubmitted(tmpProperty); } } @@ -205,6 +206,10 @@ bool VPropertyFormWidget::eventFilter(QObject *object, QEvent *event) event->accept(); return true; } + else + { + return QGroupBox::eventFilter(object, event); + } // Default: return false; diff --git a/src/libs/vpropertyexplorer/vpropertymodel.cpp b/src/libs/vpropertyexplorer/vpropertymodel.cpp index 368689200..1cb82a24f 100644 --- a/src/libs/vpropertyexplorer/vpropertymodel.cpp +++ b/src/libs/vpropertyexplorer/vpropertymodel.cpp @@ -230,14 +230,10 @@ void VPropertyModel::onDataChangedByModel(VProperty* property) if(tmpIndex.isValid()) { emit dataChanged(tmpIndex, tmpIndex); + emit onDataChangedByEditor(property); } } -void VPropertyModel::showDataChangedByEditor(VProperty *property) -{ - emit onDataChangedByEditor(property); -} - const VPropertySet *VPropertyModel::getPropertySet() const { return d_ptr->Properties; diff --git a/src/libs/vpropertyexplorer/vpropertymodel.h b/src/libs/vpropertyexplorer/vpropertymodel.h index 59de7b4a6..fb9df7a39 100644 --- a/src/libs/vpropertyexplorer/vpropertymodel.h +++ b/src/libs/vpropertyexplorer/vpropertymodel.h @@ -124,8 +124,6 @@ public slots: //! This function causes the views to update the property void onDataChangedByModel(VProperty* property); - void showDataChangedByEditor(VProperty* property); - protected: //! Gets a property by its ModelIndex virtual QModelIndex getIndexFromProperty(VProperty* property, int column = 0) const;