From e45b43f0766d545505612e45c32d37567708ca11 2017-10-27 15:42:12 From: Thibaud Rabillard Date: 2017-10-27 15:42:12 Subject: [PATCH] Drag of product --- diff --git a/core/include/Common/MimeTypesDef.h b/core/include/Common/MimeTypesDef.h index 2212853..3766fac 100644 --- a/core/include/Common/MimeTypesDef.h +++ b/core/include/Common/MimeTypesDef.h @@ -12,6 +12,7 @@ extern SCIQLOP_CORE_EXPORT const QString MIME_TYPE_GRAPH; extern SCIQLOP_CORE_EXPORT const QString MIME_TYPE_ZONE; extern SCIQLOP_CORE_EXPORT const QString MIME_TYPE_VARIABLE_LIST; +extern SCIQLOP_CORE_EXPORT const QString MIME_TYPE_PRODUCT_LIST; extern SCIQLOP_CORE_EXPORT const QString MIME_TYPE_TIME_RANGE; diff --git a/core/meson.build b/core/meson.build index 658e629..ac44feb 100644 --- a/core/meson.build +++ b/core/meson.build @@ -3,6 +3,7 @@ core_moc_headers = [ 'include/Data/IDataProvider.h', 'include/DataSource/DataSourceController.h', 'include/DataSource/DataSourceItemAction.h', + 'include/DataSource/DataSourceWidget.h', 'include/Network/NetworkController.h', 'include/Time/TimeController.h', 'include/Variable/Variable.h', @@ -29,6 +30,7 @@ core_sources = [ 'src/DataSource/DataSourceController.cpp', 'src/DataSource/DataSourceItem.cpp', 'src/DataSource/DataSourceItemAction.cpp', + 'src/DataSource/DataSourceWidget.cpp', 'src/Network/NetworkController.cpp', 'src/Plugin/PluginManager.cpp', 'src/Settings/SqpSettingsDefs.cpp', diff --git a/core/src/Common/MimeTypesDef.cpp b/core/src/Common/MimeTypesDef.cpp index 24ef739..50a5fb4 100644 --- a/core/src/Common/MimeTypesDef.cpp +++ b/core/src/Common/MimeTypesDef.cpp @@ -3,4 +3,5 @@ const QString MIME_TYPE_GRAPH = QStringLiteral("scqlop/graph"); const QString MIME_TYPE_ZONE = QStringLiteral("scqlop/zone"); const QString MIME_TYPE_VARIABLE_LIST = QStringLiteral("scqlop/var-list"); +const QString MIME_TYPE_PRODUCT_LIST = QStringLiteral("scqlop/product-list"); const QString MIME_TYPE_TIME_RANGE = QStringLiteral("scqlop/time-range"); diff --git a/gui/include/DataSource/DataSourceTreeWidget.h b/gui/include/DataSource/DataSourceTreeWidget.h new file mode 100644 index 0000000..08043ba --- /dev/null +++ b/gui/include/DataSource/DataSourceTreeWidget.h @@ -0,0 +1,14 @@ +#ifndef SCIQLOP_DATASOURCETREEWIDGET_H +#define SCIQLOP_DATASOURCETREEWIDGET_H + +#include + +class DataSourceTreeWidget : public QTreeWidget { +public: + DataSourceTreeWidget(QWidget *parent); + +protected: + QMimeData *mimeData(const QList items) const override; +}; + +#endif // SCIQLOP_DATASOURCETREEWIDGET_H diff --git a/gui/src/DataSource/DataSourceTreeWidget.cpp b/gui/src/DataSource/DataSourceTreeWidget.cpp new file mode 100644 index 0000000..db7d6f5 --- /dev/null +++ b/gui/src/DataSource/DataSourceTreeWidget.cpp @@ -0,0 +1,38 @@ +#include "DataSource/DataSourceTreeWidget.h" +#include "Common/MimeTypesDef.h" +#include "DataSource/DataSourceItem.h" +#include "DataSource/DataSourceTreeWidgetItem.h" + +#include + +DataSourceTreeWidget::DataSourceTreeWidget(QWidget *parent) : QTreeWidget(parent) {} + +QMimeData *DataSourceTreeWidget::mimeData(const QList items) const +{ + auto mimeData = new QMimeData; + + // Basic check to ensure the item are correctly typed + Q_ASSERT(items.isEmpty() || dynamic_cast(items.first()) != nullptr); + + QVariantList productData; + + for (auto item : items) { + auto dataSourceTreeItem = static_cast(item); + auto dataSource = dataSourceTreeItem->data(); + + if (dataSource->type() == DataSourceItemType::COMPONENT + || dataSource->type() == DataSourceItemType::PRODUCT) { + auto metaData = dataSource->data(); + productData << metaData; + } + } + + QByteArray encodedData; + QDataStream stream(&encodedData, QIODevice::WriteOnly); + + stream << productData; + + mimeData->setData(MIME_TYPE_PRODUCT_LIST, encodedData); + + return mimeData; +} diff --git a/gui/src/DataSource/DataSourceTreeWidgetItem.cpp b/gui/src/DataSource/DataSourceTreeWidgetItem.cpp index df831ad..67bbeb1 100644 --- a/gui/src/DataSource/DataSourceTreeWidgetItem.cpp +++ b/gui/src/DataSource/DataSourceTreeWidgetItem.cpp @@ -129,6 +129,15 @@ DataSourceTreeWidgetItem::DataSourceTreeWidgetItem(QTreeWidget *parent, const Da auto itemActions = impl->m_Data->actions(); std::transform(std::cbegin(itemActions), std::cend(itemActions), std::back_inserter(impl->m_Actions), createTreeAction); + + // Sets the flags of the items + auto flags = Qt::ItemIsSelectable | Qt::ItemIsEnabled; + if (data->type() == DataSourceItemType::COMPONENT + || data->type() == DataSourceItemType::PRODUCT) { + flags |= Qt::ItemIsDragEnabled; + } + + setFlags(flags); } const DataSourceItem *DataSourceTreeWidgetItem::data() const diff --git a/gui/ui/DataSource/DataSourceWidget.ui b/gui/ui/DataSource/DataSourceWidget.ui index e5d6f22..f6f7bc7 100644 --- a/gui/ui/DataSource/DataSourceWidget.ui +++ b/gui/ui/DataSource/DataSourceWidget.ui @@ -18,7 +18,13 @@ - + + + true + + + QAbstractItemView::DragOnly + 1 @@ -28,6 +34,13 @@ + + + DataSourceTreeWidget + QTreeWidget +
DataSource/DataSourceTreeWidget.h
+
+
diff --git a/gui/ui/Variable/VariableInspectorWidget.ui b/gui/ui/Variable/VariableInspectorWidget.ui index 70c8186..66b9377 100644 --- a/gui/ui/Variable/VariableInspectorWidget.ui +++ b/gui/ui/Variable/VariableInspectorWidget.ui @@ -16,6 +16,9 @@ + + true + true