11 #include "gui/models/allmodelcontainers.h"
30 using namespace swift::misc::aviation;
31 using namespace swift::misc::db;
35 template <
typename T,
typename K,
bool UseCompare>
41 constexpr
bool hasIntegerKey =
42 std::is_base_of_v<IDatastoreObjectWithIntegerKey, ObjectType> && std::is_same_v<int, KeyType>;
43 constexpr
bool hasStringKey =
44 std::is_base_of_v<IDatastoreObjectWithStringKey, ObjectType> && std::is_base_of_v<QString, KeyType>;
45 static_assert(hasIntegerKey || hasStringKey,
46 "ObjectType needs to implement IDatastoreObjectWithXXXXKey and have appropriate KeyType");
49 template <
typename T,
typename K,
bool UseCompare>
53 if (isHighlightedIndex(index)) {
return QBrush(m_highlightColor); }
57 template <
typename T,
typename K,
bool UseCompare>
60 if (!index.isValid()) {
return ObjectType::invalidDbKey(); }
61 return this->at(index).getDbKey();
64 template <
typename T,
typename K,
bool UseCompare>
67 if (!index.isValid()) {
return false; }
68 if (m_highlightKeys.isEmpty()) {
return false; }
69 return m_highlightKeys.contains(dbKeyForIndex(index));
72 template <
typename T,
typename K,
bool UseCompare>
78 template <
typename T,
typename K,
bool UseCompare>
81 if (items.isEmpty()) {
return; }
84 if (position >= 0 && position < container.size()) { order = container[position].getOrder(); }
85 this->setSortColumnToOrder();
86 container.moveTo(items, order);
89 this->updateContainerMaybeAsync(container);
92 template <
typename T,
typename K,
bool UseCompare>
96 return this->setSorting(IOrderable::IndexOrder);
99 template <
typename T,
typename K,
bool UseCompare>
102 if (container.needsOrder())
105 orderable.resetOrder();
QVariant data(const QModelIndex &index, int role) const
T ContainerType
Container type.
virtual int update(const ContainerType &container, bool sort=true)
Update by new container.
swift::misc::CPropertyIndexList m_sortTieBreakers
how column values are sorted if equal, if no value is given this is random
List model for DB objects.
KeyType dbKeyForIndex(const QModelIndex &index) const
DB key for given index.
bool isHighlightedIndex(const QModelIndex &index) const
Highlight index.
virtual QVariant data(const QModelIndex &index, int role) const
Get data for index and role.
T ContainerType
Container type.
bool setSortColumnToOrder()
Sort order to order property swift::misc::IOrderable::IndexOrder.
virtual int update(const ContainerType &container, bool sort)
Update by new container.
COrderableListModelDbObjects(const QString &translationContext, QObject *parent=nullptr)
Constructor.
virtual void moveItems(const ContainerType &items, int position)
Move items to position, normally called from dropMimeData.
void push_front(const T &value)
Insert as first element.
Models to be used with views, mainly QTableView.
Free functions in swift::misc.