Chris@49: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@3: Chris@3: /* Chris@52: Sonic Visualiser Chris@52: An audio file viewer and annotation editor. Chris@52: Centre for Digital Music, Queen Mary, University of London. Chris@52: This file copyright 2006 Chris Cannam. Chris@3: Chris@52: This program is free software; you can redistribute it and/or Chris@52: modify it under the terms of the GNU General Public License as Chris@52: published by the Free Software Foundation; either version 2 of the Chris@52: License, or (at your option) any later version. See the file Chris@52: COPYING included with this distribution for more information. Chris@3: */ Chris@3: Chris@3: #include "XmlExportable.h" Chris@4: #include Chris@85: #include Chris@85: #include Chris@3: Chris@3: QString Chris@3: XmlExportable::encodeEntities(QString s) Chris@3: { Chris@3: s Chris@3: .replace("&", "&") Chris@3: .replace("<", "<") Chris@3: .replace(">", ">") Chris@3: .replace("\"", """) Chris@3: .replace("'", "'"); Chris@3: Chris@3: return s; Chris@3: } Chris@3: Chris@3: QString Chris@3: XmlExportable::encodeColour(QColor c) Chris@3: { Chris@3: QString r, g, b; Chris@3: Chris@3: r.setNum(c.red(), 16); Chris@3: if (c.red() < 16) r = "0" + r; Chris@3: Chris@3: g.setNum(c.green(), 16); Chris@3: if (c.green() < 16) g = "0" + g; Chris@3: Chris@3: b.setNum(c.blue(), 16); Chris@3: if (c.blue() < 16) b = "0" + b; Chris@3: Chris@3: return "#" + r + g + b; Chris@3: } Chris@3: Chris@4: int Chris@4: XmlExportable::getObjectExportId(const void * object) Chris@4: { Chris@85: static QMutex mutex; Chris@85: QMutexLocker locker(&mutex); Chris@85: Chris@4: static std::map idMap; Chris@4: static int maxId = 0; Chris@4: Chris@4: if (idMap.find(object) == idMap.end()) { Chris@4: idMap[object] = maxId++; Chris@4: } Chris@4: Chris@4: return idMap[object]; Chris@4: } Chris@4: Chris@4: