KDDockWidgets API Documentation 2.0
Loading...
Searching...
No Matches
core/SideBar.cpp
Go to the documentation of this file.
1/*
2 This file is part of KDDockWidgets.
3
4 SPDX-FileCopyrightText: 2019 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
5 Author: SĂ©rgio Martins <sergio.martins@kdab.com>
6
7 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
8
9 Contact KDAB at <info@kdab.com> for commercial licensing options.
10*/
11
12#include "SideBar.h"
13#include "DockWidget_p.h"
14#include "MainWindow.h"
15#include "core/ViewFactory.h"
16#include "core/Logging_p.h"
18#include "Config.h"
19
20#include <unordered_map>
21#include <utility>
22
23using namespace KDDockWidgets;
24using namespace KDDockWidgets::Core;
25
26class SideBar::Private
27{
28public:
29 void removeConnection(DockWidget *dw)
30 {
31 auto it = connections.find(dw);
32 if (it == connections.end()) {
33 KDDW_ERROR("Could not find DockWidget to remove in side bar connections");
34 } else {
35 connections.erase(it);
36 }
37 }
38 std::unordered_map<DockWidget *, KDBindings::ScopedConnection> connections;
39};
40
42 : Controller(ViewType::SideBar, Config::self().viewFactory()->createSideBar(this, parent->view()))
43 , d(new Private())
44 , m_mainWindow(parent)
45 , m_location(location)
46 , m_orientation((location == SideBarLocation::North || location == SideBarLocation::South)
47 ? Qt::Horizontal
48 : Qt::Vertical)
49{
50 updateSize();
51 view()->init();
52}
53
55{
56 delete d;
57}
58
60{
61 if (!dw)
62 return;
63
64 if (m_dockWidgets.contains(dw)) {
65 KDDW_ERROR("Already contains dock widget with title={}", dw->title());
66 return;
67 }
68
69 KDBindings::ScopedConnection conn = dw->d->aboutToDelete.connect([this](auto dock) { removeDockWidget(dock); });
70 d->connections[dw] = std::move(conn);
71
72 m_dockWidgets.push_back(dw);
73 dynamic_cast<Core::SideBarViewInterface *>(view())->addDockWidget_Impl(dw);
74 updateSize();
75}
76
78{
79 if (!m_dockWidgets.contains(dw)) {
80 KDDW_ERROR("Doesn't contain dock widget with title={}", dw->title());
81 return;
82 }
83
84 d->removeConnection(dw);
85 m_dockWidgets.removeOne(dw);
86 dynamic_cast<Core::SideBarViewInterface *>(view())->removeDockWidget_Impl(dw);
87 dw->d->removedFromSideBar.emit();
88 updateSize();
89}
90
92{
93 return m_dockWidgets.contains(dw);
94}
95
100
101void SideBar::updateSize()
102{
103 const int thickness = isEmpty() ? 0 : 30;
104 if (isVertical()) {
105 view()->setFixedWidth(thickness);
106 } else {
107 view()->setFixedHeight(thickness);
108 }
109}
110
112{
113 return m_orientation;
114}
115
117{
118 return m_dockWidgets.isEmpty();
119}
120
122{
123 return m_location;
124}
125
127{
128 return m_mainWindow;
129}
130
132{
133 m_mainWindow->toggleOverlayOnSideBar(dw);
134}
135
137{
138 Vector<QString> ids;
139 ids.reserve(m_dockWidgets.size());
140 for (DockWidget *dw : m_dockWidgets)
141 ids.push_back(dw->uniqueName());
142
143 return ids;
144}
145
147{
148 for (DockWidget *dw : std::as_const(m_dockWidgets))
150}
151
153{
154 return m_dockWidgets;
155}
Application-wide config to tune certain behaviours of the framework.
A ScopedConnection is a RAII-style way to make sure a Connection is disconnected.
Definition signal.h:533
Singleton to allow to choose certain behaviours of the framework.
Definition Config.h:64
View * view() const
Returns the view associated with this controller, if any.
The DockWidget base-class. DockWidget and Core::DockWidget are only split in two so we can share some...
QString uniqueName() const
the dock widget's unique name.
QString title() const
Returns the dock widget's title. This title is visible in title bars and tab bars.
The MainWindow base-class. MainWindow and MainWindowBase are only split in two so we can share some c...
void toggleOverlayOnSideBar(KDDockWidgets::Core::DockWidget *dw)
Shows or hides an overlay. It's assumed the dock widget is already in a side-bar.
The interface that SideBar views should implement.
Vector< QString > serialize() const
returns a serialization of this sidebar's state Currently it's just a list of dock widget ids
Vector< DockWidget * > dockWidgets() const
returns the list of dock widgets in this sidebar
void clear()
clears the sidebar (removes all dock widgets from it)
MainWindow * mainWindow() const
Returns the main window this side bar belongs to.
void removeDockWidget(DockWidget *dw)
bool isVertical() const
returns if this side bar has vertical orientation
SideBarLocation location() const
returns the sidebar's location in the main window
void toggleOverlay(DockWidget *)
Toggles the dock widget overlay. Equivalent to the user clicking on the button.
bool containsDockWidget(DockWidget *) const
SideBar(SideBarLocation, MainWindow *parent=nullptr)
Qt::Orientation orientation() const
Returns this side bar's orientation.
void onButtonClicked(DockWidget *dw)
void addDockWidget(DockWidget *dw)
bool isEmpty() const
returns whether there's no dock widgets
virtual void setFixedWidth(int)=0
virtual void setFixedHeight(int)=0
ViewType
Each View type also has a specific Controller associated with, except for ViewType::None.
Definition Controller.h:26
Class to abstract QAction, so code still works with QtQuick and Flutter.
SideBarLocation
Each main window supports 4 sidebars.
Orientation
QMainWindow sub-class to enable KDDockWidgets support.

© Klarälvdalens Datakonsult AB (KDAB)
"The Qt, C++ and OpenGL Experts"
https://www.kdab.com/
KDDockWidgets
Advanced Dock Widget Framework for Qt
https://www.kdab.com/development-resources/qt-tools/kddockwidgets/
Generated by doxygen 1.9.8