summaryrefslogtreecommitdiff
path: root/tests/manual/qmlextensionplugins/timemodel.cpp
diff options
context:
space:
mode:
authorOlivier De Cannière <olivier.decanniere@qt.io>2023-04-28 11:08:02 +0200
committerOlivier De Cannière <olivier.decanniere@qt.io>2023-05-12 15:06:42 +0200
commitd88b52b541a0482b69639dbea8976287db9ca52b (patch)
tree459b4e3e373a23a7e0578aece4dc4b5cccaf9ba4 /tests/manual/qmlextensionplugins/timemodel.cpp
parent13fc038d8d4baa9e199fbd5a7e4c08650a88172e (diff)
downloadqtdeclarative-d88b52b541a0482b69639dbea8976287db9ca52b.tar.gz
Examples: Move Qml plugin example to manual tests
Outdated documention has been removed. Task-number: QTBUG-111036 Change-Id: I8db138ff71615a6ed6ac4cebdb365c27252fa5ee Pick-to: 6.5 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'tests/manual/qmlextensionplugins/timemodel.cpp')
-rw-r--r--tests/manual/qmlextensionplugins/timemodel.cpp51
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/manual/qmlextensionplugins/timemodel.cpp b/tests/manual/qmlextensionplugins/timemodel.cpp
new file mode 100644
index 0000000000..a94a7e773d
--- /dev/null
+++ b/tests/manual/qmlextensionplugins/timemodel.cpp
@@ -0,0 +1,51 @@
+// Copyright (C) 2017 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+#include "timemodel.h"
+
+int TimeModel::instances=0;
+MinuteTimer *TimeModel::timer=nullptr;
+
+void MinuteTimer::start()
+{
+ if (!timer.isActive()) {
+ time = QTime::currentTime();
+ timer.start(60000-time.second()*1000, this);
+ }
+}
+
+void MinuteTimer::stop()
+{
+ timer.stop();
+}
+
+void MinuteTimer::timerEvent(QTimerEvent *)
+{
+ QTime now = QTime::currentTime();
+ if (now.second() == 59 && now.minute() == time.minute() && now.hour() == time.hour()) {
+ // just missed time tick over, force it, wait extra 0.5 seconds
+ time = time.addSecs(60);
+ timer.start(60500, this);
+ } else {
+ time = now;
+ timer.start(60000-time.second()*1000, this);
+ }
+ emit timeChanged();
+}
+
+TimeModel::TimeModel(QObject *parent) : QObject(parent)
+{
+ if (++instances == 1) {
+ if (!timer)
+ timer = new MinuteTimer(QCoreApplication::instance());
+ connect(timer, &MinuteTimer::timeChanged, this, &TimeModel::timeChanged);
+ timer->start();
+ }
+}
+
+TimeModel::~TimeModel()
+{
+ if (--instances == 0) {
+ timer->stop();
+ }
+}