change: change code style to Linux style except indent.
This commit is contained in:
+50
-46
@@ -22,83 +22,87 @@
|
||||
|
||||
#include <QtConcurrent/QtConcurrent>
|
||||
|
||||
namespace olive {
|
||||
namespace olive
|
||||
{
|
||||
|
||||
#define super ProgressDialog
|
||||
|
||||
TaskDialog::TaskDialog(Task* task, const QString& title, QWidget *parent) :
|
||||
super(task->GetTitle(), title, parent),
|
||||
task_(task),
|
||||
destroy_on_close_(true),
|
||||
already_shown_(false)
|
||||
TaskDialog::TaskDialog(Task *task, const QString &title, QWidget *parent)
|
||||
: super(task->GetTitle(), title, parent)
|
||||
, task_(task)
|
||||
, destroy_on_close_(true)
|
||||
, already_shown_(false)
|
||||
{
|
||||
// Clear task when this dialog is destroyed
|
||||
task_->setParent(this);
|
||||
// Clear task when this dialog is destroyed
|
||||
task_->setParent(this);
|
||||
|
||||
// Connect the save manager progress signal to the progress bar update on the dialog
|
||||
connect(task_, &Task::ProgressChanged, this, &TaskDialog::SetProgress, Qt::QueuedConnection);
|
||||
// Connect the save manager progress signal to the progress bar update on the dialog
|
||||
connect(task_, &Task::ProgressChanged, this, &TaskDialog::SetProgress,
|
||||
Qt::QueuedConnection);
|
||||
|
||||
// Connect cancel signal (must be a direct connection or it'll be queued after the task has
|
||||
// already finished)
|
||||
connect(this, &TaskDialog::Cancelled, task_, &Task::Cancel, Qt::DirectConnection);
|
||||
// Connect cancel signal (must be a direct connection or it'll be queued after the task has
|
||||
// already finished)
|
||||
connect(this, &TaskDialog::Cancelled, task_, &Task::Cancel,
|
||||
Qt::DirectConnection);
|
||||
}
|
||||
|
||||
void TaskDialog::showEvent(QShowEvent *e)
|
||||
{
|
||||
super::showEvent(e);
|
||||
super::showEvent(e);
|
||||
|
||||
if (!already_shown_) {
|
||||
// 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(
|
||||
// Run task in another thread with QtConcurrent
|
||||
task_watcher->setFuture(
|
||||
#if QT_VERSION_MAJOR >= 6
|
||||
QtConcurrent::run(&Task::Start, task_)
|
||||
QtConcurrent::run(&Task::Start, task_)
|
||||
#else
|
||||
QtConcurrent::run(task_, &Task::Start)
|
||||
QtConcurrent::run(task_, &Task::Start)
|
||||
#endif
|
||||
);
|
||||
);
|
||||
|
||||
already_shown_ = true;
|
||||
}
|
||||
already_shown_ = true;
|
||||
}
|
||||
}
|
||||
|
||||
void TaskDialog::closeEvent(QCloseEvent *e)
|
||||
{
|
||||
// Cancel task if it is running
|
||||
task_->Cancel();
|
||||
// Cancel task if it is running
|
||||
task_->Cancel();
|
||||
|
||||
// Standard close function
|
||||
super::closeEvent(e);
|
||||
// Standard close function
|
||||
super::closeEvent(e);
|
||||
|
||||
// Reset shown
|
||||
already_shown_ = false;
|
||||
// Reset shown
|
||||
already_shown_ = false;
|
||||
|
||||
// Clean up this task and dialog
|
||||
if (destroy_on_close_) {
|
||||
deleteLater();
|
||||
}
|
||||
// Clean up this task and dialog
|
||||
if (destroy_on_close_) {
|
||||
deleteLater();
|
||||
}
|
||||
}
|
||||
|
||||
void TaskDialog::TaskFinished()
|
||||
{
|
||||
QFutureWatcher<bool>* task_watcher = static_cast<QFutureWatcher<bool>*>(sender());
|
||||
QFutureWatcher<bool> *task_watcher =
|
||||
static_cast<QFutureWatcher<bool> *>(sender());
|
||||
|
||||
if (task_watcher->result()) {
|
||||
emit TaskSucceeded(task_);
|
||||
} else {
|
||||
ShowErrorMessage(tr("Task Failed"), task_->GetError());
|
||||
emit TaskFailed(task_);
|
||||
}
|
||||
if (task_watcher->result()) {
|
||||
emit TaskSucceeded(task_);
|
||||
} else {
|
||||
ShowErrorMessage(tr("Task Failed"), task_->GetError());
|
||||
emit TaskFailed(task_);
|
||||
}
|
||||
|
||||
task_watcher->deleteLater();
|
||||
task_watcher->deleteLater();
|
||||
|
||||
close();
|
||||
close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+24
-25
@@ -24,59 +24,58 @@
|
||||
#include "dialog/progress/progress.h"
|
||||
#include "task/task.h"
|
||||
|
||||
namespace olive {
|
||||
|
||||
class TaskDialog : public ProgressDialog
|
||||
namespace olive
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
class TaskDialog : public ProgressDialog {
|
||||
Q_OBJECT
|
||||
public:
|
||||
/**
|
||||
/**
|
||||
* @brief TaskDialog Constructor
|
||||
*
|
||||
* Creates a TaskDialog. The TaskDialog takes ownership of the Task and will destroy it on close.
|
||||
* Connect to the Task::Succeeded() if you want to retrieve information from the task before it
|
||||
* gets destroyed.
|
||||
*/
|
||||
TaskDialog(Task *task, const QString &title, QWidget* parent = nullptr);
|
||||
TaskDialog(Task *task, const QString &title, QWidget *parent = nullptr);
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief Set whether TaskDialog should destroy itself (and the task) when it's closed
|
||||
*
|
||||
* This is TRUE by default.
|
||||
*/
|
||||
void SetDestroyOnClose(bool e)
|
||||
{
|
||||
destroy_on_close_ = e;
|
||||
}
|
||||
void SetDestroyOnClose(bool e)
|
||||
{
|
||||
destroy_on_close_ = e;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief Returns this dialog's task
|
||||
*/
|
||||
Task* GetTask() const
|
||||
{
|
||||
return task_;
|
||||
}
|
||||
Task *GetTask() const
|
||||
{
|
||||
return task_;
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void showEvent(QShowEvent* e) override;
|
||||
virtual void showEvent(QShowEvent *e) override;
|
||||
|
||||
virtual void closeEvent(QCloseEvent* e) override;
|
||||
virtual void closeEvent(QCloseEvent *e) override;
|
||||
|
||||
signals:
|
||||
void TaskSucceeded(Task* task);
|
||||
void TaskSucceeded(Task *task);
|
||||
|
||||
void TaskFailed(Task* task);
|
||||
void TaskFailed(Task *task);
|
||||
|
||||
private:
|
||||
Task* task_;
|
||||
Task *task_;
|
||||
|
||||
bool destroy_on_close_;
|
||||
bool destroy_on_close_;
|
||||
|
||||
bool already_shown_;
|
||||
bool already_shown_;
|
||||
|
||||
private slots:
|
||||
void TaskFinished();
|
||||
|
||||
void TaskFinished();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user