Mercurial > hg > svgui
changeset 1455:9e846af73f3e single-point
Add setLayerProperties (from XML string)
author | Chris Cannam |
---|---|
date | Fri, 10 May 2019 09:22:20 +0100 |
parents | 4a6ca97ce783 |
children | 98157ea8a3d2 |
files | layer/LayerFactory.cpp layer/LayerFactory.h |
diffstat | 2 files changed, 47 insertions(+), 27 deletions(-) [+] |
line wrap: on
line diff
--- a/layer/LayerFactory.cpp Fri May 10 08:44:32 2019 +0100 +++ b/layer/LayerFactory.cpp Fri May 10 09:22:20 2019 +0100 @@ -497,46 +497,54 @@ settings.beginGroup("LayerDefaults"); QString defaults = settings.value(getLayerTypeName(type), "").toString(); if (defaults == "") return; + setLayerProperties(layer, defaults); + settings.endGroup(); +} -// cerr << "defaults=\"" << defaults << "\"" << endl; +void +LayerFactory::setLayerProperties(Layer *layer, QString newXml) +{ + QDomDocument docOld, docNew; + QString oldXml = layer->toXmlString(); - QString xml = layer->toXmlString(); - QDomDocument docOld, docNew; - - if (docOld.setContent(xml, false) && - docNew.setContent(defaults, false)) { + if (!docOld.setContent(oldXml, false)) { + SVCERR << "LayerFactory::setLayerProperties: Failed to parse XML for existing layer properties! XML string is: " << oldXml << endl; + return; + } + + if (!docNew.setContent(newXml, false)) { + SVCERR << "LayerFactory::setLayerProperties: Failed to parse XML: " << newXml << endl; + return; + } - QXmlAttributes attrs; + QXmlAttributes attrs; - QDomElement layerElt = docNew.firstChildElement("layer"); - QDomNamedNodeMap attrNodes = layerElt.attributes(); + QDomElement layerElt = docNew.firstChildElement("layer"); + QDomNamedNodeMap attrNodes = layerElt.attributes(); - for (int i = 0; i < attrNodes.length(); ++i) { - QDomAttr attr = attrNodes.item(i).toAttr(); - if (attr.isNull()) continue; + for (int i = 0; i < attrNodes.length(); ++i) { + QDomAttr attr = attrNodes.item(i).toAttr(); + if (attr.isNull()) continue; // cerr << "append \"" << attr.name() // << "\" -> \"" << attr.value() << "\"" // << endl; - attrs.append(attr.name(), "", "", attr.value()); - } - - layerElt = docOld.firstChildElement("layer"); - attrNodes = layerElt.attributes(); - for (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()); + } + + layerElt = docOld.firstChildElement("layer"); + attrNodes = layerElt.attributes(); + for (int i = 0; i < attrNodes.length(); ++i) { + QDomAttr attr = attrNodes.item(i).toAttr(); + if (attr.isNull()) continue; + if (attrs.value(attr.name()) == "") { // cerr << "append \"" << attr.name() // << "\" -> \"" << attr.value() << "\"" // << endl; - attrs.append(attr.name(), "", "", attr.value()); - } + attrs.append(attr.name(), "", "", attr.value()); } - - layer->setProperties(attrs); } - - settings.endGroup(); + + layer->setProperties(attrs); } LayerFactory::LayerType
--- a/layer/LayerFactory.h Fri May 10 08:44:32 2019 +0100 +++ b/layer/LayerFactory.h Fri May 10 09:22:20 2019 +0100 @@ -68,8 +68,20 @@ Layer *createLayer(LayerType type); + /** + * Set the default properties of a layer, from the XML string + * contained in the LayerDefaults settings group for the given + * layer type. Leave unchanged any properties not mentioned in the + * settings. + */ void setLayerDefaultProperties(LayerType type, Layer *layer); + /** + * Set the properties of a layer, from the XML string + * provided. Leave unchanged any properties not mentioned. + */ + void setLayerProperties(Layer *layer, QString xmlString); + QString getLayerPresentationName(LayerType type); bool isLayerSliceable(const Layer *);