DataSourceTreeWidget.cpp
47 lines
| 1.5 KiB
| text/x-c
|
CppLexer
r868 | #include "DataSource/DataSourceTreeWidget.h" | |||
#include "Common/MimeTypesDef.h" | ||||
#include "DataSource/DataSourceController.h" | ||||
#include "DataSource/DataSourceItem.h" | ||||
#include "DataSource/DataSourceTreeWidgetItem.h" | ||||
r1075 | #include "DragAndDrop/DragDropGuiController.h" | |||
r868 | #include "SqpApplication.h" | |||
#include <QMimeData> | ||||
r912 | DataSourceTreeWidget::DataSourceTreeWidget(QWidget *parent) : QTreeWidget(parent) | |||
{ | ||||
} | ||||
r868 | ||||
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; | ||||
} | ||||
} | ||||
auto encodedData = sqpApp->dataSourceController().mimeDataForProductsData(productData); | ||||
mimeData->setData(MIME_TYPE_PRODUCT_LIST, encodedData); | ||||
return mimeData; | ||||
} | ||||
r877 | ||||
void DataSourceTreeWidget::startDrag(Qt::DropActions supportedActions) | ||||
{ | ||||
// Resets the drag&drop operations before it's starting | ||||
r1075 | sqpApp->dragDropGuiController().resetDragAndDrop(); | |||
r877 | QTreeWidget::startDrag(supportedActions); | |||
} | ||||