2 #include <QNetworkRequest>
3 //#include <QNetworkReply>
11 #include <QApplication>
12 #include "xmlwriter.h"
16 *@brief Constructor, connects object to GUI
17 *@param Pointer to carmainwindow, which is temporarily used during development
19 XmlWriter::XmlWriter(Ui_CarMainWindow* myMainWindow)
28 XmlWriter::~XmlWriter()
34 *@brief Opens and closes a file, when xml information is written into a file,
35 *and passes file to writeXmlFile()
36 *@note Partly harcoded and commented for git.
37 *@todo Replace hardcoced filename and GUI elements to finally used widgets.
39 void XmlWriter::writeXml()
41 QString filename = "xmlfile.xml";
43 if (!file.open(QFile::WriteOnly | QFile::Text)) {
44 qDebug() << "_xmlWrite fail";
53 *@brief Writes general xml information.
54 *Calls other functions to insert login and result information.
55 *@todo Check API connection to QBuffer, when Speed Freek network client has been written.
57 bool XmlWriter::writeXmlFile(QIODevice *device)
58 //bool XmlWriter::writeXmlFile(QBuffer *device)
60 xmlwriter.setDevice(device);
61 xmlwriter.writeStartDocument();
62 xmlwriter.writeStartElement("xml");
63 xmlwriter.writeAttribute("version", "1.0");
66 xmlwriter.writeEndDocument();
72 *@brief Writes Speed Freek application specific items as tags and contents.
73 *@brief Results of speed/ direction/ acceleration into QMap are calculated elsewhere
74 *@todo Replace hardcoced user, password and email to finally used GUI elements.
76 void XmlWriter::writeRegister()
78 xmlwriter.writeStartElement("user");
80 xmlwriter.writeStartElement("login");
81 xmlwriter.writeCharacters("test123");
82 xmlwriter.writeEndElement();
84 xmlwriter.writeStartElement("password");
85 xmlwriter.writeCharacters("thisisaveryinsecurepassword");
86 xmlwriter.writeEndElement();
88 //Is this neacessary when sending results
89 xmlwriter.writeStartElement("email");
90 xmlwriter.writeCharacters("test@example.com");
91 xmlwriter.writeEndElement();
93 xmlwriter.writeEndElement();
97 *@brief Writes Speed Freek results items as tags and contents.
98 *@brief Results of speed/ direction/ acceleration into QMap are calculated elsewhere
99 *@todo Consider looping of writing QMap values.
100 *@todo Replace hardcoced names to finally used values.
102 void XmlWriter::writeItems()
105 this->fillResultmap();
107 xmlwriter.writeStartElement("result");
108 xmlwriter.writeAttribute("value", QString::number(resultmap.value("speed")));
109 xmlwriter.writeAttribute("unit", "seconds");
110 xmlwriter.writeAttribute("date", QDateTime::currentDateTime().toString());
111 xmlwriter.writeEndElement();
116 *@brief A temp function during development, used until real QMap available.
118 void XmlWriter::fillResultmap()
120 resultmap["acceleration"] = 9;
121 resultmap["speed"] = 48;
122 resultmap["distance"] = 600;
126 *@brief A temp function during development, used to create a "serverfile".
128 void XmlWriter::serverWritesTop()
133 /* Server sends to client */
134 xmlwriter.writeStartElement("results");
135 xmlwriter.writeAttribute("category", "acceleration-0-100");
136 xmlwriter.writeAttribute("unit", "seconds");
137 xmlwriter.writeAttribute("description", "Acceleration from 0 to 100 km/h");
139 for (i = 0; i < n; i++) {
140 xmlwriter.writeStartElement("result");
141 xmlwriter.writeAttribute("position", QString::number(i));
142 xmlwriter.writeAttribute("user", "test123");
143 xmlwriter.writeAttribute("date", QDateTime::currentDateTime().toString());
144 xmlwriter.writeAttribute("value", QString::number(i+i+1));
145 xmlwriter.writeEndElement();