From 6464b9d4f5f248881c83053d8f778e371b9eb7ba Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Tue, 11 Jun 2024 10:40:44 +0100 Subject: [PATCH 1/2] Add a convenience function to test if a property has a binding Closes #74. --- src/kdbindings/property.h | 9 +++++++-- tests/property/tst_property.cpp | 9 +++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/kdbindings/property.h b/src/kdbindings/property.h index 98f4a4c..c88c082 100644 --- a/src/kdbindings/property.h +++ b/src/kdbindings/property.h @@ -108,8 +108,8 @@ struct equal_to { // Property can declare PropertyNode as a friend // class. namespace Private { - template - class PropertyNode; +template +class PropertyNode; } /** @@ -300,6 +300,11 @@ class Property */ Signal<> &destroyed() const { return m_destroyed; } + /** + * Returns true if this Property has a binding associated with it. + */ + bool hasBinding() const noexcept { return m_updater.get() != nullptr; } + /** * Assign a new value to this Property. * diff --git a/tests/property/tst_property.cpp b/tests/property/tst_property.cpp index 3676da5..9776eb0 100644 --- a/tests/property/tst_property.cpp +++ b/tests/property/tst_property.cpp @@ -261,6 +261,15 @@ TEST_CASE("Property Updators") REQUIRE(slotCalled); REQUIRE(updatedValue == 123); } + + SUBCASE("Can query a property to see if it has an updater") + { + Property property(std::make_unique(7)); + REQUIRE(property.hasBinding() == true); + + Property property2(7); + REQUIRE(property2.hasBinding() == false); + } } TEST_CASE("Moving") From 6279f90f53827a16c9f7e13214a2ed0850aea49b Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Tue, 11 Jun 2024 10:41:05 +0100 Subject: [PATCH 2/2] Fix typo --- tests/property/tst_property.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/property/tst_property.cpp b/tests/property/tst_property.cpp index 9776eb0..4db93d5 100644 --- a/tests/property/tst_property.cpp +++ b/tests/property/tst_property.cpp @@ -229,7 +229,7 @@ class DummyPropertyUpdater : public PropertyUpdater int m_value; }; -TEST_CASE("Property Updators") +TEST_CASE("Property Updaters") { SUBCASE("Can construct a property with an updater and the property assumes its value") {