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