6#ifndef SWIFT_MISC_ORDERABLELIST_H
7#define SWIFT_MISC_ORDERABLELIST_H
17 template <
class OBJ,
class CONTAINER>
20 static_assert(std::is_base_of_v<IOrderable, OBJ>,
"OBJ needs to implement IOrderable");
47 [](
const OBJ &obj) {
return !obj.hasValidOrder(); });
56 if (!obj.hasValidOrder())
60 orders.
append(obj.getOrder());
74 CONTAINER newContainer;
81 newContainer.push_back(obj);
95 CONTAINER newContainer;
102 newContainer.push_back(obj);
108 void moveTo(
const CONTAINER &items,
int targetOrder)
115 CONTAINER newItems(items);
116 const int shift = items.size();
117 newContainer.sortAscendingByOrder();
118 newContainer.resetOrder();
119 for (OBJ &obj : newContainer)
121 if (obj.getOrder() < targetOrder)
125 obj.setOrder(obj.getOrder() + shift);
127 newItems.sortAscendingByOrder();
128 newItems.resetOrder(targetOrder);
129 newContainer.push_back(newItems);
163 if (!obj.hasValidOrder())
167 if (obj.getOrder() < min.getOrder())
185 if (!obj.hasValidOrder())
189 if (obj.getOrder() > max.getOrder())
202 const CONTAINER &
container()
const {
return static_cast<const CONTAINER &
>(*this); }
205 CONTAINER &
container() {
return static_cast<CONTAINER &
>(*this); }
Entity with order attribute (can be manually ordered in views).
const CONTAINER & container() const
Container.
void freezeOrderReverse()
Current reverse order of list will be new order values.
void removeItemsWithSameOrder(const CONTAINER &items)
Remove the items based on their order IOrderable::order.
IOrderableList()=default
Constructor.
void sortAscendingByOrder()
Sort ascending.
void sortDescendingByOrder()
Sort descending.
void moveTo(const CONTAINER &items, int targetOrder)
Move items to given order.
OBJ maxOrderOrDefault() const
Object with max.order or default.
OBJ minOrderOrDefault() const
Object with min.order or default.
CONTAINER withoutItemsOfSameOrder(const CONTAINER &items) const
Items with order will not be included.
void resetOrder(int offset=0)
Set order member to current order.
QList< int > orderValues() const
All order values IOrderable::order.
void freezeOrder()
Current order of list will be new order values.
CONTAINER & container()
Container.
bool needsOrder() const
All order values set or missing some?
auto MemberLess(Ts... vs)
Predicate which compares the return values of some member functions of two objects.
Free functions in swift::misc.
T::const_iterator begin(const LockFreeReader< T > &reader)
Non-member begin() and end() for so LockFree containers can be used in ranged for loops.
T::const_iterator end(const LockFreeReader< T > &reader)
Non-member begin() and end() for so LockFree containers can be used in ranged for loops.
void append(QList< T > &&value)
bool contains(const AT &value) const const
bool isEmpty() const const