diff --git a/src/libcalamaresui/viewpages/QmlViewStep.cpp b/src/libcalamaresui/viewpages/QmlViewStep.cpp index 582389a5e..7a38fb588 100644 --- a/src/libcalamaresui/viewpages/QmlViewStep.cpp +++ b/src/libcalamaresui/viewpages/QmlViewStep.cpp @@ -29,6 +29,7 @@ #include "widgets/WaitingWidget.h" #include +#include #include #include #include @@ -209,6 +210,11 @@ QmlViewStep::loadComplete() // It is marked \internal in the Qt sources, but does exactly // what is needed: sets up visual parent by replacing the root // item, and handling resizes. + QObject* config = this->getConfig(); + if ( config ) + { + m_qmlWidget->engine()->rootContext()->setContextProperty( "config", config ); + } m_qmlWidget->setContent( QUrl( m_qmlFileName ), m_qmlComponent, m_qmlObject ); showQml(); } @@ -336,4 +342,10 @@ QmlViewStep::showFailedQml() m_spinner->setText( prettyName() + ' ' + tr( "Loading failed." ) ); } +QObject* +QmlViewStep::getConfig() +{ + return nullptr; +} + } // namespace Calamares diff --git a/src/libcalamaresui/viewpages/QmlViewStep.h b/src/libcalamaresui/viewpages/QmlViewStep.h index 46ba29a53..038569927 100644 --- a/src/libcalamaresui/viewpages/QmlViewStep.h +++ b/src/libcalamaresui/viewpages/QmlViewStep.h @@ -76,6 +76,18 @@ public: /// @brief Configure search paths; subclasses should call this as well virtual void setConfigurationMap( const QVariantMap& configurationMap ) override; +protected: + /** @brief Gets a pointer to the Config of this view step + * + * Parts of the configuration of the viewstep can be passed to QML + * by placing them in a QObject (as properties). The default + * implementation returns nullptr, for no-config. + * + * Ownership of the config object remains with the ViewStep; it is possible + * to return a pointer to a member variable. + */ + virtual QObject* getConfig(); + private Q_SLOTS: void loadComplete(); diff --git a/src/modules/welcomeq/WelcomeQmlViewStep.cpp b/src/modules/welcomeq/WelcomeQmlViewStep.cpp index fbed4c382..580b183d1 100644 --- a/src/modules/welcomeq/WelcomeQmlViewStep.cpp +++ b/src/modules/welcomeq/WelcomeQmlViewStep.cpp @@ -194,3 +194,9 @@ WelcomeQmlViewStep::setCountry( const QString& countryCode, CalamaresUtils::GeoI } } } + +QObject* +WelcomeQmlViewStep::getConfig() +{ + return &m_config; +} diff --git a/src/modules/welcomeq/WelcomeQmlViewStep.h b/src/modules/welcomeq/WelcomeQmlViewStep.h index 2bfe448a3..a497f4c40 100644 --- a/src/modules/welcomeq/WelcomeQmlViewStep.h +++ b/src/modules/welcomeq/WelcomeQmlViewStep.h @@ -61,6 +61,9 @@ public: Calamares::RequirementsList checkRequirements() override; +protected: + QObject* getConfig() override; + private: // TODO: a generic QML viewstep should return a config object from a method Config m_config;