diff options
author | Kai Koehne <kai.koehne@theqtcompany.com> | 2014-12-08 17:34:12 +0100 |
---|---|---|
committer | Kai Koehne <kai.koehne@theqtcompany.com> | 2014-12-10 09:44:27 +0100 |
commit | 71c248e2704225dc4e361699d08fe3b422a4da4f (patch) | |
tree | a9f12e4f3b7f3ec2315f833cfa6e4ac13b7b4285 /src | |
parent | cb57245ea95d2c1209bcc14f6d119d5ed912a0bf (diff) |
Expose findChild, findChildren methods to JS
Re-add the findChild, findChildren methods known from Qt Script.
Change-Id: I3db6be53ccd89a09b2c7de14ba7f96ebb26dbdbb
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@theqtcompany.com>
Reviewed-by: Niels Weber <niels.weber@theqtcompany.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/libs/installer/packagemanagergui.cpp | 20 | ||||
-rw-r--r-- | src/libs/installer/packagemanagergui.h | 3 | ||||
-rw-r--r-- | src/libs/installer/scriptengine.cpp | 31 | ||||
-rw-r--r-- | src/libs/installer/scriptengine.h | 2 |
4 files changed, 55 insertions, 1 deletions
diff --git a/src/libs/installer/packagemanagergui.cpp b/src/libs/installer/packagemanagergui.cpp index 4653c7ff6..5b9e7493a 100644 --- a/src/libs/installer/packagemanagergui.cpp +++ b/src/libs/installer/packagemanagergui.cpp @@ -698,6 +698,26 @@ void PackageManagerGui::setSettingsButtonEnabled(bool enabled) btn->setEnabled(enabled); } +/** + Returns the first descendant of \a parent that has \a objectName as name. + + This method is meant to be invoked from script. + */ +QObject *PackageManagerGui::findChild(QObject *parent, const QString &objectName) +{ + return parent->findChild<QObject*>(objectName); +} + +/** + Returns all descendants of \a parent that have \a objectName as name. + + This method is meant to be invoked from script. + */ +QList<QObject *> PackageManagerGui::findChildren(QObject *parent, const QString &objectName) +{ + return parent->findChildren<QObject*>(objectName); +} + void PackageManagerGui::customButtonClicked(int which) { if (QWizard::WizardButton(which) == QWizard::CustomButton1 && d->m_showSettingsButton) diff --git a/src/libs/installer/packagemanagergui.h b/src/libs/installer/packagemanagergui.h index 2830b1b3d..f99d65593 100644 --- a/src/libs/installer/packagemanagergui.h +++ b/src/libs/installer/packagemanagergui.h @@ -90,6 +90,9 @@ public: Q_INVOKABLE void showSettingsButton(bool show); Q_INVOKABLE void setSettingsButtonEnabled(bool enable); + Q_INVOKABLE QObject *findChild(QObject *parent, const QString &objectName); + Q_INVOKABLE QList<QObject*> findChildren(QObject *parent, const QString &objectName); + void updateButtonLayout(); static QWizard::WizardStyle getStyle(const QString &name); diff --git a/src/libs/installer/scriptengine.cpp b/src/libs/installer/scriptengine.cpp index c67295f57..d15357e0d 100644 --- a/src/libs/installer/scriptengine.cpp +++ b/src/libs/installer/scriptengine.cpp @@ -225,6 +225,22 @@ namespace QInstaller { */ /*! + \qmlmethod object gui::findChild(object parent, string objectName) + + Returns the first descendant of \a parent that has \a objectName as name. + + \sa QObject::findChild +*/ + +/*! + \qmlmethod object[] gui::findChildren(object parent, string objectName) + + Returns all descendants of \a parent that have \a objectName as name. + + \sa QObject::findChildren +*/ + +/*! \qmlsignal gui::interrupted() */ @@ -293,6 +309,21 @@ ScriptEngine::ScriptEngine(PackageManagerCore *core) proxy.property(QLatin1String("componentByName"))); } +QJSValue ScriptEngine::newQObject(QObject *object) +{ + QJSValue obj = m_engine.newQObject(object); + + // add findChild(), findChildren() methods known from QtScript + QJSValue findChild = m_engine.evaluate( + QLatin1String("(function() { return gui.findChild(this, arguments[0]); })")); + QJSValue findChildren = m_engine.evaluate( + QLatin1String("(function() { return gui.findChildren(this, arguments[0]); })")); + obj.setProperty(QLatin1String("findChild"), findChild); + obj.setProperty(QLatin1String("findChildren"), findChildren); + + return obj; +} + QJSValue ScriptEngine::evaluate(const QString &program, const QString &fileName, int lineNumber) { return m_engine.evaluate(program, fileName, lineNumber); diff --git a/src/libs/installer/scriptengine.h b/src/libs/installer/scriptengine.h index 5046bd14f..c4352d4ca 100644 --- a/src/libs/installer/scriptengine.h +++ b/src/libs/installer/scriptengine.h @@ -53,7 +53,7 @@ public: explicit ScriptEngine(PackageManagerCore *core = 0); QJSValue globalObject() const { return m_engine.globalObject(); } - QJSValue newQObject(QObject *object) { return m_engine.newQObject(object); } + QJSValue newQObject(QObject *object); QJSValue evaluate(const QString &program, const QString &fileName = QString(), int lineNumber = 1); |