Skip to content

Commit 1bec423

Browse files
Added support for componentsFactory per dock manager
1 parent 7245dce commit 1bec423

10 files changed

+121
-21
lines changed

demo/MainWindow.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -470,12 +470,12 @@ void MainWindowPrivate::createContent()
470470
appendFeaturStringToWindowTitle(FileSystemWidget);
471471

472472
// Test custom factory - we inject a help button into the title bar
473-
ads::CDockComponentsFactory::setFactory(new CCustomComponentsFactory());
473+
DockManager->setComponentsFactory(new CCustomComponentsFactory());
474474
auto TopDockArea = DockManager->addDockWidget(ads::TopDockWidgetArea, FileSystemWidget);
475475
// Uncomment the next line if you would like to test the
476476
// HideSingleWidgetTitleBar functionality
477477
// TopDockArea->setDockAreaFlag(ads::CDockAreaWidget::HideSingleWidgetTitleBar, true);
478-
ads::CDockComponentsFactory::resetDefaultFactory();
478+
DockManager->setComponentsFactory(ads::CDockComponentsFactory::factory());
479479

480480
// We create a calendar widget and clear all flags to prevent the dock area
481481
// from closing

src/AutoHideDockContainer.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,21 @@ struct AutoHideDockContainerPrivate
124124
*/
125125
AutoHideDockContainerPrivate(CAutoHideDockContainer *_public);
126126

127+
/**
128+
* Convenience function to ease access to dock manager components factory
129+
*/
130+
QSharedPointer<ads::CDockComponentsFactory> componentsFactory() const
131+
{
132+
if (!DockWidget || !DockWidget->dockManager())
133+
{
134+
return CDockComponentsFactory::factory();
135+
}
136+
else
137+
{
138+
return DockWidget->dockManager()->componentsFactory();
139+
}
140+
}
141+
127142
/**
128143
* Convenience function to get a dock widget area
129144
*/
@@ -199,7 +214,7 @@ CAutoHideDockContainer::CAutoHideDockContainer(CDockWidget* DockWidget, SideBarL
199214
{
200215
hide(); // auto hide dock container is initially always hidden
201216
d->SideTabBarArea = area;
202-
d->SideTab = componentsFactory()->createDockWidgetSideTab(nullptr);
217+
d->SideTab = d->componentsFactory()->createDockWidgetSideTab(nullptr);
203218
connect(d->SideTab, &CAutoHideTab::pressed, this, &CAutoHideDockContainer::toggleCollapseState);
204219
d->DockArea = new CDockAreaWidget(DockWidget->dockManager(), parent);
205220
d->DockArea->setObjectName("autoHideDockArea");

src/DockAreaTitleBar.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,14 @@ struct DockAreaTitleBarPrivate
114114
return DockArea->dockManager();
115115
}
116116

117+
/**
118+
* Convenience function for access to dock manager components factory
119+
*/
120+
QSharedPointer<ads::CDockComponentsFactory> componentsFactory() const
121+
{
122+
return dockManager()->componentsFactory();
123+
}
124+
117125
/**
118126
* Returns true if the given config flag is set
119127
* Convenience function to ease config flag testing

src/DockAreaWidget.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,14 @@ struct DockAreaWidgetPrivate
269269
*/
270270
DockAreaWidgetPrivate(CDockAreaWidget* _public);
271271

272+
/**
273+
* Convencience function to ease components factory access
274+
*/
275+
QSharedPointer<ads::CDockComponentsFactory> componentsFactory() const
276+
{
277+
return DockManager->componentsFactory();
278+
}
279+
272280
/**
273281
* Creates the layout for top area with tabs and close button
274282
*/

src/DockComponentsFactory.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121

2222
namespace ads
2323
{
24-
static std::unique_ptr<CDockComponentsFactory> DefaultFactory(new CDockComponentsFactory());
24+
25+
static QSharedPointer<ads::CDockComponentsFactory> DefaultFactory;
2526

2627

2728
//============================================================================
@@ -52,9 +53,13 @@ CDockAreaTitleBar* CDockComponentsFactory::createDockAreaTitleBar(CDockAreaWidge
5253

5354

5455
//============================================================================
55-
const CDockComponentsFactory* CDockComponentsFactory::factory()
56+
QSharedPointer<ads::CDockComponentsFactory> CDockComponentsFactory::factory()
5657
{
57-
return DefaultFactory.get();
58+
if (!DefaultFactory)
59+
{
60+
DefaultFactory.reset(new CDockComponentsFactory());
61+
}
62+
return DefaultFactory;
5863
}
5964

6065

@@ -70,6 +75,7 @@ void CDockComponentsFactory::resetDefaultFactory()
7075
{
7176
DefaultFactory.reset(new CDockComponentsFactory());
7277
}
78+
7379
} // namespace ads
7480

7581
//---------------------------------------------------------------------------

src/DockComponentsFactory.h

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,11 @@ class ADS_EXPORT CDockComponentsFactory
6666
virtual CDockAreaTitleBar* createDockAreaTitleBar(CDockAreaWidget* DockArea) const;
6767

6868
/**
69-
* Returns the default components factory
69+
* This returns the default dock components factory instance.
70+
* If no components factory is assigned to a specifc dock manager, this
71+
* global factory instance will be used.
7072
*/
71-
static const CDockComponentsFactory* factory();
73+
static QSharedPointer<ads::CDockComponentsFactory> factory();
7274

7375
/**
7476
* Sets a new default factory for creation of GUI elements.
@@ -82,15 +84,6 @@ class ADS_EXPORT CDockComponentsFactory
8284
static void resetDefaultFactory();
8385
};
8486

85-
86-
/**
87-
* Convenience function to ease factory instance access
88-
*/
89-
inline const CDockComponentsFactory* componentsFactory()
90-
{
91-
return CDockComponentsFactory::factory();
92-
}
93-
9487
} // namespace ads
9588

9689
//---------------------------------------------------------------------------

src/DockManager.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@
6060
#include "DockAreaTitleBar.h"
6161
#include "DockFocusController.h"
6262
#include "DockSplitter.h"
63+
#include "DockComponentsFactory.h"
64+
6365

6466
#if defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)
6567
#include "linux/FloatingWidgetTitleBar.h"
@@ -125,6 +127,7 @@ struct DockManagerPrivate
125127
QSize ToolBarIconSizeDocked = QSize(16, 16);
126128
QSize ToolBarIconSizeFloating = QSize(24, 24);
127129
CDockWidget::DockWidgetFeatures LockedDockWidgetFeatures;
130+
QSharedPointer<ads::CDockComponentsFactory> ComponentFactory {ads::CDockComponentsFactory::factory()};
128131

129132
/**
130133
* Private data constructor
@@ -581,6 +584,28 @@ CDockManager::~CDockManager()
581584
delete d;
582585
}
583586

587+
588+
//============================================================================
589+
QSharedPointer<ads::CDockComponentsFactory> CDockManager::componentsFactory() const
590+
{
591+
return d->ComponentFactory;
592+
}
593+
594+
595+
//============================================================================
596+
void CDockManager::setComponentsFactory(ads::CDockComponentsFactory* factory)
597+
{
598+
setComponentsFactory(QSharedPointer<ads::CDockComponentsFactory>(factory));
599+
}
600+
601+
602+
//============================================================================
603+
void CDockManager::setComponentsFactory(QSharedPointer<ads::CDockComponentsFactory> factory)
604+
{
605+
d->ComponentFactory = factory;
606+
}
607+
608+
584609
//============================================================================
585610
#if defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)
586611
bool CDockManager::eventFilter(QObject *obj, QEvent *e)

src/DockManager.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,24 @@ public Q_SLOTS:
290290
*/
291291
virtual ~CDockManager() override;
292292

293+
/**
294+
* Returns the dock manager specific factory for creating components of
295+
* fock widgets
296+
*/
297+
QSharedPointer<ads::CDockComponentsFactory> componentsFactory() const;
298+
299+
/**
300+
* Sets a custom factory for creating components of dock widgets.
301+
* The pointer is stored internally into a shared pointer so you should not
302+
* delete the given factory object as long as it is used by the dock manager.
303+
*/
304+
void setComponentsFactory(ads::CDockComponentsFactory* Factory);
305+
306+
/**
307+
* Sets a custom factory for creating components of dock widgets.
308+
*/
309+
void setComponentsFactory(QSharedPointer<ads::CDockComponentsFactory>);
310+
293311
/**
294312
* This function returns the global configuration flags
295313
*/

src/DockWidget.cpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,14 @@ struct DockWidgetPrivate
102102
*/
103103
DockWidgetPrivate(CDockWidget* _public);
104104

105+
/**
106+
* Convenience function to ease components factory access
107+
*/
108+
QSharedPointer<ads::CDockComponentsFactory> componentsFactory() const
109+
{
110+
return DockManager ? DockManager->componentsFactory() : CDockComponentsFactory::factory();
111+
}
112+
105113
/**
106114
* Show dock widget
107115
*/
@@ -358,17 +366,25 @@ void DockWidgetPrivate::setToolBarStyleFromDockManager()
358366

359367
//============================================================================
360368
CDockWidget::CDockWidget(const QString &title, QWidget *parent) :
361-
QFrame(parent),
362-
d(new DockWidgetPrivate(this))
369+
CDockWidget(nullptr, title, parent)
363370
{
371+
}
372+
373+
374+
//============================================================================
375+
CDockWidget::CDockWidget(CDockManager *manager, const QString &title, QWidget* parent)
376+
: QFrame(parent),
377+
d(new DockWidgetPrivate(this))
378+
{
379+
d->DockManager = manager;
364380
d->Layout = new QBoxLayout(QBoxLayout::TopToBottom);
365381
d->Layout->setContentsMargins(0, 0, 0, 0);
366382
d->Layout->setSpacing(0);
367383
setLayout(d->Layout);
368384
setWindowTitle(title);
369385
setObjectName(title);
370386

371-
d->TabWidget = componentsFactory()->createDockWidgetTab(this);
387+
d->TabWidget = d->componentsFactory()->createDockWidgetTab(this);
372388

373389
d->ToggleViewAction = new QAction(title, this);
374390
d->ToggleViewAction->setCheckable(true);
@@ -382,6 +398,7 @@ CDockWidget::CDockWidget(const QString &title, QWidget *parent) :
382398
}
383399
}
384400

401+
385402
//============================================================================
386403
CDockWidget::~CDockWidget()
387404
{

src/DockWidget.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,18 @@ private Q_SLOTS:
256256
* during runtime, you need to set a unique object name explicitly
257257
* by calling setObjectName() after construction.
258258
* Use the layoutFlags to configure the layout of the dock widget.
259+
* \note If you would like to use custom TabWidget implementations, you need
260+
* to use the constructor with the CDockManager argument.
259261
*/
260-
CDockWidget(const QString &title, QWidget* parent = nullptr);
262+
explicit CDockWidget(const QString &title, QWidget* parent = nullptr);
263+
264+
/**
265+
* Creates a dock widget and assigns the dock manager that manages this
266+
* widget.
267+
* This allows the dock widget to use the componentsFactory() of the dock
268+
* manager in the constructot to create its components.
269+
*/
270+
CDockWidget(CDockManager *manager, const QString &title, QWidget* parent = nullptr);
261271

262272
/**
263273
* Virtual Destructor

0 commit comments

Comments
 (0)