Added support for inserting a dock widget with a given tab index and added test case

This commit is contained in:
Uwe Kindler 2022-11-14 15:10:33 +01:00
parent 3b8775fd86
commit e4a71982d9
4 changed files with 36 additions and 40 deletions

View File

@ -790,28 +790,38 @@ void CMainWindow::createEditor()
FloatingWidget->move(QPoint(20, 20)); FloatingWidget->move(QPoint(20, 20));
d->LastCreatedFloatingEditor = DockWidget; d->LastCreatedFloatingEditor = DockWidget;
d->LastDockedEditor.clear(); d->LastDockedEditor.clear();
return;
} }
else
{
ads::CDockAreaWidget* EditorArea = d->LastDockedEditor ? d->LastDockedEditor->dockAreaWidget() : nullptr; ads::CDockAreaWidget* EditorArea = d->LastDockedEditor ? d->LastDockedEditor->dockAreaWidget() : nullptr;
if (EditorArea) if (EditorArea)
{ {
d->DockManager->setConfigFlag(ads::CDockManager::EqualSplitOnInsertion, true); if (Tabbed)
d->DockManager->addDockWidget(ads::RightDockWidgetArea, DockWidget, EditorArea); {
} // Test inserting the dock widget tab at a given position instead
else // of appending it. This function inserts the new dock widget as
{ // first tab
if (d->LastCreatedFloatingEditor) d->DockManager->addDockWidgetTabToArea(DockWidget, EditorArea, 0);
{ }
d->DockManager->addDockWidget(ads::RightDockWidgetArea, DockWidget, d->LastCreatedFloatingEditor->dockAreaWidget()); else
} {
else d->DockManager->setConfigFlag(ads::CDockManager::EqualSplitOnInsertion, true);
{ d->DockManager->addDockWidget(ads::RightDockWidgetArea, DockWidget, EditorArea);
d->DockManager->addDockWidget(ads::TopDockWidgetArea, DockWidget); }
} }
} else
d->LastDockedEditor = DockWidget; {
} if (d->LastCreatedFloatingEditor)
{
d->DockManager->addDockWidget(ads::RightDockWidgetArea, DockWidget, d->LastCreatedFloatingEditor->dockAreaWidget());
}
else
{
d->DockManager->addDockWidget(ads::TopDockWidgetArea, DockWidget);
}
}
d->LastDockedEditor = DockWidget;
} }

View File

@ -1232,13 +1232,13 @@ CDockAreaWidget* DockContainerWidgetPrivate::addDockWidgetToDockArea(DockWidgetA
{ {
if (CenterDockWidgetArea == area) if (CenterDockWidgetArea == area)
{ {
TargetDockArea->addDockWidget(Dockwidget); TargetDockArea->insertDockWidget(Index, Dockwidget);
TargetDockArea->updateTitleBarVisibility(); TargetDockArea->updateTitleBarVisibility();
return TargetDockArea; return TargetDockArea;
} }
CDockAreaWidget* NewDockArea = new CDockAreaWidget(DockManager, _this); CDockAreaWidget* NewDockArea = new CDockAreaWidget(DockManager, _this);
NewDockArea->insertDockWidget(Index, Dockwidget); NewDockArea->addDockWidget(Dockwidget);
auto InsertParam = internal::dockAreaInsertParameters(area); auto InsertParam = internal::dockAreaInsertParameters(area);
QSplitter* TargetAreaSplitter = internal::findParent<QSplitter*>(TargetDockArea); QSplitter* TargetAreaSplitter = internal::findParent<QSplitter*>(TargetDockArea);

View File

@ -880,15 +880,7 @@ CDockAreaWidget* CDockManager::addDockWidgetTab(DockWidgetArea area,
//============================================================================ //============================================================================
CDockAreaWidget* CDockManager::addDockWidgetTabToArea(CDockWidget* Dockwidget, CDockAreaWidget* CDockManager::addDockWidgetTabToArea(CDockWidget* Dockwidget,
CDockAreaWidget* DockAreaWidget) CDockAreaWidget* DockAreaWidget, int Index)
{
return addDockWidget(ads::CenterDockWidgetArea, Dockwidget, DockAreaWidget);
}
//============================================================================
CDockAreaWidget* CDockManager::insertDockWidgetTabIntoArea(CDockWidget* Dockwidget,
CDockAreaWidget* DockAreaWidget, int Index)
{ {
return addDockWidget(ads::CenterDockWidgetArea, Dockwidget, DockAreaWidget, Index); return addDockWidget(ads::CenterDockWidgetArea, Dockwidget, DockAreaWidget, Index);
} }

View File

@ -304,16 +304,10 @@ public:
/** /**
* This function will add the given Dockwidget to the given DockAreaWidget * This function will add the given Dockwidget to the given DockAreaWidget
* as a new tab. * as a new tab.
* If index is out of range, the tab is simply appended. Otherwise it is
* inserted at the specified position.
*/ */
CDockAreaWidget* addDockWidgetTabToArea(CDockWidget* Dockwidget, CDockAreaWidget* addDockWidgetTabToArea(CDockWidget* Dockwidget,
CDockAreaWidget* DockAreaWidget);
/**
* This function will inserts the given Dockwidget to the given DockAreaWidget
* as a new tab at the given index.
* If index is out of range, the tab is simply appended. Otherwise it is inserted at the specified position.
*/
CDockAreaWidget* insertDockWidgetTabIntoArea(CDockWidget* Dockwidget,
CDockAreaWidget* DockAreaWidget, int Index = -1); CDockAreaWidget* DockAreaWidget, int Index = -1);
/** /**