diff options
author | Ivan Solovev <ivan.solovev@qt.io> | 2021-10-25 17:45:29 +0200 |
---|---|---|
committer | Ivan Solovev <ivan.solovev@qt.io> | 2021-10-26 10:18:07 +0200 |
commit | 5f0e57ebc7e12a7325667fe3e5c95e06cd04388a (patch) | |
tree | 28c292feb3eb70dd1ea4b45fdb339a6486b44dff /src/corelib/doc/snippets | |
parent | da632baf34ef2308da04c56c497e115b9d1ad531 (diff) |
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 <fabian.kosmale@qt.io>
Diffstat (limited to 'src/corelib/doc/snippets')
-rw-r--r-- | src/corelib/doc/snippets/code/src_corelib_kernel_qproperty.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
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<Client> 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<bool> bindableHasClients() + { + return QBindable<bool>(&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] |