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