aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@theqtcompany.com>2016-03-11 12:13:47 +0100
committerJ-P Nurmi <jpnurmi@theqtcompany.com>2016-03-15 20:04:55 +0000
commit28ce9872fd83e82c8ece0c70624c45ea2be5c58d (patch)
tree0f4eea19bec8d0238b592f7e4a516a8a930cdffb
parent8fa998cd5172a4411984e95c08df70a1e4aacbc4 (diff)
Revert popup style inheritance changes
This is a partial revert of "Fix style inheritance" (07e0dec) and "Fix style inheritance for popups" (a3dddf0). These changes made things too complex. It's easier to revert back to the original, and then apply the new popup style inheritance rules in the next commit. Change-Id: I2842261999d258a709739ee48a78ca23a2a1092a Reviewed-by: Mitch Curtis <mitch.curtis@theqtcompany.com>
-rw-r--r--src/controls/qquickstyle.cpp90
1 files changed, 36 insertions, 54 deletions
diff --git a/src/controls/qquickstyle.cpp b/src/controls/qquickstyle.cpp
index 0ca6558e..76524629 100644
--- a/src/controls/qquickstyle.cpp
+++ b/src/controls/qquickstyle.cpp
@@ -52,49 +52,51 @@ static QQuickStyle *attachedStyle(const QMetaObject *type, QObject *object, bool
return qobject_cast<QQuickStyle *>(qmlAttachedPropertiesObject(&idx, object, type, create));
}
-static QQuickStyle *findParentStyle(const QMetaObject *type, QObject *parent)
+static QQuickStyle *findParentStyle(const QMetaObject *type, QObject *object)
{
- if (!parent)
- return Q_NULLPTR;
-
- QQuickStyle *style = attachedStyle(type, parent);
- if (style)
- return style;
-
- // lookup object parent (window/popup)
- QObject *grandParent = parent->parent();
- if (grandParent) {
- QQuickStyle *style = findParentStyle(type, grandParent);
- if (style)
- return style;
- }
-
- QQuickItem *item = qobject_cast<QQuickItem *>(parent);
+ QQuickItem *item = qobject_cast<QQuickItem *>(object);
if (item) {
// lookup parent items
QQuickItem *parent = item->parentItem();
- if (parent) {
- QQuickStyle *style = findParentStyle(type, parent);
+ while (parent) {
+ QQuickStyle *style = attachedStyle(type, parent);
if (style)
return style;
+ parent = parent->parentItem();
}
// fallback to item's window
- QQuickStyle *style = findParentStyle(type, item->window());
- if (style)
- return style;
+ QQuickWindow *window = item->window();
+ if (window) {
+ QQuickStyle *style = attachedStyle(type, window);
+ if (style)
+ return style;
+ }
+ }
+
+ // lookup parent window
+ QQuickWindow *window = qobject_cast<QQuickWindow *>(object);
+ if (window) {
+ QQuickWindow *parentWindow = qobject_cast<QQuickWindow *>(window->parent());
+ if (parentWindow) {
+ QQuickStyle *style = attachedStyle(type, window);
+ if (style)
+ return style;
+ }
}
// fallback to engine (global)
- QQmlEngine *engine = qmlEngine(parent);
- if (engine) {
- QByteArray name = QByteArray("_q_") + type->className();
- QQuickStyle *style = engine->property(name).value<QQuickStyle*>();
- if (!style) {
- style = attachedStyle(type, engine, true);
- engine->setProperty(name, QVariant::fromValue(style));
+ if (object) {
+ QQmlEngine *engine = qmlEngine(object);
+ if (engine) {
+ QByteArray name = QByteArray("_q_") + type->className();
+ QQuickStyle *style = engine->property(name).value<QQuickStyle*>();
+ if (!style) {
+ style = attachedStyle(type, engine, true);
+ engine->setProperty(name, QVariant::fromValue(style));
+ }
+ return style;
}
- return style;
}
return Q_NULLPTR;
@@ -106,7 +108,8 @@ static QList<QQuickStyle *> findChildStyles(const QMetaObject *type, QObject *ob
QQuickItem *item = qobject_cast<QQuickItem *>(object);
if (!item) {
- if (QQuickWindow *window = qobject_cast<QQuickWindow *>(object)) {
+ QQuickWindow *window = qobject_cast<QQuickWindow *>(object);
+ if (window) {
item = window->contentItem();
foreach (QObject *child, window->children()) {
@@ -117,12 +120,6 @@ static QList<QQuickStyle *> findChildStyles(const QMetaObject *type, QObject *ob
children += style;
}
}
- } else if (QQuickPopup *popup = qobject_cast<QQuickPopup *>(object)) {
- item = popup->popupItem();
-
- QQuickStyle *style = attachedStyle(type, popup);
- if (style)
- children += style;
}
}
@@ -134,16 +131,6 @@ static QList<QQuickStyle *> findChildStyles(const QMetaObject *type, QObject *ob
else
children += findChildStyles(type, child);
}
-
- foreach (QObject *child, item->children()) {
- if (!qobject_cast<QQuickItem *>(child)) {
- QQuickStyle *style = attachedStyle(type, child);
- if (style)
- children += style;
- else
- children += findChildStyles(type, child);
- }
- }
}
return children;
@@ -205,16 +192,11 @@ void QQuickStyle::setParentStyle(QQuickStyle *style)
void QQuickStyle::init()
{
- QObject *parent = QObject::parent();
- if (!parent)
- return;
-
- QQuickItem *parentItem = qobject_cast<QQuickItem *>(parent);
- QQuickStyle *parentStyle = findParentStyle(metaObject(), parentItem ? parentItem->parentItem() : parent->parent());
+ QQuickStyle *parentStyle = findParentStyle(metaObject(), parent());
if (parentStyle)
setParentStyle(parentStyle);
- QList<QQuickStyle *> children = findChildStyles(metaObject(), parent);
+ QList<QQuickStyle *> children = findChildStyles(metaObject(), parent());
foreach (QQuickStyle *child, children)
child->setParentStyle(this);
}