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