19#include <private/qdialog_p.h>
21#include <QtCore/qpointer.h>
25using namespace std::chrono_literals;
79 label->setAlignment(Qt::Alignment(align));
86 q->setCancelButtonText(cancelText);
102 int additionalSpacing = 0;
110 for (
int attempt=5; attempt--;) {
112 lh =
qMax(0,
q->height() - mb - bh.height() -
sp - cspc);
121 bh.setHeight(
qMax(4,bh.height()-
sp-1));
129 centered ?
q->width()/2 - cs.
width()/2 :
q->width() - mr - cs.
width(),
130 q->height() - mb - cs.
height(),
135 label->setGeometry(ml, additionalSpacing,
q->width() - ml - mr, lh);
136 bar->
setGeometry(ml, lh +
sp + additionalSpacing,
q->width() - ml - mr, bh.height());
250 d->useDefaultCancelText =
true;
277 const QString &cancelButtonText,
278 int minimum,
int maximum,
318 qWarning(
"QProgressDialog::setLabel: Attempt to set the same label again");
323 d->adoptChildWidget(
label);
338 return d->label->text();
346 d->label->setText(
text);
347 d->ensureSizeIsAtLeastSizeHint();
365 if (
d->cancel == cancelButton) {
367 qWarning(
"QProgressDialog::setCancelButton: Attempt to set the same button again");
371 d->cancel = cancelButton;
374#ifndef QT_NO_SHORTCUT
378#ifndef QT_NO_SHORTCUT
379 delete d->escapeShortcut;
380 d->escapeShortcut =
nullptr;
383 d->adoptChildWidget(cancelButton);
397 d->useDefaultCancelText =
false;
398 d->setCancelButtonText(cancelButtonText);
405 if (!cancelButtonText.
isNull()) {
412 q->setCancelButton(
nullptr);
429 qWarning(
"QProgressDialog::setBar: Cannot set a null progress bar");
434 qWarning(
"QProgressDialog::setBar: Cannot set a new progress bar "
435 "while the old one is active");
438 qWarning(
"QProgressDialog::setBar: Attempt to set the same progress bar again");
443 d->adoptChildWidget(bar);
451 if (
c->parentWidget() ==
q)
454 c->setParent(
q, { });
482 return d->cancellationFlag;
498 return d->bar->maximum();
519 return d->bar->minimum();
557 if (
d->autoClose ||
d->forceHide)
560 d->cancellationFlag =
false;
561 d->shownOnce =
false;
562 d->setValueCalled =
false;
563 d->forceTimer->stop();
570 if (
d->receiverToDisconnectOnClose)
585 d->forceHide =
false;
586 d->cancellationFlag =
true;
593 return d->bar->value();
616 if (
d->setValueCalled && progress ==
d->bar->value())
619 d->bar->setValue(progress);
622 if (
isModal() && !
d->processingEvents) {
627 if ((!
d->setValueCalled && progress == 0 ) || progress ==
minimum()) {
628 d->starttime.start();
629 d->forceTimer->start(
d->showTime);
630 d->setValueCalled =
true;
633 d->setValueCalled =
true;
634 bool need_show =
false;
635 using namespace std::chrono;
636 nanoseconds
elapsed =
d->starttime.durationElapsed();
642 const int myprogress = std::max(progress -
minimum(), 1);
643 const int remainingSteps = totalSteps - myprogress;
644 nanoseconds estimate;
645 if (remainingSteps >= INT_MAX /
elapsed.count())
646 estimate = (remainingSteps / myprogress) *
elapsed;
648 estimate = (
elapsed * remainingSteps) / myprogress;
649 need_show = estimate >=
d->showTime;
653 d->ensureSizeIsAtLeastSizeHint();
660 if (progress ==
d->bar->maximum() &&
d->autoReset)
673 QSize labelSize =
d->label ?
d->label->sizeHint() :
QSize(0, 0);
674 QSize barSize =
d->bar->sizeHint();
680 int height = marginBottom * 2 + barSize.height() + labelSize.height() +
spacing;
683 return QSize(
qMax(200, labelSize.width() + marginLeft + marginRight),
height);
703 d->retranslateStrings();
725 std::chrono::milliseconds msecs{ms};
727 if (
d->bar->value() ==
d->bar->minimum()) {
728 d->forceTimer->stop();
729 d->forceTimer->start(msecs);
736 return int(
d->showTime.count());
800 d->ensureSizeIsAtLeastSizeHint();
801 d->forceTimer->stop();
814 d->forceTimer->stop();
815 if (
d->shownOnce ||
d->cancellationFlag)
834 d->receiverToDisconnectOnClose = receiver;
835 d->memberToDisconnectOnClose = member;
841#include "moc_qprogressdialog.cpp"
void clear()
Clears the contents of the byte array and makes it null.
The QCloseEvent class contains parameters that describe a close event.
static void processEvents(QEventLoop::ProcessEventsFlags flags=QEventLoop::AllEvents)
Processes some pending events for the calling thread according to the specified flags.
The QDialog class is the base class of dialog windows.
void closeEvent(QCloseEvent *) override
\reimp
void showEvent(QShowEvent *) override
\reimp
void start() noexcept
\typealias QElapsedTimer::Duration Synonym for std::chrono::nanoseconds.
The QLabel widget provides a text or image display.
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
\threadsafe
The QProgressBar widget provides a horizontal or vertical progress bar.
QSize sizeHint() const override
\reimp
void setRange(int minimum, int maximum)
Sets the progress bar's minimum and maximum values to minimum and maximum respectively.
QByteArray memberToDisconnectOnClose
void retranslateStrings()
void init(const QString &labelText, const QString &cancelText, int min, int max)
void setCancelButtonText(const QString &cancelButtonText)
std::chrono::milliseconds showTime
QPointer< QObject > receiverToDisconnectOnClose
void ensureSizeIsAtLeastSizeHint()
QProgressDialogPrivate()=default
void _q_disconnectOnClose()
bool useDefaultCancelText
void adoptChildWidget(QWidget *c)
QShortcut * escapeShortcut
The QProgressDialog class provides feedback on the progress of a slow operation.
void showEvent(QShowEvent *event) override
\reimp
void setMinimum(int minimum)
void canceled()
This signal is emitted when the cancel button is clicked.
void setBar(QProgressBar *bar)
Sets the progress bar widget to bar.
void setValue(int progress)
int minimum
the lowest value represented by the progress bar
QString labelText
the label's text
void closeEvent(QCloseEvent *event) override
\reimp
void setMaximum(int maximum)
QProgressDialog(QWidget *parent=nullptr, Qt::WindowFlags flags=Qt::WindowFlags())
Constructs a progress dialog.
void setRange(int minimum, int maximum)
Sets the progress dialog's minimum and maximum values to minimum and maximum, respectively.
void changeEvent(QEvent *event) override
\reimp
bool wasCanceled
whether the dialog was canceled
bool autoClose
whether the dialog gets hidden by reset()
bool autoReset
whether the progress dialog calls reset() as soon as value() equals maximum().
void setAutoReset(bool reset)
void cancel()
Resets the progress dialog.
int minimumDuration
the time that must pass before the dialog appears
void setLabel(QLabel *label)
Sets the label to label.
QSize sizeHint() const override
Returns a size that fits the contents of the progress dialog.
int maximum
the highest value represented by the progress bar
void resizeEvent(QResizeEvent *event) override
\reimp
void forceShow()
Shows the dialog if it is still hidden after the algorithm has been started and minimumDuration milli...
int value
the current amount of progress made.
void reset()
Resets the progress dialog.
~QProgressDialog()
Destroys the progress dialog.
void setLabelText(const QString &text)
void setAutoClose(bool close)
void setMinimumDuration(int ms)
void setCancelButton(QPushButton *button)
Sets the cancel button to the push button, cancelButton.
void setCancelButtonText(const QString &text)
Sets the cancel button's text to cancelButtonText.
The QResizeEvent class contains event parameters for resize events.
The QShortcut class is used to create keyboard shortcuts.
The QShowEvent class provides an event that is sent when a widget is shown.
constexpr int height() const noexcept
Returns the height.
constexpr int width() const noexcept
Returns the width.
constexpr QSize expandedTo(const QSize &) const noexcept
Returns a size holding the maximum width and height of this size and the given otherSize.
constexpr void setHeight(int h) noexcept
Sets the height to the given height.
\macro QT_RESTRICTED_CAST_FROM_ASCII
static QString fromLatin1(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool isNull() const
Returns true if this string is null; otherwise returns false.
@ SH_ProgressDialog_CenterCancelButton
@ SH_ProgressDialog_TextLabelAlignment
@ PM_LayoutVerticalSpacing
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option=nullptr, const QWidget *widget=nullptr) const =0
Returns the value of the given pixel metric.
void start(int msec)
Starts or restarts the timer with a timeout interval of msec milliseconds.
Combined button and popup list for selecting options.
constexpr const T & qMin(const T &a, const T &b)
constexpr const T & qMax(const T &a, const T &b)
GLboolean GLboolean GLboolean b
GLint GLsizei GLsizei height
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLbitfield GLuint64 timeout
[4]
GLuint GLsizei const GLchar * label
[43]
GLdouble GLdouble GLdouble GLdouble q
static QT_BEGIN_NAMESPACE constexpr auto defaultShowTime
static constexpr auto minWaitTime
static double elapsed(qint64 after, qint64 before)