Skip to content

Commit

Permalink
Add a convenience function to test if a property has a binding
Browse files Browse the repository at this point in the history
Closes #74.
  • Loading branch information
seanharmer authored and LeonMatthesKDAB committed Jun 11, 2024
1 parent 3453ba0 commit 296bbdb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/kdbindings/property.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ struct equal_to {
// Property can declare PropertyNode as a friend
// class.
namespace Private {
template<typename PropertyType>
class PropertyNode;
template<typename PropertyType>
class PropertyNode;
}

/**
Expand Down Expand Up @@ -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.
*
Expand Down
9 changes: 9 additions & 0 deletions tests/property/tst_property.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> property(std::make_unique<DummyPropertyUpdater>(7));
REQUIRE(property.hasBinding() == true);

Property<int> property2(7);
REQUIRE(property2.hasBinding() == false);
}
}

TEST_CASE("Moving")
Expand Down

0 comments on commit 296bbdb

Please sign in to comment.