From f3bdfcce2812eb43074e363b95e463b2f3ebc412 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaakko=20Kera=CC=88nen?= Date: Wed, 14 Nov 2018 10:25:24 +0200 Subject: [PATCH] Widgets|libcore: Checking for layout rectangle validity --- .../libcore/include/de/widgets/indirectrule.h | 2 ++ .../include/de/widgets/rulerectangle.h | 2 ++ .../sdk/libcore/src/widgets/indirectrule.cpp | 11 +++++--- .../sdk/libcore/src/widgets/rulerectangle.cpp | 27 +++++++++++++++++-- 4 files changed, 37 insertions(+), 5 deletions(-) diff --git a/doomsday/sdk/libcore/include/de/widgets/indirectrule.h b/doomsday/sdk/libcore/include/de/widgets/indirectrule.h index 7062aa0a4b..c7a64a6075 100644 --- a/doomsday/sdk/libcore/include/de/widgets/indirectrule.h +++ b/doomsday/sdk/libcore/include/de/widgets/indirectrule.h @@ -49,6 +49,8 @@ class DENG2_PUBLIC IndirectRule : public Rule void unsetSource(); + bool hasSource() const; + void update(); Rule const &source() const; diff --git a/doomsday/sdk/libcore/include/de/widgets/rulerectangle.h b/doomsday/sdk/libcore/include/de/widgets/rulerectangle.h index 809e9cc6b7..011cf28dad 100644 --- a/doomsday/sdk/libcore/include/de/widgets/rulerectangle.h +++ b/doomsday/sdk/libcore/include/de/widgets/rulerectangle.h @@ -150,6 +150,8 @@ class DENG2_PUBLIC RuleRectangle : public ISizeRule void setDebugName(String const &name); + bool isFullyDefined() const; + String description() const; private: diff --git a/doomsday/sdk/libcore/src/widgets/indirectrule.cpp b/doomsday/sdk/libcore/src/widgets/indirectrule.cpp index 93ca312b7a..188fdcaafb 100644 --- a/doomsday/sdk/libcore/src/widgets/indirectrule.cpp +++ b/doomsday/sdk/libcore/src/widgets/indirectrule.cpp @@ -20,7 +20,7 @@ namespace de { -IndirectRule::IndirectRule() : _source(0) +IndirectRule::IndirectRule() : _source(nullptr) {} IndirectRule::~IndirectRule() @@ -42,9 +42,14 @@ void IndirectRule::unsetSource() invalidate(); } +bool IndirectRule::hasSource() const +{ + return _source != nullptr; +} + void IndirectRule::update() { - setValue(_source? _source->value() : 0); + setValue(_source ? _source->value() : 0.f); } Rule const &IndirectRule::source() const @@ -61,7 +66,7 @@ String IndirectRule::description() const } else { - return String("(null)"); + return String("[0]"); } } diff --git a/doomsday/sdk/libcore/src/widgets/rulerectangle.cpp b/doomsday/sdk/libcore/src/widgets/rulerectangle.cpp index b7b5e840fe..50382233d6 100644 --- a/doomsday/sdk/libcore/src/widgets/rulerectangle.cpp +++ b/doomsday/sdk/libcore/src/widgets/rulerectangle.cpp @@ -409,13 +409,25 @@ void RuleRectangle::setDebugName(String const &name) d->debugName = name; } +bool RuleRectangle::isFullyDefined() const +{ + for (const auto *out : d->outputRules) + { + if (!out->hasSource()) + { + return false; + } + } + return true; +} + String RuleRectangle::description() const { String desc = QString("RuleRectangle '%1'").arg(d->debugName); for (int i = 0; i < int(Rule::MAX_SEMANTICS); ++i) { - desc += String("\n - ") + + desc += String("\n INPUT ") + (i == Rule::Left? "Left" : i == Rule::Top? "Top" : i == Rule::Right? "Right" : @@ -430,9 +442,20 @@ String RuleRectangle::description() const } else { - desc += "(null)"; + desc += "(not set)"; } } + for (int i = 0; i < Impl::MAX_OUTPUT_RULES; ++i) + { + desc += String::format("\n OUTPUT %s: ", + i == Impl::OutLeft ? "Left" + : i == Impl::OutTop ? "Top" + : i == Impl::OutRight ? "Right" + : i == Impl::OutBottom ? "Bottom" + : i == Impl::OutWidth ? "Width" + : "Height"); + desc += d->outputRules[i]->description(); + } return desc; }