From 8926ed6f361ac0a1fe5ea476cec705b345d4ea27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Fri, 7 Sep 2018 17:08:03 +0200 Subject: [PATCH] [poincare] Un)iline some layotu constructors --- .../include/poincare/horizontal_layout_node.h | 32 ++++--------------- .../include/poincare/nth_root_layout_node.h | 14 ++------ .../poincare/right_parenthesis_layout_node.h | 2 +- .../right_square_bracket_layout_node.h | 4 +-- .../poincare/vertical_offset_layout_node.h | 7 +--- poincare/src/horizontal_layout_node.cpp | 27 ++++++++++++++++ poincare/src/nth_root_layout_node.cpp | 12 +++++++ .../src/right_parenthesis_layout_node.cpp | 9 ++---- .../src/right_square_bracket_layout_node.cpp | 2 ++ poincare/src/vertical_offset_layout_node.cpp | 7 ++++ 10 files changed, 62 insertions(+), 54 deletions(-) diff --git a/poincare/include/poincare/horizontal_layout_node.h b/poincare/include/poincare/horizontal_layout_node.h index 379d2821e..e3fa86481 100644 --- a/poincare/include/poincare/horizontal_layout_node.h +++ b/poincare/include/poincare/horizontal_layout_node.h @@ -66,32 +66,12 @@ class HorizontalLayoutRef : public LayoutReference { friend class HorizontalLayoutNode; public: HorizontalLayoutRef(HorizontalLayoutNode * n) : LayoutReference(n) {} - HorizontalLayoutRef() : LayoutReference(TreePool::sharedPool()->createTreeNode()) {} - - HorizontalLayoutRef(LayoutRef l) : HorizontalLayoutRef() { - addChildAtIndexInPlace(l, 0, 0); - } - - HorizontalLayoutRef(LayoutRef l1, LayoutRef l2) : HorizontalLayoutRef() { - addChildAtIndexInPlace(l1, 0, 0); - addChildAtIndexInPlace(l2, 1, 1); - } - HorizontalLayoutRef(LayoutRef l1, LayoutRef l2, LayoutRef l3) : HorizontalLayoutRef() { - addChildAtIndexInPlace(l1, 0, 0); - addChildAtIndexInPlace(l2, 1, 1); - addChildAtIndexInPlace(l3, 2, 2); - } - HorizontalLayoutRef(LayoutRef l1, LayoutRef l2, LayoutRef l3, LayoutRef l4) : HorizontalLayoutRef() { - addChildAtIndexInPlace(l1, 0, 0); - addChildAtIndexInPlace(l2, 1, 1); - addChildAtIndexInPlace(l3, 2, 2); - addChildAtIndexInPlace(l4, 3, 3); - } - HorizontalLayoutRef(const LayoutRef * children, size_t numberOfChildren) : HorizontalLayoutRef() { - for (size_t i = 0; i < numberOfChildren; i++) { - addChildAtIndexInPlace(children[i], i, i); - } - } + HorizontalLayoutRef(); + HorizontalLayoutRef(LayoutRef l); + HorizontalLayoutRef(LayoutRef l1, LayoutRef l2); + HorizontalLayoutRef(LayoutRef l1, LayoutRef l2, LayoutRef l3); + HorizontalLayoutRef(LayoutRef l1, LayoutRef l2, LayoutRef l3, LayoutRef l4); + HorizontalLayoutRef(const LayoutRef * children, size_t numberOfChildren); void addChildAtIndex(LayoutReference l, int index, int currentNumberOfChildren, LayoutCursor * cursor) override { LayoutReference::addChildAtIndex(l, index, currentNumberOfChildren, cursor); } diff --git a/poincare/include/poincare/nth_root_layout_node.h b/poincare/include/poincare/nth_root_layout_node.h index ddb547069..081fd945a 100644 --- a/poincare/include/poincare/nth_root_layout_node.h +++ b/poincare/include/poincare/nth_root_layout_node.h @@ -68,18 +68,10 @@ private: class NthRootLayoutRef : public LayoutReference { public: - NthRootLayoutRef(LayoutRef radicand) : NthRootLayoutRef() { - replaceChildAtIndexInPlace(0, radicand); - } - - NthRootLayoutRef(LayoutRef radicand, LayoutRef index) : NthRootLayoutRef() { - replaceChildAtIndexInPlace(0, radicand); - addChildAtIndexInPlace(index, 1, 1); - static_cast(node())->setNumberOfChildren(2); - } - + NthRootLayoutRef(LayoutRef radicand); + NthRootLayoutRef(LayoutRef radicand, LayoutRef index); private: - NthRootLayoutRef() : LayoutReference(TreePool::sharedPool()->createTreeNode()) {} + NthRootLayoutRef(); }; } diff --git a/poincare/include/poincare/right_parenthesis_layout_node.h b/poincare/include/poincare/right_parenthesis_layout_node.h index 65d8d57fa..cf3a52f70 100644 --- a/poincare/include/poincare/right_parenthesis_layout_node.h +++ b/poincare/include/poincare/right_parenthesis_layout_node.h @@ -36,7 +36,7 @@ protected: class RightParenthesisLayoutRef : public LayoutReference { public: - RightParenthesisLayoutRef() : LayoutReference(TreePool::sharedPool()->createTreeNode()) {} + RightParenthesisLayoutRef(); }; } diff --git a/poincare/include/poincare/right_square_bracket_layout_node.h b/poincare/include/poincare/right_square_bracket_layout_node.h index 1141da0b4..b45eb129a 100644 --- a/poincare/include/poincare/right_square_bracket_layout_node.h +++ b/poincare/include/poincare/right_square_bracket_layout_node.h @@ -29,9 +29,7 @@ protected: class RightSquareBracketLayoutRef : public LayoutReference { public: - RightSquareBracketLayoutRef() : LayoutReference(TreePool::sharedPool()->createTreeNode()) {} - - + RightSquareBracketLayoutRef(); }; } diff --git a/poincare/include/poincare/vertical_offset_layout_node.h b/poincare/include/poincare/vertical_offset_layout_node.h index d8a79e23b..a90ce92f7 100644 --- a/poincare/include/poincare/vertical_offset_layout_node.h +++ b/poincare/include/poincare/vertical_offset_layout_node.h @@ -59,12 +59,7 @@ private: class VerticalOffsetLayoutRef : public LayoutReference { public: - VerticalOffsetLayoutRef(LayoutRef l, VerticalOffsetLayoutNode::Type type) : - LayoutReference(TreePool::sharedPool()->createTreeNode()) - { - static_cast(node())->setType(type); - replaceChildAtIndexInPlace(0,l); - } + VerticalOffsetLayoutRef(LayoutRef l, VerticalOffsetLayoutNode::Type type); }; } diff --git a/poincare/src/horizontal_layout_node.cpp b/poincare/src/horizontal_layout_node.cpp index 12c2f607d..3b013b120 100644 --- a/poincare/src/horizontal_layout_node.cpp +++ b/poincare/src/horizontal_layout_node.cpp @@ -350,6 +350,33 @@ bool HorizontalLayoutNode::willReplaceChild(LayoutNode * oldChild, LayoutNode * // HorizontalLayoutRef +HorizontalLayoutRef::HorizontalLayoutRef() : LayoutReference(TreePool::sharedPool()->createTreeNode()) {} + +HorizontalLayoutRef::HorizontalLayoutRef(LayoutRef l) : HorizontalLayoutRef() { + addChildAtIndexInPlace(l, 0, 0); +} + +HorizontalLayoutRef::HorizontalLayoutRef(LayoutRef l1, LayoutRef l2) : HorizontalLayoutRef() { + addChildAtIndexInPlace(l1, 0, 0); + addChildAtIndexInPlace(l2, 1, 1); +} +HorizontalLayoutRef::HorizontalLayoutRef(LayoutRef l1, LayoutRef l2, LayoutRef l3) : HorizontalLayoutRef() { + addChildAtIndexInPlace(l1, 0, 0); + addChildAtIndexInPlace(l2, 1, 1); + addChildAtIndexInPlace(l3, 2, 2); +} +HorizontalLayoutRef::HorizontalLayoutRef(LayoutRef l1, LayoutRef l2, LayoutRef l3, LayoutRef l4) : HorizontalLayoutRef() { + addChildAtIndexInPlace(l1, 0, 0); + addChildAtIndexInPlace(l2, 1, 1); + addChildAtIndexInPlace(l3, 2, 2); + addChildAtIndexInPlace(l4, 3, 3); +} +HorizontalLayoutRef::HorizontalLayoutRef(const LayoutRef * children, size_t numberOfChildren) : HorizontalLayoutRef() { + for (size_t i = 0; i < numberOfChildren; i++) { + addChildAtIndexInPlace(children[i], i, i); + } +} + void HorizontalLayoutRef::addOrMergeChildAtIndex(LayoutRef l, int index, bool removeEmptyChildren, LayoutCursor * cursor) { if (l.isHorizontal()) { mergeChildrenAtIndex(HorizontalLayoutRef(static_cast(l.node())), index, removeEmptyChildren, cursor); diff --git a/poincare/src/nth_root_layout_node.cpp b/poincare/src/nth_root_layout_node.cpp index b87cbd059..b4b9aeed0 100644 --- a/poincare/src/nth_root_layout_node.cpp +++ b/poincare/src/nth_root_layout_node.cpp @@ -269,4 +269,16 @@ void NthRootLayoutNode::render(KDContext * ctx, KDPoint p, KDColor expressionCol } } +NthRootLayoutRef::NthRootLayoutRef(LayoutRef radicand) : NthRootLayoutRef() { + replaceChildAtIndexInPlace(0, radicand); +} + +NthRootLayoutRef::NthRootLayoutRef(LayoutRef radicand, LayoutRef index) : NthRootLayoutRef() { + replaceChildAtIndexInPlace(0, radicand); + addChildAtIndexInPlace(index, 1, 1); + static_cast(node())->setNumberOfChildren(2); +} + +NthRootLayoutRef::NthRootLayoutRef() : LayoutReference(TreePool::sharedPool()->createTreeNode()) {} + } diff --git a/poincare/src/right_parenthesis_layout_node.cpp b/poincare/src/right_parenthesis_layout_node.cpp index 70eb38bc4..c7b16a9cc 100644 --- a/poincare/src/right_parenthesis_layout_node.cpp +++ b/poincare/src/right_parenthesis_layout_node.cpp @@ -59,11 +59,6 @@ void RightParenthesisLayoutNode::render(KDContext * ctx, KDPoint p, KDColor expr RenderWithChildHeight(ParenthesisLayoutNode::ChildHeightGivenLayoutHeight(layoutSize().height()), ctx, p, expressionColor, backgroundColor); } +RightParenthesisLayoutRef::RightParenthesisLayoutRef() : LayoutReference(TreePool::sharedPool()->createTreeNode()) {} + } - - - - - - - diff --git a/poincare/src/right_square_bracket_layout_node.cpp b/poincare/src/right_square_bracket_layout_node.cpp index 2e97b598d..6470ce8b2 100644 --- a/poincare/src/right_square_bracket_layout_node.cpp +++ b/poincare/src/right_square_bracket_layout_node.cpp @@ -8,4 +8,6 @@ void RightSquareBracketLayoutNode::render(KDContext * ctx, KDPoint p, KDColor ex ctx->fillRect(KDRect(p.x()+k_widthMargin-k_bracketWidth+1, p.y() + childHeight(), k_bracketWidth, k_lineThickness), expressionColor); } +RightSquareBracketLayoutRef::RightSquareBracketLayoutRef() : LayoutReference(TreePool::sharedPool()->createTreeNode()) {} + } diff --git a/poincare/src/vertical_offset_layout_node.cpp b/poincare/src/vertical_offset_layout_node.cpp index 874230005..393009e10 100644 --- a/poincare/src/vertical_offset_layout_node.cpp +++ b/poincare/src/vertical_offset_layout_node.cpp @@ -271,4 +271,11 @@ LayoutNode * VerticalOffsetLayoutNode::baseLayout() { return parentNode->childAtIndex(idxInParent - 1); } +VerticalOffsetLayoutRef::VerticalOffsetLayoutRef(LayoutRef l, VerticalOffsetLayoutNode::Type type) : + LayoutReference(TreePool::sharedPool()->createTreeNode()) +{ + static_cast(node())->setType(type); + replaceChildAtIndexInPlace(0,l); +} + }