16 if ( !file.open( QIODevice::ReadOnly ) )
18 errorMessage = QString(
"Can not open file" );
24 if ( !doc.setContent( &file, &message ) )
26 errorMessage = message;
30 QFileInfo fileinfo( file );
31 QDir::setCurrent( fileinfo.absoluteDir().path() );
38 Q_UNUSED( errorMessage );
43 QDomNodeList ids = doc.elementsByTagName(
"id" );
44 for (
int i = 0; i < ids.size(); ++i )
46 QDomNode idnode = ids.at( i );
47 QDomElement idElem = idnode.toElement();
48 QString oldid = idElem.text();
50 QString layername = oldid.left( oldid.length() - 17 );
51 QDateTime dt = QDateTime::currentDateTime();
52 QString newid = layername + dt.toString(
"yyyyMMddhhmmsszzz" );
53 idElem.firstChild().setNodeValue( newid );
54 QDomNodeList treeLayerNodes = doc.elementsByTagName(
"layer-tree-layer" );
56 for (
int i = 0; i < treeLayerNodes.count(); ++i )
58 QDomNode layerNode = treeLayerNodes.at( i );
59 QDomElement layerElem = layerNode.toElement();
60 if ( layerElem.attribute(
"id" ) == oldid )
62 layerNode.toElement().setAttribute(
"id", newid );
67 QDomElement layerTreeElem = doc.documentElement().firstChildElement(
"layer-tree-group" );
68 bool loadInLegend =
true;
69 if ( !layerTreeElem.isNull() )
78 QList<QgsLayerTreeNode*> nodes = root->
children();
91 if ( !path.endsWith(
".qlr" ) )
92 path = path.append(
".qlr" );
95 QFileInfo fileinfo( file );
97 QDomDocument doc(
"qgis-layer-definition" );
98 QDomElement qgiselm = doc.createElement(
"qlr" );
99 doc.appendChild( qgiselm );
100 QList<QgsLayerTreeNode*> nodes = selectedTreeNodes;
109 QDomElement layerselm = doc.createElement(
"maplayers" );
110 QList<QgsLayerTreeLayer*> layers = root->
findLayers();
113 QDomElement layerelm = doc.createElement(
"maplayer" );
115 layerselm.appendChild( layerelm );
117 qgiselm.appendChild( layerselm );
119 if ( file.open( QFile::WriteOnly | QFile::Truncate ) )
121 QTextStream qlayerstream( &file );
122 doc.save( qlayerstream, 2 );
127 errorMessage = file.errorString();