[libcalamares] Allow QML ViewSteps to expose a config object

This commit is contained in:
Adriaan de Groot 2020-02-12 17:51:10 +01:00
parent f0134aab71
commit 49ed97cb77
4 changed files with 33 additions and 0 deletions

View File

@ -29,6 +29,7 @@
#include "widgets/WaitingWidget.h"
#include <QQmlComponent>
#include <QQmlContext>
#include <QQmlEngine>
#include <QQuickItem>
#include <QQuickWidget>
@ -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

View File

@ -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();

View File

@ -194,3 +194,9 @@ WelcomeQmlViewStep::setCountry( const QString& countryCode, CalamaresUtils::GeoI
}
}
}
QObject*
WelcomeQmlViewStep::getConfig()
{
return &m_config;
}

View File

@ -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;