KDDockWidgets API Documentation 2.1
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 updateVisibility();
51
52 if (isVertical()) {
53 view()->setFixedWidth(30);
54 } else {
55 view()->setFixedHeight(30);
56 }
57
58 view()->init();
59}
60
62{
63 delete d;
64}
65
67{
68 if (!dw)
69 return;
70
71 if (m_dockWidgets.contains(dw)) {
72 KDDW_ERROR("Already contains dock widget with title={}", dw->title());
73 return;
74 }
75
76 KDBindings::ScopedConnection conn = dw->d->aboutToDelete.connect([this](auto dock) { removeDockWidget(dock); });
77 d->connections[dw] = std::move(conn);
78
79 m_dockWidgets.push_back(dw);
80 dynamic_cast<Core::SideBarViewInterface *>(view())->addDockWidget_Impl(dw);
81 updateVisibility();
82}
83
85{
86 if (!m_dockWidgets.contains(dw)) {
87 KDDW_ERROR("Doesn't contain dock widget with title={}", dw->title());
88 return;
89 }
90
91 d->removeConnection(dw);
92 m_dockWidgets.removeOne(dw);
93 dynamic_cast<Core::SideBarViewInterface *>(view())->removeDockWidget_Impl(dw);
94 dw->d->removedFromSideBar.emit();
95 updateVisibility();
96}
97
99{
100 return m_dockWidgets.contains(dw);
101}
102
107
108void SideBar::updateVisibility()
109{
111}
112
114{
115 return m_orientation;
116}
117
119{
120 return m_dockWidgets.isEmpty();
121}
122
124{
125 return m_location;
126}
127
129{
130 return m_mainWindow;
131}
132
134{
135 m_mainWindow->toggleOverlayOnSideBar(dw);
136}
137
139{
140 Vector<QString> ids;
141 ids.reserve(m_dockWidgets.size());
142 for (DockWidget *dw : m_dockWidgets)
143 ids.push_back(dw->uniqueName());
144
145 return ids;
146}
147
149{
150 for (DockWidget *dw : std::as_const(m_dockWidgets))
152}
153
155{
156 return m_dockWidgets;
157}
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