Commit c3fe8f7c authored by Carlo Vanini's avatar Carlo Vanini
Browse files

enable sorting by version and installed size

Summary:
The list of packages can now be sorted by any column.

BUG: 390473

Reviewers: sitter

Reviewed By: sitter

Differential Revision: https://phabricator.kde.org/D13412
parent ec14a8f2
...@@ -239,7 +239,7 @@ void PackageDelegate::paintText(QPainter *painter, const QStyleOptionViewItem &o ...@@ -239,7 +239,7 @@ void PackageDelegate::paintText(QPainter *painter, const QStyleOptionViewItem &o
} }
break; break;
case 3: case 3:
text = index.data(PackageModel::InstalledSizeRole).toString(); text = index.data(PackageModel::InstalledSizeDisplayRole).toString();
pen.setBrush(foregroundColor); pen.setBrush(foregroundColor);
break; break;
case 4: case 4:
...@@ -281,7 +281,7 @@ QSize PackageDelegate::sizeHint(const QStyleOptionViewItem &option, const QModel ...@@ -281,7 +281,7 @@ QSize PackageDelegate::sizeHint(const QStyleOptionViewItem &option, const QModel
size.setWidth(metric.width(index.data(PackageModel::ActionRole).toString())); size.setWidth(metric.width(index.data(PackageModel::ActionRole).toString()));
break; break;
case 3: case 3:
size.setWidth(metric.width(index.data(PackageModel::InstalledSizeRole).toString())); size.setWidth(metric.width(index.data(PackageModel::InstalledSizeDisplayRole).toString()));
break; break;
case 4: case 4:
size.setWidth(metric.width(index.data(PackageModel::InstalledVersionRole).toString())); size.setWidth(metric.width(index.data(PackageModel::InstalledVersionRole).toString()));
......
...@@ -64,6 +64,8 @@ QVariant PackageModel::data(const QModelIndex &index, int role) const ...@@ -64,6 +64,8 @@ QVariant PackageModel::data(const QModelIndex &index, int role) const
case SupportRole: case SupportRole:
return package->isSupported(); return package->isSupported();
case InstalledSizeRole: case InstalledSizeRole:
return package->currentInstalledSize();
case InstalledSizeDisplayRole:
if (package->isInstalled()) { if (package->isInstalled()) {
return KFormat().formatByteSize(package->currentInstalledSize()); return KFormat().formatByteSize(package->currentInstalledSize());
} }
......
...@@ -37,8 +37,9 @@ public: ...@@ -37,8 +37,9 @@ public:
StatusRole = Qt::UserRole + 4, StatusRole = Qt::UserRole + 4,
SupportRole = Qt::UserRole + 5, SupportRole = Qt::UserRole + 5,
InstalledSizeRole = Qt::UserRole + 6, InstalledSizeRole = Qt::UserRole + 6,
InstalledVersionRole = Qt::UserRole + 7, InstalledSizeDisplayRole = Qt::UserRole + 7,
AvailableVersionRole = Qt::UserRole + 8 InstalledVersionRole = Qt::UserRole + 8,
AvailableVersionRole = Qt::UserRole + 9
}; };
explicit PackageModel(QObject *parent = 0); explicit PackageModel(QObject *parent = 0);
......
...@@ -207,6 +207,16 @@ bool PackageProxyModel::lessThan(const QModelIndex &left, const QModelIndex &rig ...@@ -207,6 +207,16 @@ bool PackageProxyModel::lessThan(const QModelIndex &left, const QModelIndex &rig
return packageStatusLessThan(leftPackage, rightPackage); return packageStatusLessThan(leftPackage, rightPackage);
case 2: case 2:
return packageRequestedLessThan(leftPackage, rightPackage); return packageRequestedLessThan(leftPackage, rightPackage);
case 3: /* Installed size */
{
qlonglong leftSize = left.data(PackageModel::InstalledSizeRole).toLongLong();
qlonglong rightSize = right.data(PackageModel::InstalledSizeRole).toLongLong();
return leftSize < rightSize;
}
case 4: /* Installed version */
return QApt::Package::compareVersion(leftPackage->installedVersion(), rightPackage->installedVersion()) < 0;
case 5: /* Available version */
return QApt::Package::compareVersion(leftPackage->availableVersion(), rightPackage->availableVersion()) < 0;
} }
return false; return false;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment