Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Tabs] handling of tabs: removal, switch #1067

Merged
merged 2 commits into from
Jan 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 42 additions & 4 deletions src/layers/legacy/medCoreLegacy/gui/medTabbedViewContainers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down Expand Up @@ -257,15 +256,38 @@ void medTabbedViewContainers::closeTab(int index)
poMainSpliter->disconnect(this);
}
poTmp->deleteLater();

//Reset tab name if it follows the rule '<Workspace Name>###' 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();
}
else
{
// Update the remaining tab indexes
d->containerSelectedForTabIndex.remove(index);
QHash <int, QList<QUuid> > 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)
Expand Down Expand Up @@ -456,3 +478,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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down