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

Consider dash symbols in combined symbols #2154

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
11 changes: 10 additions & 1 deletion src/core/symbols/combined_symbol.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright 2012, 2013 Thomas Schöps
* Copyright 2012-2020 Kai Pastor
* Copyright 2012-2020, 2024 Kai Pastor
*
* This file is part of OpenOrienteering.
*
Expand Down Expand Up @@ -417,4 +417,13 @@ bool CombinedSymbol::hasRotatableFillPattern() const
}


// override
bool CombinedSymbol::containsDashSymbol() const
{
return std::any_of(begin(parts), end(parts), [](auto const* part) {
return part && part->containsDashSymbol();
});
}


} // namespace OpenOrienteering
6 changes: 4 additions & 2 deletions src/core/symbols/combined_symbol.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright 2012, 2013 Thomas Schöps
* Copyright 2012-2020 Kai Pastor
* Copyright 2012-2020, 2024 Kai Pastor
*
* This file is part of OpenOrienteering.
*
Expand Down Expand Up @@ -116,6 +116,8 @@ friend class PointSymbolEditorWidget;

SymbolPropertiesWidget* createPropertiesWidget(SymbolSettingDialog* dialog) override;

bool containsDashSymbol() 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 All @@ -131,4 +133,4 @@ friend class PointSymbolEditorWidget;

} // namespace OpenOrienteering

#endif
#endif // OPENORIENTEERING_COMBINED_SYMBOL_H
6 changes: 4 additions & 2 deletions src/core/symbols/line_symbol.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright 2012, 2013 Thomas Schöps
* Copyright 2012-2020 Kai Pastor
* Copyright 2012-2020, 2024 Kai Pastor
*
* This file is part of OpenOrienteering.
*
Expand Down Expand Up @@ -283,6 +283,8 @@ friend class PointSymbolEditorWidget;

SymbolPropertiesWidget* createPropertiesWidget(SymbolSettingDialog* dialog) override;

bool containsDashSymbol() const override { return dash_symbol != nullptr; }

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 Expand Up @@ -481,4 +483,4 @@ friend class PointSymbolEditorWidget;

} // namespace OpenOrienteering

#endif
#endif // OPENORIENTEERING_LINE_SYMBOL_H
9 changes: 8 additions & 1 deletion src/core/symbols/symbol.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright 2012, 2013 Thomas Schöps
* Copyright 2012-2020 Kai Pastor
* Copyright 2012-2020, 2022, 2024 Kai Pastor
*
* This file is part of OpenOrienteering.
*
Expand Down Expand Up @@ -982,4 +982,11 @@ bool Symbol::lessByColor::operator() (const Symbol* s1, const Symbol* s2) const
}


// virtual function, derived classes LineSymbol and CombinedSymbol override default behaviour below.
bool Symbol::containsDashSymbol() const
{
return false;
}


} // namespace OpenOrienteering
11 changes: 8 additions & 3 deletions src/core/symbols/symbol.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright 2012, 2013 Thomas Schöps
* Copyright 2012-2020 Kai Pastor
* Copyright 2012-2020, 2024 Kai Pastor
*
* This file is part of OpenOrienteering.
*
Expand Down Expand Up @@ -495,10 +495,15 @@ class Symbol
bool isRotatable() const { return is_rotatable; }

/**
* Returns if the objects has fill patterns which can be rotated in arbitrary directions.
* Returns if objects with this symbol have fill patterns which can be rotated in arbitrary directions.
*/
virtual bool hasRotatableFillPattern() const;

/**
* Returns if this symbol contains a dash symbol.
*/
virtual bool containsDashSymbol() const;

protected:
/**
* Sets the rotatability state of the symbol.
Expand Down Expand Up @@ -656,4 +661,4 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(OpenOrienteering::Symbol::TypeCombination)
Q_DECLARE_OPERATORS_FOR_FLAGS(OpenOrienteering::Symbol::RenderableOptions)


#endif
#endif // OPENORIENTEERING_SYMBOL_H
21 changes: 7 additions & 14 deletions src/tools/draw_path_tool.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright 2012-2014 Thomas Schöps
* Copyright 2013-2020 Kai Pastor
* Copyright 2013-2020, 2024 Kai Pastor
*
* This file is part of OpenOrienteering.
*
Expand Down Expand Up @@ -30,8 +30,8 @@
#include <QColor>
#include <QCursor>
#include <QFlags>
#include <QLatin1String>
#include <QKeyEvent>
#include <QLatin1String>
#include <QLineF>
#include <QLocale>
#include <QMouseEvent>
Expand All @@ -51,10 +51,9 @@
#include "core/path_coord.h"
#include "core/virtual_coord_vector.h"
#include "core/virtual_path.h"
#include "core/symbols/line_symbol.h"
#include "core/symbols/symbol.h"
#include "core/objects/object.h"
#include "core/renderables/renderable.h"
#include "core/symbols/symbol.h"
#include "gui/modifier_key.h"
#include "gui/map/map_editor.h"
#include "gui/map/map_widget.h"
Expand Down Expand Up @@ -1119,19 +1118,13 @@ void DrawPathTool::updateDashPointDrawing()
if (is_helper_tool)
return;

Symbol* symbol = editor->activeSymbol();
if (symbol && symbol->getType() == Symbol::Line)
// Auto-activate dash points depending on if the selected symbol has a dash symbol.
if (editor->activeSymbol()->containsDashSymbol())
{
// Auto-activate dash points depending on if the selected symbol has a dash symbol.
// TODO: instead of just looking if it is a line symbol with dash points,
// could also check for combined symbols containing lines with dash points
draw_dash_points = (symbol->asLine()->getDashSymbol());

draw_dash_points = true;
updateStatusText();
}
else if (symbol &&
(symbol->getType() == Symbol::Area ||
symbol->getType() == Symbol::Combined))
else
{
draw_dash_points = false;
}
Expand Down
17 changes: 5 additions & 12 deletions src/tools/edit_point_tool.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright 2012-2014 Thomas Schöps
* Copyright 2013-2017 Kai Pastor
* Copyright 2013-2020, 2024 Kai Pastor
*
* This file is part of OpenOrienteering.
*
Expand All @@ -21,9 +21,9 @@

#include "edit_point_tool.h"

#include <limits>
#include <map>
#include <memory>
#include <limits>
#include <vector>

#include <QtGlobal>
Expand All @@ -48,7 +48,6 @@
#include "core/objects/object.h"
#include "core/objects/object_mover.h"
#include "core/objects/text_object.h"
#include "core/symbols/line_symbol.h"
#include "core/symbols/symbol.h"
#include "gui/modifier_key.h"
#include "gui/map/map_editor.h"
Expand Down Expand Up @@ -98,11 +97,7 @@ EditPointTool::~EditPointTool()
bool EditPointTool::addDashPointDefault() const
{
// Toggle dash points depending on if the selected symbol has a dash symbol.
// TODO: instead of just looking if it is a line symbol with dash points,
// could also check for combined symbols containing lines with dash points
return ( hover_object &&
hover_object->getSymbol()->getType() == Symbol::Line &&
hover_object->getSymbol()->asLine()->getDashSymbol() != nullptr );
return (hover_object && hover_object->getSymbol()->containsDashSymbol());
}

bool EditPointTool::mousePressEvent(QMouseEvent* event, const MapCoordF& map_coord, MapWidget* widget)
Expand Down Expand Up @@ -185,7 +180,7 @@ void EditPointTool::clickPress()
startDragging();
hover_state = OverObjectNode;
hover_point = path->subdivide(closest.path_coord);
if (addDashPointDefault() ^ switch_dash_points)
if (addDashPointDefault() != switch_dash_points)
{
auto point = path->getCoordinate(hover_point);
point.setDashPoint(true);
Expand Down Expand Up @@ -485,9 +480,7 @@ bool EditPointTool::keyRelease(QKeyEvent* event)

case Qt::Key_Shift:
snap_helper->setFilter(SnappingToolHelper::NoSnapping);
if (hoveringOverCurveHandle())
reapplyConstraintHelpers();
else if (editingInProgress())
if (hoveringOverCurveHandle() || editingInProgress())
reapplyConstraintHelpers();
updateStatusText();
return false; // not consuming Shift
Expand Down
Loading