implemented cancel feedback in project saving
The cancel button now sends a signal to the saving thread to stop.
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
#include "projectsavemanager.h"
|
||||
|
||||
ProjectSaveManager::ProjectSaveManager(Project *project) :
|
||||
project_(project)
|
||||
project_(project),
|
||||
cancelled_(false)
|
||||
{
|
||||
|
||||
}
|
||||
@@ -11,6 +12,10 @@ void ProjectSaveManager::Start()
|
||||
int prog = 0;
|
||||
|
||||
do {
|
||||
if (cancelled_) {
|
||||
break;
|
||||
}
|
||||
|
||||
prog += 10;
|
||||
|
||||
emit ProgressChanged(prog);
|
||||
@@ -20,3 +25,8 @@ void ProjectSaveManager::Start()
|
||||
|
||||
emit Finished();
|
||||
}
|
||||
|
||||
void ProjectSaveManager::Cancel()
|
||||
{
|
||||
cancelled_ = true;
|
||||
}
|
||||
|
||||
@@ -12,8 +12,22 @@ public:
|
||||
ProjectSaveManager(Project* project);
|
||||
|
||||
public slots:
|
||||
/**
|
||||
* @brief Start the save process
|
||||
*
|
||||
* It's recommended to invoke this through Qt signals/slots/QueuedConnection after moving this object to a separate
|
||||
* thread.
|
||||
*/
|
||||
void Start();
|
||||
|
||||
/**
|
||||
* @brief Cancel the current save
|
||||
*
|
||||
* Always connect to this with a DirectConnection. Otherwise, it'll be queued AFTER the save function is already
|
||||
* complete.
|
||||
*/
|
||||
void Cancel();
|
||||
|
||||
signals:
|
||||
void ProgressChanged(int);
|
||||
|
||||
@@ -22,6 +36,8 @@ signals:
|
||||
private:
|
||||
Project* project_;
|
||||
|
||||
QAtomicInt cancelled_;
|
||||
|
||||
};
|
||||
|
||||
#endif // PROJECTSAVEMANAGER_H
|
||||
|
||||
Reference in New Issue
Block a user