Skip to content

Commit ff1439c

Browse files
Added CDockComponentsFactory for creation of components for the docking framework
1 parent a4ef161 commit ff1439c

File tree

8 files changed

+146
-8
lines changed

8 files changed

+146
-8
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ set(ads_SRCS
4242
src/FloatingDockContainer.cpp
4343
src/FloatingDragPreview.cpp
4444
src/IconProvider.cpp
45+
src/DockComponentsFactory.cpp
4546
src/ads.qrc
4647
src/linux/FloatingWidgetTitleBar.cpp
4748
)
@@ -61,6 +62,7 @@ set(ads_INSTALL_INCLUDE
6162
src/FloatingDockContainer.h
6263
src/FloatingDragPreview.h
6364
src/IconProvider.h
65+
src/DockComponentsFactory.h
6466
src/linux/FloatingWidgetTitleBar.h
6567
)
6668
if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "4")

src/DockAreaTitleBar.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#include "DockWidgetTab.h"
5050
#include "DockAreaTabBar.h"
5151
#include "IconProvider.h"
52+
#include "DockComponentsFactory.h"
5253

5354
#include <iostream>
5455

@@ -273,7 +274,7 @@ void DockAreaTitleBarPrivate::createButtons()
273274
//============================================================================
274275
void DockAreaTitleBarPrivate::createTabBar()
275276
{
276-
TabBar = new CDockAreaTabBar(DockArea);
277+
TabBar = componentsFactory()->createDockAreaTabBar(DockArea);
277278
TabBar->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
278279
Layout->addWidget(TabBar);
279280
_this->connect(TabBar, SIGNAL(tabClosed(int)), SLOT(markTabsMenuOutdated()));

src/DockAreaWidget.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@
2828
//============================================================================
2929
// INCLUDES
3030
//============================================================================
31-
#include "DockWidgetTab.h"
3231
#include "DockAreaWidget.h"
3332

33+
#include <iostream>
34+
3435
#include <QStackedLayout>
3536
#include <QScrollBar>
3637
#include <QScrollArea>
@@ -53,8 +54,8 @@
5354
#include "DockAreaTabBar.h"
5455
#include "DockSplitter.h"
5556
#include "DockAreaTitleBar.h"
56-
57-
#include <iostream>
57+
#include "DockComponentsFactory.h"
58+
#include "DockWidgetTab.h"
5859

5960

6061
namespace ads
@@ -317,7 +318,7 @@ DockAreaWidgetPrivate::DockAreaWidgetPrivate(CDockAreaWidget* _public) :
317318
//============================================================================
318319
void DockAreaWidgetPrivate::createTitleBar()
319320
{
320-
TitleBar = new CDockAreaTitleBar(_this);
321+
TitleBar = componentsFactory()->createDockAreaTitleBar(_this);
321322
Layout->addWidget(TitleBar);
322323
QObject::connect(tabBar(), &CDockAreaTabBar::tabCloseRequested, _this, &CDockAreaWidget::onTabCloseRequested);
323324
QObject::connect(TitleBar, &CDockAreaTitleBar::tabBarClicked, _this, &CDockAreaWidget::setCurrentIndex);

src/DockComponentsFactory.cpp

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
//============================================================================
2+
/// \file DockComponentsFactory.cpp
3+
/// \author Uwe Kindler
4+
/// \date 10.02.2020
5+
/// \brief Implementation of DockComponentsFactory
6+
//============================================================================
7+
8+
//============================================================================
9+
// INCLUDES
10+
//============================================================================
11+
#include <DockComponentsFactory.h>
12+
#include <QScopedPointer>
13+
14+
#include "DockWidgetTab.h"
15+
#include "DockAreaTabBar.h"
16+
#include "DockAreaTitleBar.h"
17+
#include "DockWidget.h"
18+
#include "DockAreaWidget.h"
19+
20+
namespace ads
21+
{
22+
static QScopedPointer<CDockComponentsFactory> DefaultFactory(new CDockComponentsFactory());
23+
24+
25+
//============================================================================
26+
CDockWidgetTab* CDockComponentsFactory::createDockWidgetTab(CDockWidget* DockWidget) const
27+
{
28+
return new CDockWidgetTab(DockWidget);
29+
}
30+
31+
32+
//============================================================================
33+
CDockAreaTabBar* CDockComponentsFactory::createDockAreaTabBar(CDockAreaWidget* DockArea) const
34+
{
35+
return new CDockAreaTabBar(DockArea);
36+
}
37+
38+
39+
//============================================================================
40+
CDockAreaTitleBar* CDockComponentsFactory::createDockAreaTitleBar(CDockAreaWidget* DockArea) const
41+
{
42+
return new CDockAreaTitleBar(DockArea);
43+
}
44+
45+
46+
//============================================================================
47+
const CDockComponentsFactory* CDockComponentsFactory::defaultFactory()
48+
{
49+
return DefaultFactory.get();
50+
}
51+
52+
53+
//============================================================================
54+
void CDockComponentsFactory::setDefaultFactory(CDockComponentsFactory* Factory)
55+
{
56+
DefaultFactory.reset(Factory);
57+
}
58+
} // namespace ads
59+
60+
//---------------------------------------------------------------------------
61+
// EOF DockComponentsFactory.cpp

src/DockComponentsFactory.h

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#ifndef DockComponentsFactoryH
2+
#define DockComponentsFactoryH
3+
//============================================================================
4+
/// \file DockComponentsFactory.h
5+
/// \author Uwe Kindler
6+
/// \date 10.02.2020
7+
/// \brief Declaration of DockComponentsFactory
8+
//============================================================================
9+
10+
//============================================================================
11+
// INCLUDES
12+
//============================================================================
13+
namespace ads
14+
{
15+
class CDockWidgetTab;
16+
class CDockAreaTitleBar;
17+
class CDockAreaTabBar;
18+
class CDockAreaWidget;
19+
class CDockWidget;
20+
21+
22+
23+
/**
24+
* Factory for creation of certain GUI elements for the docking framework.
25+
* A default unique instance provided by CDockComponentsFactory is used for
26+
* creation of all supported components. To inject your custom components,
27+
* you can create your own derived dock components factory and register
28+
* it via setDefaultFactory() function.
29+
* \code
30+
* CDockComponentsFactory::setDefaultFactory(new MyComponentsFactory()));
31+
* \endcode
32+
*/
33+
class CDockComponentsFactory
34+
{
35+
public:
36+
/**
37+
* Force virtual destructor
38+
*/
39+
virtual ~CDockComponentsFactory() {}
40+
41+
virtual CDockWidgetTab* createDockWidgetTab(CDockWidget* DockWidget) const;
42+
virtual CDockAreaTabBar* createDockAreaTabBar(CDockAreaWidget* DockArea) const;
43+
virtual CDockAreaTitleBar* createDockAreaTitleBar(CDockAreaWidget* DockArea) const;
44+
45+
/**
46+
* Returns the default components factory
47+
*/
48+
static const CDockComponentsFactory* defaultFactory();
49+
50+
/**
51+
* Sets a new default factory for creation of GUI elements.
52+
* This function takes ownership of the given Factory.
53+
*/
54+
static void setDefaultFactory(CDockComponentsFactory* Factory);
55+
};
56+
57+
58+
/**
59+
* Convenience function to ease factory instance access
60+
*/
61+
inline const CDockComponentsFactory* componentsFactory()
62+
{
63+
return CDockComponentsFactory::defaultFactory();
64+
}
65+
66+
} // namespace ads
67+
68+
//---------------------------------------------------------------------------
69+
#endif // DockComponentsFactoryH

src/DockManager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class CDockWidgetTab;
5959
struct DockWidgetTabPrivate;
6060
struct DockAreaWidgetPrivate;
6161
class CIconProvider;
62+
class CDockComponentsFactory;
6263

6364
/**
6465
* The central dock manager that maintains the complete docking system.

src/DockWidget.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
#include "DockManager.h"
5555
#include "FloatingDockContainer.h"
5656
#include "DockSplitter.h"
57+
#include "DockComponentsFactory.h"
5758
#include "ads_globals.h"
5859

5960

@@ -220,7 +221,7 @@ CDockWidget::CDockWidget(const QString &title, QWidget *parent) :
220221
setWindowTitle(title);
221222
setObjectName(title);
222223

223-
d->TabWidget = new CDockWidgetTab(this);
224+
d->TabWidget = componentsFactory()->createDockWidgetTab(this);
224225
d->ToggleViewAction = new QAction(title, this);
225226
d->ToggleViewAction->setCheckable(true);
226227
connect(d->ToggleViewAction, SIGNAL(triggered(bool)), this,

src/src.pro

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ HEADERS += \
4343
DockSplitter.h \
4444
DockAreaTitleBar.h \
4545
ElidingLabel.h \
46-
IconProvider.h
46+
IconProvider.h \
47+
DockComponentsFactory.h
4748

4849

4950
SOURCES += \
@@ -61,7 +62,8 @@ SOURCES += \
6162
DockSplitter.cpp \
6263
DockAreaTitleBar.cpp \
6364
ElidingLabel.cpp \
64-
IconProvider.cpp
65+
IconProvider.cpp \
66+
DockComponentsFactory.cpp
6567

6668

6769
unix {

0 commit comments

Comments
 (0)