11#include "gui/models/allmodelcontainers.h"
30using namespace swift::misc::aviation;
31using 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>
58 return QBrush(m_highlightColor);
63 template <
typename T,
typename K,
bool UseCompare>
68 return ObjectType::invalidDbKey();
70 return this->at(index).getDbKey();
73 template <
typename T,
typename K,
bool UseCompare>
80 if (m_highlightKeys.isEmpty())
87 template <
typename T,
typename K,
bool UseCompare>
93 template <
typename T,
typename K,
bool UseCompare>
100 ContainerType container(this->container());
102 if (position >= 0 && position <
container.size())
106 this->setSortColumnToOrder();
107 container.moveTo(items, order);
113 template <
typename T,
typename K,
bool UseCompare>
117 return this->
setSorting(IOrderable::IndexOrder);
120 template <
typename T,
typename K,
bool UseCompare>
126 orderable.resetOrder();
const ContainerType & container() const
QVariant data(const QModelIndex &index, int role) const
virtual int update(const ContainerType &container, bool sort=true)
CListModelBase(const QString &translationContext, QObject *parent=nullptr)
virtual void updateContainerMaybeAsync(const ContainerType &container, bool sort=true)
void sort(int column, Qt::SortOrder order) final
virtual bool setSorting(const swift::misc::CPropertyIndex &propertyIndex, Qt::SortOrder order=Qt::AscendingOrder)
Sorting.
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const final
QModelIndex parent(const QModelIndex &child) const final
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.
CListModelDbObjects(const QString &translationContext, QObject *parent=nullptr)
Constructor.
KeyType dbKeyForIndex(const QModelIndex &index) const
DB key for given index.
bool isHighlightedIndex(const QModelIndex &index) const
Highlight index.
QVariant data(const QModelIndex &index, int role) const
Get data for index and role.
T ContainerType
Container type.
List model for DB objects.
T ContainerType
Container type.
bool setSortColumnToOrder()
Sort order to order property swift::misc::IOrderable::IndexOrder.
int update(const ContainerType &container, bool sort)
Update by new container.
COrderableListModelDbObjects(const QString &translationContext, QObject *parent=nullptr)
Constructor.
void moveItems(const ContainerType &items, int position)
Move items to position, normally called from dropMimeData.
Models to be used with views, mainly QTableView.
Free functions in swift::misc.