##// END OF EJS Templates
Merge pull request 152 from SCIQLOP-Initialisation develop...
perrinel -
r158:fd6bf22088a5 merge
parent child
Show More
@@ -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,31 +1,41
1 #ifndef SCIQLOP_VARIABLEMODEL_H
1 #ifndef SCIQLOP_VARIABLEMODEL_H
2 #define SCIQLOP_VARIABLEMODEL_H
2 #define SCIQLOP_VARIABLEMODEL_H
3
3
4 #include <Common/spimpl.h>
4 #include <Common/spimpl.h>
5
5
6 #include <QAbstractTableModel>
6 #include <QLoggingCategory>
7 #include <QLoggingCategory>
7
8
8 Q_DECLARE_LOGGING_CATEGORY(LOG_VariableModel)
9 Q_DECLARE_LOGGING_CATEGORY(LOG_VariableModel)
9
10
10 class Variable;
11 class Variable;
11
12
12 /**
13 /**
13 * @brief The VariableModel class aims to hold the variables that have been created in SciQlop
14 * @brief The VariableModel class aims to hold the variables that have been created in SciQlop
14 */
15 */
15 class VariableModel {
16 class VariableModel : public QAbstractTableModel {
16 public:
17 public:
17 explicit VariableModel();
18 explicit VariableModel(QObject *parent = nullptr);
18
19
19 /**
20 /**
20 * Creates a new variable in the model
21 * Creates a new variable in the model
21 * @param name the name of the new variable
22 * @param name the name of the new variable
22 * @return the variable if it was created successfully, nullptr otherwise
23 * @return the variable if it was created successfully, nullptr otherwise
23 */
24 */
24 Variable *createVariable(const QString &name) noexcept;
25 Variable *createVariable(const QString &name) noexcept;
25
26
27 // /////////////////////////// //
28 // QAbstractTableModel methods //
29 // /////////////////////////// //
30 virtual int columnCount(const QModelIndex &parent = QModelIndex{}) const override;
31 virtual int rowCount(const QModelIndex &parent = QModelIndex{}) const override;
32 virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
33 virtual QVariant headerData(int section, Qt::Orientation orientation,
34 int role = Qt::DisplayRole) const override;
35
26 private:
36 private:
27 class VariableModelPrivate;
37 class VariableModelPrivate;
28 spimpl::unique_impl_ptr<VariableModelPrivate> impl;
38 spimpl::unique_impl_ptr<VariableModelPrivate> impl;
29 };
39 };
30
40
31 #endif // SCIQLOP_VARIABLEMODEL_H
41 #endif // SCIQLOP_VARIABLEMODEL_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,24 +1,115
1 #include <Variable/VariableModel.h>
1 #include <Variable/VariableModel.h>
2
2
3 #include <Variable/Variable.h>
3 #include <Variable/Variable.h>
4
4
5 Q_LOGGING_CATEGORY(LOG_VariableModel, "VariableModel")
5 Q_LOGGING_CATEGORY(LOG_VariableModel, "VariableModel")
6
6
7 namespace {
8
9 // Column indexes
10 const auto NAME_COLUMN = 0;
11 const auto UNIT_COLUMN = 1;
12 const auto MISSION_COLUMN = 2;
13 const auto NB_COLUMNS = 3;
14
15 } // namespace
16
7 struct VariableModel::VariableModelPrivate {
17 struct VariableModel::VariableModelPrivate {
8 /// Variables created in SciQlop
18 /// Variables created in SciQlop
9 std::vector<std::unique_ptr<Variable> > m_Variables;
19 std::vector<std::unique_ptr<Variable> > m_Variables;
10 };
20 };
11
21
12 VariableModel::VariableModel() : impl{spimpl::make_unique_impl<VariableModelPrivate>()}
22 VariableModel::VariableModel(QObject *parent)
23 : QAbstractTableModel{parent}, impl{spimpl::make_unique_impl<VariableModelPrivate>()}
13 {
24 {
14 }
25 }
15
26
16 Variable *VariableModel::createVariable(const QString &name) noexcept
27 Variable *VariableModel::createVariable(const QString &name) noexcept
17 {
28 {
29 auto insertIndex = rowCount();
30 beginInsertRows({}, insertIndex, insertIndex);
31
18 /// @todo For the moment, the other data of the variable is initialized with default values
32 /// @todo For the moment, the other data of the variable is initialized with default values
19 auto variable
33 auto variable
20 = std::make_unique<Variable>(name, QStringLiteral("unit"), QStringLiteral("mission"));
34 = std::make_unique<Variable>(name, QStringLiteral("unit"), QStringLiteral("mission"));
21 impl->m_Variables.push_back(std::move(variable));
35 impl->m_Variables.push_back(std::move(variable));
22
36
23 return impl->m_Variables.back().get();
37 endInsertRows();
38
39 return impl->m_Variables.at(insertIndex).get();
40 }
41
42 int VariableModel::columnCount(const QModelIndex &parent) const
43 {
44 Q_UNUSED(parent);
45
46 return NB_COLUMNS;
47 }
48
49 int VariableModel::rowCount(const QModelIndex &parent) const
50 {
51 Q_UNUSED(parent);
52
53 return impl->m_Variables.size();
54 }
55
56 QVariant VariableModel::data(const QModelIndex &index, int role) const
57 {
58 if (!index.isValid()) {
59 return QVariant{};
60 }
61
62 if (index.row() < 0 || index.row() >= rowCount()) {
63 return QVariant{};
64 }
65
66 if (role == Qt::DisplayRole) {
67 if (auto variable = impl->m_Variables.at(index.row()).get()) {
68 switch (index.column()) {
69 case NAME_COLUMN:
70 return variable->m_Name;
71 case UNIT_COLUMN:
72 return variable->m_Unit;
73 case MISSION_COLUMN:
74 return variable->m_Mission;
75 default:
76 // No action
77 break;
78 }
79
80 qWarning(LOG_VariableModel())
81 << tr("Can't get data (unknown column %1)").arg(index.column());
82 }
83 else {
84 qWarning(LOG_VariableModel()) << tr("Can't get data (no variable)");
85 }
86 }
87
88 return QVariant{};
89 }
90
91 QVariant VariableModel::headerData(int section, Qt::Orientation orientation, int role) const
92 {
93 if (role != Qt::DisplayRole) {
94 return QVariant{};
95 }
96
97 if (orientation == Qt::Horizontal) {
98 switch (section) {
99 case NAME_COLUMN:
100 return tr("Name");
101 case UNIT_COLUMN:
102 return tr("Unit");
103 case MISSION_COLUMN:
104 return tr("Mission");
105 default:
106 // No action
107 break;
108 }
109
110 qWarning(LOG_VariableModel())
111 << tr("Can't get header data (unknown column %1)").arg(section);
112 }
113
114 return QVariant{};
24 }
115 }
@@ -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 }
@@ -1,74 +1,80
1 #include "Visualization/VisualizationWidget.h"
1 #include "Visualization/VisualizationWidget.h"
2 #include "Visualization/VisualizationTabWidget.h"
2 #include "Visualization/VisualizationTabWidget.h"
3 #include "Visualization/qcustomplot.h"
3 #include "Visualization/qcustomplot.h"
4
4
5 #include "ui_VisualizationWidget.h"
5 #include "ui_VisualizationWidget.h"
6
6
7 #include <QToolButton>
7 #include <QToolButton>
8
8
9 Q_LOGGING_CATEGORY(LOG_VisualizationWidget, "VisualizationWidget")
9 Q_LOGGING_CATEGORY(LOG_VisualizationWidget, "VisualizationWidget")
10
10
11 VisualizationWidget::VisualizationWidget(QWidget *parent)
11 VisualizationWidget::VisualizationWidget(QWidget *parent)
12 : QWidget{parent}, ui{new Ui::VisualizationWidget}
12 : QWidget{parent}, ui{new Ui::VisualizationWidget}
13 {
13 {
14 ui->setupUi(this);
14 ui->setupUi(this);
15
15
16 auto addTabViewButton = new QToolButton{ui->tabWidget};
16 auto addTabViewButton = new QToolButton{ui->tabWidget};
17 addTabViewButton->setText(tr("Add View"));
17 addTabViewButton->setText(tr("Add View"));
18 addTabViewButton->setCursor(Qt::ArrowCursor);
18 addTabViewButton->setCursor(Qt::ArrowCursor);
19 addTabViewButton->setAutoRaise(true);
19 addTabViewButton->setAutoRaise(true);
20 ui->tabWidget->setCornerWidget(addTabViewButton, Qt::TopRightCorner);
20 ui->tabWidget->setCornerWidget(addTabViewButton, Qt::TopRightCorner);
21 auto width = ui->tabWidget->cornerWidget()->width();
22 auto height = ui->tabWidget->cornerWidget()->height();
23 addTabViewButton->setMinimumHeight(height);
24 addTabViewButton->setMinimumWidth(width);
25 ui->tabWidget->setMinimumHeight(height);
26 ui->tabWidget->setMinimumWidth(width);
21
27
22 auto addTabView = [&]() {
28 auto addTabView = [&]() {
23 auto index = ui->tabWidget->addTab(new VisualizationTabWidget(ui->tabWidget),
29 auto index = ui->tabWidget->addTab(new VisualizationTabWidget(ui->tabWidget),
24 QString("View %1").arg(ui->tabWidget->count() + 1));
30 QString("View %1").arg(ui->tabWidget->count() + 1));
25 qCInfo(LOG_VisualizationWidget()) << tr("add the tab of index %1").arg(index);
31 qCInfo(LOG_VisualizationWidget()) << tr("add the tab of index %1").arg(index);
26 };
32 };
27
33
28 auto removeTabView = [&](int index) {
34 auto removeTabView = [&](int index) {
29 ui->tabWidget->removeTab(index);
35 ui->tabWidget->removeTab(index);
30 qCInfo(LOG_VisualizationWidget()) << tr("remove the tab of index %1").arg(index);
36 qCInfo(LOG_VisualizationWidget()) << tr("remove the tab of index %1").arg(index);
31 };
37 };
32
38
33 ui->tabWidget->setTabsClosable(true);
39 ui->tabWidget->setTabsClosable(true);
34
40
35 connect(addTabViewButton, &QToolButton::clicked, addTabView);
41 connect(addTabViewButton, &QToolButton::clicked, addTabView);
36 connect(ui->tabWidget, &QTabWidget::tabCloseRequested, removeTabView);
42 connect(ui->tabWidget, &QTabWidget::tabCloseRequested, removeTabView);
37 }
43 }
38
44
39 VisualizationWidget::~VisualizationWidget()
45 VisualizationWidget::~VisualizationWidget()
40 {
46 {
41 delete ui;
47 delete ui;
42 }
48 }
43
49
44 void VisualizationWidget::addTab(VisualizationTabWidget *tabWidget)
50 void VisualizationWidget::addTab(VisualizationTabWidget *tabWidget)
45 {
51 {
46 // NOTE: check is this method has to be deleted because of its dupplicated version visible as
52 // NOTE: check is this method has to be deleted because of its dupplicated version visible as
47 // lambda function (in the constructor)
53 // lambda function (in the constructor)
48 }
54 }
49
55
50 VisualizationTabWidget *VisualizationWidget::createTab()
56 VisualizationTabWidget *VisualizationWidget::createTab()
51 {
57 {
52 }
58 }
53
59
54 void VisualizationWidget::removeTab(VisualizationTabWidget *tab)
60 void VisualizationWidget::removeTab(VisualizationTabWidget *tab)
55 {
61 {
56 // NOTE: check is this method has to be deleted because of its dupplicated version visible as
62 // NOTE: check is this method has to be deleted because of its dupplicated version visible as
57 // lambda function (in the constructor)
63 // lambda function (in the constructor)
58 }
64 }
59
65
60 void VisualizationWidget::accept(IVisualizationWidget *visitor)
66 void VisualizationWidget::accept(IVisualizationWidget *visitor)
61 {
67 {
62 // TODO: manage the visitor
68 // TODO: manage the visitor
63 }
69 }
64
70
65 void VisualizationWidget::close()
71 void VisualizationWidget::close()
66 {
72 {
67 // The main view cannot be directly closed.
73 // The main view cannot be directly closed.
68 return;
74 return;
69 }
75 }
70
76
71 QString VisualizationWidget::name() const
77 QString VisualizationWidget::name() const
72 {
78 {
73 return QStringLiteral("MainView");
79 return QStringLiteral("MainView");
74 }
80 }
General Comments 0
You need to be logged in to leave comments. Login now