Added support for tab index when inserting dockwidgets into area

This commit is contained in:
Uwe Kindler 2022-11-14 14:49:58 +01:00
parent 4600af712b
commit 296c7edbd0
5 changed files with 29 additions and 9 deletions

View File

@ -416,6 +416,10 @@ void CDockAreaWidget::addDockWidget(CDockWidget* DockWidget)
void CDockAreaWidget::insertDockWidget(int index, CDockWidget* DockWidget,
bool Activate)
{
if (index < 0 || index > d->ContentsLayout->count())
{
index = d->ContentsLayout->count();
}
d->ContentsLayout->insertWidget(index, DockWidget);
DockWidget->setDockArea(this);
DockWidget->tabWidget()->setDockAreaWidget(this);

View File

@ -153,7 +153,7 @@ public:
* Adds dock widget to a existing DockWidgetArea
*/
CDockAreaWidget* addDockWidgetToDockArea(DockWidgetArea area, CDockWidget* Dockwidget,
CDockAreaWidget* TargetDockArea);
CDockAreaWidget* TargetDockArea, int Index = -1);
/**
* Add dock area to this container
@ -1228,7 +1228,7 @@ void DockContainerWidgetPrivate::dumpRecursive(int level, QWidget* widget)
//============================================================================
CDockAreaWidget* DockContainerWidgetPrivate::addDockWidgetToDockArea(DockWidgetArea area,
CDockWidget* Dockwidget, CDockAreaWidget* TargetDockArea)
CDockWidget* Dockwidget, CDockAreaWidget* TargetDockArea, int Index)
{
if (CenterDockWidgetArea == area)
{
@ -1238,7 +1238,7 @@ CDockAreaWidget* DockContainerWidgetPrivate::addDockWidgetToDockArea(DockWidgetA
}
CDockAreaWidget* NewDockArea = new CDockAreaWidget(DockManager, _this);
NewDockArea->addDockWidget(Dockwidget);
NewDockArea->insertDockWidget(Index, Dockwidget);
auto InsertParam = internal::dockAreaInsertParameters(area);
QSplitter* TargetAreaSplitter = internal::findParent<QSplitter*>(TargetDockArea);
@ -1315,7 +1315,7 @@ CDockContainerWidget::~CDockContainerWidget()
//============================================================================
CDockAreaWidget* CDockContainerWidget::addDockWidget(DockWidgetArea area, CDockWidget* Dockwidget,
CDockAreaWidget* DockAreaWidget)
CDockAreaWidget* DockAreaWidget, int Index)
{
CDockAreaWidget* OldDockArea = Dockwidget->dockAreaWidget();
if (OldDockArea)
@ -1326,7 +1326,7 @@ CDockAreaWidget* CDockContainerWidget::addDockWidget(DockWidgetArea area, CDockW
Dockwidget->setDockManager(d->DockManager);
if (DockAreaWidget)
{
return d->addDockWidgetToDockArea(area, Dockwidget, DockAreaWidget);
return d->addDockWidgetToDockArea(area, Dockwidget, DockAreaWidget, Index);
}
else
{

View File

@ -181,7 +181,7 @@ public:
* \return Returns the dock area widget that contains the new DockWidget
*/
CDockAreaWidget* addDockWidget(DockWidgetArea area, CDockWidget* Dockwidget,
CDockAreaWidget* DockAreaWidget = nullptr);
CDockAreaWidget* DockAreaWidget = nullptr, int Index = -1);
/**
* Removes dockwidget

View File

@ -842,11 +842,11 @@ void CDockManager::restoreHiddenFloatingWidgets()
//============================================================================
CDockAreaWidget* CDockManager::addDockWidget(DockWidgetArea area,
CDockWidget* Dockwidget, CDockAreaWidget* DockAreaWidget)
CDockWidget* Dockwidget, CDockAreaWidget* DockAreaWidget, int Index)
{
d->DockWidgetsMap.insert(Dockwidget->objectName(), Dockwidget);
auto Container = DockAreaWidget ? DockAreaWidget->dockContainer(): this;
auto AreaOfAddedDockWidget = Container->addDockWidget(area, Dockwidget, DockAreaWidget);
auto AreaOfAddedDockWidget = Container->addDockWidget(area, Dockwidget, DockAreaWidget, Index);
Q_EMIT dockWidgetAdded(Dockwidget);
return AreaOfAddedDockWidget;
}
@ -886,6 +886,14 @@ CDockAreaWidget* CDockManager::addDockWidgetTabToArea(CDockWidget* Dockwidget,
}
//============================================================================
CDockAreaWidget* CDockManager::insertDockWidgetTabIntoArea(CDockWidget* Dockwidget,
CDockAreaWidget* DockAreaWidget, int Index)
{
return addDockWidget(ads::CenterDockWidgetArea, Dockwidget, DockAreaWidget, Index);
}
//============================================================================
CDockWidget* CDockManager::findDockWidget(const QString& ObjectName) const
{

View File

@ -281,7 +281,7 @@ public:
* \return Returns the dock area widget that contains the new DockWidget
*/
CDockAreaWidget* addDockWidget(DockWidgetArea area, CDockWidget* Dockwidget,
CDockAreaWidget* DockAreaWidget = nullptr);
CDockAreaWidget* DockAreaWidget = nullptr, int Index = -1);
/**
* Adds dockwidget into the given container.
@ -308,6 +308,14 @@ public:
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);
/**
* Adds the given DockWidget floating and returns the created
* CFloatingDockContainer instance.