-
Notifications
You must be signed in to change notification settings - Fork 0
/
xmlwriter.cpp
34 lines (29 loc) · 860 Bytes
/
xmlwriter.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <QtGui>
#include "xmlwriter.h"
XmlWriter::XmlWriter(QTreeWidget *treeWidget)
: treeWidget(treeWidget)
{
xml.setAutoFormatting(true);
}
bool XmlWriter::writeFile(QIODevice *device)
{
xml.setDevice(device);
xml.writeStartDocument();
xml.writeDTD("<!DOCTYPE xml>");
xml.writeStartElement("xml");
xml.writeAttribute("version", "1.0");
for (int i = 0; i < treeWidget->topLevelItemCount(); ++i) {
writeItem(treeWidget->topLevelItem(i));
}
xml.writeEndDocument();
return true;
}
void XmlWriter::writeItem(QTreeWidgetItem *item)
{
xml.writeStartElement("exercise");
xml.writeTextElement("id", item->text(0));
xml.writeTextElement("action", item->text(1));
xml.writeTextElement("time", item->text(2));
xml.writeTextElement("description", item->text(3));
xml.writeEndElement();
}