1
0
mirror of https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git synced 2025-04-01 02:42:39 +08:00

Add factory method to Dock manager as an alternative method to create DockWidget, supporting custom factory

This commit is contained in:
Federico Fuga 2024-11-08 10:18:05 +01:00
parent 25e0cff048
commit 1db4cf70ac
4 changed files with 50 additions and 8 deletions

View File

@ -237,7 +237,7 @@ struct MainWindowPrivate
m->setRootPath(QDir::currentPath());
w->setModel(m);
w->setRootIndex(m->index(QDir::currentPath()));
ads::CDockWidget* DockWidget = new ads::CDockWidget(QString("Filesystem %1")
ads::CDockWidget* DockWidget = DockManager->createDockWidget(QString("Filesystem %1")
.arg(FileSystemCount++));
DockWidget->setWidget(w);
DockWidget->setIcon(svgIcon(":/adsdemo/images/folder_open.svg"));
@ -258,7 +258,7 @@ struct MainWindowPrivate
{
static int CalendarCount = 0;
QCalendarWidget* w = new QCalendarWidget();
ads::CDockWidget* DockWidget = new ads::CDockWidget(QString("Calendar %1").arg(CalendarCount++));
ads::CDockWidget* DockWidget = DockManager->createDockWidget(QString("Calendar %1").arg(CalendarCount++));
// The following lines are for testing the setWidget() and takeWidget()
// functionality
DockWidget->setWidget(w);
@ -303,7 +303,7 @@ struct MainWindowPrivate
.arg(LabelCount)
.arg(QTime::currentTime().toString("hh:mm:ss:zzz")));
ads::CDockWidget* DockWidget = new ads::CDockWidget(QString("Label %1").arg(LabelCount++));
ads::CDockWidget* DockWidget = DockManager->createDockWidget(QString("Label %1").arg(LabelCount++));
DockWidget->setWidget(l);
DockWidget->setIcon(svgIcon(":/adsdemo/images/font_download.svg"));
ui.menuView->addAction(DockWidget->toggleViewAction());
@ -321,7 +321,7 @@ struct MainWindowPrivate
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++));
ads::CDockWidget* DockWidget = DockManager->createDockWidget(QString("Editor %1").arg(EditorCount++));
DockWidget->setWidget(w);
DockWidget->setIcon(svgIcon(":/adsdemo/images/edit.svg"));
DockWidget->setFeature(ads::CDockWidget::CustomCloseHandling, true);
@ -364,7 +364,7 @@ struct MainWindowPrivate
auto Result = w->loadFile(FileName);
qDebug() << "loadFile result: " << Result;
ads::CDockWidget* DockWidget = new ads::CDockWidget(QString("Image Viewer %1").arg(ImageViewerCount++));
ads::CDockWidget* DockWidget = DockManager->createDockWidget(QString("Image Viewer %1").arg(ImageViewerCount++));
DockWidget->setIcon(svgIcon(":/adsdemo/images/photo.svg"));
DockWidget->setWidget(w,ads:: CDockWidget::ForceNoScrollArea);
auto ToolBar = DockWidget->createDefaultToolBar();
@ -379,7 +379,7 @@ struct MainWindowPrivate
{
static int TableCount = 0;
auto w = new CMinSizeTableWidget();
ads::CDockWidget* DockWidget = new ads::CDockWidget(QString("Table %1").arg(TableCount++));
ads::CDockWidget* DockWidget = DockManager->createDockWidget(QString("Table %1").arg(TableCount++));
static int colCount = 5;
static int rowCount = 30;
w->setColumnCount(colCount);
@ -418,7 +418,7 @@ struct MainWindowPrivate
ads::CDockWidget *createQQuickWidget()
{
QQuickWidget *widget = new QQuickWidget();
ads::CDockWidget *dockWidget = new ads::CDockWidget("Quick");
ads::CDockWidget *dockWidget = DockManager->createDockWidget("Quick");
dockWidget->setWidget(widget);
return dockWidget;
}
@ -433,7 +433,7 @@ struct MainWindowPrivate
{
static int ActiveXCount = 0;
QAxWidget* w = new QAxWidget("{6bf52a52-394a-11d3-b153-00c04f79faa6}", parent);
ads::CDockWidget* DockWidget = new ads::CDockWidget(QString("Active X %1").arg(ActiveXCount++));
ads::CDockWidget* DockWidget = DockManager->createDockWidget(QString("Active X %1").arg(ActiveXCount++));
DockWidget->setWidget(w);
ui.menuView->addAction(DockWidget->toggleViewAction());
return DockWidget;

View File

@ -1280,6 +1280,10 @@ CIconProvider& CDockManager::iconProvider()
return Instance;
}
CDockWidget* CDockManager::createDockWidget(const QString& title, QWidget* parent)
{
return new CDockWidget(this, title, parent);
}
//===========================================================================
void CDockManager::notifyWidgetOrAreaRelocation(QWidget* DroppedWidget)

View File

@ -336,6 +336,21 @@ public:
*/
static CIconProvider& iconProvider();
/**
* Creates a new dock widget with the specified title and optional parent
* widget.
*
* The new dock widget will be managed by the dock manager, and its lifetime
* will be tied to the dock manager. If a parent widget is provided, the dock
* widget will be created as a child of the parent widget. If no parent widget
* is provided, the dock widget will be created as a top-level widget.
*
* @param title The title of the dock widget.
* @param parent The parent widget, if any. Defaults to nullptr.
* @return Returns a pointer to the created CDockWidget.
*/
CDockWidget *createDockWidget(const QString &title, QWidget* parent = nullptr);
/**
* Adds dockwidget into the given area.
* If DockAreaWidget is not null, then the area parameter indicates the area

View File

@ -259,6 +259,29 @@ public:
*/
explicit CDockWidget(const QString &title, QWidget* parent = nullptr);
/**
* This constructor creates a dock widget for the given dock manager with the
* provided title.
*
* @param manager Pointer to the dock manager that owns the dock widget.
* @param title The title is the text that is shown in the window title when
* the dock widget is floating and it is the title that is shown in the
* titlebar or the tab of this dock widget if it is tabified.
* @param parent Pointer to the parent widget, defaults to nullptr.
*
* @note The object name of the dock widget is also set to the title. The
* object name is required by the dock manager to properly save and restore
* the state of the dock widget. That means, the title needs to be unique. If
* the title is not unique or if you would like to change the title during
* runtime, you need to set a unique object name explicitly by calling
* setObjectName() after construction. Use the layoutFlags to configure the
* layout of the dock widget.
*
* @note this constructor is preferred over the two argument version, especially
* when custom factories are in use. Indeed, it will use the Dock Manager factory,
* and not the default factory. For this reason, the original constructor should
* be deprecated in favour of this version.
*/
CDockWidget(CDockManager *manager, const QString &title, QWidget* parent = nullptr);
/**