annotate base/XmlExportable.cpp @ 137:0aafdda005ce

* Remove dependency on the actual stored object type in MatrixFile * Add alternative Compact storage format for FFTFileCache (16-bit instead of 32-bit)
author Chris Cannam
date Wed, 12 Jul 2006 14:15:46 +0000
parents 0f37e92e1782
children 70a232b1f12a
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@123 20 #include <QTextStream>
Chris@123 21
Chris@123 22 void
Chris@123 23 XmlExportable::toXml(QTextStream &stream, QString indent,
Chris@123 24 QString extraAttributes) const
Chris@123 25 {
Chris@123 26 stream << toXmlString(indent, extraAttributes);
Chris@123 27 }
Chris@3 28
Chris@3 29 QString
Chris@3 30 XmlExportable::encodeEntities(QString s)
Chris@3 31 {
Chris@3 32 s
Chris@3 33 .replace("&", "&amp;")
Chris@3 34 .replace("<", "&lt;")
Chris@3 35 .replace(">", "&gt;")
Chris@3 36 .replace("\"", "&quot;")
Chris@3 37 .replace("'", "&apos;");
Chris@3 38
Chris@3 39 return s;
Chris@3 40 }
Chris@3 41
Chris@3 42 QString
Chris@3 43 XmlExportable::encodeColour(QColor c)
Chris@3 44 {
Chris@3 45 QString r, g, b;
Chris@3 46
Chris@3 47 r.setNum(c.red(), 16);
Chris@3 48 if (c.red() < 16) r = "0" + r;
Chris@3 49
Chris@3 50 g.setNum(c.green(), 16);
Chris@3 51 if (c.green() < 16) g = "0" + g;
Chris@3 52
Chris@3 53 b.setNum(c.blue(), 16);
Chris@3 54 if (c.blue() < 16) b = "0" + b;
Chris@3 55
Chris@3 56 return "#" + r + g + b;
Chris@3 57 }
Chris@3 58
Chris@4 59 int
Chris@4 60 XmlExportable::getObjectExportId(const void * object)
Chris@4 61 {
Chris@85 62 static QMutex mutex;
Chris@85 63 QMutexLocker locker(&mutex);
Chris@85 64
Chris@4 65 static std::map<const void *, int> idMap;
Chris@4 66 static int maxId = 0;
Chris@4 67
Chris@4 68 if (idMap.find(object) == idMap.end()) {
Chris@4 69 idMap[object] = maxId++;
Chris@4 70 }
Chris@4 71
Chris@4 72 return idMap[object];
Chris@4 73 }
Chris@4 74
Chris@4 75