Skip to content

Commit a45a035

Browse files
Fixed problem with CDockAreaTabBar::onCloseOtherTabsRequested() if DockWidgets support the DockwidgetDeleteOnClose flag, enhanced demo to enabled creation of dynamic tables
1 parent 05f8ce1 commit a45a035

File tree

5 files changed

+70
-11
lines changed

5 files changed

+70
-11
lines changed

demo/MainWindow.cpp

Lines changed: 56 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
#include <QInputDialog>
5353
#include <QRubberBand>
5454
#include <QPlainTextEdit>
55+
#include <QTableWidget>
5556

5657
#include <QMap>
5758
#include <QElapsedTimer>
@@ -159,6 +160,45 @@ static ads::CDockWidget* createFileSystemTreeDockWidget(QMenu* ViewMenu)
159160
return DockWidget;
160161
}
161162

163+
//============================================================================
164+
static ads::CDockWidget* createEditorWidget(QMenu* ViewMenu)
165+
{
166+
static int EditorCount = 0;
167+
QPlainTextEdit* w = new QPlainTextEdit();
168+
w->setPlaceholderText("This is an editor. If you close the editor, it will be "
169+
"deleted. Enter your text here.");
170+
w->setStyleSheet("border: none");
171+
ads::CDockWidget* DockWidget = new ads::CDockWidget(QString("Editor %1").arg(EditorCount++));
172+
DockWidget->setWidget(w);
173+
DockWidget->setIcon(svgIcon(":/adsdemo/images/edit.svg"));
174+
ViewMenu->addAction(DockWidget->toggleViewAction());
175+
return DockWidget;
176+
}
177+
178+
//============================================================================
179+
static ads::CDockWidget* createTableWidget(QMenu* ViewMenu)
180+
{
181+
static int TableCount = 0;
182+
QTableWidget* w = new QTableWidget();
183+
ads::CDockWidget* DockWidget = new ads::CDockWidget(QString("Table %1").arg(TableCount++));
184+
static int colCount = 5;
185+
static int rowCount = 30;
186+
w->setColumnCount(colCount);
187+
w->setRowCount(rowCount);
188+
for (int col = 0; col < colCount; ++col)
189+
{
190+
w->setHorizontalHeaderItem(col, new QTableWidgetItem(QString("Col %1").arg(col+1)));
191+
for (int row = 0; row < rowCount; ++row)
192+
{
193+
w->setItem(row, col, new QTableWidgetItem(QString("T %1-%2").arg(row + 1).arg(col+1)));
194+
}
195+
}
196+
DockWidget->setWidget(w);
197+
DockWidget->setIcon(svgIcon(":/adsdemo/images/grid_on.svg"));
198+
ViewMenu->addAction(DockWidget->toggleViewAction());
199+
return DockWidget;
200+
}
201+
162202

163203
//============================================================================
164204
/**
@@ -277,6 +317,11 @@ void MainWindowPrivate::createActions()
277317
a->setToolTip("Creates floating dynamic dockable editor windows that are deleted on close");
278318
a->setIcon(svgIcon(":/adsdemo/images/note_add.svg"));
279319
_this->connect(a, SIGNAL(triggered()), SLOT(createEditor()));
320+
321+
a = ui.toolBar->addAction("Create Table");
322+
a->setToolTip("Creates floating dynamic dockable table with millions of entries");
323+
a->setIcon(svgIcon(":/adsdemo/images/grid_on.svg"));
324+
_this->connect(a, SIGNAL(triggered()), SLOT(createTable()));
280325
}
281326

282327

@@ -426,19 +471,19 @@ void CMainWindow::onViewToggled(bool Open)
426471
//============================================================================
427472
void CMainWindow::createEditor()
428473
{
429-
static int EditorCount = 0;
430-
QPlainTextEdit* w = new QPlainTextEdit();
431-
w->setPlaceholderText("This is an editor. If you close the editor, it will be "
432-
"deleted. Enter your text here.");
433-
w->setStyleSheet("border: none");
434-
ads::CDockWidget* DockWidget = new ads::CDockWidget(QString("Editor %1").arg(EditorCount++));
435-
DockWidget->setWidget(w);
436-
DockWidget->setToggleViewActionMode(ads::CDockWidget::ActionModeShow);
437-
DockWidget->setIcon(svgIcon(":/adsdemo/images/edit.svg"));
474+
auto DockWidget = createEditorWidget(d->ui.menuView);
438475
DockWidget->setFeature(ads::CDockWidget::DockWidgetDeleteOnClose, true);
439-
d->ui.menuView->addAction(DockWidget->toggleViewAction());
440-
441476
auto FloatingWidget = d->DockManager->addDockWidgetFloating(DockWidget);
442477
FloatingWidget->move(QPoint(20, 20));
443478
}
444479

480+
481+
//============================================================================
482+
void CMainWindow::createTable()
483+
{
484+
auto DockWidget = createTableWidget(d->ui.menuView);
485+
DockWidget->setFeature(ads::CDockWidget::DockWidgetDeleteOnClose, true);
486+
auto FloatingWidget = d->DockManager->addDockWidgetFloating(DockWidget);
487+
FloatingWidget->move(QPoint(40, 40));
488+
}
489+

demo/MainWindow.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ private slots:
6060
void savePerspective();
6161
void onViewToggled(bool Open);
6262
void createEditor();
63+
void createTable();
6364
};
6465

6566
#endif // MAINWINDOW_H

demo/demo.qrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@
88
<file>images/save.svg</file>
99
<file>images/date_range.svg</file>
1010
<file>images/edit.svg</file>
11+
<file>images/grid_on.svg</file>
1112
</qresource>
1213
</RCC>

demo/images/grid_on.svg

Lines changed: 6 additions & 0 deletions
Loading

src/DockAreaTabBar.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,13 @@ void CDockAreaTabBar::onCloseOtherTabsRequested()
449449
auto Tab = tab(i);
450450
if (Tab->isClosable() && !Tab->isHidden() && Tab != Sender)
451451
{
452+
// If the dock widget is deleted with the closeTab() call, its tab
453+
// it will no longer be in the layout, and thus the index needs to
454+
// be updated to not skip any tabs
455+
int Offset = Tab->dockWidget()->features().testFlag(
456+
CDockWidget::DockWidgetDeleteOnClose) ? 1 : 0;
452457
closeTab(i);
458+
i -= Offset;
453459
}
454460
}
455461
}

0 commit comments

Comments
 (0)