Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qsimpleresource.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
"qsimpleresource_p.h"
6
#
include
"widgetfactory_p.h"
7
#
include
"widgetdatabase_p.h"
8
#
include
<
qdesigner_utils_p
.
h
>
9
10
#
include
<
QtDesigner
/
private
/
properties_p
.
h
>
11
#
include
<
QtDesigner
/
private
/
ui4_p
.
h
>
12
13
#
include
<
QtDesigner
/
abstractformeditor
.
h
>
14
#
include
<
QtDesigner
/
abstractlanguage
.
h
>
15
#
include
<
QtDesigner
/
qextensionmanager
.
h
>
16
#
include
<
QtDesigner
/
extrainfo
.
h
>
17
18
#
include
<
QtUiPlugin
/
customwidget
.
h
>
19
20
#
include
<
QtWidgets
/
qwidget
.
h
>
21
22
#
include
<
QtGui
/
qaction
.
h
>
23
#
include
<
QtGui
/
qicon
.
h
>
24
25
#
include
<
QtCore
/
qdebug
.
h
>
26
#
include
<
QtCore
/
qcoreapplication
.
h
>
27
28
QT_BEGIN_NAMESPACE
29
30
using
namespace
Qt::StringLiterals;
31
32
namespace
qdesigner_internal
{
33
34
bool
QSimpleResource
::
m_warningsEnabled
=
true
;
35
36
QSimpleResource
::
QSimpleResource
(
QDesignerFormEditorInterface
*
core
) :
37
QAbstractFormBuilder
(),
38
m_core
(
core
)
39
{
40
setWorkingDirectory
(
QDir
(
dataDirectory
()));
41
}
42
43
QSimpleResource
::~
QSimpleResource
() =
default
;
44
45
QBrush
QSimpleResource
::
setupBrush
(
DomBrush
*
brush
)
46
{
47
return
QAbstractFormBuilder
::
setupBrush
(
brush
);
48
}
49
50
DomBrush
*
QSimpleResource
::
saveBrush
(
const
QBrush
&
brush
)
51
{
52
return
QAbstractFormBuilder
::
saveBrush
(
brush
);
53
}
54
55
void
QSimpleResource
::
addExtensionDataToDOM
(
QAbstractFormBuilder
*
/* afb */
,
56
QDesignerFormEditorInterface
*
core
,
57
DomWidget
*
ui_widget
,
QWidget
*
widget
)
58
{
59
QExtensionManager
*
emgr
=
core
->
extensionManager
();
60
if
(
QDesignerExtraInfoExtension
*
extra
=
qt_extension
<
QDesignerExtraInfoExtension
*>(
emgr
,
widget
)) {
61
extra
->
saveWidgetExtraInfo
(
ui_widget
);
62
}
63
}
64
65
void
QSimpleResource
::
applyExtensionDataFromDOM
(
QAbstractFormBuilder
*
/* afb */
,
66
QDesignerFormEditorInterface
*
core
,
67
DomWidget
*
ui_widget
,
QWidget
*
widget
)
68
{
69
QExtensionManager
*
emgr
=
core
->
extensionManager
();
70
if
(
QDesignerExtraInfoExtension
*
extra
=
qt_extension
<
QDesignerExtraInfoExtension
*>(
emgr
,
widget
)) {
71
extra
->
loadWidgetExtraInfo
(
ui_widget
);
72
}
73
}
74
75
QString
QSimpleResource
::
customWidgetScript
(
QDesignerFormEditorInterface
*
core
,
QObject
*
object
)
76
{
77
return
customWidgetScript
(
core
,
qdesigner_internal
::
WidgetFactory
::
classNameOf
(
core
,
object
));
78
}
79
80
bool
QSimpleResource
::
hasCustomWidgetScript
(
QDesignerFormEditorInterface
*,
QObject
*)
81
{
82
return
false
;
83
}
84
85
QString
QSimpleResource
::
customWidgetScript
(
QDesignerFormEditorInterface
*,
const
QString
&)
86
{
87
return
QString
();
88
}
89
90
// Custom widgets handling helpers
91
92
// Add unique fake slots and signals to lists
93
bool
QSimpleResource
::
addFakeMethods
(
const
DomSlots
*
domSlots
,
QStringList
&
fakeSlots
,
QStringList
&
fakeSignals
)
94
{
95
if
(!
domSlots
)
96
return
false
;
97
98
bool
rc
=
false
;
99
const
QStringList
&
elementSlots
=
domSlots
->
elementSlot
();
100
for
(
const
QString
&
fakeSlot
:
elementSlots
)
101
if
(
fakeSlots
.
indexOf
(
fakeSlot
) == -1) {
102
fakeSlots
+=
fakeSlot
;
103
rc
=
true
;
104
}
105
106
const
QStringList
&
elementSignals
=
domSlots
->
elementSignal
();
107
for
(
const
QString
&
fakeSignal
:
elementSignals
)
108
if
(
fakeSignals
.
indexOf
(
fakeSignal
) == -1) {
109
fakeSignals
+=
fakeSignal
;
110
rc
=
true
;
111
}
112
return
rc
;
113
}
114
115
void
QSimpleResource
::
addFakeMethodsToWidgetDataBase
(
const
DomCustomWidget
*
domCustomWidget
,
WidgetDataBaseItem
*
item
)
116
{
117
const
DomSlots
*
domSlots
=
domCustomWidget
->
elementSlots
();
118
if
(!
domSlots
)
119
return
;
120
121
// Merge in new slots, signals
122
QStringList
fakeSlots
=
item
->
fakeSlots
();
123
QStringList
fakeSignals
=
item
->
fakeSignals
();
124
if
(
addFakeMethods
(
domSlots
,
fakeSlots
,
fakeSignals
)) {
125
item
->
setFakeSlots
(
fakeSlots
);
126
item
->
setFakeSignals
(
fakeSignals
);
127
}
128
}
129
130
// Perform one iteration of adding the custom widgets to the database,
131
// looking up the base class and inheriting its data.
132
// Remove the succeeded custom widgets from the list.
133
// Classes whose base class could not be found are left in the list.
134
135
void
QSimpleResource
::
addCustomWidgetsToWidgetDatabase
(
const
QDesignerFormEditorInterface
*
core
,
136
QList
<
DomCustomWidget
*> &
custom_widget_list
)
137
{
138
QDesignerWidgetDataBaseInterface
*
db
=
core
->
widgetDataBase
();
139
for
(
qsizetype
i
= 0;
i
<
custom_widget_list
.
size
(); ) {
140
bool
classInserted
=
false
;
141
DomCustomWidget
*
custom_widget
=
custom_widget_list
.
at
(
i
);
142
const
QString
customClassName
=
custom_widget
->
elementClass
();
143
const
QString
base_class
=
custom_widget
->
elementExtends
();
144
QString
includeFile
;
145
IncludeType
includeType
=
IncludeLocal
;
146
if
(
const
DomHeader
*
header
=
custom_widget
->
elementHeader
()) {
147
includeFile
=
header
->
text
();
148
if
(
header
->
hasAttributeLocation
() &&
header
->
attributeLocation
() ==
"global"_L1
)
149
includeType
=
IncludeGlobal
;
150
}
151
const
bool
domIsContainer
=
custom_widget
->
elementContainer
();
152
// Append a new item
153
if
(
base_class
.
isEmpty
()) {
154
WidgetDataBaseItem
*
item
=
new
WidgetDataBaseItem
(
customClassName
);
155
item
->
setPromoted
(
false
);
156
item
->
setGroup
(
QCoreApplication
::
translate
(
"Designer"
,
"Custom Widgets"
));
157
item
->
setIncludeFile
(
buildIncludeFile
(
includeFile
,
includeType
));
158
item
->
setContainer
(
domIsContainer
);
159
item
->
setCustom
(
true
);
160
addFakeMethodsToWidgetDataBase
(
custom_widget
,
item
);
161
db
->
append
(
item
);
162
custom_widget_list
.
removeAt
(
i
);
163
classInserted
=
true
;
164
}
else
{
165
// Create a new entry cloned from base class. Note that this will ignore existing
166
// classes, eg, plugin custom widgets.
167
QDesignerWidgetDataBaseItemInterface
*
item
=
168
appendDerived
(
db
,
customClassName
,
QCoreApplication
::
translate
(
"Designer"
,
"Promoted Widgets"
),
169
base_class
,
170
buildIncludeFile
(
includeFile
,
includeType
),
171
true
,
true
);
172
// Ok, base class found.
173
if
(
item
) {
174
// Hack to accommodate for old UI-files in which "container" is not set properly:
175
// Apply "container" from DOM only if true (else, eg classes from QFrame might not accept
176
// dropping child widgets on them as container=false). This also allows for
177
// QWidget-derived stacked pages.
178
if
(
domIsContainer
)
179
item
->
setContainer
(
domIsContainer
);
180
181
addFakeMethodsToWidgetDataBase
(
custom_widget
,
static_cast
<
WidgetDataBaseItem
*>(
item
));
182
custom_widget_list
.
removeAt
(
i
);
183
classInserted
=
true
;
184
}
185
}
186
// Skip failed item.
187
if
(!
classInserted
)
188
i
++;
189
}
190
191
}
192
193
void
QSimpleResource
::
handleDomCustomWidgets
(
const
QDesignerFormEditorInterface
*
core
,
194
const
DomCustomWidgets
*
dom_custom_widgets
)
195
{
196
if
(
dom_custom_widgets
==
nullptr
)
197
return
;
198
auto
custom_widget_list
=
dom_custom_widgets
->
elementCustomWidget
();
199
// Attempt to insert each item derived from its base class.
200
// This should at most require two iterations in the event that the classes are out of order
201
// (derived first, max depth: promoted custom plugin = 2)
202
for
(
int
iteration
= 0;
iteration
< 2;
iteration
++) {
203
addCustomWidgetsToWidgetDatabase
(
core
,
custom_widget_list
);
204
if
(
custom_widget_list
.
isEmpty
())
205
return
;
206
}
207
// Oops, there are classes left whose base class could not be found.
208
// Default them to QWidget with warnings.
209
const
QString
fallBackBaseClass
= u"QWidget"_s;
210
for
(
DomCustomWidget
*
custom_widget
:
std
::
as_const
(
custom_widget_list
)) {
211
const
QString
customClassName
=
custom_widget
->
elementClass
();
212
const
QString
base_class
=
custom_widget
->
elementExtends
();
213
qDebug
() <<
"** WARNING The base class "
<<
base_class
<<
" of the custom widget class "
<<
customClassName
214
<<
" could not be found. Defaulting to "
<<
fallBackBaseClass
<<
'.'
;
215
custom_widget
->
setElementExtends
(
fallBackBaseClass
);
216
}
217
// One more pass.
218
addCustomWidgetsToWidgetDatabase
(
core
,
custom_widget_list
);
219
}
220
221
// ------------ FormBuilderClipboard
222
223
FormBuilderClipboard
::
FormBuilderClipboard
(
QWidget
*
w
)
224
{
225
m_widgets
+=
w
;
226
}
227
228
bool
FormBuilderClipboard
::
empty
()
const
229
{
230
return
m_widgets
.
isEmpty
() &&
m_actions
.
isEmpty
();
231
}
232
}
233
234
QT_END_NAMESPACE
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qdesigner_internal
Auxiliary methods to store/retrieve settings.
Definition
buddyeditor.cpp:67
qttools
src
designer
src
lib
shared
qsimpleresource.cpp
Generated on
for Qt by
1.16.1