Fix placing a symbol a second time in a project with an extra category

XmlElementCollection::importCategory() returned the project collection's
first category, taken to be "import". A project can hold other
top-level categories before it: examples/lmdg.qet has "k_elem" first.
Imported symbols were then filed under k_elem/, while every lookup of an
imported symbol is under import/ (QETProject::importElement(),
XmlElementCollection::addElement()). The first placement worked; the
second could not find the copy, tried to import it again and failed.
In the editor the drop silently placed nothing; a script's
qet.addElement() returned "".

Look the category up by name, falling back to the first one as before
when a project has none called "import".

Test: tst_importcategory places the same symbol twice in a copy of
lmdg.qet through --run. It fails without the fix (the second placement
returns "") and passes with it. ctest 45/45.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
ispyisail
2026-10-02 21:49:42 +13:00
parent b485258424
commit ec262d1af9
3 changed files with 118 additions and 0 deletions
@@ -157,6 +157,16 @@ QDomElement XmlElementCollection::root() const
*/
QDomElement XmlElementCollection::importCategory() const
{
//Found by name: a project may hold other top-level categories,
//and before the "import" one (lmdg.qet has "k_elem" first). Every
//lookup of an imported element is under "import/", so filing it
//anywhere else made the next placement of the same symbol fail.
for (QDomElement category = root().firstChildElement("category") ;
!category.isNull() ;
category = category.nextSiblingElement("category")) {
if (category.attribute("name") == QLatin1String("import"))
return category;
}
return root().firstChildElement("category");
}