Chris@49
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@3
|
2
|
Chris@3
|
3 /*
|
Chris@52
|
4 Sonic Visualiser
|
Chris@52
|
5 An audio file viewer and annotation editor.
|
Chris@52
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@52
|
7 This file copyright 2006 Chris Cannam.
|
Chris@3
|
8
|
Chris@52
|
9 This program is free software; you can redistribute it and/or
|
Chris@52
|
10 modify it under the terms of the GNU General Public License as
|
Chris@52
|
11 published by the Free Software Foundation; either version 2 of the
|
Chris@52
|
12 License, or (at your option) any later version. See the file
|
Chris@52
|
13 COPYING included with this distribution for more information.
|
Chris@3
|
14 */
|
Chris@3
|
15
|
Chris@3
|
16 #include "XmlExportable.h"
|
Chris@4
|
17 #include <map>
|
Chris@85
|
18 #include <QMutex>
|
Chris@85
|
19 #include <QMutexLocker>
|
Chris@123
|
20 #include <QTextStream>
|
Chris@123
|
21
|
Chris@314
|
22 QString
|
Chris@314
|
23 XmlExportable::toXmlString(QString indent,
|
Chris@314
|
24 QString extraAttributes) const
|
Chris@123
|
25 {
|
Chris@314
|
26 QString s;
|
Chris@314
|
27
|
Chris@314
|
28 {
|
Chris@314
|
29 QTextStream out(&s);
|
Chris@314
|
30 toXml(out, indent, extraAttributes);
|
Chris@314
|
31 }
|
Chris@314
|
32
|
Chris@314
|
33 return s;
|
Chris@123
|
34 }
|
Chris@3
|
35
|
Chris@3
|
36 QString
|
Chris@3
|
37 XmlExportable::encodeEntities(QString s)
|
Chris@3
|
38 {
|
Chris@3
|
39 s
|
Chris@3
|
40 .replace("&", "&")
|
Chris@3
|
41 .replace("<", "<")
|
Chris@3
|
42 .replace(">", ">")
|
Chris@3
|
43 .replace("\"", """)
|
Chris@3
|
44 .replace("'", "'");
|
Chris@3
|
45
|
Chris@3
|
46 return s;
|
Chris@3
|
47 }
|
Chris@3
|
48
|
Chris@3
|
49 QString
|
Chris@3
|
50 XmlExportable::encodeColour(QColor c)
|
Chris@3
|
51 {
|
Chris@3
|
52 QString r, g, b;
|
Chris@3
|
53
|
Chris@3
|
54 r.setNum(c.red(), 16);
|
Chris@3
|
55 if (c.red() < 16) r = "0" + r;
|
Chris@3
|
56
|
Chris@3
|
57 g.setNum(c.green(), 16);
|
Chris@3
|
58 if (c.green() < 16) g = "0" + g;
|
Chris@3
|
59
|
Chris@3
|
60 b.setNum(c.blue(), 16);
|
Chris@3
|
61 if (c.blue() < 16) b = "0" + b;
|
Chris@3
|
62
|
Chris@3
|
63 return "#" + r + g + b;
|
Chris@3
|
64 }
|
Chris@3
|
65
|
Chris@4
|
66 int
|
Chris@4
|
67 XmlExportable::getObjectExportId(const void * object)
|
Chris@4
|
68 {
|
Chris@85
|
69 static QMutex mutex;
|
Chris@85
|
70 QMutexLocker locker(&mutex);
|
Chris@85
|
71
|
Chris@4
|
72 static std::map<const void *, int> idMap;
|
Chris@4
|
73 static int maxId = 0;
|
Chris@4
|
74
|
Chris@4
|
75 if (idMap.find(object) == idMap.end()) {
|
Chris@4
|
76 idMap[object] = maxId++;
|
Chris@4
|
77 }
|
Chris@4
|
78
|
Chris@4
|
79 return idMap[object];
|
Chris@4
|
80 }
|
Chris@4
|
81
|
Chris@4
|
82
|