Skip to content

Commit

Permalink
Fixed hiding of object labels when deleting an object layer
Browse files Browse the repository at this point in the history
Also made sure the labels re-appear again when undoing the deletion.
  • Loading branch information
bjorn committed Feb 7, 2016
1 parent edaf663 commit 8818689
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
44 changes: 41 additions & 3 deletions src/tiled/objectselectionitem.cpp
@@ -1,6 +1,6 @@
/*
* objectselectionitem.cpp
* Copyright 2015, Thorbjørn Lindeijer <bjorn@lindeijer.nl>
* Copyright 2015-2016, Thorbjørn Lindeijer <bjorn@lindeijer.nl>
*
* This file is part of Tiled.
*
Expand Down Expand Up @@ -283,6 +283,12 @@ ObjectSelectionItem::ObjectSelectionItem(MapDocument *mapDocument)
connect(mapDocument, &MapDocument::mapChanged,
this, &ObjectSelectionItem::mapChanged);

connect(mapDocument, &MapDocument::layerAdded,
this, &ObjectSelectionItem::layerAdded);

connect(mapDocument, &MapDocument::layerAboutToBeRemoved,
this, &ObjectSelectionItem::layerAboutToBeRemoved);

connect(mapDocument, &MapDocument::layerChanged,
this, &ObjectSelectionItem::layerChanged);

Expand Down Expand Up @@ -313,6 +319,38 @@ void ObjectSelectionItem::mapChanged()
syncOverlayItems(mMapDocument->selectedObjects());
}

void ObjectSelectionItem::layerAdded(int index)
{
ObjectGroup *objectGroup = mMapDocument->map()->layerAt(index)->asObjectGroup();
if (!objectGroup)
return;

// The layer may already have objects, for example when the addition is the
// undo of a removal.
if (objectLabelVisibility() == Preferences::AllObjectLabels) {
MapRenderer *renderer = mMapDocument->renderer();

for (MapObject *object : *objectGroup) {
Q_ASSERT(!mObjectLabels.contains(object));

MapObjectLabel *labelItem = new MapObjectLabel(object, this);
labelItem->syncWithMapObject(renderer);
mObjectLabels.insert(object, labelItem);
}
}
}

void ObjectSelectionItem::layerAboutToBeRemoved(int index)
{
ObjectGroup *objectGroup = mMapDocument->map()->layerAt(index)->asObjectGroup();
if (!objectGroup)
return;

if (objectLabelVisibility() == Preferences::AllObjectLabels)
for (MapObject *object : *objectGroup)
delete mObjectLabels.take(object);
}

void ObjectSelectionItem::layerChanged(int index)
{
ObjectGroup *objectGroup = mMapDocument->map()->layerAt(index)->asObjectGroup();
Expand Down Expand Up @@ -344,9 +382,9 @@ void ObjectSelectionItem::syncOverlayItems(const QList<MapObject*> &objects)

void ObjectSelectionItem::objectsAdded(const QList<MapObject *> &objects)
{
MapRenderer *renderer = mMapDocument->renderer();

if (objectLabelVisibility() == Preferences::AllObjectLabels) {
MapRenderer *renderer = mMapDocument->renderer();

for (MapObject *object : objects) {
Q_ASSERT(!mObjectLabels.contains(object));

Expand Down
4 changes: 3 additions & 1 deletion src/tiled/objectselectionitem.h
@@ -1,6 +1,6 @@
/*
* objectselectionitem.h
* Copyright 2015, Thorbjørn Lindeijer <bjorn@lindeijer.nl>
* Copyright 2015-2016, Thorbjørn Lindeijer <bjorn@lindeijer.nl>
*
* This file is part of Tiled.
*
Expand Down Expand Up @@ -49,6 +49,8 @@ class ObjectSelectionItem : public QGraphicsObject
private slots:
void selectedObjectsChanged();
void mapChanged();
void layerAdded(int index);
void layerAboutToBeRemoved(int index);
void layerChanged(int index);
void syncOverlayItems(const QList<MapObject *> &objects);
void objectsAdded(const QList<MapObject*> &objects);
Expand Down

0 comments on commit 8818689

Please sign in to comment.