##// END OF EJS Templates
Drag of product
trabillard -
r876:86e05857e5c8
parent child
Show More
@@ -0,0 +1,14
1 #ifndef SCIQLOP_DATASOURCETREEWIDGET_H
2 #define SCIQLOP_DATASOURCETREEWIDGET_H
3
4 #include <QTreeWidget>
5
6 class DataSourceTreeWidget : public QTreeWidget {
7 public:
8 DataSourceTreeWidget(QWidget *parent);
9
10 protected:
11 QMimeData *mimeData(const QList<QTreeWidgetItem *> items) const override;
12 };
13
14 #endif // SCIQLOP_DATASOURCETREEWIDGET_H
@@ -0,0 +1,37
1 #include "DataSource/DataSourceTreeWidget.h"
2 #include "Common/MimeTypesDef.h"
3 #include "DataSource/DataSourceController.h"
4 #include "DataSource/DataSourceItem.h"
5 #include "DataSource/DataSourceTreeWidgetItem.h"
6
7 #include "SqpApplication.h"
8
9 #include <QMimeData>
10
11 DataSourceTreeWidget::DataSourceTreeWidget(QWidget *parent) : QTreeWidget(parent) {}
12
13 QMimeData *DataSourceTreeWidget::mimeData(const QList<QTreeWidgetItem *> items) const
14 {
15 auto mimeData = new QMimeData;
16
17 // Basic check to ensure the item are correctly typed
18 Q_ASSERT(items.isEmpty() || dynamic_cast<DataSourceTreeWidgetItem *>(items.first()) != nullptr);
19
20 QVariantList productData;
21
22 for (auto item : items) {
23 auto dataSourceTreeItem = static_cast<DataSourceTreeWidgetItem *>(item);
24 auto dataSource = dataSourceTreeItem->data();
25
26 if (dataSource->type() == DataSourceItemType::COMPONENT
27 || dataSource->type() == DataSourceItemType::PRODUCT) {
28 auto metaData = dataSource->data();
29 productData << metaData;
30 }
31 }
32
33 auto encodedData = sqpApp->dataSourceController().mimeDataForProductsData(productData);
34 mimeData->setData(MIME_TYPE_PRODUCT_LIST, encodedData);
35
36 return mimeData;
37 }
@@ -12,6 +12,7
12 extern SCIQLOP_CORE_EXPORT const QString MIME_TYPE_GRAPH;
12 extern SCIQLOP_CORE_EXPORT const QString MIME_TYPE_GRAPH;
13 extern SCIQLOP_CORE_EXPORT const QString MIME_TYPE_ZONE;
13 extern SCIQLOP_CORE_EXPORT const QString MIME_TYPE_ZONE;
14 extern SCIQLOP_CORE_EXPORT const QString MIME_TYPE_VARIABLE_LIST;
14 extern SCIQLOP_CORE_EXPORT const QString MIME_TYPE_VARIABLE_LIST;
15 extern SCIQLOP_CORE_EXPORT const QString MIME_TYPE_PRODUCT_LIST;
15 extern SCIQLOP_CORE_EXPORT const QString MIME_TYPE_TIME_RANGE;
16 extern SCIQLOP_CORE_EXPORT const QString MIME_TYPE_TIME_RANGE;
16
17
17
18
@@ -64,6 +64,9 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();
@@ -3,6 +3,7 core_moc_headers = [
3 'include/Data/IDataProvider.h',
3 'include/Data/IDataProvider.h',
4 'include/DataSource/DataSourceController.h',
4 'include/DataSource/DataSourceController.h',
5 'include/DataSource/DataSourceItemAction.h',
5 'include/DataSource/DataSourceItemAction.h',
6 'include/DataSource/DataSourceWidget.h',
6 'include/Network/NetworkController.h',
7 'include/Network/NetworkController.h',
7 'include/Time/TimeController.h',
8 'include/Time/TimeController.h',
8 'include/Variable/Variable.h',
9 'include/Variable/Variable.h',
@@ -31,6 +32,7 core_sources = [
31 'src/DataSource/DataSourceController.cpp',
32 'src/DataSource/DataSourceController.cpp',
32 'src/DataSource/DataSourceItem.cpp',
33 'src/DataSource/DataSourceItem.cpp',
33 'src/DataSource/DataSourceItemAction.cpp',
34 'src/DataSource/DataSourceItemAction.cpp',
35 'src/DataSource/DataSourceWidget.cpp',
34 'src/Network/NetworkController.cpp',
36 'src/Network/NetworkController.cpp',
35 'src/Plugin/PluginManager.cpp',
37 'src/Plugin/PluginManager.cpp',
36 'src/Settings/SqpSettingsDefs.cpp',
38 'src/Settings/SqpSettingsDefs.cpp',
@@ -1,6 +1,7
1 #include "Common/MimeTypesDef.h"
1 #include "Common/MimeTypesDef.h"
2
2
3 const QString MIME_TYPE_GRAPH = QStringLiteral("scqlop/graph");
3 const QString MIME_TYPE_GRAPH = QStringLiteral("sciqlop/graph");
4 const QString MIME_TYPE_ZONE = QStringLiteral("scqlop/zone");
4 const QString MIME_TYPE_ZONE = QStringLiteral("sciqlop/zone");
5 const QString MIME_TYPE_VARIABLE_LIST = QStringLiteral("scqlop/var-list");
5 const QString MIME_TYPE_VARIABLE_LIST = QStringLiteral("sciqlop/var-list");
6 const QString MIME_TYPE_TIME_RANGE = QStringLiteral("scqlop/time-range");
6 const QString MIME_TYPE_PRODUCT_LIST = QStringLiteral("sciqlop/product-list");
7 const QString MIME_TYPE_TIME_RANGE = QStringLiteral("sciqlop/time-range");
@@ -124,6 +124,26 void DataSourceController::loadProductItem(const QUuid &dataSourceUid,
124 }
124 }
125 }
125 }
126
126
127 QByteArray DataSourceController::mimeDataForProductsData(const QVariantList &productsData) const
128 {
129 QByteArray encodedData;
130 QDataStream stream{&encodedData, QIODevice::WriteOnly};
131
132 stream << productsData;
133
134 return encodedData;
135 }
136
137 QVariantList DataSourceController::productsDataForMimeData(const QByteArray &mimeData) const
138 {
139 QDataStream stream{mimeData};
140
141 QVariantList productList;
142 stream >> productList;
143
144 return productList;
145 }
146
127 void DataSourceController::initialize()
147 void DataSourceController::initialize()
128 {
148 {
129 qCDebug(LOG_DataSourceController()) << tr("DataSourceController init")
149 qCDebug(LOG_DataSourceController()) << tr("DataSourceController init")
@@ -310,7 +310,7 VariableController::variablesForMimeData(const QByteArray &mimeData) const
310 stream >> ids;
310 stream >> ids;
311
311
312 for (auto id : ids) {
312 for (auto id : ids) {
313 auto uuid = QUuid(id.toByteArray());
313 auto uuid = QUuid{id.toByteArray()};
314 auto var = impl->findVariable(uuid);
314 auto var = impl->findVariable(uuid);
315 variables << var;
315 variables << var;
316 }
316 }
@@ -248,6 +248,12 QUrl DragDropHelper::imageTemporaryUrl(const QImage &image) const
248 bool DragDropHelper::checkMimeDataForVisualization(const QMimeData *mimeData,
248 bool DragDropHelper::checkMimeDataForVisualization(const QMimeData *mimeData,
249 VisualizationDragDropContainer *dropContainer)
249 VisualizationDragDropContainer *dropContainer)
250 {
250 {
251 if (!mimeData || !dropContainer) {
252 qCWarning(LOG_DragDropHelper()) << QObject::tr(
253 "DragDropHelper::checkMimeDataForVisualization, invalid input parameters.");
254 Q_ASSERT(false);
255 }
256
251 auto result = true;
257 auto result = true;
252
258
253 if (mimeData->hasFormat(MIME_TYPE_VARIABLE_LIST)) {
259 if (mimeData->hasFormat(MIME_TYPE_VARIABLE_LIST)) {
@@ -233,7 +233,7 QString VisualizationGraphWidget::name() const
233 QMimeData *VisualizationGraphWidget::mimeData() const
233 QMimeData *VisualizationGraphWidget::mimeData() const
234 {
234 {
235 auto mimeData = new QMimeData;
235 auto mimeData = new QMimeData;
236 mimeData->setData(MIME_TYPE_GRAPH, QByteArray());
236 mimeData->setData(MIME_TYPE_GRAPH, QByteArray{});
237
237
238 return mimeData;
238 return mimeData;
239 }
239 }
@@ -287,8 +287,13 void VisualizationTabWidget::VisualizationTabWidgetPrivate::dropVariables(
287 const QList<std::shared_ptr<Variable> > &variables, int index,
287 const QList<std::shared_ptr<Variable> > &variables, int index,
288 VisualizationTabWidget *tabWidget)
288 VisualizationTabWidget *tabWidget)
289 {
289 {
290 // Note: we are sure that there is a single and compatible variable here
290 // 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
291 // compatible variable here
292 // drop can occur.
292 if (variables.count() > 1) {
293 qCWarning(LOG_VisualizationZoneWidget())
294 << tr("VisualizationTabWidget::dropVariables, dropping multiple variables, operation "
295 "aborted.");
296 return;
297
293 tabWidget->createZone(variables, index);
298 tabWidget->createZone(variables, index);
294 }
299 }
@@ -327,7 +327,7 QString VisualizationZoneWidget::name() const
327 QMimeData *VisualizationZoneWidget::mimeData() const
327 QMimeData *VisualizationZoneWidget::mimeData() const
328 {
328 {
329 auto mimeData = new QMimeData;
329 auto mimeData = new QMimeData;
330 mimeData->setData(MIME_TYPE_ZONE, QByteArray());
330 mimeData->setData(MIME_TYPE_ZONE, QByteArray{});
331
331
332 return mimeData;
332 return mimeData;
333 }
333 }
@@ -455,30 +455,14 void VisualizationZoneWidget::VisualizationZoneWidgetPrivate::dropVariables(
455 const QList<std::shared_ptr<Variable> > &variables, int index,
455 const QList<std::shared_ptr<Variable> > &variables, int index,
456 VisualizationZoneWidget *zoneWidget)
456 VisualizationZoneWidget *zoneWidget)
457 {
457 {
458 // Search for the top level VisualizationWidget
458 // Note: the AcceptMimeDataFunction (set on the drop container) ensure there is a single and
459 auto parent = zoneWidget->parentWidget();
459 // compatible variable here
460 while (parent && qobject_cast<VisualizationWidget *>(parent) == nullptr) {
460 if (variables.count() > 1) {
461 parent = parent->parentWidget();
462 }
463
464 if (!parent) {
465 qCWarning(LOG_VisualizationZoneWidget())
461 qCWarning(LOG_VisualizationZoneWidget())
466 << tr("VisualizationZoneWidget::dropVariables, drop aborted, the parent "
462 << tr("VisualizationZoneWidget::dropVariables, dropping multiple variables, operation "
467 "VisualizationWidget cannot be found.");
463 "aborted.");
468 Q_ASSERT(false);
469 return;
464 return;
470 }
465 }
471
466
472 auto visualizationWidget = static_cast<VisualizationWidget *>(parent);
467 zoneWidget->createGraph({variable}, index);
473
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 }
483 }
484 }
468 }
@@ -18,7 +18,16
18 <widget class="QLineEdit" name="filterLineEdit"/>
18 <widget class="QLineEdit" name="filterLineEdit"/>
19 </item>
19 </item>
20 <item row="1" column="0">
20 <item row="1" column="0">
21 <widget class="QTreeWidget" name="treeWidget">
21 <widget class="DataSourceTreeWidget" name="treeWidget">
22 <property name="dragEnabled">
23 <bool>true</bool>
24 </property>
25 <property name="dragDropMode">
26 <enum>QAbstractItemView::DragOnly</enum>
27 </property>
28 <property name="selectionMode">
29 <enum>QAbstractItemView::ExtendedSelection</enum>
30 </property>
22 <column>
31 <column>
23 <property name="text">
32 <property name="text">
24 <string notr="true">1</string>
33 <string notr="true">1</string>
@@ -28,6 +37,13
28 </item>
37 </item>
29 </layout>
38 </layout>
30 </widget>
39 </widget>
40 <customwidgets>
41 <customwidget>
42 <class>DataSourceTreeWidget</class>
43 <extends>QTreeWidget</extends>
44 <header>DataSource/DataSourceTreeWidget.h</header>
45 </customwidget>
46 </customwidgets>
31 <resources/>
47 <resources/>
32 <connections/>
48 <connections/>
33 </ui>
49 </ui>
General Comments 1
Under Review
author

Auto status change to "Under Review"

You need to be logged in to leave comments. Login now