mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-10-15 01:54:14 +02:00
Change a symbol's information without building its folio (stage D5)
A script changing the information of a symbol on a folio not built, when nothing else shows that information (no symbol built holds it, no partner is linked to it, no label formula), changes it through the project database: the store and the symbol's element info row, undoable by uuid (ChangeStoredElementInformationCommand). Reading it back reads the store. Building the symbol later takes the change (projectDataBase::takeUnbuiltEdit(), in Element::fromXml()), the label and texts following as for any change. Saving a .qetz writes the changed information in the database in place of the rows the folio was read with, its file copied, the folio still not built; a symbol whose file holds no information block, or a .qet, builds the folio to save. 136-folio .qetz, "comment" set on the 3 513 symbols the database can change: 0.9 s, no folio built, saved in 6.1 s, none built (27 s and 116 folios when saving built them). The same edits on the 4 039 symbols with no partner and no formula, lazily and with every folio built: the two saved projects are the same file. tst_lazyfolios: a script changes a symbol not built, building none; saved as when built (fails when building ignores the change, and when the .qetz writer does); undone; the folio built afterwards shows it. ctest 96/96 eager and lazy; 342 corpus projects save the same in all four arms and export the same. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -462,6 +462,28 @@ void QetScriptApi::setLive(QStringList *log)
|
||||
m_live_log = log;
|
||||
}
|
||||
|
||||
/**
|
||||
@brief QetScriptApi::unbuiltInformation
|
||||
@return the information of the symbol @p elementUuid on the folio
|
||||
@p folioIndex when that folio is not built (QET_LAZY_FOLIOS) and the
|
||||
symbol's information can be read and changed through the project
|
||||
database alone (projectDataBase::canEditUnbuilt()); nothing otherwise,
|
||||
the folio to be built
|
||||
*/
|
||||
std::optional<DiagramContext> QetScriptApi::unbuiltInformation(int folioIndex, const QString &elementUuid) const
|
||||
{
|
||||
if (!m_project || folioIndex < 0 || folioIndex >= m_project->folios().count()) return std::nullopt;
|
||||
Diagram *folio = m_project->folios().at(folioIndex);
|
||||
const QUuid uuid(elementUuid);
|
||||
projectDataBase *database = m_project->dataBase();
|
||||
if (folio->isLoaded() || !database->rowsFromDocument()
|
||||
|| !database->folioUuidsOfElements({uuid}).contains(folio->uuid())
|
||||
|| !database->canEditUnbuilt(uuid)) {
|
||||
return std::nullopt;
|
||||
}
|
||||
return database->elementInformation(uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief QetScriptApi::built
|
||||
@return @p folio, built if it was not yet (QET_LAZY_FOLIOS), as showing
|
||||
@@ -666,6 +688,19 @@ bool QetScriptApi::setInfoKey(int folioIndex, const QString &elementUuid,
|
||||
log(QStringLiteral("qet.%1: \"%2\" is internal, follow a numbering with numberElement()")
|
||||
.arg(caller, key));
|
||||
return false;
|
||||
}
|
||||
//A symbol on a folio not built whose information nothing else
|
||||
//shows is changed through the project database, its folio left
|
||||
//unbuilt (stage D5)
|
||||
if (key != QETInformation::ELMT_FORMULA) {
|
||||
if (const auto stored = unbuiltInformation(folioIndex, elementUuid)) {
|
||||
if (stored->value(key).toString() == value) return true; // nothing to push
|
||||
DiagramContext new_info = *stored;
|
||||
new_info.addValue(key, value);
|
||||
m_project->undoStack()->push(new ChangeStoredElementInformationCommand(
|
||||
m_project, QUuid(elementUuid), *stored, new_info));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Element *element = findElement(folioIndex, elementUuid);
|
||||
if (!element) return false;
|
||||
@@ -1009,6 +1044,8 @@ int QetScriptApi::terminalIndex(int folioIndex, const QString &elementUuid,
|
||||
|
||||
QString QetScriptApi::elementInfo(int folioIndex, const QString &elementUuid, const QString &key) const
|
||||
{
|
||||
if (const auto stored = unbuiltInformation(folioIndex, elementUuid))
|
||||
return stored->value(key).toString();
|
||||
Element *element = findElement(folioIndex, elementUuid);
|
||||
if (!element) return QString();
|
||||
return element->elementInformations().value(key).toString();
|
||||
|
||||
Reference in New Issue
Block a user