From 1e1941807e0a2627834e2a071a568ec3bad4dd1a Mon Sep 17 00:00:00 2001 From: Nova Date: Thu, 31 Jul 2025 17:35:20 +0330 Subject: [PATCH] fix drop profile behavior --- include/dataStore/Group.hpp | 2 ++ include/ui/utils/MyTableWidget.h | 2 +- src/dataStore/Group.cpp | 9 +++++++++ src/ui/mainwindow.cpp | 6 +++--- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/include/dataStore/Group.hpp b/include/dataStore/Group.hpp index c55bd83..addd4cc 100644 --- a/include/dataStore/Group.hpp +++ b/include/dataStore/Group.hpp @@ -34,6 +34,8 @@ namespace Configs bool SwapProfiles(int idx1, int idx2); + bool EmplaceProfile(int idx, int newIdx); + bool HasProfile(int id) const; }; }// namespace Configs diff --git a/include/ui/utils/MyTableWidget.h b/include/ui/utils/MyTableWidget.h index 3690d10..d3c8938 100644 --- a/include/ui/utils/MyTableWidget.h +++ b/include/ui/utils/MyTableWidget.h @@ -22,7 +22,7 @@ protected: const int row_dst = item->row(); if (rowsSwapped) { - rowsSwapped(row_dst, currentRow()); + rowsSwapped(currentRow(), row_dst); clearSelection(); } } diff --git a/src/dataStore/Group.cpp b/src/dataStore/Group.cpp index a4bfa55..f607903 100644 --- a/src/dataStore/Group.cpp +++ b/src/dataStore/Group.cpp @@ -58,6 +58,15 @@ namespace Configs return true; } + bool Group::EmplaceProfile(int idx, int newIdx) + { + if (profiles.size() <= idx || profiles.size() <= newIdx) return false; + profiles.insert(newIdx+1, profiles[idx]); + if (idx < newIdx) profiles.remove(idx); + else profiles.remove(idx+1); + return true; + } + bool Group::HasProfile(int id) const { return profiles.contains(id); diff --git a/src/ui/mainwindow.cpp b/src/ui/mainwindow.cpp index f745a06..0f00209 100644 --- a/src/ui/mainwindow.cpp +++ b/src/ui/mainwindow.cpp @@ -267,10 +267,10 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi // table UI ui->proxyListTable->rowsSwapped = [=](int row1, int row2) { + if (row1 == row2) return; auto group = Configs::profileManager->CurrentGroup(); - group->SwapProfiles(row1, row2); - refresh_proxy_list(group->profiles[row1]); - refresh_proxy_list(group->profiles[row2]); + group->EmplaceProfile(row1, row2); + refresh_proxy_list(); group->Save(); }; if (auto button = ui->proxyListTable->findChild(QString(), Qt::FindDirectChildrenOnly)) {