summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Buhr <andreas.buhr@qt.io>2021-01-28 11:00:08 +0100
committerAndreas Buhr <andreas.buhr@qt.io>2021-01-29 16:06:19 +0100
commita1a2d97e34eb7e2445877cf9e557db55a3540f9d (patch)
tree84710b494567be61f45360adab301dadf46cb5cc
parent115bcdb862ec52ebda04e1337f978096d8879e6d (diff)
Remove QObjectCompatProperty::operator= for safer usage
Introduction of QObjectCompatProperty requires every write to the property to be examined whether it is OK or should be replaced by a setValueBypassingBindings/markDirty combination. The existence of operator= make this difficult as it is easy to miss places where it is written. By not having operator=, we can help developers make sure they had a conscious decision about each write to the property. Change-Id: Ia61ea4722eb0bab26ce7684b85dd03d710cd1751 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
-rw-r--r--src/corelib/animation/qpauseanimation.cpp2
-rw-r--r--src/corelib/kernel/qproperty_p.h6
-rw-r--r--src/gui/image/qmovie.cpp2
-rw-r--r--tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp22
4 files changed, 13 insertions, 19 deletions
diff --git a/src/corelib/animation/qpauseanimation.cpp b/src/corelib/animation/qpauseanimation.cpp
index d6fa0eb210..31802f094d 100644
--- a/src/corelib/animation/qpauseanimation.cpp
+++ b/src/corelib/animation/qpauseanimation.cpp
@@ -129,7 +129,7 @@ void QPauseAnimation::setDuration(int msecs)
return;
}
Q_D(QPauseAnimation);
- d->duration = msecs;
+ d->duration.setValue(msecs);
}
QBindable<int> QPauseAnimation::bindableDuration()
diff --git a/src/corelib/kernel/qproperty_p.h b/src/corelib/kernel/qproperty_p.h
index 27cb8c907f..f4fee1befb 100644
--- a/src/corelib/kernel/qproperty_p.h
+++ b/src/corelib/kernel/qproperty_p.h
@@ -461,12 +461,6 @@ public:
notify(bd);
}
- QObjectCompatProperty &operator=(parameter_type newValue)
- {
- setValue(newValue);
- return *this;
- }
-
QPropertyBinding<T> setBinding(const QPropertyBinding<T> &newBinding)
{
QtPrivate::QPropertyBindingData *bd = qGetBindingStorage(owner())->bindingData(this, true);
diff --git a/src/gui/image/qmovie.cpp b/src/gui/image/qmovie.cpp
index 0e1cf4481e..a98a4ed154 100644
--- a/src/gui/image/qmovie.cpp
+++ b/src/gui/image/qmovie.cpp
@@ -929,7 +929,7 @@ void QMovie::setSpeed(int percentSpeed)
Q_D(QMovie);
if (!d->speed && d->movieState == Running)
d->nextImageTimer.start(nextFrameDelay());
- d->speed = percentSpeed;
+ d->speed.setValue(percentSpeed);
}
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 630eee9e9c..6062c23189 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 = i; }
+ void setEagerProp(int i) { eagerData.setValue(i); }
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 = i; }
+ void setEagerProp2(int i) { eagerData2.setValue(i); }
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 = i; } \
+ void setProp##N(int i) { propData##N.setValue(i); } \
QBindable<int> bindableProp##N() {return QBindable<int>(&propData##N);} \
Q_OBJECT_COMPAT_PROPERTY(ReallocTester, int, propData##N, &ReallocTester::setProp##N)
GEN(1)
@@ -1063,7 +1063,7 @@ public:
++setCompatCalled;
if (i < 0)
i = 0;
- compatData = i;
+ compatData.setValue(i);
emit compatChanged();
}
@@ -1201,7 +1201,7 @@ void tst_QProperty::compatBindings()
QCOMPARE(object.compatData, 0);
// setting data through the private interface should not call the changed signal or the public setter
- object.compatData = 10;
+ object.compatData.setValue(10);
QCOMPARE(object.compatChangedCount, 0);
QCOMPARE(object.setCompatCalled, 0);
// going through the public API should emit the signal
@@ -1390,7 +1390,7 @@ class CompatPropertyTester : public QObject
CompatPropertyTester(QObject *parent = nullptr) : QObject(parent) { }
int prop1() {return prop1Data.value();}
- void setProp1(int i) { prop1Data = i; }
+ void setProp1(int i) { prop1Data.setValue(i); }
QBindable<int> bindableProp1() {return QBindable<int>(&prop1Data);}
Q_OBJECT_COMPAT_PROPERTY(CompatPropertyTester, int, prop1Data, &CompatPropertyTester::setProp1)
@@ -1421,9 +1421,9 @@ signals:
void prop3Changed();
public:
- void setProp1(int val) { prop1Data = val; emit prop1Changed();}
- void setProp2(int val) { prop2Data = val; emit prop2Changed();}
- void setProp3(int val) { prop3Data = val; emit prop3Changed();}
+ 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();}
int prop1() { return prop1Data; }
int prop2() { return prop2Data; }
@@ -1496,7 +1496,7 @@ public:
QBindable<CustomType> bindableProp2() { return QBindable<CustomType>(&prop2Data); }
CustomType prop3() { return prop3Data.value(); }
- void setProp3(CustomType val) { prop3Data = val; }
+ void setProp3(CustomType val) { prop3Data.setValue(val); }
QBindable<CustomType> bindableProp3() { return QBindable<CustomType>(&prop3Data); }
Q_OBJECT_BINDABLE_PROPERTY_WITH_ARGS(PropertyWithInitializationTester, int, prop1Data, 5,
@@ -1533,7 +1533,7 @@ public:
QBindable<int> bindableValue1() {return { &m_value1 };}
int value2() const {return m_value2;}
- void setValue2(int val) {m_value2 = val;}
+ void setValue2(int val) { m_value2.setValue(val); }
QBindable<int> bindableValue2() {return { &m_value2 };}
int computed() const { return staticValue + m_value1; }