Make the signal argument in Q_OBJECT_BINDABLE_PROPERTY optional
The intention was always that you can define properties that do not require a changed signal. But having to explicitly pass a nullptr as signal parameter into the macro is ugly, so use the cool QT_OVERLOADED_MACRO to make it optional. Pick-to: 6.0 Change-Id: I0ce366d043850f983c968d73c544d89933c48df9 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This commit is contained in:
parent
cb064dee3a
commit
cb39ea0581
@ -952,6 +952,9 @@ QString QPropertyBindingError::description() const
|
||||
Q_OBJECT_BINDABLE_PROPERTY(MyClass, int, xProp, &MyClass::xChanged)
|
||||
};
|
||||
\endcode
|
||||
|
||||
If the property does not need a changed notification, you can leave out the "NOFITY xChanged" in the Q_PROPERTY macro as well as the last argument
|
||||
of the Q_OBJECT_BINDABLE_PROPERTY macro.
|
||||
*/
|
||||
|
||||
/*!
|
||||
|
@ -1013,13 +1013,23 @@ private:
|
||||
}
|
||||
};
|
||||
|
||||
#define Q_OBJECT_BINDABLE_PROPERTY(Class, Type, name, ...) \
|
||||
#define Q_OBJECT_BINDABLE_PROPERTY3(Class, Type, name) \
|
||||
static constexpr size_t _qt_property_##name##_offset() { \
|
||||
QT_WARNING_PUSH QT_WARNING_DISABLE_INVALID_OFFSETOF \
|
||||
return offsetof(Class, name); \
|
||||
QT_WARNING_POP \
|
||||
} \
|
||||
QObjectBindableProperty<Class, Type, Class::_qt_property_##name##_offset, __VA_ARGS__> name;
|
||||
QObjectBindableProperty<Class, Type, Class::_qt_property_##name##_offset, nullptr> name;
|
||||
|
||||
#define Q_OBJECT_BINDABLE_PROPERTY4(Class, Type, name, Signal) \
|
||||
static constexpr size_t _qt_property_##name##_offset() { \
|
||||
QT_WARNING_PUSH QT_WARNING_DISABLE_INVALID_OFFSETOF \
|
||||
return offsetof(Class, name); \
|
||||
QT_WARNING_POP \
|
||||
} \
|
||||
QObjectBindableProperty<Class, Type, Class::_qt_property_##name##_offset, Signal> name;
|
||||
|
||||
#define Q_OBJECT_BINDABLE_PROPERTY(...) QT_OVERLOADED_MACRO(Q_OBJECT_BINDABLE_PROPERTY, __VA_ARGS__)
|
||||
|
||||
template<typename Class, typename T, auto Offset, auto Getter>
|
||||
class QObjectComputedProperty : public QUntypedPropertyData
|
||||
|
@ -999,20 +999,18 @@ class MyQObject : public QObject
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(int foo READ foo WRITE setFoo BINDABLE bindableFoo NOTIFY fooChanged)
|
||||
Q_PROPERTY(int bar READ bar WRITE setBar BINDABLE bindableBar NOTIFY barChanged)
|
||||
Q_PROPERTY(int read READ read NOTIFY readChanged)
|
||||
Q_PROPERTY(int read READ read)
|
||||
Q_PROPERTY(int computed READ computed STORED false)
|
||||
Q_PROPERTY(int compat READ compat WRITE setCompat NOTIFY compatChanged)
|
||||
|
||||
signals:
|
||||
void fooChanged();
|
||||
void barChanged();
|
||||
void readChanged();
|
||||
void compatChanged();
|
||||
|
||||
public slots:
|
||||
void fooHasChanged() { fooChangedCount++; }
|
||||
void barHasChanged() { barChangedCount++; }
|
||||
void readHasChanged() { readChangedCount++; }
|
||||
void compatHasChanged() { compatChangedCount++; }
|
||||
|
||||
public:
|
||||
@ -1044,13 +1042,12 @@ public:
|
||||
public:
|
||||
int fooChangedCount = 0;
|
||||
int barChangedCount = 0;
|
||||
int readChangedCount = 0;
|
||||
int compatChangedCount = 0;
|
||||
int setCompatCalled = 0;
|
||||
|
||||
Q_OBJECT_BINDABLE_PROPERTY(MyQObject, int, fooData, &MyQObject::fooChanged);
|
||||
Q_OBJECT_BINDABLE_PROPERTY(MyQObject, int, barData, &MyQObject::barChanged);
|
||||
Q_OBJECT_BINDABLE_PROPERTY(MyQObject, int, readData, &MyQObject::readChanged);
|
||||
Q_OBJECT_BINDABLE_PROPERTY(MyQObject, int, readData);
|
||||
Q_OBJECT_COMPUTED_PROPERTY(MyQObject, int, computedData, &MyQObject::computed);
|
||||
Q_OBJECT_COMPAT_PROPERTY(MyQObject, int, compatData, &MyQObject::setCompat)
|
||||
};
|
||||
@ -1060,7 +1057,6 @@ void tst_QProperty::testNewStuff()
|
||||
MyQObject object;
|
||||
QObject::connect(&object, &MyQObject::fooChanged, &object, &MyQObject::fooHasChanged);
|
||||
QObject::connect(&object, &MyQObject::barChanged, &object, &MyQObject::barHasChanged);
|
||||
QObject::connect(&object, &MyQObject::readChanged, &object, &MyQObject::readHasChanged);
|
||||
|
||||
QCOMPARE(object.fooChangedCount, 0);
|
||||
object.setFoo(10);
|
||||
|
Loading…
Reference in New Issue
Block a user