diff --git a/discover/qml/UpdatesPage.qml b/discover/qml/UpdatesPage.qml --- a/discover/qml/UpdatesPage.qml +++ b/discover/qml/UpdatesPage.qml @@ -151,7 +151,10 @@ } } - model: updateModel + model: QSortFilterProxyModel { + sourceModel: updateModel + sortRole: UpdateModel.SectionResourceProgressRole + } section { property: "section" diff --git a/libdiscover/UpdateModel/UpdateItem.h b/libdiscover/UpdateModel/UpdateItem.h --- a/libdiscover/UpdateModel/UpdateItem.h +++ b/libdiscover/UpdateModel/UpdateItem.h @@ -36,9 +36,13 @@ ~UpdateItem(); + enum Section { + ApplicationSection, + SystemSection + }; - void setSection(const QString §ion) { m_section = section; } - QString section() const { return m_section; } + void setSection(const Section §ion) { m_section = section; } + Section section() const { return m_section; } void setProgress(qreal progress); qreal progress() const; @@ -61,7 +65,7 @@ const QIcon m_categoryIcon; qreal m_progress; QString m_changelog; - QString m_section; + Section m_section; }; #endif // UPDATEITEM_H diff --git a/libdiscover/UpdateModel/UpdateModel.h b/libdiscover/UpdateModel/UpdateModel.h --- a/libdiscover/UpdateModel/UpdateModel.h +++ b/libdiscover/UpdateModel/UpdateModel.h @@ -44,9 +44,11 @@ SizeRole, ResourceRole, ResourceProgressRole, + SectionResourceProgressRole, ChangelogRole, SectionRole }; + Q_ENUM(Roles) explicit UpdateModel(QObject *parent = nullptr); ~UpdateModel() override; diff --git a/libdiscover/UpdateModel/UpdateModel.cpp b/libdiscover/UpdateModel/UpdateModel.cpp --- a/libdiscover/UpdateModel/UpdateModel.cpp +++ b/libdiscover/UpdateModel/UpdateModel.cpp @@ -87,7 +87,7 @@ item->setProgress(progress); const QModelIndex idx = indexFromItem(item); - Q_EMIT dataChanged(idx, idx, { ResourceProgressRole }); + Q_EMIT dataChanged(idx, idx, { ResourceProgressRole, SectionResourceProgressRole }); } void UpdateModel::activityChanged() @@ -130,8 +130,15 @@ return item->progress(); case ChangelogRole: return item->changelog(); - case SectionRole: - return item->section(); + case SectionRole: { + static const QString appUpdatesSection = i18nc("@item:inlistbox", "Application Updates"); + static const QString systemUpdateSection = i18nc("@item:inlistbox", "System Updates"); + switch(item->section()) { + case UpdateItem::ApplicationSection: return appUpdatesSection; + case UpdateItem::SystemSection: return systemUpdateSection; + } + } case SectionResourceProgressRole: + return (100-item->progress()) + (101 * item->section()); default: break; } @@ -216,19 +223,17 @@ qDeleteAll(m_updateItems); m_updateItems.clear(); - const QString appUpdatesSection = i18nc("@item:inlistbox", "Application Updates"); - const QString systemUpdateSection = i18nc("@item:inlistbox", "System Updates"); QVector appItems, systemItems; foreach(AbstractResource* res, resources) { connect(res, &AbstractResource::changelogFetched, this, &UpdateModel::integrateChangelog, Qt::UniqueConnection); UpdateItem *updateItem = new UpdateItem(res); if(!res->isTechnical()) { - updateItem->setSection(appUpdatesSection); + updateItem->setSection(UpdateItem::ApplicationSection); appItems += updateItem; } else { - updateItem->setSection(systemUpdateSection); + updateItem->setSection(UpdateItem::SystemSection); systemItems += updateItem; } }