@@ -1,31 +1,39 | |||
|
1 | 1 | #ifndef SCIQLOP_VARIABLECONTROLLER_H |
|
2 | 2 | #define SCIQLOP_VARIABLECONTROLLER_H |
|
3 | 3 | |
|
4 | 4 | #include <QLoggingCategory> |
|
5 | 5 | #include <QObject> |
|
6 | 6 | |
|
7 | 7 | #include <Common/spimpl.h> |
|
8 | 8 | |
|
9 | class Variable; | |
|
9 | 10 | Q_DECLARE_LOGGING_CATEGORY(LOG_VariableController) |
|
10 | 11 | |
|
11 | 12 | /** |
|
12 | 13 | * @brief The VariableController class aims to handle the variables in SciQlop. |
|
13 | 14 | */ |
|
14 | 15 | class VariableController : public QObject { |
|
15 | 16 | Q_OBJECT |
|
16 | 17 | public: |
|
17 | 18 | explicit VariableController(QObject *parent = 0); |
|
18 | 19 | virtual ~VariableController(); |
|
19 | 20 | |
|
21 | /** | |
|
22 | * Creates a new variable | |
|
23 | * @param name the name of the new variable | |
|
24 | * @return the variable if it was created successfully, nullptr otherwise | |
|
25 | */ | |
|
26 | Variable *createVariable(const QString &name) noexcept; | |
|
27 | ||
|
20 | 28 | public slots: |
|
21 | 29 | void initialize(); |
|
22 | 30 | void finalize(); |
|
23 | 31 | |
|
24 | 32 | private: |
|
25 | 33 | void waitForFinish(); |
|
26 | 34 | |
|
27 | 35 | class VariableControllerPrivate; |
|
28 | 36 | spimpl::unique_impl_ptr<VariableControllerPrivate> impl; |
|
29 | 37 | }; |
|
30 | 38 | |
|
31 | 39 | #endif // SCIQLOP_VARIABLECONTROLLER_H |
@@ -1,46 +1,53 | |||
|
1 | 1 | #include <Variable/VariableController.h> |
|
2 | #include <Variable/VariableModel.h> | |
|
2 | 3 | |
|
3 | 4 | #include <QMutex> |
|
4 | 5 | #include <QThread> |
|
5 | 6 | |
|
6 | 7 | Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController") |
|
7 | 8 | |
|
8 | 9 | struct VariableController::VariableControllerPrivate { |
|
9 | 10 | explicit VariableControllerPrivate() |
|
10 | : m_WorkingMutex{} | |
|
11 | : m_WorkingMutex{}, m_VariableModel{std::make_unique<VariableModel>()} | |
|
11 | 12 | { |
|
12 | 13 | } |
|
13 | 14 | |
|
14 | 15 | QMutex m_WorkingMutex; |
|
16 | std::unique_ptr<VariableModel> m_VariableModel; | |
|
15 | 17 | }; |
|
16 | 18 | |
|
17 | 19 | VariableController::VariableController(QObject *parent) |
|
18 | 20 | : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>()} |
|
19 | 21 | { |
|
20 | 22 | qCDebug(LOG_VariableController()) |
|
21 | 23 | << tr("VariableController construction") << QThread::currentThread(); |
|
22 | 24 | } |
|
23 | 25 | |
|
24 | 26 | VariableController::~VariableController() |
|
25 | 27 | { |
|
26 | 28 | qCDebug(LOG_VariableController()) |
|
27 | 29 | << tr("VariableController destruction") << QThread::currentThread(); |
|
28 | 30 | this->waitForFinish(); |
|
29 | 31 | } |
|
30 | 32 | |
|
33 | Variable *VariableController::createVariable(const QString &name) noexcept | |
|
34 | { | |
|
35 | return impl->m_VariableModel->createVariable(name); | |
|
36 | } | |
|
37 | ||
|
31 | 38 | void VariableController::initialize() |
|
32 | 39 | { |
|
33 | 40 | qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread(); |
|
34 | 41 | impl->m_WorkingMutex.lock(); |
|
35 | 42 | qCDebug(LOG_VariableController()) << tr("VariableController init END"); |
|
36 | 43 | } |
|
37 | 44 | |
|
38 | 45 | void VariableController::finalize() |
|
39 | 46 | { |
|
40 | 47 | impl->m_WorkingMutex.unlock(); |
|
41 | 48 | } |
|
42 | 49 | |
|
43 | 50 | void VariableController::waitForFinish() |
|
44 | 51 | { |
|
45 | 52 | QMutexLocker locker{&impl->m_WorkingMutex}; |
|
46 | 53 | } |
General Comments 0
You need to be logged in to leave comments.
Login now