Scripting: look up a table or a symbol text field by its uuid

qet.textIndex(), shapeIndex() and imageIndex() turn a free text's, shape's
or picture's uuid into the index the other calls take. Tables and symbol
text fields had no such lookup, so a script could only name them by index,
and an index shifts when an earlier item is deleted: a script that deletes
table 0 and then moves "table 1" moves the wrong table.

- qet.tableIndex(folio, uuid): the table's current index in tables(folio),
  or -1.
- qet.elementTextIndex(folio, elementUuid, textUuid): the field's current
  index in elementTexts(folio, elementUuid), or -1. The element is part of
  the address because a field's uuid is unique only within its element:
  copying an element keeps its fields' uuids (2612_ats_singlephase.qet has
  one field uuid on 20 copies).

Tests in misc/qet-mcp's integration suite, which drives these through
--run: a table followed across a deletion of the one before it, and the
same field uuid resolving on two copies to each copy's own field. 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 13:29:24 +13:00
parent f5b644918b
commit fd962619b5
3 changed files with 94 additions and 0 deletions
+21
View File
@@ -2891,6 +2891,27 @@ int QetScriptApi::imageIndex(int folioIndex, const QString &uuid) const
return indexOfUuid(sortedImages(folioIndex), uuid);
}
/// @brief QetScriptApi::tableIndex as textIndex(), for tables(folioIndex).
int QetScriptApi::tableIndex(int folioIndex, const QString &uuid) const
{
return indexOfUuid(sortedTables(folioIndex), uuid);
}
/**
@brief QetScriptApi::elementTextIndex
The current index in elementTexts() of the text field carrying
@p textUuid, on the element @p elementUuid, or -1.
A field's uuid is unique only within its element: copying an element
keeps its fields' uuids, so the element is part of the address.
*/
int QetScriptApi::elementTextIndex(int folioIndex, const QString &elementUuid,
const QString &textUuid) const
{
Element *element = findElement(folioIndex, elementUuid);
if (!element) return -1;
return indexOfUuid(element->dynamicTextItems(), textUuid);
}
/**
@brief QetScriptApi::addImage
Place a picture from a file, as the "add image" tool does after its file