Scripting: look up a folio by its uuid

Every scripting call names a folio by its index, and the index shifts when
a folio is added, removed or moved: a script that removes folio 0 and then
edits "folio 2" edits the wrong one. Texts, shapes, pictures, tables and
symbol text fields already have a uuid lookup for the same reason; folios
had none.

- qet.folioUuid(index): the folio's uuid, or "".
- qet.folioIndex(uuid): the folio's current index, or -1.

A folio saved without a uuid (132 of the 133 in the shipped examples) is
given one on load, derived from the file, so it is the same on every load
and is written on the next save. No two folios share one: a clash is
renewed on load.

Tests in misc/qet-mcp's integration suite, which drives these through
--run: a folio followed across the removal of the one before it, on a file
saved without folio uuids, and a new folio's uuid found in the saved file.
Both fail against a build without this change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ispyisail
2026-09-28 23:56:08 +13:00
parent 5ca047a05d
commit b99f5551d2
3 changed files with 71 additions and 1 deletions
+31
View File
@@ -123,6 +123,37 @@ QString QetScriptApi::folioTitle(int index) const
return diagrams.at(index)->title();
}
/**
@brief QetScriptApi::folioUuid
The uuid of the folio at @p index, or an empty string.
The uuid is what to hold across an edit; the index is what the other
calls take, and it shifts when a folio is added, removed or moved.
*/
QString QetScriptApi::folioUuid(int index) const
{
if (!m_project) return QString();
const QList<Diagram *> diagrams = m_project->diagrams();
if (index < 0 || index >= diagrams.count()) return QString();
return diagrams.at(index)->uuid().toString();
}
/**
@brief QetScriptApi::folioIndex
The current index of the folio carrying @p uuid, or -1. No two folios
of a project carry the same uuid: a clash is renewed on load.
*/
int QetScriptApi::folioIndex(const QString &uuid) const
{
if (!m_project) return -1;
const QUuid wanted(uuid);
if (wanted.isNull()) return -1;
const QList<Diagram *> diagrams = m_project->diagrams();
for (int i = 0 ; i < diagrams.count() ; ++i) {
if (diagrams.at(i)->uuid() == wanted) return i;
}
return -1;
}
int QetScriptApi::elementCount(int folioIndex) const
{
if (!m_project) return 0;