12 #include <QDomDocument>
13 #include <QDomElement>
15 #include <QTextStream>
17 #define STYLE_CURRENT_VERSION "0"
38 if ( !QFile::exists( styleFilename ) )
52 for ( QMap<QString, QgsSymbolV2*>::iterator its =
mSymbols.begin(); its !=
mSymbols.end(); ++its )
54 for ( QMap<QString, QgsVectorColorRampV2*>::iterator itr =
mColorRamps.begin(); itr !=
mColorRamps.end(); ++itr )
63 if ( !symbol || name.count() == 0 )
111 if ( !colorRamp || name.count() == 0 )
162 QDomDocument doc(
"style" );
164 if ( !f.open( QFile::ReadOnly ) )
166 mErrorString =
"Couldn't open the style file: " + filename;
171 if ( !doc.setContent( &f ) )
173 mErrorString =
"Couldn't parse the style file: " + filename;
179 QDomElement docElem = doc.documentElement();
180 if ( docElem.tagName() !=
"qgis_style" )
182 mErrorString =
"Incorrect root tag in style: " + docElem.tagName();
187 QString version = docElem.attribute(
"version" );
190 mErrorString =
"Unknown style file version: " + version;
195 QDomElement symbolsElement = docElem.firstChildElement(
"symbols" );
196 if ( !symbolsElement.isNull() )
202 QDomElement rampsElement = docElem.firstChildElement(
"colorramps" );
203 QDomElement e = rampsElement.firstChildElement();
204 while ( !e.isNull() )
206 if ( e.tagName() ==
"colorramp" )
216 e = e.nextSiblingElement();
228 if ( filename.isEmpty() )
231 QDomDocument doc(
"qgis_style" );
232 QDomElement root = doc.createElement(
"qgis_style" );
234 doc.appendChild( root );
238 QDomElement rampsElem = doc.createElement(
"colorramps" );
241 for ( QMap<QString, QgsVectorColorRampV2*>::iterator itr =
mColorRamps.begin(); itr !=
mColorRamps.end(); ++itr )
244 rampsElem.appendChild( rampEl );
247 root.appendChild( symbolsElem );
248 root.appendChild( rampsElem );
252 if ( !f.open( QFile::WriteOnly ) )
254 mErrorString =
"Couldn't open file for writing: " + filename;
257 QTextStream ts( &f );
267 if ( !
mSymbols.contains( oldName ) )