aboutsummaryrefslogtreecommitdiffstats
path: root/src/webchannel/qmetaobjectpublisher.cpp
diff options
context:
space:
mode:
authorØystein Heskestad <oystein.heskestad@qt.io>2021-04-26 11:19:36 +0200
committerØystein Heskestad <oystein.heskestad@qt.io>2021-05-05 11:34:38 +0200
commit491d4e8dd223f428b95e8a26af2c44692687f248 (patch)
tree093df49dba89f042a966205149308dbc794bcd65 /src/webchannel/qmetaobjectpublisher.cpp
parent87ca0ba70cd9cb4cd33e4c59986ede6b40cfe4be (diff)
Make property update interval configurable and add tests
[ChangeLog] Make the property update interval configurable Fixes: QTBUG-92928 Change-Id: I0b02ae0c0879c1a3891d5807c1ff8c1f619841b2 Reviewed-by: Arno Rehn <a.rehn@menlosystems.com>
Diffstat (limited to 'src/webchannel/qmetaobjectpublisher.cpp')
-rw-r--r--src/webchannel/qmetaobjectpublisher.cpp39
1 files changed, 29 insertions, 10 deletions
diff --git a/src/webchannel/qmetaobjectpublisher.cpp b/src/webchannel/qmetaobjectpublisher.cpp
index b40aeab..5f2f9dc 100644
--- a/src/webchannel/qmetaobjectpublisher.cpp
+++ b/src/webchannel/qmetaobjectpublisher.cpp
@@ -177,8 +177,6 @@ QJsonObject createResponse(const QJsonValue &id, const QJsonValue &data)
return response;
}
-/// TODO: what is the proper value here?
-const int PROPERTY_UPDATE_INTERVAL = 50;
}
Q_DECLARE_TYPEINFO(OverloadResolutionCandidate, Q_MOVABLE_TYPE);
@@ -202,11 +200,14 @@ void QWebChannelPropertyChangeNotifier::notify(
}
QMetaObjectPublisher::QMetaObjectPublisher(QWebChannel *webChannel)
- : QObject(webChannel)
- , webChannel(webChannel)
- , clientIsIdle(false)
- , blockUpdates(false)
- , propertyUpdatesInitialized(false)
+ : QObject(webChannel),
+ webChannel(webChannel),
+ clientIsIdle(false),
+ blockUpdates(false),
+ propertyUpdatesInitialized(false),
+ propertyUpdateIntervalTime(50),
+ propertyUpdateIntervalHandler(propertyUpdateIntervalTime.onValueChanged(
+ std::function([&]() { this->startPropertyUpdateTimer(true); })))
{
}
@@ -618,10 +619,15 @@ void QMetaObjectPublisher::propertyValueChanged(const QObject *object, const int
startPropertyUpdateTimer();
}
-void QMetaObjectPublisher::startPropertyUpdateTimer()
+void QMetaObjectPublisher::startPropertyUpdateTimer(bool forceRestart)
{
- if (clientIsIdle && !blockUpdates && !timer.isActive()) {
- timer.start(PROPERTY_UPDATE_INTERVAL, this);
+ if (!clientIsIdle || blockUpdates)
+ return;
+ if (propertyUpdateIntervalTime >= 0) {
+ if (forceRestart || !timer.isActive())
+ timer.start(propertyUpdateIntervalTime, this);
+ } else {
+ sendPendingPropertyUpdates();
}
}
@@ -1014,6 +1020,16 @@ void QMetaObjectPublisher::handleMessage(const QJsonObject &message, QWebChannel
}
}
+int QMetaObjectPublisher::propertyUpdateInterval()
+{
+ return propertyUpdateIntervalTime;
+}
+
+void QMetaObjectPublisher::setPropertyUpdateInterval(int ms)
+{
+ propertyUpdateIntervalTime = ms;
+}
+
void QMetaObjectPublisher::setBlockUpdates(bool block)
{
if (blockUpdates == block) {
@@ -1022,6 +1038,7 @@ void QMetaObjectPublisher::setBlockUpdates(bool block)
blockUpdates = block;
if (!blockUpdates) {
+ startPropertyUpdateTimer();
sendPendingPropertyUpdates();
} else if (timer.isActive()) {
timer.stop();
@@ -1033,6 +1050,8 @@ void QMetaObjectPublisher::setBlockUpdates(bool block)
void QMetaObjectPublisher::timerEvent(QTimerEvent *event)
{
if (event->timerId() == timer.timerId()) {
+ if (propertyUpdateIntervalTime <= 0)
+ timer.stop();
sendPendingPropertyUpdates();
} else {
QObject::timerEvent(event);