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 @@
#include "SensorFaceController.h"
#include "SensorFaceController_p.h"
#include "SensorFace_p.h"
#include <Sensor.h>
#include <SensorQuery.h>
#include <QtQml>
#include <QDebug>
#include <KDesktopFile>
#include <KDeclarative/ConfigPropertyMap>
......@@ -255,11 +255,11 @@ QJsonArray SensorFaceControllerPrivate::resolveSensors(const QJsonArray &partial
KSysGuard::SensorQuery query{id.toString()};
query.execute();
query.waitForFinished();
auto ids = query.sensorIds();
std::stable_sort(ids.begin(), ids.end());
for (const auto &fitleredId : qAsConst(ids)) {
sensors.append(QJsonValue(fitleredId));
}
query.sortByName();
const auto ids = query.sensorIds();
std::transform(ids.begin(), ids.end(), std::back_inserter(sensors), [] (const QString &id) {
return QJsonValue(id);
});
}
return sensors;
};
......
......@@ -19,6 +19,7 @@
#include "SensorQuery.h"
#include <QCollator>
#include <QDBusPendingCallWatcher>
#include <QDBusReply>
#include <QRegularExpression>
......@@ -110,6 +111,15 @@ QStringList KSysGuard::SensorQuery::sensorIds() const
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
{
return d->result;
......
......@@ -50,6 +50,10 @@ public:
* A list of sensors ids that match the query.
*/
QStringList sensorIds() const;
/**
* Sort the retrieved sensors by their user visible names.
*/
void sortByName();
/**
* 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