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
=== modified file 'app/MainPage.qml'
--- app/MainPage.qml 2015-09-11 13:13:17 +0000
+++ app/MainPage.qml 2015-09-11 13:37:52 +0000
@@ -19,7 +19,6 @@
19import QtQuick 2.419import QtQuick 2.4
20import Ubuntu.Components 1.220import Ubuntu.Components 1.2
21import QtSystemInfo 5.021import QtSystemInfo 5.0
22import Stopwatch 1.0
23import Qt.labs.settings 1.022import Qt.labs.settings 1.0
24import "upstreamcomponents"23import "upstreamcomponents"
25import "alarm"24import "alarm"
@@ -56,13 +55,9 @@
56 id: alarmUtils55 id: alarmUtils
57 }56 }
5857
59 StopwatchEngine {
60 id: stopwatchEngine
61 }
62
63 ScreenSaver {58 ScreenSaver {
64 // Disable screen dimming/off when stopwatch is running59 // Disable screen dimming/off when stopwatch is running
65 screenSaverEnabled: !stopwatchEngine.running60 screenSaverEnabled: !stopwatchPage.isRunning
66 }61 }
6762
68 VisualItemModel {63 VisualItemModel {
@@ -95,6 +90,13 @@
95 ListView {90 ListView {
96 id: listview91 id: listview
9792
93 // Show the stopwatch page on app startup if it is running
94 Component.onCompleted: {
95 if (stopwatchPage.isRunning) {
96 positionViewAtIndex(1, ListView.SnapPosition)
97 }
98 }
99
98 anchors {100 anchors {
99 top: headerRow.bottom101 top: headerRow.bottom
100 left: parent.left102 left: parent.left
@@ -108,12 +110,5 @@
108 interactive: false110 interactive: false
109 highlightMoveDuration: UbuntuAnimation.BriskDuration111 highlightMoveDuration: UbuntuAnimation.BriskDuration
110 highlightRangeMode: ListView.StrictlyEnforceRange112 highlightRangeMode: ListView.StrictlyEnforceRange
111
112 // Show the stopwatch page on app startup if it is running
113 Component.onCompleted: {
114 if (stopwatchEngine.running) {
115 positionViewAtIndex(1, ListView.SnapPosition)
116 }
117 }
118 }113 }
119}114}
120115
=== modified file 'app/stopwatch/StopwatchPage.qml'
--- app/stopwatch/StopwatchPage.qml 2015-09-10 20:38:50 +0000
+++ app/stopwatch/StopwatchPage.qml 2015-09-11 13:37:52 +0000
@@ -17,24 +17,21 @@
17 */17 */
1818
19import QtQuick 2.419import QtQuick 2.4
20import Stopwatch 1.0
20import Ubuntu.Components 1.221import Ubuntu.Components 1.2
2122
22Item {23Item {
23 id: _stopwatchPage24 id: _stopwatchPage
24 objectName: "stopwatchPage"25 objectName: "stopwatchPage"
2526
27 property alias isRunning: stopwatchEngine.running
28
26 Component.onCompleted: {29 Component.onCompleted: {
27 console.log("[LOG]: Stopwatch Page Loaded")30 console.log("[LOG]: Stopwatch Page Loaded")
28 }31 }
2932
30 Timer {33 StopwatchEngine {
31 id: refreshTimer34 id: stopwatchEngine
32 interval: 45
33 repeat: true
34 running: stopwatchEngine.running
35 onTriggered: {
36 stopwatchEngine.updateStopwatch();
37 }
38 }35 }
3936
40 StopwatchFace {37 StopwatchFace {
4138
=== modified file 'backend/modules/Stopwatch/engine.cpp'
--- backend/modules/Stopwatch/engine.cpp 2015-09-10 22:58:10 +0000
+++ backend/modules/Stopwatch/engine.cpp 2015-09-11 13:37:52 +0000
@@ -33,6 +33,10 @@
33 m_totalTimeInmsecs(0)33 m_totalTimeInmsecs(0)
34{34{
35 qDebug() << "[LOG] Loading laps from " << m_settings.fileName();35 qDebug() << "[LOG] Loading laps from " << m_settings.fileName();
36
37 m_timer.setInterval(45);
38 connect(&m_timer, &QTimer::timeout, this, &StopwatchEngine::updateStopwatch);
39
36 QDateTime startTime = m_settings.value("Stopwatch/startDateTime").toDateTime();40 QDateTime startTime = m_settings.value("Stopwatch/startDateTime").toDateTime();
37 if(startTime.isValid())41 if(startTime.isValid())
38 {42 {
@@ -45,6 +49,11 @@
45 if(m_previousTimeInmsecs != 0) {49 if(m_previousTimeInmsecs != 0) {
46 setTotalTimeOfStopwatch(m_previousTimeInmsecs);50 setTotalTimeOfStopwatch(m_previousTimeInmsecs);
47 }51 }
52
53 if(m_isStopwatchRunning == true)
54 {
55 m_timer.start();
56 }
48}57}
4958
50int StopwatchEngine::rowCount(const QModelIndex &parent) const59int StopwatchEngine::rowCount(const QModelIndex &parent) const
@@ -114,6 +123,7 @@
114{123{
115 setStopwatchStartDateTime();124 setStopwatchStartDateTime();
116 setRunning(true);125 setRunning(true);
126 m_timer.start();
117}127}
118128
119void StopwatchEngine::updateStopwatch()129void StopwatchEngine::updateStopwatch()
@@ -126,6 +136,7 @@
126 setPreviousTimeOfStopwatch(m_previousTimeInmsecs + m_stopwatchStartDateTime.msecsTo(QDateTime::currentDateTimeUtc()));136 setPreviousTimeOfStopwatch(m_previousTimeInmsecs + m_stopwatchStartDateTime.msecsTo(QDateTime::currentDateTimeUtc()));
127 setTotalTimeOfStopwatch(m_previousTimeInmsecs);137 setTotalTimeOfStopwatch(m_previousTimeInmsecs);
128 setRunning(false);138 setRunning(false);
139 m_timer.stop();
129}140}
130141
131void StopwatchEngine::clearStopwatch()142void StopwatchEngine::clearStopwatch()
132143
=== modified file 'backend/modules/Stopwatch/engine.h'
--- backend/modules/Stopwatch/engine.h 2015-09-10 22:45:38 +0000
+++ backend/modules/Stopwatch/engine.h 2015-09-11 13:37:52 +0000
@@ -20,6 +20,7 @@
20#define ENGINE_H20#define ENGINE_H
2121
22#include <QAbstractListModel>22#include <QAbstractListModel>
23#include <QTimer>
23#include <QSettings>24#include <QSettings>
24#include <QDateTime>25#include <QDateTime>
2526
@@ -70,20 +71,21 @@
70 */71 */
71 QHash<int, QByteArray> roleNames() const override;72 QHash<int, QByteArray> roleNames() const override;
7273
73public slots:
74 void addLap();
75 void removeLap(int lapIndex);
76
77 void startStopwatch();
78 void pauseStopwatch();
79 void clearStopwatch();
80 void updateStopwatch();
81
82 // Getter functions for the properties74 // Getter functions for the properties
83 bool running() const;75 bool running() const;
84 int totalTimeOfStopwatch() const;76 int totalTimeOfStopwatch() const;
85 int previousTimeOfStopwatch() const;77 int previousTimeOfStopwatch() const;
8678
79 Q_INVOKABLE void addLap();
80 Q_INVOKABLE void removeLap(int lapIndex);
81
82 Q_INVOKABLE void startStopwatch();
83 Q_INVOKABLE void pauseStopwatch();
84 Q_INVOKABLE void clearStopwatch();
85
86private slots:
87 void updateStopwatch();
88
87private:89private:
88 void setStopwatchStartDateTime();90 void setStopwatchStartDateTime();
8991
@@ -94,6 +96,7 @@
94 QSettings m_settings;96 QSettings m_settings;
9597
96 QDateTime m_stopwatchStartDateTime;98 QDateTime m_stopwatchStartDateTime;
99 QTimer m_timer;
97100
98 bool m_isStopwatchRunning;101 bool m_isStopwatchRunning;
99 int m_previousTimeInmsecs;102 int m_previousTimeInmsecs;

Subscribers

People subscribed via source and target branches