Index: leahi.pro =================================================================== diff -u -rd862dfcd402206e33b314c458e41c13b684a4565 -rf20fa155dca799c332189f8d3932e35b5c4ef84a --- leahi.pro (.../leahi.pro) (revision d862dfcd402206e33b314c458e41c13b684a4565) +++ leahi.pro (.../leahi.pro) (revision f20fa155dca799c332189f8d3932e35b5c4ef84a) @@ -704,7 +704,8 @@ VER_REVIS="\\\"${buildNumber}\\\"" \ VER_REVIS_DEV=\\\"$$system( date "+%m%d%H%M" )\\\" \ VER_APPLY=\\\"$$system( touch -m main.cpp )\\\" \ - VER_BRANCH=\\\"$$system( git rev-parse --abbrev-ref HEAD )\\\" + VER_BRANCH=\\\"$$system( git rev-parse --abbrev-ref HEAD )\\\" \ + QML_PATH=\\\"$$PWD/sources/gui\\\" # Additional import path used to resolve QML modules in Qt Creator's code model QML_IMPORT_PATH = Index: main.cpp =================================================================== diff -u -ra5760947d3ed0d2748ba023a1c25e3c6aa0b1de1 -rf20fa155dca799c332189f8d3932e35b5c4ef84a --- main.cpp (.../main.cpp) (revision a5760947d3ed0d2748ba023a1c25e3c6aa0b1de1) +++ main.cpp (.../main.cpp) (revision f20fa155dca799c332189f8d3932e35b5c4ef84a) @@ -99,6 +99,7 @@ bool gConsoleoutFrameInterface = false ; bool gConsoleoutCanInterface = false ; +bool gReloadQML = false ; bool gEnableDryDemo = false ; QString gActiveCANBus = "can0"; @@ -127,6 +128,7 @@ * --help-all Displays help including Qt specific * options. * -v, --version Displays version information. + * -r, --reload-qml Enable QML reload/refresh with F5 key * -c, --canOut Show the Can Frame Output * -m, --msgOut Show the Message Output * -l, --logOut Show the Logs Output @@ -181,6 +183,12 @@ parser.addHelpOption(); parser.addVersionOption(); + // --- -r : reload + QCommandLineOption optionReloadQML( + QStringList() << "r" << "reload-qml", + QCoreApplication::translate("main", "Enable QML reload/refresh with F5 key")); + parser.addOption(optionReloadQML); + // --- -c : canOut QCommandLineOption optionConsoleoutCanInterface( QStringList() << "c" << "canOut", @@ -355,6 +363,7 @@ gDisableCheckInLog = parser.isSet(optionDisableCheckInLog ); gDisableAcknowLog = parser.isSet(optionDisableAcknowLog ); + gReloadQML = parser.isSet(optionReloadQML ); gEnableDryDemo = parser.isSet(optionEnableDryDemo ); gEnableManufacturing = parser.isSet(optionEnableManufacturing ); Index: sources/gui/GuiGlobals.cpp =================================================================== diff -u -rd862dfcd402206e33b314c458e41c13b684a4565 -rf20fa155dca799c332189f8d3932e35b5c4ef84a --- sources/gui/GuiGlobals.cpp (.../GuiGlobals.cpp) (revision d862dfcd402206e33b314c458e41c13b684a4565) +++ sources/gui/GuiGlobals.cpp (.../GuiGlobals.cpp) (revision f20fa155dca799c332189f8d3932e35b5c4ef84a) @@ -206,7 +206,53 @@ _viewer->engine()->addImportPath("qrc:/plugins"); //DEBUG: qDebug() << _viewer->engine()->importPathList(); _viewer->setSource(QStringLiteral("qrc:/main.qml")); + + // if reload QML build arguement is set then set reloadable main.qml source + if ( gReloadQML) { + const QUrl mainQML(QUrl::fromLocalFile(QStringLiteral("%1/qml/main.qml").arg(QML_PATH))); + _viewer->setReloadSource(mainQML); + } + LOG_DEBUG("MainView started"); return true; } + + /*! + * \brief setReloadSource + * \param vUrl - local top level qml file to set as reloadble source + * \details Source code url used to reload the qml during developing without requiring an application restart + */ + void MainView::setReloadSource(QUrl vUrl) + { + _reloadSource = vUrl; + } + + /*! + * \brief reload + * \details Used to reload the qml during developing without requiring an application restart + */ + void MainView::reload() + { + engine()->clearComponentCache(); + setSource(_reloadSource.isEmpty() ? source() : _reloadSource); + qDebug() << "QML reloaded."; + } + + /*! + * \brief keyPressEvent + * \param vEvent - QKeyEvent user key input + * \details event handler for input key events + */ + void MainView::keyPressEvent(QKeyEvent *vEvent) + { + // Enable reloading of the QML files for quicker development + if ( gReloadQML ) { + if (vEvent->key() == Qt::Key_F5) + { + QMetaObject::invokeMethod(this, &MainView::reload, Qt::QueuedConnection); + } + } + + QQuickView::keyPressEvent(vEvent); + } } Index: sources/gui/GuiGlobals.h =================================================================== diff -u -rd862dfcd402206e33b314c458e41c13b684a4565 -rf20fa155dca799c332189f8d3932e35b5c4ef84a --- sources/gui/GuiGlobals.h (.../GuiGlobals.h) (revision d862dfcd402206e33b314c458e41c13b684a4565) +++ sources/gui/GuiGlobals.h (.../GuiGlobals.h) (revision f20fa155dca799c332189f8d3932e35b5c4ef84a) @@ -36,6 +36,17 @@ emit eventSpy(vEvent); return QQuickView::event(vEvent); } + + public: + void setReloadSource(QUrl vUrl); + QUrl _reloadSource; + + private Q_SLOTS: + void reload(); + + private: + void keyPressEvent(QKeyEvent *vEvent) override; + signals: void eventSpy(QEvent* vEvent); }; Index: sources/main.h =================================================================== diff -u -ra5760947d3ed0d2748ba023a1c25e3c6aa0b1de1 -rf20fa155dca799c332189f8d3932e35b5c4ef84a --- sources/main.h (.../main.h) (revision a5760947d3ed0d2748ba023a1c25e3c6aa0b1de1) +++ sources/main.h (.../main.h) (revision f20fa155dca799c332189f8d3932e35b5c4ef84a) @@ -98,6 +98,7 @@ extern bool gConsoleoutFrameInterface ; extern bool gConsoleoutCanInterface ; +extern bool gReloadQML ; extern bool gEnableDryDemo ; extern QString gActiveCANBus ; extern bool gEnableManufacturing ;