2025-06-18 10:42:53 +08:00
|
|
|
#include "cpTableWidget.h"
|
|
|
|
|
|
|
|
|
|
#include <QApplication>
|
|
|
|
|
#include <QDrag>
|
2025-11-11 22:30:45 +08:00
|
|
|
#include <QMessageBox>
|
2025-06-18 10:42:53 +08:00
|
|
|
#include <QMimeData>
|
|
|
|
|
#include <QPainter>
|
2025-06-21 14:05:39 +08:00
|
|
|
#include <Util.h>
|
2025-06-25 10:54:04 +08:00
|
|
|
#include <functional>
|
2025-06-18 10:42:53 +08:00
|
|
|
|
2025-06-22 01:17:44 +08:00
|
|
|
#include "GuiUtil/Public.h"
|
|
|
|
|
|
2025-06-18 10:42:53 +08:00
|
|
|
CpTableWidget::CpTableWidget(QWidget* parent) : QTableWidget(parent)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CpTableWidget::~CpTableWidget()
|
|
|
|
|
{
|
2025-06-20 09:45:39 +08:00
|
|
|
}
|
|
|
|
|
|
2025-11-11 22:30:45 +08:00
|
|
|
void CpTableWidget::setIsResource(bool isResource)
|
|
|
|
|
{
|
|
|
|
|
isResource_ = isResource;
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-20 09:45:39 +08:00
|
|
|
void CpTableWidget::dropEvent(QDropEvent* event)
|
|
|
|
|
{
|
2025-11-11 22:30:45 +08:00
|
|
|
if (!isResource_) {
|
|
|
|
|
QMessageBox::information(this, tr("提示"), tr("请先重置搜索结果后操作。"));
|
|
|
|
|
event->ignore();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-20 16:00:18 +08:00
|
|
|
if (!event->mimeData()->hasFormat("application/x-qabstractitemmodeldatalist")) {
|
|
|
|
|
event->ignore();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
QByteArray encoded = event->mimeData()->data("application/x-qabstractitemmodeldatalist");
|
|
|
|
|
QDataStream stream(&encoded, QIODevice::ReadOnly);
|
|
|
|
|
|
2025-09-26 15:43:16 +08:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
|
|
|
|
QPoint pos = event->position().toPoint();
|
|
|
|
|
#else
|
2025-06-21 14:05:39 +08:00
|
|
|
QPoint pos = event->pos();
|
2025-09-26 15:43:16 +08:00
|
|
|
#endif
|
|
|
|
|
|
2025-06-21 14:05:39 +08:00
|
|
|
int startRow = rowAt(pos.y());
|
|
|
|
|
int startCol = columnAt(pos.x());
|
|
|
|
|
if (startCol != 1 && startCol != 2) {
|
|
|
|
|
event->ignore();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-29 11:09:27 +08:00
|
|
|
QStringList parseData;
|
2025-06-20 16:00:18 +08:00
|
|
|
while (!stream.atEnd()) {
|
|
|
|
|
int row, col;
|
|
|
|
|
QMap<int, QVariant> roleData;
|
|
|
|
|
stream >> row >> col >> roleData;
|
2025-06-29 11:09:27 +08:00
|
|
|
parseData.append(roleData[Qt::DisplayRole].toString());
|
2025-06-21 14:05:39 +08:00
|
|
|
}
|
2025-06-29 11:09:27 +08:00
|
|
|
if (parseData.isEmpty()) {
|
2025-06-21 14:05:39 +08:00
|
|
|
event->ignore();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int currentRow = startRow;
|
|
|
|
|
if (currentRow == -1) {
|
|
|
|
|
currentRow = rowCount();
|
|
|
|
|
}
|
2025-06-29 11:09:27 +08:00
|
|
|
|
|
|
|
|
auto setItemData = [this](int row, int col, const QString& data) {
|
|
|
|
|
QTableWidgetItem* item = this->item(row, col);
|
|
|
|
|
if (!item) {
|
|
|
|
|
item = new QTableWidgetItem(data);
|
|
|
|
|
setItem(row, col, item);
|
|
|
|
|
} else {
|
|
|
|
|
item->setText(data);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < (parseData.size() / 5); ++i, ++currentRow) {
|
2025-06-21 14:05:39 +08:00
|
|
|
if (currentRow >= rowCount()) {
|
|
|
|
|
insertRow(rowCount());
|
|
|
|
|
}
|
2025-06-29 11:09:27 +08:00
|
|
|
if (parseData[i * 5 + 3] == "Dir") {
|
|
|
|
|
if (startCol == 1) {
|
|
|
|
|
setItemData(currentRow, startCol, Util::Join(GlobalData::Ins()->GetLocalRoot(), parseData[i * 5 + 1]));
|
|
|
|
|
} else {
|
|
|
|
|
setItemData(currentRow, startCol, Util::Join(GlobalData::Ins()->GetRemoteRoot(), parseData[i * 5 + 1]));
|
|
|
|
|
}
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
setItemData(currentRow, 0, parseData[i * 5 + 1]);
|
|
|
|
|
if (startCol == 1) {
|
|
|
|
|
setItemData(currentRow, 1, GlobalData::Ins()->GetLocalRoot());
|
2025-06-21 14:05:39 +08:00
|
|
|
} else {
|
2025-06-29 11:09:27 +08:00
|
|
|
setItemData(currentRow, 2, GlobalData::Ins()->GetRemoteRoot());
|
2025-06-21 14:05:39 +08:00
|
|
|
}
|
2025-06-20 16:00:18 +08:00
|
|
|
}
|
2025-06-21 14:05:39 +08:00
|
|
|
event->acceptProposedAction();
|
2025-06-18 10:42:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CpTableWidget::dragEnterEvent(QDragEnterEvent* event)
|
|
|
|
|
{
|
2025-06-20 16:00:18 +08:00
|
|
|
if (event->mimeData()->hasFormat("application/x-qabstractitemmodeldatalist")) {
|
|
|
|
|
event->acceptProposedAction();
|
|
|
|
|
} else {
|
|
|
|
|
event->ignore();
|
|
|
|
|
}
|
2025-06-18 10:42:53 +08:00
|
|
|
}
|