Add CDockManager::removeDockWidget()

This commit is contained in:
Tibo Clausen 2019-05-15 13:47:58 +01:00
parent 27dd7a1b75
commit 641946bff5
5 changed files with 29 additions and 4 deletions

View File

@ -414,14 +414,15 @@ void CDockAreaWidget::removeDockWidget(CDockWidget* DockWidget)
auto TabWidget = DockWidget->tabWidget(); auto TabWidget = DockWidget->tabWidget();
TabWidget->hide(); TabWidget->hide();
d->tabBar()->removeTab(TabWidget); d->tabBar()->removeTab(TabWidget);
CDockContainerWidget* DockContainer = dockContainer();
if (NextOpenDockWidget) if (NextOpenDockWidget)
{ {
setCurrentDockWidget(NextOpenDockWidget); setCurrentDockWidget(NextOpenDockWidget);
} }
else if (d->ContentsLayout->isEmpty()) else if (d->ContentsLayout->isEmpty() && DockContainer->dockAreaCount() > 1)
{ {
qDebug() << "Dock Area empty"; qDebug() << "Dock Area empty";
dockContainer()->removeDockArea(this); DockContainer->removeDockArea(this);
this->deleteLater(); this->deleteLater();
} }
else else
@ -434,14 +435,13 @@ void CDockAreaWidget::removeDockWidget(CDockWidget* DockWidget)
d->updateCloseButtonState(); d->updateCloseButtonState();
updateTitleBarVisibility(); updateTitleBarVisibility();
auto TopLevelDockWidget = dockContainer()->topLevelDockWidget(); auto TopLevelDockWidget = DockContainer->topLevelDockWidget();
if (TopLevelDockWidget) if (TopLevelDockWidget)
{ {
TopLevelDockWidget->emitTopLevelChanged(true); TopLevelDockWidget->emitTopLevelChanged(true);
} }
#if (ADS_DEBUG_LEVEL > 0) #if (ADS_DEBUG_LEVEL > 0)
CDockContainerWidget* DockContainer = dockContainer();
DockContainer->dumpLayout(); DockContainer->dumpLayout();
#endif #endif
} }

View File

@ -998,6 +998,15 @@ CDockAreaWidget* CDockContainerWidget::addDockWidget(DockWidgetArea area, CDockW
} }
} }
//============================================================================
void CDockContainerWidget::removeDockWidget(CDockWidget* Dockwidget)
{
CDockAreaWidget* Area = Dockwidget->dockAreaWidget();
if (Area)
{
Area->removeDockWidget(Dockwidget);
}
}
//============================================================================ //============================================================================
unsigned int CDockContainerWidget::zOrderIndex() const unsigned int CDockContainerWidget::zOrderIndex() const

View File

@ -166,6 +166,11 @@ public:
CDockAreaWidget* addDockWidget(DockWidgetArea area, CDockWidget* Dockwidget, CDockAreaWidget* addDockWidget(DockWidgetArea area, CDockWidget* Dockwidget,
CDockAreaWidget* DockAreaWidget = nullptr); CDockAreaWidget* DockAreaWidget = nullptr);
/**
* Removes dockwidget
*/
void removeDockWidget(CDockWidget* Dockwidget);
/** /**
* Returns the current zOrderIndex * Returns the current zOrderIndex
*/ */

View File

@ -586,6 +586,12 @@ CDockWidget* CDockManager::findDockWidget(const QString& ObjectName) const
return d->DockWidgetsMap.value(ObjectName, nullptr); return d->DockWidgetsMap.value(ObjectName, nullptr);
} }
//============================================================================
void CDockManager::removeDockWidget(CDockWidget* Dockwidget)
{
d->DockWidgetsMap.remove(Dockwidget->objectName());
CDockContainerWidget::removeDockWidget(Dockwidget);
}
//============================================================================ //============================================================================
QMap<QString, CDockWidget*> CDockManager::dockWidgetsMap() const QMap<QString, CDockWidget*> CDockManager::dockWidgetsMap() const

View File

@ -192,6 +192,11 @@ public:
*/ */
CDockWidget* findDockWidget(const QString& ObjectName) const; CDockWidget* findDockWidget(const QString& ObjectName) const;
/**
* Remove the given Dock from the dock manager
*/
void removeDockWidget(CDockWidget* Dockwidget);
/** /**
* This function returns a readable reference to the internal dock * This function returns a readable reference to the internal dock
* widgets map so that it is possible to iterate over all dock widgets * widgets map so that it is possible to iterate over all dock widgets