| 347 | } |
| 348 | |
| 349 | void MacroScheduleTab::PopulateTable() |
| 350 | { |
| 351 | // Remember which entry was selected so we can restore it after repopulating |
| 352 | const int prevIdx = SelectedEntryIndex(); |
| 353 | QString prevId; |
| 354 | std::deque<MacroScheduleEntry> snapshot; |
| 355 | { |
| 356 | auto lock = LockContext(); |
| 357 | const auto &entries = GetScheduleEntries(); |
| 358 | if (prevIdx >= 0 && prevIdx < (int)entries.size()) { |
| 359 | prevId = QString::fromStdString(entries[prevIdx].id); |
| 360 | } |
| 361 | snapshot = entries; |
| 362 | } |
| 363 | |
| 364 | _table->setRowCount(0); |
| 365 | |
| 366 | for (const auto &entry : snapshot) { |
| 367 | const int row = _table->rowCount(); |
| 368 | _table->insertRow(row); |
| 369 | |
| 370 | auto makeItem = [](const QString &text) { |
| 371 | auto item = new QTableWidgetItem(text); |
| 372 | item->setFlags(item->flags() & ~Qt::ItemIsEditable); |
| 373 | return item; |
| 374 | }; |
| 375 | |
| 376 | _table->setItem(row, COL_NAME, makeItem(entry.GetSummary())); |
| 377 | _table->setItem( |
| 378 | row, COL_MACRO, |
| 379 | makeItem(QString::fromStdString(entry.macro.Name()))); |
| 380 | _table->setItem(row, COL_SCHEDULE, |
| 381 | makeItem(entry.GetRepeatDescription())); |
| 382 | _table->setItem(row, COL_NEXT_TRIGGER, |
| 383 | makeItem(entry.GetNextTriggerString())); |
| 384 | |
| 385 | QString status; |
| 386 | if (!entry.enabled) { |
| 387 | status = obs_module_text( |
| 388 | "AdvSceneSwitcher.macroScheduleTab.status.disabled"); |
| 389 | } else if (entry.IsExpired()) { |
| 390 | status = obs_module_text( |
| 391 | "AdvSceneSwitcher.macroScheduleTab.status.expired"); |
| 392 | } else { |
| 393 | status = obs_module_text( |
| 394 | "AdvSceneSwitcher.macroScheduleTab.status.active"); |
| 395 | } |
| 396 | _table->setItem(row, COL_STATUS, makeItem(status)); |
| 397 | |
| 398 | _table->item(row, COL_NAME) |
| 399 | ->setData(Qt::UserRole, |
| 400 | QString::fromStdString(entry.id)); |
| 401 | } |
| 402 | |
| 403 | SetHelpVisible(_table->rowCount() == 0); |
| 404 | |
| 405 | // Restore selection |
| 406 | if (!prevId.isEmpty()) { |
nothing calls this directly
no test coverage detected