##// END OF EJS Templates
Drop of product in variables
trabillard -
r870:e6294435151a
parent child
Show More
@@ -72,6 +72,8 public slots:
72 void initialize();
72 void initialize();
73 void finalize();
73 void finalize();
74
74
75 void requestVariable(const QVariantHash &productData);
76
75 signals:
77 signals:
76 /// 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
77 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)
@@ -157,6 +172,20 void DataSourceController::finalize()
157 impl->m_WorkingMutex.unlock();
172 impl->m_WorkingMutex.unlock();
158 }
173 }
159
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
160 void DataSourceController::waitForFinish()
189 void DataSourceController::waitForFinish()
161 {
190 {
162 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)
@@ -129,6 +129,15 DataSourceTreeWidgetItem::DataSourceTreeWidgetItem(QTreeWidget *parent, const Da
129 auto itemActions = impl->m_Data->actions();
129 auto itemActions = impl->m_Data->actions();
130 std::transform(std::cbegin(itemActions), std::cend(itemActions),
130 std::transform(std::cbegin(itemActions), std::cend(itemActions),
131 std::back_inserter(impl->m_Actions), createTreeAction);
131 std::back_inserter(impl->m_Actions), createTreeAction);
132
133 // Sets the flags of the items
134 auto flags = Qt::ItemIsSelectable | Qt::ItemIsEnabled;
135 if (data->type() == DataSourceItemType::COMPONENT
136 || data->type() == DataSourceItemType::PRODUCT) {
137 flags |= Qt::ItemIsDragEnabled;
138 }
139
140 setFlags(flags);
132 }
141 }
133
142
134 const DataSourceItem *DataSourceTreeWidgetItem::data() const
143 const DataSourceItem *DataSourceTreeWidgetItem::data() const
@@ -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>)),
@@ -294,6 +294,7 void VisualizationTabWidget::VisualizationTabWidgetPrivate::dropVariables(
294 << tr("VisualizationTabWidget::dropVariables, dropping multiple variables, operation "
294 << tr("VisualizationTabWidget::dropVariables, dropping multiple variables, operation "
295 "aborted.");
295 "aborted.");
296 return;
296 return;
297 }
297
298
298 tabWidget->createZone(variables, index);
299 tabWidget->createZone(variables, index);
299 }
300 }
@@ -464,5 +464,5 void VisualizationZoneWidget::VisualizationZoneWidgetPrivate::dropVariables(
464 return;
464 return;
465 }
465 }
466
466
467 zoneWidget->createGraph({variable}, index);
467 zoneWidget->createGraph(variables, index);
468 }
468 }
@@ -16,6 +16,9
16 <layout class="QGridLayout" name="gridLayout">
16 <layout class="QGridLayout" name="gridLayout">
17 <item row="0" column="0">
17 <item row="0" column="0">
18 <widget class="QTableView" name="tableView">
18 <widget class="QTableView" name="tableView">
19 <property name="acceptDrops">
20 <bool>true</bool>
21 </property>
19 <property name="dragEnabled">
22 <property name="dragEnabled">
20 <bool>true</bool>
23 <bool>true</bool>
21 </property>
24 </property>
General Comments 0
You need to be logged in to leave comments. Login now