##// END OF EJS Templates
Drag of product
trabillard -
r862:e45b43f0766d
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,38
1 #include "DataSource/DataSourceTreeWidget.h"
2 #include "Common/MimeTypesDef.h"
3 #include "DataSource/DataSourceItem.h"
4 #include "DataSource/DataSourceTreeWidgetItem.h"
5
6 #include <QMimeData>
7
8 DataSourceTreeWidget::DataSourceTreeWidget(QWidget *parent) : QTreeWidget(parent) {}
9
10 QMimeData *DataSourceTreeWidget::mimeData(const QList<QTreeWidgetItem *> items) const
11 {
12 auto mimeData = new QMimeData;
13
14 // Basic check to ensure the item are correctly typed
15 Q_ASSERT(items.isEmpty() || dynamic_cast<DataSourceTreeWidgetItem *>(items.first()) != nullptr);
16
17 QVariantList productData;
18
19 for (auto item : items) {
20 auto dataSourceTreeItem = static_cast<DataSourceTreeWidgetItem *>(item);
21 auto dataSource = dataSourceTreeItem->data();
22
23 if (dataSource->type() == DataSourceItemType::COMPONENT
24 || dataSource->type() == DataSourceItemType::PRODUCT) {
25 auto metaData = dataSource->data();
26 productData << metaData;
27 }
28 }
29
30 QByteArray encodedData;
31 QDataStream stream(&encodedData, QIODevice::WriteOnly);
32
33 stream << productData;
34
35 mimeData->setData(MIME_TYPE_PRODUCT_LIST, encodedData);
36
37 return mimeData;
38 }
@@ -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
@@ -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',
@@ -29,6 +30,7 core_sources = [
29 'src/DataSource/DataSourceController.cpp',
30 'src/DataSource/DataSourceController.cpp',
30 'src/DataSource/DataSourceItem.cpp',
31 'src/DataSource/DataSourceItem.cpp',
31 'src/DataSource/DataSourceItemAction.cpp',
32 'src/DataSource/DataSourceItemAction.cpp',
33 'src/DataSource/DataSourceWidget.cpp',
32 'src/Network/NetworkController.cpp',
34 'src/Network/NetworkController.cpp',
33 'src/Plugin/PluginManager.cpp',
35 'src/Plugin/PluginManager.cpp',
34 'src/Settings/SqpSettingsDefs.cpp',
36 'src/Settings/SqpSettingsDefs.cpp',
@@ -3,4 +3,5
3 const QString MIME_TYPE_GRAPH = QStringLiteral("scqlop/graph");
3 const QString MIME_TYPE_GRAPH = QStringLiteral("scqlop/graph");
4 const QString MIME_TYPE_ZONE = QStringLiteral("scqlop/zone");
4 const QString MIME_TYPE_ZONE = QStringLiteral("scqlop/zone");
5 const QString MIME_TYPE_VARIABLE_LIST = QStringLiteral("scqlop/var-list");
5 const QString MIME_TYPE_VARIABLE_LIST = QStringLiteral("scqlop/var-list");
6 const QString MIME_TYPE_PRODUCT_LIST = QStringLiteral("scqlop/product-list");
6 const QString MIME_TYPE_TIME_RANGE = QStringLiteral("scqlop/time-range");
7 const QString MIME_TYPE_TIME_RANGE = QStringLiteral("scqlop/time-range");
@@ -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
@@ -18,7 +18,13
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>
22 <column>
28 <column>
23 <property name="text">
29 <property name="text">
24 <string notr="true">1</string>
30 <string notr="true">1</string>
@@ -28,6 +34,13
28 </item>
34 </item>
29 </layout>
35 </layout>
30 </widget>
36 </widget>
37 <customwidgets>
38 <customwidget>
39 <class>DataSourceTreeWidget</class>
40 <extends>QTreeWidget</extends>
41 <header>DataSource/DataSourceTreeWidget.h</header>
42 </customwidget>
43 </customwidgets>
31 <resources/>
44 <resources/>
32 <connections/>
45 <connections/>
33 </ui>
46 </ui>
@@ -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