VariableController.cpp
59 lines
| 1.7 KiB
| text/x-c
|
CppLexer
Alexandre Leroux
|
r111 | #include <Variable/VariableController.h> | ||
Alexandre Leroux
|
r113 | #include <Variable/VariableModel.h> | ||
Alexandre Leroux
|
r111 | |||
#include <QMutex> | ||||
#include <QThread> | ||||
Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController") | ||||
struct VariableController::VariableControllerPrivate { | ||||
Alexandre Leroux
|
r159 | explicit VariableControllerPrivate(VariableController *parent) | ||
: m_WorkingMutex{}, m_VariableModel{new VariableModel{parent}} | ||||
Alexandre Leroux
|
r111 | { | ||
} | ||||
QMutex m_WorkingMutex; | ||||
Alexandre Leroux
|
r159 | /// Variable model. The VariableController has the ownership | ||
VariableModel *m_VariableModel; | ||||
Alexandre Leroux
|
r111 | }; | ||
VariableController::VariableController(QObject *parent) | ||||
Alexandre Leroux
|
r159 | : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)} | ||
Alexandre Leroux
|
r111 | { | ||
r134 | qCDebug(LOG_VariableController()) << tr("VariableController construction") | |||
<< QThread::currentThread(); | ||||
Alexandre Leroux
|
r111 | } | ||
VariableController::~VariableController() | ||||
{ | ||||
r134 | qCDebug(LOG_VariableController()) << tr("VariableController destruction") | |||
<< QThread::currentThread(); | ||||
Alexandre Leroux
|
r111 | this->waitForFinish(); | ||
} | ||||
Alexandre Leroux
|
r113 | Variable *VariableController::createVariable(const QString &name) noexcept | ||
{ | ||||
return impl->m_VariableModel->createVariable(name); | ||||
} | ||||
Alexandre Leroux
|
r152 | VariableModel *VariableController::variableModel() noexcept | ||
{ | ||||
Alexandre Leroux
|
r159 | return impl->m_VariableModel; | ||
Alexandre Leroux
|
r152 | } | ||
Alexandre Leroux
|
r111 | void VariableController::initialize() | ||
{ | ||||
qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread(); | ||||
impl->m_WorkingMutex.lock(); | ||||
qCDebug(LOG_VariableController()) << tr("VariableController init END"); | ||||
} | ||||
void VariableController::finalize() | ||||
{ | ||||
impl->m_WorkingMutex.unlock(); | ||||
} | ||||
void VariableController::waitForFinish() | ||||
{ | ||||
QMutexLocker locker{&impl->m_WorkingMutex}; | ||||
} | ||||