Merge pull request #602 from 0-Kutya-0/dev

added sorting by Outbound and Protocol
This commit is contained in:
parhelia512 2025-08-04 09:00:39 -04:00 committed by GitHub
commit fb460c4711
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 37 additions and 21 deletions

View File

@ -12,7 +12,9 @@ namespace Stats
ByDownload,
ByUpload,
ByProcess,
ByTraffic
ByTraffic,
ByOutbound,
ByProtocol
};
class ConnectionMetadata

View File

@ -441,11 +441,17 @@
<property name="text">
<string>Protocol</string>
</property>
<property name="toolTip">
<string>Click To Sort By Protocol</string>
</property>
</column>
<column>
<property name="text">
<string>Outbound</string>
</property>
<property name="toolTip">
<string>Click To Sort By Outbound</string>
</property>
</column>
<column>
<property name="text">

View File

@ -114,6 +114,22 @@ namespace Stats
return asc ? a.process > b.process : a.process < b.process;
});
}
if (sort == ByOutbound)
{
std::sort(sorted.begin(), sorted.end(), [=](const ConnectionMetadata& a, const ConnectionMetadata& b)
{
if (a.outbound == b.outbound) return asc ? a.id > b.id : a.id < b.id;
return asc ? a.outbound > b.outbound : a.outbound < b.outbound;
});
}
if (sort == ByProtocol)
{
std::sort(sorted.begin(), sorted.end(), [=](const ConnectionMetadata& a, const ConnectionMetadata& b)
{
if (a.protocol == b.protocol) return asc ? a.id > b.id : a.id < b.id;
return asc ? a.protocol > b.protocol : a.protocol < b.protocol;
});
}
runOnUiThread([=] {
auto m = GetMainWindow();
m->UpdateConnectionListWithRecreate(sorted);

View File

@ -235,27 +235,19 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
});
connect(ui->connections->horizontalHeader(), &QHeaderView::sectionClicked, this, [=](int index)
{
// TODO this is a very bad idea to hardcode it like this, need to refactor it later
if (index == 0)
{
Stats::connection_lister->setSort(Stats::Default);
Stats::ConnectionSort sortType;
switch (index)
{
case 1: sortType = Stats::ByProcess; break;
case 2: sortType = Stats::ByProtocol; break;
case 3: sortType = Stats::ByOutbound; break;
case 4: sortType = Stats::ByTraffic; break;
default: sortType = Stats::Default; break;
}
Stats::connection_lister->setSort(sortType);
Stats::connection_lister->ForceUpdate();
}
if (index == 2 || index == 3)
{
// ignore
return;
}
if (index == 1)
{
Stats::connection_lister->setSort(Stats::ByProcess);
Stats::connection_lister->ForceUpdate();
}
if (index == 4)
{
Stats::connection_lister->setSort(Stats::ByTraffic);
Stats::connection_lister->ForceUpdate();
}
});
// setup Speed Chart