Skip to content

Add drag-and-drop reordering of layout view tabs#2395

Open
nharjee wants to merge 1 commit into
KLayout:masterfrom
nharjee:feature/tab-drag-reorder
Open

Add drag-and-drop reordering of layout view tabs#2395
nharjee wants to merge 1 commit into
KLayout:masterfrom
nharjee:feature/tab-drag-reorder

Conversation

@nharjee

@nharjee nharjee commented Jul 18, 2026

Copy link
Copy Markdown

Summary

Enables drag-and-drop reordering of the layout view tabs in the main window. Previously the tabs could not be rearranged; this makes the tab bar movable and keeps the underlying view model in sync when tabs are dragged.

Details

The tab index is used as a positional key into mp_views and the seven parallel widget stacks (view / layer-control / layer-toolbox / hierarchy / libraries / editor-options / bookmarks), so reordering the QTabBar alone would desync them.

  • MainWindow: enable QTabBar::setMovable(true) and connect QTabBar::tabMoved(int,int) to a new MainWindow::tab_moved(from, to) slot that reorders mp_views and every widget stack to match the new tab order, then re-raises the current widgets.
    • Qt emits tabMoved before currentChanged, so any subsequent view selection operates on the already-reordered stacks.
    • The current view is tracked by object (LayoutView::current()), so it is never lost across a reorder — only its index changes.
  • ViewWidgetStack and ControlWidgetStack: add a move_widget(from, to) helper that reorders the internal widget vector.

Net change is additive: 6 files, +64 lines.

Testing

  • Built on macOS (Qt 6, build4mac.py).
  • Full unit-test suite (ut_runner via macQAT.py) run before and after: the same pre-existing set of failures (unrelated rba/lvs/drc/tl reference-data and environment-specific tests) appears with and without this change; no new failures are introduced.
  • Manually verified: drag to reorder, then switch / clone / close tabs — the tab↔view mapping stays consistent.

Known cosmetic note

On macOS, while a tab is actively being dragged, Qt's built-in movable-tab drag rendering tints the tabs flanking the lifted tab blue (the platform style's dragInProgress paint path, using a grabbed-pixmap overlay for the moving tab). This is Qt-native behavior triggered simply by enabling setMovable(true) — it occurs before any reorder logic runs, is purely visual, and reverts on drop. Left as-is.

Enable QTabBar movable tabs on the main window's layout-view tab bar and
keep the backing data model in sync when tabs are dragged.

The tab index is used as a positional key into mp_views and the seven
parallel widget stacks, so a reorder in the tab bar alone would desync
them. A new MainWindow::tab_moved(from, to) slot, connected to
QTabBar::tabMoved, reorders mp_views and every stack to match the new
tab order and re-raises the current widgets. Since Qt emits tabMoved
before currentChanged, the subsequent view selection operates on the
already-reordered stacks; the current view is tracked by object
(LayoutView::current), so it is never lost across a reorder.

Adds a move_widget(from, to) helper to both ViewWidgetStack and
ControlWidgetStack to reorder their internal widget vectors.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@klayoutmatthias

klayoutmatthias commented Jul 19, 2026

Copy link
Copy Markdown
Collaborator

The PR looks okay, but let me tell you that I am absolute not in favor of AI-authored PRs. I am basically inclined to reject them unconditionally, because I don't consider them trustworthy and I don't want to accept PRs that take me more time to review than it took to create them.

I think there is more to consider with respect to tab reordering. I will take a look, but with low priority.

Matthias

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.

2 participants