-
Notifications
You must be signed in to change notification settings - Fork 132
Expand file tree
/
Copy pathmap.h
More file actions
1953 lines (1580 loc) · 56.7 KB
/
map.h
File metadata and controls
1953 lines (1580 loc) · 56.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright 2012-2014 Thomas Schöps
* Copyright 2013-2020, 2024-2026 Kai Pastor
*
* This file is part of OpenOrienteering.
*
* OpenOrienteering is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenOrienteering is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenOrienteering. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef OPENORIENTEERING_MAP_H
#define OPENORIENTEERING_MAP_H
#include <algorithm>
#include <cstddef>
#include <functional>
#include <memory>
#include <set>
#include <vector>
#include <QtGlobal>
#include <QExplicitlySharedDataPointer>
#include <QFlags>
#include <QHash>
#include <QMetaType>
#include <QObject>
#include <QPointer>
#include <QRectF>
#include <QScopedPointer>
#include <QSharedData>
#include <QString>
#include <QTransform>
#include "core/map_coord.h"
#include "core/map_grid.h"
#include "core/map_part.h"
// IWYU pragma: no_include "templates/template.h"
class QIODevice;
class QPainter;
class QTranslator;
class QWidget;
// IWYU pragma: no_forward_declare QRectF
namespace OpenOrienteering {
class CombinedSymbol;
class Georeferencing;
class LineSymbol;
class MapColor;
class MapColorMap;
class MapPrinterConfig;
class MapRenderables;
class MapView;
class MapWidget;
class Object;
class PointSymbol;
class RenderConfig;
class Symbol;
class Template; // IWYU pragma: keep
class TextSymbol;
class UndoManager;
class UndoStep;
/**
* The translator for color and symbol texts.
*
* This translator is used by class Map but kept outside of the
* class' namespace in order to allow for forward declaration
* instead of including "map.h".
*/
extern QPointer<QTranslator> map_symbol_translator;
/** Central class for an OpenOrienteering map */
class Map : public QObject
{
Q_OBJECT
friend class MapTest;
friend class MapRenderables;
friend class XMLFileImporter;
friend class XMLFileExporter;
public:
/** A set of selected objects represented by a std::set of object pointers. */
typedef std::set<Object*> ObjectSelection;
/**
* Different strategies for importing elements from another map.
*/
enum ImportModeFlag
{
ObjectImport = 0x00, ///< Import objects, symbols and colors.
SymbolImport = 0x01, ///< Import symbols and colors.
ColorImport = 0x02, ///< Import colors.
GeorefImport = 0x10, ///< Use the georeferencing for object import.
MinimalImport = 0x20, ///< Imports with minimal symbol and color dependencies.
MinimalSymbolImport = SymbolImport | MinimalImport,
MinimalObjectImport = ObjectImport | MinimalImport,
CompleteImport = ObjectImport | GeorefImport
};
Q_DECLARE_FLAGS(ImportMode, ImportModeFlag)
/** Options for zooming to visibility of selection. */
enum SelectionVisibility
{
FullVisibility,
PartialVisibility,
IgnoreVisibilty
};
/** Default parameters for loading of image templates. */
struct ImageTemplateDefaults
{
bool use_meters_per_pixel = true;
double meters_per_pixel = 0.0;
double dpi = 0.0;
double scale = 0.0;
};
/** Creates a new, empty map. */
Map();
/** Destroys the map. */
~Map() override;
/**
* Deletes all map data.
*
* The resulting map must not be modified before another init().
*/
void clear();
/**
* Initializes an empty map.
*
* A map is empty when it is newly constructed or after clear().
*/
void init();
/**
* Deletes all map data, and reinitializes the empty map.
*
* This method combines a call to clear() followed by init().
*/
void reset();
/**
* Attempts to load the map from the specified path. Returns true on success.
*
* This is a convenience function used by tests. Normally, an importer should be
* used explicitly.
*
* @param path The file path to load the map from.
* @param view If not nullptr, restores this map view.
*/
bool loadFrom(const QString& path, MapView* view = nullptr);
/**
* Imports another map into this map.
*
* If the Map::GeorefImport mode flag is set, this overload will attempt to
* calculate a transformation based on the maps' georeferencing.
* All further processing is delegated to the other overload.
*
*/
QHash<const Symbol*, Symbol*> importMap(
const Map& imported_map,
ImportMode mode,
std::vector<bool>* filter = nullptr,
int symbol_insert_pos = -1,
bool merge_duplicate_symbols = true
);
/**
* Imports another map into this map.
*
* The amount of imported elements is controlled by the mode argument which
* is a combination of an enumeration of basic modes (ColorImport,
* SymbolImport, ObjectImport) and the flags (MinimalImport).
* - ObjectImport: Import objects, symbols and colors.
* If the MinimalImport flag is set, symbols and colors not used
* by the imported objects are ignored.
* The filter argument is not used.
* - SymbolImport: Import symbols and colors.
* If the MinimalImport flag is set, the filter argument may be used to
* select a subset of the symbols, and colors not used by the imported
* symbols are ignored.
* - ColorImport: Import colors.
* If the MinimalImport flag is set, the filter argument may be used to
* select a subset of the colors.
*
* This overload ignores the Map::GeorefImport mode flag. It only uses the
* given transformation. It is applied to all imported objects.
* No other adjustment of object positions and no scaling of symbol sizes
* (with respect to possible different map scales) is performed.
*/
QHash<const Symbol*, Symbol*> importMap(
const Map& imported_map,
ImportMode mode,
const QTransform& transform,
std::vector<bool>* filter = nullptr,
int symbol_insert_pos = -1,
bool merge_duplicate_symbols = true
);
/**
* Serializes the map directly to the given IO device, in a fixed format.
*
* This can be imported again using importFromIODevice().
* Returns true if successful.
*/
bool exportToIODevice(QIODevice& device) const;
/**
* Loads the map directly from the given IO device.
*
* The data must have been written by exportToIODevice() (or at least use
* the same format.)
* Returns true if successful.
*/
bool importFromIODevice(QIODevice& device);
/**
* Draws the part of the map which is visible in the bounding box.
*
* @param painter The QPainter used for drawing.
* @param config The rendering configuration
*/
void draw(QPainter* painter, const RenderConfig& config);
/**
* Draws a spot color overprinting simulation for the part of the map
* which is visible in the given bounding box.
*
* @param painter Must be a QPainter on a QImage of Format_ARGB32_Premultiplied.
* @param config The rendering configuration
*/
void drawOverprintingSimulation(QPainter* painter, const RenderConfig& config);
/**
* Draws the separation for a particular spot color for the part of the
* map which is visible in the given bounding box.
*
* Separations are normally drawn in levels of gray where black means
* full tone of the spot color. The parameter use_color can be used to
* draw in the actual spot color instead.
*
* @param painter The QPainter used for drawing.
* @param config The rendering configuration
* @param spot_color The spot color to draw the separation for.
* @param use_color If true, forces the separation to be drawn in its actual color.
*/
void drawColorSeparation(QPainter* painter, const RenderConfig& config,
const MapColor* spot_color, bool use_color = false);
/**
* Draws the map grid.
*
* @param painter The QPainter used for drawing.
* @param bounding_box Bounding box of area to draw, given in map coordinates.
*/
void drawGrid(QPainter* painter, const QRectF& bounding_box);
/**
* Draws the templates with indices first_template until last_template which
* are visible in the given bounding box.
*
* view determines template visibility and can be nullptr to show all templates.
* The initial transform of the given QPainter must be the map-to-paintdevice transformation.
* If on_screen is set to true, some optimizations will be applied, leading to a possibly lower display quality.
*
* @param painter The QPainter used for drawing.
* @param bounding_box Bounding box of area to draw, given in map coordinates.
* @param first_template Lowest index of the template range to draw.
* @param last_template Highest index of the template range to draw.
* @param view Optional pointer to MapView object which is used to query
* template visibilities.
* @param on_screen Potentially enables some drawing optimizations which
* decrease drawing quality. Should be enabled when drawing on-screen.
*/
void drawTemplates(QPainter* painter, const QRectF& bounding_box, int first_template,
int last_template, const MapView* view, bool on_screen) const;
/**
* Updates the renderables and extent of all objects which have changed.
* This is automatically called by draw(), you normally do not need to call it directly.
*/
void updateObjects();
/**
* Calculates the extent of all map elements.
*
* If templates shall be included, view may either be nullptr to include all
* templates, or specify a MapView to take the template visibilities from.
*/
QRectF calculateExtent(bool include_helper_symbols = false, bool include_templates = false, const MapView* view = nullptr) const;
/**
* Must be called to notify the map of new widgets displaying it.
* Useful to notify the widgets about which parts of the map have changed
* and need to be redrawn.
*/
void addMapWidget(MapWidget* widget);
/**
* Removes the map widget, see addMapWidget().
*/
void removeMapWidget(MapWidget* widget);
/**
* Redraws all map widgets completely - this can be slow!
* Try to avoid this and do partial redraws instead, if possible.
*/
void updateAllMapWidgets();
/**
* Makes sure that the selected object(s) are visible in all map widgets
* by moving the views in the widgets to the selected objects.
*/
void ensureVisibilityOfSelectedObjects(SelectionVisibility visibility);
// Current drawing
/**
* Sets the rect (given in map coordinates) as "dirty rect" for every
* map widget showing this map, enlarged by the given pixel border.
* This means that the area covered by the rect will be redrawn by
* the active tool. Use this if the current tool's display has changed.
*
* @param map_coords_rect Area covered by the current tool's drawing in map coords.
* @param pixel_border Border around the map coords rect which is also covered,
* given in pixels. Allows to enlarge the area given by the map coords
* by some pixels which are independent from the zoom level.
* For example if a tool displays markers with a radius of 3 pixels,
* it would set the bounding box of all markers as map_coords_rect and
* 3 for pixel_border.
* @param do_update Whether a repaint of the covered area should be triggered.
*/
void setDrawingBoundingBox(const QRectF& map_coords_rect, int pixel_border, bool do_update = true);
/**
* Removes the drawing bounding box and triggers a repaint. Use this if
* the current drawing is hidden or erased.
*/
void clearDrawingBoundingBox();
/**
* This is the analogon to setDrawingBoundingBox() for activities.
* See setDrawingBoundingBox().
*/
void setActivityBoundingBox(const QRectF& map_coords_rect, int pixel_border, bool do_update = true);
/**
* This is the analogon to clearDrawingBoundingBox() for activities.
* See clearDrawingBoundingBox().
*/
void clearActivityBoundingBox();
/**
* Updates all dynamic drawings at the given positions,
* i.e. tool & activity drawings.
*
* See setDrawingBoundingBox() and setActivityBoundingBox().
*/
void updateDrawing(const QRectF& map_coords_rect, int pixel_border);
// Element translations
/**
* Returns a translated symbol text (name or description), or the original text.
*/
QString translate(const QString& symbol_text) const;
/**
* Returns a translated symbol text (name or description), or an empty string.
*/
QString raw_translation(const QString& symbol_text) const;
// Colors
/** Returns the number of map colors defined in this map.*/
int getNumColors() const;
/** Returns a pointer to the MapColor identified by the non-negative priority i.
*
* Returns nullptr if the color is not defined, or if it is a special color (i.e i<0),
* i.e. only actual map colors are returned.
*/
const MapColor* getMapColor(int i) const;
/** Returns a pointer to the MapColor identified by the non-negative priority i.
*
* Returns nullptr if the color is not defined, or if it is a special color (i.e i<0),
* i.e. only actual map colors are returned.
*/
MapColor* getMapColor(int i);
/** Returns a pointer to the const MapColor identified by the priority i.
*
* Parameter i may also be negative for specifying special reserved colors.
* This is different from getMapColor();
*
* Returns nullptr if the color is not defined.
*/
const MapColor* getColor(int i) const;
/**
* Replaces the color at index pos with the given color, updates dependent
* colors and symbol icons.
*
* Emits colorChanged(). Does not delete the replaced color.
*/
void setColor(MapColor* color, int pos);
/**
* Adds the given color as a new color at the given index.
* Emits colorAdded().
*/
void addColor(MapColor* color, int pos);
/**
* Deletes the color at the given index.
* Emits colorDeleted().
*/
void deleteColor(int pos);
/**
* Loops through the color list, looking for the given color pointer.
* Returns the index of the color, or -1 if it is not found.
*/
int findColorIndex(const MapColor* color) const;
/**
* Marks the colors as "dirty", i.e. as having unsaved changes.
* Emits hasUnsavedChanged(true) if the map did not have unsaved changes before.
*/
void setColorsDirty();
/**
* Makes this map use the color set from the given map.
* Used to create the maps containing preview objects in the symbol editor.
*/
void useColorsFrom(Map* map);
/**
* Checks and returns if the given color is used by at least one symbol.
*/
bool isColorUsedByASymbol(const MapColor* color) const;
/**
* Checks which colors are in use by the symbols in this map.
*
* WARNING (FIXME): returns an empty list if the map does not contain symbols!
*
* @param by_which_symbols Must be of the same size as the symbol set.
* If set to false for a symbol, it will be disregarded.
* @param out Output parameter: a vector of the same size as the color list,
* where each element is set to true if the color is used by at least one symbol.
*/
void determineColorsInUse(const std::vector< bool >& by_which_symbols, std::vector< bool >& out) const;
/** Returns true if the map contains spot colors. */
bool hasSpotColors() const;
/**
* Returns true if any visible object uses a non-opaque color.
*/
bool hasAlpha() const;
/**
* Applies a const operation on all colors which match a particular condition.
*/
void applyOnMatchingColors(const std::function<void (const MapColor*)>& operation, const std::function<bool (const MapColor*)>& condition) const;
/**
* Applies a const operation on all colors.
*/
void applyOnAllColors(const std::function<void (const MapColor*)>& operation) const;
// Symbols
/** Returns the symbol set ID. */
QString symbolSetId() const;
/** Sets the symbol set ID. */
void setSymbolSetId(const QString& id);
/** Returns the number of symbols in this map. */
int getNumSymbols() const;
/** Returns a pointer to the i-th symbol.
*
* \sa findSymbolIndex()
*/
const Symbol* getSymbol(int i) const;
/** Returns a pointer to the i-th symbol. */
Symbol* getSymbol(int i);
/**
* Replaces the symbol at the given index with another symbol.
* Emits symbolChanged() and possibly selectedObjectEdited().
*/
void setSymbol(Symbol* symbol, int pos);
/**
* Adds the given symbol at the specified index.
* Emits symbolAdded().
*/
void addSymbol(Symbol* symbol, int pos);
/**
* Moves a symbol from one index to another in the symbol list.
*/
void moveSymbol(int from, int to);
/**
* Sorts the symbol list using the given comparator.
*/
template<typename T> void sortSymbols(T compare);
/**
* Deletes the symbol at the given index.
* Emits symbolDeleted().
*/
void deleteSymbol(int pos);
/**
* Loops over all symbols, looking for the given symbol pointer.
* Returns the index of the symbol, or -1 if the symbol is not found.
* For the "undefined" symbols, returns special indices smaller than -1.
*
* \sa getSymbol()
*/
int findSymbolIndex(const Symbol* symbol) const;
/**
* Marks the symbols as "dirty", i.e. as having unsaved changes.
* Emits hasUnsavedChanged(true) if the map did not have unsaved changes before.
*/
void setSymbolsDirty();
/**
* Updates the icons of all symbols with the given color.
*/
void updateSymbolIcons(const MapColor* color);
/**
* Scales all symbols by the given factor.
*/
void scaleAllSymbols(double factor);
/**
* Checks which symbols are in use in this map.
*
* Returns a vector of the same size as the symbol list, where each element
* is set to true if there is at least one object which uses this symbol or
* a derived (combined) symbol.
*/
void determineSymbolsInUse(std::vector<bool>& out) const;
/**
* Adds to the given symbol bitfield all other symbols which are needed to
* display the symbols indicated by the bitfield because of symbol dependencies.
*/
void determineSymbolUseClosure(std::vector< bool >& symbol_bitfield) const;
/**
* Applies a const operation on all symbols which match a particular condition.
*/
void applyOnMatchingSymbols(const std::function<void (const Symbol*)>& operation, const std::function<bool (const Symbol*)>& condition) const;
/**
* Applies a const operation on all symbols.
*/
void applyOnAllSymbols(const std::function<void (const Symbol*)>& operation) const;
/**
* Returns the scale factor to be used for default symbol icons.
*
* The full icon size (width, height) is represented by 1.0.
*/
qreal symbolIconZoom() const;
public slots:
/**
* Updates the symbol icon zoom from the current set of symbols.
*
* The symbol icon zoom is chosen so that most symbols fit into the full
* icon space, and the number of symbols below 10% size is kept low.
* For a map without symbols, this returns 1.0.
*/
void updateSymbolIconZoom();
public:
// Templates
/**
* Returns the number of templates in this map.
*/
int getNumTemplates() const { return int(templates.size()); }
/**
* Returns the i-th template.
*/
const Template* getTemplate(int pos) const { return templates[std::size_t(pos)].get(); }
/**
* Returns the i-th template.
*/
Template* getTemplate(int pos) { return templates[std::size_t(pos)].get(); }
/**
* Sets the template index which is the first (lowest) to be drawn in front of the map.
*/
void setFirstFrontTemplate(int pos);
/**
* Returns the template index which is the first (lowest) to be drawn in front of the map.
*/
int getFirstFrontTemplate() const { return first_front_template; }
/**
* Replaces the template at the given index with another.
*
* Emits templateChanged().
*/
std::unique_ptr<Template> setTemplate(int pos, std::unique_ptr<Template> temp);
/**
* Insert a new template at the given index.
*
* If the index is lower then the first front template index, the function
* increments this index. To place a template immediately below the map,
* pass index -1.
*/
void addTemplate(int pos, std::unique_ptr<Template> temp);
/**
* Moves a template to a new position.
*/
void moveTemplate(int old_pos, int new_pos);
/**
* Removes the template with the given index from the template list,
* and returns it.
*
* If the index is lower then the first front template index, the function
* decrements this index.
*/
std::unique_ptr<Template> removeTemplate(int pos);
/**
* Removes the template with the given index from the template list,
* and deletes it.
*
* If the index is lower then the first front template index, the function
* decrements this index.
*/
void deleteTemplate(int pos);
/**
* Marks the area defined by the given QRectF (in map coordinates) and
* pixel border as "dirty", i.e. as needing a repaint, for the given template
* in all map widgets.
*
* For an explanation of the area and pixel border, see setDrawingBoundingBox().
*
* Warning: does nothing if the template is not visible in a widget!
* So make sure to call this and showing/hiding a template in the correct order!
*/
void setTemplateAreaDirty(Template* temp, const QRectF& area, int pixel_border);
/**
* Marks the whole area of the i-th template as "to be repainted".
*
* Does nothing for pos == -1.
*
* @see setTemplateAreaDirty()
*/
void setTemplateAreaDirty(int pos);
/**
* Finds the index of the given template, or returns -1.
*/
int findTemplateIndex(const Template* temp) const;
/**
* Marks the template settings as "dirty", i.e. as having unsaved changes.
*
* Emits hasUnsavedChanged(true) if the map did not have unsaved changes before.
*/
void setTemplatesDirty();
/**
* Emits templateChanged() for the given template.
*/
void emitTemplateChanged(Template* temp);
/**
* Returns the number of closed templates for which the settings are still stored.
*/
int getNumClosedTemplates() const { return int(closed_templates.size()); }
/**
* Returns the i-th closed template.
*/
const Template* getClosedTemplate(int i) const { return closed_templates[std::size_t(i)].get(); }
/**
* Returns the i-th closed template.
*/
Template* getClosedTemplate(int i) { return closed_templates[std::size_t(i)].get(); }
/**
* Empties the list of closed templates.
*/
void clearClosedTemplates();
/**
* Removes the template with the given index from the normal template list,
* unloads the template file and adds the template to the closed template list.
*
* NOTE: if required, adjust first_front_template manually with setFirstFrontTemplate()!
*/
void closeTemplate(int pos);
/**
* Removes the template with the given index from the closed template list,
* adds it to the active list and loads the template file if possible.
*
* @param i The index of the closed template to reload.
* @param target_pos The desired index in the normal template list after loading.
* To place a template immediately below the map, pass index -1.
* @param dialog_parent Widget as parent for possible dialogs.
* @param map_path Path where the map is saved currently. Used as possible
* search location to locate missing templates.
*
* @return true if loading was successful.
*/
bool reloadClosedTemplate(int i, int target_pos, QWidget* dialog_parent, const QString& map_path = {});
/**
* Loads all "unloaded" templates which are marked visible in the given view.
*/
void loadTemplateFiles(const MapView& view);
/**
* Requests all visible "unloaded" templates to be loaded asynchronously.
*
* If the view is destroyed before template loading is finished, template
* loading will be stopped. (The map must not be destroyed before the view.)
*/
void loadTemplateFilesAsync(MapView& view, std::function<void(const QString&)> listener);
/**
* Returns if there is at least one non-georeferenced template (either open or closed)
*/
bool hasNonGeoreferencedTemplate() const;
// Undo & Redo
/**
* Returns the UndoManager instance for this map.
*/
UndoManager& undoManager();
/**
* Returns the UndoManager instance for this map.
*/
const UndoManager& undoManager() const;
/**
* Pushes a new undo step to the map's undoManager.
*/
void push(UndoStep* step);
// Map parts
/**
* Returns the number of map parts in this map.
*/
int getNumParts() const;
/**
* Returns the i-th map part.
*/
MapPart* getPart(std::size_t i) const;
/**
* Adds the new part at the given index.
*/
void addPart(MapPart* part, std::size_t index);
/**
* Removes the map part at position.
*/
void removePart(std::size_t index);
/**
* Loops over all map parts, looking for the given part pointer.
* Returns the part's index in the list. The part must be contained in the
* map, otherwise an assert will be triggered!
*/
int findPartIndex(const MapPart* part) const;
/**
* Returns the current map part, i.e. the part where edit operations happen.
*/
MapPart* getCurrentPart() const;
/**
* Changes the current map part.
*
* This is a convenience method which looks up the part's index and then
* calls setCurrentPartIndex.
*/
void setCurrentPart(MapPart* part);
/**
* Returns the index of the current map part.
*
* @see getCurrentPart().
*/
std::size_t getCurrentPartIndex() const;
/**
* Changes the current map part.
*/
void setCurrentPartIndex(std::size_t index);
/**
* Moves all specified objects from the source to the target map part.
*
* Objects are processed one by one. This means that processing one object
* changes the index of following objects. Thus the given indices must
* normally be in descending order.
*
* The objects will be continuously located at the end to the objects in the target part.
* Source object which were selected will be removed from the object selection.
*
* @return The index of the first object which has been reassigned.
*/
int reassignObjectsToMapPart(std::vector<int>::const_iterator first, std::vector<int>::const_iterator last, std::size_t source, std::size_t destination);
/**
* Merges the source part with the destination part.
*
* Removes the source part unless it is identical with the destination part.
*
* The objects will be continuously located at the end to the objects in the target part.
* Does not change the object selection.
*
* Makes the destination part the current part when the source part is the current part.
*
* @return The index of the first object which has been reassigned.
*/
int mergeParts(std::size_t source, std::size_t destination);
// Objects
/** Returns the total number of objects in this map (sum of all parts) */
int getNumObjects() const;
/**
* Adds the object as new object in the part with the given index,
* or in the current part if the default -1 is passed.
* Returns the index of the added object in the part.
*/
int addObject(Object* object, int part_index = -1);
/**
* Deletes the given object from the map.
*
* Be sure to call removeObjectFromSelection() if necessary.
*/
void deleteObject(Object* object);
/**
* Relinquish object ownership.
*
* Searches map parts and returns pointer if the object was found.
* Otherwise nullptr is returned.
*/
Object* releaseObject(Object* object);
/**
* Marks the objects as "dirty", i.e. as having unsaved changes.
* Emits hasUnsavedChanged(true) if the map did not have unsaved changes before.
*/
void setObjectsDirty();
/**
* Marks the area given by map_coords_rect as "dirty" in all map widgets,
* i.e. as needing to be redrawn because some object(s) changed there.
*/
void setObjectAreaDirty(const QRectF& map_coords_rect);
/**
* Finds and returns all objects at the given position in the current part.
*
* @param coord Coordinate where to query objects.
* @param tolerance Allowed distance from the query coordinate to the objects.
* @param treat_areas_as_paths If set to true, areas will be treated as paths,
* i.e. they will be returned only if the query coordinate is close to
* their border, not in all cases where the query coordinate is inside the area.
* @param extended_selection If set to true, more object than defined by the
* default behavior will be selected. For example, by default point objects
* will only be returned if the query coord is close to the point object
* coord. With extended_selection, they are also returned if the query
* coord is just inside the graphical extent of the point object.
* This can be used for a two-pass algorithm to find the most relevant
* objects first, and then query for all objects if no objects are found
* in the first pass.
* @param include_hidden_objects Set to true if you want to find hidden objects.
* @param include_protected_objects Set to true if you want to find protected objects.
* @param out Output parameter. Will be filled with pairs of symbol types
* and corresponding objects. The symbol type describes the way in which
* an object has been found and is taken from Symbol::Type. This is e.g.
* important for combined symbols, which can be found from a line or
* an area.
*/
void findObjectsAt(const MapCoordF& coord, qreal tolerance, bool treat_areas_as_paths,
bool extended_selection, bool include_hidden_objects,
bool include_protected_objects, SelectionInfoVector& out) const;
/**
* Finds and returns all objects at the given position in all parts.
*
* @see Map::findObjectsAt
*/
void findAllObjectsAt(const MapCoordF& coord, qreal tolerance, bool treat_areas_as_paths,
bool extended_selection, bool include_hidden_objects,
bool include_protected_objects, SelectionInfoVector& out) const;
/**
* Finds and returns all objects intersecting the given box in the current part.
*
* @param corner1 First corner of the query box.
* @param corner2 Second corner of the query box.
* @param include_hidden_objects Set to true if you want to find hidden objects.
* @param include_protected_objects Set to true if you want to find protected objects.
* @param out Output parameter. Will be filled with an object list.
*/
void findObjectsAtBox(const MapCoordF& corner1, const MapCoordF& corner2,
bool include_hidden_objects, bool include_protected_objects,
std::vector<Object*>& out) const;
/**
* Counts the objects whose bounding boxes intersect the given rect.
*
* This may be inaccurate because the true object shapes usually differ
* from the bounding boxes.
*
* @param map_coord_rect The query rect.
* @param include_hidden_objects Set to true if you want to find hidden objects.
*/
int countObjectsInRect(const QRectF& map_coord_rect, bool include_hidden_objects);
/**
* Applies a condition on all objects until the first match is found.
*
* @return True if there is an object matching the condition, false otherwise.