Ref T529, deterministic sort order when column values are equal

* the Qt model sorts by column
* when multiple values have the same column value the order among those is more or less random
* added additional property indexes to determine the order among the equal values
This commit is contained in:
Klaus Basan
2019-01-30 16:37:32 +01:00
committed by Mat Sutcliffe
parent 17f67d6106
commit 8c15f45007
8 changed files with 50 additions and 15 deletions

View File

@@ -40,8 +40,10 @@ namespace BlackGui
CListModelDbObjects<T, K, UseCompare>::CListModelDbObjects(const QString &translationContext, QObject *parent) :
CListModelBase<ContainerType, UseCompare>(translationContext, parent)
{
CListModelBaseNonTemplate::m_sortTieBreakers.push_front(ObjectType::keyIndex());
constexpr bool hasIntegerKey = std::is_base_of<IDatastoreObjectWithIntegerKey, ObjectType>::value && std::is_same<int, KeyType>::value;
constexpr bool hasStringKey = std::is_base_of<IDatastoreObjectWithStringKey, ObjectType>::value && std::is_base_of<QString, KeyType>::value;
constexpr bool hasStringKey = std::is_base_of<IDatastoreObjectWithStringKey, ObjectType>::value && std::is_base_of<QString, KeyType>::value;
static_assert(hasIntegerKey || hasStringKey, "ObjectType needs to implement IDatastoreObjectWithXXXXKey and have appropriate KeyType");
}
@@ -49,7 +51,7 @@ namespace BlackGui
QVariant CListModelDbObjects<T, K, UseCompare>::data(const QModelIndex &index, int role) const
{
if (role != Qt::BackgroundRole) { return CListModelBase<ContainerType, UseCompare>::data(index, role); }
if (isHighlightedIndex(index) ) { return QBrush(m_highlightColor); }
if (isHighlightedIndex(index)) { return QBrush(m_highlightColor); }
return CListModelBase<ContainerType, UseCompare>::data(index, role);
}