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
}
break;
case 3:
text = index.data(PackageModel::InstalledSizeRole).toString();
text = index.data(PackageModel::InstalledSizeDisplayRole).toString();
pen.setBrush(foregroundColor);
break;
case 4:
......@@ -281,7 +281,7 @@ QSize PackageDelegate::sizeHint(const QStyleOptionViewItem &option, const QModel
size.setWidth(metric.width(index.data(PackageModel::ActionRole).toString()));
break;
case 3:
size.setWidth(metric.width(index.data(PackageModel::InstalledSizeRole).toString()));
size.setWidth(metric.width(index.data(PackageModel::InstalledSizeDisplayRole).toString()));
break;
case 4:
size.setWidth(metric.width(index.data(PackageModel::InstalledVersionRole).toString()));
......
......@@ -64,6 +64,8 @@ QVariant PackageModel::data(const QModelIndex &index, int role) const
case SupportRole:
return package->isSupported();
case InstalledSizeRole:
return package->currentInstalledSize();
case InstalledSizeDisplayRole:
if (package->isInstalled()) {
return KFormat().formatByteSize(package->currentInstalledSize());
}
......
......@@ -37,8 +37,9 @@ public:
StatusRole = Qt::UserRole + 4,
SupportRole = Qt::UserRole + 5,
InstalledSizeRole = Qt::UserRole + 6,
InstalledVersionRole = Qt::UserRole + 7,
AvailableVersionRole = Qt::UserRole + 8
InstalledSizeDisplayRole = Qt::UserRole + 7,
InstalledVersionRole = Qt::UserRole + 8,
AvailableVersionRole = Qt::UserRole + 9
};
explicit PackageModel(QObject *parent = 0);
......
......@@ -207,6 +207,16 @@ bool PackageProxyModel::lessThan(const QModelIndex &left, const QModelIndex &rig
return packageStatusLessThan(leftPackage, rightPackage);
case 2:
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;
......
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