aboutsummaryrefslogtreecommitdiffstats
path: root/examples/qml/qmlextensionplugins/plugin.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'examples/qml/qmlextensionplugins/plugin.cpp')
-rw-r--r--examples/qml/qmlextensionplugins/plugin.cpp108
1 files changed, 2 insertions, 106 deletions
diff --git a/examples/qml/qmlextensionplugins/plugin.cpp b/examples/qml/qmlextensionplugins/plugin.cpp
index a6d1d3ff63..99d8c5378c 100644
--- a/examples/qml/qmlextensionplugins/plugin.cpp
+++ b/examples/qml/qmlextensionplugins/plugin.cpp
@@ -49,117 +49,13 @@
****************************************************************************/
#include <QtQml/QQmlExtensionPlugin>
-#include <QtQml/qqml.h>
#include <qdebug.h>
-#include <qdatetime.h>
-#include <qbasictimer.h>
-#include <qcoreapplication.h>
-
-// Implements a "TimeModel" class with hour and minute properties
-// that change on-the-minute yet efficiently sleep the rest
-// of the time.
-
-class MinuteTimer : public QObject
-{
- Q_OBJECT
-public:
- MinuteTimer(QObject *parent) : QObject(parent)
- {
- }
-
- void start()
- {
- if (!timer.isActive()) {
- time = QTime::currentTime();
- timer.start(60000-time.second()*1000, this);
- }
- }
-
- void stop()
- {
- timer.stop();
- }
-
- int hour() const { return time.hour(); }
- int minute() const { return time.minute(); }
-
-signals:
- void timeChanged();
-
-protected:
- void timerEvent(QTimerEvent *) override
- {
- 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();
- }
-
-private:
- QTime time;
- QBasicTimer timer;
-};
-
-//![0]
-class TimeModel : public QObject
-{
- Q_OBJECT
- Q_PROPERTY(int hour READ hour NOTIFY timeChanged)
- Q_PROPERTY(int minute READ minute NOTIFY timeChanged)
- QML_NAMED_ELEMENT(Time)
-//![0]
-
-public:
- TimeModel(QObject *parent=nullptr) : QObject(parent)
- {
- if (++instances == 1) {
- if (!timer)
- timer = new MinuteTimer(QCoreApplication::instance());
- connect(timer, &MinuteTimer::timeChanged, this, &TimeModel::timeChanged);
- timer->start();
- }
- }
-
- ~TimeModel() override
- {
- if (--instances == 0) {
- timer->stop();
- }
- }
-
- int minute() const { return timer->minute(); }
- int hour() const { return timer->hour(); }
-
-signals:
- void timeChanged();
-
-private:
- QTime t;
- static MinuteTimer *timer;
- static int instances;
-};
-
-int TimeModel::instances=0;
-MinuteTimer *TimeModel::timer=nullptr;
//![plugin]
-class QExampleQmlPlugin : public QQmlExtensionPlugin
+class QExampleQmlPlugin : public QQmlEngineExtensionPlugin
{
Q_OBJECT
- Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid)
-
-public:
- void registerTypes(const char *uri) override
- {
- Q_ASSERT(uri == QLatin1String("TimeExample"));
- qmlRegisterTypesAndRevisions<TimeModel>(uri, 1);
- }
+ Q_PLUGIN_METADATA(IID QQmlEngineExtensionInterface_iid)
};
//![plugin]