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