##// END OF EJS Templates
drop of product on the variables
trabillard -
r874:7d2f05cda6a0
parent child
Show More
@@ -64,11 +64,16 public:
64 */
64 */
65 void loadProductItem(const QUuid &dataSourceUid, const DataSourceItem &productItem) noexcept;
65 void loadProductItem(const QUuid &dataSourceUid, const DataSourceItem &productItem) noexcept;
66
66
67 QByteArray mimeDataForProductsData(const QVariantList &productsData) const;
68 QVariantList productsDataForMimeData(const QByteArray &mimeData) const;
69
67 public slots:
70 public slots:
68 /// Manage init/end of the controller
71 /// Manage init/end of the controller
69 void initialize();
72 void initialize();
70 void finalize();
73 void finalize();
71
74
75 void requestVariable(const QVariantHash &productData);
76
72 signals:
77 signals:
73 /// Signal emitted when a structure has been set for a data source
78 /// Signal emitted when a structure has been set for a data source
74 void dataSourceItemSet(DataSourceItem *dataSourceItem);
79 void dataSourceItemSet(DataSourceItem *dataSourceItem);
@@ -91,6 +91,14 public:
91
91
92 DataSourceItemType type() const noexcept;
92 DataSourceItemType type() const noexcept;
93
93
94 /**
95 * @brief Searches the first child matching the specified data.
96 * @param data The data to search.
97 * @param recursive So the search recursively.
98 * @return the item matching the data or nullptr if it was not found.
99 */
100 DataSourceItem *findItem(const QVariantHash &data, bool recursive);
101
94 bool operator==(const DataSourceItem &other);
102 bool operator==(const DataSourceItem &other);
95 bool operator!=(const DataSourceItem &other);
103 bool operator!=(const DataSourceItem &other);
96
104
@@ -93,6 +93,7 public:
93
93
94 signals:
94 signals:
95 void abortProgessRequested(std::shared_ptr<Variable> variable);
95 void abortProgessRequested(std::shared_ptr<Variable> variable);
96 void requestVariable(const QVariantHash &productData);
96
97
97 private:
98 private:
98 class VariableModelPrivate;
99 class VariableModelPrivate;
@@ -6,6 +6,7
6 #include <QMutex>
6 #include <QMutex>
7 #include <QThread>
7 #include <QThread>
8
8
9 #include <QDataStream>
9 #include <QDir>
10 #include <QDir>
10 #include <QStandardPaths>
11 #include <QStandardPaths>
11
12
@@ -44,6 +45,20 public:
44 /// @remarks Data providers are stored as shared_ptr as they can be sent to a variable and
45 /// @remarks Data providers are stored as shared_ptr as they can be sent to a variable and
45 /// continue to live without necessarily the data source controller
46 /// continue to live without necessarily the data source controller
46 std::map<QUuid, std::shared_ptr<IDataProvider> > m_DataProviders;
47 std::map<QUuid, std::shared_ptr<IDataProvider> > m_DataProviders;
48
49 // Search for the first datasource item matching the specified data
50 DataSourceItem *findDataSourceItem(const QVariantHash &data)
51 {
52 DataSourceItem *sourceItem = nullptr;
53 for (const auto &item : m_DataSourceItems) {
54 sourceItem = item.second->findItem(data, true);
55 if (sourceItem) {
56 break;
57 }
58 }
59
60 return sourceItem;
61 }
47 };
62 };
48
63
49 DataSourceController::DataSourceController(QObject *parent)
64 DataSourceController::DataSourceController(QObject *parent)
@@ -124,6 +139,26 void DataSourceController::loadProductItem(const QUuid &dataSourceUid,
124 }
139 }
125 }
140 }
126
141
142 QByteArray DataSourceController::mimeDataForProductsData(const QVariantList &productsData) const
143 {
144 QByteArray encodedData;
145 QDataStream stream(&encodedData, QIODevice::WriteOnly);
146
147 stream << productsData;
148
149 return encodedData;
150 }
151
152 QVariantList DataSourceController::productsDataForMimeData(const QByteArray &mimeData) const
153 {
154 QDataStream stream(mimeData);
155
156 QVariantList productList;
157 stream >> productList;
158
159 return productList;
160 }
161
127 void DataSourceController::initialize()
162 void DataSourceController::initialize()
128 {
163 {
129 qCDebug(LOG_DataSourceController())
164 qCDebug(LOG_DataSourceController())
@@ -137,6 +172,20 void DataSourceController::finalize()
137 impl->m_WorkingMutex.unlock();
172 impl->m_WorkingMutex.unlock();
138 }
173 }
139
174
175 void DataSourceController::requestVariable(const QVariantHash &productData)
176 {
177 DataSourceItem *sourceItem = impl->findDataSourceItem(productData);
178
179 if (sourceItem) {
180 auto sourceName = sourceItem->rootItem().name();
181 auto sourceId = impl->m_DataSources.key(sourceName);
182 loadProductItem(sourceId, *sourceItem);
183 }
184 else {
185 qCWarning(LOG_DataSourceController()) << tr("requestVariable, product data not found");
186 }
187 }
188
140 void DataSourceController::waitForFinish()
189 void DataSourceController::waitForFinish()
141 {
190 {
142 QMutexLocker locker{&impl->m_WorkingMutex};
191 QMutexLocker locker{&impl->m_WorkingMutex};
@@ -123,6 +123,24 DataSourceItemType DataSourceItem::type() const noexcept
123 return impl->m_Type;
123 return impl->m_Type;
124 }
124 }
125
125
126 DataSourceItem *DataSourceItem::findItem(const QVariantHash &data, bool recursive)
127 {
128 for (const auto &child : impl->m_Children) {
129 if (child->impl->m_Data == data) {
130 return child.get();
131 }
132
133 if (recursive) {
134 auto foundItem = child->findItem(data, true);
135 if (foundItem) {
136 return foundItem;
137 }
138 }
139 }
140
141 return nullptr;
142 }
143
126 bool DataSourceItem::operator==(const DataSourceItem &other)
144 bool DataSourceItem::operator==(const DataSourceItem &other)
127 {
145 {
128 // Compares items' attributes
146 // Compares items' attributes
@@ -8,6 +8,7
8
8
9 #include <Data/IDataSeries.h>
9 #include <Data/IDataSeries.h>
10
10
11 #include <QDataStream>
11 #include <QMimeData>
12 #include <QMimeData>
12 #include <QSize>
13 #include <QSize>
13 #include <unordered_map>
14 #include <unordered_map>
@@ -267,7 +268,7 Qt::ItemFlags VariableModel::flags(const QModelIndex &index) const
267
268
268 Qt::DropActions VariableModel::supportedDropActions() const
269 Qt::DropActions VariableModel::supportedDropActions() const
269 {
270 {
270 return Qt::MoveAction;
271 return Qt::CopyAction | Qt::MoveAction;
271 }
272 }
272
273
273 Qt::DropActions VariableModel::supportedDragActions() const
274 Qt::DropActions VariableModel::supportedDragActions() const
@@ -304,13 +305,29 QMimeData *VariableModel::mimeData(const QModelIndexList &indexes) const
304 bool VariableModel::canDropMimeData(const QMimeData *data, Qt::DropAction action, int row,
305 bool VariableModel::canDropMimeData(const QMimeData *data, Qt::DropAction action, int row,
305 int column, const QModelIndex &parent) const
306 int column, const QModelIndex &parent) const
306 {
307 {
307 return false;
308 // drop of a product
309 return data->hasFormat(MIME_TYPE_PRODUCT_LIST);
308 }
310 }
309
311
310 bool VariableModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column,
312 bool VariableModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column,
311 const QModelIndex &parent)
313 const QModelIndex &parent)
312 {
314 {
313 return false;
315 bool dropDone = false;
316
317 if (data->hasFormat(MIME_TYPE_PRODUCT_LIST)) {
318 QDataStream stream(data->data(MIME_TYPE_PRODUCT_LIST));
319
320 QVariantList productList;
321 stream >> productList;
322
323 for (auto metaData : productList) {
324 emit requestVariable(metaData.toHash());
325 }
326
327 dropDone = true;
328 }
329
330 return dropDone;
314 }
331 }
315
332
316 void VariableModel::abortProgress(const QModelIndex &index)
333 void VariableModel::abortProgress(const QModelIndex &index)
@@ -1,8 +1,11
1 #include "DataSource/DataSourceTreeWidget.h"
1 #include "DataSource/DataSourceTreeWidget.h"
2 #include "Common/MimeTypesDef.h"
2 #include "Common/MimeTypesDef.h"
3 #include "DataSource/DataSourceController.h"
3 #include "DataSource/DataSourceItem.h"
4 #include "DataSource/DataSourceItem.h"
4 #include "DataSource/DataSourceTreeWidgetItem.h"
5 #include "DataSource/DataSourceTreeWidgetItem.h"
5
6
7 #include "SqpApplication.h"
8
6 #include <QMimeData>
9 #include <QMimeData>
7
10
8 DataSourceTreeWidget::DataSourceTreeWidget(QWidget *parent) : QTreeWidget(parent) {}
11 DataSourceTreeWidget::DataSourceTreeWidget(QWidget *parent) : QTreeWidget(parent) {}
@@ -27,11 +30,7 QMimeData *DataSourceTreeWidget::mimeData(const QList<QTreeWidgetItem *> items)
27 }
30 }
28 }
31 }
29
32
30 QByteArray encodedData;
33 auto encodedData = sqpApp->dataSourceController().mimeDataForProductsData(productData);
31 QDataStream stream(&encodedData, QIODevice::WriteOnly);
32
33 stream << productData;
34
35 mimeData->setData(MIME_TYPE_PRODUCT_LIST, encodedData);
34 mimeData->setData(MIME_TYPE_PRODUCT_LIST, encodedData);
36
35
37 return mimeData;
36 return mimeData;
@@ -8,6 +8,7
8 #include <Time/TimeController.h>
8 #include <Time/TimeController.h>
9 #include <Variable/Variable.h>
9 #include <Variable/Variable.h>
10 #include <Variable/VariableController.h>
10 #include <Variable/VariableController.h>
11 #include <Variable/VariableModel.h>
11 #include <Visualization/VisualizationController.h>
12 #include <Visualization/VisualizationController.h>
12
13
13 Q_LOGGING_CATEGORY(LOG_SqpApplication, "SqpApplication")
14 Q_LOGGING_CATEGORY(LOG_SqpApplication, "SqpApplication")
@@ -34,6 +35,9 public:
34 SLOT(createVariable(const QString &, const QVariantHash &,
35 SLOT(createVariable(const QString &, const QVariantHash &,
35 std::shared_ptr<IDataProvider>)));
36 std::shared_ptr<IDataProvider>)));
36
37
38 connect(m_VariableController->variableModel(), &VariableModel::requestVariable,
39 m_DataSourceController.get(), &DataSourceController::requestVariable);
40
37 // VariableController <-> VisualizationController
41 // VariableController <-> VisualizationController
38 connect(m_VariableController.get(),
42 connect(m_VariableController.get(),
39 SIGNAL(variableAboutToBeDeleted(std::shared_ptr<Variable>)),
43 SIGNAL(variableAboutToBeDeleted(std::shared_ptr<Variable>)),
@@ -25,6 +25,9
25 <property name="dragDropMode">
25 <property name="dragDropMode">
26 <enum>QAbstractItemView::DragOnly</enum>
26 <enum>QAbstractItemView::DragOnly</enum>
27 </property>
27 </property>
28 <property name="selectionMode">
29 <enum>QAbstractItemView::ExtendedSelection</enum>
30 </property>
28 <column>
31 <column>
29 <property name="text">
32 <property name="text">
30 <string notr="true">1</string>
33 <string notr="true">1</string>
General Comments 0
You need to be logged in to leave comments. Login now