summaryrefslogtreecommitdiffstats
path: root/src/widgets
diff options
context:
space:
mode:
authorMark Brand <mabrand@mabrand.nl>2012-03-12 21:05:31 +0100
committerQt by Nokia <qt-info@nokia.com>2012-03-15 09:50:18 +0100
commit6d67ff4061c7648708cdc2e462f248a4a8f486db (patch)
tree3897c089ee5d8a25dda23514025e5982cf6179d9 /src/widgets
parent96fe217467ee063cbadd8518694fb0313e78272f (diff)
improve processing stylesheet properties
By scanning the properties in reverse order we don't have to save properties in the list only to remove them later when the occur again. It's also unnecessary to cache the values since they can be easily plucked out of decls. Various other tests can be done once per property instead of once per property occurence in decls. Change-Id: I81cf60c59efaeed57fc9c12df98279d6cae116cd Reviewed-by: Robin Burchell <robin+qt@viroteck.net> Reviewed-by: Rick Stockton <rickstockton@reno-computerhelp.com> Reviewed-by: Girish Ramakrishnan <girish.1.ramakrishnan@nokia.com> Reviewed-by: John Brooks <john.brooks@dereferenced.net>
Diffstat (limited to 'src/widgets')
-rw-r--r--src/widgets/styles/qstylesheetstyle.cpp49
1 files changed, 24 insertions, 25 deletions
diff --git a/src/widgets/styles/qstylesheetstyle.cpp b/src/widgets/styles/qstylesheetstyle.cpp
index a10a531b7d..0e928b13c2 100644
--- a/src/widgets/styles/qstylesheetstyle.cpp
+++ b/src/widgets/styles/qstylesheetstyle.cpp
@@ -2498,22 +2498,32 @@ void QStyleSheetStyle::setGeometry(QWidget *w)
void QStyleSheetStyle::setProperties(QWidget *w)
{
- // we have two data structures here: a hash of property -> value for lookup,
- // and a vector giving properties in the order they are specified.
- //
- // this means we only set a property once (thanks to the hash) but we set
- // properties in the order they are specified.
- QHash<QString, QVariant> propertyHash;
- QVector<QString> properties;
+ // The final occurrence of each property is authoritative.
+ // Set value for each property in the order of property final occurrence
+ // since properties interact.
+
const QVector<Declaration> decls = declarations(styleRules(w), QString());
+ QVector<int> finals; // indices in reverse order of each property's final occurrence
+
+ {
+ // scan decls for final occurence of each "qproperty"
+ QSet<const QString> propertySet;
+ for (int i = decls.count() - 1; i >= 0; --i) {
+ const QString property = decls.at(i).d->property;
+ if (!property.startsWith(QStringLiteral("qproperty-"), Qt::CaseInsensitive))
+ continue;
+ if (!propertySet.contains(property)) {
+ propertySet.insert(property);
+ finals.append(i);
+ }
+ }
+ }
- // run through the declarations in order
- for (int i = 0; i < decls.count(); i++) {
- const Declaration &decl = decls.at(i);
+ for (int i = finals.count() - 1; i >= 0; --i) {
+ const Declaration &decl = decls.at(finals[i]);
QString property = decl.d->property;
- if (!property.startsWith(QStringLiteral("qproperty-"), Qt::CaseInsensitive))
- continue;
property.remove(0, 10); // strip "qproperty-"
+
const QMetaObject *metaObject = w->metaObject();
int index = metaObject->indexOfProperty(property.toLatin1());
if (index == -1) {
@@ -2525,6 +2535,7 @@ void QStyleSheetStyle::setProperties(QWidget *w)
qWarning() << w << " cannot design property named " << property;
continue;
}
+
QVariant v;
const QVariant value = w->property(property.toLatin1());
switch (value.type()) {
@@ -2541,19 +2552,7 @@ void QStyleSheetStyle::setProperties(QWidget *w)
default: v = decl.d->values.at(0).variant; break;
}
- if (propertyHash.contains(property)) {
- // we're ignoring the original appearance of this property
- properties.remove(properties.indexOf(property));
- }
-
- propertyHash[property] = v;
- properties.append(property);
- }
-
- // apply the values from left to right order
- for (int i = 0; i < properties.count(); i++) {
- const QString &property = properties.at(i);
- w->setProperty(property.toLatin1(), propertyHash[property]);
+ w->setProperty(property.toLatin1(), v);
}
}