00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "XmlExportable.h"
00017 #include <map>
00018 #include <QMutex>
00019 #include <QMutexLocker>
00020 #include <QTextStream>
00021
00022 #include <iostream>
00023
00024 QString
00025 XmlExportable::toXmlString(QString indent,
00026 QString extraAttributes) const
00027 {
00028
00029
00030 QString s;
00031
00032 {
00033 QTextStream out(&s);
00034 toXml(out, indent, extraAttributes);
00035 }
00036
00037 return s;
00038 }
00039
00040 QString
00041 XmlExportable::encodeEntities(QString s)
00042 {
00043 s
00044 .replace("&", "&")
00045 .replace("<", "<")
00046 .replace(">", ">")
00047 .replace("\"", """)
00048 .replace("'", "'");
00049
00050 return s;
00051 }
00052
00053 QString
00054 XmlExportable::encodeColour(QColor c)
00055 {
00056 QString r, g, b;
00057
00058 r.setNum(c.red(), 16);
00059 if (c.red() < 16) r = "0" + r;
00060
00061 g.setNum(c.green(), 16);
00062 if (c.green() < 16) g = "0" + g;
00063
00064 b.setNum(c.blue(), 16);
00065 if (c.blue() < 16) b = "0" + b;
00066
00067 return "#" + r + g + b;
00068 }
00069
00070 int
00071 XmlExportable::getObjectExportId(const void * object)
00072 {
00073 static QMutex mutex;
00074 QMutexLocker locker(&mutex);
00075
00076 static std::map<const void *, int> idMap;
00077 static int maxId = 0;
00078
00079 if (idMap.find(object) == idMap.end()) {
00080 idMap[object] = maxId++;
00081 }
00082
00083 return idMap[object];
00084 }
00085
00086