mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2024-12-24 07:21:32 +08:00
Fixed problem with CDockAreaTabBar::onCloseOtherTabsRequested() if DockWidgets support the DockwidgetDeleteOnClose flag, enhanced demo to enabled creation of dynamic tables
This commit is contained in:
parent
05f8ce15a2
commit
a45a035bb3
@ -52,6 +52,7 @@
|
||||
#include <QInputDialog>
|
||||
#include <QRubberBand>
|
||||
#include <QPlainTextEdit>
|
||||
#include <QTableWidget>
|
||||
|
||||
#include <QMap>
|
||||
#include <QElapsedTimer>
|
||||
@ -159,6 +160,45 @@ static ads::CDockWidget* createFileSystemTreeDockWidget(QMenu* ViewMenu)
|
||||
return DockWidget;
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
static ads::CDockWidget* createEditorWidget(QMenu* ViewMenu)
|
||||
{
|
||||
static int EditorCount = 0;
|
||||
QPlainTextEdit* w = new QPlainTextEdit();
|
||||
w->setPlaceholderText("This is an editor. If you close the editor, it will be "
|
||||
"deleted. Enter your text here.");
|
||||
w->setStyleSheet("border: none");
|
||||
ads::CDockWidget* DockWidget = new ads::CDockWidget(QString("Editor %1").arg(EditorCount++));
|
||||
DockWidget->setWidget(w);
|
||||
DockWidget->setIcon(svgIcon(":/adsdemo/images/edit.svg"));
|
||||
ViewMenu->addAction(DockWidget->toggleViewAction());
|
||||
return DockWidget;
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
static ads::CDockWidget* createTableWidget(QMenu* ViewMenu)
|
||||
{
|
||||
static int TableCount = 0;
|
||||
QTableWidget* w = new QTableWidget();
|
||||
ads::CDockWidget* DockWidget = new ads::CDockWidget(QString("Table %1").arg(TableCount++));
|
||||
static int colCount = 5;
|
||||
static int rowCount = 30;
|
||||
w->setColumnCount(colCount);
|
||||
w->setRowCount(rowCount);
|
||||
for (int col = 0; col < colCount; ++col)
|
||||
{
|
||||
w->setHorizontalHeaderItem(col, new QTableWidgetItem(QString("Col %1").arg(col+1)));
|
||||
for (int row = 0; row < rowCount; ++row)
|
||||
{
|
||||
w->setItem(row, col, new QTableWidgetItem(QString("T %1-%2").arg(row + 1).arg(col+1)));
|
||||
}
|
||||
}
|
||||
DockWidget->setWidget(w);
|
||||
DockWidget->setIcon(svgIcon(":/adsdemo/images/grid_on.svg"));
|
||||
ViewMenu->addAction(DockWidget->toggleViewAction());
|
||||
return DockWidget;
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
/**
|
||||
@ -277,6 +317,11 @@ void MainWindowPrivate::createActions()
|
||||
a->setToolTip("Creates floating dynamic dockable editor windows that are deleted on close");
|
||||
a->setIcon(svgIcon(":/adsdemo/images/note_add.svg"));
|
||||
_this->connect(a, SIGNAL(triggered()), SLOT(createEditor()));
|
||||
|
||||
a = ui.toolBar->addAction("Create Table");
|
||||
a->setToolTip("Creates floating dynamic dockable table with millions of entries");
|
||||
a->setIcon(svgIcon(":/adsdemo/images/grid_on.svg"));
|
||||
_this->connect(a, SIGNAL(triggered()), SLOT(createTable()));
|
||||
}
|
||||
|
||||
|
||||
@ -426,19 +471,19 @@ void CMainWindow::onViewToggled(bool Open)
|
||||
//============================================================================
|
||||
void CMainWindow::createEditor()
|
||||
{
|
||||
static int EditorCount = 0;
|
||||
QPlainTextEdit* w = new QPlainTextEdit();
|
||||
w->setPlaceholderText("This is an editor. If you close the editor, it will be "
|
||||
"deleted. Enter your text here.");
|
||||
w->setStyleSheet("border: none");
|
||||
ads::CDockWidget* DockWidget = new ads::CDockWidget(QString("Editor %1").arg(EditorCount++));
|
||||
DockWidget->setWidget(w);
|
||||
DockWidget->setToggleViewActionMode(ads::CDockWidget::ActionModeShow);
|
||||
DockWidget->setIcon(svgIcon(":/adsdemo/images/edit.svg"));
|
||||
auto DockWidget = createEditorWidget(d->ui.menuView);
|
||||
DockWidget->setFeature(ads::CDockWidget::DockWidgetDeleteOnClose, true);
|
||||
d->ui.menuView->addAction(DockWidget->toggleViewAction());
|
||||
|
||||
auto FloatingWidget = d->DockManager->addDockWidgetFloating(DockWidget);
|
||||
FloatingWidget->move(QPoint(20, 20));
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CMainWindow::createTable()
|
||||
{
|
||||
auto DockWidget = createTableWidget(d->ui.menuView);
|
||||
DockWidget->setFeature(ads::CDockWidget::DockWidgetDeleteOnClose, true);
|
||||
auto FloatingWidget = d->DockManager->addDockWidgetFloating(DockWidget);
|
||||
FloatingWidget->move(QPoint(40, 40));
|
||||
}
|
||||
|
||||
|
@ -60,6 +60,7 @@ private slots:
|
||||
void savePerspective();
|
||||
void onViewToggled(bool Open);
|
||||
void createEditor();
|
||||
void createTable();
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
||||
|
@ -8,5 +8,6 @@
|
||||
<file>images/save.svg</file>
|
||||
<file>images/date_range.svg</file>
|
||||
<file>images/edit.svg</file>
|
||||
<file>images/grid_on.svg</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
6
demo/images/grid_on.svg
Normal file
6
demo/images/grid_on.svg
Normal file
@ -0,0 +1,6 @@
|
||||
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0,0,1024,1024">
|
||||
<desc>grid_on 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.)</desc>
|
||||
<g fill="#03b8e5" fill-rule="nonzero" style="mix-blend-mode: normal">
|
||||
<path d="M938.67,170.67v682.66c0,46.93 -38.41,85.34 -85.34,85.34h-682.66c-46.93,0 -85.34,-38.41 -85.34,-85.34v-682.66c0,-46.93 38.41,-85.34 85.34,-85.34h682.66c46.93,0 85.34,38.41 85.34,85.34zM341.33,170.67h-170.66v170.66h170.66zM341.33,682.67h-170.66v170.66h170.66zM341.33,426.67h-170.66v170.66h170.66zM597.33,170.67h-170.66v170.66h170.66zM853.33,170.67h-170.66v170.66h170.66zM597.33,682.67h-170.66v170.66h170.66zM597.33,426.67h-170.66v170.66h170.66zM853.33,682.67h-170.66v170.66h170.66zM853.33,426.67h-170.66v170.66h170.66z"/>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 931 B |
@ -449,7 +449,13 @@ void CDockAreaTabBar::onCloseOtherTabsRequested()
|
||||
auto Tab = tab(i);
|
||||
if (Tab->isClosable() && !Tab->isHidden() && Tab != Sender)
|
||||
{
|
||||
// If the dock widget is deleted with the closeTab() call, its tab
|
||||
// it will no longer be in the layout, and thus the index needs to
|
||||
// be updated to not skip any tabs
|
||||
int Offset = Tab->dockWidget()->features().testFlag(
|
||||
CDockWidget::DockWidgetDeleteOnClose) ? 1 : 0;
|
||||
closeTab(i);
|
||||
i -= Offset;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user