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