Mercurial > hg > svgui
comparison 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 |
comparison
equal
deleted
inserted
replaced
1454:4a6ca97ce783 | 1455:9e846af73f3e |
---|---|
495 | 495 |
496 QSettings settings; | 496 QSettings settings; |
497 settings.beginGroup("LayerDefaults"); | 497 settings.beginGroup("LayerDefaults"); |
498 QString defaults = settings.value(getLayerTypeName(type), "").toString(); | 498 QString defaults = settings.value(getLayerTypeName(type), "").toString(); |
499 if (defaults == "") return; | 499 if (defaults == "") return; |
500 | 500 setLayerProperties(layer, defaults); |
501 // cerr << "defaults=\"" << defaults << "\"" << endl; | 501 settings.endGroup(); |
502 | 502 } |
503 QString xml = layer->toXmlString(); | 503 |
504 void | |
505 LayerFactory::setLayerProperties(Layer *layer, QString newXml) | |
506 { | |
504 QDomDocument docOld, docNew; | 507 QDomDocument docOld, docNew; |
505 | 508 QString oldXml = layer->toXmlString(); |
506 if (docOld.setContent(xml, false) && | 509 |
507 docNew.setContent(defaults, false)) { | 510 if (!docOld.setContent(oldXml, false)) { |
511 SVCERR << "LayerFactory::setLayerProperties: Failed to parse XML for existing layer properties! XML string is: " << oldXml << endl; | |
512 return; | |
513 } | |
514 | |
515 if (!docNew.setContent(newXml, false)) { | |
516 SVCERR << "LayerFactory::setLayerProperties: Failed to parse XML: " << newXml << endl; | |
517 return; | |
518 } | |
508 | 519 |
509 QXmlAttributes attrs; | 520 QXmlAttributes attrs; |
510 | 521 |
511 QDomElement layerElt = docNew.firstChildElement("layer"); | 522 QDomElement layerElt = docNew.firstChildElement("layer"); |
512 QDomNamedNodeMap attrNodes = layerElt.attributes(); | 523 QDomNamedNodeMap attrNodes = layerElt.attributes(); |
513 | 524 |
514 for (int i = 0; i < attrNodes.length(); ++i) { | 525 for (int i = 0; i < attrNodes.length(); ++i) { |
515 QDomAttr attr = attrNodes.item(i).toAttr(); | 526 QDomAttr attr = attrNodes.item(i).toAttr(); |
516 if (attr.isNull()) continue; | 527 if (attr.isNull()) continue; |
517 // cerr << "append \"" << attr.name() | 528 // cerr << "append \"" << attr.name() |
518 // << "\" -> \"" << attr.value() << "\"" | 529 // << "\" -> \"" << attr.value() << "\"" |
519 // << endl; | 530 // << endl; |
520 attrs.append(attr.name(), "", "", attr.value()); | 531 attrs.append(attr.name(), "", "", attr.value()); |
521 } | 532 } |
522 | 533 |
523 layerElt = docOld.firstChildElement("layer"); | 534 layerElt = docOld.firstChildElement("layer"); |
524 attrNodes = layerElt.attributes(); | 535 attrNodes = layerElt.attributes(); |
525 for (int i = 0; i < attrNodes.length(); ++i) { | 536 for (int i = 0; i < attrNodes.length(); ++i) { |
526 QDomAttr attr = attrNodes.item(i).toAttr(); | 537 QDomAttr attr = attrNodes.item(i).toAttr(); |
527 if (attr.isNull()) continue; | 538 if (attr.isNull()) continue; |
528 if (attrs.value(attr.name()) == "") { | 539 if (attrs.value(attr.name()) == "") { |
529 // cerr << "append \"" << attr.name() | 540 // cerr << "append \"" << attr.name() |
530 // << "\" -> \"" << attr.value() << "\"" | 541 // << "\" -> \"" << attr.value() << "\"" |
531 // << endl; | 542 // << endl; |
532 attrs.append(attr.name(), "", "", attr.value()); | 543 attrs.append(attr.name(), "", "", attr.value()); |
533 } | |
534 } | 544 } |
535 | 545 } |
536 layer->setProperties(attrs); | 546 |
537 } | 547 layer->setProperties(attrs); |
538 | |
539 settings.endGroup(); | |
540 } | 548 } |
541 | 549 |
542 LayerFactory::LayerType | 550 LayerFactory::LayerType |
543 LayerFactory::getLayerTypeForClipboardContents(const Clipboard &clip) | 551 LayerFactory::getLayerTypeForClipboardContents(const Clipboard &clip) |
544 { | 552 { |