Commit 7c0f8516 authored by Isaac True's avatar Isaac True Committed by Christoph Feck

Implement sorting of the device tree items

This patch fixes the issue of processor numbers not being sorted in human-readable order.

It overloads the < operator on the SolDevice class to implement sorting by process number and sorting by storage volume names (as they
should go, e.g.: sda, sda1, sda2...).

BUG: 380355

Reviewed by: cfeck, davidedmundson

Differential Revision: https://phabricator.kde.org/D7155
parent ed7850ba
......@@ -49,6 +49,7 @@ DeviceListing::DeviceListing(QWidget *parent, InfoPanel *info, DevInfoPlugin *st
createMenuActions();
setHeaderLabels(QStringList(i18n("Devices")));
populateListing();
setSortingEnabled(true);
}
DeviceListing::~DeviceListing()
......
......@@ -153,3 +153,28 @@ bool SolDevice::isDeviceSet()
{
return deviceSet;
}
bool SolDevice::operator< ( const QTreeWidgetItem & other ) const
{
const SolDevice * otherDevice = dynamic_cast<const SolDevice*>(&other);
if (otherDevice) {
if (deviceType() != otherDevice->deviceType()) {
return deviceType() < otherDevice->deviceType();
}
switch (deviceType()) {
case Solid::DeviceInterface::Processor: {
const Solid::Processor *left = tiedDevice.as<const Solid::Processor>();
const Solid::Processor *right = otherDevice->tiedDevice.as<const Solid::Processor>();
// Processors are sorted in ascending order, so this is reversed
return left->number() > right->number();
}
case Solid::DeviceInterface::StorageVolume: {
// Storage volumes are sorted in ascending order (i.e. sda, sda1, sda2...)
return text(0) > other.text(0);
}
default:
break;
}
}
return text(0) < other.text(0);
}
......@@ -108,6 +108,7 @@ public:
QString udi() const;
bool isDeviceSet();
bool operator< (const QTreeWidgetItem & other) const;
protected:
void setDeviceText(const QString &);
......
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