Added support for componentsFactory per dock manager

This commit is contained in:
Uwe Kindler 2024-12-20 10:12:46 +01:00
parent 7245dced84
commit 1bec4234c3
10 changed files with 121 additions and 21 deletions

View File

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

View File

@ -124,6 +124,21 @@ struct AutoHideDockContainerPrivate
*/ */
AutoHideDockContainerPrivate(CAutoHideDockContainer *_public); AutoHideDockContainerPrivate(CAutoHideDockContainer *_public);
/**
* Convenience function to ease access to dock manager components factory
*/
QSharedPointer<ads::CDockComponentsFactory> componentsFactory() const
{
if (!DockWidget || !DockWidget->dockManager())
{
return CDockComponentsFactory::factory();
}
else
{
return DockWidget->dockManager()->componentsFactory();
}
}
/** /**
* Convenience function to get a dock widget area * Convenience function to get a dock widget area
*/ */
@ -199,7 +214,7 @@ CAutoHideDockContainer::CAutoHideDockContainer(CDockWidget* DockWidget, SideBarL
{ {
hide(); // auto hide dock container is initially always hidden hide(); // auto hide dock container is initially always hidden
d->SideTabBarArea = area; d->SideTabBarArea = area;
d->SideTab = componentsFactory()->createDockWidgetSideTab(nullptr); d->SideTab = d->componentsFactory()->createDockWidgetSideTab(nullptr);
connect(d->SideTab, &CAutoHideTab::pressed, this, &CAutoHideDockContainer::toggleCollapseState); connect(d->SideTab, &CAutoHideTab::pressed, this, &CAutoHideDockContainer::toggleCollapseState);
d->DockArea = new CDockAreaWidget(DockWidget->dockManager(), parent); d->DockArea = new CDockAreaWidget(DockWidget->dockManager(), parent);
d->DockArea->setObjectName("autoHideDockArea"); d->DockArea->setObjectName("autoHideDockArea");

View File

@ -114,6 +114,14 @@ struct DockAreaTitleBarPrivate
return DockArea->dockManager(); return DockArea->dockManager();
} }
/**
* Convenience function for access to dock manager components factory
*/
QSharedPointer<ads::CDockComponentsFactory> componentsFactory() const
{
return dockManager()->componentsFactory();
}
/** /**
* Returns true if the given config flag is set * Returns true if the given config flag is set
* Convenience function to ease config flag testing * Convenience function to ease config flag testing

View File

@ -269,6 +269,14 @@ struct DockAreaWidgetPrivate
*/ */
DockAreaWidgetPrivate(CDockAreaWidget* _public); DockAreaWidgetPrivate(CDockAreaWidget* _public);
/**
* Convencience function to ease components factory access
*/
QSharedPointer<ads::CDockComponentsFactory> componentsFactory() const
{
return DockManager->componentsFactory();
}
/** /**
* Creates the layout for top area with tabs and close button * Creates the layout for top area with tabs and close button
*/ */

View File

@ -21,7 +21,8 @@
namespace ads namespace ads
{ {
static std::unique_ptr<CDockComponentsFactory> DefaultFactory(new CDockComponentsFactory());
static QSharedPointer<ads::CDockComponentsFactory> DefaultFactory;
//============================================================================ //============================================================================
@ -52,9 +53,13 @@ CDockAreaTitleBar* CDockComponentsFactory::createDockAreaTitleBar(CDockAreaWidge
//============================================================================ //============================================================================
const CDockComponentsFactory* CDockComponentsFactory::factory() QSharedPointer<ads::CDockComponentsFactory> CDockComponentsFactory::factory()
{ {
return DefaultFactory.get(); if (!DefaultFactory)
{
DefaultFactory.reset(new CDockComponentsFactory());
}
return DefaultFactory;
} }
@ -70,6 +75,7 @@ void CDockComponentsFactory::resetDefaultFactory()
{ {
DefaultFactory.reset(new CDockComponentsFactory()); DefaultFactory.reset(new CDockComponentsFactory());
} }
} // namespace ads } // namespace ads
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------

View File

@ -66,9 +66,11 @@ public:
virtual CDockAreaTitleBar* createDockAreaTitleBar(CDockAreaWidget* DockArea) const; virtual CDockAreaTitleBar* createDockAreaTitleBar(CDockAreaWidget* DockArea) const;
/** /**
* Returns the default components factory * This returns the default dock components factory instance.
* If no components factory is assigned to a specifc dock manager, this
* global factory instance will be used.
*/ */
static const CDockComponentsFactory* factory(); static QSharedPointer<ads::CDockComponentsFactory> factory();
/** /**
* Sets a new default factory for creation of GUI elements. * Sets a new default factory for creation of GUI elements.
@ -82,15 +84,6 @@ public:
static void resetDefaultFactory(); static void resetDefaultFactory();
}; };
/**
* Convenience function to ease factory instance access
*/
inline const CDockComponentsFactory* componentsFactory()
{
return CDockComponentsFactory::factory();
}
} // namespace ads } // namespace ads
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------

View File

@ -60,6 +60,8 @@
#include "DockAreaTitleBar.h" #include "DockAreaTitleBar.h"
#include "DockFocusController.h" #include "DockFocusController.h"
#include "DockSplitter.h" #include "DockSplitter.h"
#include "DockComponentsFactory.h"
#if defined(Q_OS_UNIX) && !defined(Q_OS_MACOS) #if defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)
#include "linux/FloatingWidgetTitleBar.h" #include "linux/FloatingWidgetTitleBar.h"
@ -125,6 +127,7 @@ struct DockManagerPrivate
QSize ToolBarIconSizeDocked = QSize(16, 16); QSize ToolBarIconSizeDocked = QSize(16, 16);
QSize ToolBarIconSizeFloating = QSize(24, 24); QSize ToolBarIconSizeFloating = QSize(24, 24);
CDockWidget::DockWidgetFeatures LockedDockWidgetFeatures; CDockWidget::DockWidgetFeatures LockedDockWidgetFeatures;
QSharedPointer<ads::CDockComponentsFactory> ComponentFactory {ads::CDockComponentsFactory::factory()};
/** /**
* Private data constructor * Private data constructor
@ -581,6 +584,28 @@ CDockManager::~CDockManager()
delete d; delete d;
} }
//============================================================================
QSharedPointer<ads::CDockComponentsFactory> CDockManager::componentsFactory() const
{
return d->ComponentFactory;
}
//============================================================================
void CDockManager::setComponentsFactory(ads::CDockComponentsFactory* factory)
{
setComponentsFactory(QSharedPointer<ads::CDockComponentsFactory>(factory));
}
//============================================================================
void CDockManager::setComponentsFactory(QSharedPointer<ads::CDockComponentsFactory> factory)
{
d->ComponentFactory = factory;
}
//============================================================================ //============================================================================
#if defined(Q_OS_UNIX) && !defined(Q_OS_MACOS) #if defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)
bool CDockManager::eventFilter(QObject *obj, QEvent *e) bool CDockManager::eventFilter(QObject *obj, QEvent *e)

View File

@ -290,6 +290,24 @@ public:
*/ */
virtual ~CDockManager() override; virtual ~CDockManager() override;
/**
* Returns the dock manager specific factory for creating components of
* fock widgets
*/
QSharedPointer<ads::CDockComponentsFactory> componentsFactory() const;
/**
* Sets a custom factory for creating components of dock widgets.
* The pointer is stored internally into a shared pointer so you should not
* delete the given factory object as long as it is used by the dock manager.
*/
void setComponentsFactory(ads::CDockComponentsFactory* Factory);
/**
* Sets a custom factory for creating components of dock widgets.
*/
void setComponentsFactory(QSharedPointer<ads::CDockComponentsFactory>);
/** /**
* This function returns the global configuration flags * This function returns the global configuration flags
*/ */

View File

@ -102,6 +102,14 @@ struct DockWidgetPrivate
*/ */
DockWidgetPrivate(CDockWidget* _public); DockWidgetPrivate(CDockWidget* _public);
/**
* Convenience function to ease components factory access
*/
QSharedPointer<ads::CDockComponentsFactory> componentsFactory() const
{
return DockManager ? DockManager->componentsFactory() : CDockComponentsFactory::factory();
}
/** /**
* Show dock widget * Show dock widget
*/ */
@ -358,9 +366,17 @@ void DockWidgetPrivate::setToolBarStyleFromDockManager()
//============================================================================ //============================================================================
CDockWidget::CDockWidget(const QString &title, QWidget *parent) : CDockWidget::CDockWidget(const QString &title, QWidget *parent) :
QFrame(parent), CDockWidget(nullptr, title, parent)
d(new DockWidgetPrivate(this))
{ {
}
//============================================================================
CDockWidget::CDockWidget(CDockManager *manager, const QString &title, QWidget* parent)
: QFrame(parent),
d(new DockWidgetPrivate(this))
{
d->DockManager = manager;
d->Layout = new QBoxLayout(QBoxLayout::TopToBottom); d->Layout = new QBoxLayout(QBoxLayout::TopToBottom);
d->Layout->setContentsMargins(0, 0, 0, 0); d->Layout->setContentsMargins(0, 0, 0, 0);
d->Layout->setSpacing(0); d->Layout->setSpacing(0);
@ -368,7 +384,7 @@ CDockWidget::CDockWidget(const QString &title, QWidget *parent) :
setWindowTitle(title); setWindowTitle(title);
setObjectName(title); setObjectName(title);
d->TabWidget = componentsFactory()->createDockWidgetTab(this); d->TabWidget = d->componentsFactory()->createDockWidgetTab(this);
d->ToggleViewAction = new QAction(title, this); d->ToggleViewAction = new QAction(title, this);
d->ToggleViewAction->setCheckable(true); d->ToggleViewAction->setCheckable(true);
@ -382,6 +398,7 @@ CDockWidget::CDockWidget(const QString &title, QWidget *parent) :
} }
} }
//============================================================================ //============================================================================
CDockWidget::~CDockWidget() CDockWidget::~CDockWidget()
{ {

View File

@ -256,8 +256,18 @@ public:
* during runtime, you need to set a unique object name explicitly * during runtime, you need to set a unique object name explicitly
* by calling setObjectName() after construction. * by calling setObjectName() after construction.
* Use the layoutFlags to configure the layout of the dock widget. * Use the layoutFlags to configure the layout of the dock widget.
* \note If you would like to use custom TabWidget implementations, you need
* to use the constructor with the CDockManager argument.
*/ */
CDockWidget(const QString &title, QWidget* parent = nullptr); explicit CDockWidget(const QString &title, QWidget* parent = nullptr);
/**
* Creates a dock widget and assigns the dock manager that manages this
* widget.
* This allows the dock widget to use the componentsFactory() of the dock
* manager in the constructot to create its components.
*/
CDockWidget(CDockManager *manager, const QString &title, QWidget* parent = nullptr);
/** /**
* Virtual Destructor * Virtual Destructor