##// END OF EJS Templates
Merge pull request 151 from SCIQLOP-Initialisation develop...
perrinel -
r160:3db58e43e912 merge
parent child
Show More
@@ -1,58 +1,59
1 #include <Variable/VariableController.h>
1 #include <Variable/VariableController.h>
2 #include <Variable/VariableModel.h>
2 #include <Variable/VariableModel.h>
3
3
4 #include <QMutex>
4 #include <QMutex>
5 #include <QThread>
5 #include <QThread>
6
6
7 Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController")
7 Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController")
8
8
9 struct VariableController::VariableControllerPrivate {
9 struct VariableController::VariableControllerPrivate {
10 explicit VariableControllerPrivate()
10 explicit VariableControllerPrivate(VariableController *parent)
11 : m_WorkingMutex{}, m_VariableModel{std::make_unique<VariableModel>()}
11 : m_WorkingMutex{}, m_VariableModel{new VariableModel{parent}}
12 {
12 {
13 }
13 }
14
14
15 QMutex m_WorkingMutex;
15 QMutex m_WorkingMutex;
16 std::unique_ptr<VariableModel> m_VariableModel;
16 /// Variable model. The VariableController has the ownership
17 VariableModel *m_VariableModel;
17 };
18 };
18
19
19 VariableController::VariableController(QObject *parent)
20 VariableController::VariableController(QObject *parent)
20 : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>()}
21 : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)}
21 {
22 {
22 qCDebug(LOG_VariableController()) << tr("VariableController construction")
23 qCDebug(LOG_VariableController()) << tr("VariableController construction")
23 << QThread::currentThread();
24 << QThread::currentThread();
24 }
25 }
25
26
26 VariableController::~VariableController()
27 VariableController::~VariableController()
27 {
28 {
28 qCDebug(LOG_VariableController()) << tr("VariableController destruction")
29 qCDebug(LOG_VariableController()) << tr("VariableController destruction")
29 << QThread::currentThread();
30 << QThread::currentThread();
30 this->waitForFinish();
31 this->waitForFinish();
31 }
32 }
32
33
33 Variable *VariableController::createVariable(const QString &name) noexcept
34 Variable *VariableController::createVariable(const QString &name) noexcept
34 {
35 {
35 return impl->m_VariableModel->createVariable(name);
36 return impl->m_VariableModel->createVariable(name);
36 }
37 }
37
38
38 VariableModel *VariableController::variableModel() noexcept
39 VariableModel *VariableController::variableModel() noexcept
39 {
40 {
40 return impl->m_VariableModel.get();
41 return impl->m_VariableModel;
41 }
42 }
42
43
43 void VariableController::initialize()
44 void VariableController::initialize()
44 {
45 {
45 qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread();
46 qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread();
46 impl->m_WorkingMutex.lock();
47 impl->m_WorkingMutex.lock();
47 qCDebug(LOG_VariableController()) << tr("VariableController init END");
48 qCDebug(LOG_VariableController()) << tr("VariableController init END");
48 }
49 }
49
50
50 void VariableController::finalize()
51 void VariableController::finalize()
51 {
52 {
52 impl->m_WorkingMutex.unlock();
53 impl->m_WorkingMutex.unlock();
53 }
54 }
54
55
55 void VariableController::waitForFinish()
56 void VariableController::waitForFinish()
56 {
57 {
57 QMutexLocker locker{&impl->m_WorkingMutex};
58 QMutexLocker locker{&impl->m_WorkingMutex};
58 }
59 }
General Comments 0
You need to be logged in to leave comments. Login now