diff layer/LayerFactory.cpp @ 1455:9e846af73f3e single-point

Add setLayerProperties (from XML string)
author Chris Cannam
date Fri, 10 May 2019 09:22:20 +0100
parents e1a08da75427
children f2525e6cbdf1
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