Skip to content

Commit

Permalink
MeasureWidget: Warn about min size in combined symbols
Browse files Browse the repository at this point in the history
Combined symbols may contain areas with a minimum size set, be it other
area symbols or private sub-symbols. This patch makes the measure tool
examine the embedded symbols for minimum size and warn if the object is
smaller than any of the minimum sizes.

Closes GH-2083.

Co-authored-by: Matthias Kühlewein <[email protected]>
  • Loading branch information
lpechacek and dl3sdo committed Sep 10, 2022
1 parent 0fda53d commit 2a551a4
Showing 1 changed file with 37 additions and 2 deletions.
39 changes: 37 additions & 2 deletions src/gui/widgets/measure_widget.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* Copyright 2012, 2013 Thomas Schöps
* Copyright 2012-2015 Kai Pastor
* Copyright 2022 Libor Pecháček
*
* This file is part of OpenOrienteering.
*
Expand All @@ -21,13 +22,16 @@

#include "measure_widget.h"

#include <queue>

#include <QLocale>
#include <QScroller>

#include "core/map.h"
#include "core/objects/object.h"
#include "core/symbols/symbol.h"
#include "core/symbols/area_symbol.h"
#include "core/symbols/combined_symbol.h"
#include "core/symbols/line_symbol.h"


Expand Down Expand Up @@ -115,15 +119,46 @@ void MeasureWidget::objectSelectionChanged()
paper_area_text, tr("mm²", "square millimeters"),
real_area_text , tr("", "square meters")));

auto minimum_area = 0.0;
auto minimum_area = std::numeric_limits<double>::infinity();
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);
}
else if (symbol->getType() == Symbol::Combined)
{
auto to_be_examined = std::queue<CombinedSymbol const*> {};
to_be_examined.push(symbol->asCombined());
do
{
auto const* symbol = to_be_examined.front();
to_be_examined.pop();
for (auto part_num = 0; part_num < symbol->getNumParts(); ++part_num)
{
auto const* part = symbol->getPart(part_num);

if (!part)
continue;

if (part->getType() == Symbol::Area)
{
auto symbol_min_area = 0.001 * part->asArea()->getMinimumArea();
if (symbol_min_area < minimum_area)
minimum_area = symbol_min_area;
}
else if (part->getType() == Symbol::Combined)
{
to_be_examined.push(part->asCombined());
}
}
}
while (!to_be_examined.empty());
minimum_area_text = locale().toString(minimum_area, 'f', 2);
}

if (paper_area < minimum_area && paper_area_text != minimum_area_text)
if (std::isfinite(minimum_area) && paper_area < minimum_area
&& paper_area_text != minimum_area_text)
{
extra_text = QLatin1String("<b>") + tr("This object is too small.") + QLatin1String("</b><br/>")
+ tr("The minimimum area is %1 %2.").arg(minimum_area_text, tr("mm²"))
Expand Down

0 comments on commit 2a551a4

Please sign in to comment.