refactor: Qt can handle const& in signals and slots

While most Qt types cna use implicit data sharing
pasing our own structs means copies. const& ensure
it's only copied as needed by Qt.

Signed-off-by: Rachel Powers <508861+Ryex@users.noreply.github.com>
This commit is contained in:
Rachel Powers 2023-04-07 19:44:57 -07:00
parent a80b425551
commit 236764adf6
6 changed files with 17 additions and 15 deletions

View File

@ -133,7 +133,7 @@ void ConcurrentTask::startNext()
connect(next.get(), &Task::status, this, [this, next](QString msg) { subTaskStatus(next, msg); }); connect(next.get(), &Task::status, this, [this, next](QString msg) { subTaskStatus(next, msg); });
connect(next.get(), &Task::details, this, [this, next](QString msg) { subTaskDetails(next, msg); }); connect(next.get(), &Task::details, this, [this, next](QString msg) { subTaskDetails(next, msg); });
connect(next.get(), &Task::stepProgress, this, [this, next](TaskStepProgress tp) { subTaskStepProgress(next, tp); }); connect(next.get(), &Task::stepProgress, this, [this, next](TaskStepProgress const& tp) { subTaskStepProgress(next, tp); });
connect(next.get(), &Task::progress, this, [this, next](qint64 current, qint64 total) { subTaskProgress(next, current, total); }); connect(next.get(), &Task::progress, this, [this, next](qint64 current, qint64 total) { subTaskProgress(next, current, total); });
@ -224,13 +224,15 @@ void ConcurrentTask::subTaskProgress(Task::Ptr task, qint64 current, qint64 tota
updateState(); updateState();
} }
void ConcurrentTask::subTaskStepProgress(Task::Ptr task, TaskStepProgress task_progress) void ConcurrentTask::subTaskStepProgress(Task::Ptr task, TaskStepProgress const& task_progress)
{ {
Operation op = Operation::ADDED; Operation op = Operation::ADDED;
if (!m_task_progress.contains(task_progress.uid)) { if (!m_task_progress.contains(task_progress.uid)) {
m_task_progress.insert(task_progress.uid, std::make_shared<TaskStepProgress>(task_progress)); m_task_progress.insert(task_progress.uid, std::make_shared<TaskStepProgress>(task_progress));
op = Operation::ADDED; op = Operation::ADDED;
emit stepProgress(task_progress);
updateStepProgress(task_progress, op);
} else { } else {
auto tp = m_task_progress.value(task_progress.uid); auto tp = m_task_progress.value(task_progress.uid);
@ -243,10 +245,10 @@ void ConcurrentTask::subTaskStepProgress(Task::Ptr task, TaskStepProgress task_p
tp->details = task_progress.details; tp->details = task_progress.details;
op = Operation::CHANGED; op = Operation::CHANGED;
emit stepProgress(*tp.get());
updateStepProgress(*tp.get(), op);
} }
emit stepProgress(task_progress);
updateStepProgress(task_progress, op);
} }
void ConcurrentTask::updateStepProgress(TaskStepProgress const& changed_progress, Operation op) void ConcurrentTask::updateStepProgress(TaskStepProgress const& changed_progress, Operation op)

View File

@ -77,7 +77,7 @@ slots:
void subTaskStatus(Task::Ptr task, const QString &msg); void subTaskStatus(Task::Ptr task, const QString &msg);
void subTaskDetails(Task::Ptr task, const QString &msg); void subTaskDetails(Task::Ptr task, const QString &msg);
void subTaskProgress(Task::Ptr task, qint64 current, qint64 total); void subTaskProgress(Task::Ptr task, qint64 current, qint64 total);
void subTaskStepProgress(Task::Ptr task, TaskStepProgress task_step_progress); void subTaskStepProgress(Task::Ptr task, TaskStepProgress const& task_step_progress);
protected: protected:
// NOTE: This is not thread-safe. // NOTE: This is not thread-safe.

View File

@ -161,7 +161,7 @@ void Task::emitSucceeded()
emit finished(); emit finished();
} }
void Task::propogateStepProgress(TaskStepProgress task_progress) void Task::propogateStepProgress(TaskStepProgress const& task_progress)
{ {
emit stepProgress(task_progress); emit stepProgress(task_progress);
} }

View File

@ -64,7 +64,7 @@ struct TaskStepProgress {
QString status = ""; QString status = "";
QString details = ""; QString details = "";
TaskStepState state = TaskStepState::Waiting; TaskStepState state = TaskStepState::Waiting;
bool isDone() { return (state == TaskStepState::Failed) || (state == TaskStepState::Succeeded); } bool isDone() const { return (state == TaskStepState::Failed) || (state == TaskStepState::Succeeded); }
}; };
Q_DECLARE_METATYPE(TaskStepProgress) Q_DECLARE_METATYPE(TaskStepProgress)
@ -130,7 +130,7 @@ class Task : public QObject, public QRunnable {
void failed(QString reason); void failed(QString reason);
void status(QString status); void status(QString status);
void details(QString details); void details(QString details);
void stepProgress(TaskStepProgress task_progress); // void stepProgress(TaskStepProgress const& task_progress); //
/** Emitted when the canAbort() status has changed. /** Emitted when the canAbort() status has changed.
*/ */
@ -153,7 +153,7 @@ class Task : public QObject, public QRunnable {
virtual void emitAborted(); virtual void emitAborted();
virtual void emitFailed(QString reason = ""); virtual void emitFailed(QString reason = "");
virtual void propogateStepProgress(TaskStepProgress task_progress); virtual void propogateStepProgress(TaskStepProgress const& task_progress);
public slots: public slots:
void setStatus(const QString& status); void setStatus(const QString& status);

View File

@ -206,14 +206,14 @@ void ProgressDialog::changeStatus(const QString& status)
updateSize(); updateSize();
} }
void ProgressDialog::addTaskProgress(TaskStepProgress* progress) void ProgressDialog::addTaskProgress(TaskStepProgress const& progress)
{ {
SubTaskProgressBar* task_bar = new SubTaskProgressBar(this); SubTaskProgressBar* task_bar = new SubTaskProgressBar(this);
taskProgress.insert(progress->uid, task_bar); taskProgress.insert(progress.uid, task_bar);
ui->taskProgressLayout->addWidget(task_bar); ui->taskProgressLayout->addWidget(task_bar);
} }
void ProgressDialog::changeStepProgress(TaskStepProgress task_progress) void ProgressDialog::changeStepProgress(TaskStepProgress const& task_progress)
{ {
m_is_multi_step = true; m_is_multi_step = true;
if(ui->taskProgressScrollArea->isHidden()) { if(ui->taskProgressScrollArea->isHidden()) {
@ -222,7 +222,7 @@ void ProgressDialog::changeStepProgress(TaskStepProgress task_progress)
} }
if (!taskProgress.contains(task_progress.uid)) if (!taskProgress.contains(task_progress.uid))
addTaskProgress(&task_progress); addTaskProgress(task_progress);
auto task_bar = taskProgress.value(task_progress.uid); auto task_bar = taskProgress.value(task_progress.uid);

View File

@ -80,7 +80,7 @@ slots:
void changeStatus(const QString &status); void changeStatus(const QString &status);
void changeProgress(qint64 current, qint64 total); void changeProgress(qint64 current, qint64 total);
void changeStepProgress(TaskStepProgress task_progress); void changeStepProgress(TaskStepProgress const& task_progress);
private private
@ -93,7 +93,7 @@ protected:
private: private:
bool handleImmediateResult(QDialog::DialogCode &result); bool handleImmediateResult(QDialog::DialogCode &result);
void addTaskProgress(TaskStepProgress* progress); void addTaskProgress(TaskStepProgress const& progress);
private: private:
Ui::ProgressDialog *ui; Ui::ProgressDialog *ui;