From 17e29fc8d3e7d524ce6207c23ac62525811ef189 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20Vogtl=C3=A4nder?= Date: Wed, 11 Mar 2015 10:10:43 +0100 Subject: fix empty installer.components array Make sure the current list of components is used when referencing installer.components in a controller script. Change-Id: I9468110d61a958f13edba66da0059d6622aa7037 Task-number: QTIFW-601 Reviewed-by: Niels Weber Reviewed-by: Karsten Heimrich --- src/libs/installer/scriptengine.cpp | 31 +++++++++++++++++++++---------- src/libs/installer/scriptengine.h | 1 + src/libs/installer/scriptengine_p.h | 1 + 3 files changed, 23 insertions(+), 10 deletions(-) (limited to 'src/libs/installer') diff --git a/src/libs/installer/scriptengine.cpp b/src/libs/installer/scriptengine.cpp index 0b85ffa6e..fe7220a49 100644 --- a/src/libs/installer/scriptengine.cpp +++ b/src/libs/installer/scriptengine.cpp @@ -56,6 +56,20 @@ namespace QInstaller { Returns a global object. */ +QJSValue InstallerProxy::components() const +{ + if (m_core) { + const QList all = m_core->components(PackageManagerCore::ComponentType::All); + QJSValue scriptComponentsObject = m_engine->newArray(all.count()); + for (int i = 0; i < all.count(); ++i) { + Component *const component = all.at(i); + QQmlEngine::setObjectOwnership(component, QQmlEngine::CppOwnership); + scriptComponentsObject.setProperty(i, m_engine->newQObject(component)); + } + return scriptComponentsObject; + } + return m_engine->newArray(); +} QJSValue InstallerProxy::componentByName(const QString &componentName) { @@ -253,21 +267,13 @@ ScriptEngine::ScriptEngine(PackageManagerCore *core) : QQmlEngine::setObjectOwnership(core, QQmlEngine::CppOwnership); global.setProperty(QLatin1String("installer"), m_engine.newQObject(core)); connect(core, SIGNAL(guiObjectChanged(QObject*)), this, SLOT(setGuiQObject(QObject*))); - - const QList all = core->components(PackageManagerCore::ComponentType::All); - QJSValue scriptComponentsObject = m_engine.newArray(all.count()); - for (int i = 0; i < all.count(); ++i) { - Component *const component = all.at(i); - QQmlEngine::setObjectOwnership(component, QQmlEngine::CppOwnership); - scriptComponentsObject.setProperty(i, newQObject(component)); - } - global.property(QLatin1String("installer")).setProperty(QLatin1String("components"), - scriptComponentsObject); } else { global.setProperty(QLatin1String("installer"), m_engine.newQObject(new QObject)); } global.setProperty(QLatin1String("gui"), m_engine.newQObject(m_guiProxy)); + global.property(QLatin1String("installer")).setProperty(QLatin1String("components"), + proxy.property(QLatin1String("components"))); global.property(QLatin1String("installer")).setProperty(QLatin1String("componentByName"), proxy.property(QLatin1String("componentByName"))); } @@ -313,6 +319,11 @@ QJSValue ScriptEngine::newQObject(QObject *object) return jsValue; } +QJSValue ScriptEngine::newArray(uint length) +{ + return m_engine.newArray(length); +} + /*! Evaluates \a program, using \a lineNumber as the base line number, and returns the results of the evaluation. \a fileName is used for error reporting. diff --git a/src/libs/installer/scriptengine.h b/src/libs/installer/scriptengine.h index 9fe0d2e75..eac669f8b 100644 --- a/src/libs/installer/scriptengine.h +++ b/src/libs/installer/scriptengine.h @@ -55,6 +55,7 @@ public: QJSValue globalObject() const { return m_engine.globalObject(); } QJSValue newQObject(QObject *object); + QJSValue newArray(uint length = 0); QJSValue evaluate(const QString &program, const QString &fileName = QString(), int lineNumber = 1); diff --git a/src/libs/installer/scriptengine_p.h b/src/libs/installer/scriptengine_p.h index 54b6a4fc2..1b1e408d0 100644 --- a/src/libs/installer/scriptengine_p.h +++ b/src/libs/installer/scriptengine_p.h @@ -68,6 +68,7 @@ public: : m_engine(engine), m_core(core) {} public slots: + QJSValue components() const; QJSValue componentByName(const QString &componentName); private: -- cgit v1.2.3