Auto status change to "Under Review"
@@ -1,51 +1,49 | |||||
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/spimpl.h> |
|
10 | #include <Common/spimpl.h> | |
11 |
|
11 | |||
12 | Q_DECLARE_LOGGING_CATEGORY(LOG_VariableModel) |
|
12 | Q_DECLARE_LOGGING_CATEGORY(LOG_VariableModel) | |
13 |
|
13 | |||
14 | class IDataSeries; |
|
14 | class IDataSeries; | |
15 | class Variable; |
|
15 | class Variable; | |
16 |
|
16 | |||
17 | /** |
|
17 | /** | |
18 | * @brief The VariableModel class aims to hold the variables that have been created in SciQlop |
|
18 | * @brief The VariableModel class aims to hold the variables that have been created in SciQlop | |
19 | */ |
|
19 | */ | |
20 | class VariableModel : public QAbstractTableModel { |
|
20 | class VariableModel : public QAbstractTableModel { | |
21 | public: |
|
21 | public: | |
22 | explicit VariableModel(QObject *parent = nullptr); |
|
22 | explicit VariableModel(QObject *parent = nullptr); | |
23 |
|
23 | |||
24 | /** |
|
24 | /** | |
25 | * Creates a new variable in the model |
|
25 | * Creates a new variable in the model | |
26 | * @param name the name of the new variable |
|
26 | * @param name the name of the new variable | |
27 | * @param dateTime the dateTime of the new variable |
|
27 | * @param dateTime the dateTime of the new variable | |
28 | * @param defaultDataSeries the default data of the new variable |
|
|||
29 | * @return the pointer to the new variable |
|
28 | * @return the pointer to the new variable | |
30 | */ |
|
29 | */ | |
31 | std::shared_ptr<Variable> |
|
30 | std::shared_ptr<Variable> createVariable(const QString &name, | |
32 | createVariable(const QString &name, const SqpDateTime &dateTime, |
|
31 | const SqpDateTime &dateTime) noexcept; | |
33 | std::shared_ptr<IDataSeries> defaultDataSeries) noexcept; |
|
|||
34 |
|
32 | |||
35 | std::shared_ptr<Variable> variable(int index) const; |
|
33 | std::shared_ptr<Variable> variable(int index) const; | |
36 |
|
34 | |||
37 | // /////////////////////////// // |
|
35 | // /////////////////////////// // | |
38 | // QAbstractTableModel methods // |
|
36 | // QAbstractTableModel methods // | |
39 | // /////////////////////////// // |
|
37 | // /////////////////////////// // | |
40 | virtual int columnCount(const QModelIndex &parent = QModelIndex{}) const override; |
|
38 | virtual int columnCount(const QModelIndex &parent = QModelIndex{}) const override; | |
41 | virtual int rowCount(const QModelIndex &parent = QModelIndex{}) const override; |
|
39 | virtual int rowCount(const QModelIndex &parent = QModelIndex{}) const override; | |
42 | virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; |
|
40 | virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; | |
43 | virtual QVariant headerData(int section, Qt::Orientation orientation, |
|
41 | virtual QVariant headerData(int section, Qt::Orientation orientation, | |
44 | int role = Qt::DisplayRole) const override; |
|
42 | int role = Qt::DisplayRole) const override; | |
45 |
|
43 | |||
46 | private: |
|
44 | private: | |
47 | class VariableModelPrivate; |
|
45 | class VariableModelPrivate; | |
48 | spimpl::unique_impl_ptr<VariableModelPrivate> impl; |
|
46 | spimpl::unique_impl_ptr<VariableModelPrivate> impl; | |
49 | }; |
|
47 | }; | |
50 |
|
48 | |||
51 | #endif // SCIQLOP_VARIABLEMODEL_H |
|
49 | #endif // SCIQLOP_VARIABLEMODEL_H |
@@ -1,205 +1,204 | |||||
1 | #include "Variable/VariableCacheController.h" |
|
1 | #include "Variable/VariableCacheController.h" | |
2 |
|
2 | |||
3 | #include "Variable/Variable.h" |
|
3 | #include "Variable/Variable.h" | |
4 | #include <unordered_map> |
|
4 | #include <unordered_map> | |
5 |
|
5 | |||
6 | Q_LOGGING_CATEGORY(LOG_VariableCacheController, "VariableCacheController") |
|
6 | Q_LOGGING_CATEGORY(LOG_VariableCacheController, "VariableCacheController") | |
7 |
|
7 | |||
8 | struct VariableCacheController::VariableCacheControllerPrivate { |
|
8 | struct VariableCacheController::VariableCacheControllerPrivate { | |
9 |
|
9 | |||
10 | std::unordered_map<std::shared_ptr<Variable>, QVector<SqpDateTime> > |
|
10 | std::unordered_map<std::shared_ptr<Variable>, QVector<SqpDateTime> > | |
11 | m_VariableToSqpDateTimeListMap; |
|
11 | m_VariableToSqpDateTimeListMap; | |
12 |
|
12 | |||
13 | void addInCacheDataByEnd(const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList, |
|
13 | void addInCacheDataByEnd(const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList, | |
14 | QVector<SqpDateTime> ¬InCache, int cacheIndex, |
|
14 | QVector<SqpDateTime> ¬InCache, int cacheIndex, | |
15 | double currentTStart); |
|
15 | double currentTStart); | |
16 |
|
16 | |||
17 | void addInCacheDataByStart(const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList, |
|
17 | void addInCacheDataByStart(const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList, | |
18 | QVector<SqpDateTime> ¬InCache, int cacheIndex, |
|
18 | QVector<SqpDateTime> ¬InCache, int cacheIndex, | |
19 | double currentTStart); |
|
19 | double currentTStart); | |
20 |
|
20 | |||
21 |
|
21 | |||
22 | void addDateTimeRecurse(const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList, |
|
22 | void addDateTimeRecurse(const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList, | |
23 | int cacheIndex); |
|
23 | int cacheIndex); | |
24 | }; |
|
24 | }; | |
25 |
|
25 | |||
26 |
|
26 | |||
27 | VariableCacheController::VariableCacheController(QObject *parent) |
|
27 | VariableCacheController::VariableCacheController(QObject *parent) | |
28 | : QObject{parent}, impl{spimpl::make_unique_impl<VariableCacheControllerPrivate>()} |
|
28 | : QObject{parent}, impl{spimpl::make_unique_impl<VariableCacheControllerPrivate>()} | |
29 | { |
|
29 | { | |
30 | } |
|
30 | } | |
31 |
|
31 | |||
32 | void VariableCacheController::addDateTime(std::shared_ptr<Variable> variable, |
|
32 | void VariableCacheController::addDateTime(std::shared_ptr<Variable> variable, | |
33 | const SqpDateTime &dateTime) |
|
33 | const SqpDateTime &dateTime) | |
34 | { |
|
34 | { | |
35 | if (variable) { |
|
35 | if (variable) { | |
36 | auto findVariableIte = impl->m_VariableToSqpDateTimeListMap.find(variable); |
|
36 | auto findVariableIte = impl->m_VariableToSqpDateTimeListMap.find(variable); | |
37 | if (findVariableIte == impl->m_VariableToSqpDateTimeListMap.end()) { |
|
37 | if (findVariableIte == impl->m_VariableToSqpDateTimeListMap.end()) { | |
38 | impl->m_VariableToSqpDateTimeListMap[variable].push_back(dateTime); |
|
38 | impl->m_VariableToSqpDateTimeListMap[variable].push_back(dateTime); | |
39 | } |
|
39 | } | |
40 | else { |
|
40 | else { | |
41 |
|
41 | |||
42 | // addDateTime modify the list<SqpDateTime> of the variable in a way to ensure |
|
42 | // addDateTime modify the list<SqpDateTime> of the variable in a way to ensure | |
43 | // that the list is ordered : l(0) < l(1). We assume also a < b |
|
43 | // that the list is ordered : l(0) < l(1). We assume also a < b | |
44 | // (with a & b of type SqpDateTime) means ts(b) > te(a) |
|
44 | // (with a & b of type SqpDateTime) means ts(b) > te(a) | |
45 |
|
45 | |||
46 | // The algorithm will try the merge of two interval: |
|
46 | // The algorithm will try the merge of two interval: | |
47 | // - dateTime will be compare with the first interval of the list: |
|
47 | // - dateTime will be compare with the first interval of the list: | |
48 | // A: if it is inferior, it will be inserted and it's finished. |
|
48 | // A: if it is inferior, it will be inserted and it's finished. | |
49 | // B: if it is in intersection, it will be merge then the merged one |
|
49 | // B: if it is in intersection, it will be merge then the merged one | |
50 | // will be compared to the next interval. The old one is remove from the list |
|
50 | // will be compared to the next interval. The old one is remove from the list | |
51 | // C: if it is superior, we do the same with the next interval of the list |
|
51 | // C: if it is superior, we do the same with the next interval of the list | |
52 |
|
52 | |||
53 | try { |
|
53 | try { | |
54 | impl->addDateTimeRecurse(dateTime, |
|
54 | impl->addDateTimeRecurse(dateTime, | |
55 | impl->m_VariableToSqpDateTimeListMap.at(variable), 0); |
|
55 | impl->m_VariableToSqpDateTimeListMap.at(variable), 0); | |
56 | } |
|
56 | } | |
57 | catch (const std::out_of_range &e) { |
|
57 | catch (const std::out_of_range &e) { | |
58 | qCWarning(LOG_VariableCacheController()) << e.what(); |
|
58 | qCWarning(LOG_VariableCacheController()) << "addDateTime" << e.what(); | |
59 | } |
|
59 | } | |
60 | } |
|
60 | } | |
61 | } |
|
61 | } | |
62 | } |
|
62 | } | |
63 |
|
63 | |||
64 | QVector<SqpDateTime> |
|
64 | QVector<SqpDateTime> | |
65 | VariableCacheController::provideNotInCacheDateTimeList(std::shared_ptr<Variable> variable, |
|
65 | VariableCacheController::provideNotInCacheDateTimeList(std::shared_ptr<Variable> variable, | |
66 | const SqpDateTime &dateTime) |
|
66 | const SqpDateTime &dateTime) | |
67 | { |
|
67 | { | |
68 | auto notInCache = QVector<SqpDateTime>{}; |
|
68 | auto notInCache = QVector<SqpDateTime>{}; | |
69 |
|
69 | |||
70 | // This algorithm is recursif. The idea is to localise the start time then the end time in the |
|
70 | // This algorithm is recursif. The idea is to localise the start time then the end time in the | |
71 | // list of date time request associated to the variable |
|
71 | // list of date time request associated to the variable | |
72 | // We assume that the list is ordered in a way that l(0) < l(1). We assume also a < b |
|
72 | // We assume that the list is ordered in a way that l(0) < l(1). We assume also a < b | |
73 | // (with a & b of type SqpDateTime) means ts(b) > te(a) |
|
73 | // (with a & b of type SqpDateTime) means ts(b) > te(a) | |
74 |
|
74 | auto it = impl->m_VariableToSqpDateTimeListMap.find(variable); | ||
75 | try { |
|
75 | if (it != impl->m_VariableToSqpDateTimeListMap.end()) { | |
76 |
impl->addInCacheDataByStart(dateTime, i |
|
76 | impl->addInCacheDataByStart(dateTime, it->second, notInCache, 0, dateTime.m_TStart); | |
77 | notInCache, 0, dateTime.m_TStart); |
|
|||
78 | } |
|
77 | } | |
79 | catch (const std::out_of_range &e) { |
|
78 | else { | |
80 | qCWarning(LOG_VariableCacheController()) << e.what(); |
|
79 | notInCache << dateTime; | |
81 | } |
|
80 | } | |
82 |
|
81 | |||
83 | return notInCache; |
|
82 | return notInCache; | |
84 | } |
|
83 | } | |
85 |
|
84 | |||
86 | QVector<SqpDateTime> |
|
85 | QVector<SqpDateTime> | |
87 | VariableCacheController::dateCacheList(std::shared_ptr<Variable> variable) const noexcept |
|
86 | VariableCacheController::dateCacheList(std::shared_ptr<Variable> variable) const noexcept | |
88 | { |
|
87 | { | |
89 | try { |
|
88 | try { | |
90 | return impl->m_VariableToSqpDateTimeListMap.at(variable); |
|
89 | return impl->m_VariableToSqpDateTimeListMap.at(variable); | |
91 | } |
|
90 | } | |
92 | catch (const std::out_of_range &e) { |
|
91 | catch (const std::out_of_range &e) { | |
93 | qCWarning(LOG_VariableCacheController()) << e.what(); |
|
92 | qCWarning(LOG_VariableCacheController()) << e.what(); | |
94 | return QVector<SqpDateTime>{}; |
|
93 | return QVector<SqpDateTime>{}; | |
95 | } |
|
94 | } | |
96 | } |
|
95 | } | |
97 |
|
96 | |||
98 | void VariableCacheController::VariableCacheControllerPrivate::addDateTimeRecurse( |
|
97 | void VariableCacheController::VariableCacheControllerPrivate::addDateTimeRecurse( | |
99 | const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList, int cacheIndex) |
|
98 | const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList, int cacheIndex) | |
100 | { |
|
99 | { | |
101 | const auto dateTimeListSize = dateTimeList.count(); |
|
100 | const auto dateTimeListSize = dateTimeList.count(); | |
102 | if (cacheIndex >= dateTimeListSize) { |
|
101 | if (cacheIndex >= dateTimeListSize) { | |
103 | dateTimeList.push_back(dateTime); |
|
102 | dateTimeList.push_back(dateTime); | |
104 | // there is no anymore interval to compore, we can just push_back it |
|
103 | // there is no anymore interval to compore, we can just push_back it | |
105 | return; |
|
104 | return; | |
106 | } |
|
105 | } | |
107 |
|
106 | |||
108 | auto currentDateTime = dateTimeList[cacheIndex]; |
|
107 | auto currentDateTime = dateTimeList[cacheIndex]; | |
109 |
|
108 | |||
110 | if (dateTime.m_TEnd < currentDateTime.m_TStart) { |
|
109 | if (dateTime.m_TEnd < currentDateTime.m_TStart) { | |
111 | // The compared one is < to current one compared, we can insert it |
|
110 | // The compared one is < to current one compared, we can insert it | |
112 | dateTimeList.insert(cacheIndex, dateTime); |
|
111 | dateTimeList.insert(cacheIndex, dateTime); | |
113 | } |
|
112 | } | |
114 | else if (dateTime.m_TStart > currentDateTime.m_TEnd) { |
|
113 | else if (dateTime.m_TStart > currentDateTime.m_TEnd) { | |
115 | // The compared one is > to current one compared we can comparet if to the next one |
|
114 | // The compared one is > to current one compared we can comparet if to the next one | |
116 | addDateTimeRecurse(dateTime, dateTimeList, ++cacheIndex); |
|
115 | addDateTimeRecurse(dateTime, dateTimeList, ++cacheIndex); | |
117 | } |
|
116 | } | |
118 | else { |
|
117 | else { | |
119 | // Merge cases: we need to merge the two interval, remove the old one from the list then |
|
118 | // Merge cases: we need to merge the two interval, remove the old one from the list then | |
120 | // rerun the algo from this index with the merged interval |
|
119 | // rerun the algo from this index with the merged interval | |
121 | auto mTStart = std::min(dateTime.m_TStart, currentDateTime.m_TStart); |
|
120 | auto mTStart = std::min(dateTime.m_TStart, currentDateTime.m_TStart); | |
122 | auto mTEnd = std::max(dateTime.m_TEnd, currentDateTime.m_TEnd); |
|
121 | auto mTEnd = std::max(dateTime.m_TEnd, currentDateTime.m_TEnd); | |
123 | auto mergeDateTime = SqpDateTime{mTStart, mTEnd}; |
|
122 | auto mergeDateTime = SqpDateTime{mTStart, mTEnd}; | |
124 |
|
123 | |||
125 | dateTimeList.remove(cacheIndex); |
|
124 | dateTimeList.remove(cacheIndex); | |
126 | addDateTimeRecurse(mergeDateTime, dateTimeList, cacheIndex); |
|
125 | addDateTimeRecurse(mergeDateTime, dateTimeList, cacheIndex); | |
127 | } |
|
126 | } | |
128 | } |
|
127 | } | |
129 |
|
128 | |||
130 |
|
129 | |||
131 | void VariableCacheController::VariableCacheControllerPrivate::addInCacheDataByEnd( |
|
130 | void VariableCacheController::VariableCacheControllerPrivate::addInCacheDataByEnd( | |
132 | const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList, |
|
131 | const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList, | |
133 | QVector<SqpDateTime> ¬InCache, int cacheIndex, double currentTStart) |
|
132 | QVector<SqpDateTime> ¬InCache, int cacheIndex, double currentTStart) | |
134 | { |
|
133 | { | |
135 | const auto dateTimeListSize = dateTimeList.count(); |
|
134 | const auto dateTimeListSize = dateTimeList.count(); | |
136 | if (cacheIndex >= dateTimeListSize) { |
|
135 | if (cacheIndex >= dateTimeListSize) { | |
137 | if (currentTStart < dateTime.m_TEnd) { |
|
136 | if (currentTStart < dateTime.m_TEnd) { | |
138 |
|
137 | |||
139 | // te localised after all other interval: The last interval is [currentTsart, te] |
|
138 | // te localised after all other interval: The last interval is [currentTsart, te] | |
140 | notInCache.push_back(SqpDateTime{currentTStart, dateTime.m_TEnd}); |
|
139 | notInCache.push_back(SqpDateTime{currentTStart, dateTime.m_TEnd}); | |
141 | } |
|
140 | } | |
142 | return; |
|
141 | return; | |
143 | } |
|
142 | } | |
144 |
|
143 | |||
145 | auto currentDateTimeJ = dateTimeList[cacheIndex]; |
|
144 | auto currentDateTimeJ = dateTimeList[cacheIndex]; | |
146 | if (dateTime.m_TEnd <= currentDateTimeJ.m_TStart) { |
|
145 | if (dateTime.m_TEnd <= currentDateTimeJ.m_TStart) { | |
147 | // te localised between to interval: The last interval is [currentTsart, te] |
|
146 | // te localised between to interval: The last interval is [currentTsart, te] | |
148 | notInCache.push_back(SqpDateTime{currentTStart, dateTime.m_TEnd}); |
|
147 | notInCache.push_back(SqpDateTime{currentTStart, dateTime.m_TEnd}); | |
149 | } |
|
148 | } | |
150 | else { |
|
149 | else { | |
151 | notInCache.push_back(SqpDateTime{currentTStart, currentDateTimeJ.m_TStart}); |
|
150 | notInCache.push_back(SqpDateTime{currentTStart, currentDateTimeJ.m_TStart}); | |
152 | if (dateTime.m_TEnd > currentDateTimeJ.m_TEnd) { |
|
151 | if (dateTime.m_TEnd > currentDateTimeJ.m_TEnd) { | |
153 | // te not localised before the current interval: we need to look at the next interval |
|
152 | // te not localised before the current interval: we need to look at the next interval | |
154 | addInCacheDataByEnd(dateTime, dateTimeList, notInCache, ++cacheIndex, |
|
153 | addInCacheDataByEnd(dateTime, dateTimeList, notInCache, ++cacheIndex, | |
155 | currentDateTimeJ.m_TEnd); |
|
154 | currentDateTimeJ.m_TEnd); | |
156 | } |
|
155 | } | |
157 | } |
|
156 | } | |
158 | } |
|
157 | } | |
159 |
|
158 | |||
160 | void VariableCacheController::VariableCacheControllerPrivate::addInCacheDataByStart( |
|
159 | void VariableCacheController::VariableCacheControllerPrivate::addInCacheDataByStart( | |
161 | const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList, |
|
160 | const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList, | |
162 | QVector<SqpDateTime> ¬InCache, int cacheIndex, double currentTStart) |
|
161 | QVector<SqpDateTime> ¬InCache, int cacheIndex, double currentTStart) | |
163 | { |
|
162 | { | |
164 | const auto dateTimeListSize = dateTimeList.count(); |
|
163 | const auto dateTimeListSize = dateTimeList.count(); | |
165 | if (cacheIndex >= dateTimeListSize) { |
|
164 | if (cacheIndex >= dateTimeListSize) { | |
166 | // ts localised after all other interval: The last interval is [ts, te] |
|
165 | // ts localised after all other interval: The last interval is [ts, te] | |
167 | notInCache.push_back(SqpDateTime{currentTStart, dateTime.m_TEnd}); |
|
166 | notInCache.push_back(SqpDateTime{currentTStart, dateTime.m_TEnd}); | |
168 | return; |
|
167 | return; | |
169 | } |
|
168 | } | |
170 |
|
169 | |||
171 | auto currentDateTimeI = dateTimeList[cacheIndex]; |
|
170 | auto currentDateTimeI = dateTimeList[cacheIndex]; | |
172 | if (currentTStart < currentDateTimeI.m_TStart) { |
|
171 | if (currentTStart < currentDateTimeI.m_TStart) { | |
173 |
|
172 | |||
174 | // ts localised between to interval: let's localized te |
|
173 | // ts localised between to interval: let's localized te | |
175 | addInCacheDataByEnd(dateTime, dateTimeList, notInCache, cacheIndex, currentTStart); |
|
174 | addInCacheDataByEnd(dateTime, dateTimeList, notInCache, cacheIndex, currentTStart); | |
176 | } |
|
175 | } | |
177 | else if (currentTStart < currentDateTimeI.m_TEnd) { |
|
176 | else if (currentTStart < currentDateTimeI.m_TEnd) { | |
178 | if (dateTime.m_TEnd > currentDateTimeI.m_TEnd) { |
|
177 | if (dateTime.m_TEnd > currentDateTimeI.m_TEnd) { | |
179 | // ts not localised before the current interval: we need to look at the next interval |
|
178 | // ts not localised before the current interval: we need to look at the next interval | |
180 | // We can assume now current tstart is the last interval tend, because data between them |
|
179 | // We can assume now current tstart is the last interval tend, because data between them | |
181 | // are |
|
180 | // are | |
182 | // in the cache |
|
181 | // in the cache | |
183 | addInCacheDataByStart(dateTime, dateTimeList, notInCache, ++cacheIndex, |
|
182 | addInCacheDataByStart(dateTime, dateTimeList, notInCache, ++cacheIndex, | |
184 | currentDateTimeI.m_TEnd); |
|
183 | currentDateTimeI.m_TEnd); | |
185 | } |
|
184 | } | |
186 | } |
|
185 | } | |
187 | else { |
|
186 | else { | |
188 | // ts not localised before the current interval: we need to look at the next interval |
|
187 | // ts not localised before the current interval: we need to look at the next interval | |
189 | addInCacheDataByStart(dateTime, dateTimeList, notInCache, ++cacheIndex, currentTStart); |
|
188 | addInCacheDataByStart(dateTime, dateTimeList, notInCache, ++cacheIndex, currentTStart); | |
190 | } |
|
189 | } | |
191 | } |
|
190 | } | |
192 |
|
191 | |||
193 |
|
192 | |||
194 | void VariableCacheController::displayCache(std::shared_ptr<Variable> variable) const |
|
193 | void VariableCacheController::displayCache(std::shared_ptr<Variable> variable) const | |
195 | { |
|
194 | { | |
196 | auto variableDateTimeList = impl->m_VariableToSqpDateTimeListMap.find(variable); |
|
195 | auto variableDateTimeList = impl->m_VariableToSqpDateTimeListMap.find(variable); | |
197 | if (variableDateTimeList != impl->m_VariableToSqpDateTimeListMap.end()) { |
|
196 | if (variableDateTimeList != impl->m_VariableToSqpDateTimeListMap.end()) { | |
198 | qCInfo(LOG_VariableCacheController()) << tr("VariableCacheController::displayCache") |
|
197 | qCInfo(LOG_VariableCacheController()) << tr("VariableCacheController::displayCache") | |
199 | << variableDateTimeList->second; |
|
198 | << variableDateTimeList->second; | |
200 | } |
|
199 | } | |
201 | else { |
|
200 | else { | |
202 | qCWarning(LOG_VariableCacheController()) |
|
201 | qCWarning(LOG_VariableCacheController()) | |
203 | << tr("Cannot display a variable that is not in the cache"); |
|
202 | << tr("Cannot display a variable that is not in the cache"); | |
204 | } |
|
203 | } | |
205 | } |
|
204 | } |
@@ -1,181 +1,177 | |||||
1 | #include <Variable/Variable.h> |
|
1 | #include <Variable/Variable.h> | |
2 | #include <Variable/VariableCacheController.h> |
|
2 | #include <Variable/VariableCacheController.h> | |
3 | #include <Variable/VariableController.h> |
|
3 | #include <Variable/VariableController.h> | |
4 | #include <Variable/VariableModel.h> |
|
4 | #include <Variable/VariableModel.h> | |
5 |
|
5 | |||
6 | #include <Data/DataProviderParameters.h> |
|
6 | #include <Data/DataProviderParameters.h> | |
7 | #include <Data/IDataProvider.h> |
|
7 | #include <Data/IDataProvider.h> | |
8 | #include <Data/IDataSeries.h> |
|
8 | #include <Data/IDataSeries.h> | |
9 | #include <Time/TimeController.h> |
|
9 | #include <Time/TimeController.h> | |
10 |
|
10 | |||
11 | #include <QDateTime> |
|
11 | #include <QDateTime> | |
12 | #include <QMutex> |
|
12 | #include <QMutex> | |
13 | #include <QThread> |
|
13 | #include <QThread> | |
14 | #include <QtCore/QItemSelectionModel> |
|
14 | #include <QtCore/QItemSelectionModel> | |
15 |
|
15 | |||
16 | #include <unordered_map> |
|
16 | #include <unordered_map> | |
17 |
|
17 | |||
18 | Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController") |
|
18 | Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController") | |
19 |
|
19 | |||
20 | namespace { |
|
20 | namespace { | |
21 |
|
21 | |||
22 | /// @todo Generates default dataseries, according to the provider passed in parameter. This method |
|
22 | /// @todo Generates default dataseries, according to the provider passed in parameter. This method | |
23 | /// will be deleted when the timerange is recovered from SciQlop |
|
23 | /// will be deleted when the timerange is recovered from SciQlop | |
24 | std::shared_ptr<IDataSeries> generateDefaultDataSeries(const IDataProvider &provider, |
|
24 | std::shared_ptr<IDataSeries> generateDefaultDataSeries(const IDataProvider &provider, | |
25 | const SqpDateTime &dateTime) noexcept |
|
25 | const SqpDateTime &dateTime) noexcept | |
26 | { |
|
26 | { | |
27 | auto parameters = DataProviderParameters{dateTime}; |
|
27 | auto parameters = DataProviderParameters{dateTime}; | |
28 |
|
28 | |||
29 | return provider.retrieveData(parameters); |
|
29 | return provider.retrieveData(parameters); | |
30 | } |
|
30 | } | |
31 |
|
31 | |||
32 | } // namespace |
|
32 | } // namespace | |
33 |
|
33 | |||
34 | struct VariableController::VariableControllerPrivate { |
|
34 | struct VariableController::VariableControllerPrivate { | |
35 | explicit VariableControllerPrivate(VariableController *parent) |
|
35 | explicit VariableControllerPrivate(VariableController *parent) | |
36 | : m_WorkingMutex{}, |
|
36 | : m_WorkingMutex{}, | |
37 | m_VariableModel{new VariableModel{parent}}, |
|
37 | m_VariableModel{new VariableModel{parent}}, | |
38 | m_VariableSelectionModel{new QItemSelectionModel{m_VariableModel, parent}}, |
|
38 | m_VariableSelectionModel{new QItemSelectionModel{m_VariableModel, parent}}, | |
39 | m_VariableCacheController{std::make_unique<VariableCacheController>()} |
|
39 | m_VariableCacheController{std::make_unique<VariableCacheController>()} | |
40 | { |
|
40 | { | |
41 | } |
|
41 | } | |
42 |
|
42 | |||
43 | QMutex m_WorkingMutex; |
|
43 | QMutex m_WorkingMutex; | |
44 | /// Variable model. The VariableController has the ownership |
|
44 | /// Variable model. The VariableController has the ownership | |
45 | VariableModel *m_VariableModel; |
|
45 | VariableModel *m_VariableModel; | |
46 | QItemSelectionModel *m_VariableSelectionModel; |
|
46 | QItemSelectionModel *m_VariableSelectionModel; | |
47 |
|
47 | |||
48 |
|
48 | |||
49 | TimeController *m_TimeController{nullptr}; |
|
49 | TimeController *m_TimeController{nullptr}; | |
50 | std::unique_ptr<VariableCacheController> m_VariableCacheController; |
|
50 | std::unique_ptr<VariableCacheController> m_VariableCacheController; | |
51 |
|
51 | |||
52 | std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> > |
|
52 | std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> > | |
53 | m_VariableToProviderMap; |
|
53 | m_VariableToProviderMap; | |
54 | }; |
|
54 | }; | |
55 |
|
55 | |||
56 | VariableController::VariableController(QObject *parent) |
|
56 | VariableController::VariableController(QObject *parent) | |
57 | : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)} |
|
57 | : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)} | |
58 | { |
|
58 | { | |
59 | qCDebug(LOG_VariableController()) << tr("VariableController construction") |
|
59 | qCDebug(LOG_VariableController()) << tr("VariableController construction") | |
60 | << QThread::currentThread(); |
|
60 | << QThread::currentThread(); | |
61 | } |
|
61 | } | |
62 |
|
62 | |||
63 | VariableController::~VariableController() |
|
63 | VariableController::~VariableController() | |
64 | { |
|
64 | { | |
65 | qCDebug(LOG_VariableController()) << tr("VariableController destruction") |
|
65 | qCDebug(LOG_VariableController()) << tr("VariableController destruction") | |
66 | << QThread::currentThread(); |
|
66 | << QThread::currentThread(); | |
67 | this->waitForFinish(); |
|
67 | this->waitForFinish(); | |
68 | } |
|
68 | } | |
69 |
|
69 | |||
70 | VariableModel *VariableController::variableModel() noexcept |
|
70 | VariableModel *VariableController::variableModel() noexcept | |
71 | { |
|
71 | { | |
72 | return impl->m_VariableModel; |
|
72 | return impl->m_VariableModel; | |
73 | } |
|
73 | } | |
74 |
|
74 | |||
75 | QItemSelectionModel *VariableController::variableSelectionModel() noexcept |
|
75 | QItemSelectionModel *VariableController::variableSelectionModel() noexcept | |
76 | { |
|
76 | { | |
77 | return impl->m_VariableSelectionModel; |
|
77 | return impl->m_VariableSelectionModel; | |
78 | } |
|
78 | } | |
79 |
|
79 | |||
80 | void VariableController::setTimeController(TimeController *timeController) noexcept |
|
80 | void VariableController::setTimeController(TimeController *timeController) noexcept | |
81 | { |
|
81 | { | |
82 | impl->m_TimeController = timeController; |
|
82 | impl->m_TimeController = timeController; | |
83 | } |
|
83 | } | |
84 |
|
84 | |||
85 | void VariableController::createVariable(const QString &name, |
|
85 | void VariableController::createVariable(const QString &name, | |
86 | std::shared_ptr<IDataProvider> provider) noexcept |
|
86 | std::shared_ptr<IDataProvider> provider) noexcept | |
87 | { |
|
87 | { | |
88 |
|
88 | |||
89 | if (!impl->m_TimeController) { |
|
89 | if (!impl->m_TimeController) { | |
90 | qCCritical(LOG_VariableController()) |
|
90 | qCCritical(LOG_VariableController()) | |
91 | << tr("Impossible to create variable: The time controller is null"); |
|
91 | << tr("Impossible to create variable: The time controller is null"); | |
92 | return; |
|
92 | return; | |
93 | } |
|
93 | } | |
94 |
|
94 | |||
95 |
|
95 | |||
96 | /// @todo : for the moment : |
|
96 | /// @todo : for the moment : | |
97 | /// - the provider is only used to retrieve data from the variable for its initialization, but |
|
97 | /// - the provider is only used to retrieve data from the variable for its initialization, but | |
98 | /// it will be retained later |
|
98 | /// it will be retained later | |
99 | /// - default data are generated for the variable, without taking into account the timerange set |
|
99 | /// - default data are generated for the variable, without taking into account the timerange set | |
100 | /// in sciqlop |
|
100 | /// in sciqlop | |
101 | auto dateTime = impl->m_TimeController->dateTime(); |
|
101 | auto dateTime = impl->m_TimeController->dateTime(); | |
102 | if (auto newVariable = impl->m_VariableModel->createVariable( |
|
102 | if (auto newVariable = impl->m_VariableModel->createVariable(name, dateTime)) { | |
103 | name, dateTime, generateDefaultDataSeries(*provider, dateTime))) { |
|
|||
104 |
|
103 | |||
105 | // store the provider |
|
104 | // store the provider | |
106 | impl->m_VariableToProviderMap[newVariable] = provider; |
|
105 | impl->m_VariableToProviderMap[newVariable] = provider; | |
107 |
|
106 | |||
108 | auto addDateTimeAcquired |
|
107 | auto addDateTimeAcquired | |
109 | = [this, newVariable](auto dataSeriesAcquired, auto dateTimeToPutInCache) { |
|
108 | = [this, newVariable](auto dataSeriesAcquired, auto dateTimeToPutInCache) { | |
110 |
|
109 | |||
111 | impl->m_VariableCacheController->addDateTime(newVariable, dateTimeToPutInCache); |
|
110 | impl->m_VariableCacheController->addDateTime(newVariable, dateTimeToPutInCache); | |
112 | newVariable->setDataSeries(dataSeriesAcquired); |
|
111 | newVariable->setDataSeries(dataSeriesAcquired); | |
113 |
|
112 | |||
114 | }; |
|
113 | }; | |
115 |
|
114 | |||
116 | connect(provider.get(), &IDataProvider::dataProvided, addDateTimeAcquired); |
|
115 | connect(provider.get(), &IDataProvider::dataProvided, addDateTimeAcquired); | |
117 |
|
116 | this->onRequestDataLoading(newVariable, dateTime); | ||
118 |
|
||||
119 | // store in cache |
|
|||
120 | impl->m_VariableCacheController->addDateTime(newVariable, dateTime); |
|
|||
121 |
|
117 | |||
122 | // notify the creation |
|
118 | // notify the creation | |
123 | emit variableCreated(newVariable); |
|
119 | emit variableCreated(newVariable); | |
124 | } |
|
120 | } | |
125 | } |
|
121 | } | |
126 |
|
122 | |||
127 | void VariableController::onDateTimeOnSelection(const SqpDateTime &dateTime) |
|
123 | void VariableController::onDateTimeOnSelection(const SqpDateTime &dateTime) | |
128 | { |
|
124 | { | |
129 | auto selectedRows = impl->m_VariableSelectionModel->selectedRows(); |
|
125 | auto selectedRows = impl->m_VariableSelectionModel->selectedRows(); | |
130 |
|
126 | |||
131 | for (const auto &selectedRow : qAsConst(selectedRows)) { |
|
127 | for (const auto &selectedRow : qAsConst(selectedRows)) { | |
132 | if (auto selectedVariable = impl->m_VariableModel->variable(selectedRow.row())) { |
|
128 | if (auto selectedVariable = impl->m_VariableModel->variable(selectedRow.row())) { | |
133 | selectedVariable->setDateTime(dateTime); |
|
129 | selectedVariable->setDateTime(dateTime); | |
134 | this->onRequestDataLoading(selectedVariable, dateTime); |
|
130 | this->onRequestDataLoading(selectedVariable, dateTime); | |
135 | } |
|
131 | } | |
136 | } |
|
132 | } | |
137 | } |
|
133 | } | |
138 |
|
134 | |||
139 |
|
135 | |||
140 | void VariableController::onRequestDataLoading(std::shared_ptr<Variable> variable, |
|
136 | void VariableController::onRequestDataLoading(std::shared_ptr<Variable> variable, | |
141 | const SqpDateTime &dateTime) |
|
137 | const SqpDateTime &dateTime) | |
142 | { |
|
138 | { | |
143 | // we want to load data of the variable for the dateTime. |
|
139 | // we want to load data of the variable for the dateTime. | |
144 | // First we check if the cache contains some of them. |
|
140 | // First we check if the cache contains some of them. | |
145 | // For the other, we ask the provider to give them. |
|
141 | // For the other, we ask the provider to give them. | |
146 | if (variable) { |
|
142 | if (variable) { | |
147 |
|
143 | |||
148 | auto dateTimeListNotInCache |
|
144 | auto dateTimeListNotInCache | |
149 | = impl->m_VariableCacheController->provideNotInCacheDateTimeList(variable, dateTime); |
|
145 | = impl->m_VariableCacheController->provideNotInCacheDateTimeList(variable, dateTime); | |
150 |
|
146 | |||
151 | if (!dateTimeListNotInCache.empty()) { |
|
147 | if (!dateTimeListNotInCache.empty()) { | |
152 | // Ask the provider for each data on the dateTimeListNotInCache |
|
148 | // Ask the provider for each data on the dateTimeListNotInCache | |
153 | impl->m_VariableToProviderMap.at(variable)->requestDataLoading( |
|
149 | impl->m_VariableToProviderMap.at(variable)->requestDataLoading( | |
154 | std::move(dateTimeListNotInCache)); |
|
150 | std::move(dateTimeListNotInCache)); | |
155 | } |
|
151 | } | |
156 | else { |
|
152 | else { | |
157 | emit variable->updated(); |
|
153 | emit variable->updated(); | |
158 | } |
|
154 | } | |
159 | } |
|
155 | } | |
160 | else { |
|
156 | else { | |
161 | qCCritical(LOG_VariableController()) << tr("Impossible to load data of a variable null"); |
|
157 | qCCritical(LOG_VariableController()) << tr("Impossible to load data of a variable null"); | |
162 | } |
|
158 | } | |
163 | } |
|
159 | } | |
164 |
|
160 | |||
165 |
|
161 | |||
166 | void VariableController::initialize() |
|
162 | void VariableController::initialize() | |
167 | { |
|
163 | { | |
168 | qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread(); |
|
164 | qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread(); | |
169 | impl->m_WorkingMutex.lock(); |
|
165 | impl->m_WorkingMutex.lock(); | |
170 | qCDebug(LOG_VariableController()) << tr("VariableController init END"); |
|
166 | qCDebug(LOG_VariableController()) << tr("VariableController init END"); | |
171 | } |
|
167 | } | |
172 |
|
168 | |||
173 | void VariableController::finalize() |
|
169 | void VariableController::finalize() | |
174 | { |
|
170 | { | |
175 | impl->m_WorkingMutex.unlock(); |
|
171 | impl->m_WorkingMutex.unlock(); | |
176 | } |
|
172 | } | |
177 |
|
173 | |||
178 | void VariableController::waitForFinish() |
|
174 | void VariableController::waitForFinish() | |
179 | { |
|
175 | { | |
180 | QMutexLocker locker{&impl->m_WorkingMutex}; |
|
176 | QMutexLocker locker{&impl->m_WorkingMutex}; | |
181 | } |
|
177 | } |
@@ -1,155 +1,153 | |||||
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 |
|
8 | |||
9 | Q_LOGGING_CATEGORY(LOG_VariableModel, "VariableModel") |
|
9 | Q_LOGGING_CATEGORY(LOG_VariableModel, "VariableModel") | |
10 |
|
10 | |||
11 | namespace { |
|
11 | namespace { | |
12 |
|
12 | |||
13 | // Column indexes |
|
13 | // Column indexes | |
14 | const auto NAME_COLUMN = 0; |
|
14 | const auto NAME_COLUMN = 0; | |
15 | const auto TSTART_COLUMN = 1; |
|
15 | const auto TSTART_COLUMN = 1; | |
16 | const auto TEND_COLUMN = 2; |
|
16 | const auto TEND_COLUMN = 2; | |
17 | const auto NB_COLUMNS = 3; |
|
17 | const auto NB_COLUMNS = 3; | |
18 |
|
18 | |||
19 | // Column properties |
|
19 | // Column properties | |
20 | const auto DEFAULT_HEIGHT = 25; |
|
20 | const auto DEFAULT_HEIGHT = 25; | |
21 | const auto DEFAULT_WIDTH = 100; |
|
21 | const auto DEFAULT_WIDTH = 100; | |
22 |
|
22 | |||
23 | struct ColumnProperties { |
|
23 | struct ColumnProperties { | |
24 | ColumnProperties(const QString &name = {}, int width = DEFAULT_WIDTH, |
|
24 | ColumnProperties(const QString &name = {}, int width = DEFAULT_WIDTH, | |
25 | int height = DEFAULT_HEIGHT) |
|
25 | int height = DEFAULT_HEIGHT) | |
26 | : m_Name{name}, m_Width{width}, m_Height{height} |
|
26 | : m_Name{name}, m_Width{width}, m_Height{height} | |
27 | { |
|
27 | { | |
28 | } |
|
28 | } | |
29 |
|
29 | |||
30 | QString m_Name; |
|
30 | QString m_Name; | |
31 | int m_Width; |
|
31 | int m_Width; | |
32 | int m_Height; |
|
32 | int m_Height; | |
33 | }; |
|
33 | }; | |
34 |
|
34 | |||
35 | const auto COLUMN_PROPERTIES |
|
35 | const auto COLUMN_PROPERTIES | |
36 | = QHash<int, ColumnProperties>{{NAME_COLUMN, {QObject::tr("Name")}}, |
|
36 | = QHash<int, ColumnProperties>{{NAME_COLUMN, {QObject::tr("Name")}}, | |
37 | {TSTART_COLUMN, {QObject::tr("tStart"), 180}}, |
|
37 | {TSTART_COLUMN, {QObject::tr("tStart"), 180}}, | |
38 | {TEND_COLUMN, {QObject::tr("tEnd"), 180}}}; |
|
38 | {TEND_COLUMN, {QObject::tr("tEnd"), 180}}}; | |
39 |
|
39 | |||
40 | /// Format for datetimes |
|
40 | /// Format for datetimes | |
41 | const auto DATETIME_FORMAT = QStringLiteral("dd/MM/yyyy \nhh:mm:ss:zzz"); |
|
41 | const auto DATETIME_FORMAT = QStringLiteral("dd/MM/yyyy \nhh:mm:ss:zzz"); | |
42 |
|
42 | |||
43 | } // namespace |
|
43 | } // namespace | |
44 |
|
44 | |||
45 | struct VariableModel::VariableModelPrivate { |
|
45 | struct VariableModel::VariableModelPrivate { | |
46 | /// Variables created in SciQlop |
|
46 | /// Variables created in SciQlop | |
47 | std::vector<std::shared_ptr<Variable> > m_Variables; |
|
47 | std::vector<std::shared_ptr<Variable> > m_Variables; | |
48 | }; |
|
48 | }; | |
49 |
|
49 | |||
50 | VariableModel::VariableModel(QObject *parent) |
|
50 | VariableModel::VariableModel(QObject *parent) | |
51 | : QAbstractTableModel{parent}, impl{spimpl::make_unique_impl<VariableModelPrivate>()} |
|
51 | : QAbstractTableModel{parent}, impl{spimpl::make_unique_impl<VariableModelPrivate>()} | |
52 | { |
|
52 | { | |
53 | } |
|
53 | } | |
54 |
|
54 | |||
55 | std::shared_ptr<Variable> |
|
55 | std::shared_ptr<Variable> VariableModel::createVariable(const QString &name, | |
56 | VariableModel::createVariable(const QString &name, const SqpDateTime &dateTime, |
|
56 | const SqpDateTime &dateTime) noexcept | |
57 | std::shared_ptr<IDataSeries> defaultDataSeries) noexcept |
|
|||
58 | { |
|
57 | { | |
59 | auto insertIndex = rowCount(); |
|
58 | auto insertIndex = rowCount(); | |
60 | beginInsertRows({}, insertIndex, insertIndex); |
|
59 | beginInsertRows({}, insertIndex, insertIndex); | |
61 |
|
60 | |||
62 | /// @todo For the moment, the other data of the variable is initialized with default values |
|
61 | /// @todo For the moment, the other data of the variable is initialized with default values | |
63 | auto variable = std::make_shared<Variable>(name, QStringLiteral("unit"), |
|
62 | auto variable = std::make_shared<Variable>(name, QStringLiteral("unit"), | |
64 | QStringLiteral("mission"), dateTime); |
|
63 | QStringLiteral("mission"), dateTime); | |
65 | variable->setDataSeries(std::move(defaultDataSeries)); |
|
|||
66 |
|
64 | |||
67 | impl->m_Variables.push_back(variable); |
|
65 | impl->m_Variables.push_back(variable); | |
68 |
|
66 | |||
69 | endInsertRows(); |
|
67 | endInsertRows(); | |
70 |
|
68 | |||
71 | return variable; |
|
69 | return variable; | |
72 | } |
|
70 | } | |
73 |
|
71 | |||
74 | std::shared_ptr<Variable> VariableModel::variable(int index) const |
|
72 | std::shared_ptr<Variable> VariableModel::variable(int index) const | |
75 | { |
|
73 | { | |
76 | return (index >= 0 && index < impl->m_Variables.size()) ? impl->m_Variables[index] : nullptr; |
|
74 | return (index >= 0 && index < impl->m_Variables.size()) ? impl->m_Variables[index] : nullptr; | |
77 | } |
|
75 | } | |
78 |
|
76 | |||
79 | int VariableModel::columnCount(const QModelIndex &parent) const |
|
77 | int VariableModel::columnCount(const QModelIndex &parent) const | |
80 | { |
|
78 | { | |
81 | Q_UNUSED(parent); |
|
79 | Q_UNUSED(parent); | |
82 |
|
80 | |||
83 | return NB_COLUMNS; |
|
81 | return NB_COLUMNS; | |
84 | } |
|
82 | } | |
85 |
|
83 | |||
86 | int VariableModel::rowCount(const QModelIndex &parent) const |
|
84 | int VariableModel::rowCount(const QModelIndex &parent) const | |
87 | { |
|
85 | { | |
88 | Q_UNUSED(parent); |
|
86 | Q_UNUSED(parent); | |
89 |
|
87 | |||
90 | return impl->m_Variables.size(); |
|
88 | return impl->m_Variables.size(); | |
91 | } |
|
89 | } | |
92 |
|
90 | |||
93 | QVariant VariableModel::data(const QModelIndex &index, int role) const |
|
91 | QVariant VariableModel::data(const QModelIndex &index, int role) const | |
94 | { |
|
92 | { | |
95 | if (!index.isValid()) { |
|
93 | if (!index.isValid()) { | |
96 | return QVariant{}; |
|
94 | return QVariant{}; | |
97 | } |
|
95 | } | |
98 |
|
96 | |||
99 | if (index.row() < 0 || index.row() >= rowCount()) { |
|
97 | if (index.row() < 0 || index.row() >= rowCount()) { | |
100 | return QVariant{}; |
|
98 | return QVariant{}; | |
101 | } |
|
99 | } | |
102 |
|
100 | |||
103 | if (role == Qt::DisplayRole) { |
|
101 | if (role == Qt::DisplayRole) { | |
104 | if (auto variable = impl->m_Variables.at(index.row()).get()) { |
|
102 | if (auto variable = impl->m_Variables.at(index.row()).get()) { | |
105 | /// Lambda function that builds the variant to return for a time value |
|
103 | /// Lambda function that builds the variant to return for a time value | |
106 | auto dateTimeVariant = [](double time) { |
|
104 | auto dateTimeVariant = [](double time) { | |
107 | auto dateTime = QDateTime::fromMSecsSinceEpoch(time * 1000.); |
|
105 | auto dateTime = QDateTime::fromMSecsSinceEpoch(time * 1000.); | |
108 | return dateTime.toString(DATETIME_FORMAT); |
|
106 | return dateTime.toString(DATETIME_FORMAT); | |
109 | }; |
|
107 | }; | |
110 |
|
108 | |||
111 | switch (index.column()) { |
|
109 | switch (index.column()) { | |
112 | case NAME_COLUMN: |
|
110 | case NAME_COLUMN: | |
113 | return variable->name(); |
|
111 | return variable->name(); | |
114 | case TSTART_COLUMN: |
|
112 | case TSTART_COLUMN: | |
115 | return dateTimeVariant(variable->dateTime().m_TStart); |
|
113 | return dateTimeVariant(variable->dateTime().m_TStart); | |
116 | case TEND_COLUMN: |
|
114 | case TEND_COLUMN: | |
117 | return dateTimeVariant(variable->dateTime().m_TEnd); |
|
115 | return dateTimeVariant(variable->dateTime().m_TEnd); | |
118 | default: |
|
116 | default: | |
119 | // No action |
|
117 | // No action | |
120 | break; |
|
118 | break; | |
121 | } |
|
119 | } | |
122 |
|
120 | |||
123 | qWarning(LOG_VariableModel()) |
|
121 | qWarning(LOG_VariableModel()) | |
124 | << tr("Can't get data (unknown column %1)").arg(index.column()); |
|
122 | << tr("Can't get data (unknown column %1)").arg(index.column()); | |
125 | } |
|
123 | } | |
126 | else { |
|
124 | else { | |
127 | qWarning(LOG_VariableModel()) << tr("Can't get data (no variable)"); |
|
125 | qWarning(LOG_VariableModel()) << tr("Can't get data (no variable)"); | |
128 | } |
|
126 | } | |
129 | } |
|
127 | } | |
130 |
|
128 | |||
131 | return QVariant{}; |
|
129 | return QVariant{}; | |
132 | } |
|
130 | } | |
133 |
|
131 | |||
134 | QVariant VariableModel::headerData(int section, Qt::Orientation orientation, int role) const |
|
132 | QVariant VariableModel::headerData(int section, Qt::Orientation orientation, int role) const | |
135 | { |
|
133 | { | |
136 | if (role != Qt::DisplayRole && role != Qt::SizeHintRole) { |
|
134 | if (role != Qt::DisplayRole && role != Qt::SizeHintRole) { | |
137 | return QVariant{}; |
|
135 | return QVariant{}; | |
138 | } |
|
136 | } | |
139 |
|
137 | |||
140 | if (orientation == Qt::Horizontal) { |
|
138 | if (orientation == Qt::Horizontal) { | |
141 | auto propertiesIt = COLUMN_PROPERTIES.find(section); |
|
139 | auto propertiesIt = COLUMN_PROPERTIES.find(section); | |
142 | if (propertiesIt != COLUMN_PROPERTIES.cend()) { |
|
140 | if (propertiesIt != COLUMN_PROPERTIES.cend()) { | |
143 | // Role is either DisplayRole or SizeHintRole |
|
141 | // Role is either DisplayRole or SizeHintRole | |
144 | return (role == Qt::DisplayRole) |
|
142 | return (role == Qt::DisplayRole) | |
145 | ? QVariant{propertiesIt->m_Name} |
|
143 | ? QVariant{propertiesIt->m_Name} | |
146 | : QVariant{QSize{propertiesIt->m_Width, propertiesIt->m_Height}}; |
|
144 | : QVariant{QSize{propertiesIt->m_Width, propertiesIt->m_Height}}; | |
147 | } |
|
145 | } | |
148 | else { |
|
146 | else { | |
149 | qWarning(LOG_VariableModel()) |
|
147 | qWarning(LOG_VariableModel()) | |
150 | << tr("Can't get header data (unknown column %1)").arg(section); |
|
148 | << tr("Can't get header data (unknown column %1)").arg(section); | |
151 | } |
|
149 | } | |
152 | } |
|
150 | } | |
153 |
|
151 | |||
154 | return QVariant{}; |
|
152 | return QVariant{}; | |
155 | } |
|
153 | } |
General Comments 2
Pull request updated. Auto status change to "Under Review"
Changed commits: * 3 added * 0 removed Changed files: * M core/include/Data/SqpDateTime.h * M core/include/Variable/Variable.h * M core/include/Variable/VariableModel.h * M core/src/Variable/Variable.cpp * M core/src/Variable/VariableCacheController.cpp * M core/src/Variable/VariableController.cpp * M core/src/Variable/VariableModel.cpp * M gui/include/Visualization/VisualizationGraphWidget.h * M gui/src/Visualization/VisualizationGraphHelper.cpp * M gui/src/Visualization/VisualizationGraphWidget.cpp * M gui/src/Visualization/operations/GenerateVariableMenuOperation.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/DataSource/DataSourceItemAction.h * R core/include/Plugin/PluginManager.h * R core/include/Time/TimeController.h * R core/include/Variable/VariableCacheController.h * R core/include/Variable/VariableController.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/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/VariableInspectorWidget.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/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/qcustomplot.h * R gui/resources/icones/delete.png * R gui/resources/icones/next.png * R gui/resources/icones/openInspector.png * R gui/resources/icones/previous.png * R gui/resources/icones/sciqlop2PNG_1024.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/VariableInspectorWidget.cpp * R gui/src/Variable/VariableMenuHeaderWidget.cpp * R gui/src/Visualization/VisualizationTabWidget.cpp * R gui/src/Visualization/VisualizationWidget.cpp * R gui/src/Visualization/VisualizationZoneWidget.cpp * R gui/src/Visualization/operations/MenuBuilder.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/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/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 gui/src/SqpApplication.cpp * R LICENSE * R app/src/mainwindow.cpp * R app/src/mainwindow.ui
You need to be logged in to leave comments.
Login now