summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristoph VogtlÃĪnder <c.vogtlaender@sigma-surface-science.com>2015-03-11 10:10:43 +0100
committerKarsten Heimrich <karsten.heimrich@theqtcompany.com>2015-03-13 10:16:51 +0000
commit17e29fc8d3e7d524ce6207c23ac62525811ef189 (patch)
tree7ae795b5a7673508762ab3e8d171855332e9529e
parent0a49b33773e6ff2ec7ec4278b0a5a380f58457b0 (diff)
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 <niels.weber@theqtcompany.com> Reviewed-by: Karsten Heimrich <karsten.heimrich@theqtcompany.com>
-rw-r--r--src/libs/installer/scriptengine.cpp31
-rw-r--r--src/libs/installer/scriptengine.h1
-rw-r--r--src/libs/installer/scriptengine_p.h1
-rw-r--r--tests/auto/installer/scriptengine/tst_scriptengine.cpp16
4 files changed, 39 insertions, 10 deletions
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<Component*> 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<Component*> 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:
diff --git a/tests/auto/installer/scriptengine/tst_scriptengine.cpp b/tests/auto/installer/scriptengine/tst_scriptengine.cpp
index 23c4b2c4c..0bbb79060 100644
--- a/tests/auto/installer/scriptengine/tst_scriptengine.cpp
+++ b/tests/auto/installer/scriptengine/tst_scriptengine.cpp
@@ -200,6 +200,8 @@ private slots:
QCOMPARE(global.hasProperty(QLatin1String("InstallerProxy")), true);
QCOMPARE(global.property(QLatin1String("InstallerProxy"))
.hasProperty(QLatin1String("componentByName")), true);
+ QCOMPARE(global.property(QLatin1String("InstallerProxy"))
+ .hasProperty(QLatin1String("components")), true);
QCOMPARE(global.hasProperty(QLatin1String("QDesktopServices")), true);
QCOMPARE(global.property(QLatin1String("QDesktopServices"))
@@ -302,6 +304,20 @@ private slots:
QCOMPARE(value.isError(), true);
}
+ void testComponents()
+ {
+ const QString script = QString::fromLatin1("var components = installer.components();"
+ "\n"
+ "print(components[0].name);");
+
+ setExpectedScriptOutput("\"component.test.name\"");
+ const QJSValue value = m_scriptEngine->evaluate(script);
+ if (value.isError()) {
+ QFAIL(qPrintable(QString::fromLatin1("ScriptEngine error:\n %1").arg(
+ value.toString())));
+ }
+ }
+
void loadSimpleComponentScript()
{
try {