Mercurial > hg > svgui
comparison 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 |
comparison
equal
deleted
inserted
replaced
324:1f67b110c1a3 | 326:4f4f38a11cd2 |
---|---|
36 #include "data/model/TextModel.h" | 36 #include "data/model/TextModel.h" |
37 #include "data/model/ImageModel.h" | 37 #include "data/model/ImageModel.h" |
38 #include "data/model/DenseThreeDimensionalModel.h" | 38 #include "data/model/DenseThreeDimensionalModel.h" |
39 #include "data/model/WaveFileModel.h" | 39 #include "data/model/WaveFileModel.h" |
40 #include "data/model/WritableWaveFileModel.h" | 40 #include "data/model/WritableWaveFileModel.h" |
41 | |
42 #include <QDomDocument> | |
43 #include <QDomElement> | |
44 #include <QDomNamedNodeMap> | |
45 #include <QDomAttr> | |
46 | |
47 #include <QSettings> | |
41 | 48 |
42 LayerFactory * | 49 LayerFactory * |
43 LayerFactory::m_instance = new LayerFactory; | 50 LayerFactory::m_instance = new LayerFactory; |
44 | 51 |
45 LayerFactory * | 52 LayerFactory * |
210 case Text: return "text"; | 217 case Text: return "text"; |
211 case Image: return "image"; | 218 case Image: return "image"; |
212 case Colour3DPlot: return "colour3d"; | 219 case Colour3DPlot: return "colour3d"; |
213 case Spectrum: return "spectrum"; | 220 case Spectrum: return "spectrum"; |
214 case Slice: return "spectrum"; | 221 case Slice: return "spectrum"; |
222 case MelodicRangeSpectrogram: return "spectrogram"; | |
223 case PeakFrequencySpectrogram: return "spectrogram"; | |
215 default: return "unknown"; | 224 default: return "unknown"; |
216 } | 225 } |
217 } | 226 } |
218 | 227 |
219 QString | 228 QString |
229 case Text: return "text"; | 238 case Text: return "text"; |
230 case Image: return "image"; | 239 case Image: return "image"; |
231 case Colour3DPlot: return "colour3dplot"; | 240 case Colour3DPlot: return "colour3dplot"; |
232 case Spectrum: return "spectrum"; | 241 case Spectrum: return "spectrum"; |
233 case Slice: return "slice"; | 242 case Slice: return "slice"; |
243 case MelodicRangeSpectrogram: return "melodicrange"; | |
244 case PeakFrequencySpectrogram: return "peakfrequency"; | |
234 default: return "unknown"; | 245 default: return "unknown"; |
235 } | 246 } |
236 } | 247 } |
237 | 248 |
238 LayerFactory::LayerType | 249 LayerFactory::LayerType |
408 << type << std::endl; | 419 << type << std::endl; |
409 } else { | 420 } else { |
410 // std::cerr << "LayerFactory::createLayer: Setting object name " | 421 // std::cerr << "LayerFactory::createLayer: Setting object name " |
411 // << getLayerPresentationName(type).toStdString() << " on " << layer << std::endl; | 422 // << getLayerPresentationName(type).toStdString() << " on " << layer << std::endl; |
412 layer->setObjectName(getLayerPresentationName(type)); | 423 layer->setObjectName(getLayerPresentationName(type)); |
424 setLayerDefaultProperties(type, layer); | |
413 } | 425 } |
414 | 426 |
415 return layer; | 427 return layer; |
416 } | 428 } |
417 | 429 |
430 void | |
431 LayerFactory::setLayerDefaultProperties(LayerType type, Layer *layer) | |
432 { | |
433 QSettings settings; | |
434 settings.beginGroup("LayerDefaults"); | |
435 QString defaults = settings.value(getLayerTypeName(type), "").toString(); | |
436 if (defaults == "") return; | |
437 | |
438 QString xml = layer->toXmlString(); | |
439 QDomDocument docOld, docNew; | |
440 | |
441 if (docOld.setContent(xml, false) && | |
442 docNew.setContent(defaults, false)) { | |
443 | |
444 QXmlAttributes attrs; | |
445 | |
446 QDomElement layerElt = docNew.firstChildElement("layer"); | |
447 QDomNamedNodeMap attrNodes = layerElt.attributes(); | |
448 | |
449 for (unsigned int i = 0; i < attrNodes.length(); ++i) { | |
450 QDomAttr attr = attrNodes.item(i).toAttr(); | |
451 if (attr.isNull()) continue; | |
452 attrs.append(attr.name(), "", "", attr.value()); | |
453 } | |
454 | |
455 layerElt = docOld.firstChildElement("layer"); | |
456 attrNodes = layerElt.attributes(); | |
457 for (unsigned int i = 0; i < attrNodes.length(); ++i) { | |
458 QDomAttr attr = attrNodes.item(i).toAttr(); | |
459 if (attr.isNull()) continue; | |
460 if (attrs.value(attr.name()) == "") { | |
461 attrs.append(attr.name(), "", "", attr.value()); | |
462 } | |
463 } | |
464 | |
465 layer->setProperties(attrs); | |
466 } | |
467 | |
468 settings.endGroup(); | |
469 } | |
470 |