Newer
Older
Roman Tolchenov
committed
The subproperties are created by a QtBoolPropertyManager object. This
manager can be retrieved using the subBoolPropertyManager() function. In
order to provide editing widgets for the subproperties in a
property browser widget, this manager must be associated with an
editor factory.
In addition, QtFlagPropertyManager provides the valueChanged() signal
which is emitted whenever a property created by this manager
changes, and the flagNamesChanged() signal which is emitted
whenever the list of flag names is altered.
\sa QtAbstractPropertyManager, QtBoolPropertyManager
*/
Janik Zikovsky
committed
/**
Roman Tolchenov
committed
\fn void QtFlagPropertyManager::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()
*/
Janik Zikovsky
committed
/**
Roman Tolchenov
committed
\fn void QtFlagPropertyManager::flagNamesChanged(QtProperty *property, const QStringList &names)
This signal is emitted whenever a property created by this manager
changes its flag names, passing a pointer to the \a property and the
new \a names as parameters.
\sa setFlagNames()
*/
Janik Zikovsky
committed
/**
Roman Tolchenov
committed
Creates a manager with the given \a parent.
*/
QtFlagPropertyManager::QtFlagPropertyManager(QObject *parent)
: QtAbstractPropertyManager(parent)
{
d_ptr = new QtFlagPropertyManagerPrivate;
d_ptr->q_ptr = this;
d_ptr->m_boolPropertyManager = new QtBoolPropertyManager(this);
connect(d_ptr->m_boolPropertyManager, SIGNAL(valueChanged(QtProperty *, bool)),
this, SLOT(slotBoolChanged(QtProperty *, bool)));
connect(d_ptr->m_boolPropertyManager, SIGNAL(propertyDestroyed(QtProperty *)),
this, SLOT(slotPropertyDestroyed(QtProperty *)));
}
Janik Zikovsky
committed
/**
Roman Tolchenov
committed
Destroys this manager, and all the properties it has created.
*/
QtFlagPropertyManager::~QtFlagPropertyManager()
{
clear();
delete d_ptr;
}
Janik Zikovsky
committed
/**
Roman Tolchenov
committed
Returns the manager that produces the nested boolean subproperties
representing each flag.
In order to provide editing widgets for the subproperties in a
property browser widget, this manager must be associated with an
editor factory.
\sa QtAbstractPropertyBrowser::setFactoryForManager()
*/
QtBoolPropertyManager *QtFlagPropertyManager::subBoolPropertyManager() const
{
return d_ptr->m_boolPropertyManager;
}
Janik Zikovsky
committed
/**
Roman Tolchenov
committed
Returns the given \a property's value.
If the given property is not managed by this manager, this
function returns 0.
\sa flagNames(), setValue()
*/
int QtFlagPropertyManager::value(const QtProperty *property) const
{
return getValue<int>(d_ptr->m_values, property, 0);
}
Janik Zikovsky
committed
/**
Roman Tolchenov
committed
Returns the given \a property's list of flag names.
\sa value(), setFlagNames()
*/
QStringList QtFlagPropertyManager::flagNames(const QtProperty *property) const
{
return getData<QStringList>(d_ptr->m_values, &QtFlagPropertyManagerPrivate::Data::flagNames, property, QStringList());
}
Janik Zikovsky
committed
/**
Roman Tolchenov
committed
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
\reimp
*/
QString QtFlagPropertyManager::valueText(const QtProperty *property) const
{
const QtFlagPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
if (it == d_ptr->m_values.constEnd())
return QString();
const QtFlagPropertyManagerPrivate::Data &data = it.value();
QString str;
int level = 0;
const QChar bar = QLatin1Char('|');
const QStringList::const_iterator fncend = data.flagNames.constEnd();
for (QStringList::const_iterator it = data.flagNames.constBegin(); it != fncend; ++it) {
if (data.val & (1 << level)) {
if (!str.isEmpty())
str += bar;
str += *it;
}
level++;
}
return str;
}
Janik Zikovsky
committed
/**
Roman Tolchenov
committed
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
\fn void QtFlagPropertyManager::setValue(QtProperty *property, int value)
Sets the value of the given \a property to \a value. Nested
properties are updated automatically.
The specified \a value must be less than the binary combination of
the property's flagNames() list size (i.e. less than 2\sup n,
where \c n is the size of the list) and larger than (or equal to)
0.
\sa value(), valueChanged()
*/
void QtFlagPropertyManager::setValue(QtProperty *property, int val)
{
const QtFlagPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
if (it == d_ptr->m_values.end())
return;
QtFlagPropertyManagerPrivate::Data data = it.value();
if (data.val == val)
return;
if (val > (1 << data.flagNames.count()) - 1)
return;
if (val < 0)
return;
data.val = val;
it.value() = data;
QListIterator<QtProperty *> itProp(d_ptr->m_propertyToFlags[property]);
int level = 0;
while (itProp.hasNext()) {
QtProperty *prop = itProp.next();
if (prop)
d_ptr->m_boolPropertyManager->setValue(prop, val & (1 << level));
level++;
}
emit propertyChanged(property);
emit valueChanged(property, data.val);
}
Janik Zikovsky
committed
/**
Roman Tolchenov
committed
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
Sets the given \a property's list of flag names to \a flagNames. The
property's current value is reset to 0 indicating the first item
of the list.
\sa flagNames(), flagNamesChanged()
*/
void QtFlagPropertyManager::setFlagNames(QtProperty *property, const QStringList &flagNames)
{
const QtFlagPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
if (it == d_ptr->m_values.end())
return;
QtFlagPropertyManagerPrivate::Data data = it.value();
if (data.flagNames == flagNames)
return;
data.flagNames = flagNames;
data.val = 0;
it.value() = data;
QListIterator<QtProperty *> itProp(d_ptr->m_propertyToFlags[property]);
while (itProp.hasNext()) {
QtProperty *prop = itProp.next();
if (prop) {
delete prop;
d_ptr->m_flagToProperty.remove(prop);
}
}
d_ptr->m_propertyToFlags[property].clear();
QStringListIterator itFlag(flagNames);
while (itFlag.hasNext()) {
const QString flagName = itFlag.next();
QtProperty *prop = d_ptr->m_boolPropertyManager->addProperty();
prop->setPropertyName(flagName);
property->addSubProperty(prop);
d_ptr->m_propertyToFlags[property].append(prop);
d_ptr->m_flagToProperty[prop] = property;
}
emit flagNamesChanged(property, data.flagNames);
emit propertyChanged(property);
emit valueChanged(property, data.val);
}
Janik Zikovsky
committed
/**
Roman Tolchenov
committed
\reimp
*/
void QtFlagPropertyManager::initializeProperty(QtProperty *property)
{
d_ptr->m_values[property] = QtFlagPropertyManagerPrivate::Data();
d_ptr->m_propertyToFlags[property] = QList<QtProperty *>();
}
Janik Zikovsky
committed
/**
Roman Tolchenov
committed
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
\reimp
*/
void QtFlagPropertyManager::uninitializeProperty(QtProperty *property)
{
QListIterator<QtProperty *> itProp(d_ptr->m_propertyToFlags[property]);
while (itProp.hasNext()) {
QtProperty *prop = itProp.next();
if (prop) {
delete prop;
d_ptr->m_flagToProperty.remove(prop);
}
}
d_ptr->m_propertyToFlags.remove(property);
d_ptr->m_values.remove(property);
}
// QtSizePolicyPropertyManager
class QtSizePolicyPropertyManagerPrivate
{
QtSizePolicyPropertyManager *q_ptr;
Q_DECLARE_PUBLIC(QtSizePolicyPropertyManager)
public:
QtSizePolicyPropertyManagerPrivate();
void slotIntChanged(QtProperty *property, int value);
void slotEnumChanged(QtProperty *property, int value);
void slotPropertyDestroyed(QtProperty *property);
typedef QMap<const QtProperty *, QSizePolicy> PropertyValueMap;
PropertyValueMap m_values;
QtIntPropertyManager *m_intPropertyManager;
QtEnumPropertyManager *m_enumPropertyManager;
QMap<const QtProperty *, QtProperty *> m_propertyToHPolicy;
QMap<const QtProperty *, QtProperty *> m_propertyToVPolicy;
QMap<const QtProperty *, QtProperty *> m_propertyToHStretch;
QMap<const QtProperty *, QtProperty *> m_propertyToVStretch;
QMap<const QtProperty *, QtProperty *> m_hPolicyToProperty;
QMap<const QtProperty *, QtProperty *> m_vPolicyToProperty;
QMap<const QtProperty *, QtProperty *> m_hStretchToProperty;
QMap<const QtProperty *, QtProperty *> m_vStretchToProperty;
};
QtSizePolicyPropertyManagerPrivate::QtSizePolicyPropertyManagerPrivate()
{
}
void QtSizePolicyPropertyManagerPrivate::slotIntChanged(QtProperty *property, int value)
{
if (QtProperty *prop = m_hStretchToProperty.value(property, 0)) {
QSizePolicy sp = m_values[prop];
sp.setHorizontalStretch(value);
q_ptr->setValue(prop, sp);
} else if (QtProperty *prop = m_vStretchToProperty.value(property, 0)) {
QSizePolicy sp = m_values[prop];
sp.setVerticalStretch(value);
q_ptr->setValue(prop, sp);
}
}
void QtSizePolicyPropertyManagerPrivate::slotEnumChanged(QtProperty *property, int value)
{
if (QtProperty *prop = m_hPolicyToProperty.value(property, 0)) {
QSizePolicy sp = m_values[prop];
sp.setHorizontalPolicy(metaEnumProvider()->indexToSizePolicy(value));
q_ptr->setValue(prop, sp);
} else if (QtProperty *prop = m_vPolicyToProperty.value(property, 0)) {
QSizePolicy sp = m_values[prop];
sp.setVerticalPolicy(metaEnumProvider()->indexToSizePolicy(value));
q_ptr->setValue(prop, sp);
}
}
void QtSizePolicyPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property)
{
if (QtProperty *pointProp = m_hStretchToProperty.value(property, 0)) {
m_propertyToHStretch[pointProp] = 0;
m_hStretchToProperty.remove(property);
} else if (QtProperty *pointProp = m_vStretchToProperty.value(property, 0)) {
m_propertyToVStretch[pointProp] = 0;
m_vStretchToProperty.remove(property);
} else if (QtProperty *pointProp = m_hPolicyToProperty.value(property, 0)) {
m_propertyToHPolicy[pointProp] = 0;
m_hPolicyToProperty.remove(property);
} else if (QtProperty *pointProp = m_vPolicyToProperty.value(property, 0)) {
m_propertyToVPolicy[pointProp] = 0;
m_vPolicyToProperty.remove(property);
}
}
Janik Zikovsky
committed
/**
Roman Tolchenov
committed
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
\class QtSizePolicyPropertyManager
\brief The QtSizePolicyPropertyManager provides and manages QSizePolicy properties.
A size policy property has nested \e horizontalPolicy, \e
verticalPolicy, \e horizontalStretch and \e verticalStretch
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 QtIntPropertyManager and QtEnumPropertyManager
objects. These managers can be retrieved using the subIntPropertyManager()
and subEnumPropertyManager() functions respectively. In order to provide
editing widgets for the subproperties in a property browser widget,
these managers must be associated with editor factories.
In addition, QtSizePolicyPropertyManager provides the valueChanged()
signal which is emitted whenever a property created by this
manager changes.
\sa QtAbstractPropertyManager, QtIntPropertyManager, QtEnumPropertyManager
*/
Janik Zikovsky
committed
/**
Roman Tolchenov
committed
\fn void QtSizePolicyPropertyManager::valueChanged(QtProperty *property, const QSizePolicy &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()
*/
Janik Zikovsky
committed
/**
Roman Tolchenov
committed
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
Creates a manager with the given \a parent.
*/
QtSizePolicyPropertyManager::QtSizePolicyPropertyManager(QObject *parent)
: QtAbstractPropertyManager(parent)
{
d_ptr = new QtSizePolicyPropertyManagerPrivate;
d_ptr->q_ptr = this;
d_ptr->m_intPropertyManager = new QtIntPropertyManager(this);
connect(d_ptr->m_intPropertyManager, SIGNAL(valueChanged(QtProperty *, int)),
this, SLOT(slotIntChanged(QtProperty *, int)));
d_ptr->m_enumPropertyManager = new QtEnumPropertyManager(this);
connect(d_ptr->m_enumPropertyManager, SIGNAL(valueChanged(QtProperty *, int)),
this, SLOT(slotEnumChanged(QtProperty *, int)));
connect(d_ptr->m_intPropertyManager, SIGNAL(propertyDestroyed(QtProperty *)),
this, SLOT(slotPropertyDestroyed(QtProperty *)));
connect(d_ptr->m_enumPropertyManager, SIGNAL(propertyDestroyed(QtProperty *)),
this, SLOT(slotPropertyDestroyed(QtProperty *)));
}
Janik Zikovsky
committed
/**
Roman Tolchenov
committed
Destroys this manager, and all the properties it has created.
*/
QtSizePolicyPropertyManager::~QtSizePolicyPropertyManager()
{
clear();
delete d_ptr;
}
Janik Zikovsky
committed
/**
Roman Tolchenov
committed
Returns the manager that creates the nested \e horizontalStretch
and \e verticalStretch 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()
*/
QtIntPropertyManager *QtSizePolicyPropertyManager::subIntPropertyManager() const
{
return d_ptr->m_intPropertyManager;
}
Janik Zikovsky
committed
/**
Roman Tolchenov
committed
Returns the manager that creates the nested \e horizontalPolicy
and \e verticalPolicy 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()
*/
QtEnumPropertyManager *QtSizePolicyPropertyManager::subEnumPropertyManager() const
{
return d_ptr->m_enumPropertyManager;
}
Janik Zikovsky
committed
/**
Roman Tolchenov
committed
Returns the given \a property's value.
If the given property is not managed by this manager, this
function returns the default size policy.
\sa setValue()
*/
QSizePolicy QtSizePolicyPropertyManager::value(const QtProperty *property) const
{
return d_ptr->m_values.value(property, QSizePolicy());
}
Janik Zikovsky
committed
/**
Roman Tolchenov
committed
\reimp
*/
QString QtSizePolicyPropertyManager::valueText(const QtProperty *property) const
{
const QtSizePolicyPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
if (it == d_ptr->m_values.constEnd())
return QString();
const QSizePolicy sp = it.value();
const QtMetaEnumProvider *mep = metaEnumProvider();
const int hIndex = mep->sizePolicyToIndex(sp.horizontalPolicy());
const int vIndex = mep->sizePolicyToIndex(sp.verticalPolicy());
//! Unknown size policy on reading invalid uic3 files
const QString hPolicy = hIndex != -1 ? mep->policyEnumNames().at(hIndex) : tr("<Invalid>");
const QString vPolicy = vIndex != -1 ? mep->policyEnumNames().at(vIndex) : tr("<Invalid>");
const QString str = tr("[%1, %2, %3, %4]").arg(hPolicy, vPolicy).arg(sp.horizontalStretch()).arg(sp.verticalStretch());
return str;
}
Janik Zikovsky
committed
/**
Roman Tolchenov
committed
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
\fn void QtSizePolicyPropertyManager::setValue(QtProperty *property, const QSizePolicy &value)
Sets the value of the given \a property to \a value. Nested
properties are updated automatically.
\sa value(), valueChanged()
*/
void QtSizePolicyPropertyManager::setValue(QtProperty *property, const QSizePolicy &val)
{
const QtSizePolicyPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
if (it == d_ptr->m_values.end())
return;
if (it.value() == val)
return;
it.value() = val;
d_ptr->m_enumPropertyManager->setValue(d_ptr->m_propertyToHPolicy[property],
metaEnumProvider()->sizePolicyToIndex(val.horizontalPolicy()));
d_ptr->m_enumPropertyManager->setValue(d_ptr->m_propertyToVPolicy[property],
metaEnumProvider()->sizePolicyToIndex(val.verticalPolicy()));
d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToHStretch[property],
val.horizontalStretch());
d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToVStretch[property],
val.verticalStretch());
emit propertyChanged(property);
emit valueChanged(property, val);
}
Janik Zikovsky
committed
/**
Roman Tolchenov
committed
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
\reimp
*/
void QtSizePolicyPropertyManager::initializeProperty(QtProperty *property)
{
QSizePolicy val;
d_ptr->m_values[property] = val;
QtProperty *hPolicyProp = d_ptr->m_enumPropertyManager->addProperty();
hPolicyProp->setPropertyName(tr("Horizontal Policy"));
d_ptr->m_enumPropertyManager->setEnumNames(hPolicyProp, metaEnumProvider()->policyEnumNames());
d_ptr->m_enumPropertyManager->setValue(hPolicyProp,
metaEnumProvider()->sizePolicyToIndex(val.horizontalPolicy()));
d_ptr->m_propertyToHPolicy[property] = hPolicyProp;
d_ptr->m_hPolicyToProperty[hPolicyProp] = property;
property->addSubProperty(hPolicyProp);
QtProperty *vPolicyProp = d_ptr->m_enumPropertyManager->addProperty();
vPolicyProp->setPropertyName(tr("Vertical Policy"));
d_ptr->m_enumPropertyManager->setEnumNames(vPolicyProp, metaEnumProvider()->policyEnumNames());
d_ptr->m_enumPropertyManager->setValue(vPolicyProp,
metaEnumProvider()->sizePolicyToIndex(val.verticalPolicy()));
d_ptr->m_propertyToVPolicy[property] = vPolicyProp;
d_ptr->m_vPolicyToProperty[vPolicyProp] = property;
property->addSubProperty(vPolicyProp);
QtProperty *hStretchProp = d_ptr->m_intPropertyManager->addProperty();
hStretchProp->setPropertyName(tr("Horizontal Stretch"));
d_ptr->m_intPropertyManager->setValue(hStretchProp, val.horizontalStretch());
d_ptr->m_intPropertyManager->setRange(hStretchProp, 0, 0xff);
d_ptr->m_propertyToHStretch[property] = hStretchProp;
d_ptr->m_hStretchToProperty[hStretchProp] = property;
property->addSubProperty(hStretchProp);
QtProperty *vStretchProp = d_ptr->m_intPropertyManager->addProperty();
vStretchProp->setPropertyName(tr("Vertical Stretch"));
d_ptr->m_intPropertyManager->setValue(vStretchProp, val.verticalStretch());
d_ptr->m_intPropertyManager->setRange(vStretchProp, 0, 0xff);
d_ptr->m_propertyToVStretch[property] = vStretchProp;
d_ptr->m_vStretchToProperty[vStretchProp] = property;
property->addSubProperty(vStretchProp);
}
Janik Zikovsky
committed
/**
Roman Tolchenov
committed
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
\reimp
*/
void QtSizePolicyPropertyManager::uninitializeProperty(QtProperty *property)
{
QtProperty *hPolicyProp = d_ptr->m_propertyToHPolicy[property];
if (hPolicyProp) {
d_ptr->m_hPolicyToProperty.remove(hPolicyProp);
delete hPolicyProp;
}
d_ptr->m_propertyToHPolicy.remove(property);
QtProperty *vPolicyProp = d_ptr->m_propertyToVPolicy[property];
if (vPolicyProp) {
d_ptr->m_vPolicyToProperty.remove(vPolicyProp);
delete vPolicyProp;
}
d_ptr->m_propertyToVPolicy.remove(property);
QtProperty *hStretchProp = d_ptr->m_propertyToHStretch[property];
if (hStretchProp) {
d_ptr->m_hStretchToProperty.remove(hStretchProp);
delete hStretchProp;
}
d_ptr->m_propertyToHStretch.remove(property);
QtProperty *vStretchProp = d_ptr->m_propertyToVStretch[property];
if (vStretchProp) {
d_ptr->m_vStretchToProperty.remove(vStretchProp);
delete vStretchProp;
}
d_ptr->m_propertyToVStretch.remove(property);
d_ptr->m_values.remove(property);
}
// QtFontPropertyManager:
// QtFontPropertyManagerPrivate has a mechanism for reacting
// to QApplication::fontDatabaseChanged() [4.5], which is emitted
// when someone loads an application font. The signals are compressed
// using a timer with interval 0, which then causes the family
// enumeration manager to re-set its strings and index values
// for each property.
Q_GLOBAL_STATIC(QFontDatabase, fontDatabase)
class QtFontPropertyManagerPrivate
{
QtFontPropertyManager *q_ptr;
Q_DECLARE_PUBLIC(QtFontPropertyManager)
public:
QtFontPropertyManagerPrivate();
void slotIntChanged(QtProperty *property, int value);
void slotEnumChanged(QtProperty *property, int value);
void slotBoolChanged(QtProperty *property, bool value);
void slotPropertyDestroyed(QtProperty *property);
void slotFontDatabaseChanged();
void slotFontDatabaseDelayedChange();
QStringList m_familyNames;
typedef QMap<const QtProperty *, QFont> PropertyValueMap;
PropertyValueMap m_values;
QtIntPropertyManager *m_intPropertyManager;
QtEnumPropertyManager *m_enumPropertyManager;
QtBoolPropertyManager *m_boolPropertyManager;
QMap<const QtProperty *, QtProperty *> m_propertyToFamily;
QMap<const QtProperty *, QtProperty *> m_propertyToPointSize;
QMap<const QtProperty *, QtProperty *> m_propertyToBold;
QMap<const QtProperty *, QtProperty *> m_propertyToItalic;
QMap<const QtProperty *, QtProperty *> m_propertyToUnderline;
QMap<const QtProperty *, QtProperty *> m_propertyToStrikeOut;
QMap<const QtProperty *, QtProperty *> m_propertyToKerning;
QMap<const QtProperty *, QtProperty *> m_familyToProperty;
QMap<const QtProperty *, QtProperty *> m_pointSizeToProperty;
QMap<const QtProperty *, QtProperty *> m_boldToProperty;
QMap<const QtProperty *, QtProperty *> m_italicToProperty;
QMap<const QtProperty *, QtProperty *> m_underlineToProperty;
QMap<const QtProperty *, QtProperty *> m_strikeOutToProperty;
QMap<const QtProperty *, QtProperty *> m_kerningToProperty;
bool m_settingValue;
QTimer *m_fontDatabaseChangeTimer;
};
QtFontPropertyManagerPrivate::QtFontPropertyManagerPrivate() :
m_settingValue(false),
m_fontDatabaseChangeTimer(0)
{
}
void QtFontPropertyManagerPrivate::slotIntChanged(QtProperty *property, int value)
{
if (m_settingValue)
return;
if (QtProperty *prop = m_pointSizeToProperty.value(property, 0)) {
QFont f = m_values[prop];
f.setPointSize(value);
q_ptr->setValue(prop, f);
}
}
void QtFontPropertyManagerPrivate::slotEnumChanged(QtProperty *property, int value)
{
if (m_settingValue)
return;
if (QtProperty *prop = m_familyToProperty.value(property, 0)) {
QFont f = m_values[prop];
f.setFamily(m_familyNames.at(value));
q_ptr->setValue(prop, f);
}
}
void QtFontPropertyManagerPrivate::slotBoolChanged(QtProperty *property, bool value)
{
if (m_settingValue)
return;
if (QtProperty *prop = m_boldToProperty.value(property, 0)) {
QFont f = m_values[prop];
f.setBold(value);
q_ptr->setValue(prop, f);
} else if (QtProperty *prop = m_italicToProperty.value(property, 0)) {
QFont f = m_values[prop];
f.setItalic(value);
q_ptr->setValue(prop, f);
} else if (QtProperty *prop = m_underlineToProperty.value(property, 0)) {
QFont f = m_values[prop];
f.setUnderline(value);
q_ptr->setValue(prop, f);
} else if (QtProperty *prop = m_strikeOutToProperty.value(property, 0)) {
QFont f = m_values[prop];
f.setStrikeOut(value);
q_ptr->setValue(prop, f);
} else if (QtProperty *prop = m_kerningToProperty.value(property, 0)) {
QFont f = m_values[prop];
f.setKerning(value);
q_ptr->setValue(prop, f);
}
}
void QtFontPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property)
{
if (QtProperty *pointProp = m_pointSizeToProperty.value(property, 0)) {
m_propertyToPointSize[pointProp] = 0;
m_pointSizeToProperty.remove(property);
} else if (QtProperty *pointProp = m_familyToProperty.value(property, 0)) {
m_propertyToFamily[pointProp] = 0;
m_familyToProperty.remove(property);
} else if (QtProperty *pointProp = m_boldToProperty.value(property, 0)) {
m_propertyToBold[pointProp] = 0;
m_boldToProperty.remove(property);
} else if (QtProperty *pointProp = m_italicToProperty.value(property, 0)) {
m_propertyToItalic[pointProp] = 0;
m_italicToProperty.remove(property);
} else if (QtProperty *pointProp = m_underlineToProperty.value(property, 0)) {
m_propertyToUnderline[pointProp] = 0;
m_underlineToProperty.remove(property);
} else if (QtProperty *pointProp = m_strikeOutToProperty.value(property, 0)) {
m_propertyToStrikeOut[pointProp] = 0;
m_strikeOutToProperty.remove(property);
} else if (QtProperty *pointProp = m_kerningToProperty.value(property, 0)) {
m_propertyToKerning[pointProp] = 0;
m_kerningToProperty.remove(property);
}
}
void QtFontPropertyManagerPrivate::slotFontDatabaseChanged()
{
if (!m_fontDatabaseChangeTimer) {
m_fontDatabaseChangeTimer = new QTimer(q_ptr);
m_fontDatabaseChangeTimer->setInterval(0);
m_fontDatabaseChangeTimer->setSingleShot(true);
QObject::connect(m_fontDatabaseChangeTimer, SIGNAL(timeout()), q_ptr, SLOT(slotFontDatabaseDelayedChange()));
}
if (!m_fontDatabaseChangeTimer->isActive())
m_fontDatabaseChangeTimer->start();
}
void QtFontPropertyManagerPrivate::slotFontDatabaseDelayedChange()
{
typedef QMap<const QtProperty *, QtProperty *> PropertyPropertyMap;
// rescan available font names
const QStringList oldFamilies = m_familyNames;
m_familyNames = fontDatabase()->families();
// Adapt all existing properties
if (!m_propertyToFamily.empty()) {
PropertyPropertyMap::const_iterator cend = m_propertyToFamily.constEnd();
for (PropertyPropertyMap::const_iterator it = m_propertyToFamily.constBegin(); it != cend; ++it) {
QtProperty *familyProp = it.value();
const int oldIdx = m_enumPropertyManager->value(familyProp);
int newIdx = m_familyNames.indexOf(oldFamilies.at(oldIdx));
if (newIdx < 0)
newIdx = 0;
m_enumPropertyManager->setEnumNames(familyProp, m_familyNames);
m_enumPropertyManager->setValue(familyProp, newIdx);
}
}
}
Janik Zikovsky
committed
/**
Roman Tolchenov
committed
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
\class QtFontPropertyManager
\brief The QtFontPropertyManager provides and manages QFont properties.
A font property has nested \e family, \e pointSize, \e bold, \e
italic, \e underline, \e strikeOut and \e kerning 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 QtIntPropertyManager, QtEnumPropertyManager and
QtBoolPropertyManager objects. These managers can be retrieved using the
corresponding subIntPropertyManager(), subEnumPropertyManager() and
subBoolPropertyManager() functions. In order to provide editing widgets
for the subproperties in a property browser widget, these managers
must be associated with editor factories.
In addition, QtFontPropertyManager provides the valueChanged() signal
which is emitted whenever a property created by this manager
changes.
\sa QtAbstractPropertyManager, QtEnumPropertyManager, QtIntPropertyManager, QtBoolPropertyManager
*/
Janik Zikovsky
committed
/**
Roman Tolchenov
committed
\fn void QtFontPropertyManager::valueChanged(QtProperty *property, const QFont &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()
*/
Janik Zikovsky
committed
/**
Roman Tolchenov
committed
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
Creates a manager with the given \a parent.
*/
QtFontPropertyManager::QtFontPropertyManager(QObject *parent)
: QtAbstractPropertyManager(parent)
{
d_ptr = new QtFontPropertyManagerPrivate;
d_ptr->q_ptr = this;
#if QT_VERSION >= 0x040500
QObject::connect(qApp, SIGNAL(fontDatabaseChanged()), this, SLOT(slotFontDatabaseChanged()));
#endif
d_ptr->m_intPropertyManager = new QtIntPropertyManager(this);
connect(d_ptr->m_intPropertyManager, SIGNAL(valueChanged(QtProperty *, int)),
this, SLOT(slotIntChanged(QtProperty *, int)));
d_ptr->m_enumPropertyManager = new QtEnumPropertyManager(this);
connect(d_ptr->m_enumPropertyManager, SIGNAL(valueChanged(QtProperty *, int)),
this, SLOT(slotEnumChanged(QtProperty *, int)));
d_ptr->m_boolPropertyManager = new QtBoolPropertyManager(this);
connect(d_ptr->m_boolPropertyManager, SIGNAL(valueChanged(QtProperty *, bool)),
this, SLOT(slotBoolChanged(QtProperty *, bool)));
connect(d_ptr->m_intPropertyManager, SIGNAL(propertyDestroyed(QtProperty *)),
this, SLOT(slotPropertyDestroyed(QtProperty *)));
connect(d_ptr->m_enumPropertyManager, SIGNAL(propertyDestroyed(QtProperty *)),
this, SLOT(slotPropertyDestroyed(QtProperty *)));
connect(d_ptr->m_boolPropertyManager, SIGNAL(propertyDestroyed(QtProperty *)),
this, SLOT(slotPropertyDestroyed(QtProperty *)));
}
Janik Zikovsky
committed
/**
Roman Tolchenov
committed
Destroys this manager, and all the properties it has created.
*/
QtFontPropertyManager::~QtFontPropertyManager()
{
clear();
delete d_ptr;
}
Janik Zikovsky
committed
/**
Roman Tolchenov
committed
Returns the manager that creates the \e pointSize subproperty.
In order to provide editing widgets for the \e pointSize property
in a property browser widget, this manager must be associated
with an editor factory.
\sa QtAbstractPropertyBrowser::setFactoryForManager()
*/
QtIntPropertyManager *QtFontPropertyManager::subIntPropertyManager() const
{
return d_ptr->m_intPropertyManager;
}
Janik Zikovsky
committed
/**
Roman Tolchenov
committed
Returns the manager that create the \e family subproperty.
In order to provide editing widgets for the \e family property
in a property browser widget, this manager must be associated
with an editor factory.
\sa QtAbstractPropertyBrowser::setFactoryForManager()
*/
QtEnumPropertyManager *QtFontPropertyManager::subEnumPropertyManager() const
{
return d_ptr->m_enumPropertyManager;
}
Janik Zikovsky
committed
/**
Roman Tolchenov
committed
Returns the manager that creates the \e bold, \e italic, \e underline,
\e strikeOut and \e kerning subproperties.
In order to provide editing widgets for the mentioned properties
in a property browser widget, this manager must be associated with
an editor factory.
\sa QtAbstractPropertyBrowser::setFactoryForManager()
*/
QtBoolPropertyManager *QtFontPropertyManager::subBoolPropertyManager() const
{
return d_ptr->m_boolPropertyManager;
}
Janik Zikovsky
committed
/**
Roman Tolchenov
committed
Returns the given \a property's value.
If the given property is not managed by this manager, this
function returns a font object that uses the application's default
font.
\sa setValue()
*/
QFont QtFontPropertyManager::value(const QtProperty *property) const
{
return d_ptr->m_values.value(property, QFont());
}
Janik Zikovsky
committed
/**
Roman Tolchenov
committed
\reimp
*/
QString QtFontPropertyManager::valueText(const QtProperty *property) const
{
const QtFontPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
if (it == d_ptr->m_values.constEnd())
return QString();
return QtPropertyBrowserUtils::fontValueText(it.value());
}
Janik Zikovsky
committed
/**
Roman Tolchenov
committed
\reimp
*/
QIcon QtFontPropertyManager::valueIcon(const QtProperty *property) const
{
const QtFontPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
if (it == d_ptr->m_values.constEnd())
return QIcon();
return QtPropertyBrowserUtils::fontValueIcon(it.value());
}
Janik Zikovsky
committed
/**
Roman Tolchenov
committed
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
\fn void QtFontPropertyManager::setValue(QtProperty *property, const QFont &value)
Sets the value of the given \a property to \a value. Nested
properties are updated automatically.
\sa value(), valueChanged()
*/
void QtFontPropertyManager::setValue(QtProperty *property, const QFont &val)
{
const QtFontPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
if (it == d_ptr->m_values.end())
return;
const QFont oldVal = it.value();
if (oldVal == val && oldVal.resolve() == val.resolve())
return;
it.value() = val;
int idx = d_ptr->m_familyNames.indexOf(val.family());
if (idx == -1)
idx = 0;
bool settingValue = d_ptr->m_settingValue;
d_ptr->m_settingValue = true;
d_ptr->m_enumPropertyManager->setValue(d_ptr->m_propertyToFamily[property], idx);
d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToPointSize[property], val.pointSize());
d_ptr->m_boolPropertyManager->setValue(d_ptr->m_propertyToBold[property], val.bold());
d_ptr->m_boolPropertyManager->setValue(d_ptr->m_propertyToItalic[property], val.italic());
d_ptr->m_boolPropertyManager->setValue(d_ptr->m_propertyToUnderline[property], val.underline());
d_ptr->m_boolPropertyManager->setValue(d_ptr->m_propertyToStrikeOut[property], val.strikeOut());
d_ptr->m_boolPropertyManager->setValue(d_ptr->m_propertyToKerning[property], val.kerning());
d_ptr->m_settingValue = settingValue;
emit propertyChanged(property);
emit valueChanged(property, val);
}
Janik Zikovsky
committed
/**
Roman Tolchenov
committed
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
\reimp
*/
void QtFontPropertyManager::initializeProperty(QtProperty *property)
{
QFont val;
d_ptr->m_values[property] = val;
QtProperty *familyProp = d_ptr->m_enumPropertyManager->addProperty();
familyProp->setPropertyName(tr("Family"));
if (d_ptr->m_familyNames.empty())
d_ptr->m_familyNames = fontDatabase()->families();
d_ptr->m_enumPropertyManager->setEnumNames(familyProp, d_ptr->m_familyNames);
int idx = d_ptr->m_familyNames.indexOf(val.family());
if (idx == -1)
idx = 0;
d_ptr->m_enumPropertyManager->setValue(familyProp, idx);
d_ptr->m_propertyToFamily[property] = familyProp;
d_ptr->m_familyToProperty[familyProp] = property;
property->addSubProperty(familyProp);
QtProperty *pointSizeProp = d_ptr->m_intPropertyManager->addProperty();
pointSizeProp->setPropertyName(tr("Point Size"));
d_ptr->m_intPropertyManager->setValue(pointSizeProp, val.pointSize());
d_ptr->m_intPropertyManager->setMinimum(pointSizeProp, 1);
d_ptr->m_propertyToPointSize[property] = pointSizeProp;
d_ptr->m_pointSizeToProperty[pointSizeProp] = property;
property->addSubProperty(pointSizeProp);
QtProperty *boldProp = d_ptr->m_boolPropertyManager->addProperty();
boldProp->setPropertyName(tr("Bold"));
d_ptr->m_boolPropertyManager->setValue(boldProp, val.bold());
d_ptr->m_propertyToBold[property] = boldProp;
d_ptr->m_boldToProperty[boldProp] = property;
property->addSubProperty(boldProp);
QtProperty *italicProp = d_ptr->m_boolPropertyManager->addProperty();
italicProp->setPropertyName(tr("Italic"));
d_ptr->m_boolPropertyManager->setValue(italicProp, val.italic());
d_ptr->m_propertyToItalic[property] = italicProp;
d_ptr->m_italicToProperty[italicProp] = property;
property->addSubProperty(italicProp);
QtProperty *underlineProp = d_ptr->m_boolPropertyManager->addProperty();
underlineProp->setPropertyName(tr("Underline"));
d_ptr->m_boolPropertyManager->setValue(underlineProp, val.underline());
d_ptr->m_propertyToUnderline[property] = underlineProp;
d_ptr->m_underlineToProperty[underlineProp] = property;
property->addSubProperty(underlineProp);
QtProperty *strikeOutProp = d_ptr->m_boolPropertyManager->addProperty();
strikeOutProp->setPropertyName(tr("Strikeout"));
d_ptr->m_boolPropertyManager->setValue(strikeOutProp, val.strikeOut());
d_ptr->m_propertyToStrikeOut[property] = strikeOutProp;
d_ptr->m_strikeOutToProperty[strikeOutProp] = property;
property->addSubProperty(strikeOutProp);
QtProperty *kerningProp = d_ptr->m_boolPropertyManager->addProperty();
kerningProp->setPropertyName(tr("Kerning"));
d_ptr->m_boolPropertyManager->setValue(kerningProp, val.kerning());
d_ptr->m_propertyToKerning[property] = kerningProp;
d_ptr->m_kerningToProperty[kerningProp] = property;
property->addSubProperty(kerningProp);
}
Janik Zikovsky
committed
/**
Roman Tolchenov
committed
\reimp
*/
void QtFontPropertyManager::uninitializeProperty(QtProperty *property)
{
QtProperty *familyProp = d_ptr->m_propertyToFamily[property];
if (familyProp) {
d_ptr->m_familyToProperty.remove(familyProp);