AppletQuickItem: Fix finding own attached layout

Regression from 344dbeb938

BUG: 358849
REVIEW: 127073
This commit is contained in:
David Rosca 2016-02-19 13:23:26 +01:00
parent b6d636cc8f
commit 82e172cc9e
3 changed files with 24 additions and 4 deletions

View File

@ -50,7 +50,11 @@ AppletQuickItemPrivate::AppletQuickItemPrivate(Plasma::Applet *a, AppletQuickIte
applet(a),
expanded(false)
{
if (!a->pluginInfo().isValid()) {
}
void AppletQuickItemPrivate::init()
{
if (!applet->pluginInfo().isValid()) {
// This `qmlObject` is used in other parts of the code
qmlObject = new KDeclarative::QmlObject(q);
return;
@ -383,6 +387,7 @@ AppletQuickItem::AppletQuickItem(Plasma::Applet *applet, QQuickItem *parent)
: QQuickItem(parent),
d(new AppletQuickItemPrivate(applet, this))
{
d->init();
if (d->applet) {
d->appletPackage = d->applet->package();
}
@ -564,9 +569,6 @@ void AppletQuickItem::init()
d->compactRepresentationExpander->loadUrl(QUrl::fromLocalFile(compactExpanderPath));
}
//HACK: check the Layout properties we wrote
QQmlProperty p(this, "Layout.minimumWidth", QtQml::qmlContext(d->qmlObject->rootObject()));
d->compactRepresentationCheck();
qmlObject()->engine()->rootContext()->setBaseUrl(qmlObject()->source());
qmlObject()->engine()->setContextForObject(this, qmlObject()->engine()->rootContext());
@ -726,6 +728,21 @@ QObject *AppletQuickItem::rootItem()
return d->qmlObject->rootObject();
}
void AppletQuickItem::childEvent(QChildEvent *event)
{
// Added child may be QQuickLayoutAttached
if (event->added() && !d->ownLayout && d->currentRepresentationItem) {
// Child has not yet finished initialization at this point
QTimer::singleShot(0, this, [this]() {
if (!d->ownLayout) {
d->connectLayoutAttached(d->currentRepresentationItem);
}
});
}
QQuickItem::childEvent(event);
}
void AppletQuickItem::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
{
Q_UNUSED(oldGeometry)

View File

@ -146,6 +146,7 @@ protected:
KDeclarative::QmlObject *qmlObject();
//Reimplementation
void childEvent(QChildEvent *event) Q_DECL_OVERRIDE;
void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) Q_DECL_OVERRIDE;
void itemChange(ItemChange change, const ItemChangeData &value) Q_DECL_OVERRIDE;

View File

@ -55,6 +55,8 @@ class AppletQuickItemPrivate
public:
AppletQuickItemPrivate(Plasma::Applet *a, AppletQuickItem *item);
void init();
QQuickItem *createCompactRepresentationItem();
QQuickItem *createFullRepresentationItem();
QQuickItem *createCompactRepresentationExpanderItem();