From c23f2415bb5726297e49785f18644dd17d1b38d7 Mon Sep 17 00:00:00 2001 From: Aleix Pol Date: Wed, 16 Mar 2016 12:32:25 +0100 Subject: [PATCH] Make it possible for an applet to offer a test object Makes it possible for plasmoids to test themselves in the different shells by providing API to extract the object that will test the plasmoid instance. REVIEW: 127345 --- src/plasma/private/packages.cpp | 1 + src/plasmaquick/appletquickitem.cpp | 15 +++++++++++++++ src/plasmaquick/appletquickitem.h | 1 + src/plasmaquick/private/appletquickitem_p.h | 1 + 4 files changed, 18 insertions(+) diff --git a/src/plasma/private/packages.cpp b/src/plasma/private/packages.cpp index a5ba81abe..0392e8ddb 100644 --- a/src/plasma/private/packages.cpp +++ b/src/plasma/private/packages.cpp @@ -43,6 +43,7 @@ namespace Plasma void ChangeableMainScriptPackage::initPackage(KPackage::Package *package) { package->addFileDefinition("mainscript", QStringLiteral("ui/main.qml"), i18n("Main Script File")); + package->addFileDefinition("test", QStringLiteral("tests/test.qml"), i18n("Tests")); package->setRequired("mainscript", true); } diff --git a/src/plasmaquick/appletquickitem.cpp b/src/plasmaquick/appletquickitem.cpp index 9242e9e5a..bc877d0d7 100644 --- a/src/plasmaquick/appletquickitem.cpp +++ b/src/plasmaquick/appletquickitem.cpp @@ -645,6 +645,21 @@ QQmlComponent *AppletQuickItem::fullRepresentation() return d->fullRepresentation; } +QObject *AppletQuickItem::testItem() +{ + if (!d->testItem) { + const QUrl url = QUrl::fromLocalFile(d->appletPackage.filePath("test")); + if (url.isEmpty()) { + return nullptr; + } + + d->testItem = d->qmlObject->createObjectFromSource(url, QtQml::qmlContext(rootItem())); + d->testItem->setProperty("plasmoidItem", QVariant::fromValue(this)); + } + + return d->testItem; +} + void AppletQuickItem::setFullRepresentation(QQmlComponent *component) { if (d->fullRepresentation == component) { diff --git a/src/plasmaquick/appletquickitem.h b/src/plasmaquick/appletquickitem.h index 4f25f5d8d..99fcf1b42 100644 --- a/src/plasmaquick/appletquickitem.h +++ b/src/plasmaquick/appletquickitem.h @@ -105,6 +105,7 @@ public: QQuickItem *compactRepresentationItem(); QQuickItem *fullRepresentationItem(); QObject *rootItem(); + QObject *testItem(); ////PROPERTY ACCESSORS int switchWidth() const; diff --git a/src/plasmaquick/private/appletquickitem_p.h b/src/plasmaquick/private/appletquickitem_p.h index 9c2473462..143693576 100644 --- a/src/plasmaquick/private/appletquickitem_p.h +++ b/src/plasmaquick/private/appletquickitem_p.h @@ -90,6 +90,7 @@ public: QPointer fullRepresentationItem; QPointer compactRepresentationExpanderItem; QPointer currentRepresentationItem; + QPointer testItem; //Attached layout objects: own and the representation's one QPointer representationLayout;