* @brief Activates a dashboard action by transmitting its associated data and handling timer * logic. actionStatusChanged makes QML rebuild the whole actions list, so it only fires * when a timer's activity flips; per-tick transmissions emit nothing. */
| 1254 | * when a timer's activity flips; per-tick transmissions emit nothing. |
| 1255 | */ |
| 1256 | void UI::Dashboard::activateAction(const int index, const bool guiTrigger) |
| 1257 | { |
| 1258 | Q_ASSERT(index >= 0); |
| 1259 | Q_ASSERT(index < m_actions.count()); |
| 1260 | |
| 1261 | if (index < 0 || index >= m_actions.count()) { |
| 1262 | qWarning() << "Invalid action index:" << index; |
| 1263 | return; |
| 1264 | } |
| 1265 | |
| 1266 | const auto& action = m_actions[index]; |
| 1267 | |
| 1268 | if (action.timerMode == DataModel::TimerMode::RepeatNTimes && guiTrigger) { |
| 1269 | if (m_timers.contains(index) && m_timers[index]) { |
| 1270 | m_repeatCounters[index] = qMax(1, action.repeatCount); |
| 1271 | m_timers[index]->start(); |
| 1272 | } |
| 1273 | |
| 1274 | if (!IO::ConnectionManager::instance().paused()) |
| 1275 | (void)IO::ConnectionManager::instance().writeDataToDevice(action.sourceId, |
| 1276 | DataModel::get_tx_bytes(action)); |
| 1277 | |
| 1278 | if (m_repeatCounters.contains(index)) |
| 1279 | m_repeatCounters[index]--; |
| 1280 | |
| 1281 | return; |
| 1282 | } |
| 1283 | |
| 1284 | if (action.timerMode == DataModel::TimerMode::RepeatNTimes && !guiTrigger) { |
| 1285 | if (!IO::ConnectionManager::instance().paused()) |
| 1286 | (void)IO::ConnectionManager::instance().writeDataToDevice(action.sourceId, |
| 1287 | DataModel::get_tx_bytes(action)); |
| 1288 | |
| 1289 | tickRepeatTimer(index, m_timers, m_repeatCounters); |
| 1290 | return; |
| 1291 | } |
| 1292 | |
| 1293 | bool timerFlipped = false; |
| 1294 | const auto timerIt = m_timers.find(index); |
| 1295 | if (timerIt != m_timers.end()) { |
| 1296 | const bool wasActive = timerIt.value() && timerIt.value()->isActive(); |
| 1297 | applyTimerMode(timerIt.value(), action.timerMode, guiTrigger, action.title); |
| 1298 | const bool isActive = timerIt.value() && timerIt.value()->isActive(); |
| 1299 | timerFlipped = (wasActive != isActive); |
| 1300 | } |
| 1301 | |
| 1302 | if (!IO::ConnectionManager::instance().paused()) |
| 1303 | (void)IO::ConnectionManager::instance().writeDataToDevice(action.sourceId, |
| 1304 | DataModel::get_tx_bytes(action)); |
| 1305 | |
| 1306 | if (timerFlipped) |
| 1307 | Q_EMIT actionStatusChanged(); |
| 1308 | } |
| 1309 | |
| 1310 | //-------------------------------------------------------------------------------------------------- |
| 1311 | // Plot active state setters |
no test coverage detected