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_command2.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_command2_p.h"
6
#
include
"formwindowbase_p.h"
7
#
include
"layoutinfo_p.h"
8
#
include
"qdesigner_command_p.h"
9
#
include
"widgetfactory_p.h"
10
#
include
"qlayout_widget_p.h"
11
12
#
include
<
QtDesigner
/
abstractformeditor
.
h
>
13
#
include
<
QtDesigner
/
abstractmetadatabase
.
h
>
14
15
#
include
<
QtWidgets
/
qapplication
.
h
>
16
#
include
<
QtWidgets
/
qlayout
.
h
>
17
18
QT_BEGIN_NAMESPACE
19
20
namespace
qdesigner_internal
{
21
22
MorphLayoutCommand
::
MorphLayoutCommand
(
QDesignerFormWindowInterface
*
formWindow
) :
23
QDesignerFormWindowCommand
(
QString
(),
formWindow
),
24
m_breakLayoutCommand
(
new
BreakLayoutCommand
(
formWindow
)),
25
m_layoutCommand
(
new
LayoutCommand
(
formWindow
)),
26
m_newType
(
LayoutInfo
::
VBox
),
27
m_layoutBase
(
nullptr
)
28
{
29
}
30
31
MorphLayoutCommand
::~
MorphLayoutCommand
()
32
{
33
delete
m_layoutCommand
;
34
delete
m_breakLayoutCommand
;
35
}
36
37
bool
MorphLayoutCommand
::
init
(
QWidget
*
w
,
int
newType
)
38
{
39
int
oldType
;
40
QDesignerFormWindowInterface
*
fw
=
formWindow
();
41
if
(!
canMorph
(
fw
,
w
, &
oldType
) ||
oldType
==
newType
)
42
return
false
;
43
m_layoutBase
=
w
;
44
m_newType
=
newType
;
45
// Find all managed widgets
46
m_widgets
.
clear
();
47
const
QLayout
*
layout
=
LayoutInfo
::
managedLayout
(
fw
->
core
(),
w
);
48
const
int
count
=
layout
->
count
();
49
for
(
int
i
= 0;
i
<
count
;
i
++) {
50
if
(
QWidget
*
w
=
layout
->
itemAt
(
i
)->
widget
())
51
if
(
fw
->
isManaged
(
w
))
52
m_widgets
.
push_back
(
w
);
53
}
54
const
bool
reparentLayoutWidget
=
false
;
// leave QLayoutWidget intact
55
m_breakLayoutCommand
->
init
(
m_widgets
,
m_layoutBase
,
reparentLayoutWidget
);
56
m_layoutCommand
->
init
(
m_layoutBase
,
m_widgets
,
static_cast
<
LayoutInfo
::
Type
>(
m_newType
),
m_layoutBase
,
reparentLayoutWidget
);
57
setText
(
formatDescription
(
core
(),
m_layoutBase
,
oldType
,
newType
));
58
return
true
;
59
}
60
61
bool
MorphLayoutCommand
::
canMorph
(
const
QDesignerFormWindowInterface
*
formWindow
,
QWidget
*
w
,
int
*
ptrToCurrentType
)
62
{
63
if
(
ptrToCurrentType
)
64
*
ptrToCurrentType
=
LayoutInfo
::
NoLayout
;
65
// We want a managed widget or a container page
66
// with a level-0 managed layout
67
QDesignerFormEditorInterface
*
core
=
formWindow
->
core
();
68
QLayout
*
layout
=
LayoutInfo
::
managedLayout
(
core
,
w
);
69
if
(!
layout
)
70
return
false
;
71
const
LayoutInfo
::
Type
type
=
LayoutInfo
::
layoutType
(
core
,
layout
);
72
if
(
ptrToCurrentType
)
73
*
ptrToCurrentType
=
type
;
74
switch
(
type
) {
75
case
LayoutInfo
::
HBox
:
76
case
LayoutInfo
::
VBox
:
77
case
LayoutInfo
::
Grid
:
78
case
LayoutInfo
::
Form
:
79
return
true
;
80
break
;
81
case
LayoutInfo
::
NoLayout
:
82
case
LayoutInfo
::
HSplitter
:
// Nothing doing
83
case
LayoutInfo
::
VSplitter
:
84
case
LayoutInfo
::
UnknownLayout
:
85
break
;
86
}
87
return
false
;
88
}
89
90
void
MorphLayoutCommand
::
redo
()
91
{
92
m_breakLayoutCommand
->
redo
();
93
m_layoutCommand
->
redo
();
94
/* Transfer applicable properties which is a cross-section of the modified
95
* properties except object name. */
96
if
(
const
LayoutProperties
*
properties
=
m_breakLayoutCommand
->
layoutProperties
()) {
97
const
int
oldMask
=
m_breakLayoutCommand
->
propertyMask
();
98
QLayout
*
newLayout
=
LayoutInfo
::
managedLayout
(
core
(),
m_layoutBase
);
99
const
int
newMask
=
LayoutProperties
::
visibleProperties
(
newLayout
);
100
const
int
applicableMask
= (
oldMask
&
newMask
) & ~
LayoutProperties
::
ObjectNameProperty
;
101
if
(
applicableMask
)
102
properties
->
toPropertySheet
(
core
(),
newLayout
,
applicableMask
);
103
}
104
}
105
106
void
MorphLayoutCommand
::
undo
()
107
{
108
m_layoutCommand
->
undo
();
109
m_breakLayoutCommand
->
undo
();
110
}
111
112
QString
MorphLayoutCommand
::
formatDescription
(
QDesignerFormEditorInterface
*
/* core*/
,
const
QWidget
*
w
,
int
oldType
,
int
newType
)
113
{
114
const
QString
oldName
=
LayoutInfo
::
layoutName
(
static_cast
<
LayoutInfo
::
Type
>(
oldType
));
115
const
QString
newName
=
LayoutInfo
::
layoutName
(
static_cast
<
LayoutInfo
::
Type
>(
newType
));
116
const
QString
widgetName
=
qobject_cast
<
const
QLayoutWidget
*>(
w
) ?
w
->
layout
()->
objectName
() :
w
->
objectName
();
117
return
QApplication
::
translate
(
"Command"
,
"Change layout of '%1' from %2 to %3"
).
arg
(
widgetName
,
oldName
,
newName
);
118
}
119
120
LayoutAlignmentCommand
::LayoutAlignmentCommand(QDesignerFormWindowInterface *formWindow) :
121
QDesignerFormWindowCommand(QApplication::translate(
"Command"
,
"Change layout alignment"
), formWindow),
122
m_widget(
nullptr
)
123
{
124
}
125
126
bool
LayoutAlignmentCommand
::
init
(
QWidget
*w, Qt::Alignment alignment)
127
{
128
bool
enabled;
129
m_newAlignment = alignment;
130
m_oldAlignment = LayoutAlignmentCommand::alignmentOf(core(), w, &enabled);
131
m_widget = w;
132
return
enabled;
133
}
134
135
void
LayoutAlignmentCommand
::
redo
()
136
{
137
LayoutAlignmentCommand::applyAlignment(core(), m_widget, m_newAlignment);
138
}
139
140
void
LayoutAlignmentCommand
::
undo
()
141
{
142
LayoutAlignmentCommand::applyAlignment(core(), m_widget, m_oldAlignment);
143
}
144
145
// Find out alignment and return whether command is enabled.
146
Qt::Alignment
LayoutAlignmentCommand
::alignmentOf(
const
QDesignerFormEditorInterface *core,
QWidget
*w,
bool
*enabledIn)
147
{
148
bool
managed;
149
QLayout *layout;
150
151
if
(enabledIn)
152
*enabledIn =
false
;
153
// Can only work on a managed layout
154
const
LayoutInfo::Type type = LayoutInfo::laidoutWidgetType(core, w, &managed, &layout);
155
const
bool
enabled = layout && managed &&
156
(type == LayoutInfo::HBox || type == LayoutInfo::VBox
157
|| type == LayoutInfo::Grid);
158
if
(!enabled)
159
return
{};
160
// Get alignment
161
const
int
index = layout->indexOf(w);
162
Q_ASSERT(index >= 0);
163
if
(enabledIn)
164
*enabledIn =
true
;
165
return
layout->itemAt(index)->alignment();
166
}
167
168
void
LayoutAlignmentCommand
::applyAlignment(
const
QDesignerFormEditorInterface *core,
QWidget
*w, Qt::Alignment a)
169
{
170
// Find layout and apply to item
171
QLayout *layout;
172
LayoutInfo::laidoutWidgetType(core, w,
nullptr
, &layout);
173
if
(layout) {
174
const
int
index = layout->indexOf(w);
175
if
(index >= 0) {
176
layout->itemAt(index)->setAlignment(a);
177
layout->update();
178
}
179
}
180
}
181
182
}
// namespace qdesigner_internal
183
184
QT_END_NAMESPACE
QPainter::QWidget
friend class QWidget
Definition
qpainter.h:432
qdesigner_internal::LayoutAlignmentCommand
Definition
qdesigner_command2_p.h:61
qdesigner_internal::LayoutAlignmentCommand::redo
void redo() override
Applies a change to the document.
Definition
qdesigner_command2.cpp:135
qdesigner_internal::LayoutAlignmentCommand::init
bool init(QWidget *w, Qt::Alignment alignment)
Definition
qdesigner_command2.cpp:126
qdesigner_internal::LayoutAlignmentCommand::undo
void undo() override
Reverts a change to the document.
Definition
qdesigner_command2.cpp:140
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qdesigner_internal
Auxiliary methods to store/retrieve settings.
Definition
buddyeditor.cpp:67
qttools
src
designer
src
lib
shared
qdesigner_command2.cpp
Generated on
for Qt by
1.18.0