From 1f81694b82c4e33ad3431e32e84b8b7f1c9c8db2 Mon Sep 17 00:00:00 2001 From: dnk-88 Date: Sun, 10 Jun 2012 22:13:19 +0300 Subject: [PATCH] Changed: #1302 Added signal 'reset text property' for returning to default value --HG-- branch : gsoc2011-worldeditorqt --- .../qtpropertybrowser/qteditorfactory.cpp | 39 +++++++++++++++++-- .../qtpropertybrowser/qteditorfactory.h | 1 + .../qtpropertybrowser/qtpropertybrowser.cpp | 5 +++ .../qtpropertybrowser/qtpropertybrowser.h | 2 + .../qtpropertybrowser/qtpropertymanager.cpp | 5 --- .../qtpropertybrowser/qtpropertymanager.h | 2 - 6 files changed, 43 insertions(+), 11 deletions(-) diff --git a/code/nel/tools/3d/object_viewer_qt/src/3rdparty/qtpropertybrowser/qteditorfactory.cpp b/code/nel/tools/3d/object_viewer_qt/src/3rdparty/qtpropertybrowser/qteditorfactory.cpp index c1a10ff0a..9331959b9 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/3rdparty/qtpropertybrowser/qteditorfactory.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/3rdparty/qtpropertybrowser/qteditorfactory.cpp @@ -704,7 +704,7 @@ void QtCheckBoxFactoryPrivate::slotReset() QtBoolPropertyManager *manager = q_ptr->propertyManager(property); if (!manager) return; - manager->setResetProperty(property); + manager->emitResetProperty(property); return; } } @@ -2638,12 +2638,14 @@ public: public Q_SLOTS: void setValue(const QString &value); + void setStateResetButton(bool enabled); private Q_SLOTS: void buttonClicked(); Q_SIGNALS: void valueChanged(const QString &value); + void resetProperty(); private: QLineEdit *m_lineEdit; @@ -2675,6 +2677,7 @@ QtTextEditWidget::QtTextEditWidget(QWidget *parent) : m_defaultButton->setMaximumWidth(16); connect(m_button, SIGNAL(clicked()), this, SLOT(buttonClicked())); + connect(m_defaultButton, SIGNAL(clicked()), this, SIGNAL(resetProperty())); lt->addWidget(m_button); lt->addWidget(m_defaultButton); m_defaultButton->setEnabled(false); @@ -2686,6 +2689,11 @@ void QtTextEditWidget::setValue(const QString &value) m_lineEdit->setText(value); } +void QtTextEditWidget::setStateResetButton(bool enabled) +{ + m_defaultButton->setEnabled(enabled); +} + void QtTextEditWidget::buttonClicked() { QGridLayout *gridLayout; @@ -2761,6 +2769,7 @@ public: void slotPropertyChanged(QtProperty *property, const QString &value); void slotSetValue(const QString &value); + void slotResetProperty(); }; void QtTextEditorFactoryPrivate::slotPropertyChanged(QtProperty *property, @@ -2772,7 +2781,11 @@ void QtTextEditorFactoryPrivate::slotPropertyChanged(QtProperty *property, QListIterator itEditor(it.value()); while (itEditor.hasNext()) - itEditor.next()->setValue(value); + { + QtTextEditWidget *editor = itEditor.next(); + editor->setValue(value); + editor->setStateResetButton(property->isModified()); + } } void QtTextEditorFactoryPrivate::slotSetValue(const QString &value) @@ -2789,6 +2802,22 @@ void QtTextEditorFactoryPrivate::slotSetValue(const QString &value) return; } } + +void QtTextEditorFactoryPrivate::slotResetProperty() +{ + QObject *object = q_ptr->sender(); + const EditorToPropertyMap::ConstIterator ecend = m_editorToProperty.constEnd(); + for (EditorToPropertyMap::ConstIterator itEditor = m_editorToProperty.constBegin(); itEditor != ecend; ++itEditor) + if (itEditor.key() == object) { + QtProperty *property = itEditor.value(); + QtTextPropertyManager *manager = q_ptr->propertyManager(property); + if (!manager) + return; + manager->emitResetProperty(property); + return; + } +} + /*! \class QtTextEditFactory @@ -2841,8 +2870,10 @@ QWidget *QtTextEditorFactory::createEditor(QtTextPropertyManager *manager, QtTextEditWidget *editor = d_ptr->createEditor(property, parent); editor->setValue(manager->value(property)); - - connect(editor, SIGNAL(valueChanged(QString)), this, SLOT(slotSetValue(QString))); + editor->setStateResetButton(property->isModified()); + + connect(editor, SIGNAL(resetProperty()), this, SLOT(slotResetProperty())); + connect(editor, SIGNAL(valueChanged(QString)), this, SLOT(slotSetValue(QString))); connect(editor, SIGNAL(destroyed(QObject *)), this, SLOT(slotEditorDestroyed(QObject *))); return editor; } diff --git a/code/nel/tools/3d/object_viewer_qt/src/3rdparty/qtpropertybrowser/qteditorfactory.h b/code/nel/tools/3d/object_viewer_qt/src/3rdparty/qtpropertybrowser/qteditorfactory.h index 58f64b2af..38489684e 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/3rdparty/qtpropertybrowser/qteditorfactory.h +++ b/code/nel/tools/3d/object_viewer_qt/src/3rdparty/qtpropertybrowser/qteditorfactory.h @@ -462,6 +462,7 @@ private: Q_PRIVATE_SLOT(d_func(), void slotPropertyChanged(QtProperty *, const QString &)) Q_PRIVATE_SLOT(d_func(), void slotSetValue(const QString &)) Q_PRIVATE_SLOT(d_func(), void slotEditorDestroyed(QObject *)) + Q_PRIVATE_SLOT(d_func(), void slotResetProperty()) }; #if QT_VERSION >= 0x040400 diff --git a/code/nel/tools/3d/object_viewer_qt/src/3rdparty/qtpropertybrowser/qtpropertybrowser.cpp b/code/nel/tools/3d/object_viewer_qt/src/3rdparty/qtpropertybrowser/qtpropertybrowser.cpp index e8c103d9b..9b7d98b09 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/3rdparty/qtpropertybrowser/qtpropertybrowser.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/3rdparty/qtpropertybrowser/qtpropertybrowser.cpp @@ -808,6 +808,11 @@ QtProperty *QtAbstractPropertyManager::addProperty(const QString &name) return property; } +void QtAbstractPropertyManager::emitResetProperty(QtProperty *property) +{ + emit resetProperty(property); +} + /*! Creates a property. diff --git a/code/nel/tools/3d/object_viewer_qt/src/3rdparty/qtpropertybrowser/qtpropertybrowser.h b/code/nel/tools/3d/object_viewer_qt/src/3rdparty/qtpropertybrowser/qtpropertybrowser.h index 35b7ac0f8..5b63d3917 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/3rdparty/qtpropertybrowser/qtpropertybrowser.h +++ b/code/nel/tools/3d/object_viewer_qt/src/3rdparty/qtpropertybrowser/qtpropertybrowser.h @@ -170,6 +170,7 @@ public: void clear() const; QtProperty *addProperty(const QString &name = QString()); + void emitResetProperty(QtProperty *property); Q_SIGNALS: void propertyInserted(QtProperty *property, @@ -177,6 +178,7 @@ Q_SIGNALS: void propertyChanged(QtProperty *property); void propertyRemoved(QtProperty *property, QtProperty *parent); void propertyDestroyed(QtProperty *property); + void resetProperty(QtProperty *property); protected: virtual bool hasValue(const QtProperty *property) const; virtual QIcon valueIcon(const QtProperty *property) const; diff --git a/code/nel/tools/3d/object_viewer_qt/src/3rdparty/qtpropertybrowser/qtpropertymanager.cpp b/code/nel/tools/3d/object_viewer_qt/src/3rdparty/qtpropertybrowser/qtpropertymanager.cpp index 6b2d24c80..fe8ea92c9 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/3rdparty/qtpropertybrowser/qtpropertymanager.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/3rdparty/qtpropertybrowser/qtpropertymanager.cpp @@ -1588,11 +1588,6 @@ void QtBoolPropertyManager::setValue(QtProperty *property, bool val) property, val); } -void QtBoolPropertyManager::setResetProperty(QtProperty *property) -{ - emit resetProperty(property); -} - /*! \reimp */ diff --git a/code/nel/tools/3d/object_viewer_qt/src/3rdparty/qtpropertybrowser/qtpropertymanager.h b/code/nel/tools/3d/object_viewer_qt/src/3rdparty/qtpropertybrowser/qtpropertymanager.h index 958b22dc8..a19dd6e03 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/3rdparty/qtpropertybrowser/qtpropertymanager.h +++ b/code/nel/tools/3d/object_viewer_qt/src/3rdparty/qtpropertybrowser/qtpropertymanager.h @@ -160,11 +160,9 @@ public: public Q_SLOTS: void setValue(QtProperty *property, bool val); - void setResetProperty(QtProperty *property); Q_SIGNALS: void valueChanged(QtProperty *property, bool val); - void resetProperty(QtProperty *property); protected: QString valueText(const QtProperty *property) const;