mirror of
https://github.com/Mahdi-zarei/nekoray.git
synced 2025-12-24 02:20:16 +08:00
fix drop event for now...
This commit is contained in:
parent
6d384b08ea
commit
ce6cfe3584
@ -32,7 +32,9 @@ public:
|
|||||||
id2Row[id] = i;
|
id2Row[id] = i;
|
||||||
}
|
}
|
||||||
if (callback_save_order != nullptr && saveToFile)
|
if (callback_save_order != nullptr && saveToFile)
|
||||||
|
{
|
||||||
callback_save_order();
|
callback_save_order();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void update_order(bool saveToFile) {
|
void update_order(bool saveToFile) {
|
||||||
@ -46,28 +48,20 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/*
|
|
||||||
* 2021.7.6 by gy
|
|
||||||
* 拖拽 继承QTableWidget overwrite dropEvent事件
|
|
||||||
* 功能:拖动一行到鼠标落下的位置
|
|
||||||
* 注意:DragDropMode相关参数的设置
|
|
||||||
*/
|
|
||||||
void dropEvent(QDropEvent *event) override {
|
void dropEvent(QDropEvent *event) override {
|
||||||
if (order.isEmpty()) order = row2Id;
|
if (order.isEmpty()) return;
|
||||||
|
|
||||||
// 原行号与目标行号的确定
|
|
||||||
int row_src, row_dst;
|
int row_src, row_dst;
|
||||||
row_src = this->currentRow(); // 原行号 可加if
|
row_src = this->currentRow();
|
||||||
auto id_src = row2Id[row_src]; // id_src
|
auto id_src = row2Id[row_src];
|
||||||
QTableWidgetItem *item = this->itemAt(event->position().toPoint()); // 获取落点的item
|
QTableWidgetItem *item = this->itemAt(event->position().toPoint());
|
||||||
if (item != nullptr) {
|
if (item != nullptr) {
|
||||||
// 判断是否为空
|
row_dst = item->row();
|
||||||
row_dst = item->row(); // 不为空 获取其行号
|
|
||||||
// Modify order
|
// Modify order
|
||||||
|
row2Id.swapItemsAt(row_src, row_dst);
|
||||||
order.removeAt(row_src);
|
order.removeAt(row_src);
|
||||||
order.insert(row_dst, id_src);
|
order.insert(row_dst, id_src);
|
||||||
} else {
|
} else {
|
||||||
// 落点没有item 说明拖动到了最下面
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user