[libcalamares] Allow QML ViewSteps to expose a config object
This commit is contained in:
parent
f0134aab71
commit
49ed97cb77
@ -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
|
||||
|
@ -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();
|
||||
|
||||
|
@ -194,3 +194,9 @@ WelcomeQmlViewStep::setCountry( const QString& countryCode, CalamaresUtils::GeoI
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QObject*
|
||||
WelcomeQmlViewStep::getConfig()
|
||||
{
|
||||
return &m_config;
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user