Skip to content

Commit 6b4bf02

Browse files
committed
[Pages][Welcome] Turn updateData off when this page is not visible
1 parent 8a682a2 commit 6b4bf02

File tree

4 files changed

+42
-0
lines changed

4 files changed

+42
-0
lines changed

mobile/StatPage.qml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import Vedder.vesc.utility 1.0
2828
Item {
2929
property Commands mCommands: VescIf.commands()
3030
property bool isHorizontal: width > height
31+
property alias updateData: commandsUpdate.enabled
3132

3233
Component.onCompleted: {
3334
mCommands.emitEmptyStats()
@@ -87,6 +88,7 @@ Item {
8788
}
8889

8990
Connections {
91+
id: commandsUpdate
9092
target: mCommands
9193

9294
onValuesSetupReceived: {

pages/pagewelcome.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
#include <QSettings>
3030
#include <QmlHighlighter>
3131
#include <QQuickItem>
32+
#include <QQmlProperty>
33+
3234

3335
PageWelcome::PageWelcome(QWidget *parent) :
3436
QWidget(parent),
@@ -113,8 +115,39 @@ void PageWelcome::setVesc(VescInterface *vesc)
113115
ui->qmlWidget->engine()->rootContext()->setContextProperty("Utility", &mUtil);
114116

115117
ui->qmlWidget->setSource(QUrl(QLatin1String("qrc:/res/qml/WelcomeQmlPanel.qml")));
118+
119+
// Install an event filter to monitor for when this QML widget becomes hidden
120+
ui->qmlWidget->installEventFilter(this);
121+
}
122+
123+
124+
bool PageWelcome::eventFilter(QObject *obj, QEvent *event)
125+
{
126+
switch(event->type()) {
127+
case QEvent::Show: {
128+
// Set the telemetry to active when this page is visible
129+
bool ret = QQmlProperty::write(ui->qmlWidget->rootObject(), "shouldTelemetryBeActive", true);
130+
if (ret == false) {
131+
qDebug() << "[QML][Error] shouldTelemetryBeActive was not successfully written. Perhaps that variable no longer exists in the QML component file?";
132+
}
133+
} break;
134+
case QEvent::Hide: {
135+
// Set the telemetry to inactive when this page is not visible
136+
bool ret = QQmlProperty::write(ui->qmlWidget->rootObject(), "shouldTelemetryBeActive", false);
137+
138+
if (ret == false) {
139+
qDebug() << "[QML][Error] shouldTelemetryBeActive was not successfully written. Perhaps that variable no longer exists in the QML component file?";
140+
}
141+
} break;
142+
default: {
143+
} break;
144+
}
145+
146+
return QObject::eventFilter(obj, event);
116147
}
117148

149+
150+
118151
void PageWelcome::on_autoConnectButton_clicked()
119152
{
120153
Utility::autoconnectBlockingWithProgress(mVesc, this);

pages/pagewelcome.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ private slots:
5656
QmlUi mQmlUi;
5757
Utility mUtil;
5858

59+
protected:
60+
bool eventFilter(QObject *obj, QEvent *event);
61+
5962
};
6063

6164
#endif // PAGEWELCOME_H

res/qml/WelcomeQmlPanel.qml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ Item {
3737
property int notchBot: 0
3838
property int notchTop: 0
3939

40+
property bool shouldTelemetryBeActive: true
41+
4042
function setupMotors() {
4143
if (!VescIf.isPortConnected()) {
4244
VescIf.emitMessageDialog("Setup motors FOC",
@@ -213,13 +215,15 @@ Item {
213215
RtDataSetup {
214216
anchors.fill: parent
215217
dialogParent: container
218+
updateData: shouldTelemetryBeActive
216219
}
217220
}
218221

219222
Page {
220223
StatPage {
221224
anchors.fill: parent
222225
anchors.margins: 20
226+
updateData: shouldTelemetryBeActive
223227
}
224228
}
225229
}

0 commit comments

Comments
 (0)