##// 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 65 void loadProductItem(const QUuid &dataSourceUid, const DataSourceItem &productItem) noexcept;
66 66
67 std::shared_ptr<IDataProvider> providerForProductData(const QVariantHash &productData);
68
67 69 QByteArray mimeDataForProductsData(const QVariantList &productsData) const;
68 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 162 QByteArray DataSourceController::mimeDataForProductsData(const QVariantList &productsData) const
143 163 {
144 164 QByteArray encodedData;
@@ -282,6 +282,14 bool DragDropHelper::checkMimeDataForVisualization(const QMimeData *mimeData,
282 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 294 return result;
287 295 }
@@ -5,6 +5,8
5 5 #include "Visualization/VisualizationGraphWidget.h"
6 6 #include "Visualization/VisualizationZoneWidget.h"
7 7
8 #include "DataSource/DataSourceController.h"
9 #include "DataSource/DataSourceItem.h"
8 10 #include "Variable/VariableController.h"
9 11
10 12 #include "Common/MimeTypesDef.h"
@@ -12,6 +14,8
12 14 #include "DragDropHelper.h"
13 15 #include "SqpApplication.h"
14 16
17 #include <QTimer>
18
15 19 Q_LOGGING_CATEGORY(LOG_VisualizationTabWidget, "VisualizationTabWidget")
16 20
17 21 namespace {
@@ -59,6 +63,8 struct VisualizationTabWidget::VisualizationTabWidgetPrivate {
59 63 void dropZone(int index, VisualizationTabWidget *tabWidget);
60 64 void dropVariables(const QList<std::shared_ptr<Variable> > &variables, int index,
61 65 VisualizationTabWidget *tabWidget);
66 void dropProduct(const QVariantList &productDataList, int index,
67 VisualizationTabWidget *tabWidget);
62 68 };
63 69
64 70 VisualizationTabWidget::VisualizationTabWidget(const QString &name, QWidget *parent)
@@ -69,7 +75,7 VisualizationTabWidget::VisualizationTabWidget(const QString &name, QWidget *par
69 75 ui->setupUi(this);
70 76
71 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 79 connect(ui->dragDropContainer, &VisualizationDragDropContainer::dropOccured, this,
74 80 &VisualizationTabWidget::dropMimeData);
75 81 ui->dragDropContainer->setAcceptMimeDataFunction([this](auto mimeData) {
@@ -184,6 +190,11 void VisualizationTabWidget::dropMimeData(int index, const QMimeData *mimeData)
184 190 mimeData->data(MIME_TYPE_VARIABLE_LIST));
185 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 198 else {
188 199 qCWarning(LOG_VisualizationZoneWidget())
189 200 << tr("VisualizationTabWidget::dropMimeData, unknown MIME data received.");
@@ -287,8 +298,33 void VisualizationTabWidget::VisualizationTabWidgetPrivate::dropVariables(
287 298 const QList<std::shared_ptr<Variable> > &variables, int index,
288 299 VisualizationTabWidget *tabWidget)
289 300 {
290 // Note: we are sure that there is a single and compatible variable here
291 // because the AcceptMimeDataFunction, set on the drop container, makes the check before the
292 // drop can occur.
301 // Note: the AcceptMimeDataFunction (set on the drop container) ensure there is a single and
302 // compatible variable here
303 if (variables.count() > 1) {
304 qCWarning(LOG_VisualizationZoneWidget())
305 << tr("VisualizationTabWidget::dropVariables, dropping multiple variables, operation "
306 "aborted.");
307 return;
308 }
309
293 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 10 #include "Common/VisualizationDef.h"
11 11
12 12 #include <Data/SqpRange.h>
13 #include <DataSource/DataSourceController.h>
14 #include <DataSource/DataSourceItem.h>
13 15 #include <Variable/Variable.h>
14 16 #include <Variable/VariableController.h>
15 17
@@ -74,6 +76,8 struct VisualizationZoneWidget::VisualizationZoneWidgetPrivate {
74 76 void dropGraph(int index, VisualizationZoneWidget *zoneWidget);
75 77 void dropVariables(const QList<std::shared_ptr<Variable> > &variables, int index,
76 78 VisualizationZoneWidget *zoneWidget);
79 void dropProduct(const QVariantList &productDataList, int index,
80 VisualizationZoneWidget *zoneWidget);
77 81 };
78 82
79 83 VisualizationZoneWidget::VisualizationZoneWidget(const QString &name, QWidget *parent)
@@ -85,7 +89,8 VisualizationZoneWidget::VisualizationZoneWidget(const QString &name, QWidget *p
85 89
86 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 94 ui->dragDropContainer->setAcceptMimeDataFunction([this](auto mimeData) {
90 95 return sqpApp->dragDropHelper().checkMimeDataForVisualization(mimeData,
91 96 ui->dragDropContainer);
@@ -374,6 +379,11 void VisualizationZoneWidget::dropMimeData(int index, const QMimeData *mimeData)
374 379 mimeData->data(MIME_TYPE_VARIABLE_LIST));
375 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 387 else {
378 388 qCWarning(LOG_VisualizationZoneWidget())
379 389 << tr("VisualizationZoneWidget::dropMimeData, unknown MIME data received.");
@@ -455,30 +465,33 void VisualizationZoneWidget::VisualizationZoneWidgetPrivate::dropVariables(
455 465 const QList<std::shared_ptr<Variable> > &variables, int index,
456 466 VisualizationZoneWidget *zoneWidget)
457 467 {
458 // Search for the top level VisualizationWidget
459 auto parent = zoneWidget->parentWidget();
460 while (parent && qobject_cast<VisualizationWidget *>(parent) == nullptr) {
461 parent = parent->parentWidget();
462 }
463
464 if (!parent) {
468 // Note: the AcceptMimeDataFunction (set on the drop container) ensure there is a single and
469 // compatible variable here
470 if (variables.count() > 1) {
465 471 qCWarning(LOG_VisualizationZoneWidget())
466 << tr("VisualizationZoneWidget::dropVariables, drop aborted, the parent "
467 "VisualizationWidget cannot be found.");
468 Q_ASSERT(false);
472 << tr("VisualizationZoneWidget::dropVariables, dropping multiple variables, operation "
473 "aborted.");
469 474 return;
470 475 }
471 476
472 auto visualizationWidget = static_cast<VisualizationWidget *>(parent);
477 Q_ASSERT(variables.count() == 1);
478 zoneWidget->createGraph(variables, index);
479 }
473 480
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 }
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