-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogresswriterobject.h
More file actions
54 lines (48 loc) · 1.69 KB
/
progresswriterobject.h
File metadata and controls
54 lines (48 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#ifndef PROGRESSWOBJECT_H
#define PROGRESSWOBJECT_H
#include <QObject>
#include "progressworker.h"
#include <QThread>
#include "general.h"
/**
* brief :
* This class created to connect a ProgressWriterObject in a separate thread into the main QML.
* ProgressWriterObject uses for creating and controlling a ProgressWriterWorker object.
* It creates a ProgressWriterWorker object and moves it into to new thread and listens signals of the ProgressWriterWorker object.
* Then when the progress values is changed, it automatically changes QML object with new values.
*
*
* architecture:
* This is a controller class for creating, connecting to a worker thread.
* @link: https://doc.qt.io/qt-5/qthread.html
*/
class ProgressWriterObject : public QObject
{
Q_OBJECT
float m_current = 0.0; // current progress percentage
int m_step = 0; // current step
int m_total_step = 0; // total step
progress_writer_handler m_handler = nullptr;
QString m_fifo_name;
public:
explicit ProgressWriterObject(QObject *parent = nullptr);
~ProgressWriterObject();
float current();
int totalStep();
int currentStep();
void setCurrent(float);
void setTotalStep(int);
void setCurrentStep(int);
void initJob(progress_writer_handler handler, const QString file_name = "fifo_pipe");
void initJob(std::function<void(ProgressWriterObject *)> handler, const QString file_name = "fifo_pipe");
Q_INVOKABLE void prepareJob();
signals:
void currentStepChanged(int);
void totalStepChanged(int);
Q_INVOKABLE void startJob();
Q_INVOKABLE void endJob();
void jobDone(const QString result);
private:
QThread workerThread;
};
#endif // PROGRESSWOBJECT_H