annotate base/XmlExportable.cpp @ 1300:4a2bc07ec0fb 3.0-integration

Make CSV feature writer produce the same output with Qt 5.6 and 5.7+
author Chris Cannam
date Fri, 25 Nov 2016 17:33:44 +0000
parents 1424aa29ae95
children 48e9f538e6e9
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@690 28 // SVDEBUG << "XmlExportable::toXmlString" << 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@387 54 XmlExportable::encodeColour(int ri, int gi, int bi)
Chris@3 55 {
Chris@3 56 QString r, g, b;
Chris@3 57
Chris@387 58 r.setNum(ri, 16);
Chris@387 59 if (ri < 16) r = "0" + r;
Chris@3 60
Chris@387 61 g.setNum(gi, 16);
Chris@387 62 if (gi < 16) g = "0" + g;
Chris@3 63
Chris@387 64 b.setNum(bi, 16);
Chris@387 65 if (bi < 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