compare: drag to compare ui.
This commit is contained in:
@@ -4,15 +4,14 @@
|
||||
#include <QDrag>
|
||||
#include <QMimeData>
|
||||
#include <QPainter>
|
||||
#include <Util.h>
|
||||
|
||||
CpTableWidget::CpTableWidget(QWidget* parent) : QTableWidget(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CpTableWidget::~CpTableWidget()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CpTableWidget::dropEvent(QDropEvent* event)
|
||||
@@ -24,7 +23,15 @@ void CpTableWidget::dropEvent(QDropEvent* event)
|
||||
QByteArray encoded = event->mimeData()->data("application/x-qabstractitemmodeldatalist");
|
||||
QDataStream stream(&encoded, QIODevice::ReadOnly);
|
||||
|
||||
QList<QTableWidgetItem*> draggedItems;
|
||||
QPoint pos = event->pos();
|
||||
int startRow = rowAt(pos.y());
|
||||
int startCol = columnAt(pos.x());
|
||||
if (startCol != 1 && startCol != 2) {
|
||||
event->ignore();
|
||||
return;
|
||||
}
|
||||
|
||||
QStringList draggedData;
|
||||
while (!stream.atEnd()) {
|
||||
int row, col;
|
||||
QMap<int, QVariant> roleData;
|
||||
@@ -32,7 +39,35 @@ void CpTableWidget::dropEvent(QDropEvent* event)
|
||||
if (col != 1) {
|
||||
continue;
|
||||
}
|
||||
draggedData.append(roleData[Qt::DisplayRole].toString());
|
||||
}
|
||||
|
||||
if (draggedData.isEmpty()) {
|
||||
event->ignore();
|
||||
return;
|
||||
}
|
||||
|
||||
int currentRow = startRow;
|
||||
if (currentRow == -1) {
|
||||
currentRow = rowCount();
|
||||
}
|
||||
for (const QString& text : draggedData) {
|
||||
if (currentRow >= rowCount()) {
|
||||
insertRow(rowCount());
|
||||
}
|
||||
QString cur = startCol == 1 ? Util::Join(GlobalData::Ins()->GetLocalRoot(), text)
|
||||
: Util::Join(GlobalData::Ins()->GetRemoteRoot(), text);
|
||||
QTableWidgetItem* item = this->item(currentRow, startCol);
|
||||
if (!item) {
|
||||
item = new QTableWidgetItem(cur);
|
||||
setItem(currentRow, startCol, item);
|
||||
} else {
|
||||
item->setText(cur);
|
||||
}
|
||||
currentRow++;
|
||||
}
|
||||
|
||||
event->acceptProposedAction();
|
||||
}
|
||||
|
||||
void CpTableWidget::dragEnterEvent(QDragEnterEvent* event)
|
||||
@@ -43,5 +78,3 @@ void CpTableWidget::dragEnterEvent(QDragEnterEvent* event)
|
||||
event->ignore();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user