1
0
mirror of https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git synced 2025-03-31 10:22:39 +08:00

Remove DockComponentsFactory singleton. Allow Factory to be per-dock-manager customizable

This commit is contained in:
Federico Fuga 2024-11-05 19:28:26 +01:00
parent 952131a1e9
commit 25e0cff048
10 changed files with 74 additions and 62 deletions

View File

@ -471,12 +471,12 @@ void MainWindowPrivate::createContent()
appendFeaturStringToWindowTitle(FileSystemWidget);
// Test custom factory - we inject a help button into the title bar
ads::CDockComponentsFactory::setFactory(new CCustomComponentsFactory());
DockManager->setComponentsFactory(new CCustomComponentsFactory());
auto TopDockArea = DockManager->addDockWidget(ads::TopDockWidgetArea, FileSystemWidget);
// Uncomment the next line if you would like to test the
// HideSingleWidgetTitleBar functionality
// TopDockArea->setDockAreaFlag(ads::CDockAreaWidget::HideSingleWidgetTitleBar, true);
ads::CDockComponentsFactory::resetDefaultFactory();
DockManager->setComponentsFactory(ads::CDockComponentsFactory::defaultFactory());
// We create a calendar widget and clear all flags to prevent the dock area
// from closing

View File

@ -109,6 +109,7 @@ int resizeHandleLayoutPosition(SideBarLocation Area)
*/
struct AutoHideDockContainerPrivate
{
CDockManager *DockManager;
CAutoHideDockContainer* _this;
CDockAreaWidget* DockArea{nullptr};
CDockWidget* DockWidget{nullptr};
@ -122,7 +123,11 @@ struct AutoHideDockContainerPrivate
/**
* Private data constructor
*/
AutoHideDockContainerPrivate(CAutoHideDockContainer *_public);
AutoHideDockContainerPrivate(CDockManager *manager, CAutoHideDockContainer *_public);
QSharedPointer<ads::CDockComponentsFactory> componentsFactory() const {
return DockManager->componentsFactory();
}
/**
* Convenience function to get a dock widget area
@ -178,8 +183,9 @@ struct AutoHideDockContainerPrivate
//============================================================================
AutoHideDockContainerPrivate::AutoHideDockContainerPrivate(
CDockManager *manager,
CAutoHideDockContainer *_public) :
_this(_public)
DockManager(manager), _this(_public)
{
}
@ -195,11 +201,11 @@ CDockContainerWidget* CAutoHideDockContainer::dockContainer() const
//============================================================================
CAutoHideDockContainer::CAutoHideDockContainer(CDockWidget* DockWidget, SideBarLocation area, CDockContainerWidget* parent) :
Super(parent),
d(new AutoHideDockContainerPrivate(this))
d(new AutoHideDockContainerPrivate(DockWidget->dockManager(), this))
{
hide(); // auto hide dock container is initially always hidden
d->SideTabBarArea = area;
d->SideTab = componentsFactory()->createDockWidgetSideTab(nullptr);
d->SideTab = d->componentsFactory()->createDockWidgetSideTab(nullptr);
connect(d->SideTab, &CAutoHideTab::pressed, this, &CAutoHideDockContainer::toggleCollapseState);
d->DockArea = new CDockAreaWidget(DockWidget->dockManager(), parent);
d->DockArea->setObjectName("autoHideDockArea");

View File

@ -66,6 +66,7 @@ namespace ads
*/
struct DockAreaTitleBarPrivate
{
CDockManager *DockManager;
CDockAreaTitleBar* _this;
QPointer<CTitleBarButton> TabsMenuButton;
QPointer<CTitleBarButton> AutoHideButton;
@ -88,7 +89,11 @@ struct DockAreaTitleBarPrivate
/**
* Private data constructor
*/
DockAreaTitleBarPrivate(CDockAreaTitleBar* _public);
DockAreaTitleBarPrivate(CDockManager *manager, CDockAreaTitleBar* _public);
QSharedPointer<ads::CDockComponentsFactory> componentsFactory() const {
return DockManager->componentsFactory();
}
/**
* Creates the title bar close and menu buttons
@ -165,8 +170,8 @@ struct DockAreaTitleBarPrivate
};// struct DockAreaTitleBarPrivate
//============================================================================
DockAreaTitleBarPrivate::DockAreaTitleBarPrivate(CDockAreaTitleBar* _public) :
_this(_public)
DockAreaTitleBarPrivate::DockAreaTitleBarPrivate(CDockManager *manager, CDockAreaTitleBar* _public) :
DockManager(manager), _this(_public)
{
}
@ -331,7 +336,7 @@ void DockAreaTitleBarPrivate::startFloating(const QPoint& Offset)
//============================================================================
CDockAreaTitleBar::CDockAreaTitleBar(CDockAreaWidget* parent) :
QFrame(parent),
d(new DockAreaTitleBarPrivate(this))
d(new DockAreaTitleBarPrivate(parent->dockManager(), this))
{
d->DockArea = parent;

View File

@ -264,6 +264,10 @@ struct DockAreaWidgetPrivate
QSize MinSizeHint;
CDockAreaWidget::DockAreaFlags Flags{CDockAreaWidget::DefaultFlags};
QSharedPointer<ads::CDockComponentsFactory> componentsFactory() const {
return DockManager->componentsFactory();
}
/**
* Private data constructor
*/
@ -371,10 +375,10 @@ void DockAreaWidgetPrivate::updateTitleBarButtonStates()
if (_this->isAutoHide())
{
if (CDockManager::testAutoHideConfigFlag(CDockManager::AutoHideHasCloseButton))
{
if (CDockManager::testAutoHideConfigFlag(CDockManager::AutoHideHasCloseButton))
{
TitleBar->button(TitleBarButtonClose)->setEnabled(
_this->features().testFlag(CDockWidget::DockWidgetClosable));
_this->features().testFlag(CDockWidget::DockWidgetClosable));
}
}
else

View File

@ -21,7 +21,8 @@
namespace ads
{
static std::unique_ptr<CDockComponentsFactory> DefaultFactory(new CDockComponentsFactory());
static QSharedPointer<ads::CDockComponentsFactory> DefaultFactory;
//============================================================================
@ -50,26 +51,15 @@ CDockAreaTitleBar* CDockComponentsFactory::createDockAreaTitleBar(CDockAreaWidge
return new CDockAreaTitleBar(DockArea);
}
//============================================================================
const CDockComponentsFactory* CDockComponentsFactory::factory()
QSharedPointer<ads::CDockComponentsFactory>
CDockComponentsFactory::defaultFactory()
{
return DefaultFactory.get();
if (!DefaultFactory) {
DefaultFactory.reset(new CDockComponentsFactory());
}
return DefaultFactory;
}
//============================================================================
void CDockComponentsFactory::setFactory(CDockComponentsFactory* Factory)
{
DefaultFactory.reset(Factory);
}
//============================================================================
void CDockComponentsFactory::resetDefaultFactory()
{
DefaultFactory.reset(new CDockComponentsFactory());
}
} // namespace ads
//---------------------------------------------------------------------------

View File

@ -65,32 +65,9 @@ public:
*/
virtual CDockAreaTitleBar* createDockAreaTitleBar(CDockAreaWidget* DockArea) const;
/**
* Returns the default components factory
*/
static const CDockComponentsFactory* factory();
/**
* Sets a new default factory for creation of GUI elements.
* This function takes ownership of the given Factory.
*/
static void setFactory(CDockComponentsFactory* Factory);
/**
* Resets the current factory to the
*/
static void resetDefaultFactory();
static QSharedPointer<ads::CDockComponentsFactory> defaultFactory();
};
/**
* Convenience function to ease factory instance access
*/
inline const CDockComponentsFactory* componentsFactory()
{
return CDockComponentsFactory::factory();
}
} // namespace ads
//---------------------------------------------------------------------------

View File

@ -31,6 +31,7 @@
#include <AutoHideDockContainer.h>
#include "DockWidgetTab.h"
#include "DockManager.h"
#include "DockComponentsFactory.h"
#include <algorithm>
#include <iostream>
@ -124,6 +125,8 @@ struct DockManagerPrivate
QSize ToolBarIconSizeFloating = QSize(24, 24);
CDockWidget::DockWidgetFeatures LockedDockWidgetFeatures;
QSharedPointer<ads::CDockComponentsFactory> componentFactory {ads::CDockComponentsFactory::defaultFactory()};
/**
* Private data constructor
*/
@ -190,7 +193,6 @@ struct DockManagerPrivate
DockManagerPrivate::DockManagerPrivate(CDockManager* _public) :
_this(_public)
{
}
@ -579,6 +581,21 @@ CDockManager::~CDockManager()
delete d;
}
QSharedPointer<ads::CDockComponentsFactory> CDockManager::componentsFactory() const
{
return d->componentFactory;
}
void CDockManager::setComponentsFactory(ads::CDockComponentsFactory* factory)
{
d->componentFactory = QSharedPointer<ads::CDockComponentsFactory>(factory);
}
void CDockManager::setComponentsFactory(QSharedPointer<ads::CDockComponentsFactory> factory)
{
d->componentFactory = factory;
}
//============================================================================
#if defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)
bool CDockManager::eventFilter(QObject *obj, QEvent *e)

View File

@ -277,6 +277,12 @@ public:
*/
virtual ~CDockManager() override;
QSharedPointer<ads::CDockComponentsFactory> componentsFactory() const;
void setComponentsFactory(ads::CDockComponentsFactory *);
void setComponentsFactory(QSharedPointer<ads::CDockComponentsFactory>);
/**
* This function returns the global configuration flags
*/

View File

@ -80,7 +80,7 @@ struct DockWidgetPrivate
QWidget* Widget = nullptr;
CDockWidgetTab* TabWidget = nullptr;
CDockWidget::DockWidgetFeatures Features = CDockWidget::DefaultDockWidgetFeatures;
QPointer<CDockManager> DockManager;
QPointer<CDockManager> DockManager {nullptr};
QPointer<CDockAreaWidget> DockArea;
QAction* ToggleViewAction = nullptr;
bool Closed = false;
@ -357,9 +357,9 @@ void DockWidgetPrivate::setToolBarStyleFromDockManager()
//============================================================================
CDockWidget::CDockWidget(const QString &title, QWidget *parent) :
QFrame(parent),
d(new DockWidgetPrivate(this))
CDockWidget::CDockWidget(CDockManager* manager, const QString& title,
QWidget* parent)
: QFrame(parent), d(new DockWidgetPrivate(this))
{
d->Layout = new QBoxLayout(QBoxLayout::TopToBottom);
d->Layout->setContentsMargins(0, 0, 0, 0);
@ -368,7 +368,8 @@ CDockWidget::CDockWidget(const QString &title, QWidget *parent) :
setWindowTitle(title);
setObjectName(title);
d->TabWidget = componentsFactory()->createDockWidgetTab(this);
auto factory = manager ? manager->componentsFactory() : CDockComponentsFactory::defaultFactory();
d->TabWidget = factory->createDockWidgetTab(this);
d->ToggleViewAction = new QAction(title, this);
d->ToggleViewAction->setCheckable(true);
@ -382,6 +383,10 @@ CDockWidget::CDockWidget(const QString &title, QWidget *parent) :
}
}
CDockWidget::CDockWidget(const QString &title, QWidget *parent) :
CDockWidget(nullptr, title, parent)
{}
//============================================================================
CDockWidget::~CDockWidget()
{

View File

@ -257,7 +257,9 @@ public:
* by calling setObjectName() after construction.
* Use the layoutFlags to configure the layout of the dock widget.
*/
CDockWidget(const QString &title, QWidget* parent = nullptr);
explicit CDockWidget(const QString &title, QWidget* parent = nullptr);
CDockWidget(CDockManager *manager, const QString &title, QWidget* parent = nullptr);
/**
* Virtual Destructor