Replace unsupported Lambda UniqueConnection

This commit is contained in:
Lord-Grey 2023-09-14 22:09:43 +02:00
parent acc065e22b
commit 8c31e7822c
2 changed files with 25 additions and 13 deletions

View File

@ -88,6 +88,11 @@ private slots:
///
void handleInstanceStateChange(InstanceState state, quint8 instance, const QString &name = QString());
///
/// @brief Stream a new LED Colors update
///
void streamLedColorsUpdate();
signals:
///
/// Signal emits with the reply message provided with handleMessage()

View File

@ -140,6 +140,8 @@ void JsonAPI::initialize()
connect(this, &JsonAPI::toggleSuspendAll, _instanceManager, &HyperionIManager::triggerToggleSuspend);
connect(this, &JsonAPI::idleAll, _instanceManager, &HyperionIManager::triggerIdle);
connect(this, &JsonAPI::toggleIdleAll, _instanceManager, &HyperionIManager::triggerToggleIdle);
connect(_ledStreamTimer, &QTimer::timeout, this, &JsonAPI::streamLedColorsUpdate, Qt::UniqueConnection);
}
bool JsonAPI::handleInstanceSwitch(quint8 inst, bool forced)
@ -1139,6 +1141,11 @@ void JsonAPI::handleComponentStateCommand(const QJsonObject &message, const QStr
sendSuccessReply(command, tan);
}
void JsonAPI::streamLedColorsUpdate()
{
emit streamLedcolorsUpdate(_currentLedValues);
}
void JsonAPI::handleLedColorsCommand(const QJsonObject &message, const QString &command, int tan)
{
// create result
@ -1154,21 +1161,21 @@ void JsonAPI::handleLedColorsCommand(const QJsonObject &message, const QString &
_streaming_leds_reply["tan"] = tan;
connect(_hyperion, &Hyperion::rawLedColors, this, [=](const std::vector<ColorRgb> &ledValues) {
_currentLedValues = ledValues;
// necessary because Qt::UniqueConnection for lambdas does not work until 5.9
// see: https://bugreports.qt.io/browse/QTBUG-52438
if (!_ledStreamConnection)
_ledStreamConnection = connect(_ledStreamTimer, &QTimer::timeout, this, [=]() {
emit streamLedcolorsUpdate(_currentLedValues);
},
Qt::UniqueConnection);
if (ledValues != _currentLedValues)
{
_currentLedValues = ledValues;
if (!_ledStreamTimer->isActive() || _ledStreamTimer->interval() != streaming_interval)
{
_ledStreamTimer->start(streaming_interval);
}
}
else
{
_ledStreamTimer->stop();
}
});
// start the timer
if (!_ledStreamTimer->isActive() || _ledStreamTimer->interval() != streaming_interval)
_ledStreamTimer->start(streaming_interval);
},
Qt::UniqueConnection);
// push once
_hyperion->update();
}