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
qwizard_container.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
"qwizard_container.h"
6
7
#
include
<
QtDesigner
/
qextensionmanager
.
h
>
8
#
include
<
QtDesigner
/
abstractformeditor
.
h
>
9
10
#
include
<
QtWidgets
/
qwizard
.
h
>
11
#
include
<
QtCore
/
qdebug
.
h
>
12
#
include
<
QtCore
/
qlist
.
h
>
13
14
QT_BEGIN_NAMESPACE
15
16
using
namespace
Qt::StringLiterals;
17
18
using
WizardPageList = QList<QWizardPage *>;
19
20
namespace
qdesigner_internal
{
21
22
QWizardContainer
::QWizardContainer(QWizard *widget, QObject *parent) :
23
QObject(parent),
24
m_wizard(widget)
25
{
26
}
27
28
int
QWizardContainer
::
count
()
const
29
{
30
return
m_wizard->pageIds().size();
31
}
32
33
QWidget
*
QWizardContainer
::
widget
(
int
index)
const
34
{
35
QWidget *rc =
nullptr
;
36
if
(index >= 0) {
37
const
auto
idList = m_wizard->pageIds();
38
if
(index < idList.size())
39
rc = m_wizard->page(idList.at(index));
40
}
41
return
rc;
42
}
43
44
int
QWizardContainer
::
currentIndex
()
const
45
{
46
return
m_wizard->pageIds().indexOf(m_wizard->currentId());
47
}
48
49
void
QWizardContainer
::
setCurrentIndex
(
int
index)
50
{
51
if
(index < 0 || m_wizard->pageIds().isEmpty())
52
return
;
53
54
int
currentIdx =
currentIndex
(
)
;
55
56
if
(currentIdx == -1) {
57
m_wizard->restart();
58
currentIdx =
currentIndex
(
)
;
59
}
60
61
if
(currentIdx == index)
62
return
;
63
64
const
int
d = qAbs(index - currentIdx);
65
if
(index > currentIdx) {
66
for
(
int
i = 0; i < d; i++)
67
m_wizard->next();
68
}
else
{
69
for
(
int
i = 0; i < d; i++)
70
m_wizard->back();
71
}
72
}
73
74
static
const
char
msgWrongType
[] =
"** WARNING Attempt to add oject that is not of class WizardPage to a QWizard"
;
75
76
void
QWizardContainer
::addWidget(QWidget *widget)
77
{
78
QWizardPage *page = qobject_cast<QWizardPage *>(widget);
79
if
(!page) {
80
qWarning(
"%s"
,
msgWrongType
);
81
return
;
82
}
83
m_wizard->addPage(page);
84
// Might be -1 after adding the first page
85
setCurrentIndex
(m_wizard->pageIds().size() - 1);
86
}
87
88
void
QWizardContainer
::insertWidget(
int
index, QWidget *widget)
89
{
90
enum
{ delta = 5 };
91
92
QWizardPage *newPage = qobject_cast<QWizardPage *>(widget);
93
if
(!newPage) {
94
qWarning(
"%s"
,
msgWrongType
);
95
return
;
96
}
97
98
const
auto
idList = m_wizard->pageIds();
99
const
auto
pageCount = idList.size();
100
if
(index >= pageCount) {
101
addWidget(widget);
102
return
;
103
}
104
105
// Insert before, reshuffle ids if required
106
const
int
idBefore = idList.at(index);
107
const
int
newId = idBefore - 1;
108
const
bool
needsShuffle =
109
(index == 0 && newId < 0)
// At start: QWizard refuses to insert id -1
110
|| (index > 0 && idList.at(index - 1) == newId);
// In-between
111
if
(needsShuffle) {
112
// Create a gap by shuffling pages
113
WizardPageList pageList;
114
pageList.push_back(newPage);
115
for
(qsizetype i = index; i < pageCount; ++i) {
116
pageList.push_back(m_wizard->page(idList.at(i)));
117
m_wizard->removePage(idList.at(i));
118
}
119
int
newId = idBefore + delta;
120
for
(QWizardPage *page : std::as_const(pageList)) {
121
m_wizard->setPage(newId, page);
122
newId += delta;
123
}
124
}
else
{
125
// Gap found, just insert
126
m_wizard->setPage(newId, newPage);
127
}
128
// Might be at -1 after adding the first page
129
setCurrentIndex
(
index
)
;
130
}
131
132
void
QWizardContainer
::
remove
(
int
index)
133
{
134
if
(index < 0)
135
return
;
136
137
const
auto
idList = m_wizard->pageIds();
138
if
(index >= idList.size())
139
return
;
140
141
m_wizard->removePage(idList.at(index));
142
// goto next page, preferably
143
const
int
newSize = idList.size() - 1;
144
if
(index < newSize) {
145
setCurrentIndex
(
index
)
;
146
}
else
{
147
if
(newSize > 0)
148
setCurrentIndex
(
newSize - 1
)
;
149
}
150
}
151
152
// ---------------- QWizardPagePropertySheet
153
const
char
*
QWizardPagePropertySheet
::
pageIdProperty
=
"pageId"
;
154
155
QWizardPagePropertySheet
::QWizardPagePropertySheet(QWizardPage *object, QObject *parent) :
156
QDesignerPropertySheet(object, parent),
157
m_pageIdIndex(createFakeProperty(QLatin1StringView(
pageIdProperty
), QString()))
158
{
159
setAttribute(m_pageIdIndex,
true
);
160
}
161
162
bool
QWizardPagePropertySheet
::
reset
(
int
index)
163
{
164
if
(index == m_pageIdIndex) {
165
setProperty(index, QString());
166
return
true
;
167
}
168
return
QDesignerPropertySheet::reset(index);
169
}
170
171
// ---------------- QWizardPropertySheet
172
QWizardPropertySheet
::QWizardPropertySheet(QWizard *object, QObject *parent) :
173
QDesignerPropertySheet(object, parent),
174
m_startId(u"startId"_s)
175
{
176
}
177
178
bool
QWizardPropertySheet
::
isVisible
(
int
index)
const
179
{
180
if
(propertyName(index) == m_startId)
181
return
false
;
182
return
QDesignerPropertySheet::isVisible(index);
183
}
184
}
185
186
QT_END_NAMESPACE
qdesigner_internal::QWizardContainer
Definition
qwizard_container.h:25
qdesigner_internal::QWizardContainer::currentIndex
int currentIndex() const override
Definition
qwizard_container.cpp:44
qdesigner_internal::QWizardContainer::count
int count() const override
Definition
qwizard_container.cpp:28
qdesigner_internal::QWizardContainer::widget
QWidget * widget(int index) const override
Definition
qwizard_container.cpp:33
qdesigner_internal::QWizardContainer::remove
void remove(int index) override
Definition
qwizard_container.cpp:132
qdesigner_internal::QWizardContainer::setCurrentIndex
void setCurrentIndex(int index) override
Definition
qwizard_container.cpp:49
qdesigner_internal::QWizardPagePropertySheet
Definition
qwizard_container.h:51
qdesigner_internal::QWizardPagePropertySheet::pageIdProperty
static const char * pageIdProperty
Definition
qwizard_container.h:58
qdesigner_internal::QWizardPagePropertySheet::reset
bool reset(int index) override
Definition
qwizard_container.cpp:162
qdesigner_internal::QWizardPropertySheet
Definition
qwizard_container.h:69
qdesigner_internal::QWizardPropertySheet::isVisible
bool isVisible(int index) const override
Definition
qwizard_container.cpp:178
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
qdesigner_internal::msgWrongType
static const char msgWrongType[]
Definition
qwizard_container.cpp:74
qttools
src
designer
src
components
formeditor
qwizard_container.cpp
Generated on
for Qt by
1.18.0