final ports and first fixes

This commit is contained in:
Geoffray Levasseur committed 2026-11-04 11:55:54 +01:00
1 parent 77690cbd96
commit 6f3556009a
23 files changed
+2302 -41

No files matched your search

+38 -12
View File
@@ -86,14 +86,40 @@ void GraphicSet::loadFromFile(const QString &fileName)
QXmlStreamReader xml(&file);
while (!xml.atEnd()) {
xml.readNext();
if (xml.isStartElement() && xml.name() == QLatin1String("Item")) {
const QXmlStreamAttributes attrs = xml.attributes();
GraphicSetItem *newItem = addNew(attrs.value("Name").toString());
newItem->left = attrs.value("Left").toInt();
newItem->top = attrs.value("Top").toInt();
newItem->width = attrs.value("Width").toInt();
newItem->height = attrs.value("Height").toInt();
if (!xml.isStartElement() || xml.name() != QLatin1String("Item"))
continue;
// The original format stores each field as a child element (<Name>, <Left>, ...);
// attributes are accepted too.
const QXmlStreamAttributes attrs = xml.attributes();
QString name = attrs.value("Name").toString();
int left = attrs.value("Left").toInt();
int top = attrs.value("Top").toInt();
int width = attrs.value("Width").toInt();
int height = attrs.value("Height").toInt();
while (!xml.atEnd()) {
xml.readNext();
if (xml.isEndElement() && xml.name() == QLatin1String("Item"))
break;
if (!xml.isStartElement())
continue;
const QString field = xml.name().toString();
const QString text = xml.readElementText();
if (field == QLatin1String("Name"))
name = text;
else if (field == QLatin1String("Left"))
left = text.toInt();
else if (field == QLatin1String("Top"))
top = text.toInt();
else if (field == QLatin1String("Width"))
width = text.toInt();
else if (field == QLatin1String("Height"))
height = text.toInt();
}
GraphicSetItem *newItem = addNew(name);
newItem->left = left;
newItem->top = top;
newItem->width = width;
newItem->height = height;
}
}
@@ -110,11 +136,11 @@ void GraphicSet::saveToFile(const QString &fileName) const
xml.writeStartElement(QLatin1String("Items"));
for (GraphicSetItem *item : m_items) {
xml.writeStartElement(QLatin1String("Item"));
xml.writeAttribute(QLatin1String("Name"), item->name);
xml.writeAttribute(QLatin1String("Left"), QString::number(item->left));
xml.writeAttribute(QLatin1String("Top"), QString::number(item->top));
xml.writeAttribute(QLatin1String("Width"), QString::number(item->width));
xml.writeAttribute(QLatin1String("Height"), QString::number(item->height));
xml.writeTextElement(QLatin1String("Name"), item->name);
xml.writeTextElement(QLatin1String("Left"), QString::number(item->left));
xml.writeTextElement(QLatin1String("Top"), QString::number(item->top));
xml.writeTextElement(QLatin1String("Width"), QString::number(item->width));
xml.writeTextElement(QLatin1String("Height"), QString::number(item->height));
xml.writeEndElement();
}
xml.writeEndElement();