feat: add canAbort() status change in Task
By now, it's a recurring pattern of wanting to restrict aborting in certain situations. This avoids further code duplication, and adds a signal that external users can hook up to to respond to such change. Signed-off-by: flow <flowlnlnln@gmail.com>
This commit is contained in:
parent
6541570969
commit
6a50fa35ec
@ -68,7 +68,7 @@ class Task : public QObject, public QRunnable {
|
||||
|
||||
virtual QStringList warnings() const;
|
||||
|
||||
virtual bool canAbort() const { return false; }
|
||||
virtual bool canAbort() const { return m_can_abort; }
|
||||
|
||||
auto getState() const -> State { return m_state; }
|
||||
|
||||
@ -96,6 +96,10 @@ class Task : public QObject, public QRunnable {
|
||||
void status(QString status);
|
||||
void stepStatus(QString status);
|
||||
|
||||
/** Emitted when the canAbort() status has changed.
|
||||
*/
|
||||
void abortStatusChanged(bool can_abort);
|
||||
|
||||
public slots:
|
||||
// QRunnable's interface
|
||||
void run() override { start(); }
|
||||
@ -103,6 +107,8 @@ class Task : public QObject, public QRunnable {
|
||||
virtual void start();
|
||||
virtual bool abort() { if(canAbort()) emitAborted(); return canAbort(); };
|
||||
|
||||
void setAbortStatus(bool can_abort) { m_can_abort = can_abort; emit abortStatusChanged(can_abort); }
|
||||
|
||||
protected:
|
||||
virtual void executeTask() = 0;
|
||||
|
||||
@ -125,4 +131,8 @@ class Task : public QObject, public QRunnable {
|
||||
|
||||
// TODO: Nuke in favor of QLoggingCategory
|
||||
bool m_show_debug = true;
|
||||
|
||||
private:
|
||||
// Change using setAbortStatus
|
||||
bool m_can_abort = false;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user