Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
metadatabase.cpp
Go to the documentation of this file.
1
// Copyright (C) 2016 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3
// Qt-Security score:significant reason:default
4
5
#
include
"metadatabase_p.h"
6
#
include
"widgetdatabase_p.h"
7
8
// sdk
9
#
include
<
QtDesigner
/
abstractformeditor
.
h
>
10
11
// Qt
12
#
include
<
QtWidgets
/
qwidget
.
h
>
13
#
include
<
QtCore
/
qalgorithms
.
h
>
14
#
include
<
QtCore
/
qdebug
.
h
>
15
16
QT_BEGIN_NAMESPACE
17
18
namespace
{
19
const
bool
debugMetaDatabase
=
false
;
20
}
21
22
namespace
qdesigner_internal
{
23
24
MetaDataBaseItem
::
MetaDataBaseItem
(
QObject
*
object
)
25
:
m_object
(
object
),
26
m_enabled
(
true
)
27
{
28
}
29
30
MetaDataBaseItem
::~
MetaDataBaseItem
() =
default
;
31
32
QString
MetaDataBaseItem
::
name
()
const
33
{
34
Q_ASSERT
(
m_object
);
35
return
m_object
->
objectName
();
36
}
37
38
void
MetaDataBaseItem
::
setName
(
const
QString
&
name
)
39
{
40
Q_ASSERT
(
m_object
);
41
m_object
->
setObjectName
(
name
);
42
}
43
44
QString
MetaDataBaseItem
::
customClassName
()
const
45
{
46
return
m_customClassName
;
47
}
48
void
MetaDataBaseItem
::
setCustomClassName
(
const
QString
&
customClassName
)
49
{
50
m_customClassName
=
customClassName
;
51
}
52
53
54
QWidgetList
MetaDataBaseItem
::
tabOrder
()
const
55
{
56
return
m_tabOrder
;
57
}
58
59
void
MetaDataBaseItem
::
setTabOrder
(
const
QWidgetList
&
tabOrder
)
60
{
61
m_tabOrder
=
tabOrder
;
62
}
63
64
bool
MetaDataBaseItem
::
enabled
()
const
65
{
66
return
m_enabled
;
67
}
68
69
void
MetaDataBaseItem
::
setEnabled
(
bool
b
)
70
{
71
m_enabled
=
b
;
72
}
73
74
QStringList
MetaDataBaseItem
::
fakeSlots
()
const
75
{
76
return
m_fakeSlots
;
77
}
78
79
void
MetaDataBaseItem
::
setFakeSlots
(
const
QStringList
&
fs
)
80
{
81
m_fakeSlots
=
fs
;
82
}
83
84
QStringList
MetaDataBaseItem
::
fakeSignals
()
const
85
{
86
return
m_fakeSignals
;
87
}
88
89
void
MetaDataBaseItem
::
setFakeSignals
(
const
QStringList
&
fs
)
90
{
91
m_fakeSignals
=
fs
;
92
}
93
94
// -----------------------------------------------------
95
MetaDataBase
::
MetaDataBase
(
QDesignerFormEditorInterface
*
core
,
QObject
*
parent
)
96
:
QDesignerMetaDataBaseInterface
(
parent
),
97
m_core
(
core
)
98
{
99
}
100
101
MetaDataBase
::~
MetaDataBase
()
102
{
103
qDeleteAll
(
m_items
);
104
}
105
106
MetaDataBaseItem
*
MetaDataBase
::
metaDataBaseItem
(
QObject
*
object
)
const
107
{
108
MetaDataBaseItem
*
i
=
m_items
.
value
(
object
);
109
if
(
i
==
nullptr
|| !
i
->
enabled
())
110
return
nullptr
;
111
return
i
;
112
}
113
114
void
MetaDataBase
::
add
(
QObject
*
object
)
115
{
116
MetaDataBaseItem
*
item
=
m_items
.
value
(
object
);
117
if
(
item
!=
nullptr
) {
118
item
->
setEnabled
(
true
);
119
if
(
debugMetaDatabase
) {
120
qDebug
() <<
"MetaDataBase::add: Existing item for "
<<
object
->
metaObject
()->
className
() <<
item
->
name
();
121
}
122
return
;
123
}
124
125
item
=
new
MetaDataBaseItem
(
object
);
126
m_items
.
insert
(
object
,
item
);
127
if
(
debugMetaDatabase
) {
128
qDebug
() <<
"MetaDataBase::add: New item "
<<
object
->
metaObject
()->
className
() <<
item
->
name
();
129
}
130
connect
(
object
, &
QObject
::
destroyed
,
this
, &
MetaDataBase
::
slotDestroyed
);
131
132
emit
changed
();
133
}
134
135
void
MetaDataBase
::
remove
(
QObject
*
object
)
136
{
137
Q_ASSERT
(
object
);
138
139
if
(
MetaDataBaseItem
*
item
=
m_items
.
value
(
object
)) {
140
item
->
setEnabled
(
false
);
141
emit
changed
();
142
}
143
}
144
145
QObjectList
MetaDataBase
::
objects
()
const
146
{
147
QObjectList
result
;
148
149
for
(
auto
it
=
m_items
.
cbegin
(),
cend
=
m_items
.
cend
();
it
!=
cend
; ++
it
) {
150
if
(
it
.
value
()->
enabled
())
151
result
.
append
(
it
.
key
());
152
}
153
154
return
result
;
155
}
156
157
QDesignerFormEditorInterface
*
MetaDataBase
::
core
()
const
158
{
159
return
m_core
;
160
}
161
162
void
MetaDataBase
::
slotDestroyed
(
QObject
*
object
)
163
{
164
if
(
m_items
.
contains
(
object
)) {
165
MetaDataBaseItem
*
item
=
m_items
.
value
(
object
);
166
delete
item
;
167
m_items
.
remove
(
object
);
168
}
169
}
170
171
// promotion convenience
172
QDESIGNER_SHARED_EXPORT
bool
promoteWidget(QDesignerFormEditorInterface *core,QWidget *widget,
const
QString &customClassName)
173
{
174
175
MetaDataBase *db = qobject_cast<MetaDataBase *>(core->metaDataBase());
176
if
(!db)
177
return
false
;
178
MetaDataBaseItem *item = db->metaDataBaseItem(widget);
179
if
(!item) {
180
db ->add(widget);
181
item = db->metaDataBaseItem(widget);
182
}
183
// Recursive promotion occurs if there is a plugin missing.
184
const
QString oldCustomClassName = item->customClassName();
185
if
(!oldCustomClassName.isEmpty()) {
186
qDebug() <<
"WARNING: Recursive promotion of "
<< oldCustomClassName <<
" to "
<< customClassName
187
<<
". A plugin is missing."
;
188
}
189
item->setCustomClassName(customClassName);
190
if
(
debugMetaDatabase
) {
191
qDebug() <<
"Promoting "
<< widget->metaObject()->className() <<
" to "
<< customClassName;
192
}
193
return
true
;
194
}
195
196
QDESIGNER_SHARED_EXPORT
void
demoteWidget(QDesignerFormEditorInterface *core,QWidget *widget)
197
{
198
MetaDataBase *db = qobject_cast<MetaDataBase *>(core->metaDataBase());
199
if
(!db)
200
return
;
201
MetaDataBaseItem *item = db->metaDataBaseItem(widget);
202
item->setCustomClassName(QString());
203
if
(
debugMetaDatabase
) {
204
qDebug() <<
"Demoting "
<< widget;
205
}
206
}
207
208
QDESIGNER_SHARED_EXPORT
bool
isPromoted(QDesignerFormEditorInterface *core, QWidget* widget)
209
{
210
const
MetaDataBase *db = qobject_cast<
const
MetaDataBase *>(core->metaDataBase());
211
if
(!db)
212
return
false
;
213
const
MetaDataBaseItem *item = db->metaDataBaseItem(widget);
214
if
(!item)
215
return
false
;
216
return
!item->customClassName().isEmpty();
217
}
218
219
QDESIGNER_SHARED_EXPORT
QString
promotedCustomClassName
(
QDesignerFormEditorInterface
*
core
,
QWidget
*
widget
)
220
{
221
const
MetaDataBase
*
db
=
qobject_cast
<
const
MetaDataBase
*>(
core
->
metaDataBase
());
222
if
(!
db
)
223
return
QString
();
224
const
MetaDataBaseItem
*
item
=
db
->
metaDataBaseItem
(
widget
);
225
if
(!
item
)
226
return
QString
();
227
return
item
->
customClassName
();
228
}
229
230
QDESIGNER_SHARED_EXPORT
QString
promotedExtends
(
QDesignerFormEditorInterface
*
core
,
QWidget
*
widget
)
231
{
232
const
QString
customClassName
=
promotedCustomClassName
(
core
,
widget
);
233
if
(
customClassName
.
isEmpty
())
234
return
QString
();
235
const
int
i
=
core
->
widgetDataBase
()->
indexOfClassName
(
customClassName
);
236
if
(
i
== -1)
237
return
QString
();
238
return
core
->
widgetDataBase
()->
item
(
i
)->
extends
();
239
}
240
241
242
}
// namespace qdesigner_internal
243
244
QT_END_NAMESPACE
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
QT_BEGIN_NAMESPACE::debugMetaDatabase
const bool debugMetaDatabase
Definition
metadatabase.cpp:19
qdesigner_internal
Auxiliary methods to store/retrieve settings.
Definition
buddyeditor.cpp:67
QDESIGNER_SHARED_EXPORT
#define QDESIGNER_SHARED_EXPORT
Definition
shared_global_p.h:33
qttools
src
designer
src
lib
shared
metadatabase.cpp
Generated on
for Qt by
1.18.0