@@ -1,58 +1,59 | |||
|
1 | 1 | #include <Variable/VariableController.h> |
|
2 | 2 | #include <Variable/VariableModel.h> |
|
3 | 3 | |
|
4 | 4 | #include <QMutex> |
|
5 | 5 | #include <QThread> |
|
6 | 6 | |
|
7 | 7 | Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController") |
|
8 | 8 | |
|
9 | 9 | struct VariableController::VariableControllerPrivate { |
|
10 | explicit VariableControllerPrivate() | |
|
11 |
: m_WorkingMutex{}, m_VariableModel{ |
|
|
10 | explicit VariableControllerPrivate(VariableController *parent) | |
|
11 | : m_WorkingMutex{}, m_VariableModel{new VariableModel{parent}} | |
|
12 | 12 | { |
|
13 | 13 | } |
|
14 | 14 | |
|
15 | 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 | 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 | 23 | qCDebug(LOG_VariableController()) << tr("VariableController construction") |
|
23 | 24 | << QThread::currentThread(); |
|
24 | 25 | } |
|
25 | 26 | |
|
26 | 27 | VariableController::~VariableController() |
|
27 | 28 | { |
|
28 | 29 | qCDebug(LOG_VariableController()) << tr("VariableController destruction") |
|
29 | 30 | << QThread::currentThread(); |
|
30 | 31 | this->waitForFinish(); |
|
31 | 32 | } |
|
32 | 33 | |
|
33 | 34 | Variable *VariableController::createVariable(const QString &name) noexcept |
|
34 | 35 | { |
|
35 | 36 | return impl->m_VariableModel->createVariable(name); |
|
36 | 37 | } |
|
37 | 38 | |
|
38 | 39 | VariableModel *VariableController::variableModel() noexcept |
|
39 | 40 | { |
|
40 |
return impl->m_VariableModel |
|
|
41 | return impl->m_VariableModel; | |
|
41 | 42 | } |
|
42 | 43 | |
|
43 | 44 | void VariableController::initialize() |
|
44 | 45 | { |
|
45 | 46 | qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread(); |
|
46 | 47 | impl->m_WorkingMutex.lock(); |
|
47 | 48 | qCDebug(LOG_VariableController()) << tr("VariableController init END"); |
|
48 | 49 | } |
|
49 | 50 | |
|
50 | 51 | void VariableController::finalize() |
|
51 | 52 | { |
|
52 | 53 | impl->m_WorkingMutex.unlock(); |
|
53 | 54 | } |
|
54 | 55 | |
|
55 | 56 | void VariableController::waitForFinish() |
|
56 | 57 | { |
|
57 | 58 | QMutexLocker locker{&impl->m_WorkingMutex}; |
|
58 | 59 | } |
General Comments 0
You need to be logged in to leave comments.
Login now