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