* @brief Adds a new action with a unique title to the project. */
| 4535 | * @brief Adds a new action with a unique title to the project. |
| 4536 | */ |
| 4537 | void DataModel::ProjectModel::addAction(int sourceId) |
| 4538 | { |
| 4539 | int count = 1; |
| 4540 | QString title = tr("New Action"); |
| 4541 | for (const auto& action : std::as_const(m_actions)) { |
| 4542 | if (action.title == title) { |
| 4543 | count++; |
| 4544 | title = QString("%1 (%2)").arg(title, QString::number(count)); |
| 4545 | } |
| 4546 | } |
| 4547 | |
| 4548 | while (count > 1) { |
| 4549 | bool titleExists = false; |
| 4550 | for (const auto& action : std::as_const(m_actions)) { |
| 4551 | if (action.title != title) |
| 4552 | continue; |
| 4553 | |
| 4554 | count++; |
| 4555 | title = QString("%1 (%2)").arg(title, QString::number(count)); |
| 4556 | titleExists = true; |
| 4557 | break; |
| 4558 | } |
| 4559 | |
| 4560 | if (!titleExists) |
| 4561 | break; |
| 4562 | } |
| 4563 | |
| 4564 | DataModel::Action action; |
| 4565 | action.title = title; |
| 4566 | action.actionId = m_actions.size(); |
| 4567 | if (sourceId >= 0) |
| 4568 | action.sourceId = sourceId; |
| 4569 | |
| 4570 | m_actions.push_back(action); |
| 4571 | m_selectedAction = action; |
| 4572 | |
| 4573 | Q_EMIT actionsChanged(); |
| 4574 | Q_EMIT actionAdded(static_cast<int>(m_actions.size()) - 1); |
| 4575 | setModified(true); |
| 4576 | } |
| 4577 | |
| 4578 | /** |
| 4579 | * @brief Adds a new group with a unique title and the given widget type. |
no test coverage detected