Skip to content

Commit

Permalink
Show parent layer names in "Move Object to Layer" menu
Browse files Browse the repository at this point in the history
Also reversed the order of the layers, to match the order in the Layers
view.

Closes mapeditor#3454
  • Loading branch information
bjorn committed Aug 23, 2023
1 parent 061e33e commit f294453
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/tiled/abstractobjecttool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "changepolygon.h"
#include "changetileobjectgroup.h"
#include "documentmanager.h"
#include "grouplayer.h"
#include "mapdocument.h"
#include "map.h"
#include "mapobject.h"
Expand Down Expand Up @@ -711,12 +712,29 @@ void AbstractObjectTool::showContextMenu(MapObject *clickedObject,
auto objectGroups = mapDocument()->map()->objectGroups();
auto objectGroupsIterator = objectGroups.begin();
if (objectGroupsIterator != objectGroups.end() && objectGroupsIterator.next()) {
QStringList parentLayerNames;

menu.addSeparator();
QMenu *moveToLayerMenu = menu.addMenu(tr("Move %n Object(s) to Layer",
"", selectedObjects.size()));
for (Layer *layer : objectGroups) {
ObjectGroup *objectGroup = static_cast<ObjectGroup*>(layer);
QAction *action = moveToLayerMenu->addAction(objectGroup->name());

objectGroupsIterator.toBack();
while (auto objectGroup = static_cast<ObjectGroup*>(objectGroupsIterator.previous())) {
// Create a menu action name based on parent layers. For example "Layer 1 (Parent1/Parent2)".
QString actionText = objectGroup->name();

if (auto parentLayer = objectGroup->parentLayer()) {
while (parentLayer) {
parentLayerNames.prepend(parentLayer->name());
parentLayer = parentLayer->parentLayer();
}

actionText = tr("%1 (%2)").arg(actionText,
parentLayerNames.join(QLatin1String("/")));
parentLayerNames.clear();
}

QAction *action = moveToLayerMenu->addAction(actionText);
action->setData(QVariant::fromValue(objectGroup));
action->setEnabled(objectGroup != sameObjectGroup);
}
Expand Down

0 comments on commit f294453

Please sign in to comment.