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
=== modified file 'app/MainPage.qml'
--- app/MainPage.qml 2015-09-10 08:50:16 +0000
+++ app/MainPage.qml 2015-09-10 22:58:17 +0000
@@ -58,7 +58,7 @@
5858
59 ScreenSaver {59 ScreenSaver {
60 // Disable screen dimming/off when stopwatch is running60 // Disable screen dimming/off when stopwatch is running
61 screenSaverEnabled: !stopwatchEngine.isRunning61 screenSaverEnabled: !stopwatchEngine.running
62 }62 }
6363
64 StopwatchEngine {64 StopwatchEngine {
@@ -97,7 +97,7 @@
9797
98 // Show the stopwatch page on app startup if it is running98 // Show the stopwatch page on app startup if it is running
99 Component.onCompleted: {99 Component.onCompleted: {
100 if (stopwatchEngine.isRunning) {100 if (stopwatchEngine.running) {
101 positionViewAtIndex(1, ListView.SnapPosition)101 positionViewAtIndex(1, ListView.SnapPosition)
102 }102 }
103 }103 }
104104
=== modified file 'app/stopwatch/StopwatchPage.qml'
--- app/stopwatch/StopwatchPage.qml 2015-09-10 08:11:37 +0000
+++ app/stopwatch/StopwatchPage.qml 2015-09-10 22:58:17 +0000
@@ -31,9 +31,9 @@
31 id: refreshTimer31 id: refreshTimer
32 interval: 4532 interval: 45
33 repeat: true33 repeat: true
34 running: stopwatchEngine.isRunning34 running: stopwatchEngine.running
35 onTriggered: {35 onTriggered: {
36 stopwatch.milliseconds = stopwatchEngine.totalTimeOfStopwatch36 stopwatchEngine.updateStopwatch();
37 }37 }
38 }38 }
3939
@@ -64,11 +64,11 @@
6464
65 Button {65 Button {
66 id: stopButton66 id: stopButton
67 width: stopwatchEngine.previousTimeOfStopwatch !== 0 || stopwatchEngine.isRunning ? (parent.width - parent.spacing) / 2 : parent.width67 width: stopwatchEngine.previousTimeOfStopwatch !== 0 || stopwatchEngine.running ? (parent.width - parent.spacing) / 2 : parent.width
68 color: !stopwatchEngine.isRunning ? UbuntuColors.green : UbuntuColors.red68 color: !stopwatchEngine.running ? UbuntuColors.green : UbuntuColors.red
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"))
70 onClicked: {70 onClicked: {
71 if (stopwatchEngine.isRunning) {71 if (stopwatchEngine.running) {
72 stopwatchEngine.pauseStopwatch();72 stopwatchEngine.pauseStopwatch();
73 } else {73 } else {
74 stopwatchEngine.startStopwatch();74 stopwatchEngine.startStopwatch();
@@ -83,12 +83,12 @@
8383
84 Button {84 Button {
85 id: lapButton85 id: lapButton
86 text: stopwatchEngine.isRunning ? i18n.tr("Lap") : i18n.tr("Clear")86 text: stopwatchEngine.running ? i18n.tr("Lap") : i18n.tr("Clear")
87 width: stopwatchEngine.previousTimeOfStopwatch !== 0 || stopwatchEngine.isRunning ? (parent.width - parent.spacing) / 2 : 087 width: stopwatchEngine.previousTimeOfStopwatch !== 0 || stopwatchEngine.running ? (parent.width - parent.spacing) / 2 : 0
88 strokeColor: UbuntuColors.lightGrey88 strokeColor: UbuntuColors.lightGrey
89 visible: stopwatchEngine.previousTimeOfStopwatch !== 0 || stopwatchEngine.isRunning89 visible: stopwatchEngine.previousTimeOfStopwatch !== 0 || stopwatchEngine.running
90 onClicked: {90 onClicked: {
91 if (stopwatchEngine.isRunning) {91 if (stopwatchEngine.running) {
92 stopwatchEngine.addLap()92 stopwatchEngine.addLap()
93 } else {93 } else {
94 stopwatchEngine.clearStopwatch()94 stopwatchEngine.clearStopwatch()
@@ -116,7 +116,7 @@
116 Loader {116 Loader {
117 id: lapListViewLoader117 id: lapListViewLoader
118 anchors.fill: parent118 anchors.fill: parent
119 sourceComponent: !stopwatchEngine.isRunning && stopwatchEngine.totalTimeOfStopwatch === 0 ? undefined : lapListViewComponent119 sourceComponent: !stopwatchEngine.running && stopwatchEngine.totalTimeOfStopwatch === 0 ? undefined : lapListViewComponent
120 }120 }
121 }121 }
122122
123123
=== modified file 'backend/modules/Stopwatch/engine.cpp'
--- backend/modules/Stopwatch/engine.cpp 2015-09-10 01:09:57 +0000
+++ backend/modules/Stopwatch/engine.cpp 2015-09-10 22:58:17 +0000
@@ -28,7 +28,9 @@
28 when Ubuntu Touch moves over to Qt 5.5. AppConfigLocation will directly return28 when Ubuntu Touch moves over to Qt 5.5. AppConfigLocation will directly return
29 /home/phablet/.config/com.ubuntu.clock path.29 /home/phablet/.config/com.ubuntu.clock path.
30 */30 */
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),
32 m_previousTimeInmsecs(0),
33 m_totalTimeInmsecs(0)
32{34{
33 qDebug() << "[LOG] Loading laps from " << m_settings.fileName();35 qDebug() << "[LOG] Loading laps from " << m_settings.fileName();
34 QDateTime startTime = m_settings.value("Stopwatch/startDateTime").toDateTime();36 QDateTime startTime = m_settings.value("Stopwatch/startDateTime").toDateTime();
@@ -36,13 +38,13 @@
36 {38 {
37 m_stopwatchStartDateTime = startTime;39 m_stopwatchStartDateTime = startTime;
38 }40 }
39 else
40 {
41 startStopwatch();
42 }
4341
44 m_isStopwatchRunning = m_settings.value("Stopwatch/isStopwatchRunning").toBool();42 m_isStopwatchRunning = m_settings.value("Stopwatch/isStopwatchRunning").toBool();
45 m_previousTimeInmsecs = m_settings.value("Stopwatch/previousTimeInmsecs").toInt();43 m_previousTimeInmsecs = m_settings.value("Stopwatch/previousTimeInmsecs").toInt();
44
45 if(m_previousTimeInmsecs != 0) {
46 setTotalTimeOfStopwatch(m_previousTimeInmsecs);
47 }
46}48}
4749
48int StopwatchEngine::rowCount(const QModelIndex &parent) const50int StopwatchEngine::rowCount(const QModelIndex &parent) const
@@ -87,7 +89,7 @@
87{89{
88 QVariantList laps = m_settings.value("Stopwatch/laps").toList();90 QVariantList laps = m_settings.value("Stopwatch/laps").toList();
89 beginInsertRows(QModelIndex(), 0, 0);91 beginInsertRows(QModelIndex(), 0, 0);
90 int timeDiff = getTotalTimeOfStopwatch();92 int timeDiff = m_totalTimeInmsecs;
91 laps.prepend(timeDiff);93 laps.prepend(timeDiff);
92 m_settings.setValue("Stopwatch/laps", laps);94 m_settings.setValue("Stopwatch/laps", laps);
93 endInsertRows();95 endInsertRows();
@@ -102,67 +104,74 @@
102 endRemoveRows();104 endRemoveRows();
103}105}
104106
107void StopwatchEngine::setStopwatchStartDateTime()
108{
109 m_stopwatchStartDateTime = QDateTime::currentDateTimeUtc();
110 m_settings.setValue("Stopwatch/startDateTime", m_stopwatchStartDateTime);
111}
112
105void StopwatchEngine::startStopwatch()113void StopwatchEngine::startStopwatch()
106{114{
107 if(m_isStopwatchRunning == false)115 setStopwatchStartDateTime();
108 {116 setRunning(true);
109 m_stopwatchStartDateTime = QDateTime::currentDateTimeUtc();117}
110 m_settings.setValue("Stopwatch/startDateTime", m_stopwatchStartDateTime);
111118
112 setIsRunning(true);119void StopwatchEngine::updateStopwatch()
113 }120{
121 setTotalTimeOfStopwatch(m_previousTimeInmsecs + m_stopwatchStartDateTime.msecsTo(QDateTime::currentDateTimeUtc()));
114}122}
115123
116void StopwatchEngine::pauseStopwatch()124void StopwatchEngine::pauseStopwatch()
117{125{
118 setPreviousTimeOfStopwatch(m_previousTimeInmsecs + m_stopwatchStartDateTime.msecsTo(QDateTime::currentDateTimeUtc()));126 setPreviousTimeOfStopwatch(m_previousTimeInmsecs + m_stopwatchStartDateTime.msecsTo(QDateTime::currentDateTimeUtc()));
119 setIsRunning(false);127 setTotalTimeOfStopwatch(m_previousTimeInmsecs);
128 setRunning(false);
120}129}
121130
122void StopwatchEngine::clearStopwatch()131void StopwatchEngine::clearStopwatch()
123{132{
133 setPreviousTimeOfStopwatch(0);
124 setTotalTimeOfStopwatch(0);134 setTotalTimeOfStopwatch(0);
125 setPreviousTimeOfStopwatch(0);
126135
127 beginResetModel();136 beginResetModel();
128 m_settings.setValue("Stopwatch/laps", QVariantList());137 m_settings.setValue("Stopwatch/laps", QVariantList());
129 endResetModel();138 endResetModel();
130
131 setIsRunning(false);
132}139}
133140
134bool StopwatchEngine::getIsRunning()141bool StopwatchEngine::running() const
135{142{
136 return m_isStopwatchRunning;143 return m_isStopwatchRunning;
137}144}
138145
139int StopwatchEngine::getPreviousTimeOfStopwatch()146int StopwatchEngine::previousTimeOfStopwatch() const
140{147{
141 return m_previousTimeInmsecs;148 return m_previousTimeInmsecs;
142}149}
143150
144int StopwatchEngine::getTotalTimeOfStopwatch()151int StopwatchEngine::totalTimeOfStopwatch() const
145{152{
146 if(m_isStopwatchRunning == false)
147 {
148 m_totalTimeInmsecs = m_previousTimeInmsecs;
149 }
150 else
151 {
152 m_totalTimeInmsecs = m_previousTimeInmsecs + m_stopwatchStartDateTime.msecsTo(QDateTime::currentDateTimeUtc());
153 }
154 return m_totalTimeInmsecs;153 return m_totalTimeInmsecs;
155}154}
156155
157void StopwatchEngine::setIsRunning(bool value)156void StopwatchEngine::setRunning(bool value)
158{157{
158 if(value == m_isStopwatchRunning)
159 {
160 return;
161 }
162
159 m_isStopwatchRunning = value;163 m_isStopwatchRunning = value;
160 m_settings.setValue("Stopwatch/isStopwatchRunning", m_isStopwatchRunning);164 m_settings.setValue("Stopwatch/isStopwatchRunning", m_isStopwatchRunning);
161 emit isRunningChanged();165 emit runningChanged();
162}166}
163167
164void StopwatchEngine::setPreviousTimeOfStopwatch(int value)168void StopwatchEngine::setPreviousTimeOfStopwatch(int value)
165{169{
170 if(value == m_previousTimeInmsecs)
171 {
172 return;
173 }
174
166 m_previousTimeInmsecs = value;175 m_previousTimeInmsecs = value;
167 m_settings.setValue("Stopwatch/previousTimeInmsecs", m_previousTimeInmsecs);176 m_settings.setValue("Stopwatch/previousTimeInmsecs", m_previousTimeInmsecs);
168 emit previousTimeOfStopwatchChanged();177 emit previousTimeOfStopwatchChanged();
@@ -170,6 +179,11 @@
170179
171void StopwatchEngine::setTotalTimeOfStopwatch(int value)180void StopwatchEngine::setTotalTimeOfStopwatch(int value)
172{181{
182 if(value == m_totalTimeInmsecs)
183 {
184 return;
185 }
186
173 m_totalTimeInmsecs = value;187 m_totalTimeInmsecs = value;
174 emit totalTimeOfStopwatchChanged();188 emit totalTimeOfStopwatchChanged();
175}189}
176190
=== modified file 'backend/modules/Stopwatch/engine.h'
--- backend/modules/Stopwatch/engine.h 2015-09-10 10:58:51 +0000
+++ backend/modules/Stopwatch/engine.h 2015-09-10 22:58:17 +0000
@@ -27,21 +27,21 @@
27{27{
28 Q_OBJECT28 Q_OBJECT
2929
30 Q_PROPERTY( bool isRunning30 Q_PROPERTY( bool running
31 READ getIsRunning31 READ running
32 NOTIFY isRunningChanged)32 NOTIFY runningChanged)
3333
34 Q_PROPERTY( int totalTimeOfStopwatch34 Q_PROPERTY( int totalTimeOfStopwatch
35 READ getTotalTimeOfStopwatch35 READ totalTimeOfStopwatch
36 NOTIFY totalTimeOfStopwatchChanged)36 NOTIFY totalTimeOfStopwatchChanged)
3737
38 Q_PROPERTY( int previousTimeOfStopwatch38 Q_PROPERTY( int previousTimeOfStopwatch
39 READ getPreviousTimeOfStopwatch39 READ previousTimeOfStopwatch
40 NOTIFY previousTimeOfStopwatchChanged)40 NOTIFY previousTimeOfStopwatchChanged)
4141
42signals:42signals:
43 // Signal to notify the running status change to QML43 // Signal to notify the running status change to QML
44 void isRunningChanged();44 void runningChanged();
4545
46 // Signal to notify the total time change to QML46 // Signal to notify the total time change to QML
47 void totalTimeOfStopwatchChanged();47 void totalTimeOfStopwatchChanged();
@@ -71,34 +71,30 @@
71 QHash<int, QByteArray> roleNames() const override;71 QHash<int, QByteArray> roleNames() const override;
7272
73public slots:73public slots:
74 // Function to add a stopwatch lap
75 void addLap();74 void addLap();
76
77 // Function to remove a stopwatch lap
78 void removeLap(int lapIndex);75 void removeLap(int lapIndex);
7976
80 void startStopwatch();77 void startStopwatch();
81
82 void pauseStopwatch();78 void pauseStopwatch();
83
84 void clearStopwatch();79 void clearStopwatch();
8580 void updateStopwatch();
86 bool getIsRunning();81
8782 // Getter functions for the properties
88 int getTotalTimeOfStopwatch();83 bool running() const;
8984 int totalTimeOfStopwatch() const;
90 int getPreviousTimeOfStopwatch();85 int previousTimeOfStopwatch() const;
9186
92private:87private:
93 void setIsRunning(bool value);88 void setStopwatchStartDateTime();
9489
90 void setRunning(bool value);
95 void setTotalTimeOfStopwatch(int value);91 void setTotalTimeOfStopwatch(int value);
96
97 void setPreviousTimeOfStopwatch(int value);92 void setPreviousTimeOfStopwatch(int value);
9893
99 QSettings m_settings;94 QSettings m_settings;
10095
101 QDateTime m_stopwatchStartDateTime;96 QDateTime m_stopwatchStartDateTime;
97
102 bool m_isStopwatchRunning;98 bool m_isStopwatchRunning;
103 int m_previousTimeInmsecs;99 int m_previousTimeInmsecs;
104 int m_totalTimeInmsecs;100 int m_totalTimeInmsecs;

Subscribers

People subscribed via source and target branches