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