1#ifndef QMLEXECUTORGUIIMPL_H
2#define QMLEXECUTORGUIIMPL_H
9#include <QDesktopServices>
13#include <QDesktopServices>
17#include <QtQml/QQmlError>
18#include <QtQml/QQmlEngine>
19#include <QtQml/QQmlContext>
21#include "ui_qmlexecutor.h"
40 , _widget(new QWidget)
41 , _qmlUpdateCheckTimer(this)
42 , _CANBusModel(nullptr)
44 _ui->setupUi(_widget);
45 _ui->logWindow->setVisible(
false);
47 _ui->splitter->setCollapsible(1,
true);
49 constexpr int size = 1234;
50 _ui->splitter->setSizes(QList<int>({size,size}));
52 _ui->fileName->setReadOnly(
true);
54 QObject::connect(_ui->editQMLButton, SIGNAL(clicked()),
this, SLOT(
editQML()));
55 QObject::connect(_ui->loadQMLButton, SIGNAL(clicked()),
this, SLOT(
browseAndOpenQML()));
58 QObject::connect(_ui->showLog, &QPushButton::clicked, [
this] {
59 _ui->logWindow->setVisible(!_ui->logWindow->isVisible());
61 QObject::connect(_ui->pbClean, &QPushButton::clicked, [
this] {
62 _ui->logWindow->clear();
77 auto color = _widget->palette().color(_widget->backgroundRole());
78 _ui->quickWidget->setClearColor(color);
87 QUrl url = QFileDialog::getOpenFileUrl(
mainWidget(),
"Open QML");
89 if(!url.isEmpty() && url.isValid())
99 virtual void loadQML(
const QUrl& url)
override
101 if(url.isValid() && !url.isEmpty())
104 auto splitter =
static_cast<QSplitter*
>(_ui->quickWidget->parentWidget());
105 auto splitState = splitter->saveState();
107 delete _ui->quickWidget;
108 _ui->quickWidget =
new QQuickWidget();
110 splitter->insertWidget(0, _ui->quickWidget);
111 splitter->restoreState(splitState);
117 log(
"Loading qml file: " + url.toLocalFile());
119 assert(_CANBusModel !=
nullptr);
121 _ui->quickWidget->rootContext()->setContextProperty(
"CANBusModel", _CANBusModel);
122 _ui->quickWidget->rootContext()->setContextProperty(
"LogWindow", _ui->logWindow);
124 _ui->quickWidget->setSource(url);
126 _ui->fileName->setText(url.toLocalFile());
132 _ui->editQMLButton->setEnabled(
true);
143 _CANBusModel = model;
151 _qmlLoadTime = QDateTime::currentDateTime();
152 _qmlUpdateCheckTimer.start(std::chrono::milliseconds(1000).count());
160 _qmlUpdateCheckTimer.stop();
168 QDateTime modifycationTime = QFileInfo(_qmlUrl.toLocalFile()).lastModified();
170 if(modifycationTime > _qmlLoadTime)
189 QMessageBox::StandardButton reply;
191 reply = QMessageBox::question(
mainWidget(),
"QML was updated", _qmlUrl.toLocalFile() +
" was changed.\nDo you want to reload it?", QMessageBox::Yes|QMessageBox::No);
193 if (reply == QMessageBox::Yes)
205 void log(
const QString& text)
207 _ui->logWindow->appendPlainText(text);
215 if(_qmlUrl.isValid() && !_qmlUrl.isEmpty())
217 bool status = QDesktopServices::openUrl(_qmlUrl);
221 log(QString(
"Failed to launch external editor for file: ") + _qmlUrl.toString());
225 log(QString(
"System editor for QML launched!"));
240 case QQuickWidget::Status::Error:
242 auto errors = _ui->quickWidget->errors();
244 for (
auto error : errors)
246 QString errorString = error.toString();
248 log(QString(
"QML status: error - ") + errorString);
253 case QQuickWidget::Status::Null:
254 log(QString(
"QML status: Null"));
257 case QQuickWidget::Status::Loading:
258 log(QString(
"QML status: Loading"));
261 case QQuickWidget::Status::Ready:
262 log(QString(
"QML status: Ready"));
269 Ui::QMLExecutorPrivate* _ui;
278 QDateTime _qmlLoadTime;
281 QTimer _qmlUpdateCheckTimer;
The CANBusModel class is used to interface CAN operations with QML stack.
Definition canbusmodel.hpp:11
QMLExecutor plugin gui implementation.
Definition qmlexecutorguiimpl.h:29
bool askForQMLReload()
ask if qml reload should be done
Definition qmlexecutorguiimpl.h:187
void stopFileModificationChecks()
stops checking for qml file modification
Definition qmlexecutorguiimpl.h:158
virtual void setModel(CANBusModel *model) override
remembers can bus model for qml
Definition qmlexecutorguiimpl.h:141
virtual void loadQML(const QUrl &url) override
loads qml into a quick widget
Definition qmlexecutorguiimpl.h:99
void log(const QString &text)
log message to log area
Definition qmlexecutorguiimpl.h:205
void handleStatusChange(QQuickWidget::Status status)
handle status change of qml, just log it
Definition qmlexecutorguiimpl.h:236
void checkQMLModification()
checks if qml file was modified, ask the user and reloads it if needed
Definition qmlexecutorguiimpl.h:166
void updateUIColor() override
used to align empty QQuickWidget color with current color scheme
Definition qmlexecutorguiimpl.h:75
void browseAndOpenQML()
Slot to do browsing for QML file, calls qml load.
Definition qmlexecutorguiimpl.h:85
void startQMLFileModificationChecks()
starts checking for qml file modification
Definition qmlexecutorguiimpl.h:149
virtual QWidget * mainWidget() override
not used, return main widget for ui
Definition qmlexecutorguiimpl.h:66
QMLExecutorGuiImpl(QObject *parent)
explicit constructor
Definition qmlexecutorguiimpl.h:37
void editQML()
tries to launch system editor for .qml file
Definition qmlexecutorguiimpl.h:213
Interface of gui for QMLExecutor plugin.
Definition qmlexecutorguiint.h:16
void QMLLoaded(const QUrl &url)
this signal is emitted when qml was loaded
QMLExecutor plugin private implementation.
Definition qmlexecutor_p.h:18
Definition canrawsender_p.h:13