From 5f0e57ebc7e12a7325667fe3e5c95e06cd04388a Mon Sep 17 00:00:00 2001 From: Ivan Solovev Date: Mon, 25 Oct 2021 17:45:29 +0200 Subject: QObjectComputedProperty docs: move example to snippet This patch amends 89a4c8d40d2ee1b8794dd7fcf80d226c5c87ba6c. It moves the code sample into a separate snippet file, which allows us to use Q_OBJECT macro in it without complaints from moc. Task-number: QTBUG-97656 Pick-to: 6.2 Change-Id: I368d8dd8c00dbbebd8a6bf3788be796c8ca4bce8 Reviewed-by: Fabian Kosmale --- .../snippets/code/src_corelib_kernel_qproperty.cpp | 37 ++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'src/corelib/doc/snippets/code') diff --git a/src/corelib/doc/snippets/code/src_corelib_kernel_qproperty.cpp b/src/corelib/doc/snippets/code/src_corelib_kernel_qproperty.cpp index 3d63abe590..ae1d2202e7 100644 --- a/src/corelib/doc/snippets/code/src_corelib_kernel_qproperty.cpp +++ b/src/corelib/doc/snippets/code/src_corelib_kernel_qproperty.cpp @@ -160,3 +160,40 @@ int main() #include "main.moc" //! [4] + +//! [5] +class Client{}; + +class MyClassPrivate : public QObjectPrivate +{ +public: + QList clients; + bool hasClientsActualCalculation() const { return clients.size() > 0; } + Q_OBJECT_COMPUTED_PROPERTY(MyClassPrivate, bool, hasClientsData, + &MyClassPrivate::hasClientsActualCalculation) +}; + +class MyClass : public QObject +{ + Q_OBJECT + Q_PROPERTY(bool hasClients READ hasClients STORED false BINDABLE bindableHasClients) +public: + QBindable bindableHasClients() + { + return QBindable(&d_func()->hasClientsData); + } + bool hasClients() const + { + return d_func()->hasClientsData.value(); + } + void addClient(const Client &c) + { + Q_D(MyClass); + d->clients.push_back(c); + // notify that the value could have changed + d->hasClientsData.markDirty(); + } +private: + Q_DECLARE_PRIVATE(MyClass) +}; +//! [5] -- cgit v1.2.3