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
Approved by: Bartosz Kosiorek
Approved revision: 385
Merged at revision: 385
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: 307 lines (+71/-61)
4 files modified
app/MainPage.qml (+2/-2)
app/stopwatch/StopwatchPage.qml (+11/-11)
backend/modules/Stopwatch/engine.cpp (+43/-29)
backend/modules/Stopwatch/engine.h (+15/-19)
To merge this branch: bzr merge lp:~nik90/ubuntu-clock-app/engine-fixes
Reviewer Review Type Date Requested Status
Bartosz Kosiorek Approve
Review via email: mp+270743@code.launchpad.net

Description of the change

Engines fixes which include,
- Ensure get() functions only return the variable value and nothing else
- Renamed property isRunning to Running to match upstream Qt property naming
- Added a updateStopwatch() public slot

To post a comment you must log in.
Revision history for this message
Bartosz Kosiorek (gang65) wrote :

Looks ok to me.

review: Approve
386. By Nekhelesh Ramananthan

Do not emit change signal in setter functions if the value hasn't changed. Also renamed getter functions as per coding convention

387. By Nekhelesh Ramananthan

Fixed invalid variable name being used

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-10 08:50:16 +0000
3+++ app/MainPage.qml 2015-09-10 22:58:17 +0000
4@@ -58,7 +58,7 @@
5
6 ScreenSaver {
7 // Disable screen dimming/off when stopwatch is running
8- screenSaverEnabled: !stopwatchEngine.isRunning
9+ screenSaverEnabled: !stopwatchEngine.running
10 }
11
12 StopwatchEngine {
13@@ -97,7 +97,7 @@
14
15 // Show the stopwatch page on app startup if it is running
16 Component.onCompleted: {
17- if (stopwatchEngine.isRunning) {
18+ if (stopwatchEngine.running) {
19 positionViewAtIndex(1, ListView.SnapPosition)
20 }
21 }
22
23=== modified file 'app/stopwatch/StopwatchPage.qml'
24--- app/stopwatch/StopwatchPage.qml 2015-09-10 08:11:37 +0000
25+++ app/stopwatch/StopwatchPage.qml 2015-09-10 22:58:17 +0000
26@@ -31,9 +31,9 @@
27 id: refreshTimer
28 interval: 45
29 repeat: true
30- running: stopwatchEngine.isRunning
31+ running: stopwatchEngine.running
32 onTriggered: {
33- stopwatch.milliseconds = stopwatchEngine.totalTimeOfStopwatch
34+ stopwatchEngine.updateStopwatch();
35 }
36 }
37
38@@ -64,11 +64,11 @@
39
40 Button {
41 id: stopButton
42- width: stopwatchEngine.previousTimeOfStopwatch !== 0 || stopwatchEngine.isRunning ? (parent.width - parent.spacing) / 2 : parent.width
43- color: !stopwatchEngine.isRunning ? UbuntuColors.green : UbuntuColors.red
44- text: stopwatchEngine.isRunning ? i18n.tr("Stop") : (stopwatchEngine.previousTimeOfStopwatch === 0 ? i18n.tr("Start") : i18n.tr("Resume"))
45+ width: stopwatchEngine.previousTimeOfStopwatch !== 0 || stopwatchEngine.running ? (parent.width - parent.spacing) / 2 : parent.width
46+ color: !stopwatchEngine.running ? UbuntuColors.green : UbuntuColors.red
47+ text: stopwatchEngine.running ? i18n.tr("Stop") : (stopwatchEngine.previousTimeOfStopwatch === 0 ? i18n.tr("Start") : i18n.tr("Resume"))
48 onClicked: {
49- if (stopwatchEngine.isRunning) {
50+ if (stopwatchEngine.running) {
51 stopwatchEngine.pauseStopwatch();
52 } else {
53 stopwatchEngine.startStopwatch();
54@@ -83,12 +83,12 @@
55
56 Button {
57 id: lapButton
58- text: stopwatchEngine.isRunning ? i18n.tr("Lap") : i18n.tr("Clear")
59- width: stopwatchEngine.previousTimeOfStopwatch !== 0 || stopwatchEngine.isRunning ? (parent.width - parent.spacing) / 2 : 0
60+ text: stopwatchEngine.running ? i18n.tr("Lap") : i18n.tr("Clear")
61+ width: stopwatchEngine.previousTimeOfStopwatch !== 0 || stopwatchEngine.running ? (parent.width - parent.spacing) / 2 : 0
62 strokeColor: UbuntuColors.lightGrey
63- visible: stopwatchEngine.previousTimeOfStopwatch !== 0 || stopwatchEngine.isRunning
64+ visible: stopwatchEngine.previousTimeOfStopwatch !== 0 || stopwatchEngine.running
65 onClicked: {
66- if (stopwatchEngine.isRunning) {
67+ if (stopwatchEngine.running) {
68 stopwatchEngine.addLap()
69 } else {
70 stopwatchEngine.clearStopwatch()
71@@ -116,7 +116,7 @@
72 Loader {
73 id: lapListViewLoader
74 anchors.fill: parent
75- sourceComponent: !stopwatchEngine.isRunning && stopwatchEngine.totalTimeOfStopwatch === 0 ? undefined : lapListViewComponent
76+ sourceComponent: !stopwatchEngine.running && stopwatchEngine.totalTimeOfStopwatch === 0 ? undefined : lapListViewComponent
77 }
78 }
79
80
81=== modified file 'backend/modules/Stopwatch/engine.cpp'
82--- backend/modules/Stopwatch/engine.cpp 2015-09-10 01:09:57 +0000
83+++ backend/modules/Stopwatch/engine.cpp 2015-09-10 22:58:17 +0000
84@@ -28,7 +28,9 @@
85 when Ubuntu Touch moves over to Qt 5.5. AppConfigLocation will directly return
86 /home/phablet/.config/com.ubuntu.clock path.
87 */
88- m_settings(QStandardPaths::standardLocations(QStandardPaths::ConfigLocation).first() + "/com.ubuntu.clock/com.ubuntu.clock.conf", QSettings::IniFormat)
89+ m_settings(QStandardPaths::standardLocations(QStandardPaths::ConfigLocation).first() + "/com.ubuntu.clock/com.ubuntu.clock.conf", QSettings::IniFormat),
90+ m_previousTimeInmsecs(0),
91+ m_totalTimeInmsecs(0)
92 {
93 qDebug() << "[LOG] Loading laps from " << m_settings.fileName();
94 QDateTime startTime = m_settings.value("Stopwatch/startDateTime").toDateTime();
95@@ -36,13 +38,13 @@
96 {
97 m_stopwatchStartDateTime = startTime;
98 }
99- else
100- {
101- startStopwatch();
102- }
103
104 m_isStopwatchRunning = m_settings.value("Stopwatch/isStopwatchRunning").toBool();
105 m_previousTimeInmsecs = m_settings.value("Stopwatch/previousTimeInmsecs").toInt();
106+
107+ if(m_previousTimeInmsecs != 0) {
108+ setTotalTimeOfStopwatch(m_previousTimeInmsecs);
109+ }
110 }
111
112 int StopwatchEngine::rowCount(const QModelIndex &parent) const
113@@ -87,7 +89,7 @@
114 {
115 QVariantList laps = m_settings.value("Stopwatch/laps").toList();
116 beginInsertRows(QModelIndex(), 0, 0);
117- int timeDiff = getTotalTimeOfStopwatch();
118+ int timeDiff = m_totalTimeInmsecs;
119 laps.prepend(timeDiff);
120 m_settings.setValue("Stopwatch/laps", laps);
121 endInsertRows();
122@@ -102,67 +104,74 @@
123 endRemoveRows();
124 }
125
126+void StopwatchEngine::setStopwatchStartDateTime()
127+{
128+ m_stopwatchStartDateTime = QDateTime::currentDateTimeUtc();
129+ m_settings.setValue("Stopwatch/startDateTime", m_stopwatchStartDateTime);
130+}
131+
132 void StopwatchEngine::startStopwatch()
133 {
134- if(m_isStopwatchRunning == false)
135- {
136- m_stopwatchStartDateTime = QDateTime::currentDateTimeUtc();
137- m_settings.setValue("Stopwatch/startDateTime", m_stopwatchStartDateTime);
138+ setStopwatchStartDateTime();
139+ setRunning(true);
140+}
141
142- setIsRunning(true);
143- }
144+void StopwatchEngine::updateStopwatch()
145+{
146+ setTotalTimeOfStopwatch(m_previousTimeInmsecs + m_stopwatchStartDateTime.msecsTo(QDateTime::currentDateTimeUtc()));
147 }
148
149 void StopwatchEngine::pauseStopwatch()
150 {
151 setPreviousTimeOfStopwatch(m_previousTimeInmsecs + m_stopwatchStartDateTime.msecsTo(QDateTime::currentDateTimeUtc()));
152- setIsRunning(false);
153+ setTotalTimeOfStopwatch(m_previousTimeInmsecs);
154+ setRunning(false);
155 }
156
157 void StopwatchEngine::clearStopwatch()
158 {
159+ setPreviousTimeOfStopwatch(0);
160 setTotalTimeOfStopwatch(0);
161- setPreviousTimeOfStopwatch(0);
162
163 beginResetModel();
164 m_settings.setValue("Stopwatch/laps", QVariantList());
165 endResetModel();
166-
167- setIsRunning(false);
168 }
169
170-bool StopwatchEngine::getIsRunning()
171+bool StopwatchEngine::running() const
172 {
173 return m_isStopwatchRunning;
174 }
175
176-int StopwatchEngine::getPreviousTimeOfStopwatch()
177+int StopwatchEngine::previousTimeOfStopwatch() const
178 {
179 return m_previousTimeInmsecs;
180 }
181
182-int StopwatchEngine::getTotalTimeOfStopwatch()
183+int StopwatchEngine::totalTimeOfStopwatch() const
184 {
185- if(m_isStopwatchRunning == false)
186- {
187- m_totalTimeInmsecs = m_previousTimeInmsecs;
188- }
189- else
190- {
191- m_totalTimeInmsecs = m_previousTimeInmsecs + m_stopwatchStartDateTime.msecsTo(QDateTime::currentDateTimeUtc());
192- }
193 return m_totalTimeInmsecs;
194 }
195
196-void StopwatchEngine::setIsRunning(bool value)
197+void StopwatchEngine::setRunning(bool value)
198 {
199+ if(value == m_isStopwatchRunning)
200+ {
201+ return;
202+ }
203+
204 m_isStopwatchRunning = value;
205 m_settings.setValue("Stopwatch/isStopwatchRunning", m_isStopwatchRunning);
206- emit isRunningChanged();
207+ emit runningChanged();
208 }
209
210 void StopwatchEngine::setPreviousTimeOfStopwatch(int value)
211 {
212+ if(value == m_previousTimeInmsecs)
213+ {
214+ return;
215+ }
216+
217 m_previousTimeInmsecs = value;
218 m_settings.setValue("Stopwatch/previousTimeInmsecs", m_previousTimeInmsecs);
219 emit previousTimeOfStopwatchChanged();
220@@ -170,6 +179,11 @@
221
222 void StopwatchEngine::setTotalTimeOfStopwatch(int value)
223 {
224+ if(value == m_totalTimeInmsecs)
225+ {
226+ return;
227+ }
228+
229 m_totalTimeInmsecs = value;
230 emit totalTimeOfStopwatchChanged();
231 }
232
233=== modified file 'backend/modules/Stopwatch/engine.h'
234--- backend/modules/Stopwatch/engine.h 2015-09-10 10:58:51 +0000
235+++ backend/modules/Stopwatch/engine.h 2015-09-10 22:58:17 +0000
236@@ -27,21 +27,21 @@
237 {
238 Q_OBJECT
239
240- Q_PROPERTY( bool isRunning
241- READ getIsRunning
242- NOTIFY isRunningChanged)
243+ Q_PROPERTY( bool running
244+ READ running
245+ NOTIFY runningChanged)
246
247 Q_PROPERTY( int totalTimeOfStopwatch
248- READ getTotalTimeOfStopwatch
249+ READ totalTimeOfStopwatch
250 NOTIFY totalTimeOfStopwatchChanged)
251
252 Q_PROPERTY( int previousTimeOfStopwatch
253- READ getPreviousTimeOfStopwatch
254+ READ previousTimeOfStopwatch
255 NOTIFY previousTimeOfStopwatchChanged)
256
257 signals:
258 // Signal to notify the running status change to QML
259- void isRunningChanged();
260+ void runningChanged();
261
262 // Signal to notify the total time change to QML
263 void totalTimeOfStopwatchChanged();
264@@ -71,34 +71,30 @@
265 QHash<int, QByteArray> roleNames() const override;
266
267 public slots:
268- // Function to add a stopwatch lap
269 void addLap();
270-
271- // Function to remove a stopwatch lap
272 void removeLap(int lapIndex);
273
274 void startStopwatch();
275-
276 void pauseStopwatch();
277-
278 void clearStopwatch();
279-
280- bool getIsRunning();
281-
282- int getTotalTimeOfStopwatch();
283-
284- int getPreviousTimeOfStopwatch();
285+ void updateStopwatch();
286+
287+ // Getter functions for the properties
288+ bool running() const;
289+ int totalTimeOfStopwatch() const;
290+ int previousTimeOfStopwatch() const;
291
292 private:
293- void setIsRunning(bool value);
294+ void setStopwatchStartDateTime();
295
296+ void setRunning(bool value);
297 void setTotalTimeOfStopwatch(int value);
298-
299 void setPreviousTimeOfStopwatch(int value);
300
301 QSettings m_settings;
302
303 QDateTime m_stopwatchStartDateTime;
304+
305 bool m_isStopwatchRunning;
306 int m_previousTimeInmsecs;
307 int m_totalTimeInmsecs;

Subscribers

People subscribed via source and target branches