Newer
Older
If the given \a property is not managed by this manager, this
function returns an invalid rectangle.
\sa setValue(), constraint()
*/
QRect QtRectPropertyManager::value(const QtProperty *property) const {
return getValue<QRect>(d_ptr->m_values, property);
Returns the given \a property's constraining rectangle. If returned value is
null QRect it means there is no constraint applied.
QRect QtRectPropertyManager::constraint(const QtProperty *property) const {
return getData<QRect>(d_ptr->m_values,
&QtRectPropertyManagerPrivate::Data::constraint,
property, QRect());
QString QtRectPropertyManager::valueText(const QtProperty *property) const {
const QtRectPropertyManagerPrivate::PropertyValueMap::const_iterator it =
d_ptr->m_values.constFind(property);
if (it == d_ptr->m_values.constEnd())
return QString();
const QRect v = it.value().val;
return QString(tr("[(%1, %2), %3 x %4]")
.arg(QString::number(v.x()))
.arg(QString::number(v.y()))
.arg(QString::number(v.width()))
.arg(QString::number(v.height())));
\fn void QtRectPropertyManager::setValue(QtProperty *property, const QRect
&value)
Sets the value of the given \a property to \a value. Nested
properties are updated automatically.
If the specified \a value is not inside the given \a property's
constraining rectangle, the value is adjusted accordingly to fit
within the constraint.
\sa value(), setConstraint(), valueChanged()
*/
void QtRectPropertyManager::setValue(QtProperty *property, const QRect &val) {
const QtRectPropertyManagerPrivate::PropertyValueMap::iterator it =
d_ptr->m_values.find(property);
if (it == d_ptr->m_values.end())
return;
QtRectPropertyManagerPrivate::Data data = it.value();
QRect newRect = val.normalized();
if (!data.constraint.isNull() && !data.constraint.contains(newRect)) {
const QRect r1 = data.constraint;
const QRect r2 = newRect;
newRect.setLeft(qMax(r1.left(), r2.left()));
newRect.setRight(qMin(r1.right(), r2.right()));
newRect.setTop(qMax(r1.top(), r2.top()));
newRect.setBottom(qMin(r1.bottom(), r2.bottom()));
if (newRect.width() < 0 || newRect.height() < 0)
return;
}
if (data.val == newRect)
return;
it.value() = data;
d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToX[property],
newRect.x());
d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToY[property],
newRect.y());
d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToW[property],
newRect.width());
d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToH[property],
newRect.height());
emit propertyChanged(property);
emit valueChanged(property, data.val);
}
/**
Sets the given \a property's constraining rectangle to \a
constraint.
When setting the constraint, the current value is adjusted if
necessary (ensuring that the current rectangle value is inside the
constraint). In order to reset the constraint pass a null QRect value.
\sa setValue(), constraint(), constraintChanged()
*/
void QtRectPropertyManager::setConstraint(QtProperty *property,
const QRect &constraint) {
const QtRectPropertyManagerPrivate::PropertyValueMap::iterator it =
d_ptr->m_values.find(property);
if (it == d_ptr->m_values.end())
return;
QtRectPropertyManagerPrivate::Data data = it.value();
QRect newConstraint = constraint.normalized();
if (data.constraint == newConstraint)
return;
if (!data.constraint.isNull() && !data.constraint.contains(oldVal)) {
QRect r1 = data.constraint;
QRect r2 = data.val;
if (r2.width() > r1.width())
r2.setWidth(r1.width());
if (r2.height() > r1.height())
r2.setHeight(r1.height());
if (r2.left() < r1.left())
r2.moveLeft(r1.left());
else if (r2.right() > r1.right())
r2.moveRight(r1.right());
if (r2.top() < r1.top())
r2.moveTop(r1.top());
else if (r2.bottom() > r1.bottom())
r2.moveBottom(r1.bottom());
emit constraintChanged(property, data.constraint);
d_ptr->setConstraint(property, data.constraint, data.val);
if (data.val == oldVal)
return;
emit propertyChanged(property);
emit valueChanged(property, data.val);
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
void QtRectPropertyManager::initializeProperty(QtProperty *property) {
d_ptr->m_values[property] = QtRectPropertyManagerPrivate::Data();
QtProperty *xProp = d_ptr->m_intPropertyManager->addProperty();
xProp->setPropertyName(tr("X"));
d_ptr->m_intPropertyManager->setValue(xProp, 0);
d_ptr->m_propertyToX[property] = xProp;
d_ptr->m_xToProperty[xProp] = property;
property->addSubProperty(xProp);
QtProperty *yProp = d_ptr->m_intPropertyManager->addProperty();
yProp->setPropertyName(tr("Y"));
d_ptr->m_intPropertyManager->setValue(yProp, 0);
d_ptr->m_propertyToY[property] = yProp;
d_ptr->m_yToProperty[yProp] = property;
property->addSubProperty(yProp);
QtProperty *wProp = d_ptr->m_intPropertyManager->addProperty();
wProp->setPropertyName(tr("Width"));
d_ptr->m_intPropertyManager->setValue(wProp, 0);
d_ptr->m_intPropertyManager->setMinimum(wProp, 0);
d_ptr->m_propertyToW[property] = wProp;
d_ptr->m_wToProperty[wProp] = property;
property->addSubProperty(wProp);
QtProperty *hProp = d_ptr->m_intPropertyManager->addProperty();
hProp->setPropertyName(tr("Height"));
d_ptr->m_intPropertyManager->setValue(hProp, 0);
d_ptr->m_intPropertyManager->setMinimum(hProp, 0);
d_ptr->m_propertyToH[property] = hProp;
d_ptr->m_hToProperty[hProp] = property;
property->addSubProperty(hProp);
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
void QtRectPropertyManager::uninitializeProperty(QtProperty *property) {
QtProperty *xProp = d_ptr->m_propertyToX[property];
if (xProp) {
d_ptr->m_xToProperty.remove(xProp);
delete xProp;
}
d_ptr->m_propertyToX.remove(property);
QtProperty *yProp = d_ptr->m_propertyToY[property];
if (yProp) {
d_ptr->m_yToProperty.remove(yProp);
delete yProp;
}
d_ptr->m_propertyToY.remove(property);
QtProperty *wProp = d_ptr->m_propertyToW[property];
if (wProp) {
d_ptr->m_wToProperty.remove(wProp);
delete wProp;
}
d_ptr->m_propertyToW.remove(property);
QtProperty *hProp = d_ptr->m_propertyToH[property];
if (hProp) {
d_ptr->m_hToProperty.remove(hProp);
delete hProp;
}
d_ptr->m_propertyToH.remove(property);
d_ptr->m_values.remove(property);
class QtRectFPropertyManagerPrivate {
QtRectFPropertyManager *q_ptr;
Q_DECLARE_PUBLIC(QtRectFPropertyManager)
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
void slotDoubleChanged(QtProperty *property, double value);
void slotPropertyDestroyed(QtProperty *property);
void setConstraint(QtProperty *property, const QRectF &constraint,
const QRectF &val);
struct Data {
Data() : val(0, 0, 0, 0), decimals(2) {}
QRectF val;
QRectF constraint;
int decimals;
};
typedef QMap<const QtProperty *, Data> PropertyValueMap;
PropertyValueMap m_values;
QtDoublePropertyManager *m_doublePropertyManager;
QMap<const QtProperty *, QtProperty *> m_propertyToX;
QMap<const QtProperty *, QtProperty *> m_propertyToY;
QMap<const QtProperty *, QtProperty *> m_propertyToW;
QMap<const QtProperty *, QtProperty *> m_propertyToH;
QMap<const QtProperty *, QtProperty *> m_xToProperty;
QMap<const QtProperty *, QtProperty *> m_yToProperty;
QMap<const QtProperty *, QtProperty *> m_wToProperty;
QMap<const QtProperty *, QtProperty *> m_hToProperty;
void QtRectFPropertyManagerPrivate::slotDoubleChanged(QtProperty *property,
double value) {
if (QtProperty *prop = m_xToProperty.value(property, 0)) {
QRectF r = m_values[prop].val;
r.moveLeft(value);
q_ptr->setValue(prop, r);
} else if (QtProperty *prop = m_yToProperty.value(property, 0)) {
QRectF r = m_values[prop].val;
r.moveTop(value);
q_ptr->setValue(prop, r);
} else if (QtProperty *prop = m_wToProperty.value(property, 0)) {
Data data = m_values[prop];
QRectF r = data.val;
r.setWidth(value);
if (!data.constraint.isNull() &&
data.constraint.x() + data.constraint.width() < r.x() + r.width()) {
r.moveLeft(data.constraint.left() + data.constraint.width() - r.width());
q_ptr->setValue(prop, r);
} else if (QtProperty *prop = m_hToProperty.value(property, 0)) {
Data data = m_values[prop];
QRectF r = data.val;
r.setHeight(value);
if (!data.constraint.isNull() &&
data.constraint.y() + data.constraint.height() < r.y() + r.height()) {
r.moveTop(data.constraint.top() + data.constraint.height() - r.height());
q_ptr->setValue(prop, r);
}
}
void QtRectFPropertyManagerPrivate::slotPropertyDestroyed(
QtProperty *property) {
if (QtProperty *pointProp = m_xToProperty.value(property, 0)) {
m_propertyToX[pointProp] = 0;
m_xToProperty.remove(property);
} else if (QtProperty *pointProp = m_yToProperty.value(property, 0)) {
m_propertyToY[pointProp] = 0;
m_yToProperty.remove(property);
} else if (QtProperty *pointProp = m_wToProperty.value(property, 0)) {
m_propertyToW[pointProp] = 0;
m_wToProperty.remove(property);
} else if (QtProperty *pointProp = m_hToProperty.value(property, 0)) {
m_propertyToH[pointProp] = 0;
m_hToProperty.remove(property);
}
}
void QtRectFPropertyManagerPrivate::setConstraint(QtProperty *property,
const QRectF &constraint,
const QRectF &val) {
const bool isNull = constraint.isNull();
const qreal left = isNull ? FLT_MIN : constraint.left();
const qreal right = isNull ? FLT_MAX : constraint.left() + constraint.width();
const qreal top = isNull ? FLT_MIN : constraint.top();
const qreal bottom =
isNull ? FLT_MAX : constraint.top() + constraint.height();
const qreal width = isNull ? FLT_MAX : constraint.width();
const qreal height = isNull ? FLT_MAX : constraint.height();
m_doublePropertyManager->setRange(m_propertyToX[property], left, right);
m_doublePropertyManager->setRange(m_propertyToY[property], top, bottom);
m_doublePropertyManager->setRange(m_propertyToW[property], 0, width);
m_doublePropertyManager->setRange(m_propertyToH[property], 0, height);
m_doublePropertyManager->setValue(m_propertyToX[property], val.x());
m_doublePropertyManager->setValue(m_propertyToY[property], val.y());
m_doublePropertyManager->setValue(m_propertyToW[property], val.width());
m_doublePropertyManager->setValue(m_propertyToH[property], val.height());
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
}
/**
\class QtRectFPropertyManager
\brief The QtRectFPropertyManager provides and manages QRectF properties.
A rectangle property has nested \e x, \e y, \e width and \e height
subproperties. The top-level property's value can be retrieved
using the value() function, and set using the setValue() slot.
The subproperties are created by a QtDoublePropertyManager object. This
manager can be retrieved using the subDoublePropertyManager() function. In
order to provide editing widgets for the subproperties in a
property browser widget, this manager must be associated with an
editor factory.
A rectangle property also has a constraint rectangle which can be
retrieved using the constraint() function, and set using the
setConstraint() slot.
In addition, QtRectFPropertyManager provides the valueChanged() signal
which is emitted whenever a property created by this manager
changes, and the constraintChanged() signal which is emitted
whenever such a property changes its constraint rectangle.
\sa QtAbstractPropertyManager, QtDoublePropertyManager,
QtRectPropertyManager
\fn void QtRectFPropertyManager::valueChanged(QtProperty *property, const
QRectF &value)
This signal is emitted whenever a property created by this manager
changes its value, passing a pointer to the \a property and the new
\a value as parameters.
\sa setValue()
*/
/**
\fn void QtRectFPropertyManager::constraintChanged(QtProperty *property,
const QRectF &constraint)
This signal is emitted whenever property changes its constraint
rectangle, passing a pointer to the \a property and the new \a
constraint rectangle as parameters.
\sa setConstraint()
*/
/**
\fn void QtRectFPropertyManager::decimalsChanged(QtProperty *property, int
prec)
This signal is emitted whenever a property created by this manager
changes its precision of value, passing a pointer to the
\a property and the new \a prec value
\sa setDecimals()
*/
/**
Creates a manager with the given \a parent.
*/
QtRectFPropertyManager::QtRectFPropertyManager(QObject *parent)
: QtAbstractPropertyManager(parent) {
d_ptr = new QtRectFPropertyManagerPrivate;
d_ptr->q_ptr = this;
d_ptr->m_doublePropertyManager = new QtDoublePropertyManager(this);
connect(d_ptr->m_doublePropertyManager,
SIGNAL(valueChanged(QtProperty *, double)), this,
SLOT(slotDoubleChanged(QtProperty *, double)));
connect(d_ptr->m_doublePropertyManager,
SIGNAL(propertyDestroyed(QtProperty *)), this,
SLOT(slotPropertyDestroyed(QtProperty *)));
}
/**
Destroys this manager, and all the properties it has created.
*/
QtRectFPropertyManager::~QtRectFPropertyManager() {
clear();
delete d_ptr;
}
/**
Returns the manager that creates the nested \e x, \e y, \e width
and \e height subproperties.
In order to provide editing widgets for the mentioned
subproperties in a property browser widget, this manager must be
associated with an editor factory.
\sa QtAbstractPropertyBrowser::setFactoryForManager()
*/
QtDoublePropertyManager *
QtRectFPropertyManager::subDoublePropertyManager() const {
return d_ptr->m_doublePropertyManager;
}
/**
Returns the given \a property's value.
If the given \a property is not managed by this manager, this
function returns an invalid rectangle.
\sa setValue(), constraint()
*/
QRectF QtRectFPropertyManager::value(const QtProperty *property) const {
return getValue<QRectF>(d_ptr->m_values, property);
}
/**
Returns the given \a property's precision, in decimals.
\sa setDecimals()
*/
int QtRectFPropertyManager::decimals(const QtProperty *property) const {
return getData<int>(d_ptr->m_values,
&QtRectFPropertyManagerPrivate::Data::decimals, property,
0);
Returns the given \a property's constraining rectangle. If returned value is
null QRectF it means there is no constraint applied.
QRectF QtRectFPropertyManager::constraint(const QtProperty *property) const {
return getData<QRectF>(d_ptr->m_values,
&QtRectFPropertyManagerPrivate::Data::constraint,
property, QRect());
QString QtRectFPropertyManager::valueText(const QtProperty *property) const {
const QtRectFPropertyManagerPrivate::PropertyValueMap::const_iterator it =
d_ptr->m_values.constFind(property);
if (it == d_ptr->m_values.constEnd())
return QString();
const QRectF v = it.value().val;
const int dec = it.value().decimals;
return QString(tr("[(%1, %2), %3 x %4]")
.arg(QString::number(v.x(), 'f', dec))
.arg(QString::number(v.y(), 'f', dec))
.arg(QString::number(v.width(), 'f', dec))
.arg(QString::number(v.height(), 'f', dec)));
\fn void QtRectFPropertyManager::setValue(QtProperty *property, const QRectF
&value)
Sets the value of the given \a property to \a value. Nested
properties are updated automatically.
If the specified \a value is not inside the given \a property's
constraining rectangle, the value is adjusted accordingly to fit
within the constraint.
\sa value(), setConstraint(), valueChanged()
*/
void QtRectFPropertyManager::setValue(QtProperty *property, const QRectF &val) {
const QtRectFPropertyManagerPrivate::PropertyValueMap::iterator it =
d_ptr->m_values.find(property);
if (it == d_ptr->m_values.end())
return;
QtRectFPropertyManagerPrivate::Data data = it.value();
QRectF newRect = val.normalized();
if (!data.constraint.isNull() && !data.constraint.contains(newRect)) {
const QRectF r1 = data.constraint;
const QRectF r2 = newRect;
newRect.setLeft(qMax(r1.left(), r2.left()));
newRect.setRight(qMin(r1.right(), r2.right()));
newRect.setTop(qMax(r1.top(), r2.top()));
newRect.setBottom(qMin(r1.bottom(), r2.bottom()));
if (newRect.width() < 0 || newRect.height() < 0)
return;
}
if (data.val == newRect)
return;
it.value() = data;
d_ptr->m_doublePropertyManager->setValue(d_ptr->m_propertyToX[property],
newRect.x());
d_ptr->m_doublePropertyManager->setValue(d_ptr->m_propertyToY[property],
newRect.y());
d_ptr->m_doublePropertyManager->setValue(d_ptr->m_propertyToW[property],
newRect.width());
d_ptr->m_doublePropertyManager->setValue(d_ptr->m_propertyToH[property],
newRect.height());
emit propertyChanged(property);
emit valueChanged(property, data.val);
}
/**
Sets the given \a property's constraining rectangle to \a
constraint.
When setting the constraint, the current value is adjusted if
necessary (ensuring that the current rectangle value is inside the
constraint). In order to reset the constraint pass a null QRectF value.
\sa setValue(), constraint(), constraintChanged()
*/
void QtRectFPropertyManager::setConstraint(QtProperty *property,
const QRectF &constraint) {
const QtRectFPropertyManagerPrivate::PropertyValueMap::iterator it =
d_ptr->m_values.find(property);
if (it == d_ptr->m_values.end())
return;
QtRectFPropertyManagerPrivate::Data data = it.value();
QRectF newConstraint = constraint.normalized();
if (data.constraint == newConstraint)
return;
if (!data.constraint.isNull() && !data.constraint.contains(oldVal)) {
QRectF r1 = data.constraint;
QRectF r2 = data.val;
if (r2.width() > r1.width())
r2.setWidth(r1.width());
if (r2.height() > r1.height())
r2.setHeight(r1.height());
if (r2.left() < r1.left())
r2.moveLeft(r1.left());
else if (r2.right() > r1.right())
r2.moveRight(r1.right());
if (r2.top() < r1.top())
r2.moveTop(r1.top());
else if (r2.bottom() > r1.bottom())
r2.moveBottom(r1.bottom());
emit constraintChanged(property, data.constraint);
d_ptr->setConstraint(property, data.constraint, data.val);
if (data.val == oldVal)
return;
emit propertyChanged(property);
emit valueChanged(property, data.val);
}
/**
\fn void QtRectFPropertyManager::setDecimals(QtProperty *property, int prec)
Sets the precision of the given \a property to \a prec.
The valid decimal range is 0-13. The default is 2.
\sa decimals()
*/
void QtRectFPropertyManager::setDecimals(QtProperty *property, int prec) {
const QtRectFPropertyManagerPrivate::PropertyValueMap::iterator it =
d_ptr->m_values.find(property);
if (it == d_ptr->m_values.end())
return;
QtRectFPropertyManagerPrivate::Data data = it.value();
if (prec > 13)
prec = 13;
else if (prec < 0)
prec = 0;
if (data.decimals == prec)
return;
data.decimals = prec;
d_ptr->m_doublePropertyManager->setDecimals(d_ptr->m_propertyToX[property],
prec);
d_ptr->m_doublePropertyManager->setDecimals(d_ptr->m_propertyToY[property],
prec);
d_ptr->m_doublePropertyManager->setDecimals(d_ptr->m_propertyToW[property],
prec);
d_ptr->m_doublePropertyManager->setDecimals(d_ptr->m_propertyToH[property],
prec);
emit decimalsChanged(property, data.decimals);
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
void QtRectFPropertyManager::initializeProperty(QtProperty *property) {
d_ptr->m_values[property] = QtRectFPropertyManagerPrivate::Data();
QtProperty *xProp = d_ptr->m_doublePropertyManager->addProperty();
xProp->setPropertyName(tr("X"));
d_ptr->m_doublePropertyManager->setDecimals(xProp, decimals(property));
d_ptr->m_doublePropertyManager->setValue(xProp, 0);
d_ptr->m_propertyToX[property] = xProp;
d_ptr->m_xToProperty[xProp] = property;
property->addSubProperty(xProp);
QtProperty *yProp = d_ptr->m_doublePropertyManager->addProperty();
yProp->setPropertyName(tr("Y"));
d_ptr->m_doublePropertyManager->setDecimals(yProp, decimals(property));
d_ptr->m_doublePropertyManager->setValue(yProp, 0);
d_ptr->m_propertyToY[property] = yProp;
d_ptr->m_yToProperty[yProp] = property;
property->addSubProperty(yProp);
QtProperty *wProp = d_ptr->m_doublePropertyManager->addProperty();
wProp->setPropertyName(tr("Width"));
d_ptr->m_doublePropertyManager->setDecimals(wProp, decimals(property));
d_ptr->m_doublePropertyManager->setValue(wProp, 0);
d_ptr->m_doublePropertyManager->setMinimum(wProp, 0);
d_ptr->m_propertyToW[property] = wProp;
d_ptr->m_wToProperty[wProp] = property;
property->addSubProperty(wProp);
QtProperty *hProp = d_ptr->m_doublePropertyManager->addProperty();
hProp->setPropertyName(tr("Height"));
d_ptr->m_doublePropertyManager->setDecimals(hProp, decimals(property));
d_ptr->m_doublePropertyManager->setValue(hProp, 0);
d_ptr->m_doublePropertyManager->setMinimum(hProp, 0);
d_ptr->m_propertyToH[property] = hProp;
d_ptr->m_hToProperty[hProp] = property;
property->addSubProperty(hProp);
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
void QtRectFPropertyManager::uninitializeProperty(QtProperty *property) {
QtProperty *xProp = d_ptr->m_propertyToX[property];
if (xProp) {
d_ptr->m_xToProperty.remove(xProp);
delete xProp;
}
d_ptr->m_propertyToX.remove(property);
QtProperty *yProp = d_ptr->m_propertyToY[property];
if (yProp) {
d_ptr->m_yToProperty.remove(yProp);
delete yProp;
}
d_ptr->m_propertyToY.remove(property);
QtProperty *wProp = d_ptr->m_propertyToW[property];
if (wProp) {
d_ptr->m_wToProperty.remove(wProp);
delete wProp;
}
d_ptr->m_propertyToW.remove(property);
QtProperty *hProp = d_ptr->m_propertyToH[property];
if (hProp) {
d_ptr->m_hToProperty.remove(hProp);
delete hProp;
}
d_ptr->m_propertyToH.remove(property);
d_ptr->m_values.remove(property);
class QtEnumPropertyManagerPrivate {
QtEnumPropertyManager *q_ptr;
Q_DECLARE_PUBLIC(QtEnumPropertyManager)
struct Data {
Data() : val(-1) {}
int val;
QStringList enumNames;
QMap<int, QIcon> enumIcons;
};
typedef QMap<const QtProperty *, Data> PropertyValueMap;
PropertyValueMap m_values;
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
};
/**
\class QtEnumPropertyManager
\brief The QtEnumPropertyManager provides and manages enum properties.
Each enum property has an associated list of enum names which can
be retrieved using the enumNames() function, and set using the
corresponding setEnumNames() function. An enum property's value is
represented by an index in this list, and can be retrieved and set
using the value() and setValue() slots respectively.
Each enum value can also have an associated icon. The mapping from
values to icons can be set using the setEnumIcons() function and
queried with the enumIcons() function.
In addition, QtEnumPropertyManager provides the valueChanged() signal
which is emitted whenever a property created by this manager
changes. The enumNamesChanged() or enumIconsChanged() signal is emitted
whenever the list of enum names or icons is altered.
\sa QtAbstractPropertyManager, QtEnumEditorFactory
*/
/**
\fn void QtEnumPropertyManager::valueChanged(QtProperty *property, int
value)
This signal is emitted whenever a property created by this manager
changes its value, passing a pointer to the \a property and the new
\a value as parameters.
\sa setValue()
*/
/**
\fn void QtEnumPropertyManager::enumNamesChanged(QtProperty *property, const
QStringList &names)
This signal is emitted whenever a property created by this manager
changes its enum names, passing a pointer to the \a property and
the new \a names as parameters.
\sa setEnumNames()
*/
/**
\fn void QtEnumPropertyManager::enumIconsChanged(QtProperty *property, const
QMap<int, QIcon> &icons)
This signal is emitted whenever a property created by this manager
changes its enum icons, passing a pointer to the \a property and
the new mapping of values to \a icons as parameters.
\sa setEnumIcons()
*/
/**
Creates a manager with the given \a parent.
*/
QtEnumPropertyManager::QtEnumPropertyManager(QObject *parent)
: QtAbstractPropertyManager(parent) {
d_ptr = new QtEnumPropertyManagerPrivate;
d_ptr->q_ptr = this;
}
/**
Destroys this manager, and all the properties it has created.
*/
QtEnumPropertyManager::~QtEnumPropertyManager() {
clear();
delete d_ptr;
}
/**
Returns the given \a property's value which is an index in the
list returned by enumNames()
If the given property is not managed by this manager, this
function returns -1.
\sa enumNames(), setValue()
*/
int QtEnumPropertyManager::value(const QtProperty *property) const {
return getValue<int>(d_ptr->m_values, property, -1);
}
/**
Returns the given \a property's list of enum names.
\sa value(), setEnumNames()
*/
QStringList QtEnumPropertyManager::enumNames(const QtProperty *property) const {
return getData<QStringList>(d_ptr->m_values,
&QtEnumPropertyManagerPrivate::Data::enumNames,
property, QStringList());
}
/**
Returns the given \a property's map of enum values to their icons.
\sa value(), setEnumIcons()
*/
QMap<int, QIcon>
QtEnumPropertyManager::enumIcons(const QtProperty *property) const {
return getData<QMap<int, QIcon>>(
d_ptr->m_values, &QtEnumPropertyManagerPrivate::Data::enumIcons, property,
QMap<int, QIcon>());
QString QtEnumPropertyManager::valueText(const QtProperty *property) const {
const QtEnumPropertyManagerPrivate::PropertyValueMap::const_iterator it =
d_ptr->m_values.constFind(property);
if (it == d_ptr->m_values.constEnd())
return QString();
const QtEnumPropertyManagerPrivate::Data &data = it.value();
const int v = data.val;
if (v >= 0 && v < data.enumNames.count())
return data.enumNames.at(v);
return QString();
QIcon QtEnumPropertyManager::valueIcon(const QtProperty *property) const {
const QtEnumPropertyManagerPrivate::PropertyValueMap::const_iterator it =
d_ptr->m_values.constFind(property);
if (it == d_ptr->m_values.constEnd())
return QIcon();
const QtEnumPropertyManagerPrivate::Data &data = it.value();
const int v = data.val;
return data.enumIcons.value(v);
}
/**
\fn void QtEnumPropertyManager::setValue(QtProperty *property, int value)
Sets the value of the given \a property to \a value.
The specified \a value must be less than the size of the given \a
property's enumNames() list, and larger than (or equal to) 0.
\sa value(), valueChanged()
*/
void QtEnumPropertyManager::setValue(QtProperty *property, int val) {
const QtEnumPropertyManagerPrivate::PropertyValueMap::iterator it =
d_ptr->m_values.find(property);
if (it == d_ptr->m_values.end())
return;
QtEnumPropertyManagerPrivate::Data data = it.value();
if (val >= data.enumNames.count())
return;
if (val < 0 && data.enumNames.count() > 0)
return;
emit propertyChanged(property);
emit valueChanged(property, data.val);
}
/**
Sets the given \a property's list of enum names to \a
enumNames. The \a property's current value is reset to 0
indicating the first item of the list.
If the specified \a enumNames list is empty, the \a property's
current value is set to -1.
\sa enumNames(), enumNamesChanged()
*/
void QtEnumPropertyManager::setEnumNames(QtProperty *property,
const QStringList &enumNames) {
const QtEnumPropertyManagerPrivate::PropertyValueMap::iterator it =
d_ptr->m_values.find(property);
if (it == d_ptr->m_values.end())
return;
QtEnumPropertyManagerPrivate::Data data = it.value();
if (data.enumNames == enumNames)
return;
if (enumNames.count() > 0)
data.val = 0;
emit enumNamesChanged(property, data.enumNames);
emit propertyChanged(property);
emit valueChanged(property, data.val);
}
/**
Sets the given \a property's map of enum values to their icons to \a
enumIcons.
Each enum value can have associated icon. This association is represented
with passed \a enumIcons map.
\sa enumNames(), enumNamesChanged()
*/
void QtEnumPropertyManager::setEnumIcons(QtProperty *property,
const QMap<int, QIcon> &enumIcons) {
const QtEnumPropertyManagerPrivate::PropertyValueMap::iterator it =
d_ptr->m_values.find(property);
if (it == d_ptr->m_values.end())
return;
emit enumIconsChanged(property, it.value().enumIcons);
void QtEnumPropertyManager::initializeProperty(QtProperty *property) {
d_ptr->m_values[property] = QtEnumPropertyManagerPrivate::Data();
void QtEnumPropertyManager::uninitializeProperty(QtProperty *property) {
d_ptr->m_values.remove(property);
class QtFlagPropertyManagerPrivate {
QtFlagPropertyManager *q_ptr;
Q_DECLARE_PUBLIC(QtFlagPropertyManager)
void slotBoolChanged(QtProperty *property, bool value);
void slotPropertyDestroyed(QtProperty *property);
struct Data {
Data() : val(-1) {}
int val;
QStringList flagNames;
};
typedef QMap<const QtProperty *, Data> PropertyValueMap;
PropertyValueMap m_values;
QtBoolPropertyManager *m_boolPropertyManager;
QMap<const QtProperty *, QList<QtProperty *>> m_propertyToFlags;
QMap<const QtProperty *, QtProperty *> m_flagToProperty;