[libcalamaresui] Move registration into Qml-service
- Registration of QML modules may need to be done for more parts of Calamares. Move into the library, out of the model. - Register for QML when using the QML sidebar.
This commit is contained in:
parent
1c9a2e8c5f
commit
0fd7fec25e
@ -28,6 +28,7 @@
|
||||
#include "progresstree/ProgressTreeView.h"
|
||||
#include "utils/CalamaresUtilsGui.h"
|
||||
#include "utils/Logger.h"
|
||||
#include "utils/Qml.h"
|
||||
#include "utils/Retranslator.h"
|
||||
|
||||
#include <QApplication>
|
||||
@ -133,6 +134,7 @@ CalamaresWindow::getWidgetSidebar( int desiredWidth )
|
||||
QWidget*
|
||||
CalamaresWindow::getQmlSidebar( int desiredWidth )
|
||||
{
|
||||
CalamaresUtils::registerCalamaresModels();
|
||||
QQuickWidget* w = new QQuickWidget( this );
|
||||
w->setSource( QUrl( ":/sidebar.qml" ) );
|
||||
return w;
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include "Qml.h"
|
||||
|
||||
#include "Branding.h"
|
||||
#include "ViewManager.h"
|
||||
#include "utils/Logger.h"
|
||||
|
||||
#include <QByteArray>
|
||||
@ -113,5 +114,25 @@ qmlSearchNames()
|
||||
return names;
|
||||
}
|
||||
|
||||
void
|
||||
registerCalamaresModels()
|
||||
{
|
||||
static bool done = false;
|
||||
if ( !done )
|
||||
{
|
||||
done = true;
|
||||
// Because branding and viewmanager have a parent (CalamaresApplication
|
||||
// and CalamaresWindow), they will not be deleted by QmlEngine.
|
||||
// https://doc.qt.io/qt-5/qtqml-cppintegration-data.html#data-ownership
|
||||
qmlRegisterSingletonType< Calamares::Branding >(
|
||||
"io.calamares.ui", 1, 0, "Branding", []( QQmlEngine*, QJSEngine* ) -> QObject* {
|
||||
return Calamares::Branding::instance();
|
||||
} );
|
||||
qmlRegisterSingletonType< Calamares::Branding >(
|
||||
"io.calamares.core", 1, 0, "ViewManager", []( QQmlEngine*, QJSEngine* ) -> QObject* {
|
||||
return Calamares::ViewManager::instance();
|
||||
} );
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace CalamaresUtils
|
||||
|
@ -28,6 +28,12 @@ class QQuickItem;
|
||||
|
||||
namespace CalamaresUtils
|
||||
{
|
||||
/** @brief Sets up global Calamares models for QML
|
||||
*
|
||||
* This needs to be called at least once to make the global Calamares
|
||||
* models (Branding, ViewManager, ...) available to QML.
|
||||
*/
|
||||
UIDLLEXPORT void registerCalamaresModels();
|
||||
|
||||
/** @brief Calls the QML method @p method on @p qmlObject
|
||||
*
|
||||
@ -53,17 +59,17 @@ enum class QmlSearch
|
||||
Both
|
||||
};
|
||||
|
||||
///@brief Names for the search terms (in config files)
|
||||
UIDLLEXPORT const NamedEnumTable< QmlSearch >& qmlSearchNames();
|
||||
|
||||
/** @brief Find a suitable QML file, given the search method and name hints
|
||||
*
|
||||
* Returns QString() if nothing is found (which would mean the module
|
||||
* is badly configured).
|
||||
*/
|
||||
QString searchQmlFile( QmlSearch method,
|
||||
UIDLLEXPORT QString searchQmlFile( QmlSearch method,
|
||||
const QString& configuredName,
|
||||
const Calamares::ModuleSystem::InstanceKey& i = Calamares::ModuleSystem::InstanceKey() );
|
||||
|
||||
///@brief Names for the search terms (in config files)
|
||||
const NamedEnumTable< QmlSearch >& qmlSearchNames();
|
||||
const Calamares::ModuleSystem::InstanceKey& i );
|
||||
|
||||
} // namespace CalamaresUtils
|
||||
|
||||
|
@ -67,27 +67,6 @@ changeQMLState( QMLAction action, QQuickItem* item )
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
registerCalamaresModels()
|
||||
{
|
||||
static bool done = false;
|
||||
if ( !done )
|
||||
{
|
||||
done = true;
|
||||
// Because branding and viewmanager have a parent (CalamaresApplication
|
||||
// and CalamaresWindow), they will not be deleted by QmlEngine.
|
||||
// https://doc.qt.io/qt-5/qtqml-cppintegration-data.html#data-ownership
|
||||
qmlRegisterSingletonType< Calamares::Branding >(
|
||||
"io.calamares.ui", 1, 0, "Branding", []( QQmlEngine*, QJSEngine* ) -> QObject* {
|
||||
return Calamares::Branding::instance();
|
||||
} );
|
||||
qmlRegisterSingletonType< Calamares::Branding >(
|
||||
"io.calamares.core", 1, 0, "ViewManager", []( QQmlEngine*, QJSEngine* ) -> QObject* {
|
||||
return Calamares::ViewManager::instance();
|
||||
} );
|
||||
}
|
||||
}
|
||||
|
||||
namespace Calamares
|
||||
{
|
||||
|
||||
@ -97,7 +76,7 @@ QmlViewStep::QmlViewStep( QObject* parent )
|
||||
, m_spinner( new WaitingWidget( tr( "Loading ..." ) ) )
|
||||
, m_qmlWidget( new QQuickWidget )
|
||||
{
|
||||
registerCalamaresModels();
|
||||
CalamaresUtils::registerCalamaresModels();
|
||||
|
||||
QVBoxLayout* layout = new QVBoxLayout( m_widget );
|
||||
layout->addWidget( m_spinner );
|
||||
|
Loading…
Reference in New Issue
Block a user