@@ -0,0 +1,32 | |||||
|
1 | #include "Variable/Variable.h" | |||
|
2 | ||||
|
3 | struct Variable::VariablePrivate { | |||
|
4 | explicit VariablePrivate(const QString &name, const QString &unit, const QString &mission) | |||
|
5 | : m_Name{name}, m_Unit{unit}, m_Mission{mission} | |||
|
6 | { | |||
|
7 | } | |||
|
8 | ||||
|
9 | QString m_Name; | |||
|
10 | QString m_Unit; | |||
|
11 | QString m_Mission; | |||
|
12 | }; | |||
|
13 | ||||
|
14 | Variable::Variable(const QString &name, const QString &unit, const QString &mission) | |||
|
15 | : impl{spimpl::make_unique_impl<VariablePrivate>(name, unit, mission)} | |||
|
16 | { | |||
|
17 | } | |||
|
18 | ||||
|
19 | QString Variable::name() const noexcept | |||
|
20 | { | |||
|
21 | return impl->m_Name; | |||
|
22 | } | |||
|
23 | ||||
|
24 | QString Variable::mission() const noexcept | |||
|
25 | { | |||
|
26 | return impl->m_Mission; | |||
|
27 | } | |||
|
28 | ||||
|
29 | QString Variable::unit() const noexcept | |||
|
30 | { | |||
|
31 | return impl->m_Unit; | |||
|
32 | } |
@@ -1,20 +1,24 | |||||
1 | #ifndef SCIQLOP_VARIABLE_H |
|
1 | #ifndef SCIQLOP_VARIABLE_H | |
2 | #define SCIQLOP_VARIABLE_H |
|
2 | #define SCIQLOP_VARIABLE_H | |
3 |
|
3 | |||
4 | #include <QString> |
|
4 | #include <Common/spimpl.h> | |
|
5 | ||||
|
6 | class QString; | |||
5 |
|
7 | |||
6 | /** |
|
8 | /** | |
7 |
* @brief The Variable |
|
9 | * @brief The Variable class represents a variable in SciQlop. | |
8 | */ |
|
10 | */ | |
9 |
|
|
11 | class Variable { | |
10 | explicit Variable(const QString &name, const QString &unit, const QString &mission) |
|
12 | public: | |
11 | : m_Name{name}, m_Unit{unit}, m_Mission{mission} |
|
13 | explicit Variable(const QString &name, const QString &unit, const QString &mission); | |
12 | { |
|
14 | ||
13 | } |
|
15 | QString name() const noexcept; | |
|
16 | QString mission() const noexcept; | |||
|
17 | QString unit() const noexcept; | |||
14 |
|
18 | |||
15 | QString m_Name; |
|
19 | private: | |
16 | QString m_Unit; |
|
20 | class VariablePrivate; | |
17 | QString m_Mission; |
|
21 | spimpl::unique_impl_ptr<VariablePrivate> impl; | |
18 | }; |
|
22 | }; | |
19 |
|
23 | |||
20 | #endif // SCIQLOP_VARIABLE_H |
|
24 | #endif // SCIQLOP_VARIABLE_H |
@@ -1,115 +1,115 | |||||
|
1 | #include <Variable/Variable.h> | |||
1 | #include <Variable/VariableModel.h> |
|
2 | #include <Variable/VariableModel.h> | |
2 |
|
3 | |||
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 { |
|
7 | namespace { | |
8 |
|
8 | |||
9 | // Column indexes |
|
9 | // Column indexes | |
10 | const auto NAME_COLUMN = 0; |
|
10 | const auto NAME_COLUMN = 0; | |
11 | const auto UNIT_COLUMN = 1; |
|
11 | const auto UNIT_COLUMN = 1; | |
12 | const auto MISSION_COLUMN = 2; |
|
12 | const auto MISSION_COLUMN = 2; | |
13 | const auto NB_COLUMNS = 3; |
|
13 | const auto NB_COLUMNS = 3; | |
14 |
|
14 | |||
15 | } // namespace |
|
15 | } // namespace | |
16 |
|
16 | |||
17 | struct VariableModel::VariableModelPrivate { |
|
17 | struct VariableModel::VariableModelPrivate { | |
18 | /// Variables created in SciQlop |
|
18 | /// Variables created in SciQlop | |
19 | std::vector<std::unique_ptr<Variable> > m_Variables; |
|
19 | std::vector<std::unique_ptr<Variable> > m_Variables; | |
20 | }; |
|
20 | }; | |
21 |
|
21 | |||
22 | VariableModel::VariableModel(QObject *parent) |
|
22 | VariableModel::VariableModel(QObject *parent) | |
23 | : QAbstractTableModel{parent}, impl{spimpl::make_unique_impl<VariableModelPrivate>()} |
|
23 | : QAbstractTableModel{parent}, impl{spimpl::make_unique_impl<VariableModelPrivate>()} | |
24 | { |
|
24 | { | |
25 | } |
|
25 | } | |
26 |
|
26 | |||
27 | Variable *VariableModel::createVariable(const QString &name) noexcept |
|
27 | Variable *VariableModel::createVariable(const QString &name) noexcept | |
28 | { |
|
28 | { | |
29 | auto insertIndex = rowCount(); |
|
29 | auto insertIndex = rowCount(); | |
30 | beginInsertRows({}, insertIndex, insertIndex); |
|
30 | beginInsertRows({}, insertIndex, insertIndex); | |
31 |
|
31 | |||
32 | /// @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 | |
33 | auto variable |
|
33 | auto variable | |
34 | = std::make_unique<Variable>(name, QStringLiteral("unit"), QStringLiteral("mission")); |
|
34 | = std::make_unique<Variable>(name, QStringLiteral("unit"), QStringLiteral("mission")); | |
35 | impl->m_Variables.push_back(std::move(variable)); |
|
35 | impl->m_Variables.push_back(std::move(variable)); | |
36 |
|
36 | |||
37 | endInsertRows(); |
|
37 | endInsertRows(); | |
38 |
|
38 | |||
39 | return impl->m_Variables.at(insertIndex).get(); |
|
39 | return impl->m_Variables.at(insertIndex).get(); | |
40 | } |
|
40 | } | |
41 |
|
41 | |||
42 | int VariableModel::columnCount(const QModelIndex &parent) const |
|
42 | int VariableModel::columnCount(const QModelIndex &parent) const | |
43 | { |
|
43 | { | |
44 | Q_UNUSED(parent); |
|
44 | Q_UNUSED(parent); | |
45 |
|
45 | |||
46 | return NB_COLUMNS; |
|
46 | return NB_COLUMNS; | |
47 | } |
|
47 | } | |
48 |
|
48 | |||
49 | int VariableModel::rowCount(const QModelIndex &parent) const |
|
49 | int VariableModel::rowCount(const QModelIndex &parent) const | |
50 | { |
|
50 | { | |
51 | Q_UNUSED(parent); |
|
51 | Q_UNUSED(parent); | |
52 |
|
52 | |||
53 | return impl->m_Variables.size(); |
|
53 | return impl->m_Variables.size(); | |
54 | } |
|
54 | } | |
55 |
|
55 | |||
56 | QVariant VariableModel::data(const QModelIndex &index, int role) const |
|
56 | QVariant VariableModel::data(const QModelIndex &index, int role) const | |
57 | { |
|
57 | { | |
58 | if (!index.isValid()) { |
|
58 | if (!index.isValid()) { | |
59 | return QVariant{}; |
|
59 | return QVariant{}; | |
60 | } |
|
60 | } | |
61 |
|
61 | |||
62 | if (index.row() < 0 || index.row() >= rowCount()) { |
|
62 | if (index.row() < 0 || index.row() >= rowCount()) { | |
63 | return QVariant{}; |
|
63 | return QVariant{}; | |
64 | } |
|
64 | } | |
65 |
|
65 | |||
66 | if (role == Qt::DisplayRole) { |
|
66 | if (role == Qt::DisplayRole) { | |
67 | if (auto variable = impl->m_Variables.at(index.row()).get()) { |
|
67 | if (auto variable = impl->m_Variables.at(index.row()).get()) { | |
68 | switch (index.column()) { |
|
68 | switch (index.column()) { | |
69 | case NAME_COLUMN: |
|
69 | case NAME_COLUMN: | |
70 |
return variable-> |
|
70 | return variable->name(); | |
71 | case UNIT_COLUMN: |
|
71 | case UNIT_COLUMN: | |
72 |
return variable-> |
|
72 | return variable->unit(); | |
73 | case MISSION_COLUMN: |
|
73 | case MISSION_COLUMN: | |
74 |
return variable->m |
|
74 | return variable->mission(); | |
75 | default: |
|
75 | default: | |
76 | // No action |
|
76 | // No action | |
77 | break; |
|
77 | break; | |
78 | } |
|
78 | } | |
79 |
|
79 | |||
80 | qWarning(LOG_VariableModel()) |
|
80 | qWarning(LOG_VariableModel()) | |
81 | << tr("Can't get data (unknown column %1)").arg(index.column()); |
|
81 | << tr("Can't get data (unknown column %1)").arg(index.column()); | |
82 | } |
|
82 | } | |
83 | else { |
|
83 | else { | |
84 | qWarning(LOG_VariableModel()) << tr("Can't get data (no variable)"); |
|
84 | qWarning(LOG_VariableModel()) << tr("Can't get data (no variable)"); | |
85 | } |
|
85 | } | |
86 | } |
|
86 | } | |
87 |
|
87 | |||
88 | return QVariant{}; |
|
88 | return QVariant{}; | |
89 | } |
|
89 | } | |
90 |
|
90 | |||
91 | QVariant VariableModel::headerData(int section, Qt::Orientation orientation, int role) const |
|
91 | QVariant VariableModel::headerData(int section, Qt::Orientation orientation, int role) const | |
92 | { |
|
92 | { | |
93 | if (role != Qt::DisplayRole) { |
|
93 | if (role != Qt::DisplayRole) { | |
94 | return QVariant{}; |
|
94 | return QVariant{}; | |
95 | } |
|
95 | } | |
96 |
|
96 | |||
97 | if (orientation == Qt::Horizontal) { |
|
97 | if (orientation == Qt::Horizontal) { | |
98 | switch (section) { |
|
98 | switch (section) { | |
99 | case NAME_COLUMN: |
|
99 | case NAME_COLUMN: | |
100 | return tr("Name"); |
|
100 | return tr("Name"); | |
101 | case UNIT_COLUMN: |
|
101 | case UNIT_COLUMN: | |
102 | return tr("Unit"); |
|
102 | return tr("Unit"); | |
103 | case MISSION_COLUMN: |
|
103 | case MISSION_COLUMN: | |
104 | return tr("Mission"); |
|
104 | return tr("Mission"); | |
105 | default: |
|
105 | default: | |
106 | // No action |
|
106 | // No action | |
107 | break; |
|
107 | break; | |
108 | } |
|
108 | } | |
109 |
|
109 | |||
110 | qWarning(LOG_VariableModel()) |
|
110 | qWarning(LOG_VariableModel()) | |
111 | << tr("Can't get header data (unknown column %1)").arg(section); |
|
111 | << tr("Can't get header data (unknown column %1)").arg(section); | |
112 | } |
|
112 | } | |
113 |
|
113 | |||
114 | return QVariant{}; |
|
114 | return QVariant{}; | |
115 | } |
|
115 | } |
General Comments 0
You need to be logged in to leave comments.
Login now