qprogressdialog.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/widgets/dialogs/qprogressdialog.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2015 The Qt Company Ltd.-
4** Contact: http://www.qt.io/licensing/-
5**-
6** This file is part of the QtWidgets module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL21$-
9** Commercial License Usage-
10** Licensees holding valid commercial Qt licenses may use this file in-
11** accordance with the commercial license agreement provided with the-
12** Software or, alternatively, in accordance with the terms contained in-
13** a written agreement between you and The Qt Company. For licensing terms-
14** and conditions see http://www.qt.io/terms-conditions. For further-
15** information use the contact form at http://www.qt.io/contact-us.-
16**-
17** GNU Lesser General Public License Usage-
18** Alternatively, this file may be used under the terms of the GNU Lesser-
19** General Public License version 2.1 or version 3 as published by the Free-
20** Software Foundation and appearing in the file LICENSE.LGPLv21 and-
21** LICENSE.LGPLv3 included in the packaging of this file. Please review the-
22** following information to ensure the GNU Lesser General Public License-
23** requirements will be met: https://www.gnu.org/licenses/lgpl.html and-
24** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.-
25**-
26** As a special exception, The Qt Company gives you certain additional-
27** rights. These rights are described in The Qt Company LGPL Exception-
28** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.-
29**-
30** $QT_END_LICENSE$-
31**-
32****************************************************************************/-
33-
34#include "qprogressdialog.h"-
35-
36#ifndef QT_NO_PROGRESSDIALOG-
37-
38#include "qshortcut.h"-
39#include "qpainter.h"-
40#include "qdrawutil.h"-
41#include "qlabel.h"-
42#include "qprogressbar.h"-
43#include "qapplication.h"-
44#include "qstyle.h"-
45#include "qpushbutton.h"-
46#include "qcursor.h"-
47#include "qtimer.h"-
48#include "qelapsedtimer.h"-
49#include <private/qdialog_p.h>-
50#include <limits.h>-
51-
52QT_BEGIN_NAMESPACE-
53-
54// If the operation is expected to take this long (as predicted by-
55// progress time), show the progress dialog.-
56static const int defaultShowTime = 4000;-
57// Wait at least this long before attempting to make a prediction.-
58static const int minWaitTime = 50;-
59-
60class QProgressDialogPrivate : public QDialogPrivate-
61{-
62 Q_DECLARE_PUBLIC(QProgressDialog)-
63-
64public:-
65 QProgressDialogPrivate() : label(0), cancel(0), bar(0),-
66 shown_once(false),-
67 cancellation_flag(false),-
68 setValue_called(false),-
69 showTime(defaultShowTime),-
70#ifndef QT_NO_SHORTCUT-
71 escapeShortcut(0),-
72#endif-
73 useDefaultCancelText(false)-
74 {-
75 }
never executed: end of block
0
76-
77 void init(const QString &labelText, const QString &cancelText, int min, int max);-
78 void layout();-
79 void retranslateStrings();-
80 void setCancelButtonText(const QString &cancelButtonText);-
81 void adoptChildWidget(QWidget *c);-
82 void ensureSizeIsAtLeastSizeHint();-
83 void _q_disconnectOnClose();-
84-
85 QLabel *label;-
86 QPushButton *cancel;-
87 QProgressBar *bar;-
88 QTimer *forceTimer;-
89 bool shown_once;-
90 bool cancellation_flag;-
91 bool setValue_called;-
92 QElapsedTimer starttime;-
93#ifndef QT_NO_CURSOR-
94 QCursor parentCursor;-
95#endif-
96 int showTime;-
97 bool autoClose;-
98 bool autoReset;-
99 bool forceHide;-
100#ifndef QT_NO_SHORTCUT-
101 QShortcut *escapeShortcut;-
102#endif-
103 bool useDefaultCancelText;-
104 QPointer<QObject> receiverToDisconnectOnClose;-
105 QByteArray memberToDisconnectOnClose;-
106};-
107-
108void QProgressDialogPrivate::init(const QString &labelText, const QString &cancelText,-
109 int min, int max)-
110{-
111 Q_Q(QProgressDialog);-
112 label = new QLabel(labelText, q);-
113 bar = new QProgressBar(q);-
114 bar->setRange(min, max);-
115 int align = q->style()->styleHint(QStyle::SH_ProgressDialog_TextLabelAlignment, 0, q);-
116 label->setAlignment(Qt::Alignment(align));-
117 autoClose = true;-
118 autoReset = true;-
119 forceHide = false;-
120 QObject::connect(q, SIGNAL(canceled()), q, SLOT(cancel()));-
121 forceTimer = new QTimer(q);-
122 QObject::connect(forceTimer, SIGNAL(timeout()), q, SLOT(forceShow()));-
123 if (useDefaultCancelText) {
useDefaultCancelTextDescription
TRUEnever evaluated
FALSEnever evaluated
0
124 retranslateStrings();-
125 } else {
never executed: end of block
0
126 q->setCancelButtonText(cancelText);-
127 }
never executed: end of block
0
128 starttime.start();-
129 forceTimer->start(showTime);-
130}
never executed: end of block
0
131-
132void QProgressDialogPrivate::layout()-
133{-
134 Q_Q(QProgressDialog);-
135 int sp = q->style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing);-
136 int mtb = q->style()->pixelMetric(QStyle::PM_DefaultTopLevelMargin);-
137 int mlr = qMin(q->width() / 10, mtb);-
138 const bool centered =-
139 bool(q->style()->styleHint(QStyle::SH_ProgressDialog_CenterCancelButton, 0, q));-
140-
141 int additionalSpacing = 0;-
142 QSize cs = cancel ? cancel->sizeHint() : QSize(0,0);
cancelDescription
TRUEnever evaluated
FALSEnever evaluated
0
143 QSize bh = bar->sizeHint();-
144 int cspc;-
145 int lh = 0;-
146-
147 // Find spacing and sizes that fit. It is important that a progress-
148 // dialog can be made very small if the user demands it so.-
149 for (int attempt=5; attempt--;) {
attempt--Description
TRUEnever evaluated
FALSEnever evaluated
0
150 cspc = cancel ? cs.height() + sp : 0;
cancelDescription
TRUEnever evaluated
FALSEnever evaluated
0
151 lh = qMax(0, q->height() - mtb - bh.height() - sp - cspc);-
152-
153 if (lh < q->height()/4) {
lh < q->height()/4Description
TRUEnever evaluated
FALSEnever evaluated
0
154 // Getting cramped-
155 sp /= 2;-
156 mtb /= 2;-
157 if (cancel) {
cancelDescription
TRUEnever evaluated
FALSEnever evaluated
0
158 cs.setHeight(qMax(4,cs.height()-sp-2));-
159 }
never executed: end of block
0
160 bh.setHeight(qMax(4,bh.height()-sp-1));-
161 } else {
never executed: end of block
0
162 break;
never executed: break;
0
163 }-
164 }-
165-
166 if (cancel) {
cancelDescription
TRUEnever evaluated
FALSEnever evaluated
0
167 cancel->setGeometry(-
168 centered ? q->width()/2 - cs.width()/2 : q->width() - mlr - cs.width(),-
169 q->height() - mtb - cs.height(),-
170 cs.width(), cs.height());-
171 }
never executed: end of block
0
172-
173 if (label)
labelDescription
TRUEnever evaluated
FALSEnever evaluated
0
174 label->setGeometry(mlr, additionalSpacing, q->width() - mlr * 2, lh);
never executed: label->setGeometry(mlr, additionalSpacing, q->width() - mlr * 2, lh);
0
175 bar->setGeometry(mlr, lh + sp + additionalSpacing, q->width() - mlr * 2, bh.height());-
176}
never executed: end of block
0
177-
178void QProgressDialogPrivate::retranslateStrings()-
179{-
180 if (useDefaultCancelText)
useDefaultCancelTextDescription
TRUEnever evaluated
FALSEnever evaluated
0
181 setCancelButtonText(QProgressDialog::tr("Cancel"));
never executed: setCancelButtonText(QProgressDialog::tr("Cancel"));
0
182}
never executed: end of block
0
183-
184void QProgressDialogPrivate::_q_disconnectOnClose()-
185{-
186 Q_Q(QProgressDialog);-
187 if (receiverToDisconnectOnClose) {
receiverToDisconnectOnCloseDescription
TRUEnever evaluated
FALSEnever evaluated
0
188 QObject::disconnect(q, SIGNAL(canceled()), receiverToDisconnectOnClose,-
189 memberToDisconnectOnClose);-
190 receiverToDisconnectOnClose = 0;-
191 }
never executed: end of block
0
192 memberToDisconnectOnClose.clear();-
193}
never executed: end of block
0
194-
195/*!-
196 \class QProgressDialog-
197 \brief The QProgressDialog class provides feedback on the progress of a slow operation.-
198 \ingroup standard-dialogs-
199 \inmodule QtWidgets-
200-
201-
202 A progress dialog is used to give the user an indication of how long-
203 an operation is going to take, and to demonstrate that the-
204 application has not frozen. It can also give the user an opportunity-
205 to abort the operation.-
206-
207 A common problem with progress dialogs is that it is difficult to know-
208 when to use them; operations take different amounts of time on different-
209 hardware. QProgressDialog offers a solution to this problem:-
210 it estimates the time the operation will take (based on time for-
211 steps), and only shows itself if that estimate is beyond minimumDuration()-
212 (4 seconds by default).-
213-
214 Use setMinimum() and setMaximum() or the constructor to set the number of-
215 "steps" in the operation and call setValue() as the operation-
216 progresses. The number of steps can be chosen arbitrarily. It can be the-
217 number of files copied, the number of bytes received, the number of-
218 iterations through the main loop of your algorithm, or some other-
219 suitable unit. Progress starts at the value set by setMinimum(),-
220 and the progress dialog shows that the operation has finished when-
221 you call setValue() with the value set by setMaximum() as its argument.-
222-
223 The dialog automatically resets and hides itself at the end of the-
224 operation. Use setAutoReset() and setAutoClose() to change this-
225 behavior. Note that if you set a new maximum (using setMaximum() or-
226 setRange()) that equals your current value(), the dialog will not-
227 close regardless.-
228-
229 There are two ways of using QProgressDialog: modal and modeless.-
230-
231 Compared to a modeless QProgressDialog, a modal QProgressDialog is simpler-
232 to use for the programmer. Do the operation in a loop, call \l setValue() at-
233 intervals, and check for cancellation with wasCanceled(). For example:-
234-
235 \snippet dialogs/dialogs.cpp 3-
236-
237 A modeless progress dialog is suitable for operations that take-
238 place in the background, where the user is able to interact with the-
239 application. Such operations are typically based on QTimer (or-
240 QObject::timerEvent()), QSocketNotifier, or QUrlOperator; or performed-
241 in a separate thread. A QProgressBar in the status bar of your main window-
242 is often an alternative to a modeless progress dialog.-
243-
244 You need to have an event loop to be running, connect the-
245 canceled() signal to a slot that stops the operation, and call \l-
246 setValue() at intervals. For example:-
247-
248 \snippet dialogs/dialogs.cpp 4-
249 \codeline-
250 \snippet dialogs/dialogs.cpp 5-
251 \codeline-
252 \snippet dialogs/dialogs.cpp 6-
253-
254 In both modes the progress dialog may be customized by-
255 replacing the child widgets with custom widgets by using setLabel(),-
256 setBar(), and setCancelButton().-
257 The functions setLabelText() and setCancelButtonText()-
258 set the texts shown.-
259-
260 \image fusion-progressdialog.png A progress dialog shown in the Fusion widget style.-
261-
262 \sa QDialog, QProgressBar, {fowler}{GUI Design Handbook: Progress Indicator},-
263 {Find Files Example}, {Pixelator Example}-
264*/-
265-
266-
267/*!-
268 Constructs a progress dialog.-
269-
270 Default settings:-
271 \list-
272 \li The label text is empty.-
273 \li The cancel button text is (translated) "Cancel".-
274 \li minimum is 0;-
275 \li maximum is 100-
276 \endlist-
277-
278 The \a parent argument is dialog's parent widget. The widget flags, \a f, are-
279 passed to the QDialog::QDialog() constructor.-
280-
281 \sa setLabelText(), setCancelButtonText(), setCancelButton(),-
282 setMinimum(), setMaximum()-
283*/-
284-
285QProgressDialog::QProgressDialog(QWidget *parent, Qt::WindowFlags f)-
286 : QDialog(*(new QProgressDialogPrivate), parent, f)-
287{-
288 Q_D(QProgressDialog);-
289 d->useDefaultCancelText = true;-
290 d->init(QString::fromLatin1(""), QString(), 0, 100);-
291}
never executed: end of block
0
292-
293/*!-
294 Constructs a progress dialog.-
295-
296 The \a labelText is the text used to remind the user what is progressing.-
297-
298 The \a cancelButtonText is the text to display on the cancel button. If-
299 QString() is passed then no cancel button is shown.-
300-
301 The \a minimum and \a maximum is the number of steps in the operation for-
302 which this progress dialog shows progress. For example, if the-
303 operation is to examine 50 files, this value minimum value would be 0,-
304 and the maximum would be 50. Before examining the first file, call-
305 setValue(0). As each file is processed call setValue(1), setValue(2),-
306 etc., finally calling setValue(50) after examining the last file.-
307-
308 The \a parent argument is the dialog's parent widget. The parent, \a parent, and-
309 widget flags, \a f, are passed to the QDialog::QDialog() constructor.-
310-
311 \sa setLabelText(), setLabel(), setCancelButtonText(), setCancelButton(),-
312 setMinimum(), setMaximum()-
313*/-
314-
315QProgressDialog::QProgressDialog(const QString &labelText,-
316 const QString &cancelButtonText,-
317 int minimum, int maximum,-
318 QWidget *parent, Qt::WindowFlags f)-
319 : QDialog(*(new QProgressDialogPrivate), parent, f)-
320{-
321 Q_D(QProgressDialog);-
322 d->init(labelText, cancelButtonText, minimum, maximum);-
323}
never executed: end of block
0
324-
325-
326/*!-
327 Destroys the progress dialog.-
328*/-
329-
330QProgressDialog::~QProgressDialog()-
331{-
332}-
333-
334/*!-
335 \fn void QProgressDialog::canceled()-
336-
337 This signal is emitted when the cancel button is clicked.-
338 It is connected to the cancel() slot by default.-
339-
340 \sa wasCanceled()-
341*/-
342-
343-
344/*!-
345 Sets the label to \a label. The progress dialog resizes to fit. The-
346 label becomes owned by the progress dialog and will be deleted when-
347 necessary, so do not pass the address of an object on the stack.-
348-
349 \sa setLabelText()-
350*/-
351-
352void QProgressDialog::setLabel(QLabel *label)-
353{-
354 Q_D(QProgressDialog);-
355 if (label == d->label) {
label == d->labelDescription
TRUEnever evaluated
FALSEnever evaluated
0
356 if (label)
labelDescription
TRUEnever evaluated
FALSEnever evaluated
0
357 qWarning("QProgressDialog::setLabel: Attempt to set the same label again");
never executed: QMessageLogger(__FILE__, 357, __PRETTY_FUNCTION__).warning("QProgressDialog::setLabel: Attempt to set the same label again");
0
358 return;
never executed: return;
0
359 }-
360 delete d->label;-
361 d->label = label;-
362 d->adoptChildWidget(label);-
363}
never executed: end of block
0
364-
365-
366/*!-
367 \property QProgressDialog::labelText-
368 \brief the label's text-
369-
370 The default text is an empty string.-
371*/-
372-
373QString QProgressDialog::labelText() const-
374{-
375 Q_D(const QProgressDialog);-
376 if (d->label)
d->labelDescription
TRUEnever evaluated
FALSEnever evaluated
0
377 return d->label->text();
never executed: return d->label->text();
0
378 return QString();
never executed: return QString();
0
379}-
380-
381void QProgressDialog::setLabelText(const QString &text)-
382{-
383 Q_D(QProgressDialog);-
384 if (d->label) {
d->labelDescription
TRUEnever evaluated
FALSEnever evaluated
0
385 d->label->setText(text);-
386 d->ensureSizeIsAtLeastSizeHint();-
387 }
never executed: end of block
0
388}
never executed: end of block
0
389-
390-
391/*!-
392 Sets the cancel button to the push button, \a cancelButton. The-
393 progress dialog takes ownership of this button which will be deleted-
394 when necessary, so do not pass the address of an object that is on-
395 the stack, i.e. use new() to create the button. If 0 is passed then-
396 no cancel button will be shown.-
397-
398 \sa setCancelButtonText()-
399*/-
400-
401void QProgressDialog::setCancelButton(QPushButton *cancelButton)-
402{-
403 Q_D(QProgressDialog);-
404 if (d->cancel == cancelButton) {
d->cancel == cancelButtonDescription
TRUEnever evaluated
FALSEnever evaluated
0
405 if (cancelButton)
cancelButtonDescription
TRUEnever evaluated
FALSEnever evaluated
0
406 qWarning("QProgressDialog::setCancelButton: Attempt to set the same button again");
never executed: QMessageLogger(__FILE__, 406, __PRETTY_FUNCTION__).warning("QProgressDialog::setCancelButton: Attempt to set the same button again");
0
407 return;
never executed: return;
0
408 }-
409 delete d->cancel;-
410 d->cancel = cancelButton;-
411 if (cancelButton) {
cancelButtonDescription
TRUEnever evaluated
FALSEnever evaluated
0
412 connect(d->cancel, SIGNAL(clicked()), this, SIGNAL(canceled()));-
413#ifndef QT_NO_SHORTCUT-
414 // FIXME: This only registers the primary key sequence of the cancel action-
415 d->escapeShortcut = new QShortcut(QKeySequence::Cancel, this, SIGNAL(canceled()));-
416#endif-
417 } else {
never executed: end of block
0
418#ifndef QT_NO_SHORTCUT-
419 delete d->escapeShortcut;-
420 d->escapeShortcut = 0;-
421#endif-
422 }
never executed: end of block
0
423 d->adoptChildWidget(cancelButton);-
424}
never executed: end of block
0
425-
426/*!-
427 Sets the cancel button's text to \a cancelButtonText. If the text-
428 is set to QString() then it will cause the cancel button to be-
429 hidden and deleted.-
430-
431 \sa setCancelButton()-
432*/-
433-
434void QProgressDialog::setCancelButtonText(const QString &cancelButtonText)-
435{-
436 Q_D(QProgressDialog);-
437 d->useDefaultCancelText = false;-
438 d->setCancelButtonText(cancelButtonText);-
439}
never executed: end of block
0
440-
441void QProgressDialogPrivate::setCancelButtonText(const QString &cancelButtonText)-
442{-
443 Q_Q(QProgressDialog);-
444-
445 if (!cancelButtonText.isNull()) {
!cancelButtonText.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
446 if (cancel) {
cancelDescription
TRUEnever evaluated
FALSEnever evaluated
0
447 cancel->setText(cancelButtonText);-
448 } else {
never executed: end of block
0
449 q->setCancelButton(new QPushButton(cancelButtonText, q));-
450 }
never executed: end of block
0
451 } else {-
452 q->setCancelButton(0);-
453 }
never executed: end of block
0
454 ensureSizeIsAtLeastSizeHint();-
455}
never executed: end of block
0
456-
457-
458/*!-
459 Sets the progress bar widget to \a bar. The progress dialog resizes to-
460 fit. The progress dialog takes ownership of the progress \a bar which-
461 will be deleted when necessary, so do not use a progress bar-
462 allocated on the stack.-
463*/-
464-
465void QProgressDialog::setBar(QProgressBar *bar)-
466{-
467 Q_D(QProgressDialog);-
468 if (!bar) {
!barDescription
TRUEnever evaluated
FALSEnever evaluated
0
469 qWarning("QProgressDialog::setBar: Cannot set a null progress bar");-
470 return;
never executed: return;
0
471 }-
472#ifndef QT_NO_DEBUG-
473 if (value() > 0)
value() > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
474 qWarning("QProgressDialog::setBar: Cannot set a new progress bar "
never executed: QMessageLogger(__FILE__, 474, __PRETTY_FUNCTION__).warning("QProgressDialog::setBar: Cannot set a new progress bar " "while the old one is active");
0
475 "while the old one is active");
never executed: QMessageLogger(__FILE__, 474, __PRETTY_FUNCTION__).warning("QProgressDialog::setBar: Cannot set a new progress bar " "while the old one is active");
0
476#endif-
477 if (bar == d->bar) {
bar == d->barDescription
TRUEnever evaluated
FALSEnever evaluated
0
478 qWarning("QProgressDialog::setBar: Attempt to set the same progress bar again");-
479 return;
never executed: return;
0
480 }-
481 delete d->bar;-
482 d->bar = bar;-
483 d->adoptChildWidget(bar);-
484}
never executed: end of block
0
485-
486void QProgressDialogPrivate::adoptChildWidget(QWidget *c)-
487{-
488 Q_Q(QProgressDialog);-
489-
490 if (c) {
cDescription
TRUEnever evaluated
FALSEnever evaluated
0
491 if (c->parentWidget() == q)
c->parentWidget() == qDescription
TRUEnever evaluated
FALSEnever evaluated
0
492 c->hide(); // until after ensureSizeIsAtLeastSizeHint()
never executed: c->hide();
0
493 else-
494 c->setParent(q, 0);
never executed: c->setParent(q, 0);
0
495 }-
496 ensureSizeIsAtLeastSizeHint();-
497 if (c)
cDescription
TRUEnever evaluated
FALSEnever evaluated
0
498 c->show();
never executed: c->show();
0
499}
never executed: end of block
0
500-
501void QProgressDialogPrivate::ensureSizeIsAtLeastSizeHint()-
502{-
503 Q_Q(QProgressDialog);-
504-
505 QSize size = q->sizeHint();-
506 if (q->isVisible())
q->isVisible()Description
TRUEnever evaluated
FALSEnever evaluated
0
507 size = size.expandedTo(q->size());
never executed: size = size.expandedTo(q->size());
0
508 q->resize(size);-
509}
never executed: end of block
0
510-
511-
512/*!-
513 \property QProgressDialog::wasCanceled-
514 \brief whether the dialog was canceled-
515*/-
516-
517bool QProgressDialog::wasCanceled() const-
518{-
519 Q_D(const QProgressDialog);-
520 return d->cancellation_flag;
never executed: return d->cancellation_flag;
0
521}-
522-
523-
524/*!-
525 \property QProgressDialog::maximum-
526 \brief the highest value represented by the progress bar-
527-
528 The default is 100.-
529-
530 \sa minimum, setRange()-
531*/-
532-
533int QProgressDialog::maximum() const-
534{-
535 Q_D(const QProgressDialog);-
536 return d->bar->maximum();
never executed: return d->bar->maximum();
0
537}-
538-
539void QProgressDialog::setMaximum(int maximum)-
540{-
541 Q_D(QProgressDialog);-
542 d->bar->setMaximum(maximum);-
543}
never executed: end of block
0
544-
545/*!-
546 \property QProgressDialog::minimum-
547 \brief the lowest value represented by the progress bar-
548-
549 The default is 0.-
550-
551 \sa maximum, setRange()-
552*/-
553-
554int QProgressDialog::minimum() const-
555{-
556 Q_D(const QProgressDialog);-
557 return d->bar->minimum();
never executed: return d->bar->minimum();
0
558}-
559-
560void QProgressDialog::setMinimum(int minimum)-
561{-
562 Q_D(QProgressDialog);-
563 d->bar->setMinimum(minimum);-
564}
never executed: end of block
0
565-
566/*!-
567 Sets the progress dialog's minimum and maximum values-
568 to \a minimum and \a maximum, respectively.-
569-
570 If \a maximum is smaller than \a minimum, \a minimum becomes the only-
571 legal value.-
572-
573 If the current value falls outside the new range, the progress-
574 dialog is reset with reset().-
575-
576 \sa minimum, maximum-
577*/-
578void QProgressDialog::setRange(int minimum, int maximum)-
579{-
580 Q_D(QProgressDialog);-
581 d->bar->setRange(minimum, maximum);-
582}
never executed: end of block
0
583-
584-
585/*!-
586 Resets the progress dialog.-
587 The progress dialog becomes hidden if autoClose() is true.-
588-
589 \sa setAutoClose(), setAutoReset()-
590*/-
591-
592void QProgressDialog::reset()-
593{-
594 Q_D(QProgressDialog);-
595#ifndef QT_NO_CURSOR-
596 if (value() >= 0) {
value() >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
597 if (parentWidget())
parentWidget()Description
TRUEnever evaluated
FALSEnever evaluated
0
598 parentWidget()->setCursor(d->parentCursor);
never executed: parentWidget()->setCursor(d->parentCursor);
0
599 }
never executed: end of block
0
600#endif-
601 if (d->autoClose || d->forceHide)
d->autoCloseDescription
TRUEnever evaluated
FALSEnever evaluated
d->forceHideDescription
TRUEnever evaluated
FALSEnever evaluated
0
602 hide();
never executed: hide();
0
603 d->bar->reset();-
604 d->cancellation_flag = false;-
605 d->shown_once = false;-
606 d->setValue_called = false;-
607 d->forceTimer->stop();-
608-
609 /*-
610 I wish we could disconnect the user slot provided to open() here but-
611 unfortunately reset() is usually called before the slot has been invoked.-
612 (reset() is itself invoked when canceled() is emitted.)-
613 */-
614 if (d->receiverToDisconnectOnClose)
d->receiverToDisconnectOnCloseDescription
TRUEnever evaluated
FALSEnever evaluated
0
615 QMetaObject::invokeMethod(this, "_q_disconnectOnClose", Qt::QueuedConnection);
never executed: QMetaObject::invokeMethod(this, "_q_disconnectOnClose", Qt::QueuedConnection);
0
616}
never executed: end of block
0
617-
618/*!-
619 Resets the progress dialog. wasCanceled() becomes true until-
620 the progress dialog is reset.-
621 The progress dialog becomes hidden.-
622*/-
623-
624void QProgressDialog::cancel()-
625{-
626 Q_D(QProgressDialog);-
627 d->forceHide = true;-
628 reset();-
629 d->forceHide = false;-
630 d->cancellation_flag = true;-
631}
never executed: end of block
0
632-
633-
634int QProgressDialog::value() const-
635{-
636 Q_D(const QProgressDialog);-
637 return d->bar->value();
never executed: return d->bar->value();
0
638}-
639-
640/*!-
641 \property QProgressDialog::value-
642 \brief the current amount of progress made.-
643-
644 For the progress dialog to work as expected, you should initially set-
645 this property to QProgressDialog::minimum() and finally set it to-
646 QProgressDialog::maximum(); you can call setValue() any number of times-
647 in-between.-
648-
649 \warning If the progress dialog is modal-
650 (see QProgressDialog::QProgressDialog()),-
651 setValue() calls QApplication::processEvents(), so take care that-
652 this does not cause undesirable re-entrancy in your code. For example,-
653 don't use a QProgressDialog inside a paintEvent()!-
654-
655 \sa minimum, maximum-
656*/-
657void QProgressDialog::setValue(int progress)-
658{-
659 Q_D(QProgressDialog);-
660 if (d->setValue_called && progress == d->bar->value())
d->setValue_calledDescription
TRUEnever evaluated
FALSEnever evaluated
progress == d->bar->value()Description
TRUEnever evaluated
FALSEnever evaluated
0
661 return;
never executed: return;
0
662-
663 d->bar->setValue(progress);-
664-
665 if (d->shown_once) {
d->shown_onceDescription
TRUEnever evaluated
FALSEnever evaluated
0
666 if (isModal())
isModal()Description
TRUEnever evaluated
FALSEnever evaluated
0
667 QApplication::processEvents();
never executed: QApplication::processEvents();
0
668 } else {
never executed: end of block
0
669 if ((!d->setValue_called && progress == 0 /* for compat with Qt < 5.4 */) || progress == minimum()) {
!d->setValue_calledDescription
TRUEnever evaluated
FALSEnever evaluated
progress == 0Description
TRUEnever evaluated
FALSEnever evaluated
progress == minimum()Description
TRUEnever evaluated
FALSEnever evaluated
0
670 d->starttime.start();-
671 d->forceTimer->start(d->showTime);-
672 d->setValue_called = true;-
673 return;
never executed: return;
0
674 } else {-
675 d->setValue_called = true;-
676 bool need_show;-
677 int elapsed = d->starttime.elapsed();-
678 if (elapsed >= d->showTime) {
elapsed >= d->showTimeDescription
TRUEnever evaluated
FALSEnever evaluated
0
679 need_show = true;-
680 } else {
never executed: end of block
0
681 if (elapsed > minWaitTime) {
elapsed > minWaitTimeDescription
TRUEnever evaluated
FALSEnever evaluated
0
682 int estimate;-
683 int totalSteps = maximum() - minimum();-
684 int myprogress = progress - minimum();-
685 if (myprogress == 0) myprogress = 1;
never executed: myprogress = 1;
myprogress == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
686 if ((totalSteps - myprogress) >= INT_MAX / elapsed)
(totalSteps - ...3647 / elapsedDescription
TRUEnever evaluated
FALSEnever evaluated
0
687 estimate = (totalSteps - myprogress) / myprogress * elapsed;
never executed: estimate = (totalSteps - myprogress) / myprogress * elapsed;
0
688 else-
689 estimate = elapsed * (totalSteps - myprogress) / myprogress;
never executed: estimate = elapsed * (totalSteps - myprogress) / myprogress;
0
690 need_show = estimate >= d->showTime;-
691 } else {
never executed: end of block
0
692 need_show = false;-
693 }
never executed: end of block
0
694 }-
695 if (need_show) {
need_showDescription
TRUEnever evaluated
FALSEnever evaluated
0
696 d->ensureSizeIsAtLeastSizeHint();-
697 show();-
698 d->shown_once = true;-
699 }
never executed: end of block
0
700 }
never executed: end of block
0
701 }-
702-
703 if (progress == d->bar->maximum() && d->autoReset)
progress == d->bar->maximum()Description
TRUEnever evaluated
FALSEnever evaluated
d->autoResetDescription
TRUEnever evaluated
FALSEnever evaluated
0
704 reset();
never executed: reset();
0
705}
never executed: end of block
0
706-
707/*!-
708 Returns a size that fits the contents of the progress dialog.-
709 The progress dialog resizes itself as required, so you should not-
710 need to call this yourself.-
711*/-
712-
713QSize QProgressDialog::sizeHint() const-
714{-
715 Q_D(const QProgressDialog);-
716 QSize sh = d->label ? d->label->sizeHint() : QSize(0, 0);
d->labelDescription
TRUEnever evaluated
FALSEnever evaluated
0
717 QSize bh = d->bar->sizeHint();-
718 int margin = style()->pixelMetric(QStyle::PM_DefaultTopLevelMargin);-
719 int spacing = style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing);-
720 int h = margin * 2 + bh.height() + sh.height() + spacing;-
721 if (d->cancel)
d->cancelDescription
TRUEnever evaluated
FALSEnever evaluated
0
722 h += d->cancel->sizeHint().height() + spacing;
never executed: h += d->cancel->sizeHint().height() + spacing;
0
723 return QSize(qMax(200, sh.width() + 2 * margin), h);
never executed: return QSize(qMax(200, sh.width() + 2 * margin), h);
0
724}-
725-
726/*!\reimp-
727*/-
728void QProgressDialog::resizeEvent(QResizeEvent *)-
729{-
730 Q_D(QProgressDialog);-
731 d->layout();-
732}
never executed: end of block
0
733-
734/*!-
735 \reimp-
736*/-
737void QProgressDialog::changeEvent(QEvent *ev)-
738{-
739 Q_D(QProgressDialog);-
740 if (ev->type() == QEvent::StyleChange) {
ev->type() == ...t::StyleChangeDescription
TRUEnever evaluated
FALSEnever evaluated
0
741 d->layout();-
742 } else if (ev->type() == QEvent::LanguageChange) {
never executed: end of block
ev->type() == ...LanguageChangeDescription
TRUEnever evaluated
FALSEnever evaluated
0
743 d->retranslateStrings();-
744 }
never executed: end of block
0
745 QDialog::changeEvent(ev);-
746}
never executed: end of block
0
747-
748/*!-
749 \property QProgressDialog::minimumDuration-
750 \brief the time that must pass before the dialog appears-
751-
752 If the expected duration of the task is less than the-
753 minimumDuration, the dialog will not appear at all. This prevents-
754 the dialog popping up for tasks that are quickly over. For tasks-
755 that are expected to exceed the minimumDuration, the dialog will-
756 pop up after the minimumDuration time or as soon as any progress-
757 is set.-
758-
759 If set to 0, the dialog is always shown as soon as any progress is-
760 set. The default is 4000 milliseconds.-
761*/-
762void QProgressDialog::setMinimumDuration(int ms)-
763{-
764 Q_D(QProgressDialog);-
765 d->showTime = ms;-
766 if (d->bar->value() == d->bar->minimum()) {
d->bar->value(...bar->minimum()Description
TRUEnever evaluated
FALSEnever evaluated
0
767 d->forceTimer->stop();-
768 d->forceTimer->start(ms);-
769 }
never executed: end of block
0
770}
never executed: end of block
0
771-
772int QProgressDialog::minimumDuration() const-
773{-
774 Q_D(const QProgressDialog);-
775 return d->showTime;
never executed: return d->showTime;
0
776}-
777-
778-
779/*!-
780 \reimp-
781*/-
782-
783void QProgressDialog::closeEvent(QCloseEvent *e)-
784{-
785 emit canceled();-
786 QDialog::closeEvent(e);-
787}
never executed: end of block
0
788-
789/*!-
790 \property QProgressDialog::autoReset-
791 \brief whether the progress dialog calls reset() as soon as value() equals maximum()-
792-
793 The default is true.-
794-
795 \sa setAutoClose()-
796*/-
797-
798void QProgressDialog::setAutoReset(bool b)-
799{-
800 Q_D(QProgressDialog);-
801 d->autoReset = b;-
802}
never executed: end of block
0
803-
804bool QProgressDialog::autoReset() const-
805{-
806 Q_D(const QProgressDialog);-
807 return d->autoReset;
never executed: return d->autoReset;
0
808}-
809-
810/*!-
811 \property QProgressDialog::autoClose-
812 \brief whether the dialog gets hidden by reset()-
813-
814 The default is true.-
815-
816 \sa setAutoReset()-
817*/-
818-
819void QProgressDialog::setAutoClose(bool close)-
820{-
821 Q_D(QProgressDialog);-
822 d->autoClose = close;-
823}
never executed: end of block
0
824-
825bool QProgressDialog::autoClose() const-
826{-
827 Q_D(const QProgressDialog);-
828 return d->autoClose;
never executed: return d->autoClose;
0
829}-
830-
831/*!-
832 \reimp-
833*/-
834-
835void QProgressDialog::showEvent(QShowEvent *e)-
836{-
837 Q_D(QProgressDialog);-
838 QDialog::showEvent(e);-
839 d->ensureSizeIsAtLeastSizeHint();-
840 d->forceTimer->stop();-
841}
never executed: end of block
0
842-
843/*!-
844 Shows the dialog if it is still hidden after the algorithm has been started-
845 and minimumDuration milliseconds have passed.-
846-
847 \sa setMinimumDuration()-
848*/-
849-
850void QProgressDialog::forceShow()-
851{-
852 Q_D(QProgressDialog);-
853 d->forceTimer->stop();-
854 if (d->shown_once || d->cancellation_flag)
d->shown_onceDescription
TRUEnever evaluated
FALSEnever evaluated
d->cancellation_flagDescription
TRUEnever evaluated
FALSEnever evaluated
0
855 return;
never executed: return;
0
856-
857 show();-
858 d->shown_once = true;-
859}
never executed: end of block
0
860-
861/*!-
862 \since 4.5-
863 \overload-
864-
865 Opens the dialog and connects its canceled() signal to the slot specified-
866 by \a receiver and \a member.-
867-
868 The signal will be disconnected from the slot when the dialog is closed.-
869*/-
870void QProgressDialog::open(QObject *receiver, const char *member)-
871{-
872 Q_D(QProgressDialog);-
873 connect(this, SIGNAL(canceled()), receiver, member);-
874 d->receiverToDisconnectOnClose = receiver;-
875 d->memberToDisconnectOnClose = member;-
876 QDialog::open();-
877}
never executed: end of block
0
878-
879QT_END_NAMESPACE-
880-
881#include "moc_qprogressdialog.cpp"-
882-
883#endif // QT_NO_PROGRESSDIALOG-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9