Changed: #1302 Added signal 'reset enum property' for returning to default value
--HG-- branch : gsoc2011-worldeditorqt
This commit is contained in:
parent
1f81694b82
commit
4f3999168e
2 changed files with 124 additions and 27 deletions
|
@ -659,7 +659,7 @@ class QtCheckBoxFactoryPrivate : public EditorFactoryPrivate<QtBoolEdit>
|
||||||
public:
|
public:
|
||||||
void slotPropertyChanged(QtProperty *property, bool value);
|
void slotPropertyChanged(QtProperty *property, bool value);
|
||||||
void slotSetValue(bool value);
|
void slotSetValue(bool value);
|
||||||
void slotReset();
|
void slotResetProperty();
|
||||||
};
|
};
|
||||||
|
|
||||||
void QtCheckBoxFactoryPrivate::slotPropertyChanged(QtProperty *property, bool value)
|
void QtCheckBoxFactoryPrivate::slotPropertyChanged(QtProperty *property, bool value)
|
||||||
|
@ -693,7 +693,7 @@ void QtCheckBoxFactoryPrivate::slotSetValue(bool value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtCheckBoxFactoryPrivate::slotReset()
|
void QtCheckBoxFactoryPrivate::slotResetProperty()
|
||||||
{
|
{
|
||||||
QObject *object = q_ptr->sender();
|
QObject *object = q_ptr->sender();
|
||||||
|
|
||||||
|
@ -761,7 +761,7 @@ QWidget *QtCheckBoxFactory::createEditor(QtBoolPropertyManager *manager, QtPrope
|
||||||
editor->setStateResetButton(property->isModified());
|
editor->setStateResetButton(property->isModified());
|
||||||
editor->setChecked(manager->value(property));
|
editor->setChecked(manager->value(property));
|
||||||
|
|
||||||
connect(editor, SIGNAL(resetProperty()), this, SLOT(slotReset()));
|
connect(editor, SIGNAL(resetProperty()), this, SLOT(slotResetProperty()));
|
||||||
connect(editor, SIGNAL(toggled(bool)), this, SLOT(slotSetValue(bool)));
|
connect(editor, SIGNAL(toggled(bool)), this, SLOT(slotSetValue(bool)));
|
||||||
connect(editor, SIGNAL(destroyed(QObject *)),
|
connect(editor, SIGNAL(destroyed(QObject *)),
|
||||||
this, SLOT(slotEditorDestroyed(QObject *)));
|
this, SLOT(slotEditorDestroyed(QObject *)));
|
||||||
|
@ -1880,9 +1880,87 @@ void QtCharEditorFactory::disconnectPropertyManager(QtCharPropertyManager *manag
|
||||||
this, SLOT(slotPropertyChanged(QtProperty *, const QChar &)));
|
this, SLOT(slotPropertyChanged(QtProperty *, const QChar &)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class QtEnumEditWidget : public QWidget {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
QtEnumEditWidget(QWidget *parent);
|
||||||
|
|
||||||
|
bool blockComboBoxSignals(bool block);
|
||||||
|
void addItems(const QStringList &texts);
|
||||||
|
void clearComboBox();
|
||||||
|
void setItemIcon(int index, const QIcon &icon);
|
||||||
|
|
||||||
|
public Q_SLOTS:
|
||||||
|
void setValue(int value);
|
||||||
|
void setStateResetButton(bool enabled);
|
||||||
|
|
||||||
|
Q_SIGNALS:
|
||||||
|
void valueChanged(int value);
|
||||||
|
void resetProperty();
|
||||||
|
|
||||||
|
private:
|
||||||
|
QComboBox *m_comboBox;
|
||||||
|
QToolButton *m_defaultButton;
|
||||||
|
};
|
||||||
|
|
||||||
|
QtEnumEditWidget::QtEnumEditWidget(QWidget *parent) :
|
||||||
|
QWidget(parent),
|
||||||
|
m_comboBox(new QComboBox),
|
||||||
|
m_defaultButton(new QToolButton)
|
||||||
|
{
|
||||||
|
m_comboBox->view()->setTextElideMode(Qt::ElideRight);
|
||||||
|
|
||||||
|
QHBoxLayout *lt = new QHBoxLayout(this);
|
||||||
|
lt->setContentsMargins(0, 0, 0, 0);
|
||||||
|
lt->setSpacing(0);
|
||||||
|
lt->addWidget(m_comboBox);
|
||||||
|
|
||||||
|
m_defaultButton->setIcon(QIcon(":/trolltech/qtpropertybrowser/images/resetproperty.png"));
|
||||||
|
m_defaultButton->setMaximumWidth(16);
|
||||||
|
|
||||||
|
connect(m_comboBox, SIGNAL(currentIndexChanged(int)), this, SIGNAL(valueChanged(int)));
|
||||||
|
connect(m_defaultButton, SIGNAL(clicked()), this, SIGNAL(resetProperty()));
|
||||||
|
lt->addWidget(m_defaultButton);
|
||||||
|
m_defaultButton->setEnabled(false);
|
||||||
|
setFocusProxy(m_comboBox);
|
||||||
|
}
|
||||||
|
|
||||||
|
void QtEnumEditWidget::setValue(int value)
|
||||||
|
{
|
||||||
|
if (m_comboBox->currentIndex() != value)
|
||||||
|
m_comboBox->setCurrentIndex(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void QtEnumEditWidget::setStateResetButton(bool enabled)
|
||||||
|
{
|
||||||
|
m_defaultButton->setEnabled(enabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool QtEnumEditWidget::blockComboBoxSignals(bool block)
|
||||||
|
{
|
||||||
|
return m_comboBox->blockSignals(block);
|
||||||
|
}
|
||||||
|
|
||||||
|
void QtEnumEditWidget::addItems(const QStringList &texts)
|
||||||
|
{
|
||||||
|
m_comboBox->addItems(texts);
|
||||||
|
}
|
||||||
|
|
||||||
|
void QtEnumEditWidget::clearComboBox()
|
||||||
|
{
|
||||||
|
m_comboBox->clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void QtEnumEditWidget::setItemIcon(int index, const QIcon &icon)
|
||||||
|
{
|
||||||
|
m_comboBox->setItemIcon(index, icon);
|
||||||
|
}
|
||||||
|
|
||||||
// QtEnumEditorFactory
|
// QtEnumEditorFactory
|
||||||
|
|
||||||
class QtEnumEditorFactoryPrivate : public EditorFactoryPrivate<QComboBox>
|
class QtEnumEditorFactoryPrivate : public EditorFactoryPrivate<QtEnumEditWidget>
|
||||||
{
|
{
|
||||||
QtEnumEditorFactory *q_ptr;
|
QtEnumEditorFactory *q_ptr;
|
||||||
Q_DECLARE_PUBLIC(QtEnumEditorFactory)
|
Q_DECLARE_PUBLIC(QtEnumEditorFactory)
|
||||||
|
@ -1892,19 +1970,36 @@ public:
|
||||||
void slotEnumNamesChanged(QtProperty *property, const QStringList &);
|
void slotEnumNamesChanged(QtProperty *property, const QStringList &);
|
||||||
void slotEnumIconsChanged(QtProperty *property, const QMap<int, QIcon> &);
|
void slotEnumIconsChanged(QtProperty *property, const QMap<int, QIcon> &);
|
||||||
void slotSetValue(int value);
|
void slotSetValue(int value);
|
||||||
|
void slotResetProperty();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void QtEnumEditorFactoryPrivate::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();
|
||||||
|
QtEnumPropertyManager *manager = q_ptr->propertyManager(property);
|
||||||
|
if (!manager)
|
||||||
|
return;
|
||||||
|
manager->emitResetProperty(property);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void QtEnumEditorFactoryPrivate::slotPropertyChanged(QtProperty *property, int value)
|
void QtEnumEditorFactoryPrivate::slotPropertyChanged(QtProperty *property, int value)
|
||||||
{
|
{
|
||||||
if (!m_createdEditors.contains(property))
|
if (!m_createdEditors.contains(property))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QListIterator<QComboBox *> itEditor(m_createdEditors[property]);
|
QListIterator<QtEnumEditWidget *> itEditor(m_createdEditors[property]);
|
||||||
while (itEditor.hasNext()) {
|
while (itEditor.hasNext()) {
|
||||||
QComboBox *editor = itEditor.next();
|
QtEnumEditWidget *editor = itEditor.next();
|
||||||
editor->blockSignals(true);
|
editor->setStateResetButton(property->isModified());
|
||||||
editor->setCurrentIndex(value);
|
editor->blockComboBoxSignals(true);
|
||||||
editor->blockSignals(false);
|
editor->setValue(value);
|
||||||
|
editor->blockComboBoxSignals(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1920,17 +2015,17 @@ void QtEnumEditorFactoryPrivate::slotEnumNamesChanged(QtProperty *property,
|
||||||
|
|
||||||
QMap<int, QIcon> enumIcons = manager->enumIcons(property);
|
QMap<int, QIcon> enumIcons = manager->enumIcons(property);
|
||||||
|
|
||||||
QListIterator<QComboBox *> itEditor(m_createdEditors[property]);
|
QListIterator<QtEnumEditWidget *> itEditor(m_createdEditors[property]);
|
||||||
while (itEditor.hasNext()) {
|
while (itEditor.hasNext()) {
|
||||||
QComboBox *editor = itEditor.next();
|
QtEnumEditWidget *editor = itEditor.next();
|
||||||
editor->blockSignals(true);
|
editor->blockComboBoxSignals(true);
|
||||||
editor->clear();
|
editor->clearComboBox();
|
||||||
editor->addItems(enumNames);
|
editor->addItems(enumNames);
|
||||||
const int nameCount = enumNames.count();
|
const int nameCount = enumNames.count();
|
||||||
for (int i = 0; i < nameCount; i++)
|
for (int i = 0; i < nameCount; i++)
|
||||||
editor->setItemIcon(i, enumIcons.value(i));
|
editor->setItemIcon(i, enumIcons.value(i));
|
||||||
editor->setCurrentIndex(manager->value(property));
|
editor->setValue(manager->value(property));
|
||||||
editor->blockSignals(false);
|
editor->blockComboBoxSignals(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1945,23 +2040,23 @@ void QtEnumEditorFactoryPrivate::slotEnumIconsChanged(QtProperty *property,
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const QStringList enumNames = manager->enumNames(property);
|
const QStringList enumNames = manager->enumNames(property);
|
||||||
QListIterator<QComboBox *> itEditor(m_createdEditors[property]);
|
QListIterator<QtEnumEditWidget *> itEditor(m_createdEditors[property]);
|
||||||
while (itEditor.hasNext()) {
|
while (itEditor.hasNext()) {
|
||||||
QComboBox *editor = itEditor.next();
|
QtEnumEditWidget *editor = itEditor.next();
|
||||||
editor->blockSignals(true);
|
editor->blockComboBoxSignals(true);
|
||||||
const int nameCount = enumNames.count();
|
const int nameCount = enumNames.count();
|
||||||
for (int i = 0; i < nameCount; i++)
|
for (int i = 0; i < nameCount; i++)
|
||||||
editor->setItemIcon(i, enumIcons.value(i));
|
editor->setItemIcon(i, enumIcons.value(i));
|
||||||
editor->setCurrentIndex(manager->value(property));
|
editor->setValue(manager->value(property));
|
||||||
editor->blockSignals(false);
|
editor->blockComboBoxSignals(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtEnumEditorFactoryPrivate::slotSetValue(int value)
|
void QtEnumEditorFactoryPrivate::slotSetValue(int value)
|
||||||
{
|
{
|
||||||
QObject *object = q_ptr->sender();
|
QObject *object = q_ptr->sender();
|
||||||
const QMap<QComboBox *, QtProperty *>::ConstIterator ecend = m_editorToProperty.constEnd();
|
const QMap<QtEnumEditWidget *, QtProperty *>::ConstIterator ecend = m_editorToProperty.constEnd();
|
||||||
for (QMap<QComboBox *, QtProperty *>::ConstIterator itEditor = m_editorToProperty.constBegin(); itEditor != ecend; ++itEditor)
|
for (QMap<QtEnumEditWidget *, QtProperty *>::ConstIterator itEditor = m_editorToProperty.constBegin(); itEditor != ecend; ++itEditor)
|
||||||
if (itEditor.key() == object) {
|
if (itEditor.key() == object) {
|
||||||
QtProperty *property = itEditor.value();
|
QtProperty *property = itEditor.value();
|
||||||
QtEnumPropertyManager *manager = q_ptr->propertyManager(property);
|
QtEnumPropertyManager *manager = q_ptr->propertyManager(property);
|
||||||
|
@ -2022,18 +2117,19 @@ void QtEnumEditorFactory::connectPropertyManager(QtEnumPropertyManager *manager)
|
||||||
QWidget *QtEnumEditorFactory::createEditor(QtEnumPropertyManager *manager, QtProperty *property,
|
QWidget *QtEnumEditorFactory::createEditor(QtEnumPropertyManager *manager, QtProperty *property,
|
||||||
QWidget *parent)
|
QWidget *parent)
|
||||||
{
|
{
|
||||||
QComboBox *editor = d_ptr->createEditor(property, parent);
|
QtEnumEditWidget *editor = d_ptr->createEditor(property, parent);
|
||||||
editor->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed);
|
editor->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed);
|
||||||
editor->view()->setTextElideMode(Qt::ElideRight);
|
|
||||||
QStringList enumNames = manager->enumNames(property);
|
QStringList enumNames = manager->enumNames(property);
|
||||||
editor->addItems(enumNames);
|
editor->addItems(enumNames);
|
||||||
QMap<int, QIcon> enumIcons = manager->enumIcons(property);
|
QMap<int, QIcon> enumIcons = manager->enumIcons(property);
|
||||||
const int enumNamesCount = enumNames.count();
|
const int enumNamesCount = enumNames.count();
|
||||||
for (int i = 0; i < enumNamesCount; i++)
|
for (int i = 0; i < enumNamesCount; i++)
|
||||||
editor->setItemIcon(i, enumIcons.value(i));
|
editor->setItemIcon(i, enumIcons.value(i));
|
||||||
editor->setCurrentIndex(manager->value(property));
|
editor->setValue(manager->value(property));
|
||||||
|
editor->setStateResetButton(property->isModified());
|
||||||
|
|
||||||
connect(editor, SIGNAL(currentIndexChanged(int)), this, SLOT(slotSetValue(int)));
|
connect(editor, SIGNAL(resetProperty()), this, SLOT(slotResetProperty()));
|
||||||
|
connect(editor, SIGNAL(valueChanged(int)), this, SLOT(slotSetValue(int)));
|
||||||
connect(editor, SIGNAL(destroyed(QObject *)),
|
connect(editor, SIGNAL(destroyed(QObject *)),
|
||||||
this, SLOT(slotEditorDestroyed(QObject *)));
|
this, SLOT(slotEditorDestroyed(QObject *)));
|
||||||
return editor;
|
return editor;
|
||||||
|
|
|
@ -186,7 +186,7 @@ private:
|
||||||
Q_PRIVATE_SLOT(d_func(), void slotPropertyChanged(QtProperty *, bool))
|
Q_PRIVATE_SLOT(d_func(), void slotPropertyChanged(QtProperty *, bool))
|
||||||
Q_PRIVATE_SLOT(d_func(), void slotSetValue(bool))
|
Q_PRIVATE_SLOT(d_func(), void slotSetValue(bool))
|
||||||
Q_PRIVATE_SLOT(d_func(), void slotEditorDestroyed(QObject *))
|
Q_PRIVATE_SLOT(d_func(), void slotEditorDestroyed(QObject *))
|
||||||
Q_PRIVATE_SLOT(d_func(), void slotReset())
|
Q_PRIVATE_SLOT(d_func(), void slotResetProperty())
|
||||||
};
|
};
|
||||||
|
|
||||||
class QtDoubleSpinBoxFactoryPrivate;
|
class QtDoubleSpinBoxFactoryPrivate;
|
||||||
|
@ -374,6 +374,7 @@ private:
|
||||||
const QMap<int, QIcon> &))
|
const QMap<int, QIcon> &))
|
||||||
Q_PRIVATE_SLOT(d_func(), void slotSetValue(int))
|
Q_PRIVATE_SLOT(d_func(), void slotSetValue(int))
|
||||||
Q_PRIVATE_SLOT(d_func(), void slotEditorDestroyed(QObject *))
|
Q_PRIVATE_SLOT(d_func(), void slotEditorDestroyed(QObject *))
|
||||||
|
Q_PRIVATE_SLOT(d_func(), void slotResetProperty())
|
||||||
};
|
};
|
||||||
|
|
||||||
class QtCursorEditorFactoryPrivate;
|
class QtCursorEditorFactoryPrivate;
|
||||||
|
|
Loading…
Reference in a new issue