Skip to content

Commit bad5717

Browse files
committed
Closes #1959
1 parent 818ec83 commit bad5717

File tree

10 files changed

+99
-21
lines changed

10 files changed

+99
-21
lines changed

src/core/map.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright 2012-2014 Thomas Schöps
3-
* Copyright 2013-2020 Kai Pastor
3+
* Copyright 2013-2021 Kai Pastor
44
*
55
* This file is part of OpenOrienteering.
66
*
@@ -475,7 +475,7 @@ void Map::init()
475475
{
476476
color_set = new MapColorSet();
477477

478-
parts.push_back(new MapPart(tr("default part"), this));
478+
parts.push_back(new MapPart(tr("default part"), this, 100));
479479

480480
widgets.clear();
481481

@@ -744,7 +744,7 @@ QHash<const Symbol*, Symbol*> Map::importMap(
744744
if (!dest_part)
745745
{
746746
// Import as new part
747-
dest_part = new MapPart(part_to_import->getName(), this);
747+
dest_part = new MapPart(part_to_import->getName(), this, part_to_import->getVisibility());
748748
addPart(dest_part, 0);
749749
undo_step->push(new MapPartUndoStep(this, MapPartUndoStep::RemoveMapPart, 0));
750750
}
@@ -2284,7 +2284,10 @@ void Map::applyOnMatchingObjects(const std::function<void (Object*, MapPart*, in
22842284
void Map::applyOnAllObjects(const std::function<void (Object*)>& operation)
22852285
{
22862286
for (auto part : parts)
2287+
{
2288+
setTransientVisibility(part->getVisibility());
22872289
part->applyOnAllObjects(operation);
2290+
}
22882291
}
22892292

22902293

@@ -2298,7 +2301,10 @@ void Map::applyOnAllObjects(const std::function<void (const Object*)>& operation
22982301
void Map::applyOnAllObjects(const std::function<void (Object*, MapPart*, int)>& operation)
22992302
{
23002303
for (auto part : parts)
2304+
{
2305+
setTransientVisibility(part->getVisibility());
23012306
part->applyOnAllObjects(operation);
2307+
}
23022308
}
23032309

23042310

src/core/map.h

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ friend class XMLFileExporter;
153153
*/
154154
void reset();
155155

156-
156+
157157
/**
158158
* Attempts to load the map from the specified path. Returns true on success.
159159
*
@@ -580,6 +580,11 @@ friend class XMLFileExporter;
580580
* The full icon size (width, height) is represented by 1.0.
581581
*/
582582
qreal symbolIconZoom() const;
583+
584+
/**
585+
* Returns the visibility of the map part being currently processed in applyOnAllObjects().
586+
*/
587+
int getTransientVisibility() const;
583588

584589
public slots:
585590
/**
@@ -1575,6 +1580,7 @@ protected slots:
15751580
void addSelectionRenderables(const Object* object);
15761581
void updateSelectionRenderables(const Object* object);
15771582
void removeSelectionRenderables(const Object* object);
1583+
void setTransientVisibility(int visibility);
15781584

15791585
static void initStatic();
15801586

@@ -1602,6 +1608,8 @@ protected slots:
16021608
MapGrid grid;
16031609

16041610
int renderable_options;
1611+
1612+
int transientVisibility; // temporarily store the visibility of the map part being processed by applyOnAllObjects()
16051613

16061614
QScopedPointer<MapPrinterConfig> printer_config;
16071615

@@ -1639,6 +1647,18 @@ protected slots:
16391647

16401648
// ### Map inline code ###
16411649

1650+
inline
1651+
void Map::setTransientVisibility(int visibility)
1652+
{
1653+
transientVisibility = visibility;
1654+
}
1655+
1656+
inline
1657+
int Map::getTransientVisibility() const
1658+
{
1659+
return transientVisibility;
1660+
}
1661+
16421662
inline
16431663
int Map::getNumColors() const
16441664
{

src/core/map_part.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright 2012, 2013 Thomas Schöps
3-
* Copyright 2012-2017 Kai Pastor
3+
* Copyright 2012-2021 Kai Pastor
44
*
55
* This file is part of OpenOrienteering.
66
*
@@ -47,15 +47,17 @@ namespace literal
4747
const QLatin1String objects("objects");
4848
const QLatin1String object("object");
4949
const QLatin1String count("count");
50+
const QLatin1String visibility("visibility");
5051
}
5152

5253

5354

5455
namespace OpenOrienteering {
5556

56-
MapPart::MapPart(const QString& name, Map* map)
57+
MapPart::MapPart(const QString& name, Map* map, int visibility)
5758
: name(name)
5859
, map(map)
60+
, visibility(visibility)
5961
{
6062
Q_ASSERT(map);
6163
; // nothing else
@@ -75,12 +77,21 @@ void MapPart::setName(const QString& new_name)
7577
emit map->mapPartChanged(map->findPartIndex(this), this);
7678
}
7779

78-
80+
void MapPart::setVisibility(int new_visibility)
81+
{
82+
visibility = new_visibility;
83+
if (map)
84+
{
85+
emit map->mapPartChanged(map->findPartIndex(this), this);
86+
map->updateAllObjects();
87+
}
88+
}
7989

8090
void MapPart::save(QXmlStreamWriter& xml) const
8191
{
8292
XmlElementWriter part_element(xml, literal::part);
8393
part_element.writeAttribute(literal::name, name);
94+
part_element.writeAttribute(literal::visibility, visibility);
8495
{
8596
XmlElementWriter objects_element(xml, literal::objects);
8697
objects_element.writeAttribute(literal::count, objects.size());
@@ -98,7 +109,8 @@ MapPart* MapPart::load(QXmlStreamReader& xml, Map& map, SymbolDictionary& symbol
98109
Q_ASSERT(xml.name() == literal::part);
99110

100111
XmlElementReader part_element(xml);
101-
auto part = new MapPart(part_element.attribute<QString>(literal::name), &map);
112+
int visibility = part_element.hasAttribute(literal::visibility) ? part_element.attribute<int>(literal::visibility) : 100;
113+
auto part = new MapPart(part_element.attribute<QString>(literal::name), &map, visibility);
102114

103115
while (xml.readNextStartElement())
104116
{

src/core/map_part.h

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright 2012, 2013 Thomas Schöps
3-
* Copyright 2012-2017 Kai Pastor
3+
* Copyright 2012-2021 Kai Pastor
44
*
55
* This file is part of OpenOrienteering.
66
*
@@ -62,16 +62,14 @@ using SelectionInfoVector = std::vector<std::pair<int, Object*>> ;
6262
* a map part for event-specific map objects and parts for course-specific
6363
* map objects. Then a course can be printed by merging the event-specific part
6464
* with the part for the course.
65-
*
66-
* Currently, only one map part can be used per map.
6765
*/
6866
class MapPart
6967
{
7068
public:
7169
/**
7270
* Creates a new map part with the given name for a map.
7371
*/
74-
MapPart(const QString& name, Map* map);
72+
MapPart(const QString& name, Map* map, int visibility);
7573

7674
MapPart(const MapPart&) = delete;
7775

@@ -106,6 +104,15 @@ class MapPart
106104
*/
107105
void setName(const QString& new_name);
108106

107+
/**
108+
* Returns the part's visibility.
109+
*/
110+
int getVisibility() const;
111+
112+
/**
113+
* Sets the part's visibility.
114+
*/
115+
void setVisibility(int new_visibility);
109116

110117
/**
111118
* Returns the number of objects in the part.
@@ -269,6 +276,7 @@ class MapPart
269276
QString name;
270277
ObjectList objects; ///< @todo This could be a spatial representation optimized for quick access
271278
Map* const map;
279+
int visibility; // percentage as general approach, first use only values 0 and 100
272280
};
273281

274282

@@ -281,6 +289,12 @@ const QString& MapPart::getName() const
281289
return name;
282290
}
283291

292+
inline
293+
int MapPart::getVisibility() const
294+
{
295+
return visibility;
296+
}
297+
284298
inline
285299
int MapPart::getNumObjects() const
286300
{

src/core/objects/object.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright 2012, 2013 Thomas Schöps
3-
* Copyright 2012-2020 Kai Pastor
3+
* Copyright 2012-2021 Kai Pastor
44
*
55
* This file is part of OpenOrienteering.
66
*
@@ -491,7 +491,9 @@ bool Object::update() const
491491
}
492492

493493
output.deleteRenderables();
494-
494+
if (map && !map->getTransientVisibility())
495+
return true;
496+
495497
extent = QRectF();
496498

497499
updateEvent();

src/gdal/ogr_file_format.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2020 Kai Pastor
2+
* Copyright 2016-2021 Kai Pastor
33
*
44
* This file is part of OpenOrienteering.
55
*
@@ -869,7 +869,7 @@ bool OgrFileImport::importImplementation()
869869
}
870870
else
871871
{
872-
part = new MapPart(QString::fromUtf8(OGR_L_GetName(layer)), map);
872+
part = new MapPart(QString::fromUtf8(OGR_L_GetName(layer)), map, 100);
873873
auto index = std::size_t(map->getNumParts());
874874
map->addPart(part, index);
875875
map->setCurrentPartIndex(index);

src/gui/map/map_editor.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ MapEditorController::MapEditorController(OperatingMode mode, Map* map, MapView*
257257
, template_list_widget(nullptr)
258258
, mappart_remove_act(nullptr)
259259
, mappart_merge_act(nullptr)
260+
, mappart_visibility_act(nullptr)
260261
, mappart_merge_menu(nullptr)
261262
, mappart_move_menu(nullptr)
262263
, mappart_selector_box(nullptr)
@@ -468,6 +469,7 @@ void MapEditorController::setEditingInProgress(bool value)
468469
mappart_add_act->setEnabled(!editing_in_progress);
469470
mappart_rename_act->setEnabled(!editing_in_progress && num_parts > 0);
470471
mappart_remove_act->setEnabled(!editing_in_progress && num_parts > 1);
472+
mappart_visibility_act->setEnabled(!editing_in_progress && num_parts > 0);
471473
mappart_move_menu->setEnabled(!editing_in_progress && num_parts > 1);
472474
mappart_merge_act->setEnabled(!editing_in_progress && num_parts > 1);
473475
mappart_merge_menu->setEnabled(!editing_in_progress && num_parts > 1);
@@ -1092,8 +1094,9 @@ void MapEditorController::createActions()
10921094
mappart_add_act = newAction("addmappart", tr("Add new part..."), this, SLOT(addMapPart()));
10931095
mappart_rename_act = newAction("renamemappart", tr("Rename current part..."), this, SLOT(renameMapPart()));
10941096
mappart_remove_act = newAction("removemappart", tr("Remove current part"), this, SLOT(removeMapPart()));
1097+
mappart_visibility_act = newAction("visibilitymappart", tr("Hide current part"), this, SLOT(switchVisibilityMapPart())); // exact text doesn't matter since replaced in updateMapPartsUI() below, so use something that is already in use
10951098
mappart_merge_act = newAction("mergemapparts", tr("Merge all parts"), this, SLOT(mergeAllMapParts()));
1096-
1099+
10971100
import_act = newAction("import", tr("Import..."), this, SLOT(importClicked()), nullptr, QString{}, "file_menu.html");
10981101

10991102
map_coordinates_act = new QAction(tr("Map coordinates"), this);
@@ -1251,6 +1254,7 @@ void MapEditorController::createMenuAndToolbars()
12511254
map_menu->addAction(mappart_add_act);
12521255
map_menu->addAction(mappart_rename_act);
12531256
map_menu->addAction(mappart_remove_act);
1257+
map_menu->addAction(mappart_visibility_act);
12541258
map_menu->addMenu(mappart_move_menu);
12551259
map_menu->addMenu(mappart_merge_menu);
12561260
map_menu->addAction(mappart_merge_act);
@@ -3796,6 +3800,11 @@ void MapEditorController::updateMapPartsUI()
37963800
{
37973801
toolbar_mapparts->setVisible(have_multiple_parts);
37983802
}
3803+
if (mappart_visibility_act && count)
3804+
{
3805+
MapPart* const part = map->getCurrentPart();
3806+
mappart_visibility_act->setText(part->getVisibility() ? tr("Hide current part") : tr("Show current part"));
3807+
}
37993808

38003809
if (count > 0)
38013810
{
@@ -3835,7 +3844,7 @@ void MapEditorController::addMapPart()
38353844
&accepted );
38363845
if (accepted && !name.isEmpty())
38373846
{
3838-
auto* part = new MapPart(name, map);
3847+
auto* part = new MapPart(name, map, 100);
38393848
map->addPart(part, map->getCurrentPartIndex() + 1);
38403849
map->setCurrentPart(part);
38413850
map->push(new MapPartUndoStep(map, MapPartUndoStep::RemoveMapPart, part));
@@ -3996,6 +4005,11 @@ void MapEditorController::mergeAllMapParts()
39964005
}
39974006
}
39984007

4008+
void MapEditorController::switchVisibilityMapPart()
4009+
{
4010+
MapPart* const part = map->getCurrentPart();
4011+
part->setVisibility(part->getVisibility() ? 0 : 100);
4012+
}
39994013

40004014
void MapEditorController::templateAdded(int /*pos*/, const Template* /*temp*/)
40014015
{

src/gui/map/map_editor.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,8 @@ public slots:
520520
void mergeCurrentMapPartTo(int target);
521521
/** Merges all map parts into the current one. */
522522
void mergeAllMapParts();
523+
/** Switches the visibility of the current map part */
524+
void switchVisibilityMapPart();
523525

524526
/** Updates action enabled states after a template has been added */
525527
void templateAdded(int pos, const OpenOrienteering::Template* temp);
@@ -822,6 +824,7 @@ protected slots:
822824
QAction* mappart_rename_act = {};
823825
QAction* mappart_remove_act = {};
824826
QAction* mappart_merge_act = {};
827+
QAction* mappart_visibility_act = {};
825828
QMenu* mappart_merge_menu;
826829
QMenu* mappart_move_menu;
827830

0 commit comments

Comments
 (0)