Merge lp:~nik90/ubuntu-clock-app/migrate-stopwatch-utils-c++ into lp:ubuntu-clock-app
- migrate-stopwatch-utils-c++
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Bartosz Kosiorek |
Approved revision: | 367 |
Merged at revision: | 361 |
Proposed branch: | lp:~nik90/ubuntu-clock-app/migrate-stopwatch-utils-c++ |
Merge into: | lp:ubuntu-clock-app |
Diff against target: |
498 lines (+163/-113) 11 files modified
app/stopwatch/CMakeLists.txt (+0/-1) app/stopwatch/LapListView.qml (+7/-6) app/stopwatch/StopwatchFace.qml (+5/-4) app/stopwatch/StopwatchPage.qml (+1/-1) app/stopwatch/StopwatchUtils.qml (+0/-73) backend/CMakeLists.txt (+13/-12) backend/modules/Stopwatch/backend.cpp (+3/-1) backend/modules/Stopwatch/formattime.cpp (+78/-0) backend/modules/Stopwatch/formattime.h (+38/-0) backend/modules/Stopwatch/qmldir (+2/-2) tests/unit/tst_stopwatchUtils.qml (+16/-13) |
To merge this branch: | bzr merge lp:~nik90/ubuntu-clock-app/migrate-stopwatch-utils-c++ |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Bartosz Kosiorek | Approve | ||
Ubuntu Phone Apps Jenkins Bot | continuous-integration | Approve | |
Review via email: mp+269051@code.launchpad.net |
Commit message
Converted StopwatchUtils.qml functions to C++ functions to shave loading times and improve performance by a tiny bit.
Description of the change
This MP converts the StopwatchUtils.qml functions to C++ functions for the following reasons,
When I ran stopwatch using Qt Profiler, I noticed that StopwatchUtils{} takes around 60 ms to load, and each function call within takes an average of 200 microsecond. On converting this to c++, the load time reduces to 500 microseconds, so from 60ms->500micros
While the performance shaving are quite small, it raises the question as to why not do this change? I see no disadvantages. Nothing in the qml side needs to be changed, unit tests pass. Regression free!
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : | # |
- 364. By Nekhelesh Ramananthan
-
Changed StopwatchUtils to just Utils
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : | # |
PASSED: Continuous integration, rev:364
http://
Executed test runs:
SUCCESS: http://
Click here to trigger a rebuild:
http://
- 365. By Nekhelesh Ramananthan
-
Renamed Utils to FormatTime
- 366. By Nekhelesh Ramananthan
-
Fixed hours being truncated when they are greater than 99
- 367. By Nekhelesh Ramananthan
-
Fixed unit tests
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : | # |
FAILED: Continuous integration, rev:366
http://
Executed test runs:
FAILURE: http://
Click here to trigger a rebuild:
http://
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : | # |
PASSED: Continuous integration, rev:367
http://
Executed test runs:
SUCCESS: http://
Click here to trigger a rebuild:
http://
Bartosz Kosiorek (gang65) wrote : | # |
works perfectly for me, and everrything is fine according to checklist
Preview Diff
1 | === modified file 'app/stopwatch/CMakeLists.txt' | |||
2 | --- app/stopwatch/CMakeLists.txt 2015-08-09 20:59:10 +0000 | |||
3 | +++ app/stopwatch/CMakeLists.txt 2015-08-26 22:51:08 +0000 | |||
4 | @@ -2,7 +2,6 @@ | |||
5 | 2 | LapListView.qml | 2 | LapListView.qml |
6 | 3 | StopwatchFace.qml | 3 | StopwatchFace.qml |
7 | 4 | StopwatchPage.qml | 4 | StopwatchPage.qml |
8 | 5 | StopwatchUtils.qml | ||
9 | 6 | ) | 5 | ) |
10 | 7 | 6 | ||
11 | 8 | # make the files visible in the qtcreator tree | 7 | # make the files visible in the qtcreator tree |
12 | 9 | 8 | ||
13 | === modified file 'app/stopwatch/LapListView.qml' | |||
14 | --- app/stopwatch/LapListView.qml 2015-08-20 19:59:21 +0000 | |||
15 | +++ app/stopwatch/LapListView.qml 2015-08-26 22:51:08 +0000 | |||
16 | @@ -19,14 +19,15 @@ | |||
17 | 19 | import QtQuick 2.4 | 19 | import QtQuick 2.4 |
18 | 20 | import QtQuick.Layouts 1.1 | 20 | import QtQuick.Layouts 1.1 |
19 | 21 | import Ubuntu.Components 1.2 | 21 | import Ubuntu.Components 1.2 |
20 | 22 | import Stopwatch 1.0 | ||
21 | 22 | 23 | ||
22 | 23 | ListView { | 24 | ListView { |
23 | 24 | id: lapListView | 25 | id: lapListView |
24 | 25 | 26 | ||
25 | 26 | clip: true | 27 | clip: true |
26 | 27 | 28 | ||
29 | 28 | StopwatchUtils { | 29 | StopwatchFormatTime { |
30 | 29 | id: stopwatchUtils | 30 | id: stopwatchFormatTime |
31 | 30 | } | 31 | } |
32 | 31 | 32 | ||
33 | 32 | header: ListItem { | 33 | header: ListItem { |
34 | @@ -108,11 +109,11 @@ | |||
35 | 108 | Row { | 109 | Row { |
36 | 109 | anchors.horizontalCenter: parent.horizontalCenter | 110 | anchors.horizontalCenter: parent.horizontalCenter |
37 | 110 | Label { | 111 | Label { |
39 | 111 | text: stopwatchUtils.lapTimeToString(model.laptime) + "." | 112 | text: stopwatchFormatTime.lapTimeToString(model.laptime) + "." |
40 | 112 | } | 113 | } |
41 | 113 | Label { | 114 | Label { |
42 | 114 | fontSize: "x-small" | 115 | fontSize: "x-small" |
44 | 115 | text: stopwatchUtils.millisToString(model.laptime) | 116 | text: stopwatchFormatTime.millisToString(model.laptime) |
45 | 116 | anchors.bottom: parent.bottom | 117 | anchors.bottom: parent.bottom |
46 | 117 | anchors.bottomMargin: units.dp(1) | 118 | anchors.bottomMargin: units.dp(1) |
47 | 118 | } | 119 | } |
48 | @@ -125,11 +126,11 @@ | |||
49 | 125 | Row { | 126 | Row { |
50 | 126 | anchors.horizontalCenter: parent.horizontalCenter | 127 | anchors.horizontalCenter: parent.horizontalCenter |
51 | 127 | Label { | 128 | Label { |
53 | 128 | text: stopwatchUtils.lapTimeToString(model.totaltime) + "." | 129 | text: stopwatchFormatTime.lapTimeToString(model.totaltime) + "." |
54 | 129 | } | 130 | } |
55 | 130 | Label { | 131 | Label { |
56 | 131 | fontSize: "x-small" | 132 | fontSize: "x-small" |
58 | 132 | text: stopwatchUtils.millisToString(model.totaltime) | 133 | text: stopwatchFormatTime.millisToString(model.totaltime) |
59 | 133 | anchors.bottom: parent.bottom | 134 | anchors.bottom: parent.bottom |
60 | 134 | anchors.bottomMargin: units.dp(1) | 135 | anchors.bottomMargin: units.dp(1) |
61 | 135 | } | 136 | } |
62 | 136 | 137 | ||
63 | === modified file 'app/stopwatch/StopwatchFace.qml' | |||
64 | --- app/stopwatch/StopwatchFace.qml 2015-08-17 20:27:12 +0000 | |||
65 | +++ app/stopwatch/StopwatchFace.qml 2015-08-26 22:51:08 +0000 | |||
66 | @@ -17,6 +17,7 @@ | |||
67 | 17 | */ | 17 | */ |
68 | 18 | 18 | ||
69 | 19 | import QtQuick 2.4 | 19 | import QtQuick 2.4 |
70 | 20 | import Stopwatch 1.0 | ||
71 | 20 | import Ubuntu.Components 1.2 | 21 | import Ubuntu.Components 1.2 |
72 | 21 | import "../components" | 22 | import "../components" |
73 | 22 | 23 | ||
74 | @@ -29,8 +30,8 @@ | |||
75 | 29 | isOuter: true | 30 | isOuter: true |
76 | 30 | width: units.gu(32) | 31 | width: units.gu(32) |
77 | 31 | 32 | ||
80 | 32 | StopwatchUtils { | 33 | StopwatchFormatTime { |
81 | 33 | id: stopwatchUtils | 34 | id: stopwatchFormatTime |
82 | 34 | } | 35 | } |
83 | 35 | 36 | ||
84 | 36 | ClockCircle { | 37 | ClockCircle { |
85 | @@ -46,13 +47,13 @@ | |||
86 | 46 | anchors.centerIn: parent | 47 | anchors.centerIn: parent |
87 | 47 | 48 | ||
88 | 48 | Label { | 49 | Label { |
90 | 49 | text: stopwatchUtils.millisToTimeString(milliseconds, false, true) | 50 | text: stopwatchFormatTime.millisToTimeString(milliseconds, true) |
91 | 50 | font.pixelSize: units.dp(34) | 51 | font.pixelSize: units.dp(34) |
92 | 51 | color: UbuntuColors.midAubergine | 52 | color: UbuntuColors.midAubergine |
93 | 52 | } | 53 | } |
94 | 53 | 54 | ||
95 | 54 | Label { | 55 | Label { |
97 | 55 | text: stopwatchUtils.millisToString(milliseconds) | 56 | text: stopwatchFormatTime.millisToString(milliseconds) |
98 | 56 | font.pixelSize: units.dp(18) | 57 | font.pixelSize: units.dp(18) |
99 | 57 | color: UbuntuColors.midAubergine | 58 | color: UbuntuColors.midAubergine |
100 | 58 | anchors.horizontalCenter: parent.horizontalCenter | 59 | anchors.horizontalCenter: parent.horizontalCenter |
101 | 59 | 60 | ||
102 | === modified file 'app/stopwatch/StopwatchPage.qml' | |||
103 | --- app/stopwatch/StopwatchPage.qml 2015-08-18 13:13:32 +0000 | |||
104 | +++ app/stopwatch/StopwatchPage.qml 2015-08-26 22:51:08 +0000 | |||
105 | @@ -17,8 +17,8 @@ | |||
106 | 17 | */ | 17 | */ |
107 | 18 | 18 | ||
108 | 19 | import QtQuick 2.4 | 19 | import QtQuick 2.4 |
109 | 20 | import Stopwatch 1.0 | ||
110 | 20 | import Ubuntu.Components 1.2 | 21 | import Ubuntu.Components 1.2 |
111 | 21 | import Stopwatch.LapHistory 1.0 | ||
112 | 22 | 22 | ||
113 | 23 | Item { | 23 | Item { |
114 | 24 | id: _stopwatchPage | 24 | id: _stopwatchPage |
115 | 25 | 25 | ||
116 | === removed file 'app/stopwatch/StopwatchUtils.qml' | |||
117 | --- app/stopwatch/StopwatchUtils.qml 2015-08-17 20:27:12 +0000 | |||
118 | +++ app/stopwatch/StopwatchUtils.qml 1970-01-01 00:00:00 +0000 | |||
119 | @@ -1,73 +0,0 @@ | |||
120 | 1 | /* | ||
121 | 2 | * Copyright (C) 2015 Canonical Ltd | ||
122 | 3 | * | ||
123 | 4 | * This file is part of Ubuntu Clock App | ||
124 | 5 | * | ||
125 | 6 | * Ubuntu Clock App is free software: you can redistribute it and/or modify | ||
126 | 7 | * it under the terms of the GNU General Public License version 3 as | ||
127 | 8 | * published by the Free Software Foundation. | ||
128 | 9 | * | ||
129 | 10 | * Ubuntu Clock App is distributed in the hope that it will be useful, | ||
130 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
131 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
132 | 13 | * GNU General Public License for more details. | ||
133 | 14 | * | ||
134 | 15 | * You should have received a copy of the GNU General Public License | ||
135 | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
136 | 17 | */ | ||
137 | 18 | |||
138 | 19 | import QtQuick 2.4 | ||
139 | 20 | import Ubuntu.Components 1.2 | ||
140 | 21 | |||
141 | 22 | /* | ||
142 | 23 | Qt Object containing a collection of useful stopwatch functions | ||
143 | 24 | */ | ||
144 | 25 | QtObject { | ||
145 | 26 | id: stopwatchUtils | ||
146 | 27 | |||
147 | 28 | // Function to return only the milliseconds | ||
148 | 29 | function millisToString(millis) { | ||
149 | 30 | return addZeroPrefix(millis % 1000, 3) | ||
150 | 31 | } | ||
151 | 32 | |||
152 | 33 | // Function to break down time (milliseconds) to hours, minutes and seconds | ||
153 | 34 | function millisToTimeString(millis, showMilliseconds, showHours) { | ||
154 | 35 | var hours, minutes, seconds | ||
155 | 36 | |||
156 | 37 | // Break down total time (milliseconds) to hours, minutes and seconds | ||
157 | 38 | seconds = Math.floor(millis / 1000) % 60; | ||
158 | 39 | minutes = Math.floor(millis / 1000 / 60) % 60 | ||
159 | 40 | hours = Math.floor(millis / 1000 / 60 / 60) | ||
160 | 41 | |||
161 | 42 | // Build the time string | ||
162 | 43 | var timeString = "" | ||
163 | 44 | |||
164 | 45 | if (showHours) { | ||
165 | 46 | timeString += addZeroPrefix(hours, 2) + ":" | ||
166 | 47 | } | ||
167 | 48 | |||
168 | 49 | timeString += addZeroPrefix(minutes, 2) + ":" | ||
169 | 50 | timeString += addZeroPrefix(seconds, 2) | ||
170 | 51 | |||
171 | 52 | if (showMilliseconds) { | ||
172 | 53 | timeString += "." + millisToString(millis) | ||
173 | 54 | } | ||
174 | 55 | |||
175 | 56 | return timeString | ||
176 | 57 | } | ||
177 | 58 | |||
178 | 59 | // Function to add zero prefix if necessary. | ||
179 | 60 | function addZeroPrefix (str, totalLength) { | ||
180 | 61 | return ("00000" + str).slice(-totalLength) | ||
181 | 62 | } | ||
182 | 63 | |||
183 | 64 | // Function to return lap time as a string | ||
184 | 65 | function lapTimeToString(millis) { | ||
185 | 66 | var hours = hours = Math.floor(millis / 1000 / 60 / 60) | ||
186 | 67 | if (hours > 0) { | ||
187 | 68 | return millisToTimeString(millis, false, true) | ||
188 | 69 | } else { | ||
189 | 70 | return millisToTimeString(millis, false, false) | ||
190 | 71 | } | ||
191 | 72 | } | ||
192 | 73 | } | ||
193 | 74 | 0 | ||
194 | === modified file 'backend/CMakeLists.txt' | |||
195 | --- backend/CMakeLists.txt 2015-08-24 15:08:21 +0000 | |||
196 | +++ backend/CMakeLists.txt 2015-08-26 22:51:08 +0000 | |||
197 | @@ -41,9 +41,10 @@ | |||
198 | 41 | ) | 41 | ) |
199 | 42 | 42 | ||
200 | 43 | set( | 43 | set( |
204 | 44 | stopwatchlaphistory_SRCS | 44 | stopwatch_SRCS |
205 | 45 | modules/Stopwatch/LapHistory/backend.cpp | 45 | modules/Stopwatch/backend.cpp |
206 | 46 | modules/Stopwatch/LapHistory/history.cpp | 46 | modules/Stopwatch/history.cpp |
207 | 47 | modules/Stopwatch/formattime.cpp | ||
208 | 47 | ) | 48 | ) |
209 | 48 | 49 | ||
210 | 49 | add_library(timezone MODULE | 50 | add_library(timezone MODULE |
211 | @@ -66,8 +67,8 @@ | |||
212 | 66 | ${clockutility_SRCS} | 67 | ${clockutility_SRCS} |
213 | 67 | ) | 68 | ) |
214 | 68 | 69 | ||
217 | 69 | add_library(stopwatchlaphistory MODULE | 70 | add_library(stopwatch MODULE |
218 | 70 | ${stopwatchlaphistory_SRCS} | 71 | ${stopwatch_SRCS} |
219 | 71 | ) | 72 | ) |
220 | 72 | 73 | ||
221 | 73 | set_target_properties(timezone PROPERTIES | 74 | set_target_properties(timezone PROPERTIES |
222 | @@ -90,8 +91,8 @@ | |||
223 | 90 | LIBRARY_OUTPUT_DIRECTORY Clock/Utility | 91 | LIBRARY_OUTPUT_DIRECTORY Clock/Utility |
224 | 91 | ) | 92 | ) |
225 | 92 | 93 | ||
228 | 93 | set_target_properties(stopwatchlaphistory PROPERTIES | 94 | set_target_properties(stopwatch PROPERTIES |
229 | 94 | LIBRARY_OUTPUT_DIRECTORY Stopwatch/LapHistory | 95 | LIBRARY_OUTPUT_DIRECTORY Stopwatch/ |
230 | 95 | ) | 96 | ) |
231 | 96 | 97 | ||
232 | 97 | qt5_use_modules(datetime Gui Qml Quick) | 98 | qt5_use_modules(datetime Gui Qml Quick) |
233 | @@ -99,7 +100,7 @@ | |||
234 | 99 | qt5_use_modules(alarmsettings Gui Qml Quick DBus) | 100 | qt5_use_modules(alarmsettings Gui Qml Quick DBus) |
235 | 100 | qt5_use_modules(geolocation Gui Qml Quick) | 101 | qt5_use_modules(geolocation Gui Qml Quick) |
236 | 101 | qt5_use_modules(clockutility Qml) | 102 | qt5_use_modules(clockutility Qml) |
238 | 102 | qt5_use_modules(stopwatchlaphistory Qml) | 103 | qt5_use_modules(stopwatch Qml) |
239 | 103 | 104 | ||
240 | 104 | # Copy qmldir file to build dir for running in QtCreator | 105 | # Copy qmldir file to build dir for running in QtCreator |
241 | 105 | add_custom_target(timezone-qmldir ALL | 106 | add_custom_target(timezone-qmldir ALL |
242 | @@ -127,8 +128,8 @@ | |||
243 | 127 | DEPENDS ${QMLFILES} | 128 | DEPENDS ${QMLFILES} |
244 | 128 | ) | 129 | ) |
245 | 129 | 130 | ||
248 | 130 | add_custom_target(stopwatchlaphistory-qmldir ALL | 131 | add_custom_target(stopwatch-qmldir ALL |
249 | 131 | COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/modules/Stopwatch/LapHistory/qmldir ${CMAKE_CURRENT_BINARY_DIR}/Stopwatch/LapHistory | 132 | COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/modules/Stopwatch/qmldir ${CMAKE_CURRENT_BINARY_DIR}/Stopwatch |
250 | 132 | DEPENDS ${QMLFILES} | 133 | DEPENDS ${QMLFILES} |
251 | 133 | ) | 134 | ) |
252 | 134 | 135 | ||
253 | @@ -148,6 +149,6 @@ | |||
254 | 148 | install(TARGETS clockutility DESTINATION ${MODULE_PATH}/Clock/Utility/) | 149 | install(TARGETS clockutility DESTINATION ${MODULE_PATH}/Clock/Utility/) |
255 | 149 | install(FILES modules/Clock/Utility/qmldir DESTINATION ${MODULE_PATH}/Clock/Utility/) | 150 | install(FILES modules/Clock/Utility/qmldir DESTINATION ${MODULE_PATH}/Clock/Utility/) |
256 | 150 | 151 | ||
259 | 151 | install(TARGETS stopwatchlaphistory DESTINATION ${MODULE_PATH}/Stopwatch/LapHistory/) | 152 | install(TARGETS stopwatch DESTINATION ${MODULE_PATH}/Stopwatch/) |
260 | 152 | install(FILES modules/Stopwatch/LapHistory/qmldir DESTINATION ${MODULE_PATH}/Stopwatch/LapHistory/) | 153 | install(FILES modules/Stopwatch/qmldir DESTINATION ${MODULE_PATH}/Stopwatch/) |
261 | 153 | 154 | ||
262 | 154 | 155 | ||
263 | === removed directory 'backend/modules/Stopwatch/LapHistory' | |||
264 | === renamed file 'backend/modules/Stopwatch/LapHistory/backend.cpp' => 'backend/modules/Stopwatch/backend.cpp' | |||
265 | --- backend/modules/Stopwatch/LapHistory/backend.cpp 2015-08-18 05:03:59 +0000 | |||
266 | +++ backend/modules/Stopwatch/backend.cpp 2015-08-26 22:51:08 +0000 | |||
267 | @@ -20,12 +20,14 @@ | |||
268 | 20 | #include <QtQml/QQmlContext> | 20 | #include <QtQml/QQmlContext> |
269 | 21 | #include "backend.h" | 21 | #include "backend.h" |
270 | 22 | #include "history.h" | 22 | #include "history.h" |
271 | 23 | #include "formattime.h" | ||
272 | 23 | 24 | ||
273 | 24 | void BackendPlugin::registerTypes(const char *uri) | 25 | void BackendPlugin::registerTypes(const char *uri) |
274 | 25 | { | 26 | { |
276 | 26 | Q_ASSERT(uri == QLatin1String("Stopwatch.LapHistory")); | 27 | Q_ASSERT(uri == QLatin1String("Stopwatch")); |
277 | 27 | 28 | ||
278 | 28 | qmlRegisterType<LapHistory>(uri, 1, 0, "LapHistory"); | 29 | qmlRegisterType<LapHistory>(uri, 1, 0, "LapHistory"); |
279 | 30 | qmlRegisterType<FormatTime>(uri, 1, 0, "StopwatchFormatTime"); | ||
280 | 29 | } | 31 | } |
281 | 30 | 32 | ||
282 | 31 | void BackendPlugin::initializeEngine(QQmlEngine *engine, const char *uri) | 33 | void BackendPlugin::initializeEngine(QQmlEngine *engine, const char *uri) |
283 | 32 | 34 | ||
284 | === renamed file 'backend/modules/Stopwatch/LapHistory/backend.h' => 'backend/modules/Stopwatch/backend.h' | |||
285 | === added file 'backend/modules/Stopwatch/formattime.cpp' | |||
286 | --- backend/modules/Stopwatch/formattime.cpp 1970-01-01 00:00:00 +0000 | |||
287 | +++ backend/modules/Stopwatch/formattime.cpp 2015-08-26 22:51:08 +0000 | |||
288 | @@ -0,0 +1,78 @@ | |||
289 | 1 | /* | ||
290 | 2 | * Copyright (C) 2015 Canonical Ltd | ||
291 | 3 | * | ||
292 | 4 | * This file is part of Ubuntu Clock App | ||
293 | 5 | * | ||
294 | 6 | * Ubuntu Clock App is free software: you can redistribute it and/or modify | ||
295 | 7 | * it under the terms of the GNU General Public License version 3 as | ||
296 | 8 | * published by the Free Software Foundation. | ||
297 | 9 | * | ||
298 | 10 | * Ubuntu Clock App is distributed in the hope that it will be useful, | ||
299 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
300 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
301 | 13 | * GNU General Public License for more details. | ||
302 | 14 | * | ||
303 | 15 | * You should have received a copy of the GNU General Public License | ||
304 | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
305 | 17 | */ | ||
306 | 18 | |||
307 | 19 | #include "formattime.h" | ||
308 | 20 | |||
309 | 21 | #include <QtMath> | ||
310 | 22 | |||
311 | 23 | FormatTime::FormatTime(QObject *parent): | ||
312 | 24 | QObject(parent) | ||
313 | 25 | { | ||
314 | 26 | } | ||
315 | 27 | |||
316 | 28 | QString FormatTime::millisToString(int millis) const | ||
317 | 29 | { | ||
318 | 30 | return addZeroPrefix(QString::number(millis), 3); | ||
319 | 31 | } | ||
320 | 32 | |||
321 | 33 | QString FormatTime::millisToTimeString(int millis, bool showHours) const | ||
322 | 34 | { | ||
323 | 35 | int hours, minutes, seconds; | ||
324 | 36 | |||
325 | 37 | seconds = qFloor(millis / 1000) % 60; | ||
326 | 38 | minutes = qFloor(millis / 1000 / 60) % 60; | ||
327 | 39 | hours = qFloor(millis / 1000 / 60 / 60); | ||
328 | 40 | |||
329 | 41 | QString timeString(""); | ||
330 | 42 | |||
331 | 43 | if (showHours) | ||
332 | 44 | { | ||
333 | 45 | if (hours < 10) | ||
334 | 46 | { | ||
335 | 47 | timeString += addZeroPrefix(QString::number(hours), 2) + ":"; | ||
336 | 48 | } | ||
337 | 49 | |||
338 | 50 | else { | ||
339 | 51 | timeString += QString::number(hours) + ":"; | ||
340 | 52 | } | ||
341 | 53 | } | ||
342 | 54 | |||
343 | 55 | timeString += addZeroPrefix(QString::number(minutes), 2) + ":"; | ||
344 | 56 | timeString += addZeroPrefix(QString::number(seconds), 2); | ||
345 | 57 | |||
346 | 58 | return timeString; | ||
347 | 59 | } | ||
348 | 60 | |||
349 | 61 | QString FormatTime::addZeroPrefix(QString str, int totalLength) const | ||
350 | 62 | { | ||
351 | 63 | return QString("00000" + str).remove(0, 5 + str.length() - totalLength); | ||
352 | 64 | } | ||
353 | 65 | |||
354 | 66 | QString FormatTime::lapTimeToString(int millis) const | ||
355 | 67 | { | ||
356 | 68 | int hours = qFloor(millis / 1000 / 60 / 60); | ||
357 | 69 | |||
358 | 70 | if (hours > 0) | ||
359 | 71 | { | ||
360 | 72 | return millisToTimeString(millis, true); | ||
361 | 73 | } | ||
362 | 74 | |||
363 | 75 | else { | ||
364 | 76 | return millisToTimeString(millis, false); | ||
365 | 77 | } | ||
366 | 78 | } | ||
367 | 0 | 79 | ||
368 | === added file 'backend/modules/Stopwatch/formattime.h' | |||
369 | --- backend/modules/Stopwatch/formattime.h 1970-01-01 00:00:00 +0000 | |||
370 | +++ backend/modules/Stopwatch/formattime.h 2015-08-26 22:51:08 +0000 | |||
371 | @@ -0,0 +1,38 @@ | |||
372 | 1 | /* | ||
373 | 2 | * Copyright (C) 2015 Canonical Ltd | ||
374 | 3 | * | ||
375 | 4 | * This file is part of Ubuntu Clock App | ||
376 | 5 | * | ||
377 | 6 | * Ubuntu Clock App is free software: you can redistribute it and/or modify | ||
378 | 7 | * it under the terms of the GNU General Public License version 3 as | ||
379 | 8 | * published by the Free Software Foundation. | ||
380 | 9 | * | ||
381 | 10 | * Ubuntu Clock App is distributed in the hope that it will be useful, | ||
382 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
383 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
384 | 13 | * GNU General Public License for more details. | ||
385 | 14 | * | ||
386 | 15 | * You should have received a copy of the GNU General Public License | ||
387 | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
388 | 17 | */ | ||
389 | 18 | |||
390 | 19 | #ifndef FORMATTIME_H | ||
391 | 20 | #define FORMATTIME_H | ||
392 | 21 | |||
393 | 22 | #include <QObject> | ||
394 | 23 | |||
395 | 24 | class FormatTime: public QObject | ||
396 | 25 | { | ||
397 | 26 | Q_OBJECT | ||
398 | 27 | |||
399 | 28 | public: | ||
400 | 29 | FormatTime(QObject *parent=0); | ||
401 | 30 | |||
402 | 31 | public slots: | ||
403 | 32 | QString millisToString(int millis) const; | ||
404 | 33 | QString millisToTimeString(int millis, bool showHours) const; | ||
405 | 34 | QString addZeroPrefix(QString str, int totalLength) const; | ||
406 | 35 | QString lapTimeToString(int millis) const; | ||
407 | 36 | }; | ||
408 | 37 | |||
409 | 38 | #endif | ||
410 | 0 | 39 | ||
411 | === renamed file 'backend/modules/Stopwatch/LapHistory/history.cpp' => 'backend/modules/Stopwatch/history.cpp' | |||
412 | === renamed file 'backend/modules/Stopwatch/LapHistory/history.h' => 'backend/modules/Stopwatch/history.h' | |||
413 | === renamed file 'backend/modules/Stopwatch/LapHistory/qmldir' => 'backend/modules/Stopwatch/qmldir' | |||
414 | --- backend/modules/Stopwatch/LapHistory/qmldir 2015-08-18 05:03:59 +0000 | |||
415 | +++ backend/modules/Stopwatch/qmldir 2015-08-26 22:51:08 +0000 | |||
416 | @@ -1,2 +1,2 @@ | |||
419 | 1 | module Stopwatch.LapHistory | 1 | module Stopwatch |
420 | 2 | plugin stopwatchlaphistory | 2 | plugin stopwatch |
421 | 3 | 3 | ||
422 | === modified file 'tests/unit/tst_stopwatchUtils.qml' | |||
423 | --- tests/unit/tst_stopwatchUtils.qml 2015-08-17 20:27:12 +0000 | |||
424 | +++ tests/unit/tst_stopwatchUtils.qml 2015-08-26 22:51:08 +0000 | |||
425 | @@ -18,15 +18,16 @@ | |||
426 | 18 | 18 | ||
427 | 19 | import QtQuick 2.4 | 19 | import QtQuick 2.4 |
428 | 20 | import QtTest 1.0 | 20 | import QtTest 1.0 |
429 | 21 | import Stopwatch 1.0 | ||
430 | 21 | import Ubuntu.Components 1.2 | 22 | import Ubuntu.Components 1.2 |
431 | 22 | import "../../app/stopwatch" | 23 | import "../../app/stopwatch" |
432 | 23 | 24 | ||
433 | 24 | TestCase { | 25 | TestCase { |
436 | 25 | id: stopwatchUtilsTest | 26 | id: stopwatchFormatTimeTest |
437 | 26 | name: "StopwatchUtilsLibrary" | 27 | name: "StopwatchFormatTimeLibrary" |
438 | 27 | 28 | ||
441 | 28 | StopwatchUtils { | 29 | StopwatchFormatTime { |
442 | 29 | id: stopwatchUtils | 30 | id: stopwatchFormatTime |
443 | 30 | } | 31 | } |
444 | 31 | 32 | ||
445 | 32 | /* | 33 | /* |
446 | @@ -35,9 +36,9 @@ | |||
447 | 35 | */ | 36 | */ |
448 | 36 | function test_returnMillisecond() { | 37 | function test_returnMillisecond() { |
449 | 37 | var result | 38 | var result |
451 | 38 | result = stopwatchUtils.millisToString(400) | 39 | result = stopwatchFormatTime.millisToString(400) |
452 | 39 | compare(result, "400", "Milliseconds not properly converted to the format required") | 40 | compare(result, "400", "Milliseconds not properly converted to the format required") |
454 | 40 | result = stopwatchUtils.millisToString(4) | 41 | result = stopwatchFormatTime.millisToString(4) |
455 | 41 | compare(result, "004", "Milliseconds not properly converted to the format required") | 42 | compare(result, "004", "Milliseconds not properly converted to the format required") |
456 | 42 | } | 43 | } |
457 | 43 | 44 | ||
458 | @@ -46,9 +47,11 @@ | |||
459 | 46 | correctly. | 47 | correctly. |
460 | 47 | */ | 48 | */ |
461 | 48 | function test_convertTimeInMillisecondsToString() { | 49 | function test_convertTimeInMillisecondsToString() { |
464 | 49 | var timeInMilliseconds = 1123000 | 50 | var timeInMilliseconds = 1123000, result |
465 | 50 | var result = stopwatchUtils.millisToTimeString(timeInMilliseconds, false, true) | 51 | result = stopwatchFormatTime.millisToTimeString(timeInMilliseconds, true) |
466 | 51 | compare(result, "00:18:43", "Time not properly converted from milliseconds to hh:mm:ss") | 52 | compare(result, "00:18:43", "Time not properly converted from milliseconds to hh:mm:ss") |
467 | 53 | result = stopwatchFormatTime.millisToTimeString(timeInMilliseconds, false) | ||
468 | 54 | compare(result, "18:43", "Time not properly converted from milliseconds to mm:ss") | ||
469 | 52 | } | 55 | } |
470 | 53 | 56 | ||
471 | 54 | /* | 57 | /* |
472 | @@ -57,11 +60,11 @@ | |||
473 | 57 | */ | 60 | */ |
474 | 58 | function test_zeroPrefixAddedCorrectly() { | 61 | function test_zeroPrefixAddedCorrectly() { |
475 | 59 | var str = "32", result | 62 | var str = "32", result |
477 | 60 | result = stopwatchUtils.addZeroPrefix(str, 2) | 63 | result = stopwatchFormatTime.addZeroPrefix(str, 2) |
478 | 61 | compare(result, "32", "Zero prefix not added correctly") | 64 | compare(result, "32", "Zero prefix not added correctly") |
480 | 62 | result = stopwatchUtils.addZeroPrefix(str, 3) | 65 | result = stopwatchFormatTime.addZeroPrefix(str, 3) |
481 | 63 | compare(result, "032", "Zero prefix not added correctly") | 66 | compare(result, "032", "Zero prefix not added correctly") |
483 | 64 | result = stopwatchUtils.addZeroPrefix(str, 4) | 67 | result = stopwatchFormatTime.addZeroPrefix(str, 4) |
484 | 65 | compare(result, "0032", "Zero prefix not added correctly") | 68 | compare(result, "0032", "Zero prefix not added correctly") |
485 | 66 | } | 69 | } |
486 | 67 | 70 | ||
487 | @@ -71,9 +74,9 @@ | |||
488 | 71 | */ | 74 | */ |
489 | 72 | function test_lapTimeIncludesHoursCorrectly() { | 75 | function test_lapTimeIncludesHoursCorrectly() { |
490 | 73 | var result | 76 | var result |
492 | 74 | result = stopwatchUtils.lapTimeToString(1123000) | 77 | result = stopwatchFormatTime.lapTimeToString(1123000) |
493 | 75 | compare(result, "18:43", "Lap time shows hours despite it not being greater than 0") | 78 | compare(result, "18:43", "Lap time shows hours despite it not being greater than 0") |
495 | 76 | result = stopwatchUtils.lapTimeToString(8323000) | 79 | result = stopwatchFormatTime.lapTimeToString(8323000) |
496 | 77 | compare(result, "02:18:43", "Lap time not showing hours despite it being greater than 0") | 80 | compare(result, "02:18:43", "Lap time not showing hours despite it being greater than 0") |
497 | 78 | } | 81 | } |
498 | 79 | } | 82 | } |
PASSED: Continuous integration, rev:363 91.189. 93.70:8080/ job/ubuntu- clock-app- ci/811/ 91.189. 93.70:8080/ job/ubuntu- clock-app- vivid-amd64- ci/156
http://
Executed test runs:
SUCCESS: http://
Click here to trigger a rebuild: 91.189. 93.70:8080/ job/ubuntu- clock-app- ci/811/ rebuild
http://