summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnton Malov <malov.anton@gmail.com>2012-07-18 20:01:27 +0400
committerJarek Kobus <jaroslaw.kobus@digia.com>2013-01-18 14:46:47 +0100
commiteec6ad941af331d180a1f4eb77389faf17020649 (patch)
tree459d42891c7acf957c6d7ed283bfb916a119b5ac
parent4f22802c0d507985f3862942d70dea0f4ead97d1 (diff)
Read-only mode for string, double and integer properties
Added functionality to set read-only mode for string, double and integer properties using QLineEdit, QDoubleSpinBox and QSpinBox editors respectively). Read-only status can also be set using attributes of variant properties. Support for integer properties implemented by Vincent Wang https://gitorious.org/~linsong Change-Id: I0946cc44e2c5452e256f7c099427cae13cbb5264 Reviewed-by: Jarek Kobus <jaroslaw.kobus@digia.com>
-rw-r--r--qtpropertybrowser/examples/simple/main.cpp21
-rw-r--r--qtpropertybrowser/src/qteditorfactory.cpp73
-rw-r--r--qtpropertybrowser/src/qteditorfactory.h3
-rw-r--r--qtpropertybrowser/src/qtpropertymanager.cpp116
-rw-r--r--qtpropertybrowser/src/qtpropertymanager.h11
-rw-r--r--qtpropertybrowser/src/qtvariantproperty.cpp32
-rw-r--r--qtpropertybrowser/src/qtvariantproperty.h2
7 files changed, 253 insertions, 5 deletions
diff --git a/qtpropertybrowser/examples/simple/main.cpp b/qtpropertybrowser/examples/simple/main.cpp
index 0bc7810..06ae31f 100644
--- a/qtpropertybrowser/examples/simple/main.cpp
+++ b/qtpropertybrowser/examples/simple/main.cpp
@@ -66,12 +66,27 @@ int main(int argc, char **argv)
item->setAttribute(QLatin1String("singleStep"), 10);
topItem->addSubProperty(item);
+ item = variantManager->addProperty(QVariant::Int, QString::number(i++) + QLatin1String(" Int Property (ReadOnly)"));
+ item->setValue(20);
+ item->setAttribute(QLatin1String("minimum"), 0);
+ item->setAttribute(QLatin1String("maximum"), 100);
+ item->setAttribute(QLatin1String("singleStep"), 10);
+ item->setAttribute(QLatin1String("readOnly"), true);
+ topItem->addSubProperty(item);
+
item = variantManager->addProperty(QVariant::Double, QString::number(i++) + QLatin1String(" Double Property"));
item->setValue(1.2345);
item->setAttribute(QLatin1String("singleStep"), 0.1);
item->setAttribute(QLatin1String("decimals"), 3);
topItem->addSubProperty(item);
+ item = variantManager->addProperty(QVariant::Double, QString::number(i++) + QLatin1String(" Double Property (ReadOnly)"));
+ item->setValue(1.23456);
+ item->setAttribute(QLatin1String("singleStep"), 0.1);
+ item->setAttribute(QLatin1String("decimals"), 5);
+ item->setAttribute(QLatin1String("readOnly"), true);
+ topItem->addSubProperty(item);
+
item = variantManager->addProperty(QVariant::String, QString::number(i++) + QLatin1String(" String Property"));
item->setValue("Value");
topItem->addSubProperty(item);
@@ -81,6 +96,12 @@ int main(int argc, char **argv)
item->setValue("Password");
topItem->addSubProperty(item);
+ // Readonly String Property
+ item = variantManager->addProperty(QVariant::String, QString::number(i++) + QLatin1String(" String Property (ReadOnly)"));
+ item->setAttribute(QLatin1String("readOnly"), true);
+ item->setValue("readonly text");
+ topItem->addSubProperty(item);
+
item = variantManager->addProperty(QVariant::Date, QString::number(i++) + QLatin1String(" Date Property"));
item->setValue(QDate::currentDate().addDays(2));
topItem->addSubProperty(item);
diff --git a/qtpropertybrowser/src/qteditorfactory.cpp b/qtpropertybrowser/src/qteditorfactory.cpp
index 2611461..5cb4a37 100644
--- a/qtpropertybrowser/src/qteditorfactory.cpp
+++ b/qtpropertybrowser/src/qteditorfactory.cpp
@@ -149,6 +149,7 @@ public:
void slotPropertyChanged(QtProperty *property, int value);
void slotRangeChanged(QtProperty *property, int min, int max);
void slotSingleStepChanged(QtProperty *property, int step);
+ void slotReadOnlyChanged(QtProperty *property, bool readOnly);
void slotSetValue(int value);
};
@@ -199,6 +200,24 @@ void QtSpinBoxFactoryPrivate::slotSingleStepChanged(QtProperty *property, int st
}
}
+void QtSpinBoxFactoryPrivate::slotReadOnlyChanged( QtProperty *property, bool readOnly)
+{
+ if (!m_createdEditors.contains(property))
+ return;
+
+ QtIntPropertyManager *manager = q_ptr->propertyManager(property);
+ if (!manager)
+ return;
+
+ QListIterator<QSpinBox *> itEditor(m_createdEditors[property]);
+ while (itEditor.hasNext()) {
+ QSpinBox *editor = itEditor.next();
+ editor->blockSignals(true);
+ editor->setReadOnly(readOnly);
+ editor->blockSignals(false);
+ }
+}
+
void QtSpinBoxFactoryPrivate::slotSetValue(int value)
{
QObject *object = q_ptr->sender();
@@ -257,6 +276,8 @@ void QtSpinBoxFactory::connectPropertyManager(QtIntPropertyManager *manager)
this, SLOT(slotRangeChanged(QtProperty *, int, int)));
connect(manager, SIGNAL(singleStepChanged(QtProperty *, int)),
this, SLOT(slotSingleStepChanged(QtProperty *, int)));
+ connect(manager, SIGNAL(readOnlyChanged(QtProperty *, bool)),
+ this, SLOT(slotReadOnlyChanged(QtProperty *, bool)));
}
/*!
@@ -272,6 +293,7 @@ QWidget *QtSpinBoxFactory::createEditor(QtIntPropertyManager *manager, QtPropert
editor->setRange(manager->minimum(property), manager->maximum(property));
editor->setValue(manager->value(property));
editor->setKeyboardTracking(false);
+ editor->setReadOnly(manager->isReadOnly(property));
connect(editor, SIGNAL(valueChanged(int)), this, SLOT(slotSetValue(int)));
connect(editor, SIGNAL(destroyed(QObject *)),
@@ -292,6 +314,8 @@ void QtSpinBoxFactory::disconnectPropertyManager(QtIntPropertyManager *manager)
this, SLOT(slotRangeChanged(QtProperty *, int, int)));
disconnect(manager, SIGNAL(singleStepChanged(QtProperty *, int)),
this, SLOT(slotSingleStepChanged(QtProperty *, int)));
+ disconnect(manager, SIGNAL(readOnlyChanged(QtProperty *, bool)),
+ this, SLOT(slotReadOnlyChanged(QtProperty *, bool)));
}
// QtSliderFactory
@@ -720,6 +744,7 @@ public:
void slotRangeChanged(QtProperty *property, double min, double max);
void slotSingleStepChanged(QtProperty *property, double step);
void slotDecimalsChanged(QtProperty *property, int prec);
+ void slotReadOnlyChanged(QtProperty *property, bool readOnly);
void slotSetValue(double value);
};
@@ -777,6 +802,24 @@ void QtDoubleSpinBoxFactoryPrivate::slotSingleStepChanged(QtProperty *property,
}
}
+void QtDoubleSpinBoxFactoryPrivate::slotReadOnlyChanged( QtProperty *property, bool readOnly)
+{
+ if (!m_createdEditors.contains(property))
+ return;
+
+ QtDoublePropertyManager *manager = q_ptr->propertyManager(property);
+ if (!manager)
+ return;
+
+ QListIterator<QDoubleSpinBox *> itEditor(m_createdEditors[property]);
+ while (itEditor.hasNext()) {
+ QDoubleSpinBox *editor = itEditor.next();
+ editor->blockSignals(true);
+ editor->setReadOnly(readOnly);
+ editor->blockSignals(false);
+ }
+}
+
void QtDoubleSpinBoxFactoryPrivate::slotDecimalsChanged(QtProperty *property, int prec)
{
if (!m_createdEditors.contains(property))
@@ -856,6 +899,8 @@ void QtDoubleSpinBoxFactory::connectPropertyManager(QtDoublePropertyManager *man
this, SLOT(slotSingleStepChanged(QtProperty *, double)));
connect(manager, SIGNAL(decimalsChanged(QtProperty *, int)),
this, SLOT(slotDecimalsChanged(QtProperty *, int)));
+ connect(manager, SIGNAL(readOnlyChanged(QtProperty *, bool)),
+ this, SLOT(slotReadOnlyChanged(QtProperty *, bool)));
}
/*!
@@ -872,6 +917,7 @@ QWidget *QtDoubleSpinBoxFactory::createEditor(QtDoublePropertyManager *manager,
editor->setRange(manager->minimum(property), manager->maximum(property));
editor->setValue(manager->value(property));
editor->setKeyboardTracking(false);
+ editor->setReadOnly(manager->isReadOnly(property));
connect(editor, SIGNAL(valueChanged(double)), this, SLOT(slotSetValue(double)));
connect(editor, SIGNAL(destroyed(QObject *)),
@@ -894,6 +940,8 @@ void QtDoubleSpinBoxFactory::disconnectPropertyManager(QtDoublePropertyManager *
this, SLOT(slotSingleStepChanged(QtProperty *, double)));
disconnect(manager, SIGNAL(decimalsChanged(QtProperty *, int)),
this, SLOT(slotDecimalsChanged(QtProperty *, int)));
+ disconnect(manager, SIGNAL(readOnlyChanged(QtProperty *, bool)),
+ this, SLOT(slotReadOnlyChanged(QtProperty *, bool)));
}
// QtLineEditFactory
@@ -908,6 +956,7 @@ public:
void slotRegExpChanged(QtProperty *property, const QRegExp &regExp);
void slotSetValue(const QString &value);
void slotEchoModeChanged(QtProperty *, int);
+ void slotReadOnlyChanged(QtProperty *, bool);
};
void QtLineEditFactoryPrivate::slotPropertyChanged(QtProperty *property,
@@ -966,8 +1015,24 @@ void QtLineEditFactoryPrivate::slotEchoModeChanged(QtProperty *property, int ech
editor->setEchoMode((EchoMode)echoMode);
editor->blockSignals(false);
}
+}
+
+void QtLineEditFactoryPrivate::slotReadOnlyChanged( QtProperty *property, bool readOnly)
+{
+ if (!m_createdEditors.contains(property))
+ return;
+ QtStringPropertyManager *manager = q_ptr->propertyManager(property);
+ if (!manager)
+ return;
+ QListIterator<QLineEdit *> itEditor(m_createdEditors[property]);
+ while (itEditor.hasNext()) {
+ QLineEdit *editor = itEditor.next();
+ editor->blockSignals(true);
+ editor->setReadOnly(readOnly);
+ editor->blockSignals(false);
+ }
}
void QtLineEditFactoryPrivate::slotSetValue(const QString &value)
@@ -985,6 +1050,8 @@ void QtLineEditFactoryPrivate::slotSetValue(const QString &value)
}
}
+
+
/*!
\class QtLineEditFactory
@@ -1027,6 +1094,8 @@ void QtLineEditFactory::connectPropertyManager(QtStringPropertyManager *manager)
this, SLOT(slotRegExpChanged(QtProperty *, const QRegExp &)));
connect(manager, SIGNAL(echoModeChanged(QtProperty*, int)),
this, SLOT(slotEchoModeChanged(QtProperty *, int)));
+ connect(manager, SIGNAL(readOnlyChanged(QtProperty*, bool)),
+ this, SLOT(slotReadOnlyChanged(QtProperty *, bool)));
}
/*!
@@ -1040,6 +1109,7 @@ QWidget *QtLineEditFactory::createEditor(QtStringPropertyManager *manager,
QLineEdit *editor = d_ptr->createEditor(property, parent);
editor->setEchoMode((EchoMode)manager->echoMode(property));
+ editor->setReadOnly(manager->isReadOnly(property));
QRegExp regExp = manager->regExp(property);
if (regExp.isValid()) {
QValidator *validator = new QRegExpValidator(regExp, editor);
@@ -1067,6 +1137,9 @@ void QtLineEditFactory::disconnectPropertyManager(QtStringPropertyManager *manag
this, SLOT(slotRegExpChanged(QtProperty *, const QRegExp &)));
disconnect(manager, SIGNAL(echoModeChanged(QtProperty*,int)),
this, SLOT(slotEchoModeChanged(QtProperty *, int)));
+ disconnect(manager, SIGNAL(readOnlyChanged(QtProperty*, bool)),
+ this, SLOT(slotReadOnlyChanged(QtProperty *, bool)));
+
}
// QtDateEditFactory
diff --git a/qtpropertybrowser/src/qteditorfactory.h b/qtpropertybrowser/src/qteditorfactory.h
index 2894997..37204ce 100644
--- a/qtpropertybrowser/src/qteditorfactory.h
+++ b/qtpropertybrowser/src/qteditorfactory.h
@@ -68,6 +68,7 @@ private:
Q_PRIVATE_SLOT(d_func(), void slotPropertyChanged(QtProperty *, int))
Q_PRIVATE_SLOT(d_func(), void slotRangeChanged(QtProperty *, int, int))
Q_PRIVATE_SLOT(d_func(), void slotSingleStepChanged(QtProperty *, int))
+ Q_PRIVATE_SLOT(d_func(), void slotReadOnlyChanged(QtProperty *, bool))
Q_PRIVATE_SLOT(d_func(), void slotSetValue(int))
Q_PRIVATE_SLOT(d_func(), void slotEditorDestroyed(QObject *))
};
@@ -163,6 +164,7 @@ private:
Q_PRIVATE_SLOT(d_func(), void slotRangeChanged(QtProperty *, double, double))
Q_PRIVATE_SLOT(d_func(), void slotSingleStepChanged(QtProperty *, double))
Q_PRIVATE_SLOT(d_func(), void slotDecimalsChanged(QtProperty *, int))
+ Q_PRIVATE_SLOT(d_func(), void slotReadOnlyChanged(QtProperty *, bool))
Q_PRIVATE_SLOT(d_func(), void slotSetValue(double))
Q_PRIVATE_SLOT(d_func(), void slotEditorDestroyed(QObject *))
};
@@ -187,6 +189,7 @@ private:
Q_PRIVATE_SLOT(d_func(), void slotPropertyChanged(QtProperty *, const QString &))
Q_PRIVATE_SLOT(d_func(), void slotRegExpChanged(QtProperty *, const QRegExp &))
Q_PRIVATE_SLOT(d_func(), void slotEchoModeChanged(QtProperty *, int))
+ Q_PRIVATE_SLOT(d_func(), void slotReadOnlyChanged(QtProperty *, bool))
Q_PRIVATE_SLOT(d_func(), void slotSetValue(const QString &))
Q_PRIVATE_SLOT(d_func(), void slotEditorDestroyed(QObject *))
};
diff --git a/qtpropertybrowser/src/qtpropertymanager.cpp b/qtpropertybrowser/src/qtpropertymanager.cpp
index c9ecdc3..cfc54ef 100644
--- a/qtpropertybrowser/src/qtpropertymanager.cpp
+++ b/qtpropertybrowser/src/qtpropertymanager.cpp
@@ -625,11 +625,12 @@ public:
struct Data
{
- Data() : val(0), minVal(-INT_MAX), maxVal(INT_MAX), singleStep(1) {}
+ Data() : val(0), minVal(-INT_MAX), maxVal(INT_MAX), singleStep(1), readOnly(false) {}
int val;
int minVal;
int maxVal;
int singleStep;
+ bool readOnly;
int minimumValue() const { return minVal; }
int maximumValue() const { return maxVal; }
void setMinimumValue(int newMinVal) { setSimpleMinimumData(this, newMinVal); }
@@ -757,6 +758,18 @@ int QtIntPropertyManager::singleStep(const QtProperty *property) const
}
/*!
+ Returns read-only status of the property.
+
+ When property is read-only it's value can be selected and copied from editor but not modified.
+
+ \sa QtIntPropertyManager::setReadOnly
+*/
+bool QtIntPropertyManager::isReadOnly(const QtProperty *property) const
+{
+ return getData<bool>(d_ptr->m_values, &QtIntPropertyManagerPrivate::Data::readOnly, property, false);
+}
+
+/*!
\reimp
*/
QString QtIntPropertyManager::valueText(const QtProperty *property) const
@@ -876,6 +889,29 @@ void QtIntPropertyManager::setSingleStep(QtProperty *property, int step)
}
/*!
+ Sets read-only status of the property.
+
+ \sa QtIntPropertyManager::setReadOnly
+*/
+void QtIntPropertyManager::setReadOnly(QtProperty *property, bool readOnly)
+{
+ const QtIntPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
+ if (it == d_ptr->m_values.end())
+ return;
+
+ QtIntPropertyManagerPrivate::Data data = it.value();
+
+ if (data.readOnly == readOnly)
+ return;
+
+ data.readOnly = readOnly;
+ it.value() = data;
+
+ emit propertyChanged(property);
+ emit readOnlyChanged(property, data.readOnly);
+}
+
+/*!
\reimp
*/
void QtIntPropertyManager::initializeProperty(QtProperty *property)
@@ -901,12 +937,13 @@ public:
struct Data
{
- Data() : val(0), minVal(-INT_MAX), maxVal(INT_MAX), singleStep(1), decimals(2) {}
+ Data() : val(0), minVal(-INT_MAX), maxVal(INT_MAX), singleStep(1), decimals(2), readOnly(false) {}
double val;
double minVal;
double maxVal;
double singleStep;
int decimals;
+ bool readOnly;
double minimumValue() const { return minVal; }
double maximumValue() const { return maxVal; }
void setMinimumValue(double newMinVal) { setSimpleMinimumData(this, newMinVal); }
@@ -1055,6 +1092,18 @@ int QtDoublePropertyManager::decimals(const QtProperty *property) const
}
/*!
+ Returns read-only status of the property.
+
+ When property is read-only it's value can be selected and copied from editor but not modified.
+
+ \sa QtDoublePropertyManager::setReadOnly
+*/
+bool QtDoublePropertyManager::isReadOnly(const QtProperty *property) const
+{
+ return getData<bool>(d_ptr->m_values, &QtDoublePropertyManagerPrivate::Data::readOnly, property, false);
+}
+
+/*!
\reimp
*/
QString QtDoublePropertyManager::valueText(const QtProperty *property) const
@@ -1114,6 +1163,29 @@ void QtDoublePropertyManager::setSingleStep(QtProperty *property, double step)
}
/*!
+ Sets read-only status of the property.
+
+ \sa QtDoublePropertyManager::setReadOnly
+*/
+void QtDoublePropertyManager::setReadOnly(QtProperty *property, bool readOnly)
+{
+ const QtDoublePropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
+ if (it == d_ptr->m_values.end())
+ return;
+
+ QtDoublePropertyManagerPrivate::Data data = it.value();
+
+ if (data.readOnly == readOnly)
+ return;
+
+ data.readOnly = readOnly;
+ it.value() = data;
+
+ emit propertyChanged(property);
+ emit readOnlyChanged(property, data.readOnly);
+}
+
+/*!
\fn void QtDoublePropertyManager::setDecimals(QtProperty *property, int prec)
Sets the precision of the given \a property to \a prec.
@@ -1231,12 +1303,14 @@ public:
struct Data
{
- Data() : regExp(QString(QLatin1Char('*')), Qt::CaseSensitive, QRegExp::Wildcard), echoMode(QLineEdit::Normal)
+ Data() : regExp(QString(QLatin1Char('*')), Qt::CaseSensitive, QRegExp::Wildcard),
+ echoMode(QLineEdit::Normal), readOnly(false)
{
}
QString val;
QRegExp regExp;
int echoMode;
+ bool readOnly;
};
typedef QMap<const QtProperty *, Data> PropertyValueMap;
@@ -1337,6 +1411,18 @@ EchoMode QtStringPropertyManager::echoMode(const QtProperty *property) const
}
/*!
+ Returns read-only status of the property.
+
+ When property is read-only it's value can be selected and copied from editor but not modified.
+
+ \sa QtStringPropertyManager::setReadOnly
+*/
+bool QtStringPropertyManager::isReadOnly(const QtProperty *property) const
+{
+ return getData<bool>(d_ptr->m_values, &QtStringPropertyManagerPrivate::Data::readOnly, property, false);
+}
+
+/*!
\reimp
*/
QString QtStringPropertyManager::valueText(const QtProperty *property) const
@@ -1418,6 +1504,7 @@ void QtStringPropertyManager::setRegExp(QtProperty *property, const QRegExp &reg
emit regExpChanged(property, data.regExp);
}
+
void QtStringPropertyManager::setEchoMode(QtProperty *property, EchoMode echoMode)
{
const QtStringPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
@@ -1437,6 +1524,29 @@ void QtStringPropertyManager::setEchoMode(QtProperty *property, EchoMode echoMod
}
/*!
+ Sets read-only status of the property.
+
+ \sa QtStringPropertyManager::setReadOnly
+*/
+void QtStringPropertyManager::setReadOnly(QtProperty *property, bool readOnly)
+{
+ const QtStringPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
+ if (it == d_ptr->m_values.end())
+ return;
+
+ QtStringPropertyManagerPrivate::Data data = it.value();
+
+ if (data.readOnly == readOnly)
+ return;
+
+ data.readOnly = readOnly;
+ it.value() = data;
+
+ emit propertyChanged(property);
+ emit echoModeChanged(property, data.echoMode);
+}
+
+/*!
\reimp
*/
void QtStringPropertyManager::initializeProperty(QtProperty *property)
diff --git a/qtpropertybrowser/src/qtpropertymanager.h b/qtpropertybrowser/src/qtpropertymanager.h
index 6cfc4e4..6eff26e 100644
--- a/qtpropertybrowser/src/qtpropertymanager.h
+++ b/qtpropertybrowser/src/qtpropertymanager.h
@@ -81,6 +81,7 @@ public:
int minimum(const QtProperty *property) const;
int maximum(const QtProperty *property) const;
int singleStep(const QtProperty *property) const;
+ bool isReadOnly(const QtProperty *property) const;
public Q_SLOTS:
void setValue(QtProperty *property, int val);
@@ -88,10 +89,12 @@ public Q_SLOTS:
void setMaximum(QtProperty *property, int maxVal);
void setRange(QtProperty *property, int minVal, int maxVal);
void setSingleStep(QtProperty *property, int step);
+ void setReadOnly(QtProperty *property, bool readOnly);
Q_SIGNALS:
void valueChanged(QtProperty *property, int val);
void rangeChanged(QtProperty *property, int minVal, int maxVal);
void singleStepChanged(QtProperty *property, int step);
+ void readOnlyChanged(QtProperty *property, bool readOnly);
protected:
QString valueText(const QtProperty *property) const;
virtual void initializeProperty(QtProperty *property);
@@ -142,6 +145,7 @@ public:
double maximum(const QtProperty *property) const;
double singleStep(const QtProperty *property) const;
int decimals(const QtProperty *property) const;
+ bool isReadOnly(const QtProperty *property) const;
public Q_SLOTS:
void setValue(QtProperty *property, double val);
@@ -150,11 +154,13 @@ public Q_SLOTS:
void setRange(QtProperty *property, double minVal, double maxVal);
void setSingleStep(QtProperty *property, double step);
void setDecimals(QtProperty *property, int prec);
+ void setReadOnly(QtProperty *property, bool readOnly);
Q_SIGNALS:
void valueChanged(QtProperty *property, double val);
void rangeChanged(QtProperty *property, double minVal, double maxVal);
void singleStepChanged(QtProperty *property, double step);
void decimalsChanged(QtProperty *property, int prec);
+ void readOnlyChanged(QtProperty *property, bool readOnly);
protected:
QString valueText(const QtProperty *property) const;
virtual void initializeProperty(QtProperty *property);
@@ -177,15 +183,20 @@ public:
QString value(const QtProperty *property) const;
QRegExp regExp(const QtProperty *property) const;
EchoMode echoMode(const QtProperty *property) const;
+ bool isReadOnly(const QtProperty *property) const;
public Q_SLOTS:
void setValue(QtProperty *property, const QString &val);
void setRegExp(QtProperty *property, const QRegExp &regExp);
void setEchoMode(QtProperty *property, EchoMode echoMode);
+ void setReadOnly(QtProperty *property, bool readOnly);
+
Q_SIGNALS:
void valueChanged(QtProperty *property, const QString &val);
void regExpChanged(QtProperty *property, const QRegExp &regExp);
void echoModeChanged(QtProperty *property, const int);
+ void readOnlyChanged(QtProperty *property, bool);
+
protected:
QString valueText(const QtProperty *property) const;
QString displayText(const QtProperty *property) const;
diff --git a/qtpropertybrowser/src/qtvariantproperty.cpp b/qtpropertybrowser/src/qtvariantproperty.cpp
index 1dd291d..275ae16 100644
--- a/qtpropertybrowser/src/qtvariantproperty.cpp
+++ b/qtpropertybrowser/src/qtvariantproperty.cpp
@@ -343,6 +343,7 @@ public:
void slotValueChanged(QtProperty *property, const QCursor &val);
void slotFlagChanged(QtProperty *property, int val);
void slotFlagNamesChanged(QtProperty *property, const QStringList &flagNames);
+ void slotReadOnlyChanged(QtProperty *property, bool readOnly);
void slotPropertyInserted(QtProperty *property, QtProperty *parent, QtProperty *after);
void slotPropertyRemoved(QtProperty *property, QtProperty *parent);
@@ -373,6 +374,7 @@ public:
const QString m_minimumAttribute;
const QString m_regExpAttribute;
const QString m_echoModeAttribute;
+ const QString m_readOnlyAttribute;
};
QtVariantPropertyManagerPrivate::QtVariantPropertyManagerPrivate() :
@@ -385,7 +387,8 @@ QtVariantPropertyManagerPrivate::QtVariantPropertyManagerPrivate() :
m_maximumAttribute(QLatin1String("maximum")),
m_minimumAttribute(QLatin1String("minimum")),
m_regExpAttribute(QLatin1String("regExp")),
- m_echoModeAttribute(QLatin1String("echoMode"))
+ m_echoModeAttribute(QLatin1String("echoMode")),
+ m_readOnlyAttribute(QLatin1String("readOnly"))
{
}
@@ -547,6 +550,12 @@ void QtVariantPropertyManagerPrivate::slotEchoModeChanged(QtProperty *property,
emit q_ptr->attributeChanged(varProp, m_echoModeAttribute, QVariant(mode));
}
+void QtVariantPropertyManagerPrivate::slotReadOnlyChanged(QtProperty *property, bool readOnly)
+{
+ if (QtVariantProperty *varProp = m_internalToProperty.value(property, 0))
+ emit q_ptr->attributeChanged(varProp, m_readOnlyAttribute, QVariant(readOnly));
+}
+
void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QDate &val)
{
valueChanged(property, QVariant(val));
@@ -947,6 +956,7 @@ QtVariantPropertyManager::QtVariantPropertyManager(QObject *parent)
d_ptr->m_typeToAttributeToAttributeType[QVariant::Int][d_ptr->m_minimumAttribute] = QVariant::Int;
d_ptr->m_typeToAttributeToAttributeType[QVariant::Int][d_ptr->m_maximumAttribute] = QVariant::Int;
d_ptr->m_typeToAttributeToAttributeType[QVariant::Int][d_ptr->m_singleStepAttribute] = QVariant::Int;
+ d_ptr->m_typeToAttributeToAttributeType[QVariant::Int][d_ptr->m_readOnlyAttribute] = QVariant::Bool;
d_ptr->m_typeToValueType[QVariant::Int] = QVariant::Int;
connect(intPropertyManager, SIGNAL(valueChanged(QtProperty *, int)),
this, SLOT(slotValueChanged(QtProperty *, int)));
@@ -965,6 +975,8 @@ QtVariantPropertyManager::QtVariantPropertyManager(QObject *parent)
QVariant::Double;
d_ptr->m_typeToAttributeToAttributeType[QVariant::Double][d_ptr->m_decimalsAttribute] =
QVariant::Int;
+ d_ptr->m_typeToAttributeToAttributeType[QVariant::Double][d_ptr->m_readOnlyAttribute] =
+ QVariant::Bool;
d_ptr->m_typeToValueType[QVariant::Double] = QVariant::Double;
connect(doublePropertyManager, SIGNAL(valueChanged(QtProperty *, double)),
this, SLOT(slotValueChanged(QtProperty *, double)));
@@ -988,12 +1000,18 @@ QtVariantPropertyManager::QtVariantPropertyManager(QObject *parent)
QVariant::RegExp;
d_ptr->m_typeToAttributeToAttributeType[QVariant::String][d_ptr->m_echoModeAttribute] =
QVariant::Int;
+ d_ptr->m_typeToAttributeToAttributeType[QVariant::String][d_ptr->m_readOnlyAttribute] =
+ QVariant::Bool;
+
connect(stringPropertyManager, SIGNAL(valueChanged(QtProperty *, const QString &)),
this, SLOT(slotValueChanged(QtProperty *, const QString &)));
connect(stringPropertyManager, SIGNAL(regExpChanged(QtProperty *, const QRegExp &)),
this, SLOT(slotRegExpChanged(QtProperty *, const QRegExp &)));
connect(stringPropertyManager, SIGNAL(echoModeChanged(QtProperty*,int)),
this, SLOT(slotEchoModeChanged(QtProperty*, int)));
+ connect(stringPropertyManager, SIGNAL(readOnlyChanged(QtProperty*, bool)),
+ this, SLOT(slotReadOnlyChanged(QtProperty*, bool)));
+
// DatePropertyManager
QtDatePropertyManager *datePropertyManager = new QtDatePropertyManager(this);
d_ptr->m_typeToPropertyManager[QVariant::Date] = datePropertyManager;
@@ -1465,6 +1483,8 @@ QVariant QtVariantPropertyManager::attributeValue(const QtProperty *property, co
return intManager->minimum(internProp);
if (attribute == d_ptr->m_singleStepAttribute)
return intManager->singleStep(internProp);
+ if (attribute == d_ptr->m_readOnlyAttribute)
+ return intManager->isReadOnly(internProp);
return QVariant();
} else if (QtDoublePropertyManager *doubleManager = qobject_cast<QtDoublePropertyManager *>(manager)) {
if (attribute == d_ptr->m_maximumAttribute)
@@ -1475,12 +1495,16 @@ QVariant QtVariantPropertyManager::attributeValue(const QtProperty *property, co
return doubleManager->singleStep(internProp);
if (attribute == d_ptr->m_decimalsAttribute)
return doubleManager->decimals(internProp);
+ if (attribute == d_ptr->m_readOnlyAttribute)
+ return doubleManager->isReadOnly(internProp);
return QVariant();
} else if (QtStringPropertyManager *stringManager = qobject_cast<QtStringPropertyManager *>(manager)) {
if (attribute == d_ptr->m_regExpAttribute)
return stringManager->regExp(internProp);
if (attribute == d_ptr->m_echoModeAttribute)
return stringManager->echoMode(internProp);
+ if (attribute == d_ptr->m_readOnlyAttribute)
+ return stringManager->isReadOnly(internProp);
return QVariant();
} else if (QtDatePropertyManager *dateManager = qobject_cast<QtDatePropertyManager *>(manager)) {
if (attribute == d_ptr->m_maximumAttribute)
@@ -1710,6 +1734,8 @@ void QtVariantPropertyManager::setAttribute(QtProperty *property,
intManager->setMinimum(internProp, qVariantValue<int>(value));
else if (attribute == d_ptr->m_singleStepAttribute)
intManager->setSingleStep(internProp, qVariantValue<int>(value));
+ else if (attribute == d_ptr->m_readOnlyAttribute)
+ intManager->setReadOnly(internProp, qVariantValue<bool>(value));
return;
} else if (QtDoublePropertyManager *doubleManager = qobject_cast<QtDoublePropertyManager *>(manager)) {
if (attribute == d_ptr->m_maximumAttribute)
@@ -1720,12 +1746,16 @@ void QtVariantPropertyManager::setAttribute(QtProperty *property,
doubleManager->setSingleStep(internProp, qVariantValue<double>(value));
if (attribute == d_ptr->m_decimalsAttribute)
doubleManager->setDecimals(internProp, qVariantValue<int>(value));
+ if (attribute == d_ptr->m_readOnlyAttribute)
+ doubleManager->setReadOnly(internProp, qVariantValue<bool>(value));
return;
} else if (QtStringPropertyManager *stringManager = qobject_cast<QtStringPropertyManager *>(manager)) {
if (attribute == d_ptr->m_regExpAttribute)
stringManager->setRegExp(internProp, qVariantValue<QRegExp>(value));
if (attribute == d_ptr->m_echoModeAttribute)
stringManager->setEchoMode(internProp, (EchoMode)qVariantValue<int>(value));
+ if (attribute == d_ptr->m_readOnlyAttribute)
+ stringManager->setReadOnly(internProp, (EchoMode)qVariantValue<bool>(value));
return;
} else if (QtDatePropertyManager *dateManager = qobject_cast<QtDatePropertyManager *>(manager)) {
if (attribute == d_ptr->m_maximumAttribute)
diff --git a/qtpropertybrowser/src/qtvariantproperty.h b/qtpropertybrowser/src/qtvariantproperty.h
index 9884c7b..41b28a6 100644
--- a/qtpropertybrowser/src/qtvariantproperty.h
+++ b/qtpropertybrowser/src/qtvariantproperty.h
@@ -152,7 +152,7 @@ private:
Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QFont &))
Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QCursor &))
Q_PRIVATE_SLOT(d_func(), void slotFlagNamesChanged(QtProperty *, const QStringList &))
-
+ Q_PRIVATE_SLOT(d_func(), void slotReadOnlyChanged(QtProperty *, bool))
Q_PRIVATE_SLOT(d_func(), void slotPropertyInserted(QtProperty *, QtProperty *, QtProperty *))
Q_PRIVATE_SLOT(d_func(), void slotPropertyRemoved(QtProperty *, QtProperty *))
Q_DECLARE_PRIVATE(QtVariantPropertyManager)