Skip to content

Commit 2a0335a

Browse files
dg0ytdl3sdo
authored andcommitted
MapPart: Use boolean member 'visible'
The concept of dimming is not compatible with the current concept of high-performance rendering.
1 parent c92d54e commit 2a0335a

File tree

4 files changed

+25
-31
lines changed

4 files changed

+25
-31
lines changed

src/core/map_part.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,9 @@ namespace literal
5454

5555
namespace OpenOrienteering {
5656

57-
MapPart::MapPart(const QString& name, Map* map, int visibility)
57+
MapPart::MapPart(const QString& name, Map* map)
5858
: name(name)
5959
, map(map)
60-
, visibility(visibility)
6160
{
6261
Q_ASSERT(map);
6362
; // nothing else
@@ -77,17 +76,17 @@ void MapPart::setName(const QString& new_name)
7776
emit map->mapPartChanged(map->findPartIndex(this), this);
7877
}
7978

80-
void MapPart::setVisibility(int new_visibility)
79+
void MapPart::setVisible(bool visible)
8180
{
82-
if (visibility == new_visibility)
81+
if (this->visible == visible)
8382
return;
8483

85-
visibility = new_visibility;
84+
this->visible = visible;
8685
if (map)
8786
{
8887
emit map->mapPartChanged(map->findPartIndex(this), this);
89-
applyOnAllObjects([new_visibility](Object* o) {
90-
o->setVisible(new_visibility);
88+
applyOnAllObjects([visible](Object* o) {
89+
o->setVisible(visible);
9190
});
9291
}
9392
}
@@ -96,7 +95,7 @@ void MapPart::save(QXmlStreamWriter& xml) const
9695
{
9796
XmlElementWriter part_element(xml, literal::part);
9897
part_element.writeAttribute(literal::name, name);
99-
part_element.writeAttribute(literal::visibility, visibility);
98+
part_element.writeAttribute(literal::visibility, visible);
10099
{
101100
XmlElementWriter objects_element(xml, literal::objects);
102101
objects_element.writeAttribute(literal::count, objects.size());
@@ -114,8 +113,9 @@ MapPart* MapPart::load(QXmlStreamReader& xml, Map& map, SymbolDictionary& symbol
114113
Q_ASSERT(xml.name() == literal::part);
115114

116115
XmlElementReader part_element(xml);
117-
int visibility = part_element.hasAttribute(literal::visibility) ? part_element.attribute<int>(literal::visibility) : 100;
118-
auto part = new MapPart(part_element.attribute<QString>(literal::name), &map, visibility);
116+
auto part = new MapPart(part_element.attribute<QString>(literal::name), &map);
117+
if (part_element.hasAttribute(literal::visibility))
118+
part->visible = part_element.attribute<bool>(literal::visibility);
119119

120120
while (xml.readNextStartElement())
121121
{
@@ -132,7 +132,7 @@ MapPart* MapPart::load(QXmlStreamReader& xml, Map& map, SymbolDictionary& symbol
132132
if (xml.name() == literal::object)
133133
{
134134
part->objects.push_back(Object::load(xml, &map, symbol_dict));
135-
part->objects.back()->setVisible(visibility);
135+
part->objects.back()->setVisible(part->visible);
136136
}
137137
else
138138
{
@@ -172,7 +172,7 @@ void MapPart::setObject(Object* object, int pos, bool delete_old)
172172
delete objects[pos];
173173

174174
objects[pos] = object;
175-
object->setVisible(visibility);
175+
object->setVisible(visible);
176176
object->setMap(map);
177177
object->update();
178178
map->setObjectsDirty(); // TODO: remove from here, dirty state handling should be separate
@@ -186,7 +186,7 @@ void MapPart::addObject(Object* object)
186186
void MapPart::addObject(Object* object, int pos)
187187
{
188188
objects.insert(objects.begin() + pos, object);
189-
object->setVisible(visibility);
189+
object->setVisible(visible);
190190
object->setMap(map);
191191
object->update();
192192

@@ -251,7 +251,7 @@ std::unique_ptr<UndoStep> MapPart::importPart(const MapPart* other, const QHash<
251251
new_object->transform(transform);
252252

253253
objects.push_back(new_object);
254-
new_object->setVisible(visibility);
254+
new_object->setVisible(visible);
255255
new_object->setMap(map);
256256
new_object->update();
257257

src/core/map_part.h

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class MapPart
6969
/**
7070
* Creates a new map part with the given name for a map.
7171
*/
72-
MapPart(const QString& name, Map* map, int visibility=100);
72+
MapPart(const QString& name, Map* map);
7373

7474
MapPart(const MapPart&) = delete;
7575

@@ -107,12 +107,12 @@ class MapPart
107107
/**
108108
* Returns the part's visibility.
109109
*/
110-
int getVisibility() const;
110+
bool isVisible() const { return visible; };
111111

112112
/**
113113
* Sets the part's visibility.
114114
*/
115-
void setVisibility(int new_visibility);
115+
void setVisible(bool visible);
116116

117117
/**
118118
* Returns the number of objects in the part.
@@ -276,7 +276,7 @@ class MapPart
276276
QString name;
277277
ObjectList objects; ///< @todo This could be a spatial representation optimized for quick access
278278
Map* const map;
279-
int visibility; // percentage as general approach, first use only values 0 and 100
279+
bool visible = true; ///< Visibility of the part's objects.
280280
};
281281

282282

@@ -289,12 +289,6 @@ const QString& MapPart::getName() const
289289
return name;
290290
}
291291

292-
inline
293-
int MapPart::getVisibility() const
294-
{
295-
return visibility;
296-
}
297-
298292
inline
299293
int MapPart::getNumObjects() const
300294
{

src/gui/map/map_editor.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,7 +1099,7 @@ void MapEditorController::createActions()
10991099
mappart_add_act = newAction("addmappart", tr("Add new part..."), this, SLOT(addMapPart()));
11001100
mappart_rename_act = newAction("renamemappart", tr("Rename current part..."), this, SLOT(renameMapPart()));
11011101
mappart_remove_act = newAction("removemappart", tr("Remove current part"), this, SLOT(removeMapPart()));
1102-
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
1102+
mappart_visibility_act = newAction("visibilitymappart", {/* set in updateMapPartsUI() */} , this, SLOT(toggleMapPartVisible()));
11031103
mappart_merge_act = newAction("mergemapparts", tr("Merge all parts"), this, SLOT(mergeAllMapParts()));
11041104

11051105
import_act = newAction("import", tr("Import..."), this, SLOT(importClicked()), nullptr, QString{}, "file_menu.html");
@@ -3808,7 +3808,7 @@ void MapEditorController::updateMapPartsUI()
38083808
if (mappart_visibility_act && count)
38093809
{
38103810
MapPart* const part = map->getCurrentPart();
3811-
mappart_visibility_act->setText(part->getVisibility() ? tr("Hide current part") : tr("Show current part"));
3811+
mappart_visibility_act->setText(part->isVisible() ? tr("Hide current part") : tr("Show current part"));
38123812
}
38133813

38143814
if (count > 0)
@@ -3849,7 +3849,7 @@ void MapEditorController::addMapPart()
38493849
&accepted );
38503850
if (accepted && !name.isEmpty())
38513851
{
3852-
auto* part = new MapPart(name, map, 100);
3852+
auto* part = new MapPart(name, map);
38533853
map->addPart(part, map->getCurrentPartIndex() + 1);
38543854
map->setCurrentPart(part);
38553855
map->push(new MapPartUndoStep(map, MapPartUndoStep::RemoveMapPart, part));
@@ -4010,10 +4010,10 @@ void MapEditorController::mergeAllMapParts()
40104010
}
40114011
}
40124012

4013-
void MapEditorController::switchVisibilityMapPart()
4013+
void MapEditorController::toggleMapPartVisible()
40144014
{
40154015
MapPart* const part = map->getCurrentPart();
4016-
part->setVisibility(part->getVisibility() ? 0 : 100);
4016+
part->setVisible(!part->isVisible());
40174017
}
40184018

40194019
void MapEditorController::templateAdded(int /*pos*/, const Template* /*temp*/)

src/gui/map/map_editor.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -520,8 +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();
523+
/** Toggles the visibility of the current map part */
524+
void toggleMapPartVisible();
525525

526526
/** Updates action enabled states after a template has been added */
527527
void templateAdded(int pos, const OpenOrienteering::Template* temp);

0 commit comments

Comments
 (0)