Commit b06d50bc authored by David Redondo's avatar David Redondo 🏎
Browse files

Sort groups by their user visible names

For example when adding sensors from a cpu group, the sensors should be sorted
ascending from CPU 1 to CPU n.
parent a09b3ab0
...@@ -20,10 +20,10 @@ ...@@ -20,10 +20,10 @@
#include "SensorFaceController.h" #include "SensorFaceController.h"
#include "SensorFaceController_p.h" #include "SensorFaceController_p.h"
#include "SensorFace_p.h" #include "SensorFace_p.h"
#include <Sensor.h>
#include <SensorQuery.h> #include <SensorQuery.h>
#include <QtQml> #include <QtQml>
#include <QDebug>
#include <KDesktopFile> #include <KDesktopFile>
#include <KDeclarative/ConfigPropertyMap> #include <KDeclarative/ConfigPropertyMap>
...@@ -255,11 +255,11 @@ QJsonArray SensorFaceControllerPrivate::resolveSensors(const QJsonArray &partial ...@@ -255,11 +255,11 @@ QJsonArray SensorFaceControllerPrivate::resolveSensors(const QJsonArray &partial
KSysGuard::SensorQuery query{id.toString()}; KSysGuard::SensorQuery query{id.toString()};
query.execute(); query.execute();
query.waitForFinished(); query.waitForFinished();
auto ids = query.sensorIds(); query.sortByName();
std::stable_sort(ids.begin(), ids.end()); const auto ids = query.sensorIds();
for (const auto &fitleredId : qAsConst(ids)) { std::transform(ids.begin(), ids.end(), std::back_inserter(sensors), [] (const QString &id) {
sensors.append(QJsonValue(fitleredId)); return QJsonValue(id);
} });
} }
return sensors; return sensors;
}; };
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "SensorQuery.h" #include "SensorQuery.h"
#include <QCollator>
#include <QDBusPendingCallWatcher> #include <QDBusPendingCallWatcher>
#include <QDBusReply> #include <QDBusReply>
#include <QRegularExpression> #include <QRegularExpression>
...@@ -110,6 +111,15 @@ QStringList KSysGuard::SensorQuery::sensorIds() const ...@@ -110,6 +111,15 @@ QStringList KSysGuard::SensorQuery::sensorIds() const
return ids; return ids;
} }
void KSysGuard::SensorQuery::sortByName()
{
QCollator collator;
collator.setNumericMode(true);
std::sort(d->result.begin(), d->result.end(), [this, &collator] (const QPair<QString, SensorInfo> &left, const QPair<QString, SensorInfo> &right) {
return collator.compare(left.second.name, right.second.name) < 0;
});
}
QVector<QPair<QString, SensorInfo>> KSysGuard::SensorQuery::result() const QVector<QPair<QString, SensorInfo>> KSysGuard::SensorQuery::result() const
{ {
return d->result; return d->result;
......
...@@ -50,6 +50,10 @@ public: ...@@ -50,6 +50,10 @@ public:
* A list of sensors ids that match the query. * A list of sensors ids that match the query.
*/ */
QStringList sensorIds() const; QStringList sensorIds() const;
/**
* Sort the retrieved sensors by their user visible names.
*/
void sortByName();
/** /**
* Start processing the query. * Start processing the query.
......
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