diff --git a/Modules/devinfo/devicelisting.cpp b/Modules/devinfo/devicelisting.cpp --- a/Modules/devinfo/devicelisting.cpp +++ b/Modules/devinfo/devicelisting.cpp @@ -49,6 +49,7 @@ createMenuActions(); setHeaderLabels(QStringList(i18n("Devices"))); populateListing(); + setSortingEnabled(true); } DeviceListing::~DeviceListing() diff --git a/Modules/devinfo/soldevice.h b/Modules/devinfo/soldevice.h --- a/Modules/devinfo/soldevice.h +++ b/Modules/devinfo/soldevice.h @@ -108,6 +108,7 @@ QString udi() const; bool isDeviceSet(); + bool operator< (const QTreeWidgetItem & other) const; protected: void setDeviceText(const QString &); diff --git a/Modules/devinfo/soldevice.cpp b/Modules/devinfo/soldevice.cpp --- a/Modules/devinfo/soldevice.cpp +++ b/Modules/devinfo/soldevice.cpp @@ -153,3 +153,28 @@ { return deviceSet; } + +bool SolDevice::operator< ( const QTreeWidgetItem & other ) const +{ + const SolDevice * otherDevice = dynamic_cast(&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 *right = otherDevice->tiedDevice.as(); + // 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); +}