Auto status change to "Under Review"
@@ -1,70 +1,70 | |||||
1 | #ifndef SCIQLOP_VARIABLEMODEL_H |
|
1 | #ifndef SCIQLOP_VARIABLEMODEL_H | |
2 | #define SCIQLOP_VARIABLEMODEL_H |
|
2 | #define SCIQLOP_VARIABLEMODEL_H | |
3 |
|
3 | |||
4 |
|
4 | |||
5 | #include <Data/SqpDateTime.h> |
|
5 | #include <Data/SqpDateTime.h> | |
6 |
|
6 | |||
7 | #include <QAbstractTableModel> |
|
7 | #include <QAbstractTableModel> | |
8 | #include <QLoggingCategory> |
|
8 | #include <QLoggingCategory> | |
9 |
|
9 | |||
10 | #include <Common/MetaTypes.h> |
|
10 | #include <Common/MetaTypes.h> | |
11 | #include <Common/spimpl.h> |
|
11 | #include <Common/spimpl.h> | |
12 |
|
12 | |||
13 | Q_DECLARE_LOGGING_CATEGORY(LOG_VariableModel) |
|
13 | Q_DECLARE_LOGGING_CATEGORY(LOG_VariableModel) | |
14 |
|
14 | |||
15 |
enum VariableRoles { |
|
15 | enum VariableRoles { ProgressRole = Qt::UserRole }; | |
16 |
|
16 | |||
17 |
|
17 | |||
18 | class IDataSeries; |
|
18 | class IDataSeries; | |
19 | class Variable; |
|
19 | class Variable; | |
20 |
|
20 | |||
21 | /** |
|
21 | /** | |
22 | * @brief The VariableModel class aims to hold the variables that have been created in SciQlop |
|
22 | * @brief The VariableModel class aims to hold the variables that have been created in SciQlop | |
23 | */ |
|
23 | */ | |
24 | class VariableModel : public QAbstractTableModel { |
|
24 | class VariableModel : public QAbstractTableModel { | |
25 | public: |
|
25 | public: | |
26 | explicit VariableModel(QObject *parent = nullptr); |
|
26 | explicit VariableModel(QObject *parent = nullptr); | |
27 |
|
27 | |||
28 | /** |
|
28 | /** | |
29 | * Creates a new variable in the model |
|
29 | * Creates a new variable in the model | |
30 | * @param name the name of the new variable |
|
30 | * @param name the name of the new variable | |
31 | * @param dateTime the dateTime of the new variable |
|
31 | * @param dateTime the dateTime of the new variable | |
32 | * @return the pointer to the new variable |
|
32 | * @return the pointer to the new variable | |
33 | */ |
|
33 | */ | |
34 | std::shared_ptr<Variable> createVariable(const QString &name, |
|
34 | std::shared_ptr<Variable> createVariable(const QString &name, | |
35 | const SqpDateTime &dateTime) noexcept; |
|
35 | const SqpDateTime &dateTime) noexcept; | |
36 |
|
36 | |||
37 | /** |
|
37 | /** | |
38 | * Deletes a variable from the model, if it exists |
|
38 | * Deletes a variable from the model, if it exists | |
39 | * @param variable the variable to delete |
|
39 | * @param variable the variable to delete | |
40 | */ |
|
40 | */ | |
41 | void deleteVariable(std::shared_ptr<Variable> variable) noexcept; |
|
41 | void deleteVariable(std::shared_ptr<Variable> variable) noexcept; | |
42 |
|
42 | |||
43 |
|
43 | |||
44 | std::shared_ptr<Variable> variable(int index) const; |
|
44 | std::shared_ptr<Variable> variable(int index) const; | |
45 |
|
45 | |||
46 | void setDataProgress(std::shared_ptr<Variable> variable, double progress); |
|
46 | void setDataProgress(std::shared_ptr<Variable> variable, double progress); | |
47 |
|
47 | |||
48 | // /////////////////////////// // |
|
48 | // /////////////////////////// // | |
49 | // QAbstractTableModel methods // |
|
49 | // QAbstractTableModel methods // | |
50 | // /////////////////////////// // |
|
50 | // /////////////////////////// // | |
51 |
|
51 | |||
52 | virtual int columnCount(const QModelIndex &parent = QModelIndex{}) const override; |
|
52 | virtual int columnCount(const QModelIndex &parent = QModelIndex{}) const override; | |
53 | virtual int rowCount(const QModelIndex &parent = QModelIndex{}) const override; |
|
53 | virtual int rowCount(const QModelIndex &parent = QModelIndex{}) const override; | |
54 | virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; |
|
54 | virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; | |
55 | virtual QVariant headerData(int section, Qt::Orientation orientation, |
|
55 | virtual QVariant headerData(int section, Qt::Orientation orientation, | |
56 | int role = Qt::DisplayRole) const override; |
|
56 | int role = Qt::DisplayRole) const override; | |
57 |
|
57 | |||
58 | private: |
|
58 | private: | |
59 | class VariableModelPrivate; |
|
59 | class VariableModelPrivate; | |
60 | spimpl::unique_impl_ptr<VariableModelPrivate> impl; |
|
60 | spimpl::unique_impl_ptr<VariableModelPrivate> impl; | |
61 |
|
61 | |||
62 | private slots: |
|
62 | private slots: | |
63 | /// Slot called when data of a variable has been updated |
|
63 | /// Slot called when data of a variable has been updated | |
64 | void onVariableUpdated() noexcept; |
|
64 | void onVariableUpdated() noexcept; | |
65 | }; |
|
65 | }; | |
66 |
|
66 | |||
67 | // Registers QVector<int> metatype so it can be used in VariableModel::dataChanged() signal |
|
67 | // Registers QVector<int> metatype so it can be used in VariableModel::dataChanged() signal | |
68 | SCIQLOP_REGISTER_META_TYPE(QVECTOR_INT_REGISTRY, QVector<int>) |
|
68 | SCIQLOP_REGISTER_META_TYPE(QVECTOR_INT_REGISTRY, QVector<int>) | |
69 |
|
69 | |||
70 | #endif // SCIQLOP_VARIABLEMODEL_H |
|
70 | #endif // SCIQLOP_VARIABLEMODEL_H |
@@ -1,236 +1,236 | |||||
1 | #include <Variable/Variable.h> |
|
1 | #include <Variable/Variable.h> | |
2 | #include <Variable/VariableModel.h> |
|
2 | #include <Variable/VariableModel.h> | |
3 |
|
3 | |||
4 | #include <Data/IDataSeries.h> |
|
4 | #include <Data/IDataSeries.h> | |
5 |
|
5 | |||
6 | #include <QDateTime> |
|
6 | #include <QDateTime> | |
7 | #include <QSize> |
|
7 | #include <QSize> | |
8 | #include <unordered_map> |
|
8 | #include <unordered_map> | |
9 |
|
9 | |||
10 | Q_LOGGING_CATEGORY(LOG_VariableModel, "VariableModel") |
|
10 | Q_LOGGING_CATEGORY(LOG_VariableModel, "VariableModel") | |
11 |
|
11 | |||
12 | namespace { |
|
12 | namespace { | |
13 |
|
13 | |||
14 | // Column indexes |
|
14 | // Column indexes | |
15 | const auto NAME_COLUMN = 0; |
|
15 | const auto NAME_COLUMN = 0; | |
16 | const auto TSTART_COLUMN = 1; |
|
16 | const auto TSTART_COLUMN = 1; | |
17 | const auto TEND_COLUMN = 2; |
|
17 | const auto TEND_COLUMN = 2; | |
18 | const auto NB_COLUMNS = 3; |
|
18 | const auto NB_COLUMNS = 3; | |
19 |
|
19 | |||
20 | // Column properties |
|
20 | // Column properties | |
21 | const auto DEFAULT_HEIGHT = 25; |
|
21 | const auto DEFAULT_HEIGHT = 25; | |
22 | const auto DEFAULT_WIDTH = 100; |
|
22 | const auto DEFAULT_WIDTH = 100; | |
23 |
|
23 | |||
24 | struct ColumnProperties { |
|
24 | struct ColumnProperties { | |
25 | ColumnProperties(const QString &name = {}, int width = DEFAULT_WIDTH, |
|
25 | ColumnProperties(const QString &name = {}, int width = DEFAULT_WIDTH, | |
26 | int height = DEFAULT_HEIGHT) |
|
26 | int height = DEFAULT_HEIGHT) | |
27 | : m_Name{name}, m_Width{width}, m_Height{height} |
|
27 | : m_Name{name}, m_Width{width}, m_Height{height} | |
28 | { |
|
28 | { | |
29 | } |
|
29 | } | |
30 |
|
30 | |||
31 | QString m_Name; |
|
31 | QString m_Name; | |
32 | int m_Width; |
|
32 | int m_Width; | |
33 | int m_Height; |
|
33 | int m_Height; | |
34 | }; |
|
34 | }; | |
35 |
|
35 | |||
36 | const auto COLUMN_PROPERTIES |
|
36 | const auto COLUMN_PROPERTIES | |
37 | = QHash<int, ColumnProperties>{{NAME_COLUMN, {QObject::tr("Name")}}, |
|
37 | = QHash<int, ColumnProperties>{{NAME_COLUMN, {QObject::tr("Name")}}, | |
38 | {TSTART_COLUMN, {QObject::tr("tStart"), 180}}, |
|
38 | {TSTART_COLUMN, {QObject::tr("tStart"), 180}}, | |
39 | {TEND_COLUMN, {QObject::tr("tEnd"), 180}}}; |
|
39 | {TEND_COLUMN, {QObject::tr("tEnd"), 180}}}; | |
40 |
|
40 | |||
41 | /// Format for datetimes |
|
41 | /// Format for datetimes | |
42 | const auto DATETIME_FORMAT = QStringLiteral("dd/MM/yyyy \nhh:mm:ss:zzz"); |
|
42 | const auto DATETIME_FORMAT = QStringLiteral("dd/MM/yyyy \nhh:mm:ss:zzz"); | |
43 |
|
43 | |||
44 |
|
44 | |||
45 | } // namespace |
|
45 | } // namespace | |
46 |
|
46 | |||
47 | struct VariableModel::VariableModelPrivate { |
|
47 | struct VariableModel::VariableModelPrivate { | |
48 | /// Variables created in SciQlop |
|
48 | /// Variables created in SciQlop | |
49 | std::vector<std::shared_ptr<Variable> > m_Variables; |
|
49 | std::vector<std::shared_ptr<Variable> > m_Variables; | |
50 | std::unordered_map<std::shared_ptr<Variable>, double> m_VariableToProgress; |
|
50 | std::unordered_map<std::shared_ptr<Variable>, double> m_VariableToProgress; | |
51 |
|
51 | |||
52 |
|
52 | |||
53 | /// Return te row index of the variable |
|
53 | /// Return the row index of the variable. -1 if it's not found | |
54 | int indexOfVariable(Variable *variable) const noexcept; |
|
54 | int indexOfVariable(Variable *variable) const noexcept; | |
55 | }; |
|
55 | }; | |
56 |
|
56 | |||
57 | VariableModel::VariableModel(QObject *parent) |
|
57 | VariableModel::VariableModel(QObject *parent) | |
58 | : QAbstractTableModel{parent}, impl{spimpl::make_unique_impl<VariableModelPrivate>()} |
|
58 | : QAbstractTableModel{parent}, impl{spimpl::make_unique_impl<VariableModelPrivate>()} | |
59 | { |
|
59 | { | |
60 | } |
|
60 | } | |
61 |
|
61 | |||
62 | std::shared_ptr<Variable> VariableModel::createVariable(const QString &name, |
|
62 | std::shared_ptr<Variable> VariableModel::createVariable(const QString &name, | |
63 | const SqpDateTime &dateTime) noexcept |
|
63 | const SqpDateTime &dateTime) noexcept | |
64 | { |
|
64 | { | |
65 | auto insertIndex = rowCount(); |
|
65 | auto insertIndex = rowCount(); | |
66 | beginInsertRows({}, insertIndex, insertIndex); |
|
66 | beginInsertRows({}, insertIndex, insertIndex); | |
67 |
|
67 | |||
68 | /// @todo For the moment, the other data of the variable is initialized with default values |
|
68 | /// @todo For the moment, the other data of the variable is initialized with default values | |
69 | auto variable = std::make_shared<Variable>(name, QStringLiteral("unit"), |
|
69 | auto variable = std::make_shared<Variable>(name, QStringLiteral("unit"), | |
70 | QStringLiteral("mission"), dateTime); |
|
70 | QStringLiteral("mission"), dateTime); | |
71 |
|
71 | |||
72 | impl->m_Variables.push_back(variable); |
|
72 | impl->m_Variables.push_back(variable); | |
73 | connect(variable.get(), &Variable::updated, this, &VariableModel::onVariableUpdated); |
|
73 | connect(variable.get(), &Variable::updated, this, &VariableModel::onVariableUpdated); | |
74 |
|
74 | |||
75 | endInsertRows(); |
|
75 | endInsertRows(); | |
76 |
|
76 | |||
77 | return variable; |
|
77 | return variable; | |
78 | } |
|
78 | } | |
79 |
|
79 | |||
80 | void VariableModel::deleteVariable(std::shared_ptr<Variable> variable) noexcept |
|
80 | void VariableModel::deleteVariable(std::shared_ptr<Variable> variable) noexcept | |
81 | { |
|
81 | { | |
82 | if (!variable) { |
|
82 | if (!variable) { | |
83 | qCCritical(LOG_Variable()) << "Can't delete a null variable from the model"; |
|
83 | qCCritical(LOG_Variable()) << "Can't delete a null variable from the model"; | |
84 | return; |
|
84 | return; | |
85 | } |
|
85 | } | |
86 |
|
86 | |||
87 | // Finds variable in the model |
|
87 | // Finds variable in the model | |
88 | auto begin = impl->m_Variables.cbegin(); |
|
88 | auto begin = impl->m_Variables.cbegin(); | |
89 | auto end = impl->m_Variables.cend(); |
|
89 | auto end = impl->m_Variables.cend(); | |
90 | auto it = std::find(begin, end, variable); |
|
90 | auto it = std::find(begin, end, variable); | |
91 | if (it != end) { |
|
91 | if (it != end) { | |
92 | auto removeIndex = std::distance(begin, it); |
|
92 | auto removeIndex = std::distance(begin, it); | |
93 |
|
93 | |||
94 | // Deletes variable |
|
94 | // Deletes variable | |
95 | beginRemoveRows({}, removeIndex, removeIndex); |
|
95 | beginRemoveRows({}, removeIndex, removeIndex); | |
96 | impl->m_Variables.erase(it); |
|
96 | impl->m_Variables.erase(it); | |
97 | endRemoveRows(); |
|
97 | endRemoveRows(); | |
98 | } |
|
98 | } | |
99 | else { |
|
99 | else { | |
100 | qCritical(LOG_VariableModel()) |
|
100 | qCritical(LOG_VariableModel()) | |
101 | << tr("Can't delete variable %1 from the model: the variable is not in the model") |
|
101 | << tr("Can't delete variable %1 from the model: the variable is not in the model") | |
102 | .arg(variable->name()); |
|
102 | .arg(variable->name()); | |
103 | } |
|
103 | } | |
104 | } |
|
104 | } | |
105 |
|
105 | |||
106 |
|
106 | |||
107 | std::shared_ptr<Variable> VariableModel::variable(int index) const |
|
107 | std::shared_ptr<Variable> VariableModel::variable(int index) const | |
108 | { |
|
108 | { | |
109 | return (index >= 0 && index < impl->m_Variables.size()) ? impl->m_Variables[index] : nullptr; |
|
109 | return (index >= 0 && index < impl->m_Variables.size()) ? impl->m_Variables[index] : nullptr; | |
110 | } |
|
110 | } | |
111 |
|
111 | |||
112 | void VariableModel::setDataProgress(std::shared_ptr<Variable> variable, double progress) |
|
112 | void VariableModel::setDataProgress(std::shared_ptr<Variable> variable, double progress) | |
113 | { |
|
113 | { | |
114 |
|
114 | |||
115 | impl->m_VariableToProgress[variable] = progress; |
|
115 | impl->m_VariableToProgress[variable] = progress; | |
116 | auto modelIndex = createIndex(impl->indexOfVariable(variable.get()), NAME_COLUMN); |
|
116 | auto modelIndex = createIndex(impl->indexOfVariable(variable.get()), NAME_COLUMN); | |
117 |
|
117 | |||
118 | emit dataChanged(modelIndex, modelIndex); |
|
118 | emit dataChanged(modelIndex, modelIndex); | |
119 | } |
|
119 | } | |
120 |
|
120 | |||
121 | int VariableModel::columnCount(const QModelIndex &parent) const |
|
121 | int VariableModel::columnCount(const QModelIndex &parent) const | |
122 | { |
|
122 | { | |
123 | Q_UNUSED(parent); |
|
123 | Q_UNUSED(parent); | |
124 |
|
124 | |||
125 | return NB_COLUMNS; |
|
125 | return NB_COLUMNS; | |
126 | } |
|
126 | } | |
127 |
|
127 | |||
128 | int VariableModel::rowCount(const QModelIndex &parent) const |
|
128 | int VariableModel::rowCount(const QModelIndex &parent) const | |
129 | { |
|
129 | { | |
130 | Q_UNUSED(parent); |
|
130 | Q_UNUSED(parent); | |
131 |
|
131 | |||
132 | return impl->m_Variables.size(); |
|
132 | return impl->m_Variables.size(); | |
133 | } |
|
133 | } | |
134 |
|
134 | |||
135 | QVariant VariableModel::data(const QModelIndex &index, int role) const |
|
135 | QVariant VariableModel::data(const QModelIndex &index, int role) const | |
136 | { |
|
136 | { | |
137 | if (!index.isValid()) { |
|
137 | if (!index.isValid()) { | |
138 | return QVariant{}; |
|
138 | return QVariant{}; | |
139 | } |
|
139 | } | |
140 |
|
140 | |||
141 | if (index.row() < 0 || index.row() >= rowCount()) { |
|
141 | if (index.row() < 0 || index.row() >= rowCount()) { | |
142 | return QVariant{}; |
|
142 | return QVariant{}; | |
143 | } |
|
143 | } | |
144 |
|
144 | |||
145 | if (role == Qt::DisplayRole) { |
|
145 | if (role == Qt::DisplayRole) { | |
146 | if (auto variable = impl->m_Variables.at(index.row()).get()) { |
|
146 | if (auto variable = impl->m_Variables.at(index.row()).get()) { | |
147 | /// Lambda function that builds the variant to return for a time value |
|
147 | /// Lambda function that builds the variant to return for a time value | |
148 | auto dateTimeVariant = [](double time) { |
|
148 | auto dateTimeVariant = [](double time) { | |
149 | auto dateTime = QDateTime::fromMSecsSinceEpoch(time * 1000.); |
|
149 | auto dateTime = QDateTime::fromMSecsSinceEpoch(time * 1000.); | |
150 | return dateTime.toString(DATETIME_FORMAT); |
|
150 | return dateTime.toString(DATETIME_FORMAT); | |
151 | }; |
|
151 | }; | |
152 |
|
152 | |||
153 | switch (index.column()) { |
|
153 | switch (index.column()) { | |
154 | case NAME_COLUMN: |
|
154 | case NAME_COLUMN: | |
155 | return variable->name(); |
|
155 | return variable->name(); | |
156 | case TSTART_COLUMN: |
|
156 | case TSTART_COLUMN: | |
157 | return dateTimeVariant(variable->dateTime().m_TStart); |
|
157 | return dateTimeVariant(variable->dateTime().m_TStart); | |
158 | case TEND_COLUMN: |
|
158 | case TEND_COLUMN: | |
159 | return dateTimeVariant(variable->dateTime().m_TEnd); |
|
159 | return dateTimeVariant(variable->dateTime().m_TEnd); | |
160 | default: |
|
160 | default: | |
161 | // No action |
|
161 | // No action | |
162 | break; |
|
162 | break; | |
163 | } |
|
163 | } | |
164 |
|
164 | |||
165 | qWarning(LOG_VariableModel()) |
|
165 | qWarning(LOG_VariableModel()) | |
166 | << tr("Can't get data (unknown column %1)").arg(index.column()); |
|
166 | << tr("Can't get data (unknown column %1)").arg(index.column()); | |
167 | } |
|
167 | } | |
168 | else { |
|
168 | else { | |
169 | qWarning(LOG_VariableModel()) << tr("Can't get data (no variable)"); |
|
169 | qWarning(LOG_VariableModel()) << tr("Can't get data (no variable)"); | |
170 | } |
|
170 | } | |
171 | } |
|
171 | } | |
172 |
else if (role == VariableRoles:: |
|
172 | else if (role == VariableRoles::ProgressRole) { | |
173 | if (auto variable = impl->m_Variables.at(index.row())) { |
|
173 | if (auto variable = impl->m_Variables.at(index.row())) { | |
174 |
|
174 | |||
175 | auto it = impl->m_VariableToProgress.find(variable); |
|
175 | auto it = impl->m_VariableToProgress.find(variable); | |
176 | if (it != impl->m_VariableToProgress.cend()) { |
|
176 | if (it != impl->m_VariableToProgress.cend()) { | |
177 | return it->second; |
|
177 | return it->second; | |
178 | } |
|
178 | } | |
179 | } |
|
179 | } | |
180 | } |
|
180 | } | |
181 |
|
181 | |||
182 | return QVariant{}; |
|
182 | return QVariant{}; | |
183 | } |
|
183 | } | |
184 |
|
184 | |||
185 | QVariant VariableModel::headerData(int section, Qt::Orientation orientation, int role) const |
|
185 | QVariant VariableModel::headerData(int section, Qt::Orientation orientation, int role) const | |
186 | { |
|
186 | { | |
187 | if (role != Qt::DisplayRole && role != Qt::SizeHintRole) { |
|
187 | if (role != Qt::DisplayRole && role != Qt::SizeHintRole) { | |
188 | return QVariant{}; |
|
188 | return QVariant{}; | |
189 | } |
|
189 | } | |
190 |
|
190 | |||
191 | if (orientation == Qt::Horizontal) { |
|
191 | if (orientation == Qt::Horizontal) { | |
192 | auto propertiesIt = COLUMN_PROPERTIES.find(section); |
|
192 | auto propertiesIt = COLUMN_PROPERTIES.find(section); | |
193 | if (propertiesIt != COLUMN_PROPERTIES.cend()) { |
|
193 | if (propertiesIt != COLUMN_PROPERTIES.cend()) { | |
194 | // Role is either DisplayRole or SizeHintRole |
|
194 | // Role is either DisplayRole or SizeHintRole | |
195 | return (role == Qt::DisplayRole) |
|
195 | return (role == Qt::DisplayRole) | |
196 | ? QVariant{propertiesIt->m_Name} |
|
196 | ? QVariant{propertiesIt->m_Name} | |
197 | : QVariant{QSize{propertiesIt->m_Width, propertiesIt->m_Height}}; |
|
197 | : QVariant{QSize{propertiesIt->m_Width, propertiesIt->m_Height}}; | |
198 | } |
|
198 | } | |
199 | else { |
|
199 | else { | |
200 | qWarning(LOG_VariableModel()) |
|
200 | qWarning(LOG_VariableModel()) | |
201 | << tr("Can't get header data (unknown column %1)").arg(section); |
|
201 | << tr("Can't get header data (unknown column %1)").arg(section); | |
202 | } |
|
202 | } | |
203 | } |
|
203 | } | |
204 |
|
204 | |||
205 | return QVariant{}; |
|
205 | return QVariant{}; | |
206 | } |
|
206 | } | |
207 |
|
207 | |||
208 | void VariableModel::onVariableUpdated() noexcept |
|
208 | void VariableModel::onVariableUpdated() noexcept | |
209 | { |
|
209 | { | |
210 | // Finds variable that has been updated in the model |
|
210 | // Finds variable that has been updated in the model | |
211 | if (auto updatedVariable = dynamic_cast<Variable *>(sender())) { |
|
211 | if (auto updatedVariable = dynamic_cast<Variable *>(sender())) { | |
212 | auto updatedVariableIndex = impl->indexOfVariable(updatedVariable); |
|
212 | auto updatedVariableIndex = impl->indexOfVariable(updatedVariable); | |
213 |
|
213 | |||
214 | if (updatedVariableIndex > -1) { |
|
214 | if (updatedVariableIndex > -1) { | |
215 | emit dataChanged(createIndex(updatedVariableIndex, 0), |
|
215 | emit dataChanged(createIndex(updatedVariableIndex, 0), | |
216 | createIndex(updatedVariableIndex, columnCount() - 1)); |
|
216 | createIndex(updatedVariableIndex, columnCount() - 1)); | |
217 | } |
|
217 | } | |
218 | } |
|
218 | } | |
219 | } |
|
219 | } | |
220 |
|
220 | |||
221 | int VariableModel::VariableModelPrivate::indexOfVariable(Variable *variable) const noexcept |
|
221 | int VariableModel::VariableModelPrivate::indexOfVariable(Variable *variable) const noexcept | |
222 | { |
|
222 | { | |
223 | auto begin = std::cbegin(m_Variables); |
|
223 | auto begin = std::cbegin(m_Variables); | |
224 | auto end = std::cend(m_Variables); |
|
224 | auto end = std::cend(m_Variables); | |
225 | auto it |
|
225 | auto it | |
226 | = std::find_if(begin, end, [variable](const auto &var) { return var.get() == variable; }); |
|
226 | = std::find_if(begin, end, [variable](const auto &var) { return var.get() == variable; }); | |
227 |
|
227 | |||
228 | if (it != end) { |
|
228 | if (it != end) { | |
229 | // Gets the index of the variable in the model: we assume here that views have the same |
|
229 | // Gets the index of the variable in the model: we assume here that views have the same | |
230 | // order as the model |
|
230 | // order as the model | |
231 | return std::distance(begin, it); |
|
231 | return std::distance(begin, it); | |
232 | } |
|
232 | } | |
233 | else { |
|
233 | else { | |
234 | return -1; |
|
234 | return -1; | |
235 | } |
|
235 | } | |
236 | } |
|
236 | } |
@@ -1,140 +1,140 | |||||
1 | #include <Variable/VariableController.h> |
|
1 | #include <Variable/VariableController.h> | |
2 | #include <Variable/VariableInspectorWidget.h> |
|
2 | #include <Variable/VariableInspectorWidget.h> | |
3 | #include <Variable/VariableMenuHeaderWidget.h> |
|
3 | #include <Variable/VariableMenuHeaderWidget.h> | |
4 | #include <Variable/VariableModel.h> |
|
4 | #include <Variable/VariableModel.h> | |
5 |
|
5 | |||
6 | #include <ui_VariableInspectorWidget.h> |
|
6 | #include <ui_VariableInspectorWidget.h> | |
7 |
|
7 | |||
8 | #include <QSortFilterProxyModel> |
|
8 | #include <QSortFilterProxyModel> | |
9 | #include <QStyledItemDelegate> |
|
9 | #include <QStyledItemDelegate> | |
10 | #include <QWidgetAction> |
|
10 | #include <QWidgetAction> | |
11 |
|
11 | |||
12 | #include <SqpApplication.h> |
|
12 | #include <SqpApplication.h> | |
13 |
|
13 | |||
14 | Q_LOGGING_CATEGORY(LOG_VariableInspectorWidget, "VariableInspectorWidget") |
|
14 | Q_LOGGING_CATEGORY(LOG_VariableInspectorWidget, "VariableInspectorWidget") | |
15 |
|
15 | |||
16 |
|
16 | |||
17 | class QProgressBarItemDelegate : public QStyledItemDelegate { |
|
17 | class QProgressBarItemDelegate : public QStyledItemDelegate { | |
18 |
|
18 | |||
19 | public: |
|
19 | public: | |
20 |
QProgressBarItemDelegate(QObject *parent) : QStyledItemDelegate |
|
20 | QProgressBarItemDelegate(QObject *parent) : QStyledItemDelegate{parent} {} | |
21 |
|
21 | |||
22 | void paint(QPainter *painter, const QStyleOptionViewItem &option, |
|
22 | void paint(QPainter *painter, const QStyleOptionViewItem &option, | |
23 | const QModelIndex &index) const |
|
23 | const QModelIndex &index) const | |
24 | { |
|
24 | { | |
25 | auto data = index.data(Qt::DisplayRole); |
|
25 | auto data = index.data(Qt::DisplayRole); | |
26 |
auto progressData = index.data(VariableRoles:: |
|
26 | auto progressData = index.data(VariableRoles::ProgressRole); | |
27 | if (data.isValid() && progressData.isValid()) { |
|
27 | if (data.isValid() && progressData.isValid()) { | |
28 | auto name = data.value<QString>(); |
|
28 | auto name = data.value<QString>(); | |
29 | auto progress = progressData.value<double>(); |
|
29 | auto progress = progressData.value<double>(); | |
30 | if (progress >= 0) { |
|
30 | if (progress >= 0) { | |
31 | auto progressBarOption = QStyleOptionProgressBar{}; |
|
31 | auto progressBarOption = QStyleOptionProgressBar{}; | |
32 | progressBarOption.rect = option.rect; |
|
32 | progressBarOption.rect = option.rect; | |
33 | progressBarOption.minimum = 0; |
|
33 | progressBarOption.minimum = 0; | |
34 | progressBarOption.maximum = 100; |
|
34 | progressBarOption.maximum = 100; | |
35 | progressBarOption.progress = progress; |
|
35 | progressBarOption.progress = progress; | |
36 | progressBarOption.text |
|
36 | progressBarOption.text | |
37 | = QString("%1 %2").arg(name).arg(QString::number(progress, 'f', 2) + "%"); |
|
37 | = QString("%1 %2").arg(name).arg(QString::number(progress, 'f', 2) + "%"); | |
38 | progressBarOption.textVisible = true; |
|
38 | progressBarOption.textVisible = true; | |
39 | progressBarOption.textAlignment = Qt::AlignCenter; |
|
39 | progressBarOption.textAlignment = Qt::AlignCenter; | |
40 |
|
40 | |||
41 | QApplication::style()->drawControl(QStyle::CE_ProgressBar, &progressBarOption, |
|
41 | QApplication::style()->drawControl(QStyle::CE_ProgressBar, &progressBarOption, | |
42 | painter); |
|
42 | painter); | |
43 | } |
|
43 | } | |
44 | } |
|
44 | } | |
45 | else { |
|
45 | else { | |
46 | QStyledItemDelegate::paint(painter, option, index); |
|
46 | QStyledItemDelegate::paint(painter, option, index); | |
47 | } |
|
47 | } | |
48 | } |
|
48 | } | |
49 | }; |
|
49 | }; | |
50 |
|
50 | |||
51 | VariableInspectorWidget::VariableInspectorWidget(QWidget *parent) |
|
51 | VariableInspectorWidget::VariableInspectorWidget(QWidget *parent) | |
52 | : QWidget{parent}, |
|
52 | : QWidget{parent}, | |
53 | ui{new Ui::VariableInspectorWidget}, |
|
53 | ui{new Ui::VariableInspectorWidget}, | |
54 |
m_ProgressBarItemDelegate{new QProgressBarItemDelegate |
|
54 | m_ProgressBarItemDelegate{new QProgressBarItemDelegate{this}} | |
55 | { |
|
55 | { | |
56 | ui->setupUi(this); |
|
56 | ui->setupUi(this); | |
57 |
|
57 | |||
58 | // Sets model for table |
|
58 | // Sets model for table | |
59 | // auto sortFilterModel = new QSortFilterProxyModel{this}; |
|
59 | // auto sortFilterModel = new QSortFilterProxyModel{this}; | |
60 | // sortFilterModel->setSourceModel(sqpApp->variableController().variableModel()); |
|
60 | // sortFilterModel->setSourceModel(sqpApp->variableController().variableModel()); | |
61 |
|
61 | |||
62 | auto variableModel = sqpApp->variableController().variableModel(); |
|
62 | auto variableModel = sqpApp->variableController().variableModel(); | |
63 | ui->tableView->setModel(variableModel); |
|
63 | ui->tableView->setModel(variableModel); | |
64 |
|
64 | |||
65 | // Adds extra signal/slot between view and model, so the view can be updated instantly when |
|
65 | // Adds extra signal/slot between view and model, so the view can be updated instantly when | |
66 | // there is a change of data in the model |
|
66 | // there is a change of data in the model | |
67 | connect(variableModel, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)), this, |
|
67 | connect(variableModel, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)), this, | |
68 | SLOT(refresh())); |
|
68 | SLOT(refresh())); | |
69 |
|
69 | |||
70 | ui->tableView->setSelectionModel(sqpApp->variableController().variableSelectionModel()); |
|
70 | ui->tableView->setSelectionModel(sqpApp->variableController().variableSelectionModel()); | |
71 | ui->tableView->setItemDelegateForColumn(0, m_ProgressBarItemDelegate); |
|
71 | ui->tableView->setItemDelegateForColumn(0, m_ProgressBarItemDelegate); | |
72 |
|
72 | |||
73 | // Fixes column sizes |
|
73 | // Fixes column sizes | |
74 | auto model = ui->tableView->model(); |
|
74 | auto model = ui->tableView->model(); | |
75 | const auto count = model->columnCount(); |
|
75 | const auto count = model->columnCount(); | |
76 | for (auto i = 0; i < count; ++i) { |
|
76 | for (auto i = 0; i < count; ++i) { | |
77 | ui->tableView->setColumnWidth( |
|
77 | ui->tableView->setColumnWidth( | |
78 | i, model->headerData(i, Qt::Horizontal, Qt::SizeHintRole).toSize().width()); |
|
78 | i, model->headerData(i, Qt::Horizontal, Qt::SizeHintRole).toSize().width()); | |
79 | } |
|
79 | } | |
80 |
|
80 | |||
81 | // Sets selection options |
|
81 | // Sets selection options | |
82 | ui->tableView->setSelectionBehavior(QTableView::SelectRows); |
|
82 | ui->tableView->setSelectionBehavior(QTableView::SelectRows); | |
83 | ui->tableView->setSelectionMode(QTableView::ExtendedSelection); |
|
83 | ui->tableView->setSelectionMode(QTableView::ExtendedSelection); | |
84 |
|
84 | |||
85 | // Connection to show a menu when right clicking on the tree |
|
85 | // Connection to show a menu when right clicking on the tree | |
86 | ui->tableView->setContextMenuPolicy(Qt::CustomContextMenu); |
|
86 | ui->tableView->setContextMenuPolicy(Qt::CustomContextMenu); | |
87 | connect(ui->tableView, &QTableView::customContextMenuRequested, this, |
|
87 | connect(ui->tableView, &QTableView::customContextMenuRequested, this, | |
88 | &VariableInspectorWidget::onTableMenuRequested); |
|
88 | &VariableInspectorWidget::onTableMenuRequested); | |
89 | } |
|
89 | } | |
90 |
|
90 | |||
91 | VariableInspectorWidget::~VariableInspectorWidget() |
|
91 | VariableInspectorWidget::~VariableInspectorWidget() | |
92 | { |
|
92 | { | |
93 | delete ui; |
|
93 | delete ui; | |
94 | } |
|
94 | } | |
95 |
|
95 | |||
96 | void VariableInspectorWidget::onTableMenuRequested(const QPoint &pos) noexcept |
|
96 | void VariableInspectorWidget::onTableMenuRequested(const QPoint &pos) noexcept | |
97 | { |
|
97 | { | |
98 | auto selectedRows = ui->tableView->selectionModel()->selectedRows(); |
|
98 | auto selectedRows = ui->tableView->selectionModel()->selectedRows(); | |
99 |
|
99 | |||
100 | // Gets the model to retrieve the underlying selected variables |
|
100 | // Gets the model to retrieve the underlying selected variables | |
101 | auto model = sqpApp->variableController().variableModel(); |
|
101 | auto model = sqpApp->variableController().variableModel(); | |
102 | auto selectedVariables = QVector<std::shared_ptr<Variable> >{}; |
|
102 | auto selectedVariables = QVector<std::shared_ptr<Variable> >{}; | |
103 | for (const auto &selectedRow : qAsConst(selectedRows)) { |
|
103 | for (const auto &selectedRow : qAsConst(selectedRows)) { | |
104 | if (auto selectedVariable = model->variable(selectedRow.row())) { |
|
104 | if (auto selectedVariable = model->variable(selectedRow.row())) { | |
105 | selectedVariables.push_back(selectedVariable); |
|
105 | selectedVariables.push_back(selectedVariable); | |
106 | } |
|
106 | } | |
107 | } |
|
107 | } | |
108 |
|
108 | |||
109 | QMenu tableMenu{}; |
|
109 | QMenu tableMenu{}; | |
110 |
|
110 | |||
111 | // Emits a signal so that potential receivers can populate the menu before displaying it |
|
111 | // Emits a signal so that potential receivers can populate the menu before displaying it | |
112 | emit tableMenuAboutToBeDisplayed(&tableMenu, selectedVariables); |
|
112 | emit tableMenuAboutToBeDisplayed(&tableMenu, selectedVariables); | |
113 |
|
113 | |||
114 | // Adds menu-specific actions |
|
114 | // Adds menu-specific actions | |
115 | if (!selectedVariables.isEmpty()) { |
|
115 | if (!selectedVariables.isEmpty()) { | |
116 | // 'Delete' action |
|
116 | // 'Delete' action | |
117 | auto deleteFun = [&selectedVariables]() { |
|
117 | auto deleteFun = [&selectedVariables]() { | |
118 | sqpApp->variableController().deleteVariables(selectedVariables); |
|
118 | sqpApp->variableController().deleteVariables(selectedVariables); | |
119 | }; |
|
119 | }; | |
120 |
|
120 | |||
121 | tableMenu.addSeparator(); |
|
121 | tableMenu.addSeparator(); | |
122 | tableMenu.addAction(QIcon{":/icones/delete.png"}, tr("Delete"), deleteFun); |
|
122 | tableMenu.addAction(QIcon{":/icones/delete.png"}, tr("Delete"), deleteFun); | |
123 | } |
|
123 | } | |
124 |
|
124 | |||
125 | if (!tableMenu.isEmpty()) { |
|
125 | if (!tableMenu.isEmpty()) { | |
126 | // Generates menu header (inserted before first action) |
|
126 | // Generates menu header (inserted before first action) | |
127 | auto firstAction = tableMenu.actions().first(); |
|
127 | auto firstAction = tableMenu.actions().first(); | |
128 | auto headerAction = new QWidgetAction{&tableMenu}; |
|
128 | auto headerAction = new QWidgetAction{&tableMenu}; | |
129 | headerAction->setDefaultWidget(new VariableMenuHeaderWidget{selectedVariables, &tableMenu}); |
|
129 | headerAction->setDefaultWidget(new VariableMenuHeaderWidget{selectedVariables, &tableMenu}); | |
130 | tableMenu.insertAction(firstAction, headerAction); |
|
130 | tableMenu.insertAction(firstAction, headerAction); | |
131 |
|
131 | |||
132 | // Displays menu |
|
132 | // Displays menu | |
133 | tableMenu.exec(mapToGlobal(pos)); |
|
133 | tableMenu.exec(mapToGlobal(pos)); | |
134 | } |
|
134 | } | |
135 | } |
|
135 | } | |
136 |
|
136 | |||
137 | void VariableInspectorWidget::refresh() noexcept |
|
137 | void VariableInspectorWidget::refresh() noexcept | |
138 | { |
|
138 | { | |
139 | ui->tableView->viewport()->update(); |
|
139 | ui->tableView->viewport()->update(); | |
140 | } |
|
140 | } |
General Comments 2
Pull request updated. Auto status change to "Under Review"
Changed commits: * 1 added * 0 removed Changed files: * M core/include/Network/NetworkController.h * M core/include/Variable/VariableController.h * M core/include/Variable/VariableModel.h * M core/src/Network/NetworkController.cpp * M core/src/Variable/VariableController.cpp * M core/src/Variable/VariableModel.cpp * M gui/include/Variable/VariableInspectorWidget.h * M gui/src/SqpApplication.cpp * M gui/src/Variable/VariableInspectorWidget.cpp * M plugins/amda/src/AmdaResultParser.cpp * M plugins/amda/tests/TestAmdaResultParser.cpp * R COPYING * R app/src/MainWindow.cpp * R app/ui/MainWindow.ui * R cmake/sciqlop_package_qt.cmake * R core/include/Common/MetaTypes.h * R core/include/Data/ArrayData.h * R core/include/Data/DataProviderParameters.h * R core/include/Data/DataSeries.h * R core/include/Data/IDataProvider.h * R core/include/Data/IDataSeries.h * R core/include/Data/ScalarSeries.h * R core/include/Data/SqpDateTime.h * R core/include/DataSource/DataSourceItemAction.h * R core/include/Plugin/PluginManager.h * R core/include/Time/TimeController.h * R core/include/Variable/Variable.h * R core/include/Variable/VariableCacheController.h * R core/include/Visualization/VisualizationController.h * R core/src/Data/ScalarSeries.cpp * R core/src/DataSource/DataSourceItemAction.cpp * R core/src/Plugin/PluginManager.cpp * R core/src/Time/TimeController.cpp * R core/src/Variable/Variable.cpp * R core/src/Variable/VariableCacheController.cpp * R core/src/Visualization/VisualizationController.cpp * R core/tests/Variable/TestVariableCacheController.cpp * R gui/include/DataSource/DataSourceTreeWidgetItem.h * R gui/include/DataSource/DataSourceWidget.h * R gui/include/SidePane/SqpSidePane.h * R gui/include/TimeWidget/TimeWidget.h * R gui/include/Variable/VariableMenuHeaderWidget.h * R gui/include/Visualization/IVariableContainer.h * R gui/include/Visualization/IVisualizationWidget.h * R gui/include/Visualization/IVisualizationWidgetVisitor.h * R gui/include/Visualization/VisualizationGraphHelper.h * R gui/include/Visualization/VisualizationGraphWidget.h * R gui/include/Visualization/VisualizationTabWidget.h * R gui/include/Visualization/VisualizationWidget.h * R gui/include/Visualization/VisualizationZoneWidget.h * R gui/include/Visualization/operations/GenerateVariableMenuOperation.h * R gui/include/Visualization/operations/MenuBuilder.h * R gui/include/Visualization/operations/RemoveVariableOperation.h * R gui/include/Visualization/qcustomplot.h * R gui/resources/icones/dataSourceComponent.png * R gui/resources/icones/dataSourceNode.png * R gui/resources/icones/dataSourceProduct.png * R gui/resources/icones/dataSourceRoot.png * R gui/resources/icones/delete.png * R gui/resources/icones/next.png * R gui/resources/icones/openInspector.png * R gui/resources/icones/plot.png * R gui/resources/icones/previous.png * R gui/resources/icones/sciqlop2PNG_1024.png * R gui/resources/icones/unplot.png * R gui/resources/sqpguiresources.qrc * R gui/src/DataSource/DataSourceTreeWidgetItem.cpp * R gui/src/DataSource/DataSourceWidget.cpp * R gui/src/SidePane/SqpSidePane.cpp * R gui/src/TimeWidget/TimeWidget.cpp * R gui/src/Variable/VariableMenuHeaderWidget.cpp * R gui/src/Visualization/VisualizationGraphHelper.cpp * R gui/src/Visualization/VisualizationGraphWidget.cpp * R gui/src/Visualization/VisualizationTabWidget.cpp * R gui/src/Visualization/VisualizationWidget.cpp * R gui/src/Visualization/VisualizationZoneWidget.cpp * R gui/src/Visualization/operations/GenerateVariableMenuOperation.cpp * R gui/src/Visualization/operations/MenuBuilder.cpp * R gui/src/Visualization/operations/RemoveVariableOperation.cpp * R gui/src/Visualization/qcustomplot.cpp * R gui/ui/DataSource/DataSourceWidget.ui * R gui/ui/SidePane/SqpSidePane.ui * R gui/ui/TimeWidget/TimeWidget.ui * R gui/ui/Variable/VariableInspectorWidget.ui * R gui/ui/Variable/VariableMenuHeaderWidget.ui * R gui/ui/Visualization/VisualizationGraphWidget.ui * R gui/ui/Visualization/VisualizationTabWidget.ui * R gui/ui/Visualization/VisualizationWidget.ui * R gui/ui/Visualization/VisualizationZoneWidget.ui * R gui/vera-exclusions/exclusions.txt * R plugin/CMakeLists.txt * R plugin/cmake/Findsciqlop-plugin.cmake * R plugin/include/Plugin/IPlugin.h * R plugins/amda/CMakeLists.txt * R plugins/amda/cmake/Findsciqlop-amda.cmake * R plugins/amda/include/AmdaGlobal.h * R plugins/amda/include/AmdaParser.h * R plugins/amda/include/AmdaPlugin.h * R plugins/amda/include/AmdaProvider.h * R plugins/amda/include/AmdaResultParser.h * R plugins/amda/resources/amda.json * R plugins/amda/resources/amdaresources.qrc * R plugins/amda/resources/samples/AmdaSample.json * R plugins/amda/src/AmdaParser.cpp * R plugins/amda/src/AmdaPlugin.cpp * R plugins/amda/src/AmdaProvider.cpp * R plugins/amda/tests-resources/TestAmdaParser/TwoRootsFile.json * R plugins/amda/tests-resources/TestAmdaParser/ValidFile1.json * R plugins/amda/tests-resources/TestAmdaParser/WrongRootKey.json * R plugins/amda/tests-resources/TestAmdaParser/WrongRootType.json * R plugins/amda/tests-resources/TestAmdaResultParser/NaNValue.txt * R plugins/amda/tests-resources/TestAmdaResultParser/NoUnit.txt * R plugins/amda/tests-resources/TestAmdaResultParser/TooManyValues.txt * R plugins/amda/tests-resources/TestAmdaResultParser/ValidScalar1.txt * R plugins/amda/tests-resources/TestAmdaResultParser/WrongDate.txt * R plugins/amda/tests-resources/TestAmdaResultParser/WrongUnit.txt * R plugins/amda/tests-resources/TestAmdaResultParser/WrongValue.txt * R plugins/amda/tests/TestAmdaParser.cpp * R plugins/mockplugin/CMakeLists.txt * R plugins/mockplugin/cmake/Findsciqlop-mockplugin.cmake * R plugins/mockplugin/include/CosinusProvider.h * R plugins/mockplugin/include/MockPlugin.h * R plugins/mockplugin/include/MockPluginGlobal.h * R plugins/mockplugin/resources/mockplugin.json * R plugins/mockplugin/src/CosinusProvider.cpp * R plugins/mockplugin/src/MockPlugin.cpp * R README.md * R app/CMakeLists.txt * R app/include/MainWindow.h * R app/src/Main.cpp * R app/vera-exclusions/exclusions.txt * R cmake/sciqlop.cmake * R cmake/sciqlop_applications.cmake * R cmake/sciqlop_package.cmake * R cmake/sciqlop_params.cmake * R core/CMakeLists.txt * R core/include/Common/spimpl.h * R core/include/DataSource/DataSourceController.h * R core/include/DataSource/DataSourceItem.h * R core/src/DataSource/DataSourceController.cpp * R core/src/DataSource/DataSourceItem.cpp * R core/tests/DataSource/TestDataSourceController.cpp * R core/vera-exclusions/exclusions.txt * R formatting/cmake/use_clangformat.cmake * R formatting/vera-exclusions/exclusions.txt * R gui/CMakeLists.txt * R gui/include/SqpApplication.h * R LICENSE * R app/src/mainwindow.cpp * R app/src/mainwindow.ui
You need to be logged in to leave comments.
Login now