05Robot 3.0

- Main Page
- Modules
- Classes
- Files

- File List
- File Members

cxmlio.h
Go to the documentation of this file.
1
7 #ifndef CXMLIO_H
8 #define CXMLIO_H
9 #include <QDataStream>
10 #include <QVector>
11 #include <QXmlStreamReader>
12 #include <QXmlStreamWriter>
13 #include <QTextStream>
14
15 #include <QPropertyEditorWidget.h>
16 #include <QMetaObject>
17 #include <QMetaProperty>
18
22 class cXmlIO: public QObject
23 {
24 Q_OBJECT
28 Q_PROPERTY(int xmlID READ getXmlID() WRITE setXmlID DESIGNABLE true USER true)
29 int xmlID;
30 public:
31 cXmlIO(int _xmlID=0,QObject* parent=nullptr);
36 virtual QString sXmlKey()
37 {
38 return metaObject()->className();
39 }
40
46 virtual void findInXML(QString &fileName, bool compareXmlID=true);
47
52 virtual void writeXml(QXmlStreamWriter& xml);
57 virtual void readXml(QXmlStreamReader& xml);
58
59 virtual void writeCsvData(QXmlStreamWriter& stream, QString key, const QVector<QVector<double> > &s);
60 virtual void writeCsvVector(QXmlStreamWriter &stream, QString key, const QVector<double > &s);
61 virtual void readCsvData(QXmlStreamReader& stream, QVector<QVector<double> > &s);
62 virtual void readCsvVector(QXmlStreamReader &stream, QVector<double> &s);
63 virtual void write64BaseData(QXmlStreamWriter& stream, QString key, const QVector<QVector<double> > &s);
64 virtual void read64BaseData(QXmlStreamReader &stream, QVector<QVector<double> > &s);
65
66 template<typename T> void writeData(QXmlStreamWriter &stream, QString key, const T &data) {
67 stream.writeStartElement(key);
68
69 QString text;
70 QTextStream tStream(&text,QIODevice::WriteOnly);
71
72 tStream << data;
73
74 stream.writeCDATA(text.toLatin1());
75 stream.writeEndElement();
76 }
77
78 template<typename T> void readData(QXmlStreamReader &stream, T &data) {
79 QString text = stream.readElementText();
80 QTextStream tStream(&text,QIODevice::ReadOnly);
81
82 tStream >> data;
83 }
84
85
86 int getXmlID() const;
87 void setXmlID(int value);
88
89 static void metaCopy(QObject *dest, QObject *src);
90 protected:
91 void metaDataXmlReader(QXmlStreamReader &stream, QObject &obj, bool isUser=true);
92 void metaDataXmlWriter(QXmlStreamWriter &stream, const QObject &obj, bool isUser=true);
93
94 };
95 QDataStream& operator<<( QDataStream& str, const QVector<QVector<double> > &s);
96 QDataStream& operator>>( QDataStream& str, QVector<QVector<double> > &s);
97 QTextStream& operator<<( QTextStream& str, const QVector<QVector<double> > &s);
98
99 #endif // CXMLIO_H
cXmlIO::metaCopy
static void metaCopy(QObject *dest, QObject *src)
operator>>
QDataStream & operator>>(QDataStream &str, QVector< QVector< double > > &s)
cXmlIO::writeCsvData
virtual void writeCsvData(QXmlStreamWriter &stream, QString key, const QVector< QVector< double > > &s)
cXmlIO::cXmlIO
cXmlIO(int _xmlID=0, QObject *parent=nullptr)
cXmlIO::readXml
virtual void readXml(QXmlStreamReader &xml)
Called by findInXML. Reads XML entries. Has to be overloaded if additional data was written to file i...
cXmlIO::readCsvVector
virtual void readCsvVector(QXmlStreamReader &stream, QVector< double > &s)
cXmlIO::writeData
void writeData(QXmlStreamWriter &stream, QString key, const T &data)
Definition: cxmlio.h:66
cXmlIO::xmlID
int xmlID
Defines uniqe identifier for object in XML file.
Definition: cxmlio.h:28
cXmlIO::writeXml
virtual void writeXml(QXmlStreamWriter &xml)
Writes XML entries to file. Can be overloaded to save additional data, apart from object properties...
cXmlIO::metaDataXmlReader
void metaDataXmlReader(QXmlStreamReader &stream, QObject &obj, bool isUser=true)
cXmlIO::read64BaseData
virtual void read64BaseData(QXmlStreamReader &stream, QVector< QVector< double > > &s)
cXmlIO::setXmlID
void setXmlID(int value)
cXmlIO
Delivers XML file serialisation and deserialisation methods for modules.
Definition: cxmlio.h:22
cXmlIO::writeCsvVector
virtual void writeCsvVector(QXmlStreamWriter &stream, QString key, const QVector< double > &s)
cXmlIO::sXmlKey
virtual QString sXmlKey()
Generates key of XML entry (as name of the serialised class is)
Definition: cxmlio.h:36
cXmlIO::findInXML
virtual void findInXML(QString &fileName, bool compareXmlID=true)
serches th file for XML key corr to class name and fill class properties according to entries found ...
cXmlIO::metaDataXmlWriter
void metaDataXmlWriter(QXmlStreamWriter &stream, const QObject &obj, bool isUser=true)
cXmlIO::getXmlID
int getXmlID() const
cXmlIO::readCsvData
virtual void readCsvData(QXmlStreamReader &stream, QVector< QVector< double > > &s)
cXmlIO::write64BaseData
virtual void write64BaseData(QXmlStreamWriter &stream, QString key, const QVector< QVector< double > > &s)
cXmlIO::readData
void readData(QXmlStreamReader &stream, T &data)
Definition: cxmlio.h:78