compare: drag to compare ui.
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
cmake_minimum_required(VERSION 3.16)
|
cmake_minimum_required(VERSION 3.16)
|
||||||
|
|
||||||
project(frelay VERSION 0.1.2 LANGUAGES CXX)
|
project(frelay VERSION 0.1.3 LANGUAGES CXX)
|
||||||
set(CMAKE_CXX_STANDARD 11)
|
set(CMAKE_CXX_STANDARD 11)
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
|
|||||||
@@ -41,5 +41,5 @@ void Compare::InitTabWidget()
|
|||||||
ui->tableWidget->viewport()->setAcceptDrops(true);
|
ui->tableWidget->viewport()->setAcceptDrops(true);
|
||||||
ui->tableWidget->setDropIndicatorShown(true);
|
ui->tableWidget->setDropIndicatorShown(true);
|
||||||
ui->tableWidget->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
ui->tableWidget->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
||||||
ui->tableWidget->setDragDropMode(QAbstractItemView::DragDrop);
|
ui->tableWidget->setDragDropMode(QAbstractItemView::DropOnly);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,15 +4,14 @@
|
|||||||
#include <QDrag>
|
#include <QDrag>
|
||||||
#include <QMimeData>
|
#include <QMimeData>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
#include <Util.h>
|
||||||
|
|
||||||
CpTableWidget::CpTableWidget(QWidget* parent) : QTableWidget(parent)
|
CpTableWidget::CpTableWidget(QWidget* parent) : QTableWidget(parent)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CpTableWidget::~CpTableWidget()
|
CpTableWidget::~CpTableWidget()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CpTableWidget::dropEvent(QDropEvent* event)
|
void CpTableWidget::dropEvent(QDropEvent* event)
|
||||||
@@ -24,7 +23,15 @@ void CpTableWidget::dropEvent(QDropEvent* event)
|
|||||||
QByteArray encoded = event->mimeData()->data("application/x-qabstractitemmodeldatalist");
|
QByteArray encoded = event->mimeData()->data("application/x-qabstractitemmodeldatalist");
|
||||||
QDataStream stream(&encoded, QIODevice::ReadOnly);
|
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()) {
|
while (!stream.atEnd()) {
|
||||||
int row, col;
|
int row, col;
|
||||||
QMap<int, QVariant> roleData;
|
QMap<int, QVariant> roleData;
|
||||||
@@ -32,7 +39,35 @@ void CpTableWidget::dropEvent(QDropEvent* event)
|
|||||||
if (col != 1) {
|
if (col != 1) {
|
||||||
continue;
|
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)
|
void CpTableWidget::dragEnterEvent(QDragEnterEvent* event)
|
||||||
@@ -43,5 +78,3 @@ void CpTableWidget::dragEnterEvent(QDragEnterEvent* event)
|
|||||||
event->ignore();
|
event->ignore();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -42,7 +42,6 @@ void CustomTableWidget::dropEvent(QDropEvent* event)
|
|||||||
QDataStream stream(&encoded, QIODevice::ReadOnly);
|
QDataStream stream(&encoded, QIODevice::ReadOnly);
|
||||||
|
|
||||||
QVector<TransTask> tasks;
|
QVector<TransTask> tasks;
|
||||||
QList<QTableWidgetItem*> draggedItems;
|
|
||||||
while (!stream.atEnd()) {
|
while (!stream.atEnd()) {
|
||||||
int row, col;
|
int row, col;
|
||||||
QMap<int, QVariant> roleData;
|
QMap<int, QVariant> roleData;
|
||||||
|
|||||||
Reference in New Issue
Block a user