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
qquickprogressbar.cpp
Go to the documentation of this file.
1
// Copyright (C) 2017 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
// Qt-Security score:significant reason:default
4
5
#
include
"qquickprogressbar_p.h"
6
#
include
"qquickcontrol_p_p.h"
7
8
QT_BEGIN_NAMESPACE
9
10
/*!
11
\qmltype ProgressBar
12
\inherits Control
13
//! \nativetype QQuickProgressBar
14
\inqmlmodule QtQuick.Controls
15
\since 5.7
16
\ingroup qtquickcontrols-indicators
17
\brief Indicates the progress of an operation.
18
19
\image qtquickcontrols-progressbar.gif
20
{Progress bar filling from left to right}
21
22
ProgressBar indicates the progress of an operation. The value should be updated
23
regularly. The range is defined by \l from and \l to, which both can contain any value.
24
25
\code
26
ProgressBar {
27
value: 0.5
28
}
29
\endcode
30
31
ProgressBar also supports a special \l indeterminate mode, which is useful,
32
for example, when unable to determine the size of the item being downloaded,
33
or if the download progress gets interrupted due to a network disconnection.
34
35
\image qtquickcontrols-progressbar-indeterminate.gif
36
{Progress bar in indeterminate animation mode}
37
38
\code
39
ProgressBar {
40
indeterminate: true
41
}
42
\endcode
43
44
The indeterminate mode is similar to a \l BusyIndicator. Both can be used
45
to indicate background activity. The main difference is visual, and that
46
ProgressBar can also present a concrete amount of progress (when it can be
47
determined). Due to the visual difference, indeterminate progress bars and
48
busy indicators fit different places in user interfaces. Typical places for
49
an indeterminate progress bar:
50
\list
51
\li at the bottom of a \l ToolBar
52
\li inline within the content of a \l Page
53
\li in an \l ItemDelegate to show the progress of a particular item
54
\endlist
55
56
\sa {Customizing ProgressBar}, BusyIndicator, {Indicator Controls}
57
*/
58
59
class
QQuickProgressBarPrivate
:
public
QQuickControlPrivate
60
{
61
public
:
62
qreal
from
= 0;
63
qreal
to
= 1;
64
qreal
value
= 0;
65
bool
indeterminate
=
false
;
66
};
67
68
QQuickProgressBar::QQuickProgressBar(QQuickItem *parent)
69
: QQuickControl(*(
new
QQuickProgressBarPrivate), parent)
70
{
71
Q_D(QQuickProgressBar);
72
d->setSizePolicy(QLayoutPolicy::Expanding, QLayoutPolicy::Fixed);
73
}
74
75
/*!
76
\qmlproperty real QtQuick.Controls::ProgressBar::from
77
78
This property holds the starting value for the progress. The default value is \c 0.0.
79
80
\sa to, value
81
*/
82
qreal QQuickProgressBar::from()
const
83
{
84
Q_D(
const
QQuickProgressBar);
85
return
d->from;
86
}
87
88
void
QQuickProgressBar::setFrom(qreal from)
89
{
90
Q_D(QQuickProgressBar);
91
if
(qFuzzyCompare(d->from, from))
92
return
;
93
94
d->from = from;
95
emit fromChanged();
96
emit positionChanged();
97
emit visualPositionChanged();
98
if
(isComponentComplete())
99
setValue(d->value);
100
}
101
102
/*!
103
\qmlproperty real QtQuick.Controls::ProgressBar::to
104
105
This property holds the end value for the progress. The default value is \c 1.0.
106
107
\sa from, value
108
*/
109
qreal QQuickProgressBar::to()
const
110
{
111
Q_D(
const
QQuickProgressBar);
112
return
d->to;
113
}
114
115
void
QQuickProgressBar::setTo(qreal to)
116
{
117
Q_D(QQuickProgressBar);
118
if
(qFuzzyCompare(d->to, to))
119
return
;
120
121
d->to = to;
122
emit toChanged();
123
emit positionChanged();
124
emit visualPositionChanged();
125
if
(isComponentComplete())
126
setValue(d->value);
127
}
128
129
/*!
130
\qmlproperty real QtQuick.Controls::ProgressBar::value
131
132
This property holds the progress value. The default value is \c 0.0.
133
134
\sa from, to, position
135
*/
136
qreal QQuickProgressBar::value()
const
137
{
138
Q_D(
const
QQuickProgressBar);
139
return
d->value;
140
}
141
142
void
QQuickProgressBar::setValue(qreal value)
143
{
144
Q_D(QQuickProgressBar);
145
if
(isComponentComplete())
146
value = d->from > d->to ? qBound(d->to, value, d->from) : qBound(d->from, value, d->to);
147
148
if
(qFuzzyCompare(d->value, value))
149
return
;
150
151
d->value = value;
152
emit valueChanged();
153
emit positionChanged();
154
emit visualPositionChanged();
155
}
156
157
/*!
158
\qmlproperty real QtQuick.Controls::ProgressBar::position
159
\readonly
160
161
This property holds the logical position of the progress.
162
163
The position is expressed as a fraction of the value, in the range
164
\c {0.0 - 1.0}. For visualizing the progress, the right-to-left
165
aware \l visualPosition should be used instead.
166
167
\sa value, visualPosition
168
*/
169
qreal QQuickProgressBar::position()
const
170
{
171
Q_D(
const
QQuickProgressBar);
172
if
(qFuzzyCompare(d->from, d->to))
173
return
0;
174
return
(d->value - d->from) / (d->to - d->from);
175
}
176
177
/*!
178
\qmlproperty real QtQuick.Controls::ProgressBar::visualPosition
179
\readonly
180
181
This property holds the visual position of the progress.
182
183
The position is expressed as a fraction of the value, in the range \c {0.0 - 1.0}.
184
When the control is \l {Control::mirrored}{mirrored}, \c visuaPosition is equal
185
to \c {1.0 - position}. This makes \c visualPosition suitable for visualizing
186
the progress, taking right-to-left support into account.
187
188
\sa position, value
189
*/
190
qreal QQuickProgressBar::visualPosition()
const
191
{
192
if
(isMirrored())
193
return
1.0 - position();
194
return
position();
195
}
196
197
/*!
198
\qmlproperty bool QtQuick.Controls::ProgressBar::indeterminate
199
200
This property holds whether the progress bar is in indeterminate mode.
201
A progress bar in indeterminate mode displays that an operation is in progress, but it
202
doesn't show how much progress has been made.
203
204
\image qtquickcontrols-progressbar-indeterminate.gif
205
{Progress bar in indeterminate animation mode}
206
*/
207
bool
QQuickProgressBar::isIndeterminate()
const
208
{
209
Q_D(
const
QQuickProgressBar);
210
return
d->indeterminate;
211
}
212
213
void
QQuickProgressBar::setIndeterminate(
bool
indeterminate)
214
{
215
Q_D(QQuickProgressBar);
216
if
(d->indeterminate == indeterminate)
217
return
;
218
219
d->indeterminate = indeterminate;
220
emit indeterminateChanged();
221
}
222
223
void
QQuickProgressBar::mirrorChange()
224
{
225
QQuickControl::mirrorChange();
226
if
(!qFuzzyCompare(position(), qreal(0.5)))
227
emit visualPositionChanged();
228
}
229
230
void
QQuickProgressBar::componentComplete()
231
{
232
Q_D(QQuickProgressBar);
233
QQuickControl::componentComplete();
234
setValue(d->value);
235
}
236
237
#
if
QT_CONFIG
(
accessibility
)
238
QAccessible::Role QQuickProgressBar::accessibleRole()
const
239
{
240
return
QAccessible::ProgressBar;
241
}
242
#
endif
243
244
QT_END_NAMESPACE
245
246
#
include
"moc_qquickprogressbar_p.cpp"
QQuickProgressBarPrivate
Indicates the progress of an operation.
Definition
qquickprogressbar.cpp:60
QQuickProgressBarPrivate::from
qreal from
Definition
qquickprogressbar.cpp:62
QQuickProgressBarPrivate::value
qreal value
Definition
qquickprogressbar.cpp:64
QQuickProgressBarPrivate::to
qreal to
Definition
qquickprogressbar.cpp:63
QQuickProgressBarPrivate::indeterminate
bool indeterminate
Definition
qquickprogressbar.cpp:65
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qtdeclarative
src
quicktemplates
qquickprogressbar.cpp
Generated on
for Qt by
1.18.0