|
|
|
|
@ -77,9 +77,10 @@ void QtProgressCallback::connectWidgets(QLabel* const status_label, QProgressBar
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QtAsyncTaskWithProgress::QtAsyncTaskWithProgress(const QString& initial_title, const QString& initial_status_text,
|
|
|
|
|
bool cancellable, int range, int value, float show_delay,
|
|
|
|
|
QWidget* dialog_parent, WorkCallback callback)
|
|
|
|
|
QtAsyncTaskWithProgressDialog::QtAsyncTaskWithProgressDialog(const QString& initial_title,
|
|
|
|
|
const QString& initial_status_text, bool cancellable,
|
|
|
|
|
int range, int value, float show_delay,
|
|
|
|
|
QWidget* dialog_parent, WorkCallback callback)
|
|
|
|
|
: m_callback(std::move(callback)), m_show_delay(show_delay)
|
|
|
|
|
{
|
|
|
|
|
m_dialog = new ProgressDialog(initial_title, initial_status_text, cancellable, range, value, *this, dialog_parent);
|
|
|
|
|
@ -91,7 +92,7 @@ QtAsyncTaskWithProgress::QtAsyncTaskWithProgress(const QString& initial_title, c
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QtAsyncTaskWithProgress::~QtAsyncTaskWithProgress()
|
|
|
|
|
QtAsyncTaskWithProgressDialog::~QtAsyncTaskWithProgressDialog()
|
|
|
|
|
{
|
|
|
|
|
if (m_dialog)
|
|
|
|
|
{
|
|
|
|
|
@ -101,9 +102,10 @@ QtAsyncTaskWithProgress::~QtAsyncTaskWithProgress()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QtAsyncTaskWithProgress::ProgressDialog::ProgressDialog(const QString& initial_title,
|
|
|
|
|
const QString& initial_status_text, bool cancellable, int range,
|
|
|
|
|
int value, QtAsyncTaskWithProgress& task, QWidget* parent)
|
|
|
|
|
QtAsyncTaskWithProgressDialog::ProgressDialog::ProgressDialog(const QString& initial_title,
|
|
|
|
|
const QString& initial_status_text, bool cancellable,
|
|
|
|
|
int range, int value, QtAsyncTaskWithProgressDialog& task,
|
|
|
|
|
QWidget* parent)
|
|
|
|
|
: QDialog(parent), m_task(task)
|
|
|
|
|
{
|
|
|
|
|
if (!initial_title.isEmpty())
|
|
|
|
|
@ -136,13 +138,13 @@ QtAsyncTaskWithProgress::ProgressDialog::ProgressDialog(const QString& initial_t
|
|
|
|
|
layout->addWidget(m_button_box);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QtAsyncTaskWithProgress::ProgressDialog::~ProgressDialog()
|
|
|
|
|
QtAsyncTaskWithProgressDialog::ProgressDialog::~ProgressDialog()
|
|
|
|
|
{
|
|
|
|
|
DebugAssert(m_task.m_dialog == this);
|
|
|
|
|
m_task.m_dialog = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QtAsyncTaskWithProgress::ProgressDialog::setCancellable(bool cancellable)
|
|
|
|
|
void QtAsyncTaskWithProgressDialog::ProgressDialog::setCancellable(bool cancellable)
|
|
|
|
|
{
|
|
|
|
|
if (cancellable == m_button_box->isVisible())
|
|
|
|
|
return;
|
|
|
|
|
@ -153,28 +155,29 @@ void QtAsyncTaskWithProgress::ProgressDialog::setCancellable(bool cancellable)
|
|
|
|
|
m_button_box->setVisible(cancellable);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QtAsyncTaskWithProgress::ProgressDialog::closeEvent(QCloseEvent* event)
|
|
|
|
|
void QtAsyncTaskWithProgressDialog::ProgressDialog::closeEvent(QCloseEvent* event)
|
|
|
|
|
{
|
|
|
|
|
cancelled();
|
|
|
|
|
QDialog::closeEvent(event);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QtAsyncTaskWithProgress::ProgressDialog::cancelled()
|
|
|
|
|
void QtAsyncTaskWithProgressDialog::ProgressDialog::cancelled()
|
|
|
|
|
{
|
|
|
|
|
m_task.m_ts_cancelled.store(true, std::memory_order_release);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QtAsyncTaskWithProgress* QtAsyncTaskWithProgress::create(QWidget* parent, std::string_view initial_title,
|
|
|
|
|
std::string_view initial_status_text, bool cancellable,
|
|
|
|
|
int range, int value, float show_delay, WorkCallback callback)
|
|
|
|
|
QtAsyncTaskWithProgressDialog* QtAsyncTaskWithProgressDialog::create(QWidget* parent, std::string_view initial_title,
|
|
|
|
|
std::string_view initial_status_text,
|
|
|
|
|
bool cancellable, int range, int value,
|
|
|
|
|
float show_delay, WorkCallback callback)
|
|
|
|
|
{
|
|
|
|
|
DebugAssert(parent);
|
|
|
|
|
|
|
|
|
|
// NOTE: Must get connected before queuing, because otherwise you risk a race.
|
|
|
|
|
QtAsyncTaskWithProgress* task = new QtAsyncTaskWithProgress(
|
|
|
|
|
QtAsyncTaskWithProgressDialog* task = new QtAsyncTaskWithProgressDialog(
|
|
|
|
|
QtUtils::StringViewToQString(initial_title), QtUtils::StringViewToQString(initial_status_text), cancellable, range,
|
|
|
|
|
value, show_delay, parent, std::move(callback));
|
|
|
|
|
connect(task, &QtAsyncTaskWithProgress::completed, parent,
|
|
|
|
|
connect(task, &QtAsyncTaskWithProgressDialog::completed, parent,
|
|
|
|
|
[task]() { std::get<CompletionCallback>(task->m_callback)(); });
|
|
|
|
|
|
|
|
|
|
System::QueueAsyncTask([task]() {
|
|
|
|
|
@ -188,22 +191,23 @@ QtAsyncTaskWithProgress* QtAsyncTaskWithProgress::create(QWidget* parent, std::s
|
|
|
|
|
return task;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QtAsyncTaskWithProgress* QtAsyncTaskWithProgress::create(QWidget* parent, float show_delay, WorkCallback callback)
|
|
|
|
|
QtAsyncTaskWithProgressDialog* QtAsyncTaskWithProgressDialog::create(QWidget* parent, float show_delay,
|
|
|
|
|
WorkCallback callback)
|
|
|
|
|
{
|
|
|
|
|
return create(parent, {}, {}, false, 0, 1, show_delay, std::move(callback));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QtAsyncTaskWithProgress::cancel()
|
|
|
|
|
void QtAsyncTaskWithProgressDialog::cancel()
|
|
|
|
|
{
|
|
|
|
|
m_ts_cancelled.store(true, std::memory_order_release);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool QtAsyncTaskWithProgress::IsCancelled() const
|
|
|
|
|
bool QtAsyncTaskWithProgressDialog::IsCancelled() const
|
|
|
|
|
{
|
|
|
|
|
return m_ts_cancelled.load(std::memory_order_acquire);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QtAsyncTaskWithProgress::SetCancellable(bool cancellable)
|
|
|
|
|
void QtAsyncTaskWithProgressDialog::SetCancellable(bool cancellable)
|
|
|
|
|
{
|
|
|
|
|
if (m_cancellable == cancellable)
|
|
|
|
|
return;
|
|
|
|
|
@ -216,7 +220,7 @@ void QtAsyncTaskWithProgress::SetCancellable(bool cancellable)
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QtAsyncTaskWithProgress::SetTitle(const std::string_view title)
|
|
|
|
|
void QtAsyncTaskWithProgressDialog::SetTitle(const std::string_view title)
|
|
|
|
|
{
|
|
|
|
|
Host::RunOnUIThread([this, title = QtUtils::StringViewToQString(title)]() {
|
|
|
|
|
if (m_dialog)
|
|
|
|
|
@ -224,7 +228,7 @@ void QtAsyncTaskWithProgress::SetTitle(const std::string_view title)
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QtAsyncTaskWithProgress::SetStatusText(const std::string_view text)
|
|
|
|
|
void QtAsyncTaskWithProgressDialog::SetStatusText(const std::string_view text)
|
|
|
|
|
{
|
|
|
|
|
if (m_status_text == text)
|
|
|
|
|
return;
|
|
|
|
|
@ -243,7 +247,7 @@ void QtAsyncTaskWithProgress::SetStatusText(const std::string_view text)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QtAsyncTaskWithProgress::SetProgressRange(u32 range)
|
|
|
|
|
void QtAsyncTaskWithProgressDialog::SetProgressRange(u32 range)
|
|
|
|
|
{
|
|
|
|
|
const u32 prev_range = m_progress_range;
|
|
|
|
|
ProgressCallback::SetProgressRange(range);
|
|
|
|
|
@ -263,7 +267,7 @@ void QtAsyncTaskWithProgress::SetProgressRange(u32 range)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QtAsyncTaskWithProgress::SetProgressValue(u32 value)
|
|
|
|
|
void QtAsyncTaskWithProgressDialog::SetProgressValue(u32 value)
|
|
|
|
|
{
|
|
|
|
|
const u32 prev_value = m_progress_value;
|
|
|
|
|
ProgressCallback::SetProgressValue(value);
|
|
|
|
|
@ -283,7 +287,7 @@ void QtAsyncTaskWithProgress::SetProgressValue(u32 value)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QtAsyncTaskWithProgress::CheckForDelayedShow()
|
|
|
|
|
void QtAsyncTaskWithProgressDialog::CheckForDelayedShow()
|
|
|
|
|
{
|
|
|
|
|
DebugAssert(!m_shown);
|
|
|
|
|
|
|
|
|
|
|