taskdialog/progressdialog: if guard on showEvent

Fixes #1599
This commit is contained in:
itsmattkc
2021-04-30 09:58:45 +10:00
parent b82e616124
commit 6ca8dbb70a
4 changed files with 42 additions and 17 deletions
+17 -6
View File
@@ -29,9 +29,12 @@
namespace olive {
#define super QDialog
ProgressDialog::ProgressDialog(const QString& message, const QString& title, QWidget *parent) :
QDialog(parent),
show_progress_(true)
super(parent),
show_progress_(true),
first_show_(true)
{
if (!title.isEmpty()) {
setWindowTitle(title);
@@ -77,18 +80,26 @@ ProgressDialog::ProgressDialog(const QString& message, const QString& title, QWi
void ProgressDialog::showEvent(QShowEvent *e)
{
QDialog::showEvent(e);
super::showEvent(e);
elapsed_timer_lbl_->Start();
if (first_show_) {
elapsed_timer_lbl_->Start();
Core::instance()->main_window()->SetApplicationProgressStatus(MainWindow::kProgressShow);
Core::instance()->main_window()->SetApplicationProgressStatus(MainWindow::kProgressShow);
first_show_ = false;
}
}
void ProgressDialog::closeEvent(QCloseEvent *e)
{
QDialog::closeEvent(e);
super::closeEvent(e);
Core::instance()->main_window()->SetApplicationProgressStatus(MainWindow::kProgressNone);
elapsed_timer_lbl_->Stop();
first_show_ = true;
}
void ProgressDialog::SetProgress(double value)
+2
View File
@@ -56,6 +56,8 @@ private:
bool show_progress_;
bool first_show_;
private slots:
void DisableSenderWidget();
+21 -11
View File
@@ -24,10 +24,13 @@
namespace olive {
#define super ProgressDialog
TaskDialog::TaskDialog(Task* task, const QString& title, QWidget *parent) :
ProgressDialog(task->GetTitle(), title, parent),
super(task->GetTitle(), title, parent),
task_(task),
destroy_on_close_(true)
destroy_on_close_(true),
already_shown_(false)
{
// Clear task when this dialog is destroyed
task_->setParent(this);
@@ -42,17 +45,21 @@ TaskDialog::TaskDialog(Task* task, const QString& title, QWidget *parent) :
void TaskDialog::showEvent(QShowEvent *e)
{
ProgressDialog::showEvent(e);
super::showEvent(e);
// Create watcher for when the task finishes
QFutureWatcher<bool>* task_watcher = new QFutureWatcher<bool>();
if (!already_shown_) {
// Create watcher for when the task finishes
QFutureWatcher<bool>* task_watcher = new QFutureWatcher<bool>();
// Listen for when the task finishes
connect(task_watcher, &QFutureWatcher<bool>::finished,
this, &TaskDialog::TaskFinished, Qt::QueuedConnection);
// Listen for when the task finishes
connect(task_watcher, &QFutureWatcher<bool>::finished,
this, &TaskDialog::TaskFinished, Qt::QueuedConnection);
// Run task in another thread with QtConcurrent
task_watcher->setFuture(QtConcurrent::run(task_, &Task::Start));
// Run task in another thread with QtConcurrent
task_watcher->setFuture(QtConcurrent::run(task_, &Task::Start));
already_shown_ = true;
}
}
void TaskDialog::closeEvent(QCloseEvent *e)
@@ -61,7 +68,10 @@ void TaskDialog::closeEvent(QCloseEvent *e)
task_->Cancel();
// Standard close function
ProgressDialog::closeEvent(e);
super::closeEvent(e);
// Reset shown
already_shown_ = false;
// Clean up this task and dialog
if (destroy_on_close_) {
+2
View File
@@ -72,6 +72,8 @@ private:
bool destroy_on_close_;
bool already_shown_;
private slots:
void TaskFinished();