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@1581: #ifndef SV_XML_EXPORTABLE_H Chris@1581: #define SV_XML_EXPORTABLE_H Chris@3: Chris@3: #include Chris@3: Chris@686: #include "Debug.h" Chris@686: Chris@123: class QTextStream; Chris@123: Chris@3: class XmlExportable Chris@3: { Chris@3: public: Chris@1738: enum { Chris@1738: // The value NO_ID (-1) is never allocated as an export id Chris@1738: NO_ID = -1 Chris@1738: }; Chris@1738: Chris@1750: typedef int ExportId; Chris@1750: Chris@1738: XmlExportable() : m_exportId(NO_ID) { } Chris@27: virtual ~XmlExportable() { } Chris@27: Chris@123: /** Chris@1677: * Return the numerical export identifier for this object. It's Chris@1677: * allocated the first time this is called, so objects on which Chris@1677: * this is never called do not get allocated one. Chris@1677: */ Chris@1750: ExportId getExportId() const; Chris@1677: Chris@1677: /** Chris@123: * Stream this exportable object out to XML on a text stream. Chris@123: */ Chris@123: virtual void toXml(QTextStream &stream, Chris@123: QString indent = "", Chris@314: QString extraAttributes = "") const = 0; Chris@123: Chris@123: /** Chris@314: * Convert this exportable object to XML in a string. The default Chris@314: * implementation calls toXml and returns the result as a string. Chris@314: * Do not override this unless you really know what you're doing. Chris@123: */ Chris@3: virtual QString toXmlString(QString indent = "", Chris@1429: QString extraAttributes = "") const; Chris@3: Chris@3: static QString encodeEntities(QString); Chris@3: Chris@387: static QString encodeColour(int r, int g, int b); Chris@4: Chris@1677: private: Chris@1677: mutable int m_exportId; Chris@3: }; Chris@3: Chris@3: #endif