Merge lp:~nik90/ubuntu-clock-app/engine-fixes into lp:~gang65/ubuntu-clock-app/ubuntu-clock-stopwatch-runtime-timezone-fix

Proposed by Nekhelesh Ramananthan
Status: Merged
Merged at revision: 388
Proposed branch: lp:~nik90/ubuntu-clock-app/engine-fixes
Merge into: lp:~gang65/ubuntu-clock-app/ubuntu-clock-stopwatch-runtime-timezone-fix
Diff against target: 181 lines (+36/-30)
4 files modified
app/MainPage.qml (+8/-13)
app/stopwatch/StopwatchPage.qml (+5/-8)
backend/modules/Stopwatch/engine.cpp (+11/-0)
backend/modules/Stopwatch/engine.h (+12/-9)
To merge this branch: bzr merge lp:~nik90/ubuntu-clock-app/engine-fixes
Reviewer Review Type Date Requested Status
Bartosz Kosiorek Needs Fixing
Review via email: mp+270800@code.launchpad.net

Description of the change

- Replace QML Timer with QTimer
- Move StopwatchEngine to StopwatchPage.qml

To post a comment you must log in.
390. By Nekhelesh Ramananthan

Set interval once

Revision history for this message
Bartosz Kosiorek (gang65) wrote :

We should delete m_timer pointer in destructor.

review: Needs Fixing
391. By Nekhelesh Ramananthan

Proper use of Q_INVOKABLE and public slots

392. By Nekhelesh Ramananthan

fixed conflicts

393. By Nekhelesh Ramananthan

Replaced pointer with regular variable

Revision history for this message
Nekhelesh Ramananthan (nik90) wrote :

Replaced pointer with regular variable. That should prevent any memory leaks or crashes.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'app/MainPage.qml'
2--- app/MainPage.qml 2015-09-11 13:13:17 +0000
3+++ app/MainPage.qml 2015-09-11 13:37:52 +0000
4@@ -19,7 +19,6 @@
5 import QtQuick 2.4
6 import Ubuntu.Components 1.2
7 import QtSystemInfo 5.0
8-import Stopwatch 1.0
9 import Qt.labs.settings 1.0
10 import "upstreamcomponents"
11 import "alarm"
12@@ -56,13 +55,9 @@
13 id: alarmUtils
14 }
15
16- StopwatchEngine {
17- id: stopwatchEngine
18- }
19-
20 ScreenSaver {
21 // Disable screen dimming/off when stopwatch is running
22- screenSaverEnabled: !stopwatchEngine.running
23+ screenSaverEnabled: !stopwatchPage.isRunning
24 }
25
26 VisualItemModel {
27@@ -95,6 +90,13 @@
28 ListView {
29 id: listview
30
31+ // Show the stopwatch page on app startup if it is running
32+ Component.onCompleted: {
33+ if (stopwatchPage.isRunning) {
34+ positionViewAtIndex(1, ListView.SnapPosition)
35+ }
36+ }
37+
38 anchors {
39 top: headerRow.bottom
40 left: parent.left
41@@ -108,12 +110,5 @@
42 interactive: false
43 highlightMoveDuration: UbuntuAnimation.BriskDuration
44 highlightRangeMode: ListView.StrictlyEnforceRange
45-
46- // Show the stopwatch page on app startup if it is running
47- Component.onCompleted: {
48- if (stopwatchEngine.running) {
49- positionViewAtIndex(1, ListView.SnapPosition)
50- }
51- }
52 }
53 }
54
55=== modified file 'app/stopwatch/StopwatchPage.qml'
56--- app/stopwatch/StopwatchPage.qml 2015-09-10 20:38:50 +0000
57+++ app/stopwatch/StopwatchPage.qml 2015-09-11 13:37:52 +0000
58@@ -17,24 +17,21 @@
59 */
60
61 import QtQuick 2.4
62+import Stopwatch 1.0
63 import Ubuntu.Components 1.2
64
65 Item {
66 id: _stopwatchPage
67 objectName: "stopwatchPage"
68
69+ property alias isRunning: stopwatchEngine.running
70+
71 Component.onCompleted: {
72 console.log("[LOG]: Stopwatch Page Loaded")
73 }
74
75- Timer {
76- id: refreshTimer
77- interval: 45
78- repeat: true
79- running: stopwatchEngine.running
80- onTriggered: {
81- stopwatchEngine.updateStopwatch();
82- }
83+ StopwatchEngine {
84+ id: stopwatchEngine
85 }
86
87 StopwatchFace {
88
89=== modified file 'backend/modules/Stopwatch/engine.cpp'
90--- backend/modules/Stopwatch/engine.cpp 2015-09-10 22:58:10 +0000
91+++ backend/modules/Stopwatch/engine.cpp 2015-09-11 13:37:52 +0000
92@@ -33,6 +33,10 @@
93 m_totalTimeInmsecs(0)
94 {
95 qDebug() << "[LOG] Loading laps from " << m_settings.fileName();
96+
97+ m_timer.setInterval(45);
98+ connect(&m_timer, &QTimer::timeout, this, &StopwatchEngine::updateStopwatch);
99+
100 QDateTime startTime = m_settings.value("Stopwatch/startDateTime").toDateTime();
101 if(startTime.isValid())
102 {
103@@ -45,6 +49,11 @@
104 if(m_previousTimeInmsecs != 0) {
105 setTotalTimeOfStopwatch(m_previousTimeInmsecs);
106 }
107+
108+ if(m_isStopwatchRunning == true)
109+ {
110+ m_timer.start();
111+ }
112 }
113
114 int StopwatchEngine::rowCount(const QModelIndex &parent) const
115@@ -114,6 +123,7 @@
116 {
117 setStopwatchStartDateTime();
118 setRunning(true);
119+ m_timer.start();
120 }
121
122 void StopwatchEngine::updateStopwatch()
123@@ -126,6 +136,7 @@
124 setPreviousTimeOfStopwatch(m_previousTimeInmsecs + m_stopwatchStartDateTime.msecsTo(QDateTime::currentDateTimeUtc()));
125 setTotalTimeOfStopwatch(m_previousTimeInmsecs);
126 setRunning(false);
127+ m_timer.stop();
128 }
129
130 void StopwatchEngine::clearStopwatch()
131
132=== modified file 'backend/modules/Stopwatch/engine.h'
133--- backend/modules/Stopwatch/engine.h 2015-09-10 22:45:38 +0000
134+++ backend/modules/Stopwatch/engine.h 2015-09-11 13:37:52 +0000
135@@ -20,6 +20,7 @@
136 #define ENGINE_H
137
138 #include <QAbstractListModel>
139+#include <QTimer>
140 #include <QSettings>
141 #include <QDateTime>
142
143@@ -70,20 +71,21 @@
144 */
145 QHash<int, QByteArray> roleNames() const override;
146
147-public slots:
148- void addLap();
149- void removeLap(int lapIndex);
150-
151- void startStopwatch();
152- void pauseStopwatch();
153- void clearStopwatch();
154- void updateStopwatch();
155-
156 // Getter functions for the properties
157 bool running() const;
158 int totalTimeOfStopwatch() const;
159 int previousTimeOfStopwatch() const;
160
161+ Q_INVOKABLE void addLap();
162+ Q_INVOKABLE void removeLap(int lapIndex);
163+
164+ Q_INVOKABLE void startStopwatch();
165+ Q_INVOKABLE void pauseStopwatch();
166+ Q_INVOKABLE void clearStopwatch();
167+
168+private slots:
169+ void updateStopwatch();
170+
171 private:
172 void setStopwatchStartDateTime();
173
174@@ -94,6 +96,7 @@
175 QSettings m_settings;
176
177 QDateTime m_stopwatchStartDateTime;
178+ QTimer m_timer;
179
180 bool m_isStopwatchRunning;
181 int m_previousTimeInmsecs;

Subscribers

People subscribed via source and target branches