Mercurial > hg > svgui
changeset 11:2d5005f2b3d9
* Rework handling of layer properties in file I/O -- we now get the individual
layers to load and save them rather than doing it via generic property lists
in the base class, so as to ensure we read and write meaningful values rather
than generic int values requiring conversion.
author | Chris Cannam |
---|---|
date | Thu, 19 Jan 2006 12:54:38 +0000 |
parents | 8f5b812baaee |
children | 484e7320f59f |
files | layer/Colour3DPlotLayer.h layer/LayerFactory.cpp layer/SpectrogramLayer.cpp layer/SpectrogramLayer.h layer/TimeInstantLayer.cpp layer/TimeInstantLayer.h layer/TimeRulerLayer.cpp layer/TimeRulerLayer.h layer/TimeValueLayer.cpp layer/TimeValueLayer.h layer/WaveformLayer.cpp layer/WaveformLayer.h |
diffstat | 12 files changed, 136 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/layer/Colour3DPlotLayer.h Tue Jan 17 17:45:55 2006 +0000 +++ b/layer/Colour3DPlotLayer.h Thu Jan 19 12:54:38 2006 +0000 @@ -58,6 +58,8 @@ virtual QString getPropertyContainerIconName() const { return "colour3d"; } + void setProperties(const QXmlAttributes &attributes) { } + protected slots: void cacheInvalid(); void cacheInvalid(size_t startFrame, size_t endFrame);
--- a/layer/LayerFactory.cpp Tue Jan 17 17:45:55 2006 +0000 +++ b/layer/LayerFactory.cpp Thu Jan 19 12:54:38 2006 +0000 @@ -51,6 +51,8 @@ // fact -- there's nothing permanently melodic-range about it // that should be encoded in its name return Layer::tr("Spectrogram"); + + default: break; } return Layer::tr("Layer"); @@ -189,6 +191,8 @@ layer = new SpectrogramLayer(view, SpectrogramLayer::MelodicRange); static_cast<SpectrogramLayer *>(layer)->setChannel(channel); break; + + default: break; } if (!layer) {
--- a/layer/SpectrogramLayer.cpp Tue Jan 17 17:45:55 2006 +0000 +++ b/layer/SpectrogramLayer.cpp Thu Jan 19 12:54:38 2006 +0000 @@ -1778,6 +1778,44 @@ return Layer::toXmlString(indent, extraAttributes + " " + s); } +void +SpectrogramLayer::setProperties(const QXmlAttributes &attributes) +{ + bool ok = false; + + int channel = attributes.value("channel").toInt(&ok); + if (ok) setChannel(channel); + + size_t windowSize = attributes.value("windowSize").toUInt(&ok); + if (ok) setWindowSize(windowSize); + + WindowType windowType = (WindowType) + attributes.value("windowType").toInt(&ok); + if (ok) setWindowType(windowType); + + size_t windowOverlap = attributes.value("windowOverlap").toUInt(&ok); + if (ok) setWindowOverlap(windowOverlap); + + float gain = attributes.value("gain").toFloat(&ok); + if (ok) setGain(gain); + + size_t maxFrequency = attributes.value("maxFrequency").toUInt(&ok); + if (ok) setMaxFrequency(maxFrequency); + + ColourScale colourScale = (ColourScale) + attributes.value("colourScale").toInt(&ok); + if (ok) setColourScale(colourScale); + + ColourScheme colourScheme = (ColourScheme) + attributes.value("colourScheme").toInt(&ok); + if (ok) setColourScheme(colourScheme); + + FrequencyScale frequencyScale = (FrequencyScale) + attributes.value("frequencyScale").toInt(&ok); + if (ok) setFrequencyScale(frequencyScale); +} + + #ifdef INCLUDE_MOCFILES #include "SpectrogramLayer.moc.cpp" #endif
--- a/layer/SpectrogramLayer.h Tue Jan 17 17:45:55 2006 +0000 +++ b/layer/SpectrogramLayer.h Thu Jan 19 12:54:38 2006 +0000 @@ -135,6 +135,8 @@ virtual QString toXmlString(QString indent = "", QString extraAttributes = "") const; + void setProperties(const QXmlAttributes &attributes); + protected slots: void cacheInvalid(); void cacheInvalid(size_t startFrame, size_t endFrame);
--- a/layer/TimeInstantLayer.cpp Tue Jan 17 17:45:55 2006 +0000 +++ b/layer/TimeInstantLayer.cpp Thu Jan 19 12:54:38 2006 +0000 @@ -305,6 +305,18 @@ QString(" colour=\"%1\"").arg(encodeColour(m_colour))); } +void +TimeInstantLayer::setProperties(const QXmlAttributes &attributes) +{ + QString colourSpec = attributes.value("colour"); + if (colourSpec != "") { + QColor colour(colourSpec); + if (colour.isValid()) { + setBaseColour(QColor(colourSpec)); + } + } +} + #ifdef INCLUDE_MOCFILES #include "TimeInstantLayer.moc.cpp" #endif
--- a/layer/TimeInstantLayer.h Tue Jan 17 17:45:55 2006 +0000 +++ b/layer/TimeInstantLayer.h Thu Jan 19 12:54:38 2006 +0000 @@ -54,6 +54,8 @@ virtual QString toXmlString(QString indent = "", QString extraAttributes = "") const; + void setProperties(const QXmlAttributes &attributes); + protected: SparseOneDimensionalModel::PointList getLocalPoints(int) const;
--- a/layer/TimeRulerLayer.cpp Tue Jan 17 17:45:55 2006 +0000 +++ b/layer/TimeRulerLayer.cpp Thu Jan 19 12:54:38 2006 +0000 @@ -288,6 +288,18 @@ QString(" colour=\"%1\"").arg(encodeColour(m_colour))); } +void +TimeRulerLayer::setProperties(const QXmlAttributes &attributes) +{ + QString colourSpec = attributes.value("colour"); + if (colourSpec != "") { + QColor colour(colourSpec); + if (colour.isValid()) { + setBaseColour(QColor(colourSpec)); + } + } +} + #ifdef INCLUDE_MOCFILES #include "TimeRulerLayer.moc.cpp"
--- a/layer/TimeRulerLayer.h Tue Jan 17 17:45:55 2006 +0000 +++ b/layer/TimeRulerLayer.h Thu Jan 19 12:54:38 2006 +0000 @@ -51,6 +51,8 @@ virtual QString toXmlString(QString indent = "", QString extraAttributes = "") const; + void setProperties(const QXmlAttributes &attributes); + protected: Model *m_model; QColor m_colour;
--- a/layer/TimeValueLayer.cpp Tue Jan 17 17:45:55 2006 +0000 +++ b/layer/TimeValueLayer.cpp Thu Jan 19 12:54:38 2006 +0000 @@ -287,6 +287,7 @@ SparseTimeValueModel::PointList points(m_model->getPoints (frame0, frame1)); + if (points.empty()) return; paint.setPen(m_colour); @@ -438,6 +439,23 @@ .arg(encodeColour(m_colour)).arg(m_plotStyle)); } +void +TimeValueLayer::setProperties(const QXmlAttributes &attributes) +{ + QString colourSpec = attributes.value("colour"); + if (colourSpec != "") { + QColor colour(colourSpec); + if (colour.isValid()) { + setBaseColour(QColor(colourSpec)); + } + } + + bool ok; + PlotStyle style = (PlotStyle) + attributes.value("plotStyle").toInt(&ok); + if (ok) setPlotStyle(style); +} + #ifdef INCLUDE_MOCFILES #include "TimeValueLayer.moc.cpp"
--- a/layer/TimeValueLayer.h Tue Jan 17 17:45:55 2006 +0000 +++ b/layer/TimeValueLayer.h Thu Jan 19 12:54:38 2006 +0000 @@ -59,6 +59,8 @@ virtual QString toXmlString(QString indent = "", QString extraAttributes = "") const; + void setProperties(const QXmlAttributes &attributes); + protected: SparseTimeValueModel::PointList getLocalPoints(int) const;
--- a/layer/WaveformLayer.cpp Tue Jan 17 17:45:55 2006 +0000 +++ b/layer/WaveformLayer.cpp Thu Jan 19 12:54:38 2006 +0000 @@ -768,6 +768,46 @@ return Layer::toXmlString(indent, extraAttributes + " " + s); } +void +WaveformLayer::setProperties(const QXmlAttributes &attributes) +{ + bool ok = false; + + float gain = attributes.value("gain").toFloat(&ok); + if (ok) setGain(gain); + + QString colourSpec = attributes.value("colour"); + if (colourSpec != "") { + QColor colour(colourSpec); + if (colour.isValid()) { + setBaseColour(QColor(colourSpec)); + } + } + + bool showMeans = (attributes.value("showMeans") == "1" || + attributes.value("showMeans") == "true"); + setShowMeans(showMeans); + + bool greyscale = (attributes.value("greyscale") == "1" || + attributes.value("greyscale") == "true"); + setUseGreyscale(greyscale); + + ChannelMode channelMode = (ChannelMode) + attributes.value("channelMode").toInt(&ok); + if (ok) setChannelMode(channelMode); + + int channel = attributes.value("channel").toInt(&ok); + if (ok) setChannel(channel); + + Scale scale = (Scale) + attributes.value("scale").toInt(&ok); + if (ok) setScale(scale); + + bool aggressive = (attributes.value("aggressive") == "1" || + attributes.value("aggressive") == "true"); + setUseGreyscale(aggressive); +} + #ifdef INCLUDE_MOCFILES #include "WaveformLayer.moc.cpp" #endif
--- a/layer/WaveformLayer.h Tue Jan 17 17:45:55 2006 +0000 +++ b/layer/WaveformLayer.h Thu Jan 19 12:54:38 2006 +0000 @@ -160,6 +160,8 @@ virtual QString toXmlString(QString indent = "", QString extraAttributes = "") const; + void setProperties(const QXmlAttributes &attributes); + protected: int dBscale(float sample, int m) const;