mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-05-04 04:13:49 +00:00
feat: restore multithreaded processing
This commit is contained in:
parent
ac52888b0d
commit
43d02182de
@ -191,10 +191,6 @@ KCM.SimpleKCM {
|
||||
Component.onCompleted: {
|
||||
// init submodule
|
||||
awKeys.updateCache()
|
||||
|
||||
// update hdd model
|
||||
hdd.model = awKeys.getHddDevices()
|
||||
hdd.onCompleted
|
||||
}
|
||||
|
||||
Component.onDestruction: {
|
||||
|
@ -139,9 +139,16 @@ void AWDataEngineAggregator::sensorRemoved(const QString &_sensor)
|
||||
}
|
||||
|
||||
|
||||
void AWDataEngineAggregator::updateData(KSysGuard::SensorDataList _data)
|
||||
void AWDataEngineAggregator::updateData(const KSysGuard::SensorDataList &_data)
|
||||
{
|
||||
emit(dataUpdated(m_sensors, _data));
|
||||
auto data = std::accumulate(
|
||||
_data.cbegin(), _data.cend(), QHash<QString, QPair<KSysGuard::SensorInfo, QVariant>>(),
|
||||
[this](auto current, auto &single) {
|
||||
if (m_sensors.contains(single.sensorProperty))
|
||||
current[single.sensorProperty] = {m_sensors.value(single.sensorProperty), single.payload};
|
||||
return current;
|
||||
});
|
||||
emit(dataUpdated(data));
|
||||
}
|
||||
|
||||
|
||||
|
@ -42,14 +42,14 @@ public:
|
||||
void loadSources();
|
||||
|
||||
signals:
|
||||
void dataUpdated(const QHash<QString, KSysGuard::SensorInfo> &_sensors, const KSysGuard::SensorDataList &_data);
|
||||
void dataUpdated(const QHash<QString, QPair<KSysGuard::SensorInfo, QVariant>> &_data);
|
||||
void deviceAdded(const QString &_source);
|
||||
|
||||
public slots:
|
||||
void dropSource(const QString &_source);
|
||||
void sensorAdded(const QString &_sensor);
|
||||
void sensorRemoved(const QString &_sensor);
|
||||
void updateData(KSysGuard::SensorDataList _data);
|
||||
void updateData(const KSysGuard::SensorDataList &_data);
|
||||
void updateSensors(const QHash<QString, KSysGuard::SensorInfo> &_sensors);
|
||||
|
||||
private:
|
||||
|
@ -64,7 +64,12 @@ AWKeys::AWKeys(QObject *_parent)
|
||||
[this](const QString &_tooltip) { emit(needToolTipToBeUpdated(_tooltip)); });
|
||||
|
||||
connect(this, &AWKeys::dropSourceFromDataengine, m_dataEngineAggregator, &AWDataEngineAggregator::dropSource);
|
||||
connect(m_dataEngineAggregator, &AWDataEngineAggregator::dataUpdated, this, &AWKeys::dataUpdated);
|
||||
connect(m_dataEngineAggregator, &AWDataEngineAggregator::dataUpdated, [this](auto &_data) {
|
||||
QtConcurrent::map(m_threadPool, _data.keys(), [this, _data](auto &source) {
|
||||
auto data = _data[source];
|
||||
setDataBySource(source, data.first, data.second);
|
||||
}).waitForFinished();
|
||||
});
|
||||
// transfer signal from dataengine to update source list
|
||||
connect(m_dataEngineAggregator, &AWDataEngineAggregator::deviceAdded, m_keyOperator, &AWKeyOperations::addDevice);
|
||||
}
|
||||
@ -153,26 +158,6 @@ QStringList AWKeys::dictKeys(const bool _sorted, const QString &_regexp) const
|
||||
}
|
||||
|
||||
|
||||
QVariantList AWKeys::getHddDevices() const
|
||||
{
|
||||
QStringList hddDevices = m_keyOperator->devices("hdd");
|
||||
// required by selector in the UI
|
||||
hddDevices.insert(0, "disable");
|
||||
hddDevices.insert(0, "auto");
|
||||
|
||||
// build model
|
||||
QVariantList devices;
|
||||
for (auto &device : hddDevices) {
|
||||
QVariantMap model;
|
||||
model["label"] = device;
|
||||
model["name"] = device;
|
||||
devices.append(model);
|
||||
}
|
||||
|
||||
return devices;
|
||||
}
|
||||
|
||||
|
||||
QString AWKeys::infoByKey(const QString &_key) const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Requested info for key" << _key;
|
||||
@ -200,18 +185,6 @@ void AWKeys::editItem(const QString &_type)
|
||||
}
|
||||
|
||||
|
||||
void AWKeys::dataUpdated(const QHash<QString, KSysGuard::SensorInfo> &_sensors, const KSysGuard::SensorDataList &_data)
|
||||
{
|
||||
for (auto &single : _data) {
|
||||
if (_sensors.contains(single.sensorProperty)) {
|
||||
setDataBySource(single.sensorProperty, _sensors.value(single.sensorProperty), single);
|
||||
}
|
||||
// TODO use QtConcurrent::map or something like that
|
||||
// QtConcurrent::run(m_threadPool, this, &AWKeys::setDataBySource, "ss", sensor);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void AWKeys::reinitKeys(const QStringList &_currentKeys)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Update found keys by using list" << _currentKeys;
|
||||
@ -357,10 +330,9 @@ QString AWKeys::parsePattern(QString _pattern) const
|
||||
}
|
||||
|
||||
|
||||
void AWKeys::setDataBySource(const QString &_source, const KSysGuard::SensorInfo &_sensor,
|
||||
const KSysGuard::SensorData &_data)
|
||||
void AWKeys::setDataBySource(const QString &_source, const KSysGuard::SensorInfo &_sensor, const QVariant &_value)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Source" << _source << _sensor.name << "with data" << _data.payload;
|
||||
qCDebug(LOG_AW) << "Source" << _source << _sensor.name << "with data" << _value;
|
||||
|
||||
// first list init
|
||||
auto tags = m_aggregator->keysFromSource(_source);
|
||||
@ -374,6 +346,6 @@ void AWKeys::setDataBySource(const QString &_source, const KSysGuard::SensorInfo
|
||||
}
|
||||
|
||||
m_mutex.lock();
|
||||
std::for_each(tags.cbegin(), tags.cend(), [this, &_data](const QString &tag) { m_values[tag] = _data.payload; });
|
||||
std::for_each(tags.cbegin(), tags.cend(), [this, _value](const QString &tag) { m_values[tag] = _value; });
|
||||
m_mutex.unlock();
|
||||
}
|
||||
|
@ -46,16 +46,12 @@ public:
|
||||
Q_INVOKABLE void updateCache();
|
||||
// keys
|
||||
Q_INVOKABLE [[nodiscard]] QStringList dictKeys(bool _sorted = false, const QString &_regexp = "") const;
|
||||
Q_INVOKABLE [[nodiscard]] QVariantList getHddDevices() const;
|
||||
// values
|
||||
Q_INVOKABLE [[nodiscard]] QString infoByKey(const QString &_key) const;
|
||||
Q_INVOKABLE [[nodiscard]] QString valueByKey(const QString &_key) const;
|
||||
// configuration
|
||||
Q_INVOKABLE void editItem(const QString &_type);
|
||||
|
||||
public slots:
|
||||
void dataUpdated(const QHash<QString, KSysGuard::SensorInfo> &_sensors, const KSysGuard::SensorDataList &_data);
|
||||
|
||||
signals:
|
||||
void dropSourceFromDataengine(const QString &_source);
|
||||
void needTextToBeUpdated(const QString &_newText) const;
|
||||
@ -70,8 +66,7 @@ private:
|
||||
void calculateValues();
|
||||
void createDBusInterface();
|
||||
[[nodiscard]] QString parsePattern(QString _pattern) const;
|
||||
void setDataBySource(const QString &_source, const KSysGuard::SensorInfo &_sensor,
|
||||
const KSysGuard::SensorData &_data);
|
||||
void setDataBySource(const QString &_source, const KSysGuard::SensorInfo &_sensor, const QVariant &_value);
|
||||
// objects
|
||||
AWDataAggregator *m_dataAggregator = nullptr;
|
||||
AWDataEngineAggregator *m_dataEngineAggregator = nullptr;
|
||||
|
@ -2,7 +2,7 @@
|
||||
find_package(Gettext REQUIRED)
|
||||
|
||||
# main qt libraries
|
||||
find_package(Qt6 6.6.0 REQUIRED COMPONENTS Core DBus Network Qml Test Widgets)
|
||||
find_package(Qt6 6.6.0 REQUIRED COMPONENTS Core Concurrent DBus Network Qml Test Widgets)
|
||||
add_definitions(
|
||||
${Qt6Core_DEFINITIONS} ${Qt6DBus_DEFINITIONS} ${Qt6Network_DEFINITIONS}
|
||||
${Qt6Qml_DEFINITIONS} ${Qt6Widgets_DEFINITIONS}
|
||||
@ -12,7 +12,7 @@ set(Qt_INCLUDE
|
||||
${Qt6Qml_INCLUDE_DIRS} ${Qt6Widgets_INCLUDE_DIRS}
|
||||
)
|
||||
set(Qt_LIBRARIES
|
||||
${Qt6Core_LIBRARIES} ${Qt6DBus_LIBRARIES} ${Qt6Network_LIBRARIES}
|
||||
${Qt6Core_LIBRARIES} ${Qt6Concurrent_LIBRARIES} ${Qt6DBus_LIBRARIES} ${Qt6Network_LIBRARIES}
|
||||
${Qt6Qml_LIBRARIES} ${Qt6Widgets_LIBRARIES}
|
||||
)
|
||||
|
||||
|
@ -73,12 +73,6 @@ void TestAWKeys::cleanupTestCase()
|
||||
}
|
||||
|
||||
|
||||
void TestAWKeys::test_hddDevices()
|
||||
{
|
||||
QVERIFY(plugin->getHddDevices().count() >= 2);
|
||||
}
|
||||
|
||||
|
||||
void TestAWKeys::test_dictKeys()
|
||||
{
|
||||
auto keys = plugin->dictKeys();
|
||||
|
@ -31,7 +31,6 @@ private slots:
|
||||
void initTestCase();
|
||||
void cleanupTestCase();
|
||||
// test
|
||||
void test_hddDevices();
|
||||
void test_dictKeys();
|
||||
void test_pattern();
|
||||
void test_tooltip();
|
||||
|
Loading…
x
Reference in New Issue
Block a user