widgets/qprogressbar.cpp

Switch to Source codePreprocessed file
LineSource CodeCoverage
1 -
2 -
3 -
4 -
5 -
6 -
7class QProgressBarPrivate : public QWidgetPrivate -
8{ -
9 inline QProgressBar* q_func() { return static_cast<QProgressBar *>(q_ptr); } inline const QProgressBar* q_func() const { return static_cast<const QProgressBar *>(q_ptr); } friend class QProgressBar; -
10 -
11public: -
12 QProgressBarPrivate(); -
13 -
14 void init(); -
15 inline void resetLayoutItemMargins(); -
16 -
17 int minimum; -
18 int maximum; -
19 int value; -
20 Qt::Alignment alignment; -
21 uint textVisible : 1; -
22 int lastPaintedValue; -
23 Qt::Orientation orientation; -
24 bool invertedAppearance; -
25 QProgressBar::Direction textDirection; -
26 QString format; -
27 inline int bound(int val) const { return qMax(minimum-1, qMin(maximum, val)); }
never executed: return qMax(minimum-1, qMin(maximum, val));
0
28 bool repaintRequired() const; -
29}; -
30 -
31QProgressBarPrivate::QProgressBarPrivate() -
32 : minimum(0), maximum(100), value(-1), alignment(Qt::AlignLeft), textVisible(true), -
33 lastPaintedValue(-1), orientation(Qt::Horizontal), invertedAppearance(false), -
34 textDirection(QProgressBar::TopToBottom), format(QLatin1String("%p%")) -
35{ -
36}
executed: }
Execution Count:20
20
37 -
38void QProgressBarPrivate::init() -
39{ -
40 QProgressBar * const q = q_func(); -
41 QSizePolicy sp(QSizePolicy::Expanding, QSizePolicy::Fixed); -
42 if (orientation == Qt::Vertical)
partially evaluated: orientation == Qt::Vertical
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:20
0-20
43 sp.transpose();
never executed: sp.transpose();
0
44 q->setSizePolicy(sp); -
45 q->setAttribute(Qt::WA_WState_OwnSizePolicy, false); -
46 resetLayoutItemMargins(); -
47}
executed: }
Execution Count:20
20
48 -
49void QProgressBarPrivate::resetLayoutItemMargins() -
50{ -
51 QProgressBar * const q = q_func(); -
52 QStyleOptionProgressBar option; -
53 q->initStyleOption(&option); -
54 setLayoutItemMargins(QStyle::SE_ProgressBarLayoutItem, &option); -
55}
executed: }
Execution Count:26
26
56void QProgressBar::initStyleOption(QStyleOptionProgressBar *option) const -
57{ -
58 if (!option)
partially evaluated: !option
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:137
0-137
59 return;
never executed: return;
0
60 const QProgressBarPrivate * const d = d_func(); -
61 option->initFrom(this); -
62 -
63 if (d->orientation == Qt::Horizontal)
partially evaluated: d->orientation == Qt::Horizontal
TRUEFALSE
yes
Evaluation Count:137
no
Evaluation Count:0
0-137
64 option->state |= QStyle::State_Horizontal;
executed: option->state |= QStyle::State_Horizontal;
Execution Count:137
137
65 option->minimum = d->minimum; -
66 option->maximum = d->maximum; -
67 option->progress = d->value; -
68 option->textAlignment = d->alignment; -
69 option->textVisible = d->textVisible; -
70 option->text = text(); -
71 -
72 if (QStyleOptionProgressBarV2 *optionV2 0-137
73 = qstyleoption_cast<QStyleOptionProgressBarV2 *>(option)) {
partially evaluated: QStyleOptionProgressBarV2 *optionV2 = qstyleoption_cast<QStyleOptionProgressBarV2 *>(option)
TRUEFALSE
yes
Evaluation Count:137
no
Evaluation Count:0
0-137
74 optionV2->orientation = d->orientation; -
75 optionV2->invertedAppearance = d->invertedAppearance; -
76 optionV2->bottomToTop = (d->textDirection == QProgressBar::BottomToTop); -
77 }
executed: }
Execution Count:137
137
78}
executed: }
Execution Count:137
137
79 -
80bool QProgressBarPrivate::repaintRequired() const -
81{ -
82 const QProgressBar * const q = q_func(); -
83 if (value == lastPaintedValue)
partially evaluated: value == lastPaintedValue
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:33
0-33
84 return false;
never executed: return false;
0
85 -
86 int valueDifference = qAbs(value - lastPaintedValue); -
87 -
88 -
89 if (value == minimum || value == maximum)
evaluated: value == minimum
TRUEFALSE
yes
Evaluation Count:9
yes
Evaluation Count:24
evaluated: value == maximum
TRUEFALSE
yes
Evaluation Count:5
yes
Evaluation Count:19
5-24
90 return true;
executed: return true;
Execution Count:14
14
91 if (textVisible) {
partially evaluated: textVisible
TRUEFALSE
yes
Evaluation Count:19
no
Evaluation Count:0
0-19
92 if ((format.contains(QLatin1String("%v"))))
evaluated: (format.contains(QLatin1String("%v")))
TRUEFALSE
yes
Evaluation Count:9
yes
Evaluation Count:10
9-10
93 return true;
executed: return true;
Execution Count:9
9
94 if ((format.contains(QLatin1String("%p"))
partially evaluated: format.contains(QLatin1String("%p"))
TRUEFALSE
yes
Evaluation Count:10
no
Evaluation Count:0
0-10
95 && valueDifference >= qAbs((maximum - minimum) / 100)))
evaluated: valueDifference >= qAbs((maximum - minimum) / 100)
TRUEFALSE
yes
Evaluation Count:9
yes
Evaluation Count:1
1-9
96 return true;
executed: return true;
Execution Count:9
9
97 }
executed: }
Execution Count:1
1
98 -
99 -
100 QStyleOptionProgressBarV2 opt; -
101 q->initStyleOption(&opt); -
102 int cw = q->style()->pixelMetric(QStyle::PM_ProgressBarChunkWidth, &opt, q); -
103 QRect groove = q->style()->subElementRect(QStyle::SE_ProgressBarGroove, &opt, q); -
104 -
105 -
106 -
107 int grooveBlock = (q->orientation() == Qt::Horizontal) ? groove.width() : groove.height();
partially evaluated: (q->orientation() == Qt::Horizontal)
TRUEFALSE
yes
Evaluation Count:1
no
Evaluation Count:0
0-1
108 return (valueDifference * grooveBlock > cw * (maximum - minimum));
executed: return (valueDifference * grooveBlock > cw * (maximum - minimum));
Execution Count:1
1
109} -
110QProgressBar::QProgressBar(QWidget *parent) -
111 : QWidget(*(new QProgressBarPrivate), parent, 0) -
112{ -
113 d_func()->init(); -
114}
executed: }
Execution Count:20
20
115 -
116 -
117 -
118 -
119QProgressBar::~QProgressBar() -
120{ -
121} -
122 -
123 -
124 -
125 -
126 -
127 -
128void QProgressBar::reset() -
129{ -
130 QProgressBarPrivate * const d = d_func(); -
131 d->value = d->minimum - 1; -
132 if (d->minimum == (-2147483647 - 1))
evaluated: d->minimum == (-2147483647 - 1)
TRUEFALSE
yes
Evaluation Count:10
yes
Evaluation Count:16
10-16
133 d->value = (-2147483647 - 1);
executed: d->value = (-2147483647 - 1);
Execution Count:10
10
134 repaint(); -
135}
executed: }
Execution Count:26
26
136void QProgressBar::setMinimum(int minimum) -
137{ -
138 setRange(minimum, qMax(d_func()->maximum, minimum)); -
139}
executed: }
Execution Count:21
21
140 -
141int QProgressBar::minimum() const -
142{ -
143 return d_func()->minimum;
executed: return d_func()->minimum;
Execution Count:7
7
144} -
145void QProgressBar::setMaximum(int maximum) -
146{ -
147 setRange(qMin(d_func()->minimum, maximum), maximum); -
148}
executed: }
Execution Count:24
24
149 -
150int QProgressBar::maximum() const -
151{ -
152 return d_func()->maximum;
executed: return d_func()->maximum;
Execution Count:24
24
153} -
154void QProgressBar::setValue(int value) -
155{ -
156 QProgressBarPrivate * const d = d_func(); -
157 if (d->value == value
partially evaluated: d->value == value
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:33
0-33
158 || ((value > d->maximum || value < d->minimum)
partially evaluated: value > d->maximum
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:33
partially evaluated: value < d->minimum
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:33
0-33
159 && (d->maximum != 0 || d->minimum != 0)))
never evaluated: d->maximum != 0
never evaluated: d->minimum != 0
0
160 return;
never executed: return;
0
161 d->value = value; -
162 valueChanged(value); -
163 -
164 if (isVisible()) {
evaluated: isVisible()
TRUEFALSE
yes
Evaluation Count:14
yes
Evaluation Count:19
14-19
165 QAccessibleValueChangeEvent event(this, value); -
166 QAccessible::updateAccessibility(&event); -
167 }
executed: }
Execution Count:14
14
168 -
169 if (d->repaintRequired())
evaluated: d->repaintRequired()
TRUEFALSE
yes
Evaluation Count:32
yes
Evaluation Count:1
1-32
170 repaint();
executed: repaint();
Execution Count:32
32
171}
executed: }
Execution Count:33
33
172 -
173int QProgressBar::value() const -
174{ -
175 return d_func()->value;
executed: return d_func()->value;
Execution Count:31
31
176} -
177void QProgressBar::setRange(int minimum, int maximum) -
178{ -
179 QProgressBarPrivate * const d = d_func(); -
180 if (minimum != d->minimum || maximum != d->maximum) {
evaluated: minimum != d->minimum
TRUEFALSE
yes
Evaluation Count:31
yes
Evaluation Count:33
evaluated: maximum != d->maximum
TRUEFALSE
yes
Evaluation Count:23
yes
Evaluation Count:10
10-33
181 d->minimum = minimum; -
182 d->maximum = qMax(minimum, maximum); -
183 -
184 if (d->value < (d->minimum - 1) || d->value > d->maximum)
evaluated: d->value < (d->minimum - 1)
TRUEFALSE
yes
Evaluation Count:22
yes
Evaluation Count:32
evaluated: d->value > d->maximum
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:31
1-32
185 reset();
executed: reset();
Execution Count:23
23
186 else -
187 update();
executed: update();
Execution Count:31
31
188 } -
189}
executed: }
Execution Count:64
64
190void QProgressBar::setTextVisible(bool visible) -
191{ -
192 QProgressBarPrivate * const d = d_func(); -
193 if (d->textVisible != visible) {
never evaluated: d->textVisible != visible
0
194 d->textVisible = visible; -
195 repaint(); -
196 }
never executed: }
0
197}
never executed: }
0
198 -
199bool QProgressBar::isTextVisible() const -
200{ -
201 return d_func()->textVisible;
never executed: return d_func()->textVisible;
0
202} -
203 -
204 -
205 -
206 -
207 -
208void QProgressBar::setAlignment(Qt::Alignment alignment) -
209{ -
210 if (d_func()->alignment != alignment) {
never evaluated: d_func()->alignment != alignment
0
211 d_func()->alignment = alignment; -
212 repaint(); -
213 }
never executed: }
0
214}
never executed: }
0
215 -
216Qt::Alignment QProgressBar::alignment() const -
217{ -
218 return d_func()->alignment;
never executed: return d_func()->alignment;
0
219} -
220 -
221 -
222 -
223 -
224void QProgressBar::paintEvent(QPaintEvent *) -
225{ -
226 QStylePainter paint(this); -
227 QStyleOptionProgressBarV2 opt; -
228 initStyleOption(&opt); -
229 paint.drawControl(QStyle::CE_ProgressBar, opt); -
230 d_func()->lastPaintedValue = d_func()->value; -
231}
executed: }
Execution Count:62
62
232 -
233 -
234 -
235 -
236QSize QProgressBar::sizeHint() const -
237{ -
238 ensurePolished(); -
239 QFontMetrics fm = fontMetrics(); -
240 QStyleOptionProgressBarV2 opt; -
241 initStyleOption(&opt); -
242 int cw = style()->pixelMetric(QStyle::PM_ProgressBarChunkWidth, &opt, this); -
243 QSize size = QSize(qMax(9, cw) * 7 + fm.width(QLatin1Char('0')) * 4, fm.height() + 8); -
244 if (opt.orientation == Qt::Vertical)
partially evaluated: opt.orientation == Qt::Vertical
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:47
0-47
245 size.transpose();
never executed: size.transpose();
0
246 return style()->sizeFromContents(QStyle::CT_ProgressBar, &opt, size, this);
executed: return style()->sizeFromContents(QStyle::CT_ProgressBar, &opt, size, this);
Execution Count:47
47
247} -
248 -
249 -
250 -
251 -
252QSize QProgressBar::minimumSizeHint() const -
253{ -
254 QSize size; -
255 if (orientation() == Qt::Horizontal)
partially evaluated: orientation() == Qt::Horizontal
TRUEFALSE
yes
Evaluation Count:1
no
Evaluation Count:0
0-1
256 size = QSize(sizeHint().width(), fontMetrics().height() + 2);
executed: size = QSize(sizeHint().width(), fontMetrics().height() + 2);
Execution Count:1
1
257 else -
258 size = QSize(fontMetrics().height() + 2, sizeHint().height());
never executed: size = QSize(fontMetrics().height() + 2, sizeHint().height());
0
259 return size;
executed: return size;
Execution Count:1
1
260} -
261QString QProgressBar::text() const -
262{ -
263 const QProgressBarPrivate * const d = d_func(); -
264 if ((d->maximum == 0 && d->minimum == 0) || d->value < d->minimum
evaluated: d->maximum == 0
TRUEFALSE
yes
Evaluation Count:19
yes
Evaluation Count:129
evaluated: d->minimum == 0
TRUEFALSE
yes
Evaluation Count:18
yes
Evaluation Count:1
evaluated: d->value < d->minimum
TRUEFALSE
yes
Evaluation Count:87
yes
Evaluation Count:43
1-129
265 || (d->value == (-2147483647 - 1) && d->minimum == (-2147483647 - 1)))
partially evaluated: d->value == (-2147483647 - 1)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:43
never evaluated: d->minimum == (-2147483647 - 1)
0-43
266 return QString();
executed: return QString();
Execution Count:105
105
267 -
268 qint64 totalSteps = qint64(d->maximum) - d->minimum; -
269 -
270 QString result = d->format; -
271 result.replace(QLatin1String("%m"), QString::number(totalSteps)); -
272 result.replace(QLatin1String("%v"), QString::number(d->value)); -
273 -
274 -
275 -
276 -
277 if (totalSteps == 0) {
evaluated: totalSteps == 0
TRUEFALSE
yes
Evaluation Count:5
yes
Evaluation Count:38
5-38
278 result.replace(QLatin1String("%p"), QString::number(100)); -
279 return result;
executed: return result;
Execution Count:5
5
280 } -
281 -
282 int progress = (qreal(d->value) - d->minimum) * 100.0 / totalSteps; -
283 result.replace(QLatin1String("%p"), QString::number(progress)); -
284 return result;
executed: return result;
Execution Count:38
38
285} -
286void QProgressBar::setOrientation(Qt::Orientation orientation) -
287{ -
288 QProgressBarPrivate * const d = d_func(); -
289 if (d->orientation == orientation)
never evaluated: d->orientation == orientation
0
290 return;
never executed: return;
0
291 d->orientation = orientation; -
292 if (!testAttribute(Qt::WA_WState_OwnSizePolicy)) {
never evaluated: !testAttribute(Qt::WA_WState_OwnSizePolicy)
0
293 QSizePolicy sp = sizePolicy(); -
294 sp.transpose(); -
295 setSizePolicy(sp); -
296 setAttribute(Qt::WA_WState_OwnSizePolicy, false); -
297 }
never executed: }
0
298 d->resetLayoutItemMargins(); -
299 update(); -
300 updateGeometry(); -
301}
never executed: }
0
302 -
303Qt::Orientation QProgressBar::orientation() const -
304{ -
305 const QProgressBarPrivate * const d = d_func(); -
306 return d->orientation;
executed: return d->orientation;
Execution Count:2
2
307} -
308void QProgressBar::setInvertedAppearance(bool invert) -
309{ -
310 QProgressBarPrivate * const d = d_func(); -
311 d->invertedAppearance = invert; -
312 update(); -
313}
executed: }
Execution Count:2
2
314 -
315bool QProgressBar::invertedAppearance() const -
316{ -
317 const QProgressBarPrivate * const d = d_func(); -
318 return d->invertedAppearance;
executed: return d->invertedAppearance;
Execution Count:2
2
319} -
320void QProgressBar::setTextDirection(QProgressBar::Direction textDirection) -
321{ -
322 QProgressBarPrivate * const d = d_func(); -
323 d->textDirection = textDirection; -
324 update(); -
325}
never executed: }
0
326 -
327QProgressBar::Direction QProgressBar::textDirection() const -
328{ -
329 const QProgressBarPrivate * const d = d_func(); -
330 return d->textDirection;
never executed: return d->textDirection;
0
331} -
332 -
333 -
334bool QProgressBar::event(QEvent *e) -
335{ -
336 QProgressBarPrivate * const d = d_func(); -
337 if (e->type() == QEvent::StyleChange
evaluated: e->type() == QEvent::StyleChange
TRUEFALSE
yes
Evaluation Count:6
yes
Evaluation Count:281
6-281
338 -
339 -
340 -
341 ) -
342 d->resetLayoutItemMargins();
executed: d->resetLayoutItemMargins();
Execution Count:6
6
343 return QWidget::event(e);
executed: return QWidget::event(e);
Execution Count:287
287
344} -
345void QProgressBar::setFormat(const QString &format) -
346{ -
347 QProgressBarPrivate * const d = d_func(); -
348 if (d->format == format)
evaluated: d->format == format
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:7
1-7
349 return;
executed: return;
Execution Count:1
1
350 d->format = format; -
351 update(); -
352}
executed: }
Execution Count:7
7
353 -
354QString QProgressBar::format() const -
355{ -
356 const QProgressBarPrivate * const d = d_func(); -
357 return d->format;
never executed: return d->format;
0
358} -
359 -
360 -
361 -
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial