* @brief Updates an existing register -- rename, retype, and/or default value. * Returns true only when the update was applied and tablesChanged() was * emitted; false on every validation-failure path so callers can key * refresh-suppression off confirmed success rather than emit timing. */
| 5388 | * refresh-suppression off confirmed success rather than emit timing. |
| 5389 | */ |
| 5390 | bool DataModel::ProjectModel::updateRegister(const QString& table, |
| 5391 | const QString& registerName, |
| 5392 | const QString& newName, |
| 5393 | bool computed, |
| 5394 | const QVariant& defaultValue) |
| 5395 | { |
| 5396 | const int idx = findTableIndexByPath(table); |
| 5397 | if (idx < 0) |
| 5398 | return false; |
| 5399 | |
| 5400 | auto it = m_tables.begin() + idx; |
| 5401 | |
| 5402 | const QString n = newName.simplified(); |
| 5403 | if (n.isEmpty()) |
| 5404 | return false; |
| 5405 | |
| 5406 | if (n != registerName) { |
| 5407 | for (const auto& r : it->registers) |
| 5408 | if (r.name == n) |
| 5409 | return false; |
| 5410 | } |
| 5411 | |
| 5412 | for (auto& r : it->registers) { |
| 5413 | if (r.name == registerName) { |
| 5414 | r.name = n; |
| 5415 | r.type = computed ? RegisterType::Computed : RegisterType::Constant; |
| 5416 | r.defaultValue = defaultValue.isValid() ? defaultValue : r.defaultValue; |
| 5417 | setModified(true); |
| 5418 | Q_EMIT tablesChanged(); |
| 5419 | return true; |
| 5420 | } |
| 5421 | } |
| 5422 | |
| 5423 | return false; |
| 5424 | } |
| 5425 | |
| 5426 | /** |
| 5427 | * @brief Returns the register list of a table as a QVariantList for QML. |
no test coverage detected