From 296bbdbf788fe325dd95f206715b1f2527a35cf0 Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Tue, 11 Jun 2024 10:40:44 +0100 Subject: [PATCH] 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")