KParts

part.cpp
1/*
2 This file is part of the KDE project
3 SPDX-FileCopyrightText: 1999 Simon Hausmann <hausmann@kde.org>
4 SPDX-FileCopyrightText: 1999-2005 David Faure <faure@kde.org>
5
6 SPDX-License-Identifier: LGPL-2.0-or-later
7*/
8
9#include "part.h"
10#include "part_p.h"
11
12#include "kparts_logging.h"
13#include "partmanager.h"
14
15// The events have randomly generated numbers using `shuf -i1000-65535 -n 1`
16#include "guiactivateevent.h"
17#include "partactivateevent.h"
18
19#include <KXMLGUIFactory>
20
21using namespace KParts;
22
23Part::Part(QObject *parent, const KPluginMetaData &data)
24 : Part(*new PartPrivate(this, data), parent)
25{
26}
27
28Part::Part(PartPrivate &dd, QObject *parent)
29 : QObject(parent)
30 , PartBase(dd)
31{
32 Q_D(Part);
33
35 if (d->m_metaData.isValid()) {
36 KXMLGUIClient::setComponentName(d->m_metaData.pluginId(), d->m_metaData.name());
37 }
38}
39
41{
42 Q_D(Part);
43
44 // qCDebug(KPARTSLOG) << this;
45
46 if (d->m_widget) {
47 // We need to disconnect first, to avoid calling it !
48 disconnect(d->m_widget.data(), &QWidget::destroyed, this, &Part::slotWidgetDestroyed);
49 }
50
51 if (d->m_manager) {
52 d->m_manager->removePart(this);
53 }
54
55 if (d->m_widget && d->m_autoDeleteWidget) {
56 // qCDebug(KPARTSLOG) << "deleting widget" << d->m_widget << d->m_widget->objectName();
57 delete static_cast<QWidget *>(d->m_widget);
58 }
59}
60
62{
63 Q_D(Part);
64
65 return d->m_widget;
66}
67
68void Part::setAutoDeleteWidget(bool autoDeleteWidget)
69{
70 Q_D(Part);
71 d->m_autoDeleteWidget = autoDeleteWidget;
72}
73
74void Part::setAutoDeletePart(bool autoDeletePart)
75{
76 Q_D(Part);
77 d->m_autoDeletePart = autoDeletePart;
78}
79
81{
82 Q_D(const Part);
83
84 return d->m_metaData;
85}
86
88{
89 Q_D(Part);
90
91 d->m_manager = manager;
92}
93
95{
96 Q_D(const Part);
97
98 return d->m_manager;
99}
100
102{
103 Q_D(Part);
104
105 if ((QWidget *)d->m_widget != widget) {
106 return nullptr;
107 }
108
109 return this;
110}
111
113{
114 Q_D(Part);
115 d->m_widget = widget;
117}
118
120{
121 if (PartActivateEvent::test(ev)) {
122 partActivateEvent(static_cast<PartActivateEvent *>(ev));
123 return;
124 }
125
126 if (GUIActivateEvent::test(ev)) {
127 guiActivateEvent(static_cast<GUIActivateEvent *>(ev));
128 return;
129 }
130
132}
133
137
141
142QWidget *Part::hostContainer(const QString &containerName)
143{
144 if (!factory()) {
145 return nullptr;
146 }
147
148 return factory()->container(containerName, this);
149}
150
152{
153 Q_D(Part);
154
155 d->m_widget = nullptr;
156 if (d->m_autoDeletePart) {
157 // qCDebug(KPARTSLOG) << "deleting part" << objectName();
158 this->deleteLater();
159 }
160}
161
162#include "moc_part.cpp"
This event is sent to a Part when its GUI has been activated or deactivated.
This event is sent by the part manager when the active part changes.
Base class for all parts.
Definition partbase.h:35
void setPartObject(QObject *object)
Internal method.
Definition partbase.cpp:26
The part manager is an object which knows about a collection of parts (even nested ones) and handles ...
Definition partmanager.h:37
Base class for parts.
Definition part.h:57
virtual Part * hitTest(QWidget *widget, const QPoint &globalPos)
Returns the part (this, or a child part) at the given global position.
Definition part.cpp:101
virtual QWidget * widget()
Definition part.cpp:61
virtual void setWidget(QWidget *widget)
Set the main widget.
Definition part.cpp:112
void customEvent(QEvent *event) override
Definition part.cpp:119
virtual void setManager(PartManager *manager)
Definition part.cpp:87
QWidget * hostContainer(const QString &containerName)
Convenience method for KXMLGUIFactory::container.
Definition part.cpp:142
~Part() override
Destructor.
Definition part.cpp:40
void setAutoDeletePart(bool autoDeletePart)
By default, the part deletes itself when its widget is deleted.
Definition part.cpp:74
virtual void guiActivateEvent(GUIActivateEvent *event)
Convenience method which is called when the Part received a GUIActivateEvent .
Definition part.cpp:138
virtual void partActivateEvent(PartActivateEvent *event)
Convenience method which is called when the Part received a PartActivateEvent .
Definition part.cpp:134
void setAutoDeleteWidget(bool autoDeleteWidget)
By default, the widget is deleted by the part when the part is deleted.
Definition part.cpp:68
Part(QObject *parent=nullptr, const KPluginMetaData &data={})
Constructor.
Definition part.cpp:23
KPluginMetaData metaData() const
Definition part.cpp:80
void slotWidgetDestroyed()
Definition part.cpp:151
PartManager * manager() const
Returns the part manager handling this part, if any (0L otherwise).
Definition part.cpp:94
KXMLGUIFactory * factory() const
virtual void setComponentName(const QString &componentName, const QString &componentDisplayName)
QWidget * container(const QString &containerName, KXMLGUIClient *client, bool useTagName=false)
The KParts namespace,.
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
virtual void customEvent(QEvent *event)
void deleteLater()
void destroyed(QObject *obj)
bool disconnect(const QMetaObject::Connection &connection)
UniqueConnection
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:11:50 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.