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/libs/installer/scriptengine.cpp | |
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/libs/installer/scriptengine.cpp')
-rw-r--r-- | src/libs/installer/scriptengine.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
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); |