Add direct swap for tileset tile order#4524
Open
Cz1ang wants to merge 1 commit into
Open
Conversation
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.
There was a problem hiding this comment.
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
SwapTilesetTilesQUndoCommandand a low-levelTileset::swapTilesimplementation 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. |
|
|
||
| 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 on lines
+805
to
+809
| const bool exactlyTwoTilesSelected = | ||
| (selectionModel()->selectedIndexes().size() == 2); | ||
|
|
||
| QAction *swapTilesAction = menu.addAction(tr("&Swap Tiles")); | ||
| swapTilesAction->setEnabled(exactlyTwoTilesSelected); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SwapTilesetTilescommandFixes #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
git diff --checkTilesetViewtoTilesetEditor, undo command,TilesetDocument, andTilesetNot run locally: full Tiled build/runtime. This Windows environment has no
qbs,cmake,ninja,g++,clang++, orclavailable.