service/tray: provide default sorting for SystemTray.items

Items are first sorted by category, and then by name.
This commit is contained in:
outfoxxed 2025-03-27 13:51:43 -07:00
parent 392f56c40e
commit 69430e3873
Signed by untrusted user: outfoxxed
GPG key ID: 4C88A185FB89301E
3 changed files with 30 additions and 2 deletions

View file

@ -1,5 +1,7 @@
#pragma once
#include <functional>
#include <bit>
#include <qabstractitemmodel.h>
#include <qcontainerfwd.h>
@ -98,6 +100,19 @@ public:
this->UntypedObjectModel::insertObject(object, index);
}
void insertObjectSorted(T* object, const std::function<bool(T*, T*)>& compare) {
auto& list = this->valueList();
auto iter = list.begin();
while (iter != list.end()) {
if (!compare(object, *iter)) break;
++iter;
}
auto idx = iter - list.begin();
this->UntypedObjectModel::insertObject(object, idx);
}
void removeObject(const T* object) { this->UntypedObjectModel::removeObject(object); }
// Assumes only one instance of a specific value