diff --git a/src/core/symbols/combined_symbol.cpp b/src/core/symbols/combined_symbol.cpp index 5141f8db8..5b9af26ff 100644 --- a/src/core/symbols/combined_symbol.cpp +++ b/src/core/symbols/combined_symbol.cpp @@ -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. * @@ -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 diff --git a/src/core/symbols/combined_symbol.h b/src/core/symbols/combined_symbol.h index fb61f441a..185cf0c40 100644 --- a/src/core/symbols/combined_symbol.h +++ b/src/core/symbols/combined_symbol.h @@ -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. * @@ -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; @@ -131,4 +133,4 @@ friend class PointSymbolEditorWidget; } // namespace OpenOrienteering -#endif +#endif // OPENORIENTEERING_COMBINED_SYMBOL_H diff --git a/src/core/symbols/line_symbol.h b/src/core/symbols/line_symbol.h index 40d77038c..f141e9b2f 100644 --- a/src/core/symbols/line_symbol.h +++ b/src/core/symbols/line_symbol.h @@ -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. * @@ -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; @@ -481,4 +483,4 @@ friend class PointSymbolEditorWidget; } // namespace OpenOrienteering -#endif +#endif // OPENORIENTEERING_LINE_SYMBOL_H diff --git a/src/core/symbols/symbol.cpp b/src/core/symbols/symbol.cpp index 8f8c2fec9..9d0d1b7b9 100644 --- a/src/core/symbols/symbol.cpp +++ b/src/core/symbols/symbol.cpp @@ -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. * @@ -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 diff --git a/src/core/symbols/symbol.h b/src/core/symbols/symbol.h index 07be8e868..d5a6a6a69 100644 --- a/src/core/symbols/symbol.h +++ b/src/core/symbols/symbol.h @@ -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. * @@ -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. @@ -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 diff --git a/src/tools/draw_path_tool.cpp b/src/tools/draw_path_tool.cpp index 82fdd9b3c..0a4b7cdaf 100644 --- a/src/tools/draw_path_tool.cpp +++ b/src/tools/draw_path_tool.cpp @@ -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. * @@ -30,8 +30,8 @@ #include #include #include -#include #include +#include #include #include #include @@ -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" @@ -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; } diff --git a/src/tools/edit_point_tool.cpp b/src/tools/edit_point_tool.cpp index 314339a64..f62b429b1 100644 --- a/src/tools/edit_point_tool.cpp +++ b/src/tools/edit_point_tool.cpp @@ -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. * @@ -21,9 +21,9 @@ #include "edit_point_tool.h" +#include #include #include -#include #include #include @@ -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" @@ -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) @@ -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); @@ -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