annotate base/XmlExportable.cpp @ 331:f620ce48c950

* Further naming change: Transformer -> ModelTransformer. The Transform class now describes a thing that can be done, and the ModelTransformer does it to a Model.
author Chris Cannam
date Wed, 07 Nov 2007 12:59:01 +0000
parents 7a4bd2c8585c
children ca3b91119482
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@318 22 #include <iostream>
Chris@318 23
Chris@314 24 QString
Chris@314 25 XmlExportable::toXmlString(QString indent,
Chris@314 26 QString extraAttributes) const
Chris@123 27 {
Chris@318 28 std::cerr << "XmlExportable::toXmlString" << std::endl;
Chris@318 29
Chris@314 30 QString s;
Chris@314 31
Chris@314 32 {
Chris@314 33 QTextStream out(&s);
Chris@314 34 toXml(out, indent, extraAttributes);
Chris@314 35 }
Chris@314 36
Chris@314 37 return s;
Chris@123 38 }
Chris@3 39
Chris@3 40 QString
Chris@3 41 XmlExportable::encodeEntities(QString s)
Chris@3 42 {
Chris@3 43 s
Chris@3 44 .replace("&", "&amp;")
Chris@3 45 .replace("<", "&lt;")
Chris@3 46 .replace(">", "&gt;")
Chris@3 47 .replace("\"", "&quot;")
Chris@3 48 .replace("'", "&apos;");
Chris@3 49
Chris@3 50 return s;
Chris@3 51 }
Chris@3 52
Chris@3 53 QString
Chris@3 54 XmlExportable::encodeColour(QColor c)
Chris@3 55 {
Chris@3 56 QString r, g, b;
Chris@3 57
Chris@3 58 r.setNum(c.red(), 16);
Chris@3 59 if (c.red() < 16) r = "0" + r;
Chris@3 60
Chris@3 61 g.setNum(c.green(), 16);
Chris@3 62 if (c.green() < 16) g = "0" + g;
Chris@3 63
Chris@3 64 b.setNum(c.blue(), 16);
Chris@3 65 if (c.blue() < 16) b = "0" + b;
Chris@3 66
Chris@3 67 return "#" + r + g + b;
Chris@3 68 }
Chris@3 69
Chris@4 70 int
Chris@4 71 XmlExportable::getObjectExportId(const void * object)
Chris@4 72 {
Chris@85 73 static QMutex mutex;
Chris@85 74 QMutexLocker locker(&mutex);
Chris@85 75
Chris@4 76 static std::map<const void *, int> idMap;
Chris@4 77 static int maxId = 0;
Chris@4 78
Chris@4 79 if (idMap.find(object) == idMap.end()) {
Chris@4 80 idMap[object] = maxId++;
Chris@4 81 }
Chris@4 82
Chris@4 83 return idMap[object];
Chris@4 84 }
Chris@4 85
Chris@4 86