summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2021-02-03 12:02:29 +0100
committerFabian Kosmale <fabian.kosmale@qt.io>2021-04-01 10:04:27 +0200
commit2ffb91ac592d69adf9458ac45074174537435918 (patch)
treef9a6873e1c735c795fe55ac4cbae90c6a633eac2
parentaa84de1afa78cf4b63239b35a4b65f1c9c4eab6c (diff)
QObjectCompatProperty: Require explicit notify
For QObjectCompatProperty, which allows to do basically anything in its setter, it is actually easier to manually specify when the change should become visible. This is in line with manually writing emit calls in the old property system, and allows the preservation of class invariants. Change-Id: I585bd3f25d722ca3fd721ead85fe73dbee26c5f6 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
-rw-r--r--src/corelib/animation/qpauseanimation.cpp1
-rw-r--r--src/corelib/kernel/qproperty_p.h5
-rw-r--r--src/corelib/kernel/qtimer.cpp9
-rw-r--r--src/gui/image/qmovie.cpp1
-rw-r--r--tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp15
5 files changed, 13 insertions, 18 deletions
diff --git a/src/corelib/animation/qpauseanimation.cpp b/src/corelib/animation/qpauseanimation.cpp
index 31802f094d..c2599da692 100644
--- a/src/corelib/animation/qpauseanimation.cpp
+++ b/src/corelib/animation/qpauseanimation.cpp
@@ -130,6 +130,7 @@ void QPauseAnimation::setDuration(int msecs)
}
Q_D(QPauseAnimation);
d->duration.setValue(msecs);
+ d->duration.notify();
}
QBindable<int> QPauseAnimation::bindableDuration()
diff --git a/src/corelib/kernel/qproperty_p.h b/src/corelib/kernel/qproperty_p.h
index d1f4c5acba..a355a7faea 100644
--- a/src/corelib/kernel/qproperty_p.h
+++ b/src/corelib/kernel/qproperty_p.h
@@ -467,12 +467,7 @@ public:
const bool inWrapper = inBindingWrapper(storage);
if (bd && !inWrapper)
bd->removeBinding();
- if constexpr (QTypeTraits::has_operator_equal_v<T>)
- if (this->val == t)
- return;
this->val = t;
- if (!inWrapper)
- notify(bd);
}
QPropertyBinding<T> setBinding(const QPropertyBinding<T> &newBinding)
diff --git a/src/corelib/kernel/qtimer.cpp b/src/corelib/kernel/qtimer.cpp
index 49c57cb6ee..0946e1af48 100644
--- a/src/corelib/kernel/qtimer.cpp
+++ b/src/corelib/kernel/qtimer.cpp
@@ -257,10 +257,9 @@ void QTimer::start()
void QTimer::start(int msec)
{
Q_D(QTimer);
- d->inter.removeBindingUnlessInWrapper();
- d->inter.setValueBypassingBindings(msec);
+ d->inter.setValue(msec);
start();
- d->inter.markDirty();
+ d->inter.notify();
}
@@ -754,9 +753,7 @@ QBindable<bool> QTimer::bindableSingleShot()
void QTimer::setInterval(int msec)
{
Q_D(QTimer);
- d->inter.removeBindingUnlessInWrapper();
-
- d->inter.setValueBypassingBindings(msec);
+ d->inter.setValue(msec);
if (d->id != INV_TIMER) { // create new timer
QObject::killTimer(d->id); // restart timer
d->id = QObject::startTimer(msec, d->type);
diff --git a/src/gui/image/qmovie.cpp b/src/gui/image/qmovie.cpp
index a98a4ed154..a293d358cf 100644
--- a/src/gui/image/qmovie.cpp
+++ b/src/gui/image/qmovie.cpp
@@ -930,6 +930,7 @@ void QMovie::setSpeed(int percentSpeed)
if (!d->speed && d->movieState == Running)
d->nextImageTimer.start(nextFrameDelay());
d->speed.setValue(percentSpeed);
+ d->speed.notify();
}
int QMovie::speed() const
diff --git a/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp b/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp
index 6062c23189..4186607d90 100644
--- a/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp
+++ b/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp
@@ -469,12 +469,12 @@ class BindingLoopTester : public QObject
BindingLoopTester() {}
int eagerProp() {return eagerData.value();}
- void setEagerProp(int i) { eagerData.setValue(i); }
+ void setEagerProp(int i) { eagerData.setValue(i); eagerData.notify(); }
QBindable<int> bindableEagerProp() {return QBindable<int>(&eagerData);}
Q_OBJECT_COMPAT_PROPERTY(BindingLoopTester, int, eagerData, &BindingLoopTester::setEagerProp)
int eagerProp2() {return eagerData2.value();}
- void setEagerProp2(int i) { eagerData2.setValue(i); }
+ void setEagerProp2(int i) { eagerData2.setValue(i); eagerData2.notify(); }
QBindable<int> bindableEagerProp2() {return QBindable<int>(&eagerData2);}
Q_OBJECT_COMPAT_PROPERTY(BindingLoopTester, int, eagerData2, &BindingLoopTester::setEagerProp2)
};
@@ -536,7 +536,7 @@ public:
#define GEN(N) \
int prop##N() {return propData##N.value();} \
- void setProp##N(int i) { propData##N.setValue(i); } \
+ void setProp##N(int i) { if (i == propData##N) return; propData##N.setValue(i); propData##N.notify(); } \
QBindable<int> bindableProp##N() {return QBindable<int>(&propData##N);} \
Q_OBJECT_COMPAT_PROPERTY(ReallocTester, int, propData##N, &ReallocTester::setProp##N)
GEN(1)
@@ -1064,6 +1064,7 @@ public:
if (i < 0)
i = 0;
compatData.setValue(i);
+ compatData.notify();
emit compatChanged();
}
@@ -1390,7 +1391,7 @@ class CompatPropertyTester : public QObject
CompatPropertyTester(QObject *parent = nullptr) : QObject(parent) { }
int prop1() {return prop1Data.value();}
- void setProp1(int i) { prop1Data.setValue(i); }
+ void setProp1(int i) { if (i == prop1Data) return; prop1Data.setValue(i); prop1Data.notify(); }
QBindable<int> bindableProp1() {return QBindable<int>(&prop1Data);}
Q_OBJECT_COMPAT_PROPERTY(CompatPropertyTester, int, prop1Data, &CompatPropertyTester::setProp1)
@@ -1421,9 +1422,9 @@ signals:
void prop3Changed();
public:
- void setProp1(int val) { prop1Data.setValue(val); emit prop1Changed();}
- void setProp2(int val) { prop2Data.setValue(val); emit prop2Changed();}
- void setProp3(int val) { prop3Data.setValue(val); emit prop3Changed();}
+ void setProp1(int val) { prop1Data.setValue(val); prop1Data.notify(); emit prop1Changed();}
+ void setProp2(int val) { prop2Data.setValue(val); prop2Data.notify(); emit prop2Changed();}
+ void setProp3(int val) { prop3Data.setValue(val); prop3Data.notify(); emit prop3Changed();}
int prop1() { return prop1Data; }
int prop2() { return prop2Data; }