@@ -92,7 +92,7 signals: | |||
|
92 | 92 | * @param variableProvider the provider that will be used to retrieve the data of the variable |
|
93 | 93 | * (can be null) |
|
94 | 94 | */ |
|
95 |
void |
|
|
95 | void createVariable(const QString &variableName, | |
|
96 | 96 | const QVariantHash &variableMetadata, |
|
97 | 97 | std::shared_ptr<IDataProvider> variableProvider); |
|
98 | 98 |
@@ -7,6 +7,7 | |||
|
7 | 7 | #include <QObject> |
|
8 | 8 | #include <QUuid> |
|
9 | 9 | #include <QReadWriteLock> |
|
10 | #include <QDataStream> | |
|
10 | 11 | |
|
11 | 12 | #include "CoreGlobal.h" |
|
12 | 13 | #include <Data/DataSeriesIterator.h> |
@@ -69,6 +70,30 public: | |||
|
69 | 70 | const DateTimeRange& newRange, const DateTimeRange& newCacheRange, |
|
70 | 71 | bool notify=true); |
|
71 | 72 | |
|
73 | static QByteArray mimeData(const std::vector<std::shared_ptr<Variable> > &variables) | |
|
74 | { | |
|
75 | auto encodedData = QByteArray{}; | |
|
76 | QDataStream stream{&encodedData, QIODevice::WriteOnly}; | |
|
77 | for (auto &var : variables) { | |
|
78 | stream << var->ID().toByteArray(); | |
|
79 | } | |
|
80 | return encodedData; | |
|
81 | } | |
|
82 | ||
|
83 | static std::vector<QUuid> variablesIDs(QByteArray mimeData) | |
|
84 | { | |
|
85 | std::vector<QUuid> variables; | |
|
86 | QDataStream stream{mimeData}; | |
|
87 | ||
|
88 | QVariantList ids; | |
|
89 | stream >> ids; | |
|
90 | ||
|
91 | for (const auto& id : ids) { | |
|
92 | variables.emplace_back (id.toByteArray()); | |
|
93 | } | |
|
94 | return variables; | |
|
95 | } | |
|
96 | ||
|
72 | 97 | DEPRECATE( |
|
73 | 98 | |
|
74 | 99 | bool contains(const DateTimeRange &range) const noexcept; |
@@ -37,9 +37,7 public: | |||
|
37 | 37 | |
|
38 | 38 | void synchronize(const std::shared_ptr<Variable>& var, const std::shared_ptr<Variable>& with); |
|
39 | 39 | |
|
40 | //This should be somewhere else VC has nothing to do with MIMEData | |
|
41 | QByteArray mimeData(const std::vector<std::shared_ptr<Variable>> &variables) const; | |
|
42 | const std::vector<std::shared_ptr<Variable>> variables(QByteArray mimeData); | |
|
40 | const std::vector<std::shared_ptr<Variable>> variables(const std::vector<QUuid>& ids); | |
|
43 | 41 | |
|
44 | 42 | const std::shared_ptr<Variable>& operator[] (int index) const; |
|
45 | 43 | std::shared_ptr<Variable> operator[] (int index); |
@@ -24,9 +24,10 enum VariableRoles { ProgressRole = Qt::UserRole }; | |||
|
24 | 24 | */ |
|
25 | 25 | class SCIQLOP_CORE_EXPORT VariableModel2 : public QAbstractTableModel { |
|
26 | 26 | Q_OBJECT |
|
27 | std::shared_ptr<VariableController2> _variableController; | |
|
27 | // read only mirror of VariableController2 content | |
|
28 | std::vector<std::shared_ptr<Variable>> _variables; | |
|
28 | 29 | public: |
|
29 |
explicit VariableModel2( |
|
|
30 | explicit VariableModel2(QObject *parent = nullptr); | |
|
30 | 31 | |
|
31 | 32 | // /////////////////////////// // |
|
32 | 33 | // QAbstractTableModel methods // |
@@ -52,12 +53,14 public: | |||
|
52 | 53 | virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, |
|
53 | 54 | const QModelIndex &parent) override; |
|
54 | 55 | |
|
55 | ||
|
56 | 56 | signals: |
|
57 | ||
|
58 | private slots: | |
|
57 | void createVariable(const QVariantHash &productData); | |
|
58 | void asyncChangeRange(const std::shared_ptr<Variable>& variable, const DateTimeRange& r); | |
|
59 | public slots: | |
|
59 | 60 | /// Slot called when data of a variable has been updated |
|
60 | 61 | void variableUpdated() noexcept; |
|
62 | void variableAdded(const std::shared_ptr<Variable>&); | |
|
63 | void variableDeleted(const std::shared_ptr<Variable>&); | |
|
61 | 64 | }; |
|
62 | 65 | |
|
63 | 66 | #endif // SCIQLOP_VARIABLEMODEL2_H |
@@ -123,7 +123,7 void DataSourceController::loadProductItem(const QUuid &dataSourceUid, | |||
|
123 | 123 | auto it = impl->m_DataProviders.find(dataSourceUid); |
|
124 | 124 | auto dataProvider = (it != impl->m_DataProviders.end()) ? it->second : nullptr; |
|
125 | 125 | |
|
126 |
emit |
|
|
126 | emit createVariable(productItem.name(), productItem.data(), dataProvider); | |
|
127 | 127 | } |
|
128 | 128 | else { |
|
129 | 129 | qCWarning(LOG_DataSourceController()) << tr("Can't load an item that is not a product"); |
@@ -32,7 +32,7 class VariableController2::VariableController2Private | |||
|
32 | 32 | inline void removeVariable(const std::shared_ptr<Variable>& variable) |
|
33 | 33 | { |
|
34 | 34 | QWriteLocker lock{&_lock}; |
|
35 |
_variables. |
|
|
35 | _variables.erase(*variable); | |
|
36 | 36 | _providers.remove(*variable); |
|
37 | 37 | _synchronizationGroups.remove(*variable); |
|
38 | 38 | } |
@@ -55,10 +55,11 class VariableController2::VariableController2Private | |||
|
55 | 55 | inline std::shared_ptr<Variable> variable(QUuid variable) |
|
56 | 56 | { |
|
57 | 57 | QReadLocker lock{&_lock}; |
|
58 | auto it = _variables.find(variable); | |
|
58 | 59 | [[unlikely]] |
|
59 |
if( |
|
|
60 | if(it==_variables.end()) | |
|
60 | 61 | SCIQLOP_ERROR(threadSafeVaraiblesMaps,"Unknown Variable"); |
|
61 |
return |
|
|
62 | return (*it).second; | |
|
62 | 63 | } |
|
63 | 64 | |
|
64 | 65 | inline std::shared_ptr<Variable> variable(int index) |
@@ -67,14 +68,19 class VariableController2::VariableController2Private | |||
|
67 | 68 | [[unlikely]] |
|
68 | 69 | if(!_variables.size() > index) |
|
69 | 70 | SCIQLOP_ERROR(threadSafeVaraiblesMaps,"Index is out of bounds"); |
|
70 |
|
|
|
71 | auto it = _variables.cbegin(); | |
|
72 | while (index!=0) { | |
|
73 | index-=1; | |
|
74 | it++; | |
|
75 | } | |
|
76 | return (*it).second; | |
|
71 | 77 | } |
|
72 | 78 | |
|
73 | 79 | inline const std::vector<std::shared_ptr<Variable>> variables() |
|
74 | 80 | { |
|
75 | 81 | std::vector<std::shared_ptr<Variable>> vars; |
|
76 | 82 | QReadLocker lock{&_lock}; |
|
77 |
for(const auto |
|
|
83 | for(const auto&[id, var]:_variables) | |
|
78 | 84 | { |
|
79 | 85 | vars.push_back(var); |
|
80 | 86 | } |
@@ -102,11 +108,11 class VariableController2::VariableController2Private | |||
|
102 | 108 | inline bool has(const std::shared_ptr<Variable>& variable) |
|
103 | 109 | { |
|
104 | 110 | QReadLocker lock{&_lock}; |
|
105 |
return _variables. |
|
|
111 | return _variables.find(*variable)==_variables.end(); | |
|
106 | 112 | } |
|
107 | 113 | |
|
108 | 114 | private: |
|
109 |
|
|
|
115 | std::map<QUuid,std::shared_ptr<Variable>> _variables; | |
|
110 | 116 | QMap<QUuid,std::shared_ptr<IDataProvider>> _providers; |
|
111 | 117 | QMap<QUuid,std::shared_ptr<VariableSynchronizationGroup2>> _synchronizationGroups; |
|
112 | 118 | QReadWriteLock _lock{QReadWriteLock::Recursive}; |
@@ -366,29 +372,12 void VariableController2::synchronize(const std::shared_ptr<Variable> &var, cons | |||
|
366 | 372 | impl->synchronize(var, with); |
|
367 | 373 | } |
|
368 | 374 | |
|
369 | QByteArray VariableController2::mimeData(const std::vector<std::shared_ptr<Variable> > &variables) const | |
|
370 | { | |
|
371 | auto encodedData = QByteArray{}; | |
|
372 | QDataStream stream{&encodedData, QIODevice::WriteOnly}; | |
|
373 | for (auto &var : variables) { | |
|
374 | stream << var->ID().toByteArray(); | |
|
375 | } | |
|
376 | return encodedData; | |
|
377 | } | |
|
378 | ||
|
379 | const std::vector<std::shared_ptr<Variable>> VariableController2::variables(QByteArray mimeData) | |
|
375 | const std::vector<std::shared_ptr<Variable>> VariableController2::variables(const std::vector<QUuid> &ids) | |
|
380 | 376 | { |
|
381 | 377 | std::vector<std::shared_ptr<Variable>> variables; |
|
382 | QDataStream stream{mimeData}; | |
|
383 | ||
|
384 | QVariantList ids; | |
|
385 | stream >> ids; | |
|
386 | ||
|
387 | 378 | for (const auto& id : ids) { |
|
388 | auto uuid = QUuid{id.toByteArray()}; | |
|
389 | variables.push_back (impl->variable(uuid)); | |
|
379 | variables.push_back(impl->variable(id)); | |
|
390 | 380 | } |
|
391 | ||
|
392 | 381 | return variables; |
|
393 | 382 | } |
|
394 | 383 |
@@ -1,3 +1,8 | |||
|
1 | #include <QMimeData> | |
|
2 | #include <QSize> | |
|
3 | #include <QTimer> | |
|
4 | #include <unordered_map> | |
|
5 | ||
|
1 | 6 | #include <Variable/Variable.h> |
|
2 | 7 | #include <Variable/VariableController2.h> |
|
3 | 8 | #include <Variable/VariableModel2.h> |
@@ -5,17 +10,13 | |||
|
5 | 10 | #include <Common/DateUtils.h> |
|
6 | 11 | #include <Common/MimeTypesDef.h> |
|
7 | 12 | #include <Common/StringUtils.h> |
|
13 | #include <Common/containers.h> | |
|
8 | 14 | |
|
9 | 15 | #include <Data/IDataSeries.h> |
|
10 | 16 | |
|
11 | 17 | #include <DataSource/DataSourceController.h> |
|
12 | 18 | #include <Time/TimeController.h> |
|
13 | 19 | |
|
14 | #include <QMimeData> | |
|
15 | #include <QSize> | |
|
16 | #include <QTimer> | |
|
17 | #include <unordered_map> | |
|
18 | ||
|
19 | 20 | namespace { |
|
20 | 21 | |
|
21 | 22 | // Column indexes |
@@ -66,8 +67,8 QString uniqueName(const QString &defaultName, | |||
|
66 | 67 | |
|
67 | 68 | |
|
68 | 69 | |
|
69 | VariableModel2::VariableModel2(const std::shared_ptr<VariableController2> &variableController, QObject *parent) | |
|
70 |
: QAbstractTableModel{parent} |
|
|
70 | VariableModel2::VariableModel2(QObject *parent) | |
|
71 | : QAbstractTableModel{parent} | |
|
71 | 72 | { |
|
72 | 73 | } |
|
73 | 74 | |
@@ -82,7 +83,7 int VariableModel2::columnCount(const QModelIndex &parent) const | |||
|
82 | 83 | int VariableModel2::rowCount(const QModelIndex &parent) const |
|
83 | 84 | { |
|
84 | 85 | Q_UNUSED(parent); |
|
85 | return static_cast<int>(_variableController->variables().size()); | |
|
86 | return _variables.size(); | |
|
86 | 87 | } |
|
87 | 88 | |
|
88 | 89 | QVariant VariableModel2::data(const QModelIndex &index, int role) const |
@@ -96,7 +97,7 QVariant VariableModel2::data(const QModelIndex &index, int role) const | |||
|
96 | 97 | } |
|
97 | 98 | |
|
98 | 99 | if (role == Qt::DisplayRole) { |
|
99 |
if (auto variable = _variable |
|
|
100 | if (auto variable = _variables[index.row()]) { | |
|
100 | 101 | switch (index.column()) { |
|
101 | 102 | case NAME_COLUMN: |
|
102 | 103 | return variable->name(); |
@@ -178,19 +179,19 QMimeData *VariableModel2::mimeData(const QModelIndexList &indexes) const | |||
|
178 | 179 | DateTimeRange firstTimeRange; |
|
179 | 180 | for (const auto &index : indexes) { |
|
180 | 181 | if (index.column() == 0) { // only the first column |
|
181 |
auto variable = _variable |
|
|
182 | auto variable = _variables[index.row()]; | |
|
182 | 183 | if (variable.get() && index.isValid()) { |
|
183 | 184 | |
|
184 | 185 | if (variables.size()==0) { |
|
185 | 186 | // Gets the range of the first variable |
|
186 |
firstTimeRange = |
|
|
187 | firstTimeRange = variable->range(); | |
|
187 | 188 | } |
|
188 | 189 | variables.push_back(variable); |
|
189 | 190 | } |
|
190 | 191 | } |
|
191 | 192 | } |
|
192 | 193 | |
|
193 |
auto variablesEncodedData = |
|
|
194 | auto variablesEncodedData = Variable::mimeData(variables); | |
|
194 | 195 | mimeData->setData(MIME_TYPE_VARIABLE_LIST, variablesEncodedData); |
|
195 | 196 | |
|
196 | 197 | if (variables.size() == 1) { |
@@ -205,6 +206,7 QMimeData *VariableModel2::mimeData(const QModelIndexList &indexes) const | |||
|
205 | 206 | bool VariableModel2::canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, |
|
206 | 207 | int column, const QModelIndex &parent) const |
|
207 | 208 | { |
|
209 | Q_UNUSED(column); | |
|
208 | 210 | // drop of a product |
|
209 | 211 | return data->hasFormat(MIME_TYPE_PRODUCT_LIST) |
|
210 | 212 | || (data->hasFormat(MIME_TYPE_TIME_RANGE) && parent.isValid() |
@@ -221,17 +223,16 bool VariableModel2::dropMimeData(const QMimeData *data, Qt::DropAction action, | |||
|
221 | 223 | = DataSourceController::productsDataForMimeData(data->data(MIME_TYPE_PRODUCT_LIST)); |
|
222 | 224 | |
|
223 | 225 | for (auto metaData : productList) { |
|
224 |
|
|
|
225 | //@TODO No idea what this does | |
|
226 | emit createVariable(metaData.toHash()); | |
|
226 | 227 | } |
|
227 | 228 | |
|
228 | 229 | dropDone = true; |
|
229 | 230 | } |
|
230 | 231 | else if (data->hasFormat(MIME_TYPE_TIME_RANGE) && parent.isValid()) { |
|
231 |
auto variable = _variable |
|
|
232 | auto variable = _variables[parent.row()]; | |
|
232 | 233 | auto range = TimeController::timeRangeForMimeData(data->data(MIME_TYPE_TIME_RANGE)); |
|
233 | 234 | |
|
234 |
|
|
|
235 | emit asyncChangeRange(variable, range); | |
|
235 | 236 | |
|
236 | 237 | dropDone = true; |
|
237 | 238 | } |
@@ -241,6 +242,29 bool VariableModel2::dropMimeData(const QMimeData *data, Qt::DropAction action, | |||
|
241 | 242 | |
|
242 | 243 | void VariableModel2::variableUpdated() noexcept |
|
243 | 244 | { |
|
245 | emit dataChanged(QModelIndex(),QModelIndex()); | |
|
246 | } | |
|
244 | 247 | |
|
248 | void VariableModel2::variableAdded(const std::shared_ptr<Variable> & variable) | |
|
249 | { | |
|
250 | if(!SciQLop::containers::contains(_variables,variable)) | |
|
251 | { | |
|
252 | beginInsertRows(QModelIndex(), this->_variables.size(), this->_variables.size()); | |
|
253 | this->_variables.push_back(variable); | |
|
254 | endInsertRows(); | |
|
255 | connect(variable.get(),&Variable::updated,this,&VariableModel2::variableUpdated); | |
|
256 | } | |
|
257 | } | |
|
258 | ||
|
259 | void VariableModel2::variableDeleted(const std::shared_ptr<Variable> &variable) | |
|
260 | { | |
|
261 | auto it = std::find(_variables.begin(), _variables.end(), variable); | |
|
262 | if (it != _variables.end()) | |
|
263 | { | |
|
264 | auto index = std::distance(_variables.begin(), it); | |
|
265 | beginRemoveRows(QModelIndex(), index, index); | |
|
266 | _variables.erase(it); | |
|
267 | endRemoveRows(); | |
|
268 | } | |
|
245 | 269 | } |
|
246 | 270 |
General Comments 0
You need to be logged in to leave comments.
Login now