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
qdesigner_command.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
"qdesigner_command_p.h"
6
#
include
"qdesigner_propertycommand_p.h"
7
#
include
"qdesigner_utils_p.h"
8
#
include
"layout_p.h"
9
#
include
"qlayout_widget_p.h"
10
#
include
"qdesigner_widget_p.h"
11
#
include
"qdesigner_menu_p.h"
12
#
include
"shared_enums_p.h"
13
#
include
"metadatabase_p.h"
14
#
include
"formwindowbase_p.h"
15
#
include
<
abstractformbuilder
.
h
>
16
17
#
include
<
QtDesigner
/
abstractformwindow
.
h
>
18
#
include
<
QtDesigner
/
abstractformeditor
.
h
>
19
#
include
<
QtDesigner
/
propertysheet
.
h
>
20
#
include
<
QtDesigner
/
abstractactioneditor
.
h
>
21
#
include
<
QtDesigner
/
abstractpropertyeditor
.
h
>
22
#
include
<
QtDesigner
/
qextensionmanager
.
h
>
23
#
include
<
QtDesigner
/
container
.
h
>
24
#
include
<
QtDesigner
/
layoutdecoration
.
h
>
25
#
include
<
QtDesigner
/
abstractwidgetfactory
.
h
>
26
#
include
<
QtDesigner
/
abstractobjectinspector
.
h
>
27
#
include
<
QtDesigner
/
abstractintegration
.
h
>
28
#
include
<
QtDesigner
/
abstractformwindowcursor
.
h
>
29
#
include
<
QtCore
/
qdebug
.
h
>
30
#
include
<
QtCore
/
qtextstream
.
h
>
31
#
include
<
QtCore
/
qqueue
.
h
>
32
33
#
include
<
QtWidgets
/
qmenubar
.
h
>
34
#
include
<
QtWidgets
/
qstatusbar
.
h
>
35
#
include
<
QtWidgets
/
qtoolbar
.
h
>
36
#
include
<
QtWidgets
/
qtoolbox
.
h
>
37
#
include
<
QtWidgets
/
qstackedwidget
.
h
>
38
#
include
<
QtWidgets
/
qtabwidget
.
h
>
39
#
include
<
QtWidgets
/
qtablewidget
.
h
>
40
#
include
<
QtWidgets
/
qtreewidget
.
h
>
41
#
include
<
QtWidgets
/
qlistwidget
.
h
>
42
#
include
<
QtWidgets
/
qcombobox
.
h
>
43
#
include
<
QtWidgets
/
qsplitter
.
h
>
44
#
include
<
QtWidgets
/
qdockwidget
.
h
>
45
#
include
<
QtWidgets
/
qmainwindow
.
h
>
46
#
include
<
QtWidgets
/
qwizard
.
h
>
47
#
include
<
QtWidgets
/
qapplication
.
h
>
48
#
include
<
QtWidgets
/
qformlayout
.
h
>
49
50
#
include
<
algorithm
>
51
52
Q_DECLARE_METATYPE(QWidgetList)
53
54
QT_BEGIN_NAMESPACE
55
56
using
namespace
Qt::StringLiterals;
57
58
static
inline
void
setPropertySheetWindowTitle
(
const
QDesignerFormEditorInterface *core, QObject *o,
const
QString &t)
59
{
60
if
(
QDesignerPropertySheetExtension
*sheet = qt_extension<
QDesignerPropertySheetExtension
*>(core->extensionManager(), o)) {
61
const
int
idx = sheet->indexOf(u"windowTitle"_s);
62
if
(idx != -1) {
63
sheet->setProperty(idx, t);
64
sheet->setChanged(idx,
true
);
65
}
66
}
67
}
68
69
namespace
qdesigner_internal
{
70
71
// Helpers for the dynamic properties that store Z/Widget order
72
static
const
char
widgetOrderPropertyC
[] =
"_q_widgetOrder"
;
73
static
const
char
zOrderPropertyC
[] =
"_q_zOrder"
;
74
75
static
void
addToWidgetListDynamicProperty
(
QWidget
*parentWidget,
QWidget
*widget,
const
char
*name,
int
index = -1)
76
{
77
auto
list = qvariant_cast<QWidgetList>(parentWidget->property(name));
78
list.removeAll(widget);
79
if
(index >= 0 && index < list.size()) {
80
list.insert(index, widget);
81
}
else
{
82
list.append(widget);
83
}
84
parentWidget->setProperty(name, QVariant::fromValue(list));
85
}
86
87
static
int
removeFromWidgetListDynamicProperty
(
QWidget
*parentWidget,
QWidget
*widget,
const
char
*name)
88
{
89
auto
list = qvariant_cast<QWidgetList>(parentWidget->property(name));
90
const
auto
firstIndex = list.indexOf(widget);
91
if
(firstIndex != -1) {
92
list.removeAll(widget);
93
parentWidget->setProperty(name, QVariant::fromValue(list));
94
}
95
return
firstIndex;
96
}
97
98
// ---- InsertWidgetCommand ----
99
InsertWidgetCommand
::
InsertWidgetCommand
(
QDesignerFormWindowInterface
*
formWindow
) :
100
QDesignerFormWindowCommand
(
QString
(),
formWindow
),
101
m_insertMode
(
QDesignerLayoutDecorationExtension
::
InsertWidgetMode
),
102
m_layoutHelper
(
nullptr
),
103
m_widgetWasManaged
(
false
)
104
{
105
}
106
107
InsertWidgetCommand
::~
InsertWidgetCommand
()
108
{
109
delete
m_layoutHelper
;
110
}
111
112
void
InsertWidgetCommand
::
init
(
QWidget
*
widget
,
bool
already_in_form
,
int
layoutRow
,
int
layoutColumn
)
113
{
114
m_widget
=
widget
;
115
116
setText
(
QApplication
::
translate
(
"Command"
,
"Insert '%1'"
).
arg
(
widget
->
objectName
()));
117
118
QWidget
*
parentWidget
=
m_widget
->
parentWidget
();
119
QDesignerFormEditorInterface
*
core
=
formWindow
()->
core
();
120
QDesignerLayoutDecorationExtension
*
deco
=
qt_extension
<
QDesignerLayoutDecorationExtension
*>(
core
->
extensionManager
(),
parentWidget
);
121
122
m_insertMode
=
deco
?
deco
->
currentInsertMode
() :
QDesignerLayoutDecorationExtension
::
InsertWidgetMode
;
123
if
(
layoutRow
>= 0 &&
layoutColumn
>= 0) {
124
m_cell
.
first
=
layoutRow
;
125
m_cell
.
second
=
layoutColumn
;
126
}
else
{
127
m_cell
=
deco
?
deco
->
currentCell
() :
std
::
make_pair
(0, 0);
128
}
129
m_widgetWasManaged
=
already_in_form
;
130
}
131
132
static
void
recursiveUpdate
(
QWidget
*w)
133
{
134
w->update();
135
136
for
(
auto
*child : w->children()) {
137
if
(QWidget *w = qobject_cast<QWidget*>(child))
138
recursiveUpdate(w);
139
}
140
}
141
142
void
InsertWidgetCommand
::
redo
()
143
{
144
QWidget
*
parentWidget
=
m_widget
->
parentWidget
();
145
Q_ASSERT
(
parentWidget
);
146
147
addToWidgetListDynamicProperty
(
parentWidget
,
m_widget
,
widgetOrderPropertyC
);
148
addToWidgetListDynamicProperty
(
parentWidget
,
m_widget
,
zOrderPropertyC
);
149
150
QDesignerFormEditorInterface
*
core
=
formWindow
()->
core
();
151
QDesignerLayoutDecorationExtension
*
deco
=
qt_extension
<
QDesignerLayoutDecorationExtension
*>(
core
->
extensionManager
(),
parentWidget
);
152
153
if
(
deco
!=
nullptr
) {
154
const
LayoutInfo
::
Type
type
=
LayoutInfo
::
layoutType
(
core
,
LayoutInfo
::
managedLayout
(
core
,
parentWidget
));
155
m_layoutHelper
=
LayoutHelper
::
createLayoutHelper
(
type
);
156
m_layoutHelper
->
pushState
(
core
,
parentWidget
);
157
if
(
type
==
LayoutInfo
::
Grid
) {
158
switch
(
m_insertMode
) {
159
case
QDesignerLayoutDecorationExtension
::
InsertRowMode
: {
160
deco
->
insertRow
(
m_cell
.
first
);
161
}
break
;
162
163
case
QDesignerLayoutDecorationExtension
::
InsertColumnMode
: {
164
deco
->
insertColumn
(
m_cell
.
second
);
165
}
break
;
166
167
default
:
break
;
168
}
// end switch
169
}
170
deco
->
insertWidget
(
m_widget
,
m_cell
);
171
}
172
173
if
(!
m_widgetWasManaged
)
174
formWindow
()->
manageWidget
(
m_widget
);
175
m_widget
->
show
();
176
formWindow
()->
emitSelectionChanged
();
177
178
if
(
parentWidget
&&
parentWidget
->
layout
()) {
179
recursiveUpdate
(
parentWidget
);
180
parentWidget
->
layout
()->
invalidate
();
181
}
182
183
refreshBuddyLabels
();
184
}
185
186
void
InsertWidgetCommand
::
undo
()
187
{
188
QWidget
*
parentWidget
=
m_widget
->
parentWidget
();
189
190
QDesignerFormEditorInterface
*
core
=
formWindow
()->
core
();
191
QDesignerLayoutDecorationExtension
*
deco
=
qt_extension
<
QDesignerLayoutDecorationExtension
*>(
core
->
extensionManager
(),
parentWidget
);
192
193
if
(
deco
) {
194
deco
->
removeWidget
(
m_widget
);
195
m_layoutHelper
->
popState
(
core
,
parentWidget
);
196
}
197
198
if
(!
m_widgetWasManaged
) {
199
formWindow
()->
unmanageWidget
(
m_widget
);
200
m_widget
->
hide
();
201
}
202
203
removeFromWidgetListDynamicProperty
(
parentWidget
,
m_widget
,
widgetOrderPropertyC
);
204
removeFromWidgetListDynamicProperty
(
parentWidget
,
m_widget
,
zOrderPropertyC
);
205
206
formWindow
()->
emitSelectionChanged
();
207
208
refreshBuddyLabels
();
209
}
210
211
void
InsertWidgetCommand
::
refreshBuddyLabels
()
212
{
213
const
auto
label_list
=
formWindow
()->
findChildren
<
QLabel
*>();
214
if
(
label_list
.
isEmpty
())
215
return
;
216
217
const
QString
buddyProperty
= u"buddy"_s;
218
const
QByteArray
objectNameU8
=
m_widget
->
objectName
().
toUtf8
();
219
// Re-set the buddy (The sheet locates the object by name and sets it)
220
for
(
QLabel
*
label
:
label_list
) {
221
if
(
QDesignerPropertySheetExtension
*
sheet
=
propertySheet
(
label
)) {
222
const
int
idx
=
sheet
->
indexOf
(
buddyProperty
);
223
if
(
idx
!= -1) {
224
const
QVariant
value
=
sheet
->
property
(
idx
);
225
if
(
value
.
toByteArray
() ==
objectNameU8
)
226
sheet
->
setProperty
(
idx
,
value
);
227
}
228
}
229
}
230
}
231
232
// ---- ChangeZOrderCommand ----
233
ChangeZOrderCommand
::
ChangeZOrderCommand
(
QDesignerFormWindowInterface
*
formWindow
)
234
:
QDesignerFormWindowCommand
(
QString
(),
formWindow
)
235
{
236
}
237
238
void
ChangeZOrderCommand
::
init
(
QWidget
*
widget
)
239
{
240
Q_ASSERT
(
widget
);
241
242
m_widget
=
widget
;
243
244
setText
(
QApplication
::
translate
(
"Command"
,
"Change Z-order of '%1'"
).
arg
(
widget
->
objectName
()));
245
246
m_oldParentZOrder
=
qvariant_cast
<
QWidgetList
>(
widget
->
parentWidget
()->
property
(
"_q_zOrder"
));
247
const
qsizetype
index
=
m_oldParentZOrder
.
indexOf
(
m_widget
);
248
if
(
index
!= -1 &&
index
+ 1 <
m_oldParentZOrder
.
size
())
249
m_oldPreceding
=
m_oldParentZOrder
.
at
(
index
+ 1);
250
}
251
252
void
ChangeZOrderCommand
::
redo
()
253
{
254
m_widget
->
parentWidget
()->
setProperty
(
"_q_zOrder"
,
QVariant
::
fromValue
(
reorderWidget
(
m_oldParentZOrder
,
m_widget
)));
255
256
reorder
(
m_widget
);
257
}
258
259
void
ChangeZOrderCommand
::
undo
()
260
{
261
m_widget
->
parentWidget
()->
setProperty
(
"_q_zOrder"
,
QVariant
::
fromValue
(
m_oldParentZOrder
));
262
263
if
(
m_oldPreceding
)
264
m_widget
->
stackUnder
(
m_oldPreceding
);
265
else
266
m_widget
->
raise
();
267
}
268
269
// ---- RaiseWidgetCommand ----
270
RaiseWidgetCommand
::
RaiseWidgetCommand
(
QDesignerFormWindowInterface
*
formWindow
)
271
:
ChangeZOrderCommand
(
formWindow
)
272
{
273
}
274
275
void
RaiseWidgetCommand
::
init
(
QWidget
*
widget
)
276
{
277
ChangeZOrderCommand
::
init
(
widget
);
278
setText
(
QApplication
::
translate
(
"Command"
,
"Raise '%1'"
).
arg
(
widget
->
objectName
()));
279
}
280
281
QWidgetList
RaiseWidgetCommand
::
reorderWidget
(
const
QWidgetList
&
list
,
QWidget
*
widget
)
const
282
{
283
QWidgetList
l
=
list
;
284
l
.
removeAll
(
widget
);
285
l
.
append
(
widget
);
286
return
l
;
287
}
288
289
void
RaiseWidgetCommand
::
reorder
(
QWidget
*
widget
)
const
290
{
291
widget
->
raise
();
292
}
293
294
// ---- LowerWidgetCommand ----
295
LowerWidgetCommand
::
LowerWidgetCommand
(
QDesignerFormWindowInterface
*
formWindow
)
296
:
ChangeZOrderCommand
(
formWindow
)
297
{
298
}
299
300
QWidgetList
LowerWidgetCommand
::
reorderWidget
(
const
QWidgetList
&
list
,
QWidget
*
widget
)
const
301
{
302
QWidgetList
l
=
list
;
303
l
.
removeAll
(
widget
);
304
l
.
prepend
(
widget
);
305
return
l
;
306
}
307
308
void
LowerWidgetCommand
::
init
(
QWidget
*
widget
)
309
{
310
ChangeZOrderCommand
::
init
(
widget
);
311
setText
(
QApplication
::
translate
(
"Command"
,
"Lower '%1'"
).
arg
(
widget
->
objectName
()));
312
}
313
314
void
LowerWidgetCommand
::
reorder
(
QWidget
*
widget
)
const
315
{
316
widget
->
lower
();
317
}
318
319
// ---- ManageWidgetCommandHelper
320
ManageWidgetCommandHelper
::
ManageWidgetCommandHelper
() =
default
;
321
322
void
ManageWidgetCommandHelper
::
init
(
const
QDesignerFormWindowInterface
*
fw
,
QWidget
*
widget
)
323
{
324
m_widget
=
widget
;
325
m_managedChildren
.
clear
();
326
327
const
QWidgetList
children
=
m_widget
->
findChildren
<
QWidget
*>();
328
m_managedChildren
.
reserve
(
children
.
size
());
329
for
(
auto
*
w
:
children
) {
330
if
(
fw
->
isManaged
(
w
))
331
m_managedChildren
.
push_back
(
w
);
332
}
333
}
334
335
void
ManageWidgetCommandHelper
::
init
(
QWidget
*
widget
,
const
QWidgetList
&
managedChildren
)
336
{
337
m_widget
=
widget
;
338
m_managedChildren
=
managedChildren
;
339
}
340
341
void
ManageWidgetCommandHelper
::
manage
(
QDesignerFormWindowInterface
*
fw
)
342
{
343
// Manage the managed children after parent
344
fw
->
manageWidget
(
m_widget
);
345
for
(
auto
*
w
:
std
::
as_const
(
m_managedChildren
))
346
fw
->
manageWidget
(
w
);
347
}
348
349
void
ManageWidgetCommandHelper
::
unmanage
(
QDesignerFormWindowInterface
*
fw
)
350
{
351
// Unmanage the managed children first
352
for
(
auto
*
w
:
std
::
as_const
(
m_managedChildren
))
353
fw
->
unmanageWidget
(
w
);
354
fw
->
unmanageWidget
(
m_widget
);
355
}
356
357
// ---- DeleteWidgetCommand ----
358
DeleteWidgetCommand
::
DeleteWidgetCommand
(
QDesignerFormWindowInterface
*
formWindow
) :
359
QDesignerFormWindowCommand
(
QString
(),
formWindow
),
360
m_layoutType
(
LayoutInfo
::
NoLayout
),
361
m_layoutHelper
(
nullptr
),
362
m_flags
(0),
363
m_splitterIndex
(-1),
364
m_layoutSimplified
(
false
),
365
m_formItem
(
nullptr
),
366
m_tabOrderIndex
(-1),
367
m_widgetOrderIndex
(-1),
368
m_zOrderIndex
(-1)
369
{
370
}
371
372
DeleteWidgetCommand
::~
DeleteWidgetCommand
()
373
{
374
delete
m_layoutHelper
;
375
}
376
377
void
DeleteWidgetCommand
::
init
(
QWidget
*
widget
,
unsigned
flags
)
378
{
379
m_widget
=
widget
;
380
m_parentWidget
=
widget
->
parentWidget
();
381
m_geometry
=
widget
->
geometry
();
382
m_flags
=
flags
;
383
m_layoutType
=
LayoutInfo
::
NoLayout
;
384
m_splitterIndex
= -1;
385
bool
isManaged
=
false
;
// Check for a managed layout
386
QLayout
*
layout
=
nullptr
;
387
m_layoutType
=
LayoutInfo
::
laidoutWidgetType
(
formWindow
()->
core
(),
m_widget
, &
isManaged
, &
layout
);
388
if
(!
isManaged
)
389
m_layoutType
=
LayoutInfo
::
NoLayout
;
390
switch
(
m_layoutType
) {
391
case
LayoutInfo
::
HSplitter
:
392
case
LayoutInfo
::
VSplitter
: {
393
auto
*
splitter
=
qobject_cast
<
QSplitter
*>(
m_parentWidget
);
394
Q_ASSERT
(
splitter
);
395
m_splitterIndex
=
splitter
->
indexOf
(
widget
);
396
}
397
break
;
398
case
LayoutInfo
::
NoLayout
:
399
break
;
400
default
:
401
m_layoutHelper
=
LayoutHelper
::
createLayoutHelper
(
m_layoutType
);
402
m_layoutPosition
=
m_layoutHelper
->
itemInfo
(
layout
,
m_widget
);
403
break
;
404
}
405
406
m_formItem
=
formWindow
()->
core
()->
metaDataBase
()->
item
(
formWindow
());
407
m_tabOrderIndex
=
m_formItem
->
tabOrder
().
indexOf
(
widget
);
408
409
// Build the list of managed children
410
m_manageHelper
.
init
(
formWindow
(),
m_widget
);
411
412
setText
(
QApplication
::
translate
(
"Command"
,
"Delete '%1'"
).
arg
(
widget
->
objectName
()));
413
}
414
415
void
DeleteWidgetCommand
::
redo
()
416
{
417
formWindow
()->
clearSelection
();
418
QDesignerFormEditorInterface
*
core
=
formWindow
()->
core
();
419
420
if
(
QDesignerContainerExtension
*
c
=
qt_extension
<
QDesignerContainerExtension
*>(
core
->
extensionManager
(),
m_parentWidget
)) {
421
const
int
count
=
c
->
count
();
422
for
(
int
i
=0;
i
<
count
; ++
i
) {
423
if
(
c
->
widget
(
i
) ==
m_widget
) {
424
c
->
remove
(
i
);
425
return
;
426
}
427
}
428
}
429
430
m_widgetOrderIndex
=
removeFromWidgetListDynamicProperty
(
m_parentWidget
,
m_widget
,
widgetOrderPropertyC
);
431
m_zOrderIndex
=
removeFromWidgetListDynamicProperty
(
m_parentWidget
,
m_widget
,
zOrderPropertyC
);
432
433
if
(
QDesignerLayoutDecorationExtension
*
deco
=
qt_extension
<
QDesignerLayoutDecorationExtension
*>(
core
->
extensionManager
(),
m_parentWidget
))
434
deco
->
removeWidget
(
m_widget
);
435
436
if
(
m_layoutHelper
)
437
switch
(
m_layoutType
) {
438
case
LayoutInfo
::
NoLayout
:
439
case
LayoutInfo
::
HSplitter
:
440
case
LayoutInfo
::
VSplitter
:
441
break
;
442
default
:
443
// Attempt to simplify grids if a row/column becomes empty
444
m_layoutSimplified
= (
m_flags
&
DoNotSimplifyLayout
) ?
false
:
m_layoutHelper
->
canSimplify
(
core
,
m_parentWidget
,
m_layoutPosition
);
445
if
(
m_layoutSimplified
) {
446
m_layoutHelper
->
pushState
(
core
,
m_parentWidget
);
447
m_layoutHelper
->
simplify
(
core
,
m_parentWidget
,
m_layoutPosition
);
448
}
449
break
;
450
}
451
452
if
(!(
m_flags
&
DoNotUnmanage
))
453
m_manageHelper
.
unmanage
(
formWindow
());
454
455
m_widget
->
setParent
(
formWindow
());
456
m_widget
->
hide
();
457
458
if
(
m_tabOrderIndex
!= -1) {
459
QWidgetList
tab_order
=
m_formItem
->
tabOrder
();
460
tab_order
.
removeAt
(
m_tabOrderIndex
);
461
m_formItem
->
setTabOrder
(
tab_order
);
462
}
463
}
464
465
void
DeleteWidgetCommand
::
undo
()
466
{
467
QDesignerFormEditorInterface
*
core
=
formWindow
()->
core
();
468
formWindow
()->
clearSelection
();
469
470
m_widget
->
setParent
(
m_parentWidget
);
471
472
if
(
QDesignerContainerExtension
*
c
=
qt_extension
<
QDesignerContainerExtension
*>(
core
->
extensionManager
(),
m_parentWidget
)) {
473
c
->
addWidget
(
m_widget
);
474
return
;
475
}
476
477
addToWidgetListDynamicProperty
(
m_parentWidget
,
m_widget
,
widgetOrderPropertyC
,
m_widgetOrderIndex
);
478
addToWidgetListDynamicProperty
(
m_parentWidget
,
m_widget
,
zOrderPropertyC
,
m_zOrderIndex
);
479
480
m_widget
->
setGeometry
(
m_geometry
);
481
482
if
(!(
m_flags
&
DoNotUnmanage
))
483
m_manageHelper
.
manage
(
formWindow
());
484
// ### set up alignment
485
switch
(
m_layoutType
) {
486
case
LayoutInfo
::
NoLayout
:
487
break
;
488
case
LayoutInfo
::
HSplitter
:
489
case
LayoutInfo
::
VSplitter
: {
490
auto
*
splitter
=
qobject_cast
<
QSplitter
*>(
m_widget
->
parent
());
491
Q_ASSERT
(
splitter
);
492
splitter
->
insertWidget
(
m_splitterIndex
,
m_widget
);
493
}
break
;
494
default
: {
495
Q_ASSERT
(
m_layoutHelper
);
496
if
(
m_layoutSimplified
)
497
m_layoutHelper
->
popState
(
core
,
m_parentWidget
);
498
QLayout
*
layout
=
LayoutInfo
::
managedLayout
(
core
,
m_parentWidget
);
499
Q_ASSERT
(
m_layoutType
==
LayoutInfo
::
layoutType
(
core
,
layout
));
500
m_layoutHelper
->
insertWidget
(
layout
,
m_layoutPosition
,
m_widget
);
501
}
502
break
;
503
}
504
505
m_widget
->
show
();
506
507
if
(
m_tabOrderIndex
!= -1) {
508
QWidgetList
tab_order
=
m_formItem
->
tabOrder
();
509
tab_order
.
insert
(
m_tabOrderIndex
,
m_widget
);
510
m_formItem
->
setTabOrder
(
tab_order
);
511
}
512
}
513
514
// ---- ReparentWidgetCommand ----
515
ReparentWidgetCommand
::
ReparentWidgetCommand
(
QDesignerFormWindowInterface
*
formWindow
)
516
:
QDesignerFormWindowCommand
(
QString
(),
formWindow
)
517
{
518
}
519
520
void
ReparentWidgetCommand
::
init
(
QWidget
*
widget
,
QWidget
*
parentWidget
)
521
{
522
Q_ASSERT
(
widget
);
523
524
m_widget
=
widget
;
525
m_oldParentWidget
=
widget
->
parentWidget
();
526
m_newParentWidget
=
parentWidget
;
527
528
m_oldPos
=
m_widget
->
pos
();
529
m_newPos
=
m_newParentWidget
->
mapFromGlobal
(
m_oldParentWidget
->
mapToGlobal
(
m_oldPos
));
530
531
setText
(
QApplication
::
translate
(
"Command"
,
"Reparent '%1'"
).
arg
(
widget
->
objectName
()));
532
533
m_oldParentList
=
qvariant_cast
<
QWidgetList
>(
m_oldParentWidget
->
property
(
"_q_widgetOrder"
));
534
m_oldParentZOrder
=
qvariant_cast
<
QWidgetList
>(
m_oldParentWidget
->
property
(
"_q_zOrder"
));
535
}
536
537
void
ReparentWidgetCommand
::
redo
()
538
{
539
m_widget
->
setParent
(
m_newParentWidget
);
540
m_widget
->
move
(
m_newPos
);
541
542
QWidgetList
oldList
=
m_oldParentList
;
543
oldList
.
removeAll
(
m_widget
);
544
m_oldParentWidget
->
setProperty
(
"_q_widgetOrder"
,
QVariant
::
fromValue
(
oldList
));
545
546
auto
newList
=
qvariant_cast
<
QWidgetList
>(
m_newParentWidget
->
property
(
"_q_widgetOrder"
));
547
newList
.
append
(
m_widget
);
548
m_newParentWidget
->
setProperty
(
"_q_widgetOrder"
,
QVariant
::
fromValue
(
newList
));
549
550
QWidgetList
oldZOrder
=
m_oldParentZOrder
;
551
oldZOrder
.
removeAll
(
m_widget
);
552
m_oldParentWidget
->
setProperty
(
"_q_zOrder"
,
QVariant
::
fromValue
(
oldZOrder
));
553
554
auto
newZOrder
=
qvariant_cast
<
QWidgetList
>(
m_newParentWidget
->
property
(
"_q_zOrder"
));
555
newZOrder
.
append
(
m_widget
);
556
m_newParentWidget
->
setProperty
(
"_q_zOrder"
,
QVariant
::
fromValue
(
newZOrder
));
557
558
m_widget
->
show
();
559
core
()->
objectInspector
()->
setFormWindow
(
formWindow
());
560
}
561
562
void
ReparentWidgetCommand
::
undo
()
563
{
564
m_widget
->
setParent
(
m_oldParentWidget
);
565
m_widget
->
move
(
m_oldPos
);
566
567
m_oldParentWidget
->
setProperty
(
"_q_widgetOrder"
,
QVariant
::
fromValue
(
m_oldParentList
));
568
569
auto
newList
=
qvariant_cast
<
QWidgetList
>(
m_newParentWidget
->
property
(
"_q_widgetOrder"
));
570
newList
.
removeAll
(
m_widget
);
571
m_newParentWidget
->
setProperty
(
"_q_widgetOrder"
,
QVariant
::
fromValue
(
newList
));
572
573
m_oldParentWidget
->
setProperty
(
"_q_zOrder"
,
QVariant
::
fromValue
(
m_oldParentZOrder
));
574
575
auto
newZOrder
=
qvariant_cast
<
QWidgetList
>(
m_newParentWidget
->
property
(
"_q_zOrder"
));
576
newZOrder
.
removeAll
(
m_widget
);
577
m_newParentWidget
->
setProperty
(
"_q_zOrder"
,
QVariant
::
fromValue
(
newZOrder
));
578
579
m_widget
->
show
();
580
core
()->
objectInspector
()->
setFormWindow
(
formWindow
());
581
}
582
583
PromoteToCustomWidgetCommand
::
PromoteToCustomWidgetCommand
584
(
QDesignerFormWindowInterface
*
formWindow
)
585
:
QDesignerFormWindowCommand
(
QApplication
::
translate
(
"Command"
,
"Promote to custom widget"
),
formWindow
)
586
{
587
}
588
589
void
PromoteToCustomWidgetCommand
::
init
(
const
WidgetPointerList
&
widgets
,
const
QString
&
customClassName
)
590
{
591
m_widgets
=
widgets
;
592
m_customClassName
=
customClassName
;
593
}
594
595
void
PromoteToCustomWidgetCommand
::
redo
()
596
{
597
for
(
QWidget
*
w
:
std
::
as_const
(
m_widgets
)) {
598
if
(
w
)
599
promoteWidget
(
core
(),
w
,
m_customClassName
);
600
}
601
updateSelection
();
602
}
603
604
void
PromoteToCustomWidgetCommand
::
updateSelection
()
605
{
606
// Update class names in ObjectInspector, PropertyEditor
607
QDesignerFormWindowInterface
*
fw
=
formWindow
();
608
QDesignerFormEditorInterface
*
core
=
fw
->
core
();
609
core
->
objectInspector
()->
setFormWindow
(
fw
);
610
if
(
QObject
*
o
=
core
->
propertyEditor
()->
object
())
611
core
->
propertyEditor
()->
setObject
(
o
);
612
}
613
614
void
PromoteToCustomWidgetCommand
::
undo
()
615
{
616
for
(
QWidget
*
w
:
std
::
as_const
(
m_widgets
)) {
617
if
(
w
)
618
demoteWidget
(
core
(),
w
);
619
}
620
updateSelection
();
621
}
622
623
// ---- DemoteFromCustomWidgetCommand ----
624
625
DemoteFromCustomWidgetCommand
::
DemoteFromCustomWidgetCommand
626
(
QDesignerFormWindowInterface
*
formWindow
) :
627
QDesignerFormWindowCommand
(
QApplication
::
translate
(
"Command"
,
"Demote from custom widget"
),
formWindow
),
628
m_promote_cmd
(
formWindow
)
629
{
630
}
631
632
void
DemoteFromCustomWidgetCommand
::
init
(
const
WidgetList
&
promoted
)
633
{
634
m_promote_cmd
.
init
(
promoted
,
promotedCustomClassName
(
core
(),
promoted
.
constFirst
()));
635
}
636
637
void
DemoteFromCustomWidgetCommand
::
redo
()
638
{
639
m_promote_cmd
.
undo
();
640
}
641
642
void
DemoteFromCustomWidgetCommand
::
undo
()
643
{
644
m_promote_cmd
.
redo
();
645
}
646
647
// ---------- CursorSelectionState
648
CursorSelectionState
::
CursorSelectionState
() =
default
;
649
650
void
CursorSelectionState
::
save
(
const
QDesignerFormWindowInterface
*
formWindow
)
651
{
652
const
QDesignerFormWindowCursorInterface
*
cursor
=
formWindow
->
cursor
();
653
m_selection
.
clear
();
654
m_current
=
cursor
->
current
();
655
if
(
cursor
->
hasSelection
()) {
656
const
int
count
=
cursor
->
selectedWidgetCount
();
657
for
(
int
i
= 0;
i
<
count
;
i
++)
658
m_selection
.
push_back
(
cursor
->
selectedWidget
(
i
));
659
}
660
}
661
662
void
CursorSelectionState
::
restore
(
QDesignerFormWindowInterface
*
formWindow
)
const
663
{
664
if
(
m_selection
.
isEmpty
()) {
665
formWindow
->
clearSelection
(
true
);
666
}
else
{
667
// Select current as last
668
formWindow
->
clearSelection
(
false
);
669
for
(
const
auto
&
wp
:
m_selection
) {
670
if
(!
wp
.
isNull
() &&
wp
.
data
() !=
m_current
)
671
formWindow
->
selectWidget
(
wp
.
data
(),
true
);
672
}
673
if
(
m_current
)
674
formWindow
->
selectWidget
(
m_current
,
true
);
675
}
676
}
677
678
// ---- LayoutCommand ----
679
680
LayoutCommand
::
LayoutCommand
(
QDesignerFormWindowInterface
*
formWindow
) :
681
QDesignerFormWindowCommand
(
QString
(),
formWindow
),
682
m_setup
(
false
)
683
{
684
}
685
686
LayoutCommand
::~
LayoutCommand
()
687
{
688
delete
m_layout
;
689
}
690
691
void
LayoutCommand
::
init
(
QWidget
*
parentWidget
,
const
QWidgetList
&
widgets
,
692
LayoutInfo
::
Type
layoutType
,
QWidget
*
layoutBase
,
693
bool
reparentLayoutWidget
)
694
{
695
m_parentWidget
=
parentWidget
;
696
m_widgets
=
widgets
;
697
formWindow
()->
simplifySelection
(&
m_widgets
);
698
m_layout
=
Layout
::
createLayout
(
widgets
,
parentWidget
,
formWindow
(),
layoutBase
,
layoutType
);
699
m_layout
->
setReparentLayoutWidget
(
reparentLayoutWidget
);
700
701
switch
(
layoutType
) {
702
case
LayoutInfo
::
Grid
:
703
setText
(
QApplication
::
translate
(
"Command"
,
"Lay out using grid"
));
704
break
;
705
case
LayoutInfo
::
VBox
:
706
setText
(
QApplication
::
translate
(
"Command"
,
"Lay out vertically"
));
707
break
;
708
case
LayoutInfo
::
HBox
:
709
setText
(
QApplication
::
translate
(
"Command"
,
"Lay out horizontally"
));
710
break
;
711
default
:
712
break
;
713
}
714
// Delayed setup to avoid confusion in case we are chained
715
// with a BreakLayout in a morph layout macro
716
m_setup
=
false
;
717
}
718
719
void
LayoutCommand
::
redo
()
720
{
721
if
(!
m_setup
) {
722
m_layout
->
setup
();
723
m_cursorSelectionState
.
save
(
formWindow
());
724
m_setup
=
true
;
725
}
726
m_layout
->
doLayout
();
727
core
()->
objectInspector
()->
setFormWindow
(
formWindow
());
728
}
729
730
void
LayoutCommand
::
undo
()
731
{
732
QDesignerFormEditorInterface
*
core
=
formWindow
()->
core
();
733
734
QWidget
*
lb
=
m_layout
->
layoutBaseWidget
();
735
auto
*
deco
=
qt_extension
<
QDesignerLayoutDecorationExtension
*>(
core
->
extensionManager
(),
lb
);
736
m_layout
->
undoLayout
();
737
delete
deco
;
// release the extension
738
739
// ### generalize (put in function)
740
if
(!
m_layoutBase
&&
lb
!=
nullptr
&& !(
qobject_cast
<
QLayoutWidget
*>(
lb
) ||
qobject_cast
<
QSplitter
*>(
lb
))) {
741
core
->
metaDataBase
()->
add
(
lb
);
742
lb
->
show
();
743
}
744
m_cursorSelectionState
.
restore
(
formWindow
());
745
core
->
objectInspector
()->
setFormWindow
(
formWindow
());
746
}
747
748
// ---- BreakLayoutCommand ----
749
BreakLayoutCommand
::
BreakLayoutCommand
(
QDesignerFormWindowInterface
*
formWindow
) :
750
QDesignerFormWindowCommand
(
QApplication
::
translate
(
"Command"
,
"Break layout"
),
formWindow
),
751
m_layoutHelper
(
nullptr
),
752
m_properties
(
nullptr
),
753
m_propertyMask
(0)
754
{
755
}
756
757
BreakLayoutCommand
::~
BreakLayoutCommand
()
758
{
759
delete
m_layoutHelper
;
760
delete
m_layout
;
761
delete
m_properties
;
762
}
763
764
const
LayoutProperties
*
BreakLayoutCommand
::
layoutProperties
()
const
765
{
766
return
m_properties
;
767
}
768
769
int
BreakLayoutCommand
::
propertyMask
()
const
770
{
771
return
m_propertyMask
;
772
}
773
774
void
BreakLayoutCommand
::
init
(
const
QWidgetList
&
widgets
,
QWidget
*
layoutBase
,
bool
reparentLayoutWidget
)
775
{
776
enum
Type
{
SplitterLayout
,
LayoutHasMarginSpacing
,
LayoutHasState
};
777
778
const
QDesignerFormEditorInterface
*
core
=
formWindow
()->
core
();
779
m_widgets
=
widgets
;
780
m_layoutBase
=
core
->
widgetFactory
()->
containerOfWidget
(
layoutBase
);
781
QLayout
*
layoutToBeBroken
=
nullptr
;
782
const
LayoutInfo
::
Type
layoutType
=
LayoutInfo
::
managedLayoutType
(
core
,
m_layoutBase
, &
layoutToBeBroken
);
783
m_layout
=
Layout
::
createLayout
(
widgets
,
m_layoutBase
,
formWindow
(),
layoutBase
,
layoutType
);
784
m_layout
->
setReparentLayoutWidget
(
reparentLayoutWidget
);
785
786
Type
type
=
LayoutHasState
;
787
switch
(
layoutType
) {
788
case
LayoutInfo
::
NoLayout
:
789
case
LayoutInfo
::
HSplitter
:
790
case
LayoutInfo
::
VSplitter
:
791
type
=
SplitterLayout
;
792
break
;
793
case
LayoutInfo
::
HBox
:
794
case
LayoutInfo
::
VBox
:
// Margin/spacing need to be saved
795
type
=
LayoutHasMarginSpacing
;
796
break
;
797
default
:
// Margin/spacing need to be saved + has a state (empty rows/columns of a grid)
798
type
=
LayoutHasState
;
799
break
;
800
}
801
Q_ASSERT
(
m_layout
!=
nullptr
);
802
m_layout
->
sort
();
803
804
805
if
(
type
>=
LayoutHasMarginSpacing
) {
806
m_properties
=
new
LayoutProperties
;
807
m_propertyMask
=
m_properties
->
fromPropertySheet
(
core
,
layoutToBeBroken
,
LayoutProperties
::
AllProperties
);
808
}
809
if
(
type
>=
LayoutHasState
)
810
m_layoutHelper
=
LayoutHelper
::
createLayoutHelper
(
layoutType
);
811
m_cursorSelectionState
.
save
(
formWindow
());
812
}
813
814
void
BreakLayoutCommand
::
redo
()
815
{
816
if
(!
m_layout
)
817
return
;
818
819
QDesignerFormEditorInterface
*
core
=
formWindow
()->
core
();
820
QWidget
*
lb
=
m_layout
->
layoutBaseWidget
();
821
QDesignerLayoutDecorationExtension
*
deco
=
qt_extension
<
QDesignerLayoutDecorationExtension
*>(
core
->
extensionManager
(),
lb
);
822
formWindow
()->
clearSelection
(
false
);
823
if
(
m_layoutHelper
)
824
m_layoutHelper
->
pushState
(
core
,
m_layoutBase
);
825
m_layout
->
breakLayout
();
826
delete
deco
;
// release the extension
827
828
for
(
QWidget
*
widget
:
std
::
as_const
(
m_widgets
)) {
829
widget
->
resize
(
widget
->
size
().
expandedTo
(
QSize
(16, 16)));
830
}
831
// Update unless we are in an intermediate state of morphing layout
832
// in which a QLayoutWidget will have no layout at all.
833
if
(
m_layout
->
reparentLayoutWidget
())
834
core
->
objectInspector
()->
setFormWindow
(
formWindow
());
835
}
836
837
void
BreakLayoutCommand
::
undo
()
838
{
839
if
(!
m_layout
)
840
return
;
841
842
formWindow
()->
clearSelection
(
false
);
843
m_layout
->
doLayout
();
844
if
(
m_layoutHelper
)
845
m_layoutHelper
->
popState
(
formWindow
()->
core
(),
m_layoutBase
);
846
847
QLayout
*
layoutToRestored
=
LayoutInfo
::
managedLayout
(
formWindow
()->
core
(),
m_layoutBase
);
848
if
(
m_properties
&&
m_layoutBase
&&
layoutToRestored
)
849
m_properties
->
toPropertySheet
(
formWindow
()->
core
(),
layoutToRestored
,
m_propertyMask
);
850
m_cursorSelectionState
.
restore
(
formWindow
());
851
core
()->
objectInspector
()->
setFormWindow
(
formWindow
());
852
}
853
// ---- SimplifyLayoutCommand
854
SimplifyLayoutCommand
::
SimplifyLayoutCommand
(
QDesignerFormWindowInterface
*
formWindow
) :
855
QDesignerFormWindowCommand
(
QApplication
::
translate
(
"Command"
,
"Simplify Grid Layout"
),
formWindow
),
856
m_area
(0, 0, 32767, 32767),
857
m_layoutBase
(
nullptr
),
858
m_layoutHelper
(
nullptr
),
859
m_layoutSimplified
(
false
)
860
{
861
}
862
863
SimplifyLayoutCommand
::~
SimplifyLayoutCommand
()
864
{
865
delete
m_layoutHelper
;
866
}
867
868
bool
SimplifyLayoutCommand
::
canSimplify
(
QDesignerFormEditorInterface
*
core
,
const
QWidget
*
w
,
int
*
layoutType
)
869
{
870
if
(!
w
)
871
return
false
;
872
QLayout
*
layout
=
nullptr
;
873
const
LayoutInfo
::
Type
type
=
LayoutInfo
::
managedLayoutType
(
core
,
w
, &
layout
);
874
if
(
layoutType
)
875
*
layoutType
=
type
;
876
if
(!
layout
)
877
return
false
;
878
switch
(
type
) {
// Known negatives
879
case
LayoutInfo
::
NoLayout
:
880
case
LayoutInfo
::
UnknownLayout
:
881
case
LayoutInfo
::
HSplitter
:
882
case
LayoutInfo
::
VSplitter
:
883
case
LayoutInfo
::
HBox
:
884
case
LayoutInfo
::
VBox
:
885
return
false
;
886
default
:
887
break
;
888
}
889
switch
(
type
) {
890
case
LayoutInfo
::
Grid
:
891
return
QLayoutSupport
::
canSimplifyQuickCheck
(
qobject_cast
<
QGridLayout
*>(
layout
));
892
case
LayoutInfo
::
Form
:
893
return
QLayoutSupport
::
canSimplifyQuickCheck
(
qobject_cast
<
const
QFormLayout
*>(
layout
));
894
default
:
895
break
;
896
}
897
return
false
;
898
}
899
900
bool
SimplifyLayoutCommand
::
init
(
QWidget
*
layoutBase
)
901
{
902
QDesignerFormEditorInterface
*
core
=
formWindow
()->
core
();
903
m_layoutSimplified
=
false
;
904
int
type
= 0;
905
if
(
canSimplify
(
core
,
layoutBase
, &
type
)) {
906
m_layoutBase
=
layoutBase
;
907
m_layoutHelper
=
LayoutHelper
::
createLayoutHelper
(
type
);
908
m_layoutSimplified
=
m_layoutHelper
->
canSimplify
(
core
,
layoutBase
,
m_area
);
909
}
910
return
m_layoutSimplified
;
911
}
912
913
void
SimplifyLayoutCommand
::
redo
()
914
{
915
const
QDesignerFormEditorInterface
*
core
=
formWindow
()->
core
();
916
if
(
m_layoutSimplified
) {
917
m_layoutHelper
->
pushState
(
core
,
m_layoutBase
);
918
m_layoutHelper
->
simplify
(
core
,
m_layoutBase
,
m_area
);
919
}
920
}
921
void
SimplifyLayoutCommand
::
undo
()
922
{
923
if
(
m_layoutSimplified
)
924
m_layoutHelper
->
popState
(
formWindow
()->
core
(),
m_layoutBase
);
925
}
926
927
// ---- ToolBoxCommand ----
928
ToolBoxCommand
::
ToolBoxCommand
(
QDesignerFormWindowInterface
*
formWindow
) :
929
QDesignerFormWindowCommand
(
QString
(),
formWindow
),
930
m_index
(-1)
931
{
932
}
933
934
ToolBoxCommand
::~
ToolBoxCommand
() =
default
;
935
936
void
ToolBoxCommand
::
init
(
QToolBox
*
toolBox
)
937
{
938
m_toolBox
=
toolBox
;
939
m_index
=
m_toolBox
->
currentIndex
();
940
m_widget
=
m_toolBox
->
widget
(
m_index
);
941
m_itemText
=
m_toolBox
->
itemText
(
m_index
);
942
m_itemIcon
=
m_toolBox
->
itemIcon
(
m_index
);
943
}
944
945
void
ToolBoxCommand
::
removePage
()
946
{
947
m_toolBox
->
removeItem
(
m_index
);
948
949
m_widget
->
hide
();
950
m_widget
->
setParent
(
formWindow
());
951
formWindow
()->
clearSelection
();
952
formWindow
()->
selectWidget
(
m_toolBox
,
true
);
953
954
}
955
956
void
ToolBoxCommand
::
addPage
()
957
{
958
m_widget
->
setParent
(
m_toolBox
);
959
m_toolBox
->
insertItem
(
m_index
,
m_widget
,
m_itemIcon
,
m_itemText
);
960
m_toolBox
->
setCurrentIndex
(
m_index
);
961
962
QDesignerPropertySheetExtension
*sheet = qt_extension<
QDesignerPropertySheetExtension
*>(formWindow()->core()->extensionManager(), m_toolBox);
963
if
(
sheet
) {
964
qdesigner_internal
::
PropertySheetStringValue
itemText
(
m_itemText
);
965
sheet
->
setProperty
(
sheet
->
indexOf
(u"currentItemText"_s),
QVariant
::
fromValue
(
itemText
));
966
}
967
968
m_widget
->
show
();
969
formWindow
()->
clearSelection
();
970
formWindow
()->
selectWidget
(
m_toolBox
,
true
);
971
}
972
973
// ---- MoveToolBoxPageCommand ----
974
MoveToolBoxPageCommand
::
MoveToolBoxPageCommand
(
QDesignerFormWindowInterface
*
formWindow
) :
975
ToolBoxCommand
(
formWindow
),
976
m_newIndex
(-1),
977
m_oldIndex
(-1)
978
{
979
}
980
981
MoveToolBoxPageCommand
::~
MoveToolBoxPageCommand
() =
default
;
982
983
void
MoveToolBoxPageCommand
::
init
(
QToolBox
*
toolBox
,
QWidget
*
page
,
int
newIndex
)
984
{
985
ToolBoxCommand
::
init
(
toolBox
);
986
setText
(
QApplication
::
translate
(
"Command"
,
"Move Page"
));
987
988
m_widget
=
page
;
989
m_oldIndex
=
m_toolBox
->
indexOf
(
m_widget
);
990
m_itemText
=
m_toolBox
->
itemText
(
m_oldIndex
);
991
m_itemIcon
=
m_toolBox
->
itemIcon
(
m_oldIndex
);
992
m_newIndex
=
newIndex
;
993
}
994
995
void
MoveToolBoxPageCommand
::
redo
()
996
{
997
m_toolBox
->
removeItem
(
m_oldIndex
);
998
m_toolBox
->
insertItem
(
m_newIndex
,
m_widget
,
m_itemIcon
,
m_itemText
);
999
}
1000
1001
void
MoveToolBoxPageCommand
::
undo
()
1002
{
1003
m_toolBox
->
removeItem
(
m_newIndex
);
1004
m_toolBox
->
insertItem
(
m_oldIndex
,
m_widget
,
m_itemIcon
,
m_itemText
);
1005
}
1006
1007
// ---- DeleteToolBoxPageCommand ----
1008
DeleteToolBoxPageCommand
::
DeleteToolBoxPageCommand
(
QDesignerFormWindowInterface
*
formWindow
)
1009
:
ToolBoxCommand
(
formWindow
)
1010
{
1011
}
1012
1013
DeleteToolBoxPageCommand
::~
DeleteToolBoxPageCommand
() =
default
;
1014
1015
void
DeleteToolBoxPageCommand
::
init
(
QToolBox
*
toolBox
)
1016
{
1017
ToolBoxCommand
::
init
(
toolBox
);
1018
setText
(
QApplication
::
translate
(
"Command"
,
"Delete Page"
));
1019
}
1020
1021
void
DeleteToolBoxPageCommand
::
redo
()
1022
{
1023
removePage
();
1024
cheapUpdate
();
1025
}
1026
1027
void
DeleteToolBoxPageCommand
::
undo
()
1028
{
1029
addPage
();
1030
cheapUpdate
();
1031
}
1032
1033
// ---- AddToolBoxPageCommand ----
1034
AddToolBoxPageCommand
::
AddToolBoxPageCommand
(
QDesignerFormWindowInterface
*
formWindow
)
1035
:
ToolBoxCommand
(
formWindow
)
1036
{
1037
}
1038
1039
AddToolBoxPageCommand
::~
AddToolBoxPageCommand
() =
default
;
1040
1041
void
AddToolBoxPageCommand
::
init
(
QToolBox
*
toolBox
)
1042
{
1043
init
(
toolBox
,
InsertBefore
);
1044
}
1045
1046
void
AddToolBoxPageCommand
::
init
(
QToolBox
*
toolBox
,
InsertionMode
mode
)
1047
{
1048
m_toolBox
=
toolBox
;
1049
1050
m_index
=
m_toolBox
->
currentIndex
();
1051
if
(
mode
==
InsertAfter
)
1052
m_index
++;
1053
m_widget
=
new
QDesignerWidget
(
formWindow
(),
m_toolBox
);
1054
m_itemText
=
QApplication
::
translate
(
"Command"
,
"Page"
);
1055
m_itemIcon
=
QIcon
();
1056
m_widget
->
setObjectName
(u"page"_s);
1057
formWindow
()->
ensureUniqueObjectName
(
m_widget
);
1058
1059
setText
(
QApplication
::
translate
(
"Command"
,
"Insert Page"
));
1060
1061
QDesignerFormEditorInterface *core = formWindow()->core();
1062
core
->
metaDataBase
()->
add
(
m_widget
);
1063
}
1064
1065
void
AddToolBoxPageCommand
::
redo
()
1066
{
1067
addPage
();
1068
cheapUpdate
();
1069
}
1070
1071
void
AddToolBoxPageCommand
::
undo
()
1072
{
1073
removePage
();
1074
cheapUpdate
();
1075
}
1076
1077
// ---- TabWidgetCommand ----
1078
TabWidgetCommand
::
TabWidgetCommand
(
QDesignerFormWindowInterface
*
formWindow
) :
1079
QDesignerFormWindowCommand
(
QString
(),
formWindow
),
1080
m_index
(-1)
1081
{
1082
}
1083
1084
TabWidgetCommand
::~
TabWidgetCommand
() =
default
;
1085
1086
void
TabWidgetCommand
::
init
(
QTabWidget
*
tabWidget
)
1087
{
1088
m_tabWidget
=
tabWidget
;
1089
m_index
=
m_tabWidget
->
currentIndex
();
1090
m_widget
=
m_tabWidget
->
widget
(
m_index
);
1091
m_itemText
=
m_tabWidget
->
tabText
(
m_index
);
1092
m_itemIcon
=
m_tabWidget
->
tabIcon
(
m_index
);
1093
}
1094
1095
void
TabWidgetCommand
::
removePage
()
1096
{
1097
m_tabWidget
->
removeTab
(
m_index
);
1098
1099
m_widget
->
hide
();
1100
m_widget
->
setParent
(
formWindow
());
1101
m_tabWidget
->
setCurrentIndex
(
qMin
(
m_index
,
m_tabWidget
->
count
()));
1102
1103
formWindow
()->
clearSelection
();
1104
formWindow
()->
selectWidget
(
m_tabWidget
,
true
);
1105
}
1106
1107
void
TabWidgetCommand
::
addPage
()
1108
{
1109
m_widget
->
setParent
(
nullptr
);
1110
m_tabWidget
->
insertTab
(
m_index
,
m_widget
,
m_itemIcon
,
m_itemText
);
1111
m_widget
->
show
();
1112
m_tabWidget
->
setCurrentIndex
(
m_index
);
1113
1114
QDesignerPropertySheetExtension
*sheet = qt_extension<
QDesignerPropertySheetExtension
*>(formWindow()->core()->extensionManager(), m_tabWidget);
1115
if
(
sheet
) {
1116
qdesigner_internal
::
PropertySheetStringValue
itemText
(
m_itemText
);
1117
sheet
->
setProperty
(
sheet
->
indexOf
(u"currentTabText"_s),
1118
QVariant
::
fromValue
(
itemText
));
1119
}
1120
1121
formWindow
()->
clearSelection
();
1122
formWindow
()->
selectWidget
(
m_tabWidget
,
true
);
1123
}
1124
1125
// ---- DeleteTabPageCommand ----
1126
DeleteTabPageCommand
::
DeleteTabPageCommand
(
QDesignerFormWindowInterface
*
formWindow
)
1127
:
TabWidgetCommand
(
formWindow
)
1128
{
1129
}
1130
1131
DeleteTabPageCommand
::~
DeleteTabPageCommand
() =
default
;
1132
1133
void
DeleteTabPageCommand
::
init
(
QTabWidget
*
tabWidget
)
1134
{
1135
TabWidgetCommand
::
init
(
tabWidget
);
1136
setText
(
QApplication
::
translate
(
"Command"
,
"Delete Page"
));
1137
}
1138
1139
void
DeleteTabPageCommand
::
redo
()
1140
{
1141
removePage
();
1142
cheapUpdate
();
1143
}
1144
1145
void
DeleteTabPageCommand
::
undo
()
1146
{
1147
addPage
();
1148
cheapUpdate
();
1149
}
1150
1151
// ---- AddTabPageCommand ----
1152
AddTabPageCommand
::
AddTabPageCommand
(
QDesignerFormWindowInterface
*
formWindow
)
1153
:
TabWidgetCommand
(
formWindow
)
1154
{
1155
}
1156
1157
AddTabPageCommand
::~
AddTabPageCommand
() =
default
;
1158
1159
void
AddTabPageCommand
::
init
(
QTabWidget
*
tabWidget
)
1160
{
1161
init
(
tabWidget
,
InsertBefore
);
1162
}
1163
1164
void
AddTabPageCommand
::
init
(
QTabWidget
*
tabWidget
,
InsertionMode
mode
)
1165
{
1166
m_tabWidget
=
tabWidget
;
1167
1168
m_index
=
m_tabWidget
->
currentIndex
();
1169
if
(
mode
==
InsertAfter
)
1170
m_index
++;
1171
m_widget
=
new
QDesignerWidget
(
formWindow
(),
m_tabWidget
);
1172
m_itemText
=
QApplication
::
translate
(
"Command"
,
"Page"
);
1173
m_itemIcon
=
QIcon
();
1174
m_widget
->
setObjectName
(u"tab"_s);
1175
formWindow
()->
ensureUniqueObjectName
(
m_widget
);
1176
1177
setText
(
QApplication
::
translate
(
"Command"
,
"Insert Page"
));
1178
1179
QDesignerFormEditorInterface *core = formWindow()->core();
1180
core
->
metaDataBase
()->
add
(
m_widget
);
1181
}
1182
1183
void
AddTabPageCommand
::
redo
()
1184
{
1185
addPage
();
1186
cheapUpdate
();
1187
}
1188
1189
void
AddTabPageCommand
::
undo
()
1190
{
1191
removePage
();
1192
cheapUpdate
();
1193
}
1194
1195
// ---- MoveTabPageCommand ----
1196
MoveTabPageCommand
::
MoveTabPageCommand
(
QDesignerFormWindowInterface
*
formWindow
) :
1197
TabWidgetCommand
(
formWindow
),
1198
m_newIndex
(-1),
1199
m_oldIndex
(-1)
1200
{
1201
}
1202
1203
MoveTabPageCommand
::~
MoveTabPageCommand
() =
default
;
1204
1205
void
MoveTabPageCommand
::
init
(
QTabWidget
*
tabWidget
,
QWidget
*
page
,
1206
const
QIcon
&
icon
,
const
QString
&
label
,
1207
int
index
,
int
newIndex
)
1208
{
1209
TabWidgetCommand
::
init
(
tabWidget
);
1210
setText
(
QApplication
::
translate
(
"Command"
,
"Move Page"
));
1211
1212
m_page
=
page
;
1213
m_newIndex
=
newIndex
;
1214
m_oldIndex
=
index
;
1215
m_label
=
label
;
1216
m_icon
=
icon
;
1217
}
1218
1219
void
MoveTabPageCommand
::
redo
()
1220
{
1221
m_tabWidget
->
removeTab
(
m_oldIndex
);
1222
m_tabWidget
->
insertTab
(
m_newIndex
,
m_page
,
m_icon
,
m_label
);
1223
m_tabWidget
->
setCurrentIndex
(
m_newIndex
);
1224
}
1225
1226
void
MoveTabPageCommand
::
undo
()
1227
{
1228
m_tabWidget
->
removeTab
(
m_newIndex
);
1229
m_tabWidget
->
insertTab
(
m_oldIndex
,
m_page
,
m_icon
,
m_label
);
1230
m_tabWidget
->
setCurrentIndex
(
m_oldIndex
);
1231
}
1232
1233
// ---- StackedWidgetCommand ----
1234
StackedWidgetCommand
::
StackedWidgetCommand
(
QDesignerFormWindowInterface
*
formWindow
) :
1235
QDesignerFormWindowCommand
(
QString
(),
formWindow
),
1236
m_index
(-1)
1237
{
1238
}
1239
1240
StackedWidgetCommand
::~
StackedWidgetCommand
() =
default
;
1241
1242
void
StackedWidgetCommand
::
init
(
QStackedWidget
*
stackedWidget
)
1243
{
1244
m_stackedWidget
=
stackedWidget
;
1245
m_index
=
m_stackedWidget
->
currentIndex
();
1246
m_widget
=
m_stackedWidget
->
widget
(
m_index
);
1247
}
1248
1249
void
StackedWidgetCommand
::
removePage
()
1250
{
1251
m_stackedWidget
->
removeWidget
(
m_stackedWidget
->
widget
(
m_index
));
1252
1253
m_widget
->
hide
();
1254
m_widget
->
setParent
(
formWindow
());
1255
1256
formWindow
()->
clearSelection
();
1257
formWindow
()->
selectWidget
(
m_stackedWidget
,
true
);
1258
}
1259
1260
void
StackedWidgetCommand
::
addPage
()
1261
{
1262
m_stackedWidget
->
insertWidget
(
m_index
,
m_widget
);
1263
1264
m_widget
->
show
();
1265
m_stackedWidget
->
setCurrentIndex
(
m_index
);
1266
1267
formWindow
()->
clearSelection
();
1268
formWindow
()->
selectWidget
(
m_stackedWidget
,
true
);
1269
}
1270
1271
// ---- MoveStackedWidgetCommand ----
1272
MoveStackedWidgetCommand
::
MoveStackedWidgetCommand
(
QDesignerFormWindowInterface
*
formWindow
) :
1273
StackedWidgetCommand
(
formWindow
),
1274
m_newIndex
(-1),
1275
m_oldIndex
(-1)
1276
{
1277
}
1278
1279
MoveStackedWidgetCommand
::~
MoveStackedWidgetCommand
() =
default
;
1280
1281
void
MoveStackedWidgetCommand
::
init
(
QStackedWidget
*
stackedWidget
,
QWidget
*
page
,
int
newIndex
)
1282
{
1283
StackedWidgetCommand
::
init
(
stackedWidget
);
1284
setText
(
QApplication
::
translate
(
"Command"
,
"Move Page"
));
1285
1286
m_widget
=
page
;
1287
m_newIndex
=
newIndex
;
1288
m_oldIndex
=
m_stackedWidget
->
indexOf
(
m_widget
);
1289
}
1290
1291
void
MoveStackedWidgetCommand
::
redo
()
1292
{
1293
m_stackedWidget
->
removeWidget
(
m_widget
);
1294
m_stackedWidget
->
insertWidget
(
m_newIndex
,
m_widget
);
1295
}
1296
1297
void
MoveStackedWidgetCommand
::
undo
()
1298
{
1299
m_stackedWidget
->
removeWidget
(
m_widget
);
1300
m_stackedWidget
->
insertWidget
(
m_oldIndex
,
m_widget
);
1301
}
1302
1303
// ---- DeleteStackedWidgetPageCommand ----
1304
DeleteStackedWidgetPageCommand
::
DeleteStackedWidgetPageCommand
(
QDesignerFormWindowInterface
*
formWindow
)
1305
:
StackedWidgetCommand
(
formWindow
)
1306
{
1307
}
1308
1309
DeleteStackedWidgetPageCommand
::~
DeleteStackedWidgetPageCommand
() =
default
;
1310
1311
void
DeleteStackedWidgetPageCommand
::
init
(
QStackedWidget
*
stackedWidget
)
1312
{
1313
StackedWidgetCommand
::
init
(
stackedWidget
);
1314
setText
(
QApplication
::
translate
(
"Command"
,
"Delete Page"
));
1315
}
1316
1317
void
DeleteStackedWidgetPageCommand
::
redo
()
1318
{
1319
removePage
();
1320
cheapUpdate
();
1321
}
1322
1323
void
DeleteStackedWidgetPageCommand
::
undo
()
1324
{
1325
addPage
();
1326
cheapUpdate
();
1327
}
1328
1329
// ---- AddStackedWidgetPageCommand ----
1330
AddStackedWidgetPageCommand
::
AddStackedWidgetPageCommand
(
QDesignerFormWindowInterface
*
formWindow
)
1331
:
StackedWidgetCommand
(
formWindow
)
1332
{
1333
}
1334
1335
AddStackedWidgetPageCommand
::~
AddStackedWidgetPageCommand
() =
default
;
1336
1337
void
AddStackedWidgetPageCommand
::
init
(
QStackedWidget
*
stackedWidget
)
1338
{
1339
init
(
stackedWidget
,
InsertBefore
);
1340
}
1341
1342
void
AddStackedWidgetPageCommand
::
init
(
QStackedWidget
*
stackedWidget
,
InsertionMode
mode
)
1343
{
1344
m_stackedWidget
=
stackedWidget
;
1345
1346
m_index
=
m_stackedWidget
->
currentIndex
();
1347
if
(
mode
==
InsertAfter
)
1348
m_index
++;
1349
m_widget
=
new
QDesignerWidget
(
formWindow
(),
m_stackedWidget
);
1350
m_widget
->
setObjectName
(u"page"_s);
1351
formWindow
()->
ensureUniqueObjectName
(
m_widget
);
1352
1353
setText
(
QApplication
::
translate
(
"Command"
,
"Insert Page"
));
1354
1355
QDesignerFormEditorInterface *core = formWindow()->core();
1356
core
->
metaDataBase
()->
add
(
m_widget
);
1357
}
1358
1359
void
AddStackedWidgetPageCommand
::
redo
()
1360
{
1361
addPage
();
1362
cheapUpdate
();
1363
}
1364
1365
void
AddStackedWidgetPageCommand
::
undo
()
1366
{
1367
removePage
();
1368
cheapUpdate
();
1369
}
1370
1371
// ---- TabOrderCommand ----
1372
TabOrderCommand
::
TabOrderCommand
(
QDesignerFormWindowInterface
*
formWindow
)
1373
:
QDesignerFormWindowCommand
(
QApplication
::
translate
(
"Command"
,
"Change Tab order"
),
formWindow
),
1374
m_widgetItem
(
nullptr
)
1375
{
1376
}
1377
1378
void
TabOrderCommand
::
init
(
const
QWidgetList
&
newTabOrder
)
1379
{
1380
QDesignerFormEditorInterface
*
core
=
formWindow
()->
core
();
1381
Q_ASSERT
(
core
);
1382
1383
m_widgetItem
=
core
->
metaDataBase
()->
item
(
formWindow
());
1384
Q_ASSERT
(
m_widgetItem
);
1385
m_oldTabOrder
=
m_widgetItem
->
tabOrder
();
1386
m_newTabOrder
=
newTabOrder
;
1387
}
1388
1389
void
TabOrderCommand
::
redo
()
1390
{
1391
m_widgetItem
->
setTabOrder
(
m_newTabOrder
);
1392
}
1393
1394
void
TabOrderCommand
::
undo
()
1395
{
1396
m_widgetItem
->
setTabOrder
(
m_oldTabOrder
);
1397
}
1398
1399
// ---- CreateMenuBarCommand ----
1400
CreateMenuBarCommand
::
CreateMenuBarCommand
(
QDesignerFormWindowInterface
*
formWindow
)
1401
:
QDesignerFormWindowCommand
(
QApplication
::
translate
(
"Command"
,
"Create Menu Bar"
),
formWindow
)
1402
{
1403
}
1404
1405
void
CreateMenuBarCommand
::
init
(
QMainWindow
*
mainWindow
)
1406
{
1407
m_mainWindow
=
mainWindow
;
1408
QDesignerFormEditorInterface *core = formWindow()->core();
1409
m_menuBar
=
qobject_cast
<
QMenuBar
*>(
core
->
widgetFactory
()->
createWidget
(u"QMenuBar"_s,
m_mainWindow
));
1410
core
->
widgetFactory
()->
initialize
(
m_menuBar
);
1411
}
1412
1413
void
CreateMenuBarCommand
::
redo
()
1414
{
1415
QDesignerFormEditorInterface *core = formWindow()->core();
1416
auto
*c = qt_extension<
QDesignerContainerExtension
*>(core->extensionManager(), m_mainWindow);
1417
c
->
addWidget
(
m_menuBar
);
1418
1419
m_menuBar
->
setObjectName
(u"menuBar"_s);
1420
formWindow
()->
ensureUniqueObjectName
(
m_menuBar
);
1421
core
->
metaDataBase
()->
add
(
m_menuBar
);
1422
formWindow
()->
emitSelectionChanged
();
1423
m_menuBar
->
setFocus
();
1424
}
1425
1426
void
CreateMenuBarCommand
::
undo
()
1427
{
1428
QDesignerFormEditorInterface *core = formWindow()->core();
1429
auto
*c = qt_extension<
QDesignerContainerExtension
*>(core->extensionManager(), m_mainWindow);
1430
for
(
int
i = 0;
i
<
c
->
count
(); ++
i
) {
1431
if
(
c
->
widget
(
i
) ==
m_menuBar
) {
1432
c
->
remove
(
i
);
1433
break
;
1434
}
1435
}
1436
1437
core
->
metaDataBase
()->
remove
(
m_menuBar
);
1438
formWindow
()->
emitSelectionChanged
();
1439
}
1440
1441
// ---- DeleteMenuBarCommand ----
1442
DeleteMenuBarCommand
::
DeleteMenuBarCommand
(
QDesignerFormWindowInterface
*
formWindow
)
1443
:
QDesignerFormWindowCommand
(
QApplication
::
translate
(
"Command"
,
"Delete Menu Bar"
),
formWindow
)
1444
{
1445
}
1446
1447
void
DeleteMenuBarCommand
::
init
(
QMenuBar
*
menuBar
)
1448
{
1449
m_menuBar
=
menuBar
;
1450
m_mainWindow
=
qobject_cast
<
QMainWindow
*>(
menuBar
->
parentWidget
());
1451
}
1452
1453
void
DeleteMenuBarCommand
::
redo
()
1454
{
1455
if
(
m_mainWindow
) {
1456
auto
*c = qt_extension<
QDesignerContainerExtension
*>(core()->extensionManager(), m_mainWindow);
1457
Q_ASSERT
(
c
!=
nullptr
);
1458
for
(
int
i=0;
i
<
c
->
count
(); ++
i
) {
1459
if
(
c
->
widget
(
i
) ==
m_menuBar
) {
1460
c
->
remove
(
i
);
1461
break
;
1462
}
1463
}
1464
}
1465
1466
core
()->
metaDataBase
()->
remove
(
m_menuBar
);
1467
m_menuBar
->
hide
();
1468
m_menuBar
->
setParent
(
formWindow
());
1469
formWindow
()->
emitSelectionChanged
();
1470
}
1471
1472
void
DeleteMenuBarCommand
::
undo
()
1473
{
1474
if
(
m_mainWindow
) {
1475
m_menuBar
->
setParent
(
m_mainWindow
);
1476
auto
*c = qt_extension<
QDesignerContainerExtension
*>(core()->extensionManager(), m_mainWindow);
1477
1478
c
->
addWidget
(
m_menuBar
);
1479
1480
core
()->
metaDataBase
()->
add
(
m_menuBar
);
1481
m_menuBar
->
show
();
1482
formWindow
()->
emitSelectionChanged
();
1483
}
1484
}
1485
1486
// ---- CreateStatusBarCommand ----
1487
CreateStatusBarCommand
::
CreateStatusBarCommand
(
QDesignerFormWindowInterface
*
formWindow
)
1488
:
QDesignerFormWindowCommand
(
QApplication
::
translate
(
"Command"
,
"Create Status Bar"
),
formWindow
)
1489
{
1490
}
1491
1492
void
CreateStatusBarCommand
::
init
(
QMainWindow
*
mainWindow
)
1493
{
1494
m_mainWindow
=
mainWindow
;
1495
QDesignerFormEditorInterface *core = formWindow()->core();
1496
m_statusBar
=
qobject_cast
<
QStatusBar
*>(
core
->
widgetFactory
()->
createWidget
(u"QStatusBar"_s,
m_mainWindow
));
1497
core
->
widgetFactory
()->
initialize
(
m_statusBar
);
1498
}
1499
1500
void
CreateStatusBarCommand
::
redo
()
1501
{
1502
QDesignerFormEditorInterface *core = formWindow()->core();
1503
auto
*c = qt_extension<
QDesignerContainerExtension
*>(core->extensionManager(), m_mainWindow);
1504
c
->
addWidget
(
m_statusBar
);
1505
1506
m_statusBar
->
setObjectName
(u"statusBar"_s);
1507
formWindow
()->
ensureUniqueObjectName
(
m_statusBar
);
1508
core
->
metaDataBase
()->
add
(
m_statusBar
);
1509
formWindow
()->
emitSelectionChanged
();
1510
}
1511
1512
void
CreateStatusBarCommand
::
undo
()
1513
{
1514
QDesignerFormEditorInterface *core = formWindow()->core();
1515
QDesignerContainerExtension
*c = qt_extension<
QDesignerContainerExtension
*>(core->extensionManager(), m_mainWindow);
1516
for
(
int
i = 0;
i
<
c
->
count
(); ++
i
) {
1517
if
(
c
->
widget
(
i
) ==
m_statusBar
) {
1518
c
->
remove
(
i
);
1519
break
;
1520
}
1521
}
1522
1523
core
->
metaDataBase
()->
remove
(
m_statusBar
);
1524
formWindow
()->
emitSelectionChanged
();
1525
}
1526
1527
// ---- DeleteStatusBarCommand ----
1528
DeleteStatusBarCommand
::
DeleteStatusBarCommand
(
QDesignerFormWindowInterface
*
formWindow
)
1529
:
QDesignerFormWindowCommand
(
QApplication
::
translate
(
"Command"
,
"Delete Status Bar"
),
formWindow
)
1530
{
1531
}
1532
1533
void
DeleteStatusBarCommand
::
init
(
QStatusBar
*
statusBar
)
1534
{
1535
m_statusBar
=
statusBar
;
1536
m_mainWindow
=
qobject_cast
<
QMainWindow
*>(
statusBar
->
parentWidget
());
1537
}
1538
1539
void
DeleteStatusBarCommand
::
redo
()
1540
{
1541
if
(
m_mainWindow
) {
1542
QDesignerContainerExtension
*
c
=
qt_extension
<
QDesignerContainerExtension
*>(
core
()->
extensionManager
(),
m_mainWindow
);
1543
Q_ASSERT
(
c
!=
nullptr
);
1544
for
(
int
i
=0;
i
<
c
->
count
(); ++
i
) {
1545
if
(
c
->
widget
(
i
) ==
m_statusBar
) {
1546
c
->
remove
(
i
);
1547
break
;
1548
}
1549
}
1550
}
1551
1552
core
()->
metaDataBase
()->
remove
(
m_statusBar
);
1553
m_statusBar
->
hide
();
1554
m_statusBar
->
setParent
(
formWindow
());
1555
formWindow
()->
emitSelectionChanged
();
1556
}
1557
1558
void
DeleteStatusBarCommand
::
undo
()
1559
{
1560
if
(
m_mainWindow
) {
1561
m_statusBar
->
setParent
(
m_mainWindow
);
1562
QDesignerContainerExtension
*
c
=
qt_extension
<
QDesignerContainerExtension
*>(
core
()->
extensionManager
(),
m_mainWindow
);
1563
1564
c
->
addWidget
(
m_statusBar
);
1565
1566
core
()->
metaDataBase
()->
add
(
m_statusBar
);
1567
m_statusBar
->
show
();
1568
formWindow
()->
emitSelectionChanged
();
1569
}
1570
}
1571
1572
// ---- AddToolBarCommand ----
1573
AddToolBarCommand
::
AddToolBarCommand
(
QDesignerFormWindowInterface
*
formWindow
)
1574
:
QDesignerFormWindowCommand
(
QApplication
::
translate
(
"Command"
,
"Add Tool Bar"
),
formWindow
)
1575
{
1576
}
1577
1578
void
AddToolBarCommand
::
init
(
QMainWindow
*
mainWindow
,
Qt
::
ToolBarArea
area
)
1579
{
1580
m_mainWindow
=
mainWindow
;
1581
QDesignerWidgetFactoryInterface * wf = formWindow()->core()->widgetFactory();
1582
// Pass on 0 parent first to avoid reparenting flicker.
1583
m_toolBar
=
qobject_cast
<
QToolBar
*>(
wf
->
createWidget
(u"QToolBar"_s,
nullptr
));
1584
m_toolBar
->
setProperty
(
"_q_desiredArea"
,
QVariant
(
area
));
1585
wf
->
initialize
(
m_toolBar
);
1586
m_toolBar
->
hide
();
1587
}
1588
1589
void
AddToolBarCommand
::
redo
()
1590
{
1591
QDesignerFormEditorInterface *core = formWindow()->core();
1592
core
->
metaDataBase
()->
add
(
m_toolBar
);
1593
1594
QDesignerContainerExtension
*c = qt_extension<
QDesignerContainerExtension
*>(core->extensionManager(), m_mainWindow);
1595
c
->
addWidget
(
m_toolBar
);
1596
1597
m_toolBar
->
setObjectName
(u"toolBar"_s);
1598
formWindow
()->
ensureUniqueObjectName
(
m_toolBar
);
1599
setPropertySheetWindowTitle
(
core
,
m_toolBar
,
m_toolBar
->
objectName
());
1600
formWindow
()->
emitSelectionChanged
();
1601
}
1602
1603
void
AddToolBarCommand
::
undo
()
1604
{
1605
QDesignerFormEditorInterface *core = formWindow()->core();
1606
core
->
metaDataBase
()->
remove
(
m_toolBar
);
1607
QDesignerContainerExtension
*c = qt_extension<
QDesignerContainerExtension
*>(core->extensionManager(), m_mainWindow);
1608
for
(
int
i = 0;
i
<
c
->
count
(); ++
i
) {
1609
if
(
c
->
widget
(
i
) ==
m_toolBar
) {
1610
c
->
remove
(
i
);
1611
break
;
1612
}
1613
}
1614
formWindow
()->
emitSelectionChanged
();
1615
}
1616
1617
// ---- DockWidgetCommand:: ----
1618
DockWidgetCommand
::
DockWidgetCommand
(
const
QString
&
description
,
QDesignerFormWindowInterface
*
formWindow
)
1619
:
QDesignerFormWindowCommand
(
description
,
formWindow
)
1620
{
1621
}
1622
1623
DockWidgetCommand
::~
DockWidgetCommand
() =
default
;
1624
1625
void
DockWidgetCommand
::
init
(
QDockWidget
*
dockWidget
)
1626
{
1627
m_dockWidget
=
dockWidget
;
1628
}
1629
1630
// ---- AddDockWidgetCommand ----
1631
AddDockWidgetCommand
::
AddDockWidgetCommand
(
QDesignerFormWindowInterface
*
formWindow
)
1632
:
QDesignerFormWindowCommand
(
QApplication
::
translate
(
"Command"
,
"Add Dock Window"
),
formWindow
)
1633
{
1634
}
1635
1636
void
AddDockWidgetCommand
::
init
(
QMainWindow
*
mainWindow
,
QDockWidget
*
dockWidget
)
1637
{
1638
m_mainWindow
=
mainWindow
;
1639
m_dockWidget
=
dockWidget
;
1640
}
1641
1642
void
AddDockWidgetCommand
::
init
(
QMainWindow
*
mainWindow
)
1643
{
1644
m_mainWindow
=
mainWindow
;
1645
QDesignerFormEditorInterface
*
core
=
formWindow
()->
core
();
1646
m_dockWidget
=
qobject_cast
<
QDockWidget
*>(
core
->
widgetFactory
()->
createWidget
(u"QDockWidget"_s,
m_mainWindow
));
1647
}
1648
1649
void
AddDockWidgetCommand
::
redo
()
1650
{
1651
QDesignerFormEditorInterface
*
core
=
formWindow
()->
core
();
1652
QDesignerContainerExtension
*
c
=
qt_extension
<
QDesignerContainerExtension
*>(
core
->
extensionManager
(),
m_mainWindow
);
1653
c
->
addWidget
(
m_dockWidget
);
1654
1655
m_dockWidget
->
setObjectName
(u"dockWidget"_s);
1656
formWindow
()->
ensureUniqueObjectName
(
m_dockWidget
);
1657
formWindow
()->
manageWidget
(
m_dockWidget
);
1658
formWindow
()->
emitSelectionChanged
();
1659
}
1660
1661
void
AddDockWidgetCommand
::
undo
()
1662
{
1663
QDesignerFormEditorInterface
*
core
=
formWindow
()->
core
();
1664
QDesignerContainerExtension
*
c
=
qt_extension
<
QDesignerContainerExtension
*>(
core
->
extensionManager
(),
m_mainWindow
);
1665
for
(
int
i
= 0;
i
<
c
->
count
(); ++
i
) {
1666
if
(
c
->
widget
(
i
) ==
m_dockWidget
) {
1667
c
->
remove
(
i
);
1668
break
;
1669
}
1670
}
1671
1672
formWindow
()->
unmanageWidget
(
m_dockWidget
);
1673
formWindow
()->
emitSelectionChanged
();
1674
}
1675
1676
// ---- AdjustWidgetSizeCommand ----
1677
AdjustWidgetSizeCommand
::
AdjustWidgetSizeCommand
(
QDesignerFormWindowInterface
*
formWindow
)
1678
:
QDesignerFormWindowCommand
(
QString
(),
formWindow
)
1679
{
1680
}
1681
1682
void
AdjustWidgetSizeCommand
::
init
(
QWidget
*
widget
)
1683
{
1684
m_widget
=
widget
;
1685
setText
(
QApplication
::
translate
(
"Command"
,
"Adjust Size of '%1'"
).
arg
(
widget
->
objectName
()));
1686
}
1687
1688
QWidget
*
AdjustWidgetSizeCommand
::
widgetForAdjust
()
const
1689
{
1690
QDesignerFormWindowInterface
*
fw
=
formWindow
();
1691
// Return the outer, embedding widget if it is the main container
1692
if
(
Utils
::
isCentralWidget
(
fw
,
m_widget
))
1693
return
fw
->
core
()->
integration
()->
containerWindow
(
m_widget
);
1694
return
m_widget
;
1695
}
1696
1697
void
AdjustWidgetSizeCommand
::
redo
()
1698
{
1699
QWidget
*
aw
=
widgetForAdjust
();
1700
m_geometry
=
aw
->
geometry
();
1701
QApplication
::
processEvents
(
QEventLoop
::
ExcludeUserInputEvents
);
1702
aw
->
adjustSize
();
1703
const
bool
isMainContainer
=
aw
!=
m_widget
;
1704
if
(!
isMainContainer
) {
1705
/* When doing adjustsize on a selected non-laid out child that has been enlarged
1706
* and pushed partially over the top/left edge[s], it is possible that it "disappears"
1707
* when shrinking. In that case, move it back so that it remains visible. */
1708
if
(
aw
->
parentWidget
()->
layout
() ==
nullptr
) {
1709
const
QRect
contentsRect
=
aw
->
parentWidget
()->
contentsRect
();
1710
const
QRect
newGeometry
=
aw
->
geometry
();
1711
QPoint
newPos
=
m_geometry
.
topLeft
();
1712
if
(
newGeometry
.
bottom
() <=
contentsRect
.
y
())
1713
newPos
.
setY
(
contentsRect
.
y
());
1714
if
(
newGeometry
.
right
() <=
contentsRect
.
x
())
1715
newPos
.
setX
(
contentsRect
.
x
());
1716
if
(
newPos
!=
m_geometry
.
topLeft
())
1717
aw
->
move
(
newPos
);
1718
}
1719
}
1720
updatePropertyEditor
();
1721
}
1722
1723
void
AdjustWidgetSizeCommand
::
undo
()
1724
{
1725
QWidget
*
aw
=
widgetForAdjust
();
1726
aw
->
resize
(
m_geometry
.
size
());
1727
if
(
m_geometry
.
topLeft
() !=
aw
->
geometry
().
topLeft
())
1728
aw
->
move
(
m_geometry
.
topLeft
());
1729
updatePropertyEditor
();
1730
}
1731
1732
void
AdjustWidgetSizeCommand
::
updatePropertyEditor
()
const
1733
{
1734
if
(
QDesignerPropertyEditorInterface
*
propertyEditor
=
formWindow
()->
core
()->
propertyEditor
()) {
1735
if
(
propertyEditor
->
object
() ==
m_widget
)
1736
propertyEditor
->
setPropertyValue
(u"geometry"_s,
m_widget
->
geometry
(),
true
);
1737
}
1738
}
1739
// ------------ ChangeFormLayoutItemRoleCommand
1740
1741
ChangeFormLayoutItemRoleCommand
::
ChangeFormLayoutItemRoleCommand
(
QDesignerFormWindowInterface
*
formWindow
) :
1742
QDesignerFormWindowCommand
(
QApplication
::
translate
(
"Command"
,
"Change Form Layout Item Geometry"
),
formWindow
),
1743
m_operation
(
SpanningToLabel
)
1744
{
1745
}
1746
1747
void
ChangeFormLayoutItemRoleCommand
::
init
(
QWidget
*
widget
,
Operation
op
)
1748
{
1749
m_widget
=
widget
;
1750
m_operation
=
op
;
1751
}
1752
1753
void
ChangeFormLayoutItemRoleCommand
::
redo
()
1754
{
1755
doOperation
(
m_operation
);
1756
}
1757
1758
void
ChangeFormLayoutItemRoleCommand
::
undo
()
1759
{
1760
doOperation
(
reverseOperation
(
m_operation
));
1761
}
1762
1763
ChangeFormLayoutItemRoleCommand
::
Operation
ChangeFormLayoutItemRoleCommand
::
reverseOperation
(
Operation
op
)
1764
{
1765
switch
(
op
) {
1766
case
SpanningToLabel
:
1767
return
LabelToSpanning
;
1768
case
SpanningToField
:
1769
return
FieldToSpanning
;
1770
case
LabelToSpanning
:
1771
return
SpanningToLabel
;
1772
case
FieldToSpanning
:
1773
return
SpanningToField
;
1774
}
1775
return
SpanningToField
;
1776
}
1777
1778
void
ChangeFormLayoutItemRoleCommand
::
doOperation
(
Operation
op
)
1779
{
1780
QFormLayout
*
fl
=
ChangeFormLayoutItemRoleCommand
::
managedFormLayoutOf
(
formWindow
()->
core
(),
m_widget
);
1781
const
int
index
=
fl
->
indexOf
(
m_widget
);
1782
Q_ASSERT
(
index
!= -1);
1783
int
row
= 0;
1784
QFormLayout
::
ItemRole
role
=
QFormLayout
::
LabelRole
;
1785
fl
->
getItemPosition
(
index
, &
row
, &
role
);
1786
Q_ASSERT
(
index
!= -1);
1787
QLayoutItem
*
item
=
fl
->
takeAt
(
index
);
1788
const
QRect
area
=
QRect
(0,
row
, 2, 1);
1789
switch
(
op
) {
1790
case
SpanningToLabel
:
1791
fl
->
setItem
(
row
,
QFormLayout
::
LabelRole
,
item
);
1792
QLayoutSupport
::
createEmptyCells
(
fl
);
1793
break
;
1794
case
SpanningToField
:
1795
fl
->
setItem
(
row
,
QFormLayout
::
FieldRole
,
item
);
1796
QLayoutSupport
::
createEmptyCells
(
fl
);
1797
break
;
1798
case
LabelToSpanning
:
1799
case
FieldToSpanning
:
1800
QLayoutSupport
::
removeEmptyCells
(
fl
,
area
);
1801
fl
->
setItem
(
row
,
QFormLayout
::
SpanningRole
,
item
);
1802
break
;
1803
}
1804
}
1805
1806
unsigned
ChangeFormLayoutItemRoleCommand
::
possibleOperations
(
QDesignerFormEditorInterface
*
core
,
QWidget
*
w
)
1807
{
1808
QFormLayout
*
fl
=
managedFormLayoutOf
(
core
,
w
);
1809
if
(!
fl
)
1810
return
0;
1811
const
int
index
=
fl
->
indexOf
(
w
);
1812
if
(
index
== -1)
1813
return
0;
1814
int
row
= 0,
col
= 0,
colspan
= 0;
1815
getFormLayoutItemPosition
(
fl
,
index
, &
row
, &
col
,
nullptr
, &
colspan
);
1816
// Spanning item?
1817
if
(
colspan
> 1)
1818
return
SpanningToLabel
|
SpanningToField
;
1819
// Is the neighbouring column free, that is, can the current item be expanded?
1820
const
QFormLayout
::
ItemRole
neighbouringRole
=
col
== 0 ?
QFormLayout
::
FieldRole
:
QFormLayout
::
LabelRole
;
1821
const
bool
empty
=
LayoutInfo
::
isEmptyItem
(
fl
->
itemAt
(
row
,
neighbouringRole
));
1822
if
(
empty
)
1823
return
col
== 0 ?
LabelToSpanning
:
FieldToSpanning
;
1824
return
0;
1825
}
1826
1827
QFormLayout
*
ChangeFormLayoutItemRoleCommand
::
managedFormLayoutOf
(
QDesignerFormEditorInterface
*
core
,
QWidget
*
w
)
1828
{
1829
if
(
auto
*
layout
=
LayoutInfo
::
managedLayout
(
core
,
w
->
parentWidget
())) {
1830
if
(
auto
*
fl
=
qobject_cast
<
QFormLayout
*>(
layout
))
1831
return
fl
;
1832
}
1833
return
nullptr
;
1834
}
1835
1836
// ---- ChangeLayoutItemGeometry ----
1837
ChangeLayoutItemGeometry
::
ChangeLayoutItemGeometry
(
QDesignerFormWindowInterface
*
formWindow
)
1838
:
QDesignerFormWindowCommand
(
QApplication
::
translate
(
"Command"
,
"Change Layout Item Geometry"
),
formWindow
)
1839
{
1840
}
1841
1842
void
ChangeLayoutItemGeometry
::
init
(
QWidget
*
widget
,
int
row
,
int
column
,
int
rowspan
,
int
colspan
)
1843
{
1844
m_widget
=
widget
;
1845
Q_ASSERT
(
m_widget
->
parentWidget
() !=
nullptr
);
1846
1847
QLayout
*
layout
=
LayoutInfo
::
managedLayout
(
formWindow
()->
core
(),
m_widget
->
parentWidget
());
1848
Q_ASSERT
(
layout
!=
nullptr
);
1849
1850
auto
*
grid
=
qobject_cast
<
QGridLayout
*>(
layout
);
1851
Q_ASSERT
(
grid
!=
nullptr
);
1852
1853
const
int
itemIndex
=
grid
->
indexOf
(
m_widget
);
1854
Q_ASSERT
(
itemIndex
!= -1);
1855
1856
int
current_row
= 0,
current_column
= 0,
current_rowspan
= 0,
current_colspan
= 0;
1857
grid
->
getItemPosition
(
itemIndex
, &
current_row
, &
current_column
, &
current_rowspan
, &
current_colspan
);
1858
1859
m_oldInfo
.
setRect
(
current_column
,
current_row
,
current_colspan
,
current_rowspan
);
1860
m_newInfo
.
setRect
(
column
,
row
,
colspan
,
rowspan
);
1861
}
1862
1863
void
ChangeLayoutItemGeometry
::
changeItemPosition
(
const
QRect
&
g
)
1864
{
1865
QLayout
*
layout
=
LayoutInfo
::
managedLayout
(
formWindow
()->
core
(),
m_widget
->
parentWidget
());
1866
Q_ASSERT
(
layout
!=
nullptr
);
1867
1868
auto
*
grid
=
qobject_cast
<
QGridLayout
*>(
layout
);
1869
Q_ASSERT
(
grid
!=
nullptr
);
1870
1871
const
int
itemIndex
=
grid
->
indexOf
(
m_widget
);
1872
Q_ASSERT
(
itemIndex
!= -1);
1873
1874
QLayoutItem
*
item
=
grid
->
takeAt
(
itemIndex
);
1875
delete
item
;
1876
1877
if
(!
QLayoutSupport
::
removeEmptyCells
(
grid
,
g
))
1878
qWarning
() <<
"ChangeLayoutItemGeometry::changeItemPosition: Nonempty cell at "
<<
g
<<
'.'
;
1879
1880
grid
->
addWidget
(
m_widget
,
g
.
top
(),
g
.
left
(),
g
.
height
(),
g
.
width
());
1881
1882
grid
->
invalidate
();
1883
grid
->
activate
();
1884
1885
QLayoutSupport
::
createEmptyCells
(
grid
);
1886
1887
formWindow
()->
clearSelection
(
false
);
1888
formWindow
()->
selectWidget
(
m_widget
,
true
);
1889
}
1890
1891
void
ChangeLayoutItemGeometry
::
redo
()
1892
{
1893
changeItemPosition
(
m_newInfo
);
1894
}
1895
1896
void
ChangeLayoutItemGeometry
::
undo
()
1897
{
1898
changeItemPosition
(
m_oldInfo
);
1899
}
1900
1901
// ---- ContainerWidgetCommand ----
1902
ContainerWidgetCommand
::
ContainerWidgetCommand
(
QDesignerFormWindowInterface
*
formWindow
) :
1903
QDesignerFormWindowCommand
(
QString
(),
formWindow
),
1904
m_index
(-1)
1905
{
1906
}
1907
1908
ContainerWidgetCommand
::~
ContainerWidgetCommand
() =
default
;
1909
1910
QDesignerContainerExtension
*
ContainerWidgetCommand
::
containerExtension
()
const
1911
{
1912
QExtensionManager
*
mgr
=
core
()->
extensionManager
();
1913
return
qt_extension
<
QDesignerContainerExtension
*>(
mgr
,
m_containerWidget
);
1914
}
1915
1916
void
ContainerWidgetCommand
::
init
(
QWidget
*
containerWidget
)
1917
{
1918
m_containerWidget
=
containerWidget
;
1919
1920
if
(
QDesignerContainerExtension
*
c
=
containerExtension
()) {
1921
m_index
=
c
->
currentIndex
();
1922
m_widget
=
c
->
widget
(
m_index
);
1923
}
1924
}
1925
1926
void
ContainerWidgetCommand
::
removePage
()
1927
{
1928
if
(
QDesignerContainerExtension
*
c
=
containerExtension
()) {
1929
if
(
const
int
count
=
c
->
count
()) {
1930
// Undo add after last?
1931
const
int
deleteIndex
=
m_index
>= 0 ?
m_index
:
count
- 1;
1932
c
->
remove
(
deleteIndex
);
1933
m_widget
->
hide
();
1934
m_widget
->
setParent
(
formWindow
());
1935
}
1936
}
1937
}
1938
1939
void
ContainerWidgetCommand
::
addPage
()
1940
{
1941
if
(
QDesignerContainerExtension
*
c
=
containerExtension
()) {
1942
int
newCurrentIndex
= 0;
1943
if
(
m_index
>= 0) {
1944
c
->
insertWidget
(
m_index
,
m_widget
);
1945
newCurrentIndex
=
m_index
;
1946
}
else
{
1947
c
->
addWidget
(
m_widget
);
1948
newCurrentIndex
=
c
->
count
() -1 ;
1949
}
1950
m_widget
->
show
();
1951
c
->
setCurrentIndex
(
newCurrentIndex
);
1952
}
1953
}
1954
1955
// ---- DeleteContainerWidgetPageCommand ----
1956
DeleteContainerWidgetPageCommand
::
DeleteContainerWidgetPageCommand
(
QDesignerFormWindowInterface
*
formWindow
)
1957
:
ContainerWidgetCommand
(
formWindow
)
1958
{
1959
}
1960
1961
DeleteContainerWidgetPageCommand
::~
DeleteContainerWidgetPageCommand
() =
default
;
1962
1963
void
DeleteContainerWidgetPageCommand
::
init
(
QWidget
*
containerWidget
,
ContainerType
ct
)
1964
{
1965
ContainerWidgetCommand
::
init
(
containerWidget
);
1966
switch
(
ct
) {
1967
case
WizardContainer
:
1968
case
PageContainer
:
1969
setText
(
QApplication
::
translate
(
"Command"
,
"Delete Page"
));
1970
break
;
1971
case
MdiContainer
:
1972
setText
(
QApplication
::
translate
(
"Command"
,
"Delete Subwindow"
));
1973
break
;
1974
}
1975
}
1976
1977
void
DeleteContainerWidgetPageCommand
::
redo
()
1978
{
1979
removePage
();
1980
cheapUpdate
();
1981
}
1982
1983
void
DeleteContainerWidgetPageCommand
::
undo
()
1984
{
1985
addPage
();
1986
cheapUpdate
();
1987
}
1988
1989
// ---- AddContainerWidgetPageCommand ----
1990
AddContainerWidgetPageCommand
::
AddContainerWidgetPageCommand
(
QDesignerFormWindowInterface
*
formWindow
)
1991
:
ContainerWidgetCommand
(
formWindow
)
1992
{
1993
}
1994
1995
AddContainerWidgetPageCommand
::~
AddContainerWidgetPageCommand
() =
default
;
1996
1997
void
AddContainerWidgetPageCommand
::
init
(
QWidget
*
containerWidget
,
ContainerType
ct
,
InsertionMode
mode
)
1998
{
1999
m_containerWidget
=
containerWidget
;
2000
2001
if
(
QDesignerContainerExtension
*
c
=
containerExtension
()) {
2002
m_index
=
c
->
currentIndex
();
2003
if
(
m_index
>= 0 &&
mode
==
InsertAfter
)
2004
m_index
++;
2005
m_widget
=
nullptr
;
2006
const
QDesignerFormEditorInterface
*
core
=
formWindow
()->
core
();
2007
switch
(
ct
) {
2008
case
PageContainer
:
2009
setText
(
QApplication
::
translate
(
"Command"
,
"Insert Page"
));
2010
m_widget
=
new
QDesignerWidget
(
formWindow
(),
m_containerWidget
);
2011
m_widget
->
setObjectName
(u"page"_s);
2012
break
;
2013
case
MdiContainer
:
2014
setText
(
QApplication
::
translate
(
"Command"
,
"Insert Subwindow"
));
2015
m_widget
=
new
QDesignerWidget
(
formWindow
(),
m_containerWidget
);
2016
m_widget
->
setObjectName
(u"subwindow"_s);
2017
setPropertySheetWindowTitle
(
core
,
m_widget
,
QApplication
::
translate
(
"Command"
,
"Subwindow"
));
2018
break
;
2019
case
WizardContainer
:
// Apply style, don't manage
2020
m_widget
=
core
->
widgetFactory
()->
createWidget
(u"QWizardPage"_s,
nullptr
);
2021
break
;
2022
}
2023
formWindow
()->
ensureUniqueObjectName
(
m_widget
);
2024
core
->
metaDataBase
()->
add
(
m_widget
);
2025
}
2026
}
2027
2028
void
AddContainerWidgetPageCommand
::
redo
()
2029
{
2030
addPage
();
2031
cheapUpdate
();
2032
}
2033
2034
void
AddContainerWidgetPageCommand
::
undo
()
2035
{
2036
removePage
();
2037
cheapUpdate
();
2038
}
2039
2040
ChangeCurrentPageCommand
::
ChangeCurrentPageCommand
(
QDesignerFormWindowInterface
*
formWindow
)
2041
:
2042
QDesignerFormWindowCommand
(
QString
(),
formWindow
),
m_oldIndex
(0),
m_newIndex
(0)
2043
{
2044
}
2045
2046
ChangeCurrentPageCommand
::~
ChangeCurrentPageCommand
() =
default
;
2047
2048
QDesignerContainerExtension
*
ChangeCurrentPageCommand
::
containerExtension
()
const
2049
{
2050
QExtensionManager
*
mgr
=
core
()->
extensionManager
();
2051
return
qt_extension
<
QDesignerContainerExtension
*>(
mgr
,
m_containerWidget
);
2052
}
2053
2054
void
ChangeCurrentPageCommand
::
init
(
QWidget
*
containerWidget
,
int
newIndex
)
2055
{
2056
m_containerWidget
=
containerWidget
;
2057
2058
if
(
QDesignerContainerExtension
*
c
=
containerExtension
()) {
2059
m_newIndex
=
newIndex
;
2060
m_oldIndex
=
c
->
currentIndex
();
2061
m_widget
=
c
->
widget
(
m_oldIndex
);
2062
}
2063
}
2064
2065
void
ChangeCurrentPageCommand
::
redo
()
2066
{
2067
containerExtension
()->
setCurrentIndex
(
m_newIndex
);
2068
}
2069
2070
void
ChangeCurrentPageCommand
::
undo
()
2071
{
2072
containerExtension
()->
setCurrentIndex
(
m_oldIndex
);
2073
}
2074
2075
static
const
int
itemRoles
[] = {
2076
Qt
::
DecorationPropertyRole
,
2077
Qt
::
DisplayPropertyRole
,
2078
Qt
::
ToolTipPropertyRole
,
2079
Qt
::
StatusTipPropertyRole
,
2080
Qt
::
WhatsThisPropertyRole
,
2081
Qt
::
FontRole
,
2082
Qt
::
TextAlignmentRole
,
2083
Qt
::
BackgroundRole
,
2084
Qt
::
ForegroundRole
,
2085
Qt
::
CheckStateRole
2086
};
2087
2088
template
<
class
T
>
2089
static
void
copyRoleFromItem
(
ItemData
*
id
,
int
role
,
const
T
*
item
)
2090
{
2091
QVariant
v
=
item
->
data
(
role
);
2092
if
(
v
.
isValid
())
2093
id
->
m_properties
.
insert
(
role
,
v
);
2094
}
2095
2096
template
<
class
T
>
2097
static
void
copyRolesFromItem
(
ItemData
*
id
,
const
T
*
item
,
bool
editor
)
2098
{
2099
static
const
Qt
::
ItemFlags
defaultFlags
=
T
().
flags
();
2100
2101
for
(
int
i
:
itemRoles
)
2102
copyRoleFromItem
<
T
>(
id
,
i
,
item
);
2103
2104
if
(
editor
)
2105
copyRoleFromItem
<
T
>(
id
,
ItemFlagsShadowRole
,
item
);
2106
else
if
(
item
->
flags
() !=
defaultFlags
)
2107
id
->
m_properties
.
insert
(
ItemFlagsShadowRole
,
QVariant
::
fromValue
(
int
(
item
->
flags
())));
2108
}
2109
2110
template
<
class
T>
2111
static
void
copyRolesToItem
(
const
ItemData *id, T *item, DesignerIconCache *iconCache,
bool
editor)
2112
{
2113
for
(
auto
it = id->m_properties.cbegin(), end = id->m_properties.cend(); it != end; ++it) {
2114
if
(it.value().isValid()) {
2115
if
(!editor && it.key() ==
ItemFlagsShadowRole
) {
2116
item->setFlags((Qt::ItemFlags)it.value().toInt());
2117
}
else
{
2118
item->setData(it.key(), it.value());
2119
switch
(it.key()) {
2120
case
Qt::DecorationPropertyRole:
2121
if
(iconCache)
2122
item->setIcon(iconCache->icon(qvariant_cast<PropertySheetIconValue>(it.value())));
2123
break
;
2124
case
Qt::DisplayPropertyRole:
2125
item->setText(qvariant_cast<
PropertySheetStringValue
>(it.value()).value());
2126
break
;
2127
case
Qt::ToolTipPropertyRole:
2128
item->setToolTip(qvariant_cast<
PropertySheetStringValue
>(it.value()).value());
2129
break
;
2130
case
Qt::StatusTipPropertyRole:
2131
item->setStatusTip(qvariant_cast<
PropertySheetStringValue
>(it.value()).value());
2132
break
;
2133
case
Qt::WhatsThisPropertyRole:
2134
item->setWhatsThis(qvariant_cast<
PropertySheetStringValue
>(it.value()).value());
2135
break
;
2136
}
2137
}
2138
}
2139
}
2140
2141
if
(editor)
2142
item->setFlags(item->flags() | Qt::ItemIsEditable);
2143
}
2144
2145
ItemData
::
ItemData
(
const
QListWidgetItem
*
item
,
bool
editor
)
2146
{
2147
copyRolesFromItem
<
QListWidgetItem
>(
this
,
item
,
editor
);
2148
}
2149
2150
QListWidgetItem
*
ItemData
::
createListItem
(
DesignerIconCache
*
iconCache
,
bool
editor
)
const
2151
{
2152
auto
*
item
=
new
QListWidgetItem
();
2153
copyRolesToItem
(
this
,
item
,
iconCache
,
editor
);
2154
return
item
;
2155
}
2156
2157
ItemData
::
ItemData
(
const
QTableWidgetItem
*
item
,
bool
editor
)
2158
{
2159
copyRolesFromItem
(
this
,
item
,
editor
);
2160
}
2161
2162
QTableWidgetItem
*
ItemData
::
createTableItem
(
DesignerIconCache
*
iconCache
,
bool
editor
)
const
2163
{
2164
auto
*
item
=
new
QTableWidgetItem
;
2165
copyRolesToItem
(
this
,
item
,
iconCache
,
editor
);
2166
return
item
;
2167
}
2168
2169
static
void
copyRoleFromItem
(
ItemData
*
id
,
int
role
,
const
QTreeWidgetItem
*
item
,
int
column
)
2170
{
2171
QVariant
v
=
item
->
data
(
column
,
role
);
2172
if
(
v
.
isValid
())
2173
id
->
m_properties
.
insert
(
role
,
v
);
2174
}
2175
2176
ItemData
::
ItemData
(
const
QTreeWidgetItem
*
item
,
int
column
)
2177
{
2178
copyRoleFromItem
(
this
,
Qt
::
EditRole
,
item
,
column
);
2179
PropertySheetStringValue
str
(
item
->
text
(
column
));
2180
m_properties
.
insert
(
Qt
::
DisplayPropertyRole
,
QVariant
::
fromValue
(
str
));
2181
2182
for
(
int
i
:
itemRoles
)
2183
copyRoleFromItem
(
this
,
i
,
item
,
column
);
2184
}
2185
2186
void
ItemData
::
fillTreeItemColumn
(
QTreeWidgetItem
*
item
,
int
column
,
DesignerIconCache
*
iconCache
)
const
2187
{
2188
for
(
auto
it
=
m_properties
.
cbegin
(),
end
=
m_properties
.
cend
();
it
!=
end
; ++
it
) {
2189
if
(
it
.
value
().
isValid
()) {
2190
item
->
setData
(
column
,
it
.
key
(),
it
.
value
());
2191
switch
(
it
.
key
()) {
2192
case
Qt
::
DecorationPropertyRole
:
2193
if
(
iconCache
)
2194
item
->
setIcon
(
column
,
iconCache
->
icon
(
qvariant_cast
<
PropertySheetIconValue
>(
it
.
value
())));
2195
break
;
2196
case
Qt
::
DisplayPropertyRole
:
2197
item
->
setText
(
column
,
qvariant_cast
<
PropertySheetStringValue
>(
it
.
value
()).
value
());
2198
break
;
2199
case
Qt
::
ToolTipPropertyRole
:
2200
item
->
setToolTip
(
column
,
qvariant_cast
<
PropertySheetStringValue
>(
it
.
value
()).
value
());
2201
break
;
2202
case
Qt
::
StatusTipPropertyRole
:
2203
item
->
setStatusTip
(
column
,
qvariant_cast
<
PropertySheetStringValue
>(
it
.
value
()).
value
());
2204
break
;
2205
case
Qt
::
WhatsThisPropertyRole
:
2206
item
->
setWhatsThis
(
column
,
qvariant_cast
<
PropertySheetStringValue
>(
it
.
value
()).
value
());
2207
break
;
2208
}
2209
}
2210
}
2211
}
2212
2213
ListContents
::
ListContents
(
const
QTreeWidgetItem
*
item
)
2214
{
2215
for
(
int
i
= 0;
i
<
item
->
columnCount
();
i
++)
2216
m_items
.
append
(
ItemData
(
item
,
i
));
2217
}
2218
2219
QTreeWidgetItem
*
ListContents
::
createTreeItem
(
DesignerIconCache
*
iconCache
)
const
2220
{
2221
auto
*
item
=
new
QTreeWidgetItem
;
2222
int
i
= 0;
2223
for
(
const
ItemData
&
id
:
m_items
)
2224
id
.
fillTreeItemColumn
(
item
,
i
++,
iconCache
);
2225
return
item
;
2226
}
2227
2228
void
ListContents
::
createFromListWidget
(
const
QListWidget
*
listWidget
,
bool
editor
)
2229
{
2230
m_items
.
clear
();
2231
2232
for
(
int
i
= 0;
i
<
listWidget
->
count
();
i
++)
2233
m_items
.
append
(
ItemData
(
listWidget
->
item
(
i
),
editor
));
2234
}
2235
2236
void
ListContents
::
applyToListWidget
(
QListWidget
*
listWidget
,
DesignerIconCache
*
iconCache
,
2237
bool
editor
,
Qt
::
Alignment
alignmentDefault
)
const
2238
{
2239
listWidget
->
clear
();
2240
2241
int
i
= 0;
2242
for
(
const
ItemData
&
entry
:
m_items
) {
2243
auto
*
item
=
entry
.
isValid
()
2244
?
entry
.
createListItem
(
iconCache
,
editor
)
2245
:
new
QListWidgetItem
(
TableWidgetContents
::
defaultHeaderText
(
i
));
2246
if
(
item
->
textAlignment
() == 0)
2247
item
->
setTextAlignment
(
alignmentDefault
);
2248
listWidget
->
addItem
(
item
);
2249
i
++;
2250
}
2251
}
2252
2253
void
ListContents
::
createFromComboBox
(
const
QComboBox
*
comboBox
)
2254
{
2255
m_items
.
clear
();
2256
2257
const
int
count
=
comboBox
->
count
();
2258
for
(
int
i
= 0;
i
<
count
;
i
++) {
2259
// We might encounter items added in a custom combo
2260
// constructor. Ignore those.
2261
const
QVariant
textValue
=
comboBox
->
itemData
(
i
,
Qt
::
DisplayPropertyRole
);
2262
if
(!
textValue
.
isNull
()) {
2263
ItemData
entry
;
2264
entry
.
m_properties
.
insert
(
Qt
::
DisplayPropertyRole
,
textValue
);
2265
const
QVariant
iconValue
=
comboBox
->
itemData
(
i
,
Qt
::
DecorationPropertyRole
);
2266
if
(!
iconValue
.
isNull
())
2267
entry
.
m_properties
.
insert
(
Qt
::
DecorationPropertyRole
,
iconValue
);
2268
m_items
.
append
(
entry
);
2269
}
2270
}
2271
}
2272
2273
void
ListContents
::
applyToComboBox
(
QComboBox
*
comboBox
,
DesignerIconCache
*
iconCache
)
const
2274
{
2275
comboBox
->
clear
();
2276
2277
for
(
const
ItemData
&
hash
:
m_items
) {
2278
QIcon
icon
;
2279
if
(
iconCache
)
2280
icon
=
iconCache
->
icon
(
qvariant_cast
<
PropertySheetIconValue
>(
2281
hash
.
m_properties
[
Qt
::
DecorationPropertyRole
]));
2282
QVariant
var
=
hash
.
m_properties
[
Qt
::
DisplayPropertyRole
];
2283
auto
str
=
qvariant_cast
<
PropertySheetStringValue
>(
var
);
2284
comboBox
->
addItem
(
icon
,
str
.
value
());
2285
comboBox
->
setItemData
(
comboBox
->
count
() - 1,
2286
var
,
2287
Qt
::
DisplayPropertyRole
);
2288
comboBox
->
setItemData
(
comboBox
->
count
() - 1,
2289
hash
.
m_properties
[
Qt
::
DecorationPropertyRole
],
2290
Qt
::
DecorationPropertyRole
);
2291
}
2292
}
2293
2294
// --------- TableWidgetContents
2295
2296
TableWidgetContents
::
TableWidgetContents
() =
default
;
2297
2298
void
TableWidgetContents
::
clear
()
2299
{
2300
m_horizontalHeader
.
m_items
.
clear
();
2301
m_verticalHeader
.
m_items
.
clear
();
2302
m_items
.
clear
();
2303
m_columnCount
= 0;
2304
m_rowCount
= 0;
2305
}
2306
2307
QString
TableWidgetContents
::
defaultHeaderText
(
int
i
)
2308
{
2309
return
QString
::
number
(
i
+ 1);
2310
}
2311
2312
bool
TableWidgetContents
::
nonEmpty
(
const
QTableWidgetItem
*
item
,
int
headerColumn
)
2313
{
2314
static
const
Qt
::
ItemFlags
defaultFlags
=
QTableWidgetItem
().
flags
();
2315
2316
if
(
item
->
flags
() !=
defaultFlags
)
2317
return
true
;
2318
2319
QString
text
=
qvariant_cast
<
PropertySheetStringValue
>(
item
->
data
(
Qt
::
DisplayPropertyRole
)).
value
();
2320
if
(!
text
.
isEmpty
()) {
2321
if
(
headerColumn
< 0 ||
text
!=
defaultHeaderText
(
headerColumn
))
2322
return
true
;
2323
}
else
{
2324
// FIXME: This doesn't seem to make sense
2325
return
true
;
2326
}
2327
2328
auto
pred
= [
item
](
int
i
) {
2329
return
i
!=
Qt
::
DisplayPropertyRole
&&
item
->
data
(
i
).
isValid
();
2330
};
2331
return
std
::
any_of
(
std
::
begin
(
itemRoles
),
std
::
end
(
itemRoles
),
pred
);
2332
}
2333
2334
void
TableWidgetContents
::
insertHeaderItem
(
const
QTableWidgetItem
*
item
,
int
i
,
ListContents
*
header
,
bool
editor
)
2335
{
2336
if
(
nonEmpty
(
item
,
i
))
2337
header
->
m_items
.
append
(
ItemData
(
item
,
editor
));
2338
else
2339
header
->
m_items
.
append
(
ItemData
());
2340
}
2341
2342
void
TableWidgetContents
::
fromTableWidget
(
const
QTableWidget
*
tableWidget
,
bool
editor
)
2343
{
2344
clear
();
2345
m_columnCount
=
tableWidget
->
columnCount
();
2346
m_rowCount
=
tableWidget
->
rowCount
();
2347
// horiz header: Legacy behaviour: auto-generate number for empty items
2348
for
(
int
col
= 0;
col
<
m_columnCount
;
col
++)
2349
if
(
const
QTableWidgetItem
*
item
=
tableWidget
->
horizontalHeaderItem
(
col
))
2350
insertHeaderItem
(
item
,
col
, &
m_horizontalHeader
,
editor
);
2351
// vertical header: Legacy behaviour: auto-generate number for empty items
2352
for
(
int
row
= 0;
row
<
m_rowCount
;
row
++)
2353
if
(
const
QTableWidgetItem
*
item
=
tableWidget
->
verticalHeaderItem
(
row
))
2354
insertHeaderItem
(
item
,
row
, &
m_verticalHeader
,
editor
);
2355
// cell data
2356
for
(
int
col
= 0;
col
<
m_columnCount
;
col
++)
2357
for
(
int
row
= 0;
row
<
m_rowCount
;
row
++)
2358
if
(
const
QTableWidgetItem
*
item
=
tableWidget
->
item
(
row
,
col
))
2359
if
(
nonEmpty
(
item
, -1))
2360
m_items
.
insert
(
CellRowColumnAddress
(
row
,
col
),
ItemData
(
item
,
editor
));
2361
}
2362
2363
void
TableWidgetContents
::
applyToTableWidget
(
QTableWidget
*
tableWidget
,
DesignerIconCache
*
iconCache
,
bool
editor
)
const
2364
{
2365
tableWidget
->
clear
();
2366
2367
tableWidget
->
setColumnCount
(
m_columnCount
);
2368
tableWidget
->
setRowCount
(
m_rowCount
);
2369
2370
// horiz header
2371
int
col
= 0;
2372
for
(
const
ItemData
&
id
:
m_horizontalHeader
.
m_items
) {
2373
if
(
id
.
isValid
())
2374
tableWidget
->
setHorizontalHeaderItem
(
col
,
id
.
createTableItem
(
iconCache
,
editor
));
2375
col
++;
2376
}
2377
// vertical header
2378
int
row
= 0;
2379
for
(
const
ItemData
&
id
:
m_verticalHeader
.
m_items
) {
2380
if
(
id
.
isValid
())
2381
tableWidget
->
setVerticalHeaderItem
(
row
,
id
.
createTableItem
(
iconCache
,
editor
));
2382
row
++;
2383
}
2384
// items
2385
for
(
auto
it
=
m_items
.
cbegin
(),
icend
=
m_items
.
cend
();
it
!=
icend
; ++
it
) {
2386
tableWidget
->
setItem
(
it
.
key
().
first
,
it
.
key
().
second
,
2387
it
.
value
().
createTableItem
(
iconCache
,
editor
));
2388
}
2389
}
2390
2391
bool
comparesEqual
(
const
TableWidgetContents &lhs,
2392
const
TableWidgetContents &rhs)
noexcept
2393
{
2394
return
lhs.m_columnCount == rhs.m_columnCount && lhs.m_rowCount == rhs.m_rowCount &&
2395
lhs.m_horizontalHeader.m_items == rhs.m_horizontalHeader.m_items &&
2396
lhs.m_verticalHeader.m_items == rhs.m_verticalHeader.m_items &&
2397
lhs.m_items == rhs.m_items;
2398
}
2399
2400
// ---- ChangeTableContentsCommand ----
2401
ChangeTableContentsCommand
::
ChangeTableContentsCommand
(
QDesignerFormWindowInterface
*
formWindow
) :
2402
QDesignerFormWindowCommand
(
QApplication
::
translate
(
"Command"
,
"Change Table Contents"
),
2403
formWindow
),
m_iconCache
(
nullptr
)
2404
{
2405
if
(
auto
*
fwb
=
qobject_cast
<
FormWindowBase
*>(
formWindow
))
2406
m_iconCache
=
fwb
->
iconCache
();
2407
}
2408
2409
void
ChangeTableContentsCommand
::
init
(
QTableWidget
*
tableWidget
,
2410
const
TableWidgetContents
&
oldCont
,
const
TableWidgetContents
&
newCont
)
2411
{
2412
m_tableWidget
=
tableWidget
;
2413
m_oldContents
=
oldCont
;
2414
m_newContents
=
newCont
;
2415
}
2416
2417
void
ChangeTableContentsCommand
::
redo
()
2418
{
2419
m_newContents
.
applyToTableWidget
(
m_tableWidget
,
m_iconCache
,
false
);
2420
QMetaObject
::
invokeMethod
(
m_tableWidget
,
"updateGeometries"
);
2421
}
2422
2423
void
ChangeTableContentsCommand
::
undo
()
2424
{
2425
m_oldContents
.
applyToTableWidget
(
m_tableWidget
,
m_iconCache
,
false
);
2426
QMetaObject
::
invokeMethod
(
m_tableWidget
,
"updateGeometries"
);
2427
}
2428
2429
// --------- TreeWidgetContents
2430
TreeWidgetContents
::
ItemContents
::
ItemContents
(
const
QTreeWidgetItem
*
item
,
bool
editor
) :
2431
ListContents
(
item
)
2432
{
2433
static
const
Qt
::
ItemFlags
defaultFlags
=
QTreeWidgetItem
().
flags
();
2434
2435
if
(
editor
) {
2436
QVariant
v
=
item
->
data
(0,
ItemFlagsShadowRole
);
2437
m_itemFlags
=
v
.
isValid
() ?
v
.
toInt
() : -1;
2438
}
else
{
2439
m_itemFlags
= (
item
->
flags
() !=
defaultFlags
) ?
int
(
item
->
flags
()) : -1;
2440
}
2441
2442
for
(
int
i
= 0;
i
<
item
->
childCount
();
i
++)
2443
m_children
.
append
(
ItemContents
(
item
->
child
(
i
),
editor
));
2444
}
2445
2446
QTreeWidgetItem
*
TreeWidgetContents
::
ItemContents
::
createTreeItem
(
DesignerIconCache
*
iconCache
,
bool
editor
)
const
2447
{
2448
QTreeWidgetItem
*
item
=
ListContents
::
createTreeItem
(
iconCache
);
2449
2450
if
(
editor
)
2451
item
->
setFlags
(
item
->
flags
() |
Qt
::
ItemIsEditable
);
2452
2453
if
(
m_itemFlags
!= -1) {
2454
if
(
editor
)
2455
item
->
setData
(0,
ItemFlagsShadowRole
,
QVariant
::
fromValue
(
m_itemFlags
));
2456
else
2457
item
->
setFlags
((
Qt
::
ItemFlags
)
m_itemFlags
);
2458
}
2459
2460
for
(
const
ItemContents
&
ic
:
m_children
)
2461
item
->
addChild
(
ic
.
createTreeItem
(
iconCache
,
editor
));
2462
2463
return
item
;
2464
}
2465
2466
bool
comparesEqual
(
const
TreeWidgetContents::ItemContents &lhs,
2467
const
TreeWidgetContents::ItemContents &rhs)
noexcept
2468
{
2469
return
lhs.m_itemFlags == rhs.m_itemFlags && lhs.m_items == rhs.m_items
2470
&& lhs.m_children == rhs.m_children;
2471
}
2472
2473
void
TreeWidgetContents
::
clear
()
2474
{
2475
m_headerItem
.
m_items
.
clear
();
2476
m_rootItems
.
clear
();
2477
}
2478
2479
void
TreeWidgetContents
::
fromTreeWidget
(
const
QTreeWidget
*
treeWidget
,
bool
editor
)
2480
{
2481
clear
();
2482
m_headerItem
=
ListContents
(
treeWidget
->
headerItem
());
2483
for
(
int
col
= 0;
col
<
treeWidget
->
topLevelItemCount
();
col
++)
2484
m_rootItems
.
append
(
ItemContents
(
treeWidget
->
topLevelItem
(
col
),
editor
));
2485
}
2486
2487
void
TreeWidgetContents
::
applyToTreeWidget
(
QTreeWidget
*
treeWidget
,
DesignerIconCache
*
iconCache
,
bool
editor
)
const
2488
{
2489
treeWidget
->
clear
();
2490
2491
treeWidget
->
setColumnCount
(
m_headerItem
.
m_items
.
size
());
2492
treeWidget
->
setHeaderItem
(
m_headerItem
.
createTreeItem
(
iconCache
));
2493
for
(
const
ItemContents
&
ic
:
m_rootItems
)
2494
treeWidget
->
addTopLevelItem
(
ic
.
createTreeItem
(
iconCache
,
editor
));
2495
treeWidget
->
expandAll
();
2496
}
2497
2498
// ---- ChangeTreeContentsCommand ----
2499
ChangeTreeContentsCommand
::
ChangeTreeContentsCommand
(
QDesignerFormWindowInterface
*
formWindow
)
2500
:
QDesignerFormWindowCommand
(
QApplication
::
translate
(
"Command"
,
"Change Tree Contents"
),
formWindow
),
2501
m_iconCache
(
nullptr
)
2502
{
2503
if
(
auto
*
fwb
=
qobject_cast
<
FormWindowBase
*>(
formWindow
))
2504
m_iconCache
=
fwb
->
iconCache
();
2505
}
2506
2507
void
ChangeTreeContentsCommand
::
init
(
QTreeWidget
*
treeWidget
,
2508
const
TreeWidgetContents
&
oldState
,
const
TreeWidgetContents
&
newState
)
2509
{
2510
m_treeWidget
=
treeWidget
;
2511
m_oldState
=
oldState
;
2512
m_newState
=
newState
;
2513
}
2514
2515
void
ChangeTreeContentsCommand
::
redo
()
2516
{
2517
m_newState
.
applyToTreeWidget
(
m_treeWidget
,
m_iconCache
,
false
);
2518
}
2519
2520
void
ChangeTreeContentsCommand
::
undo
()
2521
{
2522
m_oldState
.
applyToTreeWidget
(
m_treeWidget
,
m_iconCache
,
false
);
2523
}
2524
2525
// ---- ChangeListContentsCommand ----
2526
ChangeListContentsCommand
::
ChangeListContentsCommand
(
QDesignerFormWindowInterface
*
formWindow
)
2527
:
QDesignerFormWindowCommand
(
QString
(),
formWindow
),
m_iconCache
(
nullptr
)
2528
{
2529
if
(
auto
*
fwb
=
qobject_cast
<
FormWindowBase
*>(
formWindow
))
2530
m_iconCache
=
fwb
->
iconCache
();
2531
}
2532
2533
void
ChangeListContentsCommand
::
init
(
QListWidget
*
listWidget
,
2534
const
ListContents
&
oldItems
,
const
ListContents
&
items
)
2535
{
2536
m_listWidget
=
listWidget
;
2537
m_comboBox
=
nullptr
;
2538
2539
m_newItemsState
=
items
;
2540
m_oldItemsState
=
oldItems
;
2541
}
2542
2543
void
ChangeListContentsCommand
::
init
(
QComboBox
*
comboBox
,
2544
const
ListContents
&
oldItems
,
const
ListContents
&
items
)
2545
{
2546
m_listWidget
=
nullptr
;
2547
m_comboBox
=
comboBox
;
2548
2549
m_newItemsState
=
items
;
2550
m_oldItemsState
=
oldItems
;
2551
}
2552
2553
void
ChangeListContentsCommand
::
redo
()
2554
{
2555
if
(
m_listWidget
)
2556
m_newItemsState
.
applyToListWidget
(
m_listWidget
,
m_iconCache
,
false
);
2557
else
if
(
m_comboBox
)
2558
m_newItemsState
.
applyToComboBox
(
m_comboBox
,
m_iconCache
);
2559
}
2560
2561
void
ChangeListContentsCommand
::
undo
()
2562
{
2563
if
(
m_listWidget
)
2564
m_oldItemsState
.
applyToListWidget
(
m_listWidget
,
m_iconCache
,
false
);
2565
else
if
(
m_comboBox
)
2566
m_oldItemsState
.
applyToComboBox
(
m_comboBox
,
m_iconCache
);
2567
}
2568
2569
// ---- AddActionCommand ----
2570
2571
AddActionCommand
::
AddActionCommand
(
QDesignerFormWindowInterface
*
formWindow
) :
2572
QDesignerFormWindowCommand
(
QApplication
::
translate
(
"Command"
,
"Add action"
),
formWindow
)
2573
{
2574
}
2575
2576
void
AddActionCommand
::
init
(
QAction
*
action
)
2577
{
2578
Q_ASSERT
(
m_action
==
nullptr
);
2579
m_action
=
action
;
2580
}
2581
2582
void
AddActionCommand
::
redo
()
2583
{
2584
core
()->
actionEditor
()->
setFormWindow
(
formWindow
());
2585
core
()->
actionEditor
()->
manageAction
(
m_action
);
2586
}
2587
2588
void
AddActionCommand
::
undo
()
2589
{
2590
core
()->
actionEditor
()->
setFormWindow
(
formWindow
());
2591
core
()->
actionEditor
()->
unmanageAction
(
m_action
);
2592
}
2593
2594
// ---- RemoveActionCommand ----
2595
2596
RemoveActionCommand
::
RemoveActionCommand
(
QDesignerFormWindowInterface
*
formWindow
) :
2597
QDesignerFormWindowCommand
(
QApplication
::
translate
(
"Command"
,
"Remove action"
),
formWindow
)
2598
{
2599
}
2600
2601
static
RemoveActionCommand
::
ActionData
findActionIn
(
QAction
*
action
)
2602
{
2603
RemoveActionCommand
::
ActionData
result
;
2604
// We only want menus and toolbars, no toolbuttons.
2605
const
QObjectList
associatedObjects
=
action
->
associatedObjects
();
2606
for
(
QObject
*
obj
:
associatedObjects
) {
2607
if
(!
qobject_cast
<
const
QMenu
*>(
obj
) && !
qobject_cast
<
const
QToolBar
*>(
obj
))
2608
continue
;
2609
auto
*
widget
=
static_cast
<
QWidget
*>(
obj
);
2610
const
auto
actionList
=
widget
->
actions
();
2611
for
(
qsizetype
i
= 0,
size
=
actionList
.
size
();
i
<
size
; ++
i
) {
2612
if
(
actionList
.
at
(
i
) ==
action
) {
2613
QAction
*
before
=
nullptr
;
2614
if
(
i
+ 1 <
size
)
2615
before
=
actionList
.
at
(
i
+ 1);
2616
result
.
append
(
RemoveActionCommand
::
ActionDataItem
(
before
,
widget
));
2617
break
;
2618
}
2619
}
2620
}
2621
return
result
;
2622
}
2623
2624
void
RemoveActionCommand
::
init
(
QAction
*
action
)
2625
{
2626
Q_ASSERT
(
m_action
==
nullptr
);
2627
m_action
=
action
;
2628
2629
m_actionData
=
findActionIn
(
action
);
2630
}
2631
2632
void
RemoveActionCommand
::
redo
()
2633
{
2634
QDesignerFormWindowInterface
*
fw
=
formWindow
();
2635
for
(
const
ActionDataItem
&
item
:
std
::
as_const
(
m_actionData
)) {
2636
item
.
widget
->
removeAction
(
m_action
);
2637
}
2638
// Notify components (for example, signal slot editor)
2639
if
(
auto
*
fwb
=
qobject_cast
<
qdesigner_internal
::
FormWindowBase
*>(
fw
))
2640
fwb
->
emitObjectRemoved
(
m_action
);
2641
2642
core
()->
actionEditor
()->
setFormWindow
(
fw
);
2643
core
()->
actionEditor
()->
unmanageAction
(
m_action
);
2644
if
(!
m_actionData
.
isEmpty
())
2645
core
()->
objectInspector
()->
setFormWindow
(
fw
);
2646
}
2647
2648
void
RemoveActionCommand
::
undo
()
2649
{
2650
core
()->
actionEditor
()->
setFormWindow
(
formWindow
());
2651
core
()->
actionEditor
()->
manageAction
(
m_action
);
2652
for
(
const
ActionDataItem
&
item
:
std
::
as_const
(
m_actionData
))
2653
item
.
widget
->
insertAction
(
item
.
before
,
m_action
);
2654
if
(!
m_actionData
.
isEmpty
())
2655
core
()->
objectInspector
()->
setFormWindow
(
formWindow
());
2656
}
2657
2658
// ---- ActionInsertionCommand ----
2659
2660
ActionInsertionCommand
::
ActionInsertionCommand
(
const
QString
&
text
,
QDesignerFormWindowInterface
*
formWindow
) :
2661
QDesignerFormWindowCommand
(
text
,
formWindow
),
2662
m_parentWidget
(
nullptr
),
2663
m_action
(
nullptr
),
2664
m_beforeAction
(
nullptr
),
2665
m_update
(
false
)
2666
{
2667
}
2668
2669
void
ActionInsertionCommand
::
init
(
QWidget
*
parentWidget
,
QAction
*
action
,
QAction
*
beforeAction
,
bool
update
)
2670
{
2671
Q_ASSERT
(
m_parentWidget
==
nullptr
);
2672
Q_ASSERT
(
m_action
==
nullptr
);
2673
2674
m_parentWidget
=
parentWidget
;
2675
m_action
=
action
;
2676
m_beforeAction
=
beforeAction
;
2677
m_update
=
update
;
2678
}
2679
2680
void
ActionInsertionCommand
::
insertAction
()
2681
{
2682
Q_ASSERT
(
m_action
!=
nullptr
);
2683
Q_ASSERT
(
m_parentWidget
!=
nullptr
);
2684
2685
if
(
m_beforeAction
)
2686
m_parentWidget
->
insertAction
(
m_beforeAction
,
m_action
);
2687
else
2688
m_parentWidget
->
addAction
(
m_action
);
2689
2690
if
(
m_update
) {
2691
cheapUpdate
();
2692
if
(
QMenu
*
menu
=
m_action
->
menu
())
2693
selectUnmanagedObject
(
menu
);
2694
else
2695
selectUnmanagedObject
(
m_action
);
2696
PropertyHelper
::
triggerActionChanged
(
m_action
);
// Update Used column in action editor.
2697
}
2698
}
2699
void
ActionInsertionCommand
::
removeAction
()
2700
{
2701
Q_ASSERT
(
m_action
!=
nullptr
);
2702
Q_ASSERT
(
m_parentWidget
!=
nullptr
);
2703
2704
if
(
auto
*
menu
=
qobject_cast
<
QDesignerMenu
*>(
m_parentWidget
))
2705
menu
->
hideSubMenu
();
2706
2707
m_parentWidget
->
removeAction
(
m_action
);
2708
2709
if
(
m_update
) {
2710
cheapUpdate
();
2711
selectUnmanagedObject
(
m_parentWidget
);
2712
PropertyHelper
::
triggerActionChanged
(
m_action
);
// Update Used column in action editor.
2713
}
2714
}
2715
2716
InsertActionIntoCommand
::
InsertActionIntoCommand
(
QDesignerFormWindowInterface
*
formWindow
) :
2717
ActionInsertionCommand
(
QApplication
::
translate
(
"Command"
,
"Add action"
),
formWindow
)
2718
{
2719
}
2720
// ---- RemoveActionFromCommand ----
2721
2722
RemoveActionFromCommand
::
RemoveActionFromCommand
(
QDesignerFormWindowInterface
*
formWindow
) :
2723
ActionInsertionCommand
(
QApplication
::
translate
(
"Command"
,
"Remove action"
),
formWindow
)
2724
{
2725
}
2726
2727
// ---- AddMenuActionCommand ----
2728
2729
MenuActionCommand
::
MenuActionCommand
(
const
QString
&
text
,
QDesignerFormWindowInterface
*
formWindow
) :
2730
QDesignerFormWindowCommand
(
text
,
formWindow
),
2731
m_action
(
nullptr
),
2732
m_actionBefore
(
nullptr
),
2733
m_menuParent
(
nullptr
),
2734
m_associatedWidget
(
nullptr
),
2735
m_objectToSelect
(
nullptr
)
2736
{
2737
}
2738
2739
void
MenuActionCommand
::
init
(
QAction
*
action
,
QAction
*
actionBefore
,
2740
QWidget
*
associatedWidget
,
QWidget
*
objectToSelect
)
2741
{
2742
QMenu *menu =
action
->
menu
();
2743
Q_ASSERT
(
menu
);
2744
m_menuParent
=
menu
->
parentWidget
();
2745
m_action
=
action
;
2746
m_actionBefore
=
actionBefore
;
2747
m_associatedWidget
=
associatedWidget
;
2748
m_objectToSelect
=
objectToSelect
;
2749
}
2750
2751
void
MenuActionCommand
::
insertMenu
()
2752
{
2753
core
()->
metaDataBase
()->
add
(
m_action
);
2754
QMenu *menu =
m_action
->
menu
();
2755
if
(
m_menuParent
&&
menu
->
parentWidget
() !=
m_menuParent
)
2756
menu
->
setParent
(
m_menuParent
);
2757
core
()->
metaDataBase
()->
add
(
menu
);
2758
m_associatedWidget
->
insertAction
(
m_actionBefore
,
m_action
);
2759
cheapUpdate
();
2760
selectUnmanagedObject
(
menu
);
2761
}
2762
2763
void
MenuActionCommand
::
removeMenu
()
2764
{
2765
m_action
->
menu
()->
setParent
(
nullptr
);
2766
QMenu *menu =
m_action
->
menu
();
2767
core
()->
metaDataBase
()->
remove
(
menu
);
2768
menu
->
setParent
(
nullptr
);
2769
core
()->
metaDataBase
()->
remove
(
m_action
);
2770
m_associatedWidget
->
removeAction
(
m_action
);
2771
cheapUpdate
();
2772
selectUnmanagedObject
(
m_objectToSelect
);
2773
}
2774
2775
AddMenuActionCommand
::
AddMenuActionCommand
(
QDesignerFormWindowInterface
*
formWindow
) :
2776
MenuActionCommand
(
QApplication
::
translate
(
"Command"
,
"Add menu"
),
formWindow
)
2777
{
2778
}
2779
2780
// ---- RemoveMenuActionCommand ----
2781
RemoveMenuActionCommand
::
RemoveMenuActionCommand
(
QDesignerFormWindowInterface
*
formWindow
) :
2782
MenuActionCommand
(
QApplication
::
translate
(
"Command"
,
"Remove menu"
),
formWindow
)
2783
{
2784
}
2785
2786
// ---- CreateSubmenuCommand ----
2787
CreateSubmenuCommand
::
CreateSubmenuCommand
(
QDesignerFormWindowInterface
*
formWindow
) :
2788
QDesignerFormWindowCommand
(
QApplication
::
translate
(
"Command"
,
"Create submenu"
),
formWindow
),
2789
m_action
(
nullptr
),
2790
m_menu
(
nullptr
),
2791
m_objectToSelect
(
nullptr
)
2792
{
2793
}
2794
2795
void
CreateSubmenuCommand
::
init
(
QDesignerMenu
*
menu
,
QAction
*
action
,
QObject
*
objectToSelect
)
2796
{
2797
m_menu
=
menu
;
2798
m_action
=
action
;
2799
m_objectToSelect
=
objectToSelect
;
2800
}
2801
2802
void
CreateSubmenuCommand
::
redo
()
2803
{
2804
m_menu
->
createRealMenuAction
(
m_action
);
2805
cheapUpdate
();
2806
if
(
m_objectToSelect
)
2807
selectUnmanagedObject
(
m_objectToSelect
);
2808
}
2809
2810
void
CreateSubmenuCommand
::
undo
()
2811
{
2812
m_menu
->
removeRealMenu
(
m_action
);
2813
cheapUpdate
();
2814
selectUnmanagedObject
(
m_menu
);
2815
}
2816
2817
// ---- DeleteToolBarCommand ----
2818
DeleteToolBarCommand
::
DeleteToolBarCommand
(
QDesignerFormWindowInterface
*
formWindow
)
2819
:
QDesignerFormWindowCommand
(
QApplication
::
translate
(
"Command"
,
"Delete Tool Bar"
),
formWindow
)
2820
{
2821
}
2822
2823
void
DeleteToolBarCommand
::
init
(
QToolBar
*
toolBar
)
2824
{
2825
m_toolBar
=
toolBar
;
2826
m_mainWindow
=
qobject_cast
<
QMainWindow
*>(
toolBar
->
parentWidget
());
2827
}
2828
2829
void
DeleteToolBarCommand
::
redo
()
2830
{
2831
if
(
m_mainWindow
) {
2832
QDesignerContainerExtension
*c = qt_extension<
QDesignerContainerExtension
*>(core()->extensionManager(), m_mainWindow);
2833
Q_ASSERT
(
c
!=
nullptr
);
2834
for
(
int
i=0;
i
<
c
->
count
(); ++
i
) {
2835
if
(
c
->
widget
(
i
) ==
m_toolBar
) {
2836
c
->
remove
(
i
);
2837
break
;
2838
}
2839
}
2840
}
2841
2842
core
()->
metaDataBase
()->
remove
(
m_toolBar
);
2843
m_toolBar
->
hide
();
2844
m_toolBar
->
setParent
(
formWindow
());
2845
formWindow
()->
emitSelectionChanged
();
2846
}
2847
2848
void
DeleteToolBarCommand
::
undo
()
2849
{
2850
if
(
m_mainWindow
) {
2851
m_toolBar
->
setParent
(
m_mainWindow
);
2852
QDesignerContainerExtension
*c = qt_extension<
QDesignerContainerExtension
*>(core()->extensionManager(), m_mainWindow);
2853
2854
c
->
addWidget
(
m_toolBar
);
2855
2856
core
()->
metaDataBase
()->
add
(
m_toolBar
);
2857
m_toolBar
->
show
();
2858
formWindow
()->
emitSelectionChanged
();
2859
}
2860
}
2861
2862
}
// namespace qdesigner_internal
2863
2864
QT_END_NAMESPACE
QDesignerContainerExtension
Definition
container.h:16
QDesignerPropertySheetExtension
Definition
propertysheet.h:15
QPainter::QWidget
friend class QWidget
Definition
qpainter.h:432
qdesigner_internal::PropertySheetStringValue
Definition
qdesigner_utils_p.h:385
qdesigner_internal
Auxiliary methods to store/retrieve settings.
Definition
buddyeditor.cpp:67
qdesigner_internal::itemRoles
static const int itemRoles[]
Definition
qdesigner_command.cpp:2075
qdesigner_internal::copyRoleFromItem
static void copyRoleFromItem(ItemData *id, int role, const T *item)
Definition
qdesigner_command.cpp:2089
qdesigner_internal::copyRolesToItem
static void copyRolesToItem(const ItemData *id, T *item, DesignerIconCache *iconCache, bool editor)
Definition
qdesigner_command.cpp:2111
qdesigner_internal::copyRolesFromItem
static void copyRolesFromItem(ItemData *id, const T *item, bool editor)
Definition
qdesigner_command.cpp:2097
qdesigner_internal::removeFromWidgetListDynamicProperty
static int removeFromWidgetListDynamicProperty(QWidget *parentWidget, QWidget *widget, const char *name)
Definition
qdesigner_command.cpp:87
qdesigner_internal::findActionIn
static RemoveActionCommand::ActionData findActionIn(QAction *action)
Definition
qdesigner_command.cpp:2601
qdesigner_internal::copyRoleFromItem
static void copyRoleFromItem(ItemData *id, int role, const QTreeWidgetItem *item, int column)
Definition
qdesigner_command.cpp:2169
qdesigner_internal::addToWidgetListDynamicProperty
static void addToWidgetListDynamicProperty(QWidget *parentWidget, QWidget *widget, const char *name, int index=-1)
Definition
qdesigner_command.cpp:75
qdesigner_internal::recursiveUpdate
static void recursiveUpdate(QWidget *w)
Definition
qdesigner_command.cpp:132
qdesigner_internal::widgetOrderPropertyC
static const char widgetOrderPropertyC[]
Definition
qdesigner_command.cpp:72
qdesigner_internal::zOrderPropertyC
static const char zOrderPropertyC[]
Definition
qdesigner_command.cpp:73
qdesigner_internal::ItemFlagsShadowRole
@ ItemFlagsShadowRole
Definition
shared_enums_p.h:55
qdesigner_internal::comparesEqual
bool comparesEqual(const DeviceProfile &lhs, const DeviceProfile &rhs) noexcept
Definition
deviceprofile.cpp:267
setPropertySheetWindowTitle
static void setPropertySheetWindowTitle(const QDesignerFormEditorInterface *core, QObject *o, const QString &t)
Definition
qdesigner_command.cpp:58
qttools
src
designer
src
lib
shared
qdesigner_command.cpp
Generated on
for Qt by
1.18.0