Skip to content

Commit 3fded82

Browse files
Merge branch 'master' into auto_hide_feature
2 parents 07d0bdc + e4a7198 commit 3fded82

File tree

8 files changed

+66
-33
lines changed

8 files changed

+66
-33
lines changed

demo/MainWindow.cpp

Lines changed: 41 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,14 @@ void MainWindowPrivate::createActions()
578578
_this->connect(a, SIGNAL(triggered()), SLOT(createEditor()));
579579
ui.menuTests->addAction(a);
580580

581+
a = ui.toolBar->addAction("Create Editor Tab");
582+
a->setProperty("Floating", false);
583+
a->setToolTip("Creates a editor tab and inserts it as second tab into an area");
584+
a->setIcon(svgIcon(":/adsdemo/images/tab.svg"));
585+
a->setProperty("Tabbed", true);
586+
_this->connect(a, SIGNAL(triggered()), SLOT(createEditor()));
587+
ui.menuTests->addAction(a);
588+
581589
a = ui.toolBar->addAction("Create Floating Table");
582590
a->setToolTip("Creates floating dynamic dockable table with millions of entries");
583591
a->setIcon(svgIcon(":/adsdemo/images/grid_on.svg"));
@@ -829,6 +837,8 @@ void CMainWindow::createEditor()
829837
QObject* Sender = sender();
830838
QVariant vFloating = Sender->property("Floating");
831839
bool Floating = vFloating.isValid() ? vFloating.toBool() : true;
840+
QVariant vTabbed = Sender->property("Tabbed");
841+
bool Tabbed = vTabbed.isValid() ? vTabbed.toBool() : true;
832842
auto DockWidget = d->createEditorWidget();
833843
DockWidget->setFeature(ads::CDockWidget::DockWidgetDeleteOnClose, true);
834844
DockWidget->setFeature(ads::CDockWidget::DockWidgetForceCloseWithArea, true);
@@ -840,28 +850,38 @@ void CMainWindow::createEditor()
840850
FloatingWidget->move(QPoint(20, 20));
841851
d->LastCreatedFloatingEditor = DockWidget;
842852
d->LastDockedEditor.clear();
853+
return;
843854
}
844-
else
845-
{
846-
ads::CDockAreaWidget* EditorArea = d->LastDockedEditor ? d->LastDockedEditor->dockAreaWidget() : nullptr;
847-
if (EditorArea)
848-
{
849-
d->DockManager->setConfigFlag(ads::CDockManager::EqualSplitOnInsertion, true);
850-
d->DockManager->addDockWidget(ads::RightDockWidgetArea, DockWidget, EditorArea);
851-
}
852-
else
853-
{
854-
if (d->LastCreatedFloatingEditor)
855-
{
856-
d->DockManager->addDockWidget(ads::RightDockWidgetArea, DockWidget, d->LastCreatedFloatingEditor->dockAreaWidget());
857-
}
858-
else
859-
{
860-
d->DockManager->addDockWidget(ads::TopDockWidgetArea, DockWidget);
861-
}
862-
}
863-
d->LastDockedEditor = DockWidget;
864-
}
855+
856+
857+
ads::CDockAreaWidget* EditorArea = d->LastDockedEditor ? d->LastDockedEditor->dockAreaWidget() : nullptr;
858+
if (EditorArea)
859+
{
860+
if (Tabbed)
861+
{
862+
// Test inserting the dock widget tab at a given position instead
863+
// of appending it. This function inserts the new dock widget as
864+
// first tab
865+
d->DockManager->addDockWidgetTabToArea(DockWidget, EditorArea, 0);
866+
}
867+
else
868+
{
869+
d->DockManager->setConfigFlag(ads::CDockManager::EqualSplitOnInsertion, true);
870+
d->DockManager->addDockWidget(ads::RightDockWidgetArea, DockWidget, EditorArea);
871+
}
872+
}
873+
else
874+
{
875+
if (d->LastCreatedFloatingEditor)
876+
{
877+
d->DockManager->addDockWidget(ads::RightDockWidgetArea, DockWidget, d->LastCreatedFloatingEditor->dockAreaWidget());
878+
}
879+
else
880+
{
881+
d->DockManager->addDockWidget(ads::TopDockWidgetArea, DockWidget);
882+
}
883+
}
884+
d->LastDockedEditor = DockWidget;
865885
}
866886

867887

demo/demo.qrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<file>images/create_floating_editor.svg</file>
1818
<file>images/create_floating_table.svg</file>
1919
<file>images/docked_editor.svg</file>
20+
<file>images/tab.svg</file>
2021
<file>res/visual_studio_light.css</file>
2122
<file>images/color_lens.svg</file>
2223
<file>images/ads_icon.svg</file>

demo/images/tab.svg

Lines changed: 6 additions & 0 deletions
Loading

src/DockAreaWidget.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,10 @@ void CDockAreaWidget::addDockWidget(CDockWidget* DockWidget)
480480
void CDockAreaWidget::insertDockWidget(int index, CDockWidget* DockWidget,
481481
bool Activate)
482482
{
483+
if (index < 0 || index > d->ContentsLayout->count())
484+
{
485+
index = d->ContentsLayout->count();
486+
}
483487
d->ContentsLayout->insertWidget(index, DockWidget);
484488
DockWidget->setDockArea(this);
485489
DockWidget->tabWidget()->setDockAreaWidget(this);

src/DockContainerWidget.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ class DockContainerWidgetPrivate
169169
* Adds dock widget to a existing DockWidgetArea
170170
*/
171171
CDockAreaWidget* addDockWidgetToDockArea(DockWidgetArea area, CDockWidget* Dockwidget,
172-
CDockAreaWidget* TargetDockArea);
172+
CDockAreaWidget* TargetDockArea, int Index = -1);
173173

174174
/**
175175
* Add dock area to this container
@@ -1278,11 +1278,11 @@ void DockContainerWidgetPrivate::dumpRecursive(int level, QWidget* widget)
12781278

12791279
//============================================================================
12801280
CDockAreaWidget* DockContainerWidgetPrivate::addDockWidgetToDockArea(DockWidgetArea area,
1281-
CDockWidget* Dockwidget, CDockAreaWidget* TargetDockArea)
1281+
CDockWidget* Dockwidget, CDockAreaWidget* TargetDockArea, int Index)
12821282
{
12831283
if (CenterDockWidgetArea == area)
12841284
{
1285-
TargetDockArea->addDockWidget(Dockwidget);
1285+
TargetDockArea->insertDockWidget(Index, Dockwidget);
12861286
TargetDockArea->updateTitleBarVisibility();
12871287
return TargetDockArea;
12881288
}
@@ -1370,7 +1370,7 @@ CDockContainerWidget::~CDockContainerWidget()
13701370

13711371
//============================================================================
13721372
CDockAreaWidget* CDockContainerWidget::addDockWidget(DockWidgetArea area, CDockWidget* Dockwidget,
1373-
CDockAreaWidget* DockAreaWidget)
1373+
CDockAreaWidget* DockAreaWidget, int Index)
13741374
{
13751375
auto TopLevelDockWidget = topLevelDockWidget();
13761376
CDockAreaWidget* OldDockArea = Dockwidget->dockAreaWidget();
@@ -1383,7 +1383,7 @@ CDockAreaWidget* CDockContainerWidget::addDockWidget(DockWidgetArea area, CDockW
13831383
CDockAreaWidget* DockArea;
13841384
if (DockAreaWidget)
13851385
{
1386-
DockArea = d->addDockWidgetToDockArea(area, Dockwidget, DockAreaWidget);
1386+
DockArea = d->addDockWidgetToDockArea(area, Dockwidget, DockAreaWidget, Index);
13871387
}
13881388
else
13891389
{

src/DockContainerWidget.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ class ADS_EXPORT CDockContainerWidget : public QFrame
221221
* \return Returns the dock area widget that contains the new DockWidget
222222
*/
223223
CDockAreaWidget* addDockWidget(DockWidgetArea area, CDockWidget* Dockwidget,
224-
CDockAreaWidget* DockAreaWidget = nullptr);
224+
CDockAreaWidget* DockAreaWidget = nullptr, int Index = -1);
225225

226226
/**
227227
* Removes dockwidget

src/DockManager.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -851,11 +851,11 @@ void CDockManager::restoreHiddenFloatingWidgets()
851851

852852
//============================================================================
853853
CDockAreaWidget* CDockManager::addDockWidget(DockWidgetArea area,
854-
CDockWidget* Dockwidget, CDockAreaWidget* DockAreaWidget)
854+
CDockWidget* Dockwidget, CDockAreaWidget* DockAreaWidget, int Index)
855855
{
856856
d->DockWidgetsMap.insert(Dockwidget->objectName(), Dockwidget);
857857
auto Container = DockAreaWidget ? DockAreaWidget->dockContainer() : this;
858-
auto AreaOfAddedDockWidget = Container->addDockWidget(area, Dockwidget, DockAreaWidget);
858+
auto AreaOfAddedDockWidget = Container->addDockWidget(area, Dockwidget, DockAreaWidget, Index);
859859
Q_EMIT dockWidgetAdded(Dockwidget);
860860
return AreaOfAddedDockWidget;
861861
}
@@ -907,9 +907,9 @@ CDockAreaWidget* CDockManager::addDockWidgetTab(DockWidgetArea area,
907907

908908
//============================================================================
909909
CDockAreaWidget* CDockManager::addDockWidgetTabToArea(CDockWidget* Dockwidget,
910-
CDockAreaWidget* DockAreaWidget)
910+
CDockAreaWidget* DockAreaWidget, int Index)
911911
{
912-
return addDockWidget(ads::CenterDockWidgetArea, Dockwidget, DockAreaWidget);
912+
return addDockWidget(ads::CenterDockWidgetArea, Dockwidget, DockAreaWidget, Index);
913913
}
914914

915915

src/DockManager.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ class ADS_EXPORT CDockManager : public CDockContainerWidget
328328
* \return Returns the dock area widget that contains the new DockWidget
329329
*/
330330
CDockAreaWidget* addDockWidget(DockWidgetArea area, CDockWidget* Dockwidget,
331-
CDockAreaWidget* DockAreaWidget = nullptr);
331+
CDockAreaWidget* DockAreaWidget = nullptr, int Index = -1);
332332

333333
/**
334334
* Adds dockwidget into the given container.
@@ -366,9 +366,11 @@ class ADS_EXPORT CDockManager : public CDockContainerWidget
366366
/**
367367
* This function will add the given Dockwidget to the given DockAreaWidget
368368
* as a new tab.
369+
* If index is out of range, the tab is simply appended. Otherwise it is
370+
* inserted at the specified position.
369371
*/
370372
CDockAreaWidget* addDockWidgetTabToArea(CDockWidget* Dockwidget,
371-
CDockAreaWidget* DockAreaWidget);
373+
CDockAreaWidget* DockAreaWidget, int Index = -1);
372374

373375
/**
374376
* Adds the given DockWidget floating and returns the created

0 commit comments

Comments
 (0)