优化了bad smells

LayerStyleContainer::boundingBoxAffectedValue()
dev-LayerStyle
ArgonarioD 2023-03-19 01:20:32 +08:00
parent 1378997f64
commit 47ada04c3a
2 changed files with 15 additions and 10 deletions

View File

@ -194,18 +194,23 @@ bool LayerStyleContainer::dropStyle(const QString& styleName)
return true; return true;
} }
float LayerStyleContainer::boundingBoxAffectValue() { float LayerStyleContainer::boundingBoxAffectValue() const {
float maxLineWidth = 0; float maxLineWidth = 0;
auto strokeStyle = styles[StrokeElementLayerStyle::displayName()]; const auto strokeStyle = styles.at(StrokeElementLayerStyle::displayName());
if (strokeStyle != nullptr) { if (strokeStyle != nullptr)
auto strokeElementLayerStyle = dynamic_cast<StrokeElementLayerStyle*>(strokeStyle.get()); {
if (strokeElementLayerStyle != nullptr) { if (const auto strokeElementLayerStyle =
auto leftStyleStroke = strokeElementLayerStyle->strokePair.first; std::dynamic_pointer_cast<StrokeElementLayerStyle>(strokeStyle);
auto rightStyleStroke = strokeElementLayerStyle->strokePair.second; strokeElementLayerStyle != nullptr)
if (leftStyleStroke != nullptr) { {
const auto& leftStyleStroke = strokeElementLayerStyle->strokePair.first;
const auto& rightStyleStroke = strokeElementLayerStyle->strokePair.second;
if (leftStyleStroke != nullptr)
{
maxLineWidth = std::max(maxLineWidth, leftStyleStroke->halfWidth); maxLineWidth = std::max(maxLineWidth, leftStyleStroke->halfWidth);
} }
if (rightStyleStroke != nullptr) { if (rightStyleStroke != nullptr)
{
maxLineWidth = std::max(maxLineWidth, rightStyleStroke->halfWidth); maxLineWidth = std::max(maxLineWidth, rightStyleStroke->halfWidth);
} }
} }

View File

@ -65,7 +65,7 @@ public:
std::unique_ptr<LayerStyle> makeUnusedStyle(const QString& styleName) const; std::unique_ptr<LayerStyle> makeUnusedStyle(const QString& styleName) const;
bool useStyle(const std::shared_ptr<LayerStyle>& style); bool useStyle(const std::shared_ptr<LayerStyle>& style);
bool dropStyle(const QString& styleName); bool dropStyle(const QString& styleName);
float boundingBoxAffectValue(); float boundingBoxAffectValue() const;
size_t getHash() const; size_t getHash() const;
/** /**