Changed: #1302 Added signal 'reset bool property' for returning to default value

This commit is contained in:
dnk-88 2012-06-10 21:15:22 +03:00
parent fe361a9ca0
commit 07ecce1b45
8 changed files with 52 additions and 3 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 169 B

View file

@ -659,6 +659,7 @@ class QtCheckBoxFactoryPrivate : public EditorFactoryPrivate<QtBoolEdit>
public:
void slotPropertyChanged(QtProperty *property, bool value);
void slotSetValue(bool value);
void slotReset();
};
void QtCheckBoxFactoryPrivate::slotPropertyChanged(QtProperty *property, bool value)
@ -669,6 +670,7 @@ void QtCheckBoxFactoryPrivate::slotPropertyChanged(QtProperty *property, bool va
QListIterator<QtBoolEdit *> itEditor(m_createdEditors[property]);
while (itEditor.hasNext()) {
QtBoolEdit *editor = itEditor.next();
editor->setStateResetButton(property->isModified());
editor->blockCheckBoxSignals(true);
editor->setChecked(value);
editor->blockCheckBoxSignals(false);
@ -691,6 +693,22 @@ void QtCheckBoxFactoryPrivate::slotSetValue(bool value)
}
}
void QtCheckBoxFactoryPrivate::slotReset()
{
QObject *object = q_ptr->sender();
const QMap<QtBoolEdit *, QtProperty *>::ConstIterator ecend = m_editorToProperty.constEnd();
for (QMap<QtBoolEdit *, QtProperty *>::ConstIterator itEditor = m_editorToProperty.constBegin(); itEditor != ecend; ++itEditor)
if (itEditor.key() == object) {
QtProperty *property = itEditor.value();
QtBoolPropertyManager *manager = q_ptr->propertyManager(property);
if (!manager)
return;
manager->setResetProperty(property);
return;
}
}
/*!
\class QtCheckBoxFactory
@ -740,8 +758,10 @@ QWidget *QtCheckBoxFactory::createEditor(QtBoolPropertyManager *manager, QtPrope
QWidget *parent)
{
QtBoolEdit *editor = d_ptr->createEditor(property, parent);
editor->setStateResetButton(property->isModified());
editor->setChecked(manager->value(property));
connect(editor, SIGNAL(resetProperty()), this, SLOT(slotReset()));
connect(editor, SIGNAL(toggled(bool)), this, SLOT(slotSetValue(bool)));
connect(editor, SIGNAL(destroyed(QObject *)),
this, SLOT(slotEditorDestroyed(QObject *)));
@ -2645,10 +2665,15 @@ QtTextEditWidget::QtTextEditWidget(QWidget *parent) :
m_button->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Ignored);
m_button->setFixedWidth(20);
setFocusProxy(m_button);
setFocusPolicy(m_button->focusPolicy());
m_button->setText(tr("..."));
m_button->installEventFilter(this);
setFocusProxy(m_button);
setFocusPolicy(m_button->focusPolicy());
m_defaultButton->setIcon(QIcon(":/trolltech/qtpropertybrowser/images/resetproperty.png"));
m_defaultButton->setMaximumWidth(16);
connect(m_button, SIGNAL(clicked()), this, SLOT(buttonClicked()));
lt->addWidget(m_button);
lt->addWidget(m_defaultButton);

View file

@ -186,6 +186,7 @@ private:
Q_PRIVATE_SLOT(d_func(), void slotPropertyChanged(QtProperty *, bool))
Q_PRIVATE_SLOT(d_func(), void slotSetValue(bool))
Q_PRIVATE_SLOT(d_func(), void slotEditorDestroyed(QObject *))
Q_PRIVATE_SLOT(d_func(), void slotReset())
};
class QtDoubleSpinBoxFactoryPrivate;

View file

@ -18,6 +18,7 @@
<file>images/cursor-vsplit.png</file>
<file>images/cursor-wait.png</file>
<file>images/cursor-whatsthis.png</file>
<file>images/resetproperty.png</file>
</qresource>
</RCC>

View file

@ -264,6 +264,10 @@ QtBoolEdit::QtBoolEdit(QWidget *parent) :
m_defaultButton(new QToolButton(this)),
m_textVisible(true)
{
m_defaultButton->setIcon(QIcon(":/trolltech/qtpropertybrowser/images/resetproperty.png"));
m_defaultButton->setMaximumWidth(16);
m_defaultButton->setEnabled(false);
QHBoxLayout *lt = new QHBoxLayout;
if (QApplication::layoutDirection() == Qt::LeftToRight)
lt->setContentsMargins(4, 0, 0, 0);
@ -271,9 +275,11 @@ QtBoolEdit::QtBoolEdit(QWidget *parent) :
lt->setContentsMargins(0, 0, 4, 0);
lt->addWidget(m_checkBox);
lt->addWidget(m_defaultButton);
m_defaultButton->setEnabled(false);
setLayout(lt);
connect(m_checkBox, SIGNAL(toggled(bool)), this, SIGNAL(toggled(bool)));
connect(m_defaultButton, SIGNAL(clicked()), this, SIGNAL(resetProperty()));
setFocusProxy(m_checkBox);
m_checkBox->setText(QString());
}
@ -297,6 +303,11 @@ void QtBoolEdit::setCheckState(Qt::CheckState state)
m_checkBox->setCheckState(state);
}
void QtBoolEdit::setStateResetButton(bool enabled)
{
m_defaultButton->setEnabled(enabled);
}
bool QtBoolEdit::isChecked() const
{
return m_checkBox->isChecked();

View file

@ -155,6 +155,7 @@ public:
Qt::CheckState checkState() const;
void setCheckState(Qt::CheckState state);
void setStateResetButton(bool enabled);
bool isChecked() const;
void setChecked(bool c);
@ -163,6 +164,7 @@ public:
Q_SIGNALS:
void toggled(bool);
void resetProperty();
protected:
void mousePressEvent(QMouseEvent * event);

View file

@ -1588,6 +1588,11 @@ void QtBoolPropertyManager::setValue(QtProperty *property, bool val)
property, val);
}
void QtBoolPropertyManager::setResetProperty(QtProperty *property)
{
emit resetProperty(property);
}
/*!
\reimp
*/

View file

@ -160,8 +160,12 @@ 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;
QIcon valueIcon(const QtProperty *property) const;