forked from quickshell/quickshell
service/tray: provide default sorting for SystemTray.items
Items are first sorted by category, and then by name.
This commit is contained in:
parent
392f56c40e
commit
69430e3873
3 changed files with 30 additions and 2 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue