Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
orderdialog.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
"orderdialog_p.h"
6
#
include
"iconloader_p.h"
7
#
include
"ui_orderdialog.h"
8
9
#
include
<
QtDesigner
/
qextensionmanager
.
h
>
10
#
include
<
QtDesigner
/
abstractformeditor
.
h
>
11
#
include
<
QtDesigner
/
container
.
h
>
12
#
include
<
QtCore
/
qabstractitemmodel
.
h
>
13
#
include
<
QtWidgets
/
qpushbutton
.
h
>
14
15
QT_BEGIN_NAMESPACE
16
17
using
namespace
Qt::StringLiterals;
18
19
// OrderDialog: Used to reorder the pages of QStackedWidget and QToolBox.
20
// Provides up and down buttons as well as DnD via QAbstractItemView::InternalMove mode
21
namespace
qdesigner_internal
{
22
23
OrderDialog
::
OrderDialog
(
QWidget
*
parent
) :
24
QDialog
(
parent
),
25
m_ui
(
new
QT_PREPEND_NAMESPACE
(
qdesigner_internal
)::
Ui
::
OrderDialog
),
26
m_format
(
PageOrderFormat
)
27
{
28
m_ui
->
setupUi
(
this
);
29
m_ui
->
upButton
->
setIcon
(
createIconSet
(
"up.png"_L1
));
30
m_ui
->
downButton
->
setIcon
(
createIconSet
(
"down.png"_L1
));
31
m_ui
->
buttonBox
->
button
(
QDialogButtonBox
::
Ok
)->
setDefault
(
true
);
32
connect
(
m_ui
->
buttonBox
->
button
(
QDialogButtonBox
::
Reset
), &
QAbstractButton
::
clicked
,
33
this
, &
OrderDialog
::
slotReset
);
34
// Catch the remove operation of a DnD operation in QAbstractItemView::InternalMove mode to enable buttons
35
// Selection mode is 'contiguous' to enable DnD of groups
36
connect
(
m_ui
->
pageList
->
model
(), &
QAbstractItemModel
::
rowsRemoved
,
37
this
, &
OrderDialog
::
slotEnableButtonsAfterDnD
);
38
39
connect
(
m_ui
->
upButton
, &
QAbstractButton
::
clicked
,
this
, &
OrderDialog
::
upButtonClicked
);
40
connect
(
m_ui
->
downButton
, &
QAbstractButton
::
clicked
,
this
, &
OrderDialog
::
downButtonClicked
);
41
connect
(
m_ui
->
pageList
, &
QListWidget
::
currentRowChanged
,
42
this
, &
OrderDialog
::
pageListCurrentRowChanged
);
43
44
m_ui
->
upButton
->
setEnabled
(
false
);
45
m_ui
->
downButton
->
setEnabled
(
false
);
46
}
47
48
OrderDialog
::~
OrderDialog
()
49
{
50
delete
m_ui
;
51
}
52
53
void
OrderDialog
::
setDescription
(
const
QString
&
d
)
54
{
55
m_ui
->
groupBox
->
setTitle
(
d
);
56
}
57
58
void
OrderDialog
::
setPageList
(
const
QWidgetList
&
pages
)
59
{
60
// The QWidget* are stored in a map indexed by the old index.
61
// The old index is set as user data on the item instead of the QWidget*
62
// because DnD is enabled which requires the user data to serializable
63
m_orderMap
.
clear
();
64
const
qsizetype
count
=
pages
.
size
();
65
for
(
qsizetype
i
= 0;
i
<
count
; ++
i
)
66
m_orderMap
.
insert
(
int
(
i
),
pages
.
at
(
i
));
67
buildList
();
68
}
69
70
void
OrderDialog
::
buildList
()
71
{
72
m_ui
->
pageList
->
clear
();
73
for
(
auto
it
=
m_orderMap
.
cbegin
(),
cend
=
m_orderMap
.
cend
();
it
!=
cend
; ++
it
) {
74
QListWidgetItem
*
item
=
new
QListWidgetItem
();
75
const
int
index
=
it
.
key
();
76
switch
(
m_format
) {
77
case
PageOrderFormat
:
78
item
->
setText
(
tr
(
"Index %1 (%2)"
).
arg
(
index
).
arg
(
it
.
value
()->
objectName
()));
79
break
;
80
case
TabOrderFormat
:
81
item
->
setText
(
tr
(
"%1 %2"
).
arg
(
index
+1).
arg
(
it
.
value
()->
objectName
()));
82
break
;
83
}
84
item
->
setData
(
Qt
::
UserRole
,
QVariant
(
index
));
85
m_ui
->
pageList
->
addItem
(
item
);
86
}
87
88
if
(
m_ui
->
pageList
->
count
() > 0)
89
m_ui
->
pageList
->
setCurrentRow
(0);
90
}
91
92
void
OrderDialog
::
slotReset
()
93
{
94
buildList
();
95
}
96
97
QWidgetList
OrderDialog
::
pageList
()
const
98
{
99
QWidgetList
rc
;
100
const
int
count
=
m_ui
->
pageList
->
count
();
101
for
(
int
i
=0;
i
<
count
; ++
i
) {
102
const
int
oldIndex
=
m_ui
->
pageList
->
item
(
i
)->
data
(
Qt
::
UserRole
).
toInt
();
103
rc
.
append
(
m_orderMap
.
value
(
oldIndex
));
104
}
105
return
rc
;
106
}
107
108
void
OrderDialog
::
upButtonClicked
()
109
{
110
const
int
row
=
m_ui
->
pageList
->
currentRow
();
111
if
(
row
<= 0)
112
return
;
113
114
m_ui
->
pageList
->
insertItem
(
row
- 1,
m_ui
->
pageList
->
takeItem
(
row
));
115
m_ui
->
pageList
->
setCurrentRow
(
row
- 1);
116
}
117
118
void
OrderDialog
::
downButtonClicked
()
119
{
120
const
int
row
=
m_ui
->
pageList
->
currentRow
();
121
if
(
row
== -1 ||
row
==
m_ui
->
pageList
->
count
() - 1)
122
return
;
123
124
m_ui
->
pageList
->
insertItem
(
row
+ 1,
m_ui
->
pageList
->
takeItem
(
row
));
125
m_ui
->
pageList
->
setCurrentRow
(
row
+ 1);
126
}
127
128
void
OrderDialog
::
slotEnableButtonsAfterDnD
()
129
{
130
enableButtons
(
m_ui
->
pageList
->
currentRow
());
131
}
132
133
void
OrderDialog
::
pageListCurrentRowChanged
(
int
r
)
134
{
135
enableButtons
(
r
);
136
}
137
138
void
OrderDialog
::
enableButtons
(
int
r
)
139
{
140
m_ui
->
upButton
->
setEnabled
(
r
> 0);
141
m_ui
->
downButton
->
setEnabled
(
r
>= 0 &&
r
<
m_ui
->
pageList
->
count
() - 1);
142
}
143
144
QWidgetList
OrderDialog
::
pagesOfContainer
(
const
QDesignerFormEditorInterface
*
core
,
QWidget
*
container
)
145
{
146
QWidgetList
rc
;
147
if
(
QDesignerContainerExtension
*
ce
=
qt_extension
<
QDesignerContainerExtension
*>(
core
->
extensionManager
(),
container
)) {
148
const
int
count
=
ce
->
count
();
149
for
(
int
i
= 0;
i
<
count
;
i
++)
150
rc
.
push_back
(
ce
->
widget
(
i
));
151
}
152
return
rc
;
153
}
154
155
}
156
157
QT_END_NAMESPACE
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qdesigner_internal
Auxiliary methods to store/retrieve settings.
Definition
buddyeditor.cpp:67
qttools
src
designer
src
lib
shared
orderdialog.cpp
Generated on
for Qt by
1.16.1