@@ -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 | 12 | extern SCIQLOP_CORE_EXPORT const QString MIME_TYPE_GRAPH; |
|
13 | 13 | extern SCIQLOP_CORE_EXPORT const QString MIME_TYPE_ZONE; |
|
14 | 14 | extern SCIQLOP_CORE_EXPORT const QString MIME_TYPE_VARIABLE_LIST; |
|
15 | extern SCIQLOP_CORE_EXPORT const QString MIME_TYPE_PRODUCT_LIST; | |
|
15 | 16 | extern SCIQLOP_CORE_EXPORT const QString MIME_TYPE_TIME_RANGE; |
|
16 | 17 | |
|
17 | 18 |
@@ -3,6 +3,7 core_moc_headers = [ | |||
|
3 | 3 | 'include/Data/IDataProvider.h', |
|
4 | 4 | 'include/DataSource/DataSourceController.h', |
|
5 | 5 | 'include/DataSource/DataSourceItemAction.h', |
|
6 | 'include/DataSource/DataSourceWidget.h', | |
|
6 | 7 | 'include/Network/NetworkController.h', |
|
7 | 8 | 'include/Time/TimeController.h', |
|
8 | 9 | 'include/Variable/Variable.h', |
@@ -29,6 +30,7 core_sources = [ | |||
|
29 | 30 | 'src/DataSource/DataSourceController.cpp', |
|
30 | 31 | 'src/DataSource/DataSourceItem.cpp', |
|
31 | 32 | 'src/DataSource/DataSourceItemAction.cpp', |
|
33 | 'src/DataSource/DataSourceWidget.cpp', | |
|
32 | 34 | 'src/Network/NetworkController.cpp', |
|
33 | 35 | 'src/Plugin/PluginManager.cpp', |
|
34 | 36 | 'src/Settings/SqpSettingsDefs.cpp', |
@@ -3,4 +3,5 | |||
|
3 | 3 | const QString MIME_TYPE_GRAPH = QStringLiteral("scqlop/graph"); |
|
4 | 4 | const QString MIME_TYPE_ZONE = QStringLiteral("scqlop/zone"); |
|
5 | 5 | const QString MIME_TYPE_VARIABLE_LIST = QStringLiteral("scqlop/var-list"); |
|
6 | const QString MIME_TYPE_PRODUCT_LIST = QStringLiteral("scqlop/product-list"); | |
|
6 | 7 | const QString MIME_TYPE_TIME_RANGE = QStringLiteral("scqlop/time-range"); |
@@ -129,6 +129,15 DataSourceTreeWidgetItem::DataSourceTreeWidgetItem(QTreeWidget *parent, const Da | |||
|
129 | 129 | auto itemActions = impl->m_Data->actions(); |
|
130 | 130 | std::transform(std::cbegin(itemActions), std::cend(itemActions), |
|
131 | 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 | 143 | const DataSourceItem *DataSourceTreeWidgetItem::data() const |
@@ -18,7 +18,13 | |||
|
18 | 18 | <widget class="QLineEdit" name="filterLineEdit"/> |
|
19 | 19 | </item> |
|
20 | 20 | <item row="1" column="0"> |
|
21 |
<widget class=" |
|
|
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 | 28 | <column> |
|
23 | 29 | <property name="text"> |
|
24 | 30 | <string notr="true">1</string> |
@@ -28,6 +34,13 | |||
|
28 | 34 | </item> |
|
29 | 35 | </layout> |
|
30 | 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 | 44 | <resources/> |
|
32 | 45 | <connections/> |
|
33 | 46 | </ui> |
General Comments 0
You need to be logged in to leave comments.
Login now