Mercurial > hg > svgui
diff layer/LayerFactory.cpp @ 326:4f4f38a11cd2
* Factor out uses of "Sonic Visualiser" in "common" code to applicationName()
* Add ability to show work title + artist in top-left of pane (thinking of Vect
but may be useful in SV in future)
* A few other generalisations useful for Vect
author | Chris Cannam |
---|---|
date | Fri, 09 Nov 2007 17:46:58 +0000 |
parents | 46faec7aae12 |
children | 29fcf125f98b |
line wrap: on
line diff
--- a/layer/LayerFactory.cpp Wed Nov 07 16:52:52 2007 +0000 +++ b/layer/LayerFactory.cpp Fri Nov 09 17:46:58 2007 +0000 @@ -39,6 +39,13 @@ #include "data/model/WaveFileModel.h" #include "data/model/WritableWaveFileModel.h" +#include <QDomDocument> +#include <QDomElement> +#include <QDomNamedNodeMap> +#include <QDomAttr> + +#include <QSettings> + LayerFactory * LayerFactory::m_instance = new LayerFactory; @@ -212,6 +219,8 @@ case Colour3DPlot: return "colour3d"; case Spectrum: return "spectrum"; case Slice: return "spectrum"; + case MelodicRangeSpectrogram: return "spectrogram"; + case PeakFrequencySpectrogram: return "spectrogram"; default: return "unknown"; } } @@ -231,6 +240,8 @@ case Colour3DPlot: return "colour3dplot"; case Spectrum: return "spectrum"; case Slice: return "slice"; + case MelodicRangeSpectrogram: return "melodicrange"; + case PeakFrequencySpectrogram: return "peakfrequency"; default: return "unknown"; } } @@ -410,8 +421,50 @@ // std::cerr << "LayerFactory::createLayer: Setting object name " // << getLayerPresentationName(type).toStdString() << " on " << layer << std::endl; layer->setObjectName(getLayerPresentationName(type)); + setLayerDefaultProperties(type, layer); } return layer; } +void +LayerFactory::setLayerDefaultProperties(LayerType type, Layer *layer) +{ + QSettings settings; + settings.beginGroup("LayerDefaults"); + QString defaults = settings.value(getLayerTypeName(type), "").toString(); + if (defaults == "") return; + + QString xml = layer->toXmlString(); + QDomDocument docOld, docNew; + + if (docOld.setContent(xml, false) && + docNew.setContent(defaults, false)) { + + QXmlAttributes attrs; + + QDomElement layerElt = docNew.firstChildElement("layer"); + QDomNamedNodeMap attrNodes = layerElt.attributes(); + + for (unsigned int i = 0; i < attrNodes.length(); ++i) { + QDomAttr attr = attrNodes.item(i).toAttr(); + if (attr.isNull()) continue; + attrs.append(attr.name(), "", "", attr.value()); + } + + layerElt = docOld.firstChildElement("layer"); + attrNodes = layerElt.attributes(); + for (unsigned int i = 0; i < attrNodes.length(); ++i) { + QDomAttr attr = attrNodes.item(i).toAttr(); + if (attr.isNull()) continue; + if (attrs.value(attr.name()) == "") { + attrs.append(attr.name(), "", "", attr.value()); + } + } + + layer->setProperties(attrs); + } + + settings.endGroup(); +} +