fix: Revert commit - Improve sorting performance
The proper fix will be handled in another task
This commit is contained in:
parent
67a7f727a6
commit
b176badf6e
|
@ -350,10 +350,10 @@ bool QQmlSortFilterProxyModel::lessThan(const QModelIndex& source_left, const QM
|
||||||
{
|
{
|
||||||
if (m_completed) {
|
if (m_completed) {
|
||||||
if (!m_sortRoleName.isEmpty()) {
|
if (!m_sortRoleName.isEmpty()) {
|
||||||
if (m_ascendingSortOrder)
|
if (QSortFilterProxyModel::lessThan(source_left, source_right))
|
||||||
return QSortFilterProxyModel::lessThan(source_left, source_right);
|
return m_ascendingSortOrder;
|
||||||
else
|
if (QSortFilterProxyModel::lessThan(source_right, source_left))
|
||||||
return QSortFilterProxyModel::lessThan(source_right, source_left);
|
return !m_ascendingSortOrder;
|
||||||
}
|
}
|
||||||
auto sortedSorters = m_sorters;
|
auto sortedSorters = m_sorters;
|
||||||
std::stable_sort(sortedSorters.begin(),
|
std::stable_sort(sortedSorters.begin(),
|
||||||
|
@ -364,7 +364,8 @@ bool QQmlSortFilterProxyModel::lessThan(const QModelIndex& source_left, const QM
|
||||||
for(auto sorter : sortedSorters) {
|
for(auto sorter : sortedSorters) {
|
||||||
if (sorter->enabled()) {
|
if (sorter->enabled()) {
|
||||||
int comparison = sorter->compareRows(source_left, source_right, *this);
|
int comparison = sorter->compareRows(source_left, source_right, *this);
|
||||||
return comparison == -1;
|
if (comparison != 0)
|
||||||
|
return comparison < 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,7 +59,6 @@ void ExpressionSorter::setExpression(const QQmlScriptString& scriptString)
|
||||||
|
|
||||||
void ExpressionSorter::proxyModelCompleted(const QQmlSortFilterProxyModel& proxyModel)
|
void ExpressionSorter::proxyModelCompleted(const QQmlSortFilterProxyModel& proxyModel)
|
||||||
{
|
{
|
||||||
Sorter::proxyModelCompleted(proxyModel);
|
|
||||||
updateContext(proxyModel);
|
updateContext(proxyModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,8 +48,6 @@ int FilterSorter::compare(const QModelIndex& sourceLeft, const QModelIndex& sour
|
||||||
|
|
||||||
void FilterSorter::proxyModelCompleted(const QQmlSortFilterProxyModel& proxyModel)
|
void FilterSorter::proxyModelCompleted(const QQmlSortFilterProxyModel& proxyModel)
|
||||||
{
|
{
|
||||||
Sorter::proxyModelCompleted(proxyModel);
|
|
||||||
|
|
||||||
for (Filter* filter : qAsConst(m_filters))
|
for (Filter* filter : qAsConst(m_filters))
|
||||||
filter->proxyModelCompleted(proxyModel);
|
filter->proxyModelCompleted(proxyModel);
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,20 +107,21 @@ void Sorter::setPriority(int priority)
|
||||||
|
|
||||||
int Sorter::compareRows(const QModelIndex &source_left, const QModelIndex &source_right, const QQmlSortFilterProxyModel& proxyModel) const
|
int Sorter::compareRows(const QModelIndex &source_left, const QModelIndex &source_right, const QQmlSortFilterProxyModel& proxyModel) const
|
||||||
{
|
{
|
||||||
if (m_sortOrder == Qt::AscendingOrder)
|
int comparison = compare(source_left, source_right, proxyModel);
|
||||||
return compare(source_left, source_right, proxyModel);
|
return (m_sortOrder == Qt::AscendingOrder) ? comparison : -comparison;
|
||||||
else
|
|
||||||
return compare(source_right, source_left, proxyModel);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int Sorter::compare(const QModelIndex &sourceLeft, const QModelIndex &sourceRight, const QQmlSortFilterProxyModel& proxyModel) const
|
int Sorter::compare(const QModelIndex &sourceLeft, const QModelIndex &sourceRight, const QQmlSortFilterProxyModel& proxyModel) const
|
||||||
{
|
{
|
||||||
return lessThan(sourceLeft, sourceRight, proxyModel) ? -1 : 1;
|
if (lessThan(sourceLeft, sourceRight, proxyModel))
|
||||||
|
return -1;
|
||||||
|
if (lessThan(sourceRight, sourceLeft, proxyModel))
|
||||||
|
return 1;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sorter::proxyModelCompleted(const QQmlSortFilterProxyModel& proxyModel)
|
void Sorter::proxyModelCompleted(const QQmlSortFilterProxyModel& proxyModel)
|
||||||
{
|
{
|
||||||
m_proxyCompleted = true;
|
|
||||||
Q_UNUSED(proxyModel)
|
Q_UNUSED(proxyModel)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,7 +135,7 @@ bool Sorter::lessThan(const QModelIndex &sourceLeft, const QModelIndex &sourceRi
|
||||||
|
|
||||||
void Sorter::invalidate()
|
void Sorter::invalidate()
|
||||||
{
|
{
|
||||||
if (m_enabled && m_proxyCompleted)
|
if (m_enabled)
|
||||||
Q_EMIT invalidated();
|
Q_EMIT invalidated();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,14 +45,12 @@ Q_SIGNALS:
|
||||||
protected:
|
protected:
|
||||||
virtual int compare(const QModelIndex& sourceLeft, const QModelIndex& sourceRight, const QQmlSortFilterProxyModel& proxyModel) const;
|
virtual int compare(const QModelIndex& sourceLeft, const QModelIndex& sourceRight, const QQmlSortFilterProxyModel& proxyModel) const;
|
||||||
virtual bool lessThan(const QModelIndex& sourceLeft, const QModelIndex& sourceRight, const QQmlSortFilterProxyModel& proxyModel) const;
|
virtual bool lessThan(const QModelIndex& sourceLeft, const QModelIndex& sourceRight, const QQmlSortFilterProxyModel& proxyModel) const;
|
||||||
virtual void invalidate();
|
void invalidate();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_enabled = true;
|
bool m_enabled = true;
|
||||||
Qt::SortOrder m_sortOrder = Qt::AscendingOrder;
|
Qt::SortOrder m_sortOrder = Qt::AscendingOrder;
|
||||||
int m_priority = 0;
|
int m_priority = 0;
|
||||||
|
|
||||||
bool m_proxyCompleted = false;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue