Skip to content

Commit

Permalink
Make double-property limitless by default, instead of previous `nonne…
Browse files Browse the repository at this point in the history
…gative` option
  • Loading branch information
gpospelov committed Dec 27, 2020
1 parent 51afd5e commit 68aa44c
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 23 deletions.
4 changes: 1 addition & 3 deletions examples/celleditors/celleditorscore/samplemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ DemoPropertiesItem::DemoPropertiesItem() : CompoundItem(::Constants::DemoPropert
addProperty(P_BOOL_PROPERTY, true)->setDisplayName("Bool")->setToolTip("tooltip");
addProperty(P_INTEGER_PROPERTY, 42)->setDisplayName("Integer");
addProperty(P_STRING_PROPERTY, "abc")->setDisplayName("String");
addProperty(P_DOUBLE_PROPERTY, 42.1234)
->setDisplayName("Double")
->setLimits(RealLimits::limitless());
addProperty(P_DOUBLE_PROPERTY, 42.1234)->setDisplayName("Double");
addProperty(P_COLOR_PROPERTY, QColor(Qt::green))->setDisplayName("Color");

auto combo = ComboProperty::createFrom({"option 1", "option 2", "option 3"});
Expand Down
14 changes: 5 additions & 9 deletions examples/collidingmice/collidingmicecore/mousemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,16 @@
#include <cmath>

namespace {
static const int MouseCount = 7;
const int MouseCount = 7;
} // namespace

MouseItem::MouseItem() : ModelView::CompoundItem("MouseItem")
{
addProperty(P_COLOR, QColor(Qt::red))->setDisplayName("Color");
addProperty(P_XPOS, 0.0)->setLimits(ModelView::RealLimits::limitless())->setDisplayName("X");
addProperty(P_YPOS, 0.0)->setLimits(ModelView::RealLimits::limitless())->setDisplayName("Y");
addProperty(P_ANGLE, 0.0)
->setLimits(ModelView::RealLimits::limitless())
->setDisplayName("Angle of yaw");
addProperty(P_SPEED, 0.0)
->setLimits(ModelView::RealLimits::limitless())
->setDisplayName("Speed");
addProperty(P_XPOS, 0.0)->setDisplayName("X");
addProperty(P_YPOS, 0.0)->setDisplayName("Y");
addProperty(P_ANGLE, 0.0)->setDisplayName("Angle of yaw");
addProperty(P_SPEED, 0.0)->setDisplayName("Speed");
}

// ----------------------------------------------------------------------------
Expand Down
8 changes: 4 additions & 4 deletions examples/graphicsproxy/graphicsproxycore/sceneitems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ using namespace ModelView;

RegionOfInterestItem::RegionOfInterestItem() : CompoundItem(RegionOfInterestItemType)
{
addProperty(P_XLOW, 0.0)->setDisplayName("Xlow")->setLimits(RealLimits::limitless());
addProperty(P_YLOW, 0.0)->setDisplayName("Ylow")->setLimits(RealLimits::limitless());
addProperty(P_XUP, 0.0)->setDisplayName("Xup")->setLimits(RealLimits::limitless());
addProperty(P_YUP, 0.0)->setDisplayName("Yup")->setLimits(RealLimits::limitless());
addProperty(P_XLOW, 0.0)->setDisplayName("Xlow");
addProperty(P_YLOW, 0.0)->setDisplayName("Ylow");
addProperty(P_XUP, 0.0)->setDisplayName("Xup");
addProperty(P_YUP, 0.0)->setDisplayName("Yup");
}
4 changes: 1 addition & 3 deletions source/libmvvm_model/mvvm/model/compounditem.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,8 @@ PropertyItem* CompoundItem::addProperty(const std::string& name, const V& value)
property->setDisplayName(name);
property->setData(value);

// FIXME consider limitless values by default.

if constexpr (std::is_floating_point_v<V>)
property->setData(RealLimits::nonnegative(), ItemDataRole::LIMITS);
property->setData(RealLimits::limitless(), ItemDataRole::LIMITS);

insertItem(property, {name, 0});
return property;
Expand Down
4 changes: 2 additions & 2 deletions source/libmvvm_model/mvvm/standarditems/axisitems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ BasicAxisItem::BasicAxisItem(const std::string& model_type) : CompoundItem(model

void BasicAxisItem::register_min_max()
{
addProperty(P_MIN, default_axis_min)->setDisplayName("Min")->setLimits(RealLimits::limitless());
addProperty(P_MAX, default_axis_max)->setDisplayName("Max")->setLimits(RealLimits::limitless());
addProperty(P_MIN, default_axis_min)->setDisplayName("Min");
addProperty(P_MAX, default_axis_max)->setDisplayName("Max");
}

// --- ViewportAxisItem ------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions tests/testmodel/compounditem.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ TEST_F(CompoundItemTest, addDoubleProperty)

EXPECT_TRUE(propertyItem->data<QVariant>(ItemDataRole::LIMITS).isValid());

// limits should be non negative by default
// limits should be "negative 'unlimited' by default
auto limits = propertyItem->data<RealLimits>(ItemDataRole::LIMITS);
EXPECT_TRUE(limits.hasLowerLimit());
EXPECT_FALSE(limits.hasLowerLimit());
EXPECT_FALSE(limits.hasUpperLimit());
}

Expand Down

0 comments on commit 68aa44c

Please sign in to comment.