Qt: Fix progress dialog cancelling

This commit is contained in:
Stenzek 2023-11-24 16:08:28 +10:00
parent cc6f22163c
commit 365e3fb965
No known key found for this signature in database
2 changed files with 14 additions and 8 deletions

View File

@ -16,16 +16,12 @@ QtModalProgressCallback::QtModalProgressCallback(QWidget* parent_widget, float s
m_dialog.setModal(parent_widget != nullptr); m_dialog.setModal(parent_widget != nullptr);
m_dialog.setAutoClose(false); m_dialog.setAutoClose(false);
m_dialog.setAutoReset(false); m_dialog.setAutoReset(false);
connect(&m_dialog, &QProgressDialog::canceled, this, &QtModalProgressCallback::dialogCancelled);
checkForDelayedShow(); checkForDelayedShow();
} }
QtModalProgressCallback::~QtModalProgressCallback() = default; QtModalProgressCallback::~QtModalProgressCallback() = default;
bool QtModalProgressCallback::IsCancelled() const
{
return m_dialog.wasCanceled();
}
void QtModalProgressCallback::SetCancellable(bool cancellable) void QtModalProgressCallback::SetCancellable(bool cancellable)
{ {
if (m_cancellable == cancellable) if (m_cancellable == cancellable)
@ -105,6 +101,11 @@ void QtModalProgressCallback::ModalInformation(const char* message)
QMessageBox::information(&m_dialog, tr("Information"), QString::fromUtf8(message)); QMessageBox::information(&m_dialog, tr("Information"), QString::fromUtf8(message));
} }
void QtModalProgressCallback::dialogCancelled()
{
m_cancelled = true;
}
void QtModalProgressCallback::checkForDelayedShow() void QtModalProgressCallback::checkForDelayedShow()
{ {
if (m_dialog.isVisible()) if (m_dialog.isVisible())

View File

@ -1,11 +1,13 @@
// SPDX-FileCopyrightText: 2019-2022 Connor McLaughlin <stenzek@gmail.com> // SPDX-FileCopyrightText: 2019-2023 Connor McLaughlin <stenzek@gmail.com>
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) // SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0)
#pragma once #pragma once
#include "common/progress_callback.h" #include "common/progress_callback.h"
#include "common/timer.h" #include "common/timer.h"
#include <QtCore/QThread>
#include <QtCore/QSemaphore> #include <QtCore/QSemaphore>
#include <QtCore/QThread>
#include <QtWidgets/QProgressDialog> #include <QtWidgets/QProgressDialog>
#include <atomic> #include <atomic>
@ -17,7 +19,7 @@ public:
QtModalProgressCallback(QWidget* parent_widget, float show_delay = 0.0f); QtModalProgressCallback(QWidget* parent_widget, float show_delay = 0.0f);
~QtModalProgressCallback(); ~QtModalProgressCallback();
bool IsCancelled() const override; QProgressDialog& GetDialog() { return m_dialog; }
void SetCancellable(bool cancellable) override; void SetCancellable(bool cancellable) override;
void SetTitle(const char* title) override; void SetTitle(const char* title) override;
@ -34,6 +36,9 @@ public:
bool ModalConfirmation(const char* message) override; bool ModalConfirmation(const char* message) override;
void ModalInformation(const char* message) override; void ModalInformation(const char* message) override;
private Q_SLOTS:
void dialogCancelled();
private: private:
void checkForDelayedShow(); void checkForDelayedShow();