Skip to content

Commit

Permalink
MeasureWidget: Consider minimum size in combined symbols
Browse files Browse the repository at this point in the history
Combined symbols may contain areas with a minimum size, either in
area symbols or private sub-symbols.

Closes OpenOrienteeringGH-2083.
  • Loading branch information
dl3sdo committed Dec 26, 2024
1 parent bc5ee49 commit 0879a21
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/core/symbols/area_symbol.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)];}
Expand Down
13 changes: 13 additions & 0 deletions src/core/symbols/combined_symbol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,4 +426,17 @@ bool CombinedSymbol::containsDashSymbol() const
}


// override
int CombinedSymbol::getMinimumArea() const
{
auto minimum_area = std::numeric_limits<int>::max();
for (auto const* part : parts)
{
if (part)
minimum_area = qMin(minimum_area, part->getMinimumArea());
}
return minimum_area;
}


} // namespace OpenOrienteering
2 changes: 2 additions & 0 deletions src/core/symbols/combined_symbol.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions src/core/symbols/symbol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <cmath>
#include <cstddef>
#include <iterator>
#include <limits>
#include <memory>

#include <QtGlobal>
Expand Down Expand Up @@ -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<int>::max();
}


} // namespace OpenOrienteering
5 changes: 5 additions & 0 deletions src/core/symbols/symbol.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
26 changes: 14 additions & 12 deletions src/gui/widgets/measure_widget.cpp
Original file line number Diff line number Diff line change
@@ -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.
*
Expand All @@ -21,16 +21,22 @@

#include "measure_widget.h"

#include <limits>

#include <QBuffer>
#include <QIcon>
#include <QIODevice>
#include <QLatin1String>
#include <QLocale>
#include <QPixmap>
#include <QScroller>
#include <QSize>
#include <QStyle>

#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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -127,13 +133,9 @@ void MeasureWidget::objectSelectionChanged()
paper_area_text, tr("mm²", "square millimeters"),
real_area_text , tr("", "square meters")));

auto minimum_area = 0.0;
auto minimum_area_text = QString{ };
if (symbol->getType() == Symbol::Area)
{
minimum_area = 0.001 * static_cast<const AreaSymbol*>(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<int>::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)
{
Expand Down

0 comments on commit 0879a21

Please sign in to comment.