Line | Source Code | Coverage |
---|
1 | | - |
2 | | - |
3 | | - |
4 | | - |
5 | | - |
6 | | - |
7 | class 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 | | - |
11 | public: | - |
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 | | - |
31 | QProgressBarPrivate::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 | | - |
38 | void 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 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 | | - |
49 | void 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 |
56 | void QProgressBar::initStyleOption(QStyleOptionProgressBar *option) const | - |
57 | { | - |
58 | if (!option) partially evaluated: !option no Evaluation Count:0 | yes Evaluation Count:137 |
| 0-137 |
59 | 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 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) 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 | | - |
80 | bool QProgressBarPrivate::repaintRequired() const | - |
81 | { | - |
82 | const QProgressBar * const q = q_func(); | - |
83 | if (value == lastPaintedValue) partially evaluated: value == lastPaintedValue 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 yes Evaluation Count:9 | yes Evaluation Count:24 |
evaluated: value == maximum 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 yes Evaluation Count:19 | no Evaluation Count:0 |
| 0-19 |
92 | if ((format.contains(QLatin1String("%v")))) evaluated: (format.contains(QLatin1String("%v"))) 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")) yes Evaluation Count:10 | no Evaluation Count:0 |
| 0-10 |
95 | && valueDifference >= qAbs((maximum - minimum) / 100))) evaluated: valueDifference >= qAbs((maximum - minimum) / 100) 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) 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 | } | - |
110 | QProgressBar::QProgressBar(QWidget *parent) | - |
111 | : QWidget(*(new QProgressBarPrivate), parent, 0) | - |
112 | { | - |
113 | d_func()->init(); | - |
114 | } executed: } Execution Count:20 | 20 |
115 | | - |
116 | | - |
117 | | - |
118 | | - |
119 | QProgressBar::~QProgressBar() | - |
120 | { | - |
121 | } | - |
122 | | - |
123 | | - |
124 | | - |
125 | | - |
126 | | - |
127 | | - |
128 | void 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) 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 |
136 | void QProgressBar::setMinimum(int minimum) | - |
137 | { | - |
138 | setRange(minimum, qMax(d_func()->maximum, minimum)); | - |
139 | } executed: } Execution Count:21 | 21 |
140 | | - |
141 | int QProgressBar::minimum() const | - |
142 | { | - |
143 | return d_func()->minimum; executed: return d_func()->minimum; Execution Count:7 | 7 |
144 | } | - |
145 | void QProgressBar::setMaximum(int maximum) | - |
146 | { | - |
147 | setRange(qMin(d_func()->minimum, maximum), maximum); | - |
148 | } executed: } Execution Count:24 | 24 |
149 | | - |
150 | int QProgressBar::maximum() const | - |
151 | { | - |
152 | return d_func()->maximum; executed: return d_func()->maximum; Execution Count:24 | 24 |
153 | } | - |
154 | void QProgressBar::setValue(int value) | - |
155 | { | - |
156 | QProgressBarPrivate * const d = d_func(); | - |
157 | if (d->value == value partially evaluated: d->value == value no Evaluation Count:0 | yes Evaluation Count:33 |
| 0-33 |
158 | || ((value > d->maximum || value < d->minimum) partially evaluated: value > d->maximum no Evaluation Count:0 | yes Evaluation Count:33 |
partially evaluated: value < d->minimum 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; | 0 |
161 | d->value = value; | - |
162 | valueChanged(value); | - |
163 | | - |
164 | if (isVisible()) { evaluated: isVisible() 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() 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 | | - |
173 | int QProgressBar::value() const | - |
174 | { | - |
175 | return d_func()->value; executed: return d_func()->value; Execution Count:31 | 31 |
176 | } | - |
177 | void 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 yes Evaluation Count:31 | yes Evaluation Count:33 |
evaluated: maximum != d->maximum 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) yes Evaluation Count:22 | yes Evaluation Count:32 |
evaluated: d->value > d->maximum 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 |
190 | void 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 | } | 0 |
197 | } | 0 |
198 | | - |
199 | bool QProgressBar::isTextVisible() const | - |
200 | { | - |
201 | return d_func()->textVisible; never executed: return d_func()->textVisible; | 0 |
202 | } | - |
203 | | - |
204 | | - |
205 | | - |
206 | | - |
207 | | - |
208 | void 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 | } | 0 |
214 | } | 0 |
215 | | - |
216 | Qt::Alignment QProgressBar::alignment() const | - |
217 | { | - |
218 | return d_func()->alignment; never executed: return d_func()->alignment; | 0 |
219 | } | - |
220 | | - |
221 | | - |
222 | | - |
223 | | - |
224 | void 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 | | - |
236 | QSize 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 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 | | - |
252 | QSize QProgressBar::minimumSizeHint() const | - |
253 | { | - |
254 | QSize size; | - |
255 | if (orientation() == Qt::Horizontal) partially evaluated: orientation() == Qt::Horizontal 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 | } | - |
261 | QString 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 yes Evaluation Count:19 | yes Evaluation Count:129 |
evaluated: d->minimum == 0 yes Evaluation Count:18 | yes Evaluation Count:1 |
evaluated: d->value < d->minimum 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) 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 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 | } | - |
286 | void 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; | 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 | } | 0 |
298 | d->resetLayoutItemMargins(); | - |
299 | update(); | - |
300 | updateGeometry(); | - |
301 | } | 0 |
302 | | - |
303 | Qt::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 | } | - |
308 | void QProgressBar::setInvertedAppearance(bool invert) | - |
309 | { | - |
310 | QProgressBarPrivate * const d = d_func(); | - |
311 | d->invertedAppearance = invert; | - |
312 | update(); | - |
313 | } executed: } Execution Count:2 | 2 |
314 | | - |
315 | bool QProgressBar::invertedAppearance() const | - |
316 | { | - |
317 | const QProgressBarPrivate * const d = d_func(); | - |
318 | return d->invertedAppearance; executed: return d->invertedAppearance; Execution Count:2 | 2 |
319 | } | - |
320 | void QProgressBar::setTextDirection(QProgressBar::Direction textDirection) | - |
321 | { | - |
322 | QProgressBarPrivate * const d = d_func(); | - |
323 | d->textDirection = textDirection; | - |
324 | update(); | - |
325 | } | 0 |
326 | | - |
327 | QProgressBar::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 | | - |
334 | bool QProgressBar::event(QEvent *e) | - |
335 | { | - |
336 | QProgressBarPrivate * const d = d_func(); | - |
337 | if (e->type() == QEvent::StyleChange evaluated: e->type() == QEvent::StyleChange 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 | } | - |
345 | void QProgressBar::setFormat(const QString &format) | - |
346 | { | - |
347 | QProgressBarPrivate * const d = d_func(); | - |
348 | if (d->format == format) evaluated: d->format == format 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 | | - |
354 | QString 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 | | - |
| | |