fix drop profile behavior

This commit is contained in:
Nova 2025-07-31 17:35:20 +03:30
parent 0b6422d38e
commit 1e1941807e
4 changed files with 15 additions and 4 deletions

View File

@ -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

View File

@ -22,7 +22,7 @@ protected:
const int row_dst = item->row();
if (rowsSwapped)
{
rowsSwapped(row_dst, currentRow());
rowsSwapped(currentRow(), row_dst);
clearSelection();
}
}

View File

@ -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);

View File

@ -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<QAbstractButton *>(QString(), Qt::FindDirectChildrenOnly)) {