# HG changeset patch # User Chris Cannam # Date 1192702507 0 # Node ID 70a232b1f12aab0cc9cafff90d0a660595a89ce4 # Parent 29485aa03da400252741c2d872920a89a12bad4c * Make XmlExportable::toXml the function that is universally overridden (and pure virtual) instead of toXmlString. Tidies up some classes, notably the model classes, significantly. Closes #1794561. diff -r 29485aa03da4 -r 70a232b1f12a base/PlayParameters.cpp --- a/base/PlayParameters.cpp Wed Oct 17 12:58:45 2007 +0000 +++ b/base/PlayParameters.cpp Thu Oct 18 10:15:07 2007 +0000 @@ -17,6 +17,8 @@ #include +#include + void PlayParameters::copyFrom(const PlayParameters *pp) { @@ -27,25 +29,24 @@ m_playPluginConfiguration = pp->getPlayPluginConfiguration(); } -QString -PlayParameters::toXmlString(QString indent, - QString extraAttributes) const +void +PlayParameters::toXml(QTextStream &stream, + QString indent, + QString extraAttributes) const { - QString s; - s += indent; - s += QString("\n"; + stream << ">\n " << indent << m_playPluginConfiguration + << "\n" << indent << "\n"; } else { - s += "/>\n"; + stream << "/>\n"; } - return s; } void diff -r 29485aa03da4 -r 70a232b1f12a base/PlayParameters.h --- a/base/PlayParameters.h Wed Oct 17 12:58:45 2007 +0000 +++ b/base/PlayParameters.h Thu Oct 18 10:15:07 2007 +0000 @@ -36,8 +36,9 @@ virtual void copyFrom(const PlayParameters *); - virtual QString toXmlString(QString indent = "", - QString extraAttributes = "") const; + virtual void toXml(QTextStream &stream, + QString indent = "", + QString extraAttributes = "") const; public slots: virtual void setPlayMuted(bool muted); diff -r 29485aa03da4 -r 70a232b1f12a base/Selection.cpp --- a/base/Selection.cpp Wed Oct 17 12:58:45 2007 +0000 +++ b/base/Selection.cpp Thu Oct 18 10:15:07 2007 +0000 @@ -14,6 +14,7 @@ */ #include "Selection.h" +#include Selection::Selection() : m_startFrame(0), @@ -212,18 +213,17 @@ return Selection(); } -QString -MultiSelection::toXmlString(QString indent, - QString extraAttributes) const +void +MultiSelection::toXml(QTextStream &stream, QString indent, + QString extraAttributes) const { - QString s; - s += indent + QString("\n").arg(extraAttributes); + stream << indent << QString("\n").arg(extraAttributes); for (SelectionList::iterator i = m_selections.begin(); i != m_selections.end(); ++i) { - s += indent + QString(" \n") + stream << indent + << QString(" \n") .arg(i->getStartFrame()).arg(i->getEndFrame()); } - s += indent + "\n"; - return s; + stream << indent << "\n"; } diff -r 29485aa03da4 -r 70a232b1f12a base/Selection.h --- a/base/Selection.h Wed Oct 17 12:58:45 2007 +0000 +++ b/base/Selection.h Thu Oct 18 10:15:07 2007 +0000 @@ -67,8 +67,8 @@ */ Selection getContainingSelection(size_t frame, bool defaultToFollowing) const; - virtual QString toXmlString(QString indent = "", - QString extraAttributes = "") const; + virtual void toXml(QTextStream &stream, QString indent = "", + QString extraAttributes = "") const; protected: SelectionList m_selections; diff -r 29485aa03da4 -r 70a232b1f12a base/XmlExportable.cpp --- a/base/XmlExportable.cpp Wed Oct 17 12:58:45 2007 +0000 +++ b/base/XmlExportable.cpp Thu Oct 18 10:15:07 2007 +0000 @@ -19,11 +19,18 @@ #include #include -void -XmlExportable::toXml(QTextStream &stream, QString indent, - QString extraAttributes) const +QString +XmlExportable::toXmlString(QString indent, + QString extraAttributes) const { - stream << toXmlString(indent, extraAttributes); + QString s; + + { + QTextStream out(&s); + toXml(out, indent, extraAttributes); + } + + return s; } QString diff -r 29485aa03da4 -r 70a232b1f12a base/XmlExportable.h --- a/base/XmlExportable.h Wed Oct 17 12:58:45 2007 +0000 +++ b/base/XmlExportable.h Thu Oct 18 10:15:07 2007 +0000 @@ -28,23 +28,18 @@ /** * Stream this exportable object out to XML on a text stream. - * - * The default implementation calls toXmlString and streams the - * resulting string. This is only appropriate for objects with - * short representations. Bigger objects should override this - * method so as to write to the stream directly and override - * toXmlString with a method that calls this one, so that the - * direct streaming method can be used when appropriate. */ virtual void toXml(QTextStream &stream, QString indent = "", - QString extraAttributes = "") const; + QString extraAttributes = "") const = 0; /** - * Convert this exportable object to XML in a string. + * Convert this exportable object to XML in a string. The default + * implementation calls toXml and returns the result as a string. + * Do not override this unless you really know what you're doing. */ virtual QString toXmlString(QString indent = "", - QString extraAttributes = "") const = 0; + QString extraAttributes = "") const; static QString encodeEntities(QString); diff -r 29485aa03da4 -r 70a232b1f12a data/model/AggregateWaveModel.cpp --- a/data/model/AggregateWaveModel.cpp Wed Oct 17 12:58:45 2007 +0000 +++ b/data/model/AggregateWaveModel.cpp Thu Oct 18 10:15:07 2007 +0000 @@ -17,6 +17,8 @@ #include +#include + PowerOfSqrtTwoZoomConstraint AggregateWaveModel::m_zoomConstraint; diff -r 29485aa03da4 -r 70a232b1f12a data/model/EditableDenseThreeDimensionalModel.cpp --- a/data/model/EditableDenseThreeDimensionalModel.cpp Wed Oct 17 12:58:45 2007 +0000 +++ b/data/model/EditableDenseThreeDimensionalModel.cpp Thu Oct 18 10:15:07 2007 +0000 @@ -272,13 +272,14 @@ void EditableDenseThreeDimensionalModel::toXml(QTextStream &out, - QString indent, - QString extraAttributes) const + QString indent, + QString extraAttributes) const { // For historical reasons we read and write "resolution" as "windowSize" - out << Model::toXmlString - (indent, QString("type=\"dense\" dimensions=\"3\" windowSize=\"%1\" yBinCount=\"%2\" minimum=\"%3\" maximum=\"%4\" dataset=\"%5\" %6") + Model::toXml + (out, indent, + QString("type=\"dense\" dimensions=\"3\" windowSize=\"%1\" yBinCount=\"%2\" minimum=\"%3\" maximum=\"%4\" dataset=\"%5\" %6") .arg(m_resolution) .arg(m_yBinCount) .arg(m_minimum) @@ -311,17 +312,4 @@ out << indent + "\n"; } -QString -EditableDenseThreeDimensionalModel::toXmlString(QString indent, - QString extraAttributes) const -{ - QString s; - { - QTextStream out(&s); - toXml(out, indent, extraAttributes); - } - - return s; -} - diff -r 29485aa03da4 -r 70a232b1f12a data/model/EditableDenseThreeDimensionalModel.h --- a/data/model/EditableDenseThreeDimensionalModel.h Wed Oct 17 12:58:45 2007 +0000 +++ b/data/model/EditableDenseThreeDimensionalModel.h Thu Oct 18 10:15:07 2007 +0000 @@ -113,9 +113,6 @@ QString indent = "", QString extraAttributes = "") const; - virtual QString toXmlString(QString indent = "", - QString extraAttributes = "") const; - protected: typedef std::vector ValueMatrix; ValueMatrix m_data; diff -r 29485aa03da4 -r 70a232b1f12a data/model/ImageModel.h --- a/data/model/ImageModel.h Wed Oct 17 12:58:45 2007 +0000 +++ b/data/model/ImageModel.h Thu Oct 18 10:15:07 2007 +0000 @@ -39,10 +39,12 @@ QString image; QString label; - QString toXmlString(QString indent = "", - QString extraAttributes = "") const + void toXml(QTextStream &stream, + QString indent = "", + QString extraAttributes = "") const { - return QString("%1\n") + stream << + QString("%1\n") .arg(indent).arg(frame) .arg(encodeEntities(image)) .arg(encodeEntities(label)) diff -r 29485aa03da4 -r 70a232b1f12a data/model/Model.cpp --- a/data/model/Model.cpp Wed Oct 17 12:58:45 2007 +0000 +++ b/data/model/Model.cpp Thu Oct 18 10:15:07 2007 +0000 @@ -47,16 +47,4 @@ .arg(extraAttributes); } -QString -Model::toXmlString(QString indent, QString extraAttributes) const -{ - QString s; - { - QTextStream out(&s); - toXml(out, indent, extraAttributes); - } - - return s; -} - diff -r 29485aa03da4 -r 70a232b1f12a data/model/Model.h --- a/data/model/Model.h Wed Oct 17 12:58:45 2007 +0000 +++ b/data/model/Model.h Thu Oct 18 10:15:07 2007 +0000 @@ -132,9 +132,6 @@ QString indent = "", QString extraAttributes = "") const; - virtual QString toXmlString(QString indent = "", - QString extraAttributes = "") const; - virtual QString toDelimitedDataString(QString) const { return ""; } signals: diff -r 29485aa03da4 -r 70a232b1f12a data/model/NoteModel.h --- a/data/model/NoteModel.h Wed Oct 17 12:58:45 2007 +0000 +++ b/data/model/NoteModel.h Thu Oct 18 10:15:07 2007 +0000 @@ -43,10 +43,12 @@ size_t duration; QString label; - QString toXmlString(QString indent = "", - QString extraAttributes = "") const + void toXml(QTextStream &stream, + QString indent = "", + QString extraAttributes = "") const { - return QString("%1\n") + stream << + QString("%1\n") .arg(indent).arg(frame).arg(value).arg(duration).arg(label).arg(extraAttributes); } @@ -124,7 +126,7 @@ QString indent = "", QString extraAttributes = "") const { - return SparseValueModel::toXml + SparseValueModel::toXml (out, indent, QString("%1 valueQuantization=\"%2\"") diff -r 29485aa03da4 -r 70a232b1f12a data/model/SparseModel.h --- a/data/model/SparseModel.h Wed Oct 17 12:58:45 2007 +0000 +++ b/data/model/SparseModel.h Thu Oct 18 10:15:07 2007 +0000 @@ -136,9 +136,6 @@ QString indent = "", QString extraAttributes = "") const; - virtual QString toXmlString(QString indent = "", - QString extraAttributes = "") const; - virtual QString toDelimitedDataString(QString delimiter) const { QString s; @@ -567,7 +564,7 @@ .arg(PointType(0).getDimensions()); for (PointListIterator i = m_points.begin(); i != m_points.end(); ++i) { - out << i->toXmlString(indent + " "); + i->toXml(out, indent + " "); } out << indent; @@ -575,21 +572,6 @@ } template -QString -SparseModel::toXmlString(QString indent, - QString extraAttributes) const -{ - QString s; - - { - QTextStream out(&s); - toXml(out, indent, extraAttributes); - } - - return s; -} - -template SparseModel::EditCommand::EditCommand(SparseModel *model, QString commandName) : MacroCommand(commandName), diff -r 29485aa03da4 -r 70a232b1f12a data/model/SparseOneDimensionalModel.h --- a/data/model/SparseOneDimensionalModel.h Wed Oct 17 12:58:45 2007 +0000 +++ b/data/model/SparseOneDimensionalModel.h Thu Oct 18 10:15:07 2007 +0000 @@ -31,10 +31,11 @@ long frame; QString label; - QString toXmlString(QString indent = "", - QString extraAttributes = "") const + void toXml(QTextStream &stream, + QString indent = "", + QString extraAttributes = "") const { - return QString("%1\n") + stream << QString("%1\n") .arg(indent).arg(frame).arg(label).arg(extraAttributes); } diff -r 29485aa03da4 -r 70a232b1f12a data/model/SparseTimeValueModel.h --- a/data/model/SparseTimeValueModel.h Wed Oct 17 12:58:45 2007 +0000 +++ b/data/model/SparseTimeValueModel.h Thu Oct 18 10:15:07 2007 +0000 @@ -39,10 +39,10 @@ float value; QString label; - QString toXmlString(QString indent = "", - QString extraAttributes = "") const + void toXml(QTextStream &stream, QString indent = "", + QString extraAttributes = "") const { - return QString("%1\n") + stream << QString("%1\n") .arg(indent).arg(frame).arg(value).arg(label).arg(extraAttributes); } diff -r 29485aa03da4 -r 70a232b1f12a data/model/SparseValueModel.h --- a/data/model/SparseValueModel.h Wed Oct 17 12:58:45 2007 +0000 +++ b/data/model/SparseValueModel.h Thu Oct 18 10:15:07 2007 +0000 @@ -110,11 +110,11 @@ } } - virtual QString toXmlString(QString indent = "", - QString extraAttributes = "") const + virtual void toXml(QTextStream &stream, QString indent = "", + QString extraAttributes = "") const { - return SparseModel::toXmlString - (indent, + SparseModel::toXml + (stream, indent, QString("%1 minimum=\"%2\" maximum=\"%3\" units=\"%4\"") .arg(extraAttributes).arg(m_valueMinimum).arg(m_valueMaximum) .arg(this->encodeEntities(m_units))); diff -r 29485aa03da4 -r 70a232b1f12a data/model/TextModel.h --- a/data/model/TextModel.h Wed Oct 17 12:58:45 2007 +0000 +++ b/data/model/TextModel.h Thu Oct 18 10:15:07 2007 +0000 @@ -39,10 +39,10 @@ float height; QString label; - QString toXmlString(QString indent = "", - QString extraAttributes = "") const + void toXml(QTextStream &stream, QString indent = "", + QString extraAttributes = "") const { - return QString("%1\n") + stream << QString("%1\n") .arg(indent).arg(frame).arg(height) .arg(encodeEntities(label)).arg(extraAttributes); } diff -r 29485aa03da4 -r 70a232b1f12a data/model/WaveFileModel.cpp --- a/data/model/WaveFileModel.cpp Wed Oct 17 12:58:45 2007 +0000 +++ b/data/model/WaveFileModel.cpp Thu Oct 18 10:15:07 2007 +0000 @@ -22,6 +22,7 @@ #include #include +#include #include #include diff -r 29485aa03da4 -r 70a232b1f12a data/model/WritableWaveFileModel.cpp --- a/data/model/WritableWaveFileModel.cpp Wed Oct 17 12:58:45 2007 +0000 +++ b/data/model/WritableWaveFileModel.cpp Thu Oct 18 10:15:07 2007 +0000 @@ -22,6 +22,7 @@ #include "fileio/WavFileReader.h" #include +#include #include #include diff -r 29485aa03da4 -r 70a232b1f12a plugin/PluginXml.cpp --- a/plugin/PluginXml.cpp Wed Oct 17 12:58:45 2007 +0000 +++ b/plugin/PluginXml.cpp Thu Oct 18 10:15:07 2007 +0000 @@ -23,6 +23,8 @@ #include #include +#include + #include "vamp-sdk/PluginBase.h" #include "RealTimePluginInstance.h" @@ -53,13 +55,13 @@ return rv; } -QString -PluginXml::toXmlString(QString indent, QString extraAttributes) const +void +PluginXml::toXml(QTextStream &stream, + QString indent, QString extraAttributes) const { - QString s; - s += indent; + stream << indent; - s += QString("getIdentifier().c_str()))) .arg(encodeEntities(QString(m_plugin->getName().c_str()))) .arg(encodeEntities(QString(m_plugin->getDescription().c_str()))) @@ -69,7 +71,7 @@ .arg(extraAttributes); if (!m_plugin->getPrograms().empty()) { - s += QString("program=\"%1\" ") + stream << QString("program=\"%1\" ") .arg(encodeEntities(m_plugin->getCurrentProgram().c_str())); } @@ -79,11 +81,11 @@ for (Vamp::PluginBase::ParameterList::const_iterator i = parameters.begin(); i != parameters.end(); ++i) { -// std::cerr << "PluginXml::toXmlString: parameter name \"" +// std::cerr << "PluginXml::toXml: parameter name \"" // << i->name.c_str() << "\" has value " // << m_plugin->getParameter(i->name) << std::endl; - s += QString("param-%1=\"%2\" ") + stream << QString("param-%1=\"%2\" ") .arg(stripInvalidParameterNameCharacters(QString(i->identifier.c_str()))) .arg(m_plugin->getParameter(i->identifier)); } @@ -104,13 +106,12 @@ config += QString("%1=%2").arg(key).arg(value); } if (config != "") { - s += QString("configuration=\"%1\" ") + stream << QString("configuration=\"%1\" ") .arg(encodeEntities(config)); } } - s += "/>\n"; - return s; + stream << "/>\n"; } #define CHECK_ATTRIBUTE(ATTRIBUTE, ACCESSOR) \ diff -r 29485aa03da4 -r 70a232b1f12a plugin/PluginXml.h --- a/plugin/PluginXml.h Wed Oct 17 12:58:45 2007 +0000 +++ b/plugin/PluginXml.h Thu Oct 18 10:15:07 2007 +0000 @@ -31,19 +31,20 @@ /** * Export plugin settings to XML. */ - virtual QString toXmlString(QString indent = "", - QString extraAttributes = "") const; + virtual void toXml(QTextStream &stream, + QString indent = "", + QString extraAttributes = "") const; /** * Set the parameters and program of a plugin from a set of XML - * attributes. This is a partial inverse of toXmlString. + * attributes. This is a partial inverse of toXml. */ virtual void setParameters(const QXmlAttributes &); /** * Set the parameters and program of a plugin from an XML plugin - * element as returned by toXmlString. This is a partial inverse - * of toXmlString. + * element as returned by toXml. This is a partial inverse of + * toXml. */ virtual void setParametersFromXml(QString xml);