MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / updateRegister

Method updateRegister

app/src/DataModel/ProjectModel.cpp:5390–5424  ·  view source on GitHub ↗

* @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. */

Source from the content-addressed store, hash-verified

5388 * refresh-suppression off confirmed success rather than emit timing.
5389 */
5390bool 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.

Callers 1

registerUpdateMethod · 0.80

Calls 3

beginMethod · 0.80
isEmptyMethod · 0.80
isValidMethod · 0.45

Tested by

no test coverage detected