annotate base/XmlExportable.cpp @ 116:a08718723b20

* Add units repository, and unit property on time-value and note layers.
author Chris Cannam
date Thu, 11 May 2006 15:02:14 +0000
parents ea730e3f9ace
children 0f37e92e1782
rev   line source
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@3 20
Chris@3 21 QString
Chris@3 22 XmlExportable::encodeEntities(QString s)
Chris@3 23 {
Chris@3 24 s
Chris@3 25 .replace("&", "&amp;")
Chris@3 26 .replace("<", "&lt;")
Chris@3 27 .replace(">", "&gt;")
Chris@3 28 .replace("\"", "&quot;")
Chris@3 29 .replace("'", "&apos;");
Chris@3 30
Chris@3 31 return s;
Chris@3 32 }
Chris@3 33
Chris@3 34 QString
Chris@3 35 XmlExportable::encodeColour(QColor c)
Chris@3 36 {
Chris@3 37 QString r, g, b;
Chris@3 38
Chris@3 39 r.setNum(c.red(), 16);
Chris@3 40 if (c.red() < 16) r = "0" + r;
Chris@3 41
Chris@3 42 g.setNum(c.green(), 16);
Chris@3 43 if (c.green() < 16) g = "0" + g;
Chris@3 44
Chris@3 45 b.setNum(c.blue(), 16);
Chris@3 46 if (c.blue() < 16) b = "0" + b;
Chris@3 47
Chris@3 48 return "#" + r + g + b;
Chris@3 49 }
Chris@3 50
Chris@4 51 int
Chris@4 52 XmlExportable::getObjectExportId(const void * object)
Chris@4 53 {
Chris@85 54 static QMutex mutex;
Chris@85 55 QMutexLocker locker(&mutex);
Chris@85 56
Chris@4 57 static std::map<const void *, int> idMap;
Chris@4 58 static int maxId = 0;
Chris@4 59
Chris@4 60 if (idMap.find(object) == idMap.end()) {
Chris@4 61 idMap[object] = maxId++;
Chris@4 62 }
Chris@4 63
Chris@4 64 return idMap[object];
Chris@4 65 }
Chris@4 66
Chris@4 67