From 71209b323ad0e0a31bc242e6c94feda146842d02 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Sun, 16 Jun 2019 13:06:34 +0200 Subject: [PATCH] [libcalamaresui] Call QML methods on start and stop - Use onActivate() and onLeave() in QML as well, to start and stop the slideshow. --- src/libcalamaresui/ExecutionViewStep.cpp | 31 ++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/libcalamaresui/ExecutionViewStep.cpp b/src/libcalamaresui/ExecutionViewStep.cpp index f8f9ea03b..047fcede0 100644 --- a/src/libcalamaresui/ExecutionViewStep.cpp +++ b/src/libcalamaresui/ExecutionViewStep.cpp @@ -160,10 +160,40 @@ ExecutionViewStep::loadQml() } } +/** @brief Calls the QML method @p method() + * + * Pass in only the name of the method (e.g. onActivate). This function + * checks if the method exists (with no arguments) before trying to + * call it, so that no warnings are printed due to missing methods. + * + * If there is a return value from the QML method, it is logged (but not otherwise used). + */ +void +callQMLFunction( QQuickItem* qmlObject, const char* method ) +{ + QByteArray methodSignature( method ); + methodSignature.append( "()" ); + + if ( qmlObject && qmlObject->metaObject()->indexOfMethod( methodSignature ) >= 0 ) + { + QVariant returnValue; + QMetaObject::invokeMethod( qmlObject, method, Q_RETURN_ARG( QVariant, returnValue ) ); + if ( !returnValue.isNull() ) + { + cDebug() << "QML" << methodSignature << "returned" << returnValue; + } + } + else if ( qmlObject ) + { + cDebug() << "QML" << methodSignature << "is missing."; + } +} + void ExecutionViewStep::onActivate() { loadQml(); + callQMLFunction( m_qmlObject, "onActivate" ); JobQueue* queue = JobQueue::instance(); foreach ( const QString& instanceKey, m_jobInstanceKeys ) @@ -209,6 +239,7 @@ ExecutionViewStep::updateFromJobQueue( qreal percent, const QString& message ) void ExecutionViewStep::onLeave() { + callQMLFunction( m_qmlObject, "onLeave" ); delete m_qmlObject; m_qmlObject = nullptr; }