diff options
author | Sona Kurazyan <sona.kurazyan@qt.io> | 2021-11-26 15:49:18 +0100 |
---|---|---|
committer | Sona Kurazyan <sona.kurazyan@qt.io> | 2021-12-02 12:53:34 +0100 |
commit | 022891bcd8ae4e8de02cdef9ed281e9a31eedbc4 (patch) | |
tree | 31c3228b888f891298a75dc730eb45006f85a03b /examples/corelib/bindableproperties/bindablesubscription | |
parent | cee89e70a6011c3fcae29ad95d5fec4b2026d055 (diff) |
Document the example showing the benefits of using bindable properties
And mention the example in the bindable properties docs.
Pick-to: 6.2
Task-number: QTBUG-97655
Change-Id: I676e90dbda66c2e718c7f6c2240fac608a8653df
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'examples/corelib/bindableproperties/bindablesubscription')
5 files changed, 23 insertions, 0 deletions
diff --git a/examples/corelib/bindableproperties/bindablesubscription/bindablesubscription.cpp b/examples/corelib/bindableproperties/bindablesubscription/bindablesubscription.cpp index d962216cd9..14b28b3fae 100644 --- a/examples/corelib/bindableproperties/bindablesubscription/bindablesubscription.cpp +++ b/examples/corelib/bindableproperties/bindablesubscription/bindablesubscription.cpp @@ -51,6 +51,8 @@ #include "bindablesubscription.h" #include "bindableuser.h" +//! [binding-expressions] + BindableSubscription::BindableSubscription(BindableUser *user) : m_user(user) { Q_ASSERT(user); @@ -62,11 +64,17 @@ BindableSubscription::BindableSubscription(BindableUser *user) : m_user(user) }); } +//! [binding-expressions] + +//! [set-duration] + void BindableSubscription::setDuration(Duration newDuration) { m_duration = newDuration; } +//! [set-duration] + double BindableSubscription::calculateDiscount() const { switch (m_duration) { diff --git a/examples/corelib/bindableproperties/bindablesubscription/bindablesubscription.h b/examples/corelib/bindableproperties/bindablesubscription/bindablesubscription.h index 86dd0bdf26..763864d627 100644 --- a/examples/corelib/bindableproperties/bindablesubscription/bindablesubscription.h +++ b/examples/corelib/bindableproperties/bindablesubscription/bindablesubscription.h @@ -56,6 +56,8 @@ class BindableUser; +//! [bindable-subscription-class] + class BindableSubscription { public: @@ -84,4 +86,6 @@ private: QProperty<bool> m_isValid { false }; }; +//! [bindable-subscription-class] + #endif // BNDABLESUBSCRIPTION_H diff --git a/examples/corelib/bindableproperties/bindablesubscription/bindableuser.cpp b/examples/corelib/bindableproperties/bindablesubscription/bindableuser.cpp index fc651c2579..d30e203b61 100644 --- a/examples/corelib/bindableproperties/bindablesubscription/bindableuser.cpp +++ b/examples/corelib/bindableproperties/bindablesubscription/bindableuser.cpp @@ -50,6 +50,8 @@ #include "bindableuser.h" +//! [bindable-user-setters] + void BindableUser::setCountry(Country country) { m_country = country; @@ -59,3 +61,5 @@ void BindableUser::setAge(int age) { m_age = age; } + +//! [bindable-user-setters] diff --git a/examples/corelib/bindableproperties/bindablesubscription/bindableuser.h b/examples/corelib/bindableproperties/bindablesubscription/bindableuser.h index 1c37078076..65541e6ac1 100644 --- a/examples/corelib/bindableproperties/bindablesubscription/bindableuser.h +++ b/examples/corelib/bindableproperties/bindablesubscription/bindableuser.h @@ -53,6 +53,8 @@ #include <QProperty> +//! [bindable-user-class] + class BindableUser { public: @@ -78,4 +80,7 @@ private: QProperty<Country> m_country { None }; QProperty<int> m_age { 0 }; }; + +//! [bindable-user-class] + #endif // BINDABLEUSER_H diff --git a/examples/corelib/bindableproperties/bindablesubscription/main.cpp b/examples/corelib/bindableproperties/bindablesubscription/main.cpp index 2ee39c5bb5..df935679ad 100644 --- a/examples/corelib/bindableproperties/bindablesubscription/main.cpp +++ b/examples/corelib/bindableproperties/bindablesubscription/main.cpp @@ -103,6 +103,7 @@ int main(int argc, char *argv[]) QLabel *priceDisplay = w.findChild<QLabel *>("priceDisplay"); // Track price changes +//! [update-ui] auto priceChangeHandler = subscription.bindablePrice().subscribe([&] { priceDisplay->setText(QString::number(subscription.price())); }); @@ -110,6 +111,7 @@ int main(int argc, char *argv[]) auto priceValidHandler = subscription.bindableIsValid().subscribe([&] { priceDisplay->setEnabled(subscription.isValid()); }); +//! [update-ui] w.show(); return a.exec(); |