##// END OF EJS Templates
Drag of product
Drag of product

File last commit:

r862:e45b43f0766d
r862:e45b43f0766d
Show More
DataSourceTreeWidget.cpp
38 lines | 1.2 KiB | text/x-c | CppLexer
/ gui / src / DataSource / DataSourceTreeWidget.cpp
Drag of product
r862 #include "DataSource/DataSourceTreeWidget.h"
#include "Common/MimeTypesDef.h"
#include "DataSource/DataSourceItem.h"
#include "DataSource/DataSourceTreeWidgetItem.h"
#include <QMimeData>
DataSourceTreeWidget::DataSourceTreeWidget(QWidget *parent) : QTreeWidget(parent) {}
QMimeData *DataSourceTreeWidget::mimeData(const QList<QTreeWidgetItem *> items) const
{
auto mimeData = new QMimeData;
// Basic check to ensure the item are correctly typed
Q_ASSERT(items.isEmpty() || dynamic_cast<DataSourceTreeWidgetItem *>(items.first()) != nullptr);
QVariantList productData;
for (auto item : items) {
auto dataSourceTreeItem = static_cast<DataSourceTreeWidgetItem *>(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;
}