Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MeasureWidget: Warn about min size in combined symbols #2084

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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