summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleix Pol <[email protected]>2016-10-25 19:48:37 +0200
committerAleix Pol <[email protected]>2016-10-25 19:48:37 +0200
commit079eb38aa073fa89d672d1d652e37c816ec90635 (patch)
treef4c8215fdf6de32ad1971e62d66ec3f823b87e6b
parentdddf06175b64fdefcf79a2062b4970d5355fbd31 (diff)
Don't sort everything over only because a resource moved
-rw-r--r--libdiscover/resources/ResourcesProxyModel.cpp32
-rw-r--r--libdiscover/resources/ResourcesProxyModel.h1
2 files changed, 21 insertions, 12 deletions
diff --git a/libdiscover/resources/ResourcesProxyModel.cpp b/libdiscover/resources/ResourcesProxyModel.cpp
index 5dd6a04..0472a4e 100644
--- a/libdiscover/resources/ResourcesProxyModel.cpp
+++ b/libdiscover/resources/ResourcesProxyModel.cpp
@@ -412,19 +412,23 @@ QVariant ResourcesProxyModel::roleToValue(AbstractResource* resource, int role)
}
}
+void ResourcesProxyModel::sortedInsertion(AbstractResource* resource)
+{
+ const auto finder = [this, resource](AbstractResource* res){ return lessThan(res, resource); };
+ const auto it = std::find_if(m_displayedResources.constBegin(), m_displayedResources.constEnd(), finder);
+ const auto newIdx = it == m_displayedResources.constEnd() ? m_displayedResources.count() : (it - m_displayedResources.constBegin());
+
+ beginInsertRows({}, newIdx, newIdx);
+ m_displayedResources.insert(newIdx, resource);
+ endInsertRows();
+}
+
void ResourcesProxyModel::refreshResource(AbstractResource* resource, const QVector<QByteArray>& properties)
{
const auto residx = m_displayedResources.indexOf(resource);
- auto include = m_filters.shouldFilter(resource);
if (residx<0) {
- if (include) {
- const auto finder = [this, resource](AbstractResource* res){ return lessThan(res, resource); };
- const auto it = std::find_if(m_displayedResources.constBegin(), m_displayedResources.constEnd(), finder);
- auto newIdx = it == m_displayedResources.constEnd() ? m_displayedResources.count() : (it - m_displayedResources.constBegin());
-
- beginInsertRows({}, newIdx, newIdx);
- m_displayedResources.insert(newIdx, resource);
- endInsertRows();
+ if (m_filters.shouldFilter(resource)) {
+ sortedInsertion(resource);
}
return;
}
@@ -439,9 +443,13 @@ void ResourcesProxyModel::refreshResource(AbstractResource* resource, const QVec
const QModelIndex idx = index(residx, 0);
Q_ASSERT(idx.isValid());
const auto roles = propertiesToRoles(properties);
- if (roles.contains(m_sortRole))
- invalidateSorting();
- else
+ if (roles.contains(m_sortRole)) {
+ beginRemoveRows({}, residx, residx);
+ m_displayedResources.removeAt(residx);
+ endRemoveRows();
+
+ sortedInsertion(resource);
+ } else
emit dataChanged(idx, idx, roles);
}
diff --git a/libdiscover/resources/ResourcesProxyModel.h b/libdiscover/resources/ResourcesProxyModel.h
index b196901..249f311 100644
--- a/libdiscover/resources/ResourcesProxyModel.h
+++ b/libdiscover/resources/ResourcesProxyModel.h
@@ -99,6 +99,7 @@ private Q_SLOTS:
void refreshResource(AbstractResource* resource, const QVector<QByteArray>& properties);
void removeResource(AbstractResource* resource);
private:
+ void sortedInsertion(AbstractResource* res);
QVariant roleToValue(AbstractResource* res, int role) const;
QVector<int> propertiesToRoles(const QVector<QByteArray>& properties) const;