diff options
author | Kai Koehne <kai.koehne@theqtcompany.com> | 2015-01-06 10:56:49 +0100 |
---|---|---|
committer | Kai Koehne <kai.koehne@theqtcompany.com> | 2015-01-08 08:59:06 +0100 |
commit | f87efd7c14e0a332341e58ed1e52d46328e31d03 (patch) | |
tree | 8c5bbf677eb2bdecad92abe60f54acb95fb4e5bf /src/libs/installer/scriptengine.cpp | |
parent | 8d86c06aef110ad6cf6f1dcb6af56b19ddbe7f24 (diff) |
Fix objects returned by gui methods
We need to make sure objects like pageWidgetByObjectName are augmented
too (so that one can access child objects). This is achieved by
a proxy object that augments all raw QObject * and QWidget * return
values.
This fixes e.g. the dynamicpage example.
Task-number: QTIFW-605
Change-Id: If26dc59220946a7445ef0f9ec7caa15e5b04eaa8
Reviewed-by: Niels Weber <niels.weber@theqtcompany.com>
Diffstat (limited to 'src/libs/installer/scriptengine.cpp')
-rw-r--r-- | src/libs/installer/scriptengine.cpp | 155 |
1 files changed, 146 insertions, 9 deletions
diff --git a/src/libs/installer/scriptengine.cpp b/src/libs/installer/scriptengine.cpp index ba5edd1c0..2ab7c47f8 100644 --- a/src/libs/installer/scriptengine.cpp +++ b/src/libs/installer/scriptengine.cpp @@ -189,40 +189,139 @@ namespace QInstaller { */ /*! + \qmlsignal gui::interrupted() +*/ + +/*! + \qmlsignal gui::languageChanged() +*/ + +/*! + \qmlsignal gui::finishButtonClicked() +*/ + +/*! + \qmlsignal gui::gotRestarted() +*/ + +/*! + \qmlsignal gui::settingsButtonClicked(); +*/ + +GuiProxy::GuiProxy(ScriptEngine *engine, QObject *parent) : + QObject(parent), + m_engine(engine), + m_gui(0) +{ +} + +void GuiProxy::setPackageManagerGui(PackageManagerGui *gui) +{ + if (m_gui) { + disconnect(m_gui, &PackageManagerGui::interrupted, this, &GuiProxy::interrupted); + disconnect(m_gui, &PackageManagerGui::languageChanged, this, &GuiProxy::languageChanged); + disconnect(m_gui, &PackageManagerGui::finishButtonClicked, this, &GuiProxy::finishButtonClicked); + disconnect(m_gui, &PackageManagerGui::gotRestarted, this, &GuiProxy::gotRestarted); + disconnect(m_gui, &PackageManagerGui::settingsButtonClicked, this, &GuiProxy::settingsButtonClicked); + } + + m_gui = gui; + + if (m_gui) { + connect(m_gui, &PackageManagerGui::interrupted, this, &GuiProxy::interrupted); + connect(m_gui, &PackageManagerGui::languageChanged, this, &GuiProxy::languageChanged); + connect(m_gui, &PackageManagerGui::finishButtonClicked, this, &GuiProxy::finishButtonClicked); + connect(m_gui, &PackageManagerGui::gotRestarted, this, &GuiProxy::gotRestarted); + connect(m_gui, &PackageManagerGui::settingsButtonClicked, this, &GuiProxy::settingsButtonClicked); + } +} + +/*! \qmlmethod object gui::pageById(int id) */ +QJSValue GuiProxy::pageById(int id) const +{ + if (!m_gui) + return QJSValue(); + return m_engine->newQObject(m_gui->pageById(id)); +} /*! \qmlmethod object gui::pageByObjectName(string name) */ +QJSValue GuiProxy::pageByObjectName(const QString &name) const +{ + if (!m_gui) + return QJSValue(); + return m_engine->newQObject(m_gui->pageByObjectName(name)); +} /*! \qmlmethod object gui::currentPageWidget() */ +QJSValue GuiProxy::currentPageWidget() const +{ + if (!m_gui) + return QJSValue(); + return m_engine->newQObject(m_gui->currentPageWidget()); +} /*! \qmlmethod object gui::pageWidgetByObjectName(string name) */ +QJSValue GuiProxy::pageWidgetByObjectName(const QString &name) const +{ + if (!m_gui) + return QJSValue(); + return m_engine->newQObject(m_gui->pageWidgetByObjectName(name)); +} /*! \qmlmethod string gui::defaultButtonText(int wizardButton) */ +QString GuiProxy::defaultButtonText(int wizardButton) const +{ + if (!m_gui) + return QString(); + return m_gui->defaultButtonText(wizardButton); +} /*! \qmlmethod void gui::clickButton(int wizardButton, int delayInMs) */ +void GuiProxy::clickButton(int wizardButton, int delayInMs) +{ + if (m_gui) + m_gui->clickButton(wizardButton, delayInMs); +} /*! \qmlmethod boolean gui::isButtonEnabled(int wizardButton) */ +bool GuiProxy::isButtonEnabled(int wizardButton) +{ + if (!m_gui) + return false; + return m_gui->isButtonEnabled(wizardButton); +} /*! \qmlmethod void gui::showSettingsButton(boolean show) */ +void GuiProxy::showSettingsButton(bool show) +{ + if (m_gui) + m_gui->showSettingsButton(show); +} /*! \qmlmethod void gui::setSettingsButtonEnabled(boolean enable) */ +void GuiProxy::setSettingsButtonEnabled(bool enable) +{ + if (m_gui) + m_gui->setSettingsButtonEnabled(enable); +} /*! \qmlmethod object gui::findChild(object parent, string objectName) @@ -231,6 +330,10 @@ namespace QInstaller { \sa QObject::findChild */ +QJSValue GuiProxy::findChild(QObject *parent, const QString &objectName) +{ + return m_engine->newQObject(parent->findChild<QObject*>(objectName)); +} /*! \qmlmethod object[] gui::findChildren(object parent, string objectName) @@ -239,32 +342,66 @@ namespace QInstaller { \sa QObject::findChildren */ +QList<QJSValue> GuiProxy::findChildren(QObject *parent, const QString &objectName) +{ + QList<QJSValue> children; + foreach (QObject *child, parent->findChildren<QObject*>(objectName)) + children.append(m_engine->newQObject(child)); + return children; +} /*! - \qmlsignal gui::interrupted() + \qmlmethod void gui::cancelButtonClicked() */ +void GuiProxy::cancelButtonClicked() +{ + if (m_gui) + m_gui->cancelButtonClicked(); +} /*! - \qmlsignal gui::languageChanged() + \qmlmethod void gui::reject() */ +void GuiProxy::reject() +{ + if (m_gui) + m_gui->reject(); +} /*! - \qmlsignal gui::finishButtonClicked() + \qmlmethod void gui::rejectWithoutPrompt() */ +void GuiProxy::rejectWithoutPrompt() +{ + if (m_gui) + m_gui->rejectWithoutPrompt(); +} /*! - \qmlsignal gui::gotRestarted() + \qmlmethod void gui::showFinishedPage() */ +void GuiProxy::showFinishedPage() +{ + if (m_gui) + m_gui->showFinishedPage(); +} /*! - \qmlsignal gui::settingsButtonClicked(); + \qmlmethod void gui::setModified(boolean value) */ +void GuiProxy::setModified(bool value) +{ + if (m_gui) + m_gui->setModified(value); +} + /*! Constructs a script engine with \a core as parent. */ -ScriptEngine::ScriptEngine(PackageManagerCore *core) - : QObject(core) +ScriptEngine::ScriptEngine(PackageManagerCore *core) : + QObject(core), + m_guiProxy(new GuiProxy(this, this)) { QJSValue global = m_engine.globalObject(); global.setProperty(QLatin1String("console"), m_engine.newQObject(new ConsoleProxy)); @@ -304,6 +441,7 @@ ScriptEngine::ScriptEngine(PackageManagerCore *core) } 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("componentByName"), proxy.property(QLatin1String("componentByName"))); @@ -452,8 +590,7 @@ QJSValue ScriptEngine::callScriptMethod(const QJSValue &scriptContext, const QSt void ScriptEngine::setGuiQObject(QObject *guiQObject) { - QQmlEngine::setObjectOwnership(guiQObject, QQmlEngine::CppOwnership); - m_engine.globalObject().setProperty(QLatin1String("gui"), m_engine.newQObject(guiQObject)); + m_guiProxy->setPackageManagerGui(qobject_cast<PackageManagerGui*>(guiQObject)); } |