##// END OF EJS Templates
drop of product on the visu
trabillard -
r875:4aae8a8d06e9 DropProductOnVisu...
parent child
Show More
@@ -64,6 +64,8 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 std::shared_ptr<IDataProvider> providerForProductData(const QVariantHash &productData);
68
67 QByteArray mimeDataForProductsData(const QVariantList &productsData) const;
69 QByteArray mimeDataForProductsData(const QVariantList &productsData) const;
68 QVariantList productsDataForMimeData(const QByteArray &mimeData) const;
70 QVariantList productsDataForMimeData(const QByteArray &mimeData) const;
69
71
@@ -139,6 +139,26 void DataSourceController::loadProductItem(const QUuid &dataSourceUid,
139 }
139 }
140 }
140 }
141
141
142 std::shared_ptr<IDataProvider>
143 DataSourceController::providerForProductData(const QVariantHash &productData)
144 {
145 DataSourceItem *sourceItem = impl->findDataSourceItem(productData);
146
147 if (sourceItem && sourceItem->type() == DataSourceItemType::PRODUCT
148 || sourceItem->type() == DataSourceItemType::COMPONENT) {
149 auto sourceName = sourceItem->rootItem().name();
150 auto sourceId = impl->m_DataSources.key(sourceName);
151 auto it = impl->m_DataProviders.find(sourceId);
152 auto dataProvider = (it != impl->m_DataProviders.end()) ? it->second : nullptr;
153 return dataProvider;
154 }
155 else {
156 qCWarning(LOG_DataSourceController()) << tr("requestVariable, product data not found");
157 }
158
159 return nullptr;
160 }
161
142 QByteArray DataSourceController::mimeDataForProductsData(const QVariantList &productsData) const
162 QByteArray DataSourceController::mimeDataForProductsData(const QVariantList &productsData) const
143 {
163 {
144 QByteArray encodedData;
164 QByteArray encodedData;
@@ -282,6 +282,14 bool DragDropHelper::checkMimeDataForVisualization(const QMimeData *mimeData,
282 result = false;
282 result = false;
283 }
283 }
284 }
284 }
285 else if (mimeData->hasFormat(MIME_TYPE_PRODUCT_LIST)) {
286 QDataStream stream(mimeData->data(MIME_TYPE_PRODUCT_LIST));
287
288 QVariantList productList;
289 stream >> productList;
290
291 result = productList.count() == 1;
292 }
285
293
286 return result;
294 return result;
287 }
295 }
@@ -5,6 +5,8
5 #include "Visualization/VisualizationGraphWidget.h"
5 #include "Visualization/VisualizationGraphWidget.h"
6 #include "Visualization/VisualizationZoneWidget.h"
6 #include "Visualization/VisualizationZoneWidget.h"
7
7
8 #include "DataSource/DataSourceController.h"
9 #include "DataSource/DataSourceItem.h"
8 #include "Variable/VariableController.h"
10 #include "Variable/VariableController.h"
9
11
10 #include "Common/MimeTypesDef.h"
12 #include "Common/MimeTypesDef.h"
@@ -12,6 +14,8
12 #include "DragDropHelper.h"
14 #include "DragDropHelper.h"
13 #include "SqpApplication.h"
15 #include "SqpApplication.h"
14
16
17 #include <QTimer>
18
15 Q_LOGGING_CATEGORY(LOG_VisualizationTabWidget, "VisualizationTabWidget")
19 Q_LOGGING_CATEGORY(LOG_VisualizationTabWidget, "VisualizationTabWidget")
16
20
17 namespace {
21 namespace {
@@ -59,6 +63,8 struct VisualizationTabWidget::VisualizationTabWidgetPrivate {
59 void dropZone(int index, VisualizationTabWidget *tabWidget);
63 void dropZone(int index, VisualizationTabWidget *tabWidget);
60 void dropVariables(const QList<std::shared_ptr<Variable> > &variables, int index,
64 void dropVariables(const QList<std::shared_ptr<Variable> > &variables, int index,
61 VisualizationTabWidget *tabWidget);
65 VisualizationTabWidget *tabWidget);
66 void dropProduct(const QVariantList &productDataList, int index,
67 VisualizationTabWidget *tabWidget);
62 };
68 };
63
69
64 VisualizationTabWidget::VisualizationTabWidget(const QString &name, QWidget *parent)
70 VisualizationTabWidget::VisualizationTabWidget(const QString &name, QWidget *parent)
@@ -69,7 +75,7 VisualizationTabWidget::VisualizationTabWidget(const QString &name, QWidget *par
69 ui->setupUi(this);
75 ui->setupUi(this);
70
76
71 ui->dragDropContainer->setAcceptedMimeTypes(
77 ui->dragDropContainer->setAcceptedMimeTypes(
72 {MIME_TYPE_GRAPH, MIME_TYPE_ZONE, MIME_TYPE_VARIABLE_LIST});
78 {MIME_TYPE_GRAPH, MIME_TYPE_ZONE, MIME_TYPE_VARIABLE_LIST, MIME_TYPE_PRODUCT_LIST});
73 connect(ui->dragDropContainer, &VisualizationDragDropContainer::dropOccured, this,
79 connect(ui->dragDropContainer, &VisualizationDragDropContainer::dropOccured, this,
74 &VisualizationTabWidget::dropMimeData);
80 &VisualizationTabWidget::dropMimeData);
75 ui->dragDropContainer->setAcceptMimeDataFunction([this](auto mimeData) {
81 ui->dragDropContainer->setAcceptMimeDataFunction([this](auto mimeData) {
@@ -184,6 +190,11 void VisualizationTabWidget::dropMimeData(int index, const QMimeData *mimeData)
184 mimeData->data(MIME_TYPE_VARIABLE_LIST));
190 mimeData->data(MIME_TYPE_VARIABLE_LIST));
185 impl->dropVariables(variables, index, this);
191 impl->dropVariables(variables, index, this);
186 }
192 }
193 else if (mimeData->hasFormat(MIME_TYPE_PRODUCT_LIST)) {
194 auto productList = sqpApp->dataSourceController().productsDataForMimeData(
195 mimeData->data(MIME_TYPE_PRODUCT_LIST));
196 impl->dropProduct(productList, index, this);
197 }
187 else {
198 else {
188 qCWarning(LOG_VisualizationZoneWidget())
199 qCWarning(LOG_VisualizationZoneWidget())
189 << tr("VisualizationTabWidget::dropMimeData, unknown MIME data received.");
200 << tr("VisualizationTabWidget::dropMimeData, unknown MIME data received.");
@@ -287,8 +298,33 void VisualizationTabWidget::VisualizationTabWidgetPrivate::dropVariables(
287 const QList<std::shared_ptr<Variable> > &variables, int index,
298 const QList<std::shared_ptr<Variable> > &variables, int index,
288 VisualizationTabWidget *tabWidget)
299 VisualizationTabWidget *tabWidget)
289 {
300 {
290 // Note: we are sure that there is a single and compatible variable here
301 // Note: the AcceptMimeDataFunction (set on the drop container) ensure there is a single and
291 // because the AcceptMimeDataFunction, set on the drop container, makes the check before the
302 // compatible variable here
292 // drop can occur.
303 if (variables.count() > 1) {
304 qCWarning(LOG_VisualizationZoneWidget())
305 << tr("VisualizationTabWidget::dropVariables, dropping multiple variables, operation "
306 "aborted.");
307 return;
308 }
309
293 tabWidget->createZone(variables, index);
310 tabWidget->createZone(variables, index);
294 }
311 }
312
313 void VisualizationTabWidget::VisualizationTabWidgetPrivate::dropProduct(
314 const QVariantList &productDataList, int index, VisualizationTabWidget *tabWidget)
315 {
316 // Note: the AcceptMimeDataFunction (set on the drop container) ensure there is a single and
317 // compatible product here
318 if (productDataList.count() > 1) {
319 qCWarning(LOG_VisualizationZoneWidget()) << tr(
320 "VisualizationTabWidget::dropProduct, dropping multiple products, operation aborted.");
321 return;
322 }
323
324 auto productData = productDataList.first().toHash();
325 auto provider = sqpApp->dataSourceController().providerForProductData(productData);
326 auto name = productData.value(DataSourceItem::NAME_DATA_KEY).toString();
327 auto variable = sqpApp->variableController().createVariable(name, productData, provider);
328 QTimer::singleShot(
329 3000, [tabWidget, variable, index]() { tabWidget->createZone({variable}, index); });
330 }
@@ -10,6 +10,8
10 #include "Common/VisualizationDef.h"
10 #include "Common/VisualizationDef.h"
11
11
12 #include <Data/SqpRange.h>
12 #include <Data/SqpRange.h>
13 #include <DataSource/DataSourceController.h>
14 #include <DataSource/DataSourceItem.h>
13 #include <Variable/Variable.h>
15 #include <Variable/Variable.h>
14 #include <Variable/VariableController.h>
16 #include <Variable/VariableController.h>
15
17
@@ -74,6 +76,8 struct VisualizationZoneWidget::VisualizationZoneWidgetPrivate {
74 void dropGraph(int index, VisualizationZoneWidget *zoneWidget);
76 void dropGraph(int index, VisualizationZoneWidget *zoneWidget);
75 void dropVariables(const QList<std::shared_ptr<Variable> > &variables, int index,
77 void dropVariables(const QList<std::shared_ptr<Variable> > &variables, int index,
76 VisualizationZoneWidget *zoneWidget);
78 VisualizationZoneWidget *zoneWidget);
79 void dropProduct(const QVariantList &productDataList, int index,
80 VisualizationZoneWidget *zoneWidget);
77 };
81 };
78
82
79 VisualizationZoneWidget::VisualizationZoneWidget(const QString &name, QWidget *parent)
83 VisualizationZoneWidget::VisualizationZoneWidget(const QString &name, QWidget *parent)
@@ -85,7 +89,8 VisualizationZoneWidget::VisualizationZoneWidget(const QString &name, QWidget *p
85
89
86 ui->zoneNameLabel->setText(name);
90 ui->zoneNameLabel->setText(name);
87
91
88 ui->dragDropContainer->setAcceptedMimeTypes({MIME_TYPE_GRAPH, MIME_TYPE_VARIABLE_LIST});
92 ui->dragDropContainer->setAcceptedMimeTypes(
93 {MIME_TYPE_GRAPH, MIME_TYPE_VARIABLE_LIST, MIME_TYPE_PRODUCT_LIST});
89 ui->dragDropContainer->setAcceptMimeDataFunction([this](auto mimeData) {
94 ui->dragDropContainer->setAcceptMimeDataFunction([this](auto mimeData) {
90 return sqpApp->dragDropHelper().checkMimeDataForVisualization(mimeData,
95 return sqpApp->dragDropHelper().checkMimeDataForVisualization(mimeData,
91 ui->dragDropContainer);
96 ui->dragDropContainer);
@@ -374,6 +379,11 void VisualizationZoneWidget::dropMimeData(int index, const QMimeData *mimeData)
374 mimeData->data(MIME_TYPE_VARIABLE_LIST));
379 mimeData->data(MIME_TYPE_VARIABLE_LIST));
375 impl->dropVariables(variables, index, this);
380 impl->dropVariables(variables, index, this);
376 }
381 }
382 else if (mimeData->hasFormat(MIME_TYPE_PRODUCT_LIST)) {
383 auto productList = sqpApp->dataSourceController().productsDataForMimeData(
384 mimeData->data(MIME_TYPE_PRODUCT_LIST));
385 impl->dropProduct(productList, index, this);
386 }
377 else {
387 else {
378 qCWarning(LOG_VisualizationZoneWidget())
388 qCWarning(LOG_VisualizationZoneWidget())
379 << tr("VisualizationZoneWidget::dropMimeData, unknown MIME data received.");
389 << tr("VisualizationZoneWidget::dropMimeData, unknown MIME data received.");
@@ -455,30 +465,33 void VisualizationZoneWidget::VisualizationZoneWidgetPrivate::dropVariables(
455 const QList<std::shared_ptr<Variable> > &variables, int index,
465 const QList<std::shared_ptr<Variable> > &variables, int index,
456 VisualizationZoneWidget *zoneWidget)
466 VisualizationZoneWidget *zoneWidget)
457 {
467 {
458 // Search for the top level VisualizationWidget
468 // Note: the AcceptMimeDataFunction (set on the drop container) ensure there is a single and
459 auto parent = zoneWidget->parentWidget();
469 // compatible variable here
460 while (parent && qobject_cast<VisualizationWidget *>(parent) == nullptr) {
470 if (variables.count() > 1) {
461 parent = parent->parentWidget();
462 }
463
464 if (!parent) {
465 qCWarning(LOG_VisualizationZoneWidget())
471 qCWarning(LOG_VisualizationZoneWidget())
466 << tr("VisualizationZoneWidget::dropVariables, drop aborted, the parent "
472 << tr("VisualizationZoneWidget::dropVariables, dropping multiple variables, operation "
467 "VisualizationWidget cannot be found.");
473 "aborted.");
468 Q_ASSERT(false);
469 return;
474 return;
470 }
475 }
471
476
472 auto visualizationWidget = static_cast<VisualizationWidget *>(parent);
477 Q_ASSERT(variables.count() == 1);
473
478 zoneWidget->createGraph(variables, index);
474 // Search for the first variable which can be dropped
475 for (auto variable : variables) {
476 FindVariableOperation findVariableOperation{variable};
477 visualizationWidget->accept(&findVariableOperation);
478 auto variableContainers = findVariableOperation.result();
479 if (variableContainers.empty()) {
480 zoneWidget->createGraph(variable, index);
481 break;
482 }
479 }
480
481 void VisualizationZoneWidget::VisualizationZoneWidgetPrivate::dropProduct(
482 const QVariantList &productDataList, int index, VisualizationZoneWidget *zoneWidget)
483 {
484 // Note: the AcceptMimeDataFunction (set on the drop container) ensure there is a single and
485 // compatible product here
486 if (productDataList.count() > 1) {
487 qCWarning(LOG_VisualizationZoneWidget()) << tr(
488 "VisualizationZoneWidget::dropProduct, dropping multiple products, operation aborted.");
489 return;
483 }
490 }
491
492 auto productData = productDataList.first().toHash();
493 auto provider = sqpApp->dataSourceController().providerForProductData(productData);
494 auto name = productData.value(DataSourceItem::NAME_DATA_KEY).toString();
495 auto variable = sqpApp->variableController().createVariable(name, productData, provider);
496 zoneWidget->createGraph(variable, index);
484 }
497 }
General Comments 0
You need to be logged in to leave comments. Login now