Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Has binding #75

Merged
merged 2 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
11 changes: 10 additions & 1 deletion tests/property/tst_property.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ class DummyPropertyUpdater : public PropertyUpdater<int>
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")
{
Expand Down 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
Loading