From 7644d308081f8ee42a6da38543ad9173fc2344de Mon Sep 17 00:00:00 2001 From: MERLE Mathilde <“mathilde.merle@ihu-liryc.fr”> Date: Wed, 7 Dec 2022 12:26:48 +0100 Subject: [PATCH 1/2] [Tabs] handling of tabs: removal, switch --- .../gui/medTabbedViewContainers.cpp | 44 +++++++++++++++++-- .../gui/medTabbedViewContainers.h | 1 + 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/src/layers/legacy/medCoreLegacy/gui/medTabbedViewContainers.cpp b/src/layers/legacy/medCoreLegacy/gui/medTabbedViewContainers.cpp index 7c0a5fe184..3a943d4963 100644 --- a/src/layers/legacy/medCoreLegacy/gui/medTabbedViewContainers.cpp +++ b/src/layers/legacy/medCoreLegacy/gui/medTabbedViewContainers.cpp @@ -59,13 +59,12 @@ medTabbedViewContainers::medTabbedViewContainers(medAbstractWorkspaceLegacy* own d->closeShortcut = new QShortcut(this); d->closeShortcut->setKey(Qt::ControlModifier + Qt::Key_W); - // /////////////////////////////////////////////////////////////////////// - // Connect for creation and remove tab + // Connect for creation, removal and move of tabs connect(d->addTabButton, SIGNAL(clicked()), this, SLOT(addContainerInTabUnNamed())); connect(this, SIGNAL(tabCloseRequested(int)), this, SLOT(closeTab(int))); connect(d->closeShortcut, SIGNAL(activated()), this, SLOT(closeCurrentTab())); + connect(tabBar(), SIGNAL(tabMoved(int,int)), this, SLOT(movedTabs(int,int))); - // /////////////////////////////////////////////////////////////////////// // Connect group of view handling connect(medViewContainerManager::instance(), SIGNAL(containerAboutToBeDestroyed(QUuid)), this, SLOT(removeContainerFromSelection(QUuid))); connect(this, SIGNAL(containersSelectedChanged()), this, SLOT(buildTemporaryPool())); @@ -257,15 +256,36 @@ void medTabbedViewContainers::closeTab(int index) poMainSpliter->disconnect(this); } poTmp->deleteLater(); - + //Reset tab name if it follows the rule '###' is follows for (int i = 0; i < this->count(); ++i) + { if (this->tabText(i).isEmpty() || this->tabText(i).startsWith(d->owningWorkspace->name(), Qt::CaseSensitive)) + { this->setTabText(i, d->owningWorkspace->name() + " " + QString::number(i + 1)); + } + } // If medTabbedViewContainers is empty and empty is not allowed, we recreate one tab if (d->bKeepLeastOne && (this->count() < 1)) + { this->addContainerInTabUnNamed(); + } + + // Update the remaining tab indexes + d->containerSelectedForTabIndex.remove(index); + QHash > copyHash; + for(auto currentTabIndex : d->containerSelectedForTabIndex.keys()) + { + auto previousTab = d->containerSelectedForTabIndex.take(currentTabIndex); + copyHash.insert(copyHash.count(), previousTab); + } + d->containerSelectedForTabIndex.clear(); + d->containerSelectedForTabIndex = copyHash; + + // Update the current tab to the last one + setCurrentIndex(this->count()-1); + emit containersSelectedChanged(); } void medTabbedViewContainers::tabBarDoubleClickedHandler(int index) @@ -456,3 +476,19 @@ void medTabbedViewContainers::minimizeSplitterContainers(QUuid containerMaximize splitter->show(); } } + +/** + * @brief Launched when a tab from the tabs bar is moved to a new position + * + * @param from index tab before + * @param to index tab after + */ +void medTabbedViewContainers::movedTabs(int from, int to) +{ + auto previousFrom = d->containerSelectedForTabIndex.take(from); + auto previousTo = d->containerSelectedForTabIndex.take(to); + d->containerSelectedForTabIndex.insert(from, previousTo); + d->containerSelectedForTabIndex.insert(to, previousFrom); + + emit containersSelectedChanged(); +} \ No newline at end of file diff --git a/src/layers/legacy/medCoreLegacy/gui/medTabbedViewContainers.h b/src/layers/legacy/medCoreLegacy/gui/medTabbedViewContainers.h index a620a9e00a..36664ecd37 100644 --- a/src/layers/legacy/medCoreLegacy/gui/medTabbedViewContainers.h +++ b/src/layers/legacy/medCoreLegacy/gui/medTabbedViewContainers.h @@ -58,6 +58,7 @@ public slots: medViewContainer* insertNewTab(int index, const QString &name); void closeCurrentTab(); void closeTab(int index); + void movedTabs(int from, int to); private slots : void tabBarDoubleClickedHandler(int index); From 0adbb707b02d4d6850bd3b52e5a350f370ad59df Mon Sep 17 00:00:00 2001 From: MERLE Mathilde <“mathilde.merle@ihu-liryc.fr”> Date: Wed, 7 Dec 2022 12:50:30 +0100 Subject: [PATCH 2/2] [Tabs] manage the case of removing the last tab before opening new ones --- .../gui/medTabbedViewContainers.cpp | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/layers/legacy/medCoreLegacy/gui/medTabbedViewContainers.cpp b/src/layers/legacy/medCoreLegacy/gui/medTabbedViewContainers.cpp index 3a943d4963..37384d952f 100644 --- a/src/layers/legacy/medCoreLegacy/gui/medTabbedViewContainers.cpp +++ b/src/layers/legacy/medCoreLegacy/gui/medTabbedViewContainers.cpp @@ -271,21 +271,23 @@ void medTabbedViewContainers::closeTab(int index) { this->addContainerInTabUnNamed(); } - - // Update the remaining tab indexes - d->containerSelectedForTabIndex.remove(index); - QHash > copyHash; - for(auto currentTabIndex : d->containerSelectedForTabIndex.keys()) + else { - auto previousTab = d->containerSelectedForTabIndex.take(currentTabIndex); - copyHash.insert(copyHash.count(), previousTab); - } - d->containerSelectedForTabIndex.clear(); - d->containerSelectedForTabIndex = copyHash; + // Update the remaining tab indexes + d->containerSelectedForTabIndex.remove(index); + QHash > copyHash; + for(auto currentTabIndex : d->containerSelectedForTabIndex.keys()) + { + auto previousTab = d->containerSelectedForTabIndex.take(currentTabIndex); + copyHash.insert(copyHash.count(), previousTab); + } + d->containerSelectedForTabIndex.clear(); + d->containerSelectedForTabIndex = copyHash; - // Update the current tab to the last one - setCurrentIndex(this->count()-1); - emit containersSelectedChanged(); + // Update the current tab to the last one + setCurrentIndex(this->count()-1); + emit containersSelectedChanged(); + } } void medTabbedViewContainers::tabBarDoubleClickedHandler(int index)