From 47ada04c3aedf5831af1d463fc03ac79826f78cc Mon Sep 17 00:00:00 2001 From: ArgonarioD Date: Sun, 19 Mar 2023 01:20:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BA=86bad=20smells=20Layer?= =?UTF-8?q?StyleContainer::boundingBoxAffectedValue()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Editor/LayerStyle.cpp | 23 +++++++++++-------- .../src/Editor/LayerStyle.h | 2 +- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/ArchitectureColoredPainting/src/Editor/LayerStyle.cpp b/ArchitectureColoredPainting/src/Editor/LayerStyle.cpp index a6dc9d8..c57ea2f 100644 --- a/ArchitectureColoredPainting/src/Editor/LayerStyle.cpp +++ b/ArchitectureColoredPainting/src/Editor/LayerStyle.cpp @@ -194,18 +194,23 @@ bool LayerStyleContainer::dropStyle(const QString& styleName) return true; } -float LayerStyleContainer::boundingBoxAffectValue() { +float LayerStyleContainer::boundingBoxAffectValue() const { float maxLineWidth = 0; - auto strokeStyle = styles[StrokeElementLayerStyle::displayName()]; - if (strokeStyle != nullptr) { - auto strokeElementLayerStyle = dynamic_cast(strokeStyle.get()); - if (strokeElementLayerStyle != nullptr) { - auto leftStyleStroke = strokeElementLayerStyle->strokePair.first; - auto rightStyleStroke = strokeElementLayerStyle->strokePair.second; - if (leftStyleStroke != nullptr) { + const auto strokeStyle = styles.at(StrokeElementLayerStyle::displayName()); + if (strokeStyle != nullptr) + { + if (const auto strokeElementLayerStyle = + std::dynamic_pointer_cast(strokeStyle); + strokeElementLayerStyle != nullptr) + { + const auto& leftStyleStroke = strokeElementLayerStyle->strokePair.first; + const auto& rightStyleStroke = strokeElementLayerStyle->strokePair.second; + if (leftStyleStroke != nullptr) + { maxLineWidth = std::max(maxLineWidth, leftStyleStroke->halfWidth); } - if (rightStyleStroke != nullptr) { + if (rightStyleStroke != nullptr) + { maxLineWidth = std::max(maxLineWidth, rightStyleStroke->halfWidth); } } diff --git a/ArchitectureColoredPainting/src/Editor/LayerStyle.h b/ArchitectureColoredPainting/src/Editor/LayerStyle.h index 780b207..6db22d6 100644 --- a/ArchitectureColoredPainting/src/Editor/LayerStyle.h +++ b/ArchitectureColoredPainting/src/Editor/LayerStyle.h @@ -65,7 +65,7 @@ public: std::unique_ptr makeUnusedStyle(const QString& styleName) const; bool useStyle(const std::shared_ptr& style); bool dropStyle(const QString& styleName); - float boundingBoxAffectValue(); + float boundingBoxAffectValue() const; size_t getHash() const; /**