Skip to content

Add direct swap for tileset tile order#4524

Open
Cz1ang wants to merge 1 commit into
mapeditor:masterfrom
Cz1ang:codex/swap-tileset-order
Open

Add direct swap for tileset tile order#4524
Cz1ang wants to merge 1 commit into
mapeditor:masterfrom
Cz1ang:codex/swap-tileset-order

Conversation

@Cz1ang
Copy link
Copy Markdown

@Cz1ang Cz1ang commented May 19, 2026

Summary

  • add a direct tileset-order swap path for two selected tiles in the tileset editor
  • keep it undoable with a dedicated SwapTilesetTiles command
  • leave the existing map tile-reference swap behavior separate from tileset display-order rearranging

Fixes #3112.

Behavior

In the tileset editor, select exactly two tiles and use the context menu action Swap Tiles. Their display order is exchanged without changing tile IDs, map references, or the source tileset image.

Testing

Not run locally: full Tiled build/runtime. This Windows environment has no qbs, cmake, ninja, g++, clang++, or cl available.

Constraint: Issue mapeditor#3112 asks for swap and displacement to be separate rearrangement techniques without rewriting source images or tile IDs.

Rejected: Reusing RelocateTiles for swap semantics | relocating twice depends on shifting indexes and keeps the feature hidden behind displacement behavior.

Confidence: medium

Scope-risk: moderate

Directive: Keep map tile-reference swapping separate from tileset display-order swapping; they solve different workflows despite sharing menu text.

Tested: git diff --check; verified issue mapeditor#3112 is open and no related open PR exists; statically checked signal, command, document, and tileset method references.

Not-tested: Full Tiled build/runtime; this environment has no qbs, cmake, ninja, g++, clang++, or cl available.
Copilot AI review requested due to automatic review settings May 19, 2026 05:34
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds a "Swap Tiles" action to the tileset editor's context menu, allowing the user to swap the display order of exactly two selected tiles via an undoable command.

Changes:

  • Adds a SwapTilesetTiles QUndoCommand and a low-level Tileset::swapTiles implementation that swaps the two tiles in the tile list.
  • Adds a context menu entry in TilesetView (enabled only when two tiles are selected) that triggers the swap via the editor.
  • Wires the view/editor/document/library layers together to perform the swap and notify listeners via tilesetChanged.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/libtiled/tileset.h Declares new swapTiles method on Tileset.
src/libtiled/tileset.cpp Implements list-index swap of two tiles with asserts.
src/tiled/relocatetiles.h Declares the SwapTilesetTiles undo command.
src/tiled/relocatetiles.cpp Implements the undo command, dispatching to the document.
src/tiled/tilesetdocument.h Declares document-level swapTiles.
src/tiled/tilesetdocument.cpp Calls Tileset::swapTiles and emits tilesetChanged.
src/tiled/tileseteditor.h Declares editor slot swapTiles(Tile*, Tile*).
src/tiled/tileseteditor.cpp Connects view signal and pushes the undo command.
src/tiled/tilesetview.cpp Adds the "Swap Tiles" context menu action.

Comment thread src/libtiled/tileset.cpp

Q_ASSERT(indexA != -1);
Q_ASSERT(indexB != -1);

Comment on lines +370 to +374
void TilesetDocument::swapTiles(Tile *tileA, Tile *tileB)
{
mTileset->swapTiles(tileA, tileB);
emit tilesetChanged(mTileset.data());
}
Comment thread src/tiled/tilesetview.cpp
Comment on lines +805 to +809
const bool exactlyTwoTilesSelected =
(selectionModel()->selectedIndexes().size() == 2);

QAction *swapTilesAction = menu.addAction(tr("&Swap Tiles"));
swapTilesAction->setEnabled(exactlyTwoTilesSelected);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rearrange Tiles (Swap) + Rearrange Tiles (Displacement)

2 participants