diff --git a/src/core/symbols/area_symbol.h b/src/core/symbols/area_symbol.h index c066470b1..6e18f1f8e 100644 --- a/src/core/symbols/area_symbol.h +++ b/src/core/symbols/area_symbol.h @@ -277,7 +277,7 @@ friend class PointSymbolEditorWidget; // Getters / Setters inline const MapColor* getColor() const {return color;} inline void setColor(const MapColor* color) {this->color = color;} - inline int getMinimumArea() const {return minimum_area; } + inline int getMinimumArea() const override {return minimum_area; } inline int getNumFillPatterns() const {return int(patterns.size());} inline void setNumFillPatterns(int count) {patterns.resize(std::size_t(count));} inline FillPattern& getFillPattern(int i) {return patterns[std::size_t(i)];} diff --git a/src/core/symbols/combined_symbol.cpp b/src/core/symbols/combined_symbol.cpp index 5b9af26ff..0496a1895 100644 --- a/src/core/symbols/combined_symbol.cpp +++ b/src/core/symbols/combined_symbol.cpp @@ -426,4 +426,17 @@ bool CombinedSymbol::containsDashSymbol() const } +// override +int CombinedSymbol::getMinimumArea() const +{ + auto minimum_area = std::numeric_limits::max(); + for (auto const* part : parts) + { + if (part) + minimum_area = qMin(minimum_area, part->getMinimumArea()); + } + return minimum_area; +} + + } // namespace OpenOrienteering diff --git a/src/core/symbols/combined_symbol.h b/src/core/symbols/combined_symbol.h index a1d81b519..d1a13f3b2 100644 --- a/src/core/symbols/combined_symbol.h +++ b/src/core/symbols/combined_symbol.h @@ -118,6 +118,8 @@ friend class PointSymbolEditorWidget; bool containsDashSymbol() const override; + int getMinimumArea() const override; + protected: void saveImpl(QXmlStreamWriter& xml, const Map& map) const override; bool loadImpl(QXmlStreamReader& xml, const Map& map, SymbolDictionary& symbol_dict, int version) override; diff --git a/src/core/symbols/symbol.cpp b/src/core/symbols/symbol.cpp index 5cf924218..dbaca3e45 100644 --- a/src/core/symbols/symbol.cpp +++ b/src/core/symbols/symbol.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -994,4 +995,11 @@ bool Symbol::containsDashSymbol() const } +// virtual function, derived classes AreaSymbol and CombinedSymbol override default behaviour below. +int Symbol::getMinimumArea() const +{ + return std::numeric_limits::max(); +} + + } // namespace OpenOrienteering diff --git a/src/core/symbols/symbol.h b/src/core/symbols/symbol.h index 9ae09a405..cae4bbbe9 100644 --- a/src/core/symbols/symbol.h +++ b/src/core/symbols/symbol.h @@ -510,6 +510,11 @@ class Symbol */ virtual bool containsDashSymbol() const; + /** + * Returns the specified minimum area of this symbol otherwise the maximum int value. + */ + virtual int getMinimumArea() const; + protected: /** * Sets the rotatability state of the symbol. diff --git a/src/gui/widgets/measure_widget.cpp b/src/gui/widgets/measure_widget.cpp index e6dd0147f..31e840a7f 100644 --- a/src/gui/widgets/measure_widget.cpp +++ b/src/gui/widgets/measure_widget.cpp @@ -1,6 +1,6 @@ /* * Copyright 2012, 2013 Thomas Schöps - * Copyright 2012-2015, 2024 Kai Pastor + * Copyright 2012-2018, 2024 Kai Pastor * * This file is part of OpenOrienteering. * @@ -21,16 +21,22 @@ #include "measure_widget.h" +#include + #include +#include +#include +#include #include +#include #include +#include #include #include "core/map.h" #include "core/objects/object.h" -#include "core/symbols/symbol.h" -#include "core/symbols/area_symbol.h" #include "core/symbols/line_symbol.h" +#include "core/symbols/symbol.h" namespace OpenOrienteering { @@ -78,8 +84,8 @@ void MeasureWidget::objectSelectionChanged() } else { - const Object* object = *begin(selected_objects); - const Symbol* symbol = object->getSymbol(); + const auto* object = *begin(selected_objects); + const auto* symbol = object->getSymbol(); headline = symbol->getNumberAsString() + QLatin1Char(' ') + symbol->getName(); if (object->getType() != Object::Path) @@ -127,13 +133,9 @@ void MeasureWidget::objectSelectionChanged() paper_area_text, tr("mm²", "square millimeters"), real_area_text , tr("m²", "square meters"))); - auto minimum_area = 0.0; - auto minimum_area_text = QString{ }; - if (symbol->getType() == Symbol::Area) - { - minimum_area = 0.001 * static_cast(symbol)->getMinimumArea(); - minimum_area_text = locale().toString(minimum_area, 'f', 2); - } + auto minimum_area_int = symbol->getMinimumArea(); + auto minimum_area = 0.001 * (minimum_area_int == std::numeric_limits::max() ? 0 : minimum_area_int); + auto minimum_area_text = locale().toString(minimum_area, 'f', 2); if (paper_area < minimum_area && paper_area_text != minimum_area_text) {