From 296c7edbd092be76146946e5cf3f0e344e10678d Mon Sep 17 00:00:00 2001 From: Uwe Kindler Date: Mon, 14 Nov 2022 14:49:58 +0100 Subject: [PATCH 1/4] Added support for tab index when inserting dockwidgets into area --- src/DockAreaWidget.cpp | 4 ++++ src/DockContainerWidget.cpp | 10 +++++----- src/DockContainerWidget.h | 2 +- src/DockManager.cpp | 12 ++++++++++-- src/DockManager.h | 10 +++++++++- 5 files changed, 29 insertions(+), 9 deletions(-) diff --git a/src/DockAreaWidget.cpp b/src/DockAreaWidget.cpp index a8d4297..90d21e9 100644 --- a/src/DockAreaWidget.cpp +++ b/src/DockAreaWidget.cpp @@ -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); diff --git a/src/DockContainerWidget.cpp b/src/DockContainerWidget.cpp index 5451eb3..b96a416 100644 --- a/src/DockContainerWidget.cpp +++ b/src/DockContainerWidget.cpp @@ -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(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 { diff --git a/src/DockContainerWidget.h b/src/DockContainerWidget.h index a9ebea4..1420557 100644 --- a/src/DockContainerWidget.h +++ b/src/DockContainerWidget.h @@ -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 diff --git a/src/DockManager.cpp b/src/DockManager.cpp index 61210d0..2025682 100644 --- a/src/DockManager.cpp +++ b/src/DockManager.cpp @@ -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 { diff --git a/src/DockManager.h b/src/DockManager.h index 2072287..73e05cc 100644 --- a/src/DockManager.h +++ b/src/DockManager.h @@ -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. From d5ffd8f6a7518aa888ce0d48752e6917bb33c6aa Mon Sep 17 00:00:00 2001 From: Uwe Kindler Date: Mon, 14 Nov 2022 14:56:06 +0100 Subject: [PATCH 2/4] Removed debug output --- demo/MainWindow.cpp | 13 ++++++++++--- demo/demo.qrc | 1 + 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/demo/MainWindow.cpp b/demo/MainWindow.cpp index 6d8d0c9..f4d07cd 100644 --- a/demo/MainWindow.cpp +++ b/demo/MainWindow.cpp @@ -544,6 +544,14 @@ void MainWindowPrivate::createActions() _this->connect(a, SIGNAL(triggered()), SLOT(createEditor())); ui.menuTests->addAction(a); + a = ui.toolBar->addAction("Create Editor Tab"); + a->setProperty("Floating", false); + a->setToolTip("Creates a editor tab and inserts it as second tab into an area"); + a->setIcon(svgIcon(":/adsdemo/images/tab.svg")); + a->setProperty("Tabbed", true); + _this->connect(a, SIGNAL(triggered()), SLOT(createEditor())); + ui.menuTests->addAction(a); + a = ui.toolBar->addAction("Create Floating Table"); a->setToolTip("Creates floating dynamic dockable table with millions of entries"); a->setIcon(svgIcon(":/adsdemo/images/grid_on.svg")); @@ -769,6 +777,8 @@ void CMainWindow::createEditor() QObject* Sender = sender(); QVariant vFloating = Sender->property("Floating"); bool Floating = vFloating.isValid() ? vFloating.toBool() : true; + QVariant vTabbed = Sender->property("Tabbed"); + bool Tabbed = vTabbed.isValid() ? vTabbed.toBool() : true; auto DockWidget = d->createEditorWidget(); DockWidget->setFeature(ads::CDockWidget::DockWidgetDeleteOnClose, true); DockWidget->setFeature(ads::CDockWidget::DockWidgetForceCloseWithArea, true); @@ -786,16 +796,13 @@ void CMainWindow::createEditor() ads::CDockAreaWidget* EditorArea = d->LastDockedEditor ? d->LastDockedEditor->dockAreaWidget() : nullptr; if (EditorArea) { - std::cout << "DockAreaCount before: " << EditorArea->dockContainer()->dockAreaCount() << std::endl; d->DockManager->setConfigFlag(ads::CDockManager::EqualSplitOnInsertion, true); d->DockManager->addDockWidget(ads::RightDockWidgetArea, DockWidget, EditorArea); - std::cout << "DockAreaCount after: " << DockWidget->dockContainer()->dockAreaCount() << std::endl; } else { if (d->LastCreatedFloatingEditor) { - std::cout << "LastCreated" << std::endl; d->DockManager->addDockWidget(ads::RightDockWidgetArea, DockWidget, d->LastCreatedFloatingEditor->dockAreaWidget()); } else diff --git a/demo/demo.qrc b/demo/demo.qrc index cabf109..a097571 100644 --- a/demo/demo.qrc +++ b/demo/demo.qrc @@ -17,5 +17,6 @@ images/create_floating_editor.svg images/create_floating_table.svg images/docked_editor.svg + images/tab.svg From 3b8775fd86ef72f8ada0c2a8a85b23993eb0e393 Mon Sep 17 00:00:00 2001 From: Uwe Kindler Date: Mon, 14 Nov 2022 14:56:18 +0100 Subject: [PATCH 3/4] Added tab icon --- demo/images/tab.svg | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 demo/images/tab.svg diff --git a/demo/images/tab.svg b/demo/images/tab.svg new file mode 100644 index 0000000..df5fd7c --- /dev/null +++ b/demo/images/tab.svg @@ -0,0 +1,6 @@ + + tab icon - Licensed under Apache License v2.0 (http://www.apache.org/licenses/LICENSE-2.0) - Created with Iconfu.com - Derivative work of Material icons (Copyright Google Inc.) + + + + \ No newline at end of file From e4a71982d9c708d8cd42d52959bd9f845d5d461b Mon Sep 17 00:00:00 2001 From: Uwe Kindler Date: Mon, 14 Nov 2022 15:10:33 +0100 Subject: [PATCH 4/4] Added support for inserting a dock widget with a given tab index and added test case --- demo/MainWindow.cpp | 52 ++++++++++++++++++++++--------------- src/DockContainerWidget.cpp | 4 +-- src/DockManager.cpp | 10 +------ src/DockManager.h | 10 ++----- 4 files changed, 36 insertions(+), 40 deletions(-) diff --git a/demo/MainWindow.cpp b/demo/MainWindow.cpp index f4d07cd..dd8b7f3 100644 --- a/demo/MainWindow.cpp +++ b/demo/MainWindow.cpp @@ -790,28 +790,38 @@ void CMainWindow::createEditor() FloatingWidget->move(QPoint(20, 20)); d->LastCreatedFloatingEditor = DockWidget; d->LastDockedEditor.clear(); + return; } - else - { - ads::CDockAreaWidget* EditorArea = d->LastDockedEditor ? d->LastDockedEditor->dockAreaWidget() : nullptr; - if (EditorArea) - { - d->DockManager->setConfigFlag(ads::CDockManager::EqualSplitOnInsertion, true); - d->DockManager->addDockWidget(ads::RightDockWidgetArea, DockWidget, EditorArea); - } - else - { - if (d->LastCreatedFloatingEditor) - { - d->DockManager->addDockWidget(ads::RightDockWidgetArea, DockWidget, d->LastCreatedFloatingEditor->dockAreaWidget()); - } - else - { - d->DockManager->addDockWidget(ads::TopDockWidgetArea, DockWidget); - } - } - d->LastDockedEditor = DockWidget; - } + + + ads::CDockAreaWidget* EditorArea = d->LastDockedEditor ? d->LastDockedEditor->dockAreaWidget() : nullptr; + if (EditorArea) + { + if (Tabbed) + { + // Test inserting the dock widget tab at a given position instead + // of appending it. This function inserts the new dock widget as + // first tab + d->DockManager->addDockWidgetTabToArea(DockWidget, EditorArea, 0); + } + else + { + d->DockManager->setConfigFlag(ads::CDockManager::EqualSplitOnInsertion, true); + d->DockManager->addDockWidget(ads::RightDockWidgetArea, DockWidget, EditorArea); + } + } + else + { + if (d->LastCreatedFloatingEditor) + { + d->DockManager->addDockWidget(ads::RightDockWidgetArea, DockWidget, d->LastCreatedFloatingEditor->dockAreaWidget()); + } + else + { + d->DockManager->addDockWidget(ads::TopDockWidgetArea, DockWidget); + } + } + d->LastDockedEditor = DockWidget; } diff --git a/src/DockContainerWidget.cpp b/src/DockContainerWidget.cpp index b96a416..1d2539a 100644 --- a/src/DockContainerWidget.cpp +++ b/src/DockContainerWidget.cpp @@ -1232,13 +1232,13 @@ CDockAreaWidget* DockContainerWidgetPrivate::addDockWidgetToDockArea(DockWidgetA { if (CenterDockWidgetArea == area) { - TargetDockArea->addDockWidget(Dockwidget); + TargetDockArea->insertDockWidget(Index, Dockwidget); TargetDockArea->updateTitleBarVisibility(); return TargetDockArea; } CDockAreaWidget* NewDockArea = new CDockAreaWidget(DockManager, _this); - NewDockArea->insertDockWidget(Index, Dockwidget); + NewDockArea->addDockWidget(Dockwidget); auto InsertParam = internal::dockAreaInsertParameters(area); QSplitter* TargetAreaSplitter = internal::findParent(TargetDockArea); diff --git a/src/DockManager.cpp b/src/DockManager.cpp index 2025682..ea98221 100644 --- a/src/DockManager.cpp +++ b/src/DockManager.cpp @@ -880,15 +880,7 @@ CDockAreaWidget* CDockManager::addDockWidgetTab(DockWidgetArea area, //============================================================================ CDockAreaWidget* CDockManager::addDockWidgetTabToArea(CDockWidget* Dockwidget, - CDockAreaWidget* DockAreaWidget) -{ - return addDockWidget(ads::CenterDockWidgetArea, Dockwidget, DockAreaWidget); -} - - -//============================================================================ -CDockAreaWidget* CDockManager::insertDockWidgetTabIntoArea(CDockWidget* Dockwidget, - CDockAreaWidget* DockAreaWidget, int Index) + CDockAreaWidget* DockAreaWidget, int Index) { return addDockWidget(ads::CenterDockWidgetArea, Dockwidget, DockAreaWidget, Index); } diff --git a/src/DockManager.h b/src/DockManager.h index 73e05cc..258d45e 100644 --- a/src/DockManager.h +++ b/src/DockManager.h @@ -304,16 +304,10 @@ public: /** * This function will add the given Dockwidget to the given DockAreaWidget * 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* 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); /**