21 #include <QDomDocument>
22 #include <QDomElement>
23 #include <QDomImplementation>
28 #include <QTextStream>
53 mDataSource( source ),
54 mLayerOrigName( lyrname ),
57 mBlendMode( QPainter::CompositionMode_SourceOver )
69 QDateTime dt = QDateTime::currentDateTime();
70 mID = lyrname + dt.toString(
"yyyyMMddhhmmsszzz" );
77 mID.replace( QRegExp(
"[\\W]" ),
"_" );
81 mMaxScale = 100000000;
82 mScaleBasedVisibility =
false;
106 QgsDebugMsg(
"new original name: '" + name +
"'" );
155 Q_UNUSED( rendererContext );
161 Q_UNUSED( rendererContext );
175 mnl = layerElement.namedItem(
"provider" );
176 mne = mnl.toElement();
177 provider = mne.text();
180 mnl = layerElement.namedItem(
"datasource" );
181 mne = mnl.toElement();
185 if ( provider ==
"spatialite" )
191 else if ( provider ==
"ogr" )
193 QStringList theURIParts =
mDataSource.split(
"|" );
197 else if ( provider ==
"gpx" )
199 QStringList theURIParts =
mDataSource.split(
"?" );
203 else if ( provider ==
"delimitedtext" )
205 QUrl urlSource = QUrl::fromEncoded(
mDataSource.toAscii() );
210 urlSource.setScheme(
"file" );
211 urlSource.setPath( file.path() );
214 QUrl urlDest = QUrl::fromLocalFile(
QgsProject::instance()->readPath( urlSource.toLocalFile() ) );
215 urlDest.setQueryItems( urlSource.queryItems() );
216 mDataSource = QString::fromAscii( urlDest.toEncoded() );
218 else if ( provider ==
"wms" )
233 QgsDebugMsg(
"Old WMS URI format detected -> converting to new format" );
238 QStringListIterator iter( parts );
239 while ( iter.hasNext() )
241 QString item = iter.next();
242 if ( item.startsWith(
"username=" ) )
244 uri.
setParam(
"username", item.mid( 9 ) );
246 else if ( item.startsWith(
"password=" ) )
248 uri.
setParam(
"password", item.mid( 9 ) );
250 else if ( item.startsWith(
"tiled=" ) )
256 QStringList params = item.mid( 6 ).split(
";" );
258 if ( params.size() == 2 )
260 uri.
setParam(
"maxWidth", params.takeFirst() );
261 uri.
setParam(
"maxHeight", params.takeFirst() );
263 else if ( params.size() > 2 )
267 uri.
setParam(
"tileMatrixSet",
"" );
270 else if ( item.startsWith(
"featureCount=" ) )
272 uri.
setParam(
"featureCount", item.mid( 13 ) );
274 else if ( item.startsWith(
"url=" ) )
276 uri.
setParam(
"url", item.mid( 4 ) );
278 else if ( item.startsWith(
"ignoreUrl=" ) )
280 uri.
setParam(
"ignoreUrl", item.mid( 10 ).split(
";" ) );
303 mnl = layerElement.namedItem(
"layername" );
304 mne = mnl.toElement();
306 QDomNode srsNode = layerElement.namedItem(
"srs" );
318 layerError = !
readXml( layerElement );
337 mnl = layerElement.namedItem(
"id" );
338 if ( ! mnl.isNull() )
340 mne = mnl.toElement();
341 if ( ! mne.isNull() && mne.text().length() > 10 )
353 mnl = layerElement.namedItem(
"layername" );
354 mne = mnl.toElement();
358 QDomElement titleElem = layerElement.firstChildElement(
"title" );
359 if ( !titleElem.isNull() )
361 mTitle = titleElem.text();
365 QDomElement abstractElem = layerElement.firstChildElement(
"abstract" );
366 if ( !abstractElem.isNull() )
372 QDomElement keywordListElem = layerElement.firstChildElement(
"keywordList" );
373 if ( !keywordListElem.isNull() )
376 for ( QDomNode n = keywordListElem.firstChild(); !n.isNull(); n = n.nextSibling() )
378 kwdList << n.toElement().text();
384 QDomElement dataUrlElem = layerElement.firstChildElement(
"dataUrl" );
385 if ( !dataUrlElem.isNull() )
392 QDomElement legendUrlElem = layerElement.firstChildElement(
"legendUrl" );
393 if ( !legendUrlElem.isNull() )
400 QDomElement attribElem = layerElement.firstChildElement(
"attribution" );
401 if ( !attribElem.isNull() )
408 QDomElement metaUrlElem = layerElement.firstChildElement(
"metadataUrl" );
409 if ( !metaUrlElem.isNull() )
418 QDomNode transparencyNode = layer_node.namedItem(
"transparencyLevelInt" );
419 if ( ! transparencyNode.isNull() )
423 QDomElement myElement = transparencyNode.toElement();
424 setTransparency( myElement.text().toInt() );
436 Q_UNUSED( layer_node );
448 layerElement.setAttribute(
"minimumScale", QString::number(
minimumScale() ) );
449 layerElement.setAttribute(
"maximumScale", QString::number(
maximumScale() ) );
452 QDomElement layerId = document.createElement(
"id" );
453 QDomText layerIdText = document.createTextNode(
id() );
454 layerId.appendChild( layerIdText );
456 layerElement.appendChild( layerId );
459 QDomElement dataSource = document.createElement(
"datasource" );
474 QStringList theURIParts = src.split(
"|" );
476 src = theURIParts.join(
"|" );
480 QStringList theURIParts = src.split(
"?" );
482 src = theURIParts.join(
"?" );
484 else if ( vlayer && vlayer->
providerType() ==
"delimitedtext" )
486 QUrl urlSource = QUrl::fromEncoded( src.toAscii() );
487 QUrl urlDest = QUrl::fromLocalFile(
QgsProject::instance()->writePath( urlSource.toLocalFile(), relativeBasePath ) );
488 urlDest.setQueryItems( urlSource.queryItems() );
489 src = QString::fromAscii( urlDest.toEncoded() );
496 QDomText dataSourceText = document.createTextNode( src );
497 dataSource.appendChild( dataSourceText );
499 layerElement.appendChild( dataSource );
503 QDomElement layerName = document.createElement(
"layername" );
504 QDomText layerNameText = document.createTextNode(
originalName() );
505 layerName.appendChild( layerNameText );
508 QDomElement layerTitle = document.createElement(
"title" );
509 QDomText layerTitleText = document.createTextNode(
title() );
510 layerTitle.appendChild( layerTitleText );
513 QDomElement layerAbstract = document.createElement(
"abstract" );
514 QDomText layerAbstractText = document.createTextNode(
abstract() );
515 layerAbstract.appendChild( layerAbstractText );
517 layerElement.appendChild( layerName );
518 layerElement.appendChild( layerTitle );
519 layerElement.appendChild( layerAbstract );
522 QStringList keywordStringList =
keywordList().split(
"," );
523 if ( keywordStringList.size() > 0 )
525 QDomElement layerKeywordList = document.createElement(
"keywordList" );
526 for (
int i = 0; i < keywordStringList.size(); ++i )
528 QDomElement layerKeywordValue = document.createElement(
"value" );
529 QDomText layerKeywordText = document.createTextNode( keywordStringList.at( i ).trimmed() );
530 layerKeywordValue.appendChild( layerKeywordText );
531 layerKeywordList.appendChild( layerKeywordValue );
533 layerElement.appendChild( layerKeywordList );
538 if ( !aDataUrl.isEmpty() )
540 QDomElement layerDataUrl = document.createElement(
"dataUrl" );
541 QDomText layerDataUrlText = document.createTextNode( aDataUrl );
542 layerDataUrl.appendChild( layerDataUrlText );
544 layerElement.appendChild( layerDataUrl );
549 if ( !aLegendUrl.isEmpty() )
551 QDomElement layerLegendUrl = document.createElement(
"legendUrl" );
552 QDomText layerLegendUrlText = document.createTextNode( aLegendUrl );
553 layerLegendUrl.appendChild( layerLegendUrlText );
555 layerElement.appendChild( layerLegendUrl );
560 if ( !aAttribution.isEmpty() )
562 QDomElement layerAttribution = document.createElement(
"attribution" );
563 QDomText layerAttributionText = document.createTextNode( aAttribution );
564 layerAttribution.appendChild( layerAttributionText );
566 layerElement.appendChild( layerAttribution );
571 if ( !aMetadataUrl.isEmpty() )
573 QDomElement layerMetadataUrl = document.createElement(
"metadataUrl" );
574 QDomText layerMetadataUrlText = document.createTextNode( aMetadataUrl );
575 layerMetadataUrl.appendChild( layerMetadataUrlText );
578 layerElement.appendChild( layerMetadataUrl );
584 QDomElement stamp = document.createElement(
"timestamp" );
585 QDomText stampText = document.createTextNode(
timestamp().toString( Qt::ISODate ) );
586 stamp.appendChild( stampText );
587 layerElement.appendChild( stamp );
590 layerElement.appendChild( layerName );
597 QDomElement mySrsElement = document.createElement(
"srs" );
598 mCRS->
writeXML( mySrsElement, document );
599 layerElement.appendChild( mySrsElement );
603 QDomElement transparencyLevelIntElement = document.createElement(
"transparencyLevelInt" );
604 QDomText transparencyLevelIntText = document.createTextNode( QString::number( getTransparency() ) );
605 transparencyLevelIntElement.appendChild( transparencyLevelIntText );
606 maplayer.appendChild( transparencyLevelIntElement );
613 return writeXml( layerElement, document );
619 QDomDocument doc(
"qgis-layer-definition" );
620 QDomElement qgiselm = doc.createElement(
"qlr" );
621 doc.appendChild( qgiselm );
622 QDomElement layerselm = doc.createElement(
"maplayers" );
625 QDomElement layerelm = doc.createElement(
"maplayer" );
627 layerselm.appendChild( layerelm );
629 qgiselm.appendChild( layerselm );
635 QList<QgsMapLayer*> layers;
636 QDomNodeList layernodes = document.elementsByTagName(
"maplayer" );
637 for (
int i = 0; i < layernodes.size(); ++i )
639 QDomNode layernode = layernodes.at( i );
640 QDomElement layerElem = layernode.toElement();
642 QString
type = layerElem.attribute(
"type" );
646 if ( type ==
"vector" )
650 else if ( type ==
"raster" )
654 else if ( type ==
"plugin" )
656 QString typeName = layerElem.attribute(
"name" );
672 QFile
file( qlrfile );
673 if ( !file.open( QIODevice::ReadOnly ) )
676 return QList<QgsMapLayer*>();
680 if ( !doc.setContent( &file ) )
683 return QList<QgsMapLayer*>();
686 QFileInfo fileinfo( file );
687 QDir::setCurrent( fileinfo.absoluteDir().path() );
694 Q_UNUSED( layer_node );
695 Q_UNUSED( document );
704 mCustomProperties.
readXml( layerNode, keyStartsWith );
709 mCustomProperties.
writeXml( layerNode, doc );
714 QDomElement styleMgrElem = layerNode.firstChildElement(
"map-layer-style-manager" );
715 if ( !styleMgrElem.isNull() )
716 mStyleManager->
readXml( styleMgrElem );
718 mStyleManager->
reset();
725 QDomElement styleMgrElem = doc.createElement(
"map-layer-style-manager" );
726 mStyleManager->
writeXml( styleMgrElem );
727 layerNode.appendChild( styleMgrElem );
758 void QgsMapLayer::connectNotify(
const char * signal )
773 return mScaleBasedVisibility;
778 mMinScale = theMinScale;
789 mMaxScale = theMaxScale;
794 mScaleBasedVisibility = enabled;
804 return QStringList();
844 settings.value(
"/qgis/capitaliseLayerName", QVariant(
false ) ).toBool();
846 QString layerName( name );
848 if ( capitaliseLayerName )
849 layerName = layerName.left( 1 ).toUpper() + layerName.mid( 1 );
859 if ( myURI.startsWith(
"/vsigzip/", Qt::CaseInsensitive ) )
861 myURI.remove( 0, 9 );
863 else if ( myURI.startsWith(
"/vsizip/", Qt::CaseInsensitive ) &&
864 myURI.endsWith(
".zip", Qt::CaseInsensitive ) )
867 myURI.remove( 0, 8 );
869 else if ( myURI.startsWith(
"/vsitar/", Qt::CaseInsensitive ) &&
870 ( myURI.endsWith(
".tar", Qt::CaseInsensitive ) ||
871 myURI.endsWith(
".tar.gz", Qt::CaseInsensitive ) ||
872 myURI.endsWith(
".tgz", Qt::CaseInsensitive ) ) )
875 myURI.remove( 0, 8 );
878 QFileInfo myFileInfo( myURI );
881 if ( myFileInfo.exists() )
884 if ( myURI.endsWith(
".gz", Qt::CaseInsensitive ) )
886 else if ( myURI.endsWith(
".zip", Qt::CaseInsensitive ) )
888 else if ( myURI.endsWith(
".tar", Qt::CaseInsensitive ) )
890 else if ( myURI.endsWith(
".tar.gz", Qt::CaseInsensitive ) )
892 else if ( myURI.endsWith(
".tgz", Qt::CaseInsensitive ) )
894 myFileInfo.setFile( myURI );
896 key = myFileInfo.path() + QDir::separator() + myFileInfo.completeBaseName() +
".qml";
913 QgsDebugMsg( QString(
"db = %1 uri = %2" ).arg( db ).arg( theURI ) );
915 bool theResultFlag =
false;
919 sqlite3_stmt *myPreparedStatement;
923 QgsDebugMsg( QString(
"Trying to load style for \"%1\" from \"%2\"" ).arg( theURI ).arg( db ) );
925 if ( db.isEmpty() || !QFile( db ).exists() )
928 myResult = sqlite3_open_v2( db.toUtf8().data(), &myDatabase, SQLITE_OPEN_READONLY, NULL );
929 if ( myResult != SQLITE_OK )
934 QString mySql =
"select qml from tbl_styles where style=?";
935 myResult = sqlite3_prepare( myDatabase, mySql.toUtf8().data(), mySql.toUtf8().length(), &myPreparedStatement, &myTail );
936 if ( myResult == SQLITE_OK )
938 QByteArray param = theURI.toUtf8();
940 if ( sqlite3_bind_text( myPreparedStatement, 1, param.data(), param.length(), SQLITE_STATIC ) == SQLITE_OK &&
941 sqlite3_step( myPreparedStatement ) == SQLITE_ROW )
943 qml = QString::fromUtf8((
char * )sqlite3_column_text( myPreparedStatement, 0 ) );
944 theResultFlag =
true;
947 sqlite3_finalize( myPreparedStatement );
950 sqlite3_close( myDatabase );
952 return theResultFlag;
960 theResultFlag =
false;
962 QDomDocument myDocument(
"qgis" );
966 QString myErrorMessage;
968 QFile myFile( theURI );
969 if ( myFile.open( QFile::ReadOnly ) )
972 theResultFlag = myDocument.setContent( &myFile, &myErrorMessage, &line, &column );
973 if ( !theResultFlag )
974 myErrorMessage =
tr(
"%1 at line %2 column %3" ).arg( myErrorMessage ).arg( line ).arg( column );
980 QgsDebugMsg( QString(
"project fileName: %1" ).arg( project.absoluteFilePath() ) );
984 ( project.exists() &&
loadNamedStyleFromDb( project.absoluteDir().absoluteFilePath( project.baseName() +
".qmldb" ), theURI, qml ) ) ||
987 theResultFlag = myDocument.setContent( qml, &myErrorMessage, &line, &column );
988 if ( !theResultFlag )
990 myErrorMessage =
tr(
"%1 at line %2 column %3" ).arg( myErrorMessage ).arg( line ).arg( column );
995 myErrorMessage =
tr(
"Style not found in database" );
999 if ( !theResultFlag )
1001 return myErrorMessage;
1005 if ( !theResultFlag )
1006 myErrorMessage =
tr(
"Loading style file %1 failed because:\n%2" ).arg( theURI ).arg( myErrorMessage );
1008 return myErrorMessage;
1015 QgsProjectVersion fileVersion( myDocument.firstChildElement(
"qgis" ).attribute(
"version" ) );
1018 if ( thisVersion > fileVersion )
1021 "version of qgis (saved in " + fileVersion.text() +
1023 "). Problems may occur." );
1027 styleFile.updateRevision( thisVersion );
1033 QDomElement myRoot = myDocument.firstChildElement(
"qgis" );
1034 if ( myRoot.isNull() )
1036 myErrorMessage =
tr(
"Root <qgis> element could not be found" );
1047 QDomNode transparencyNode = myRoot.namedItem(
"transparencyLevelInt" );
1048 if ( ! transparencyNode.isNull() )
1052 QDomElement myElement = transparencyNode.toElement();
1053 setTransparency( myElement.text().toInt() );
1062 QDomImplementation DomImplementation;
1063 QDomDocumentType documentType = DomImplementation.createDocumentType(
"qgis",
"http://mrcc.com/qgis.dtd",
"SYSTEM" );
1064 QDomDocument myDocument( documentType );
1066 QDomElement myRootNode = myDocument.createElement(
"qgis" );
1068 myDocument.appendChild( myRootNode );
1071 myRootNode.setAttribute(
"minimumScale", QString::number(
minimumScale() ) );
1072 myRootNode.setAttribute(
"maximumScale", QString::number(
maximumScale() ) );
1076 QDomElement transparencyLevelIntElement = myDocument.createElement(
"transparencyLevelInt" );
1077 QDomText transparencyLevelIntText = myDocument.createTextNode( QString::number( getTransparency() ) );
1078 transparencyLevelIntElement.appendChild( transparencyLevelIntText );
1079 myRootNode.appendChild( transparencyLevelIntElement );
1084 errorMsg =
QObject::tr(
"Could not save symbology because:\n%1" ).arg( errorMsg );
1097 QString myErrorMessage;
1098 QDomDocument myDocument;
1109 QStringList theURIParts = theURI.split(
"|" );
1110 filename = theURIParts[0];
1114 QStringList theURIParts = theURI.split(
"?" );
1115 filename = theURIParts[0];
1117 else if ( vlayer && vlayer->
providerType() ==
"delimitedtext" )
1119 filename = QUrl::fromEncoded( theURI.toAscii() ).toLocalFile();
1126 QFileInfo myFileInfo( filename );
1127 if ( myFileInfo.exists() || filename.endsWith(
".qml", Qt::CaseInsensitive ) )
1129 QFileInfo myDirInfo( myFileInfo.path() );
1130 if ( !myDirInfo.isWritable() )
1132 return tr(
"The directory containing your dataset needs to be writable!" );
1136 QString myFileName = myFileInfo.path() + QDir::separator() + myFileInfo.completeBaseName() +
".qml";
1138 QFile myFile( myFileName );
1139 if ( myFile.open( QFile::WriteOnly | QFile::Truncate ) )
1141 QTextStream myFileStream( &myFile );
1143 myDocument.save( myFileStream, 2 );
1145 theResultFlag =
true;
1146 return tr(
"Created default style file as %1" ).arg( myFileName );
1150 theResultFlag =
false;
1151 return tr(
"ERROR: Failed to created default style file as %1. Check file permissions and retry." ).arg( myFileName );
1156 QString qml = myDocument.toString();
1160 sqlite3_stmt *myPreparedStatement;
1165 if ( myResult != SQLITE_OK )
1167 return tr(
"User database could not be opened." );
1170 QByteArray param0 = theURI.toUtf8();
1171 QByteArray param1 = qml.toUtf8();
1173 QString mySql =
"create table if not exists tbl_styles(style varchar primary key,qml varchar)";
1174 myResult = sqlite3_prepare( myDatabase, mySql.toUtf8().data(), mySql.toUtf8().length(), &myPreparedStatement, &myTail );
1175 if ( myResult == SQLITE_OK )
1177 if ( sqlite3_step( myPreparedStatement ) != SQLITE_DONE )
1179 sqlite3_finalize( myPreparedStatement );
1180 sqlite3_close( myDatabase );
1181 theResultFlag =
false;
1182 return tr(
"The style table could not be created." );
1186 sqlite3_finalize( myPreparedStatement );
1188 mySql =
"insert into tbl_styles(style,qml) values (?,?)";
1189 myResult = sqlite3_prepare( myDatabase, mySql.toUtf8().data(), mySql.toUtf8().length(), &myPreparedStatement, &myTail );
1190 if ( myResult == SQLITE_OK )
1192 if ( sqlite3_bind_text( myPreparedStatement, 1, param0.data(), param0.length(), SQLITE_STATIC ) == SQLITE_OK &&
1193 sqlite3_bind_text( myPreparedStatement, 2, param1.data(), param1.length(), SQLITE_STATIC ) == SQLITE_OK &&
1194 sqlite3_step( myPreparedStatement ) == SQLITE_DONE )
1196 theResultFlag =
true;
1197 myErrorMessage =
tr(
"The style %1 was saved to database" ).arg( theURI );
1201 sqlite3_finalize( myPreparedStatement );
1203 if ( !theResultFlag )
1205 QString mySql =
"update tbl_styles set qml=? where style=?";
1206 myResult = sqlite3_prepare( myDatabase, mySql.toUtf8().data(), mySql.toUtf8().length(), &myPreparedStatement, &myTail );
1207 if ( myResult == SQLITE_OK )
1209 if ( sqlite3_bind_text( myPreparedStatement, 2, param0.data(), param0.length(), SQLITE_STATIC ) == SQLITE_OK &&
1210 sqlite3_bind_text( myPreparedStatement, 1, param1.data(), param1.length(), SQLITE_STATIC ) == SQLITE_OK &&
1211 sqlite3_step( myPreparedStatement ) == SQLITE_DONE )
1213 theResultFlag =
true;
1214 myErrorMessage =
tr(
"The style %1 was updated in the database." ).arg( theURI );
1218 theResultFlag =
false;
1219 myErrorMessage =
tr(
"The style %1 could not be updated in the database." ).arg( theURI );
1224 theResultFlag =
false;
1225 myErrorMessage =
tr(
"The style %1 could not be inserted into database." ).arg( theURI );
1228 sqlite3_finalize( myPreparedStatement );
1231 sqlite3_close( myDatabase );
1234 return myErrorMessage;
1239 QDomDocument myDocument = QDomDocument();
1241 QDomNode header = myDocument.createProcessingInstruction(
"xml",
"version=\"1.0\" encoding=\"UTF-8\"" );
1242 myDocument.appendChild( header );
1245 QDomElement root = myDocument.createElementNS(
"http://www.opengis.net/sld",
"StyledLayerDescriptor" );
1246 root.setAttribute(
"version",
"1.1.0" );
1247 root.setAttribute(
"xsi:schemaLocation",
"http://www.opengis.net/sld http://schemas.opengis.net/sld/1.1.0/StyledLayerDescriptor.xsd" );
1248 root.setAttribute(
"xmlns:ogc",
"http://www.opengis.net/ogc" );
1249 root.setAttribute(
"xmlns:se",
"http://www.opengis.net/se" );
1250 root.setAttribute(
"xmlns:xlink",
"http://www.w3.org/1999/xlink" );
1251 root.setAttribute(
"xmlns:xsi",
"http://www.w3.org/2001/XMLSchema-instance" );
1252 myDocument.appendChild( root );
1255 QDomElement namedLayerNode = myDocument.createElement(
"NamedLayer" );
1256 root.appendChild( namedLayerNode );
1261 errorMsg =
tr(
"Could not save symbology because:\n%1" )
1262 .arg(
"Non-vector layers not supported yet" );
1266 if ( !vlayer->
writeSld( namedLayerNode, myDocument, errorMsg ) )
1268 errorMsg =
tr(
"Could not save symbology because:\n%1" ).arg( errorMsg );
1278 QDomDocument myDocument;
1280 if ( !errorMsg.isNull() )
1282 theResultFlag =
false;
1292 QStringList theURIParts = theURI.split(
"|" );
1293 filename = theURIParts[0];
1297 QStringList theURIParts = theURI.split(
"?" );
1298 filename = theURIParts[0];
1302 filename = QUrl::fromEncoded( theURI.toAscii() ).toLocalFile();
1309 QFileInfo myFileInfo( filename );
1310 if ( myFileInfo.exists() || filename.endsWith(
".sld", Qt::CaseInsensitive ) )
1312 QFileInfo myDirInfo( myFileInfo.path() );
1313 if ( !myDirInfo.isWritable() )
1315 return tr(
"The directory containing your dataset needs to be writable!" );
1319 QString myFileName = myFileInfo.path() + QDir::separator() + myFileInfo.completeBaseName() +
".sld";
1321 QFile myFile( myFileName );
1322 if ( myFile.open( QFile::WriteOnly | QFile::Truncate ) )
1324 QTextStream myFileStream( &myFile );
1326 myDocument.save( myFileStream, 2 );
1328 theResultFlag =
true;
1329 return tr(
"Created default style file as %1" ).arg( myFileName );
1333 theResultFlag =
false;
1334 return tr(
"ERROR: Failed to created SLD style file as %1. Check file permissions and retry." ).arg( filename );
1341 theResultFlag =
false;
1343 QDomDocument myDocument;
1347 QString myErrorMessage;
1349 QFile myFile( theURI );
1350 if ( myFile.open( QFile::ReadOnly ) )
1353 theResultFlag = myDocument.setContent( &myFile,
true, &myErrorMessage, &line, &column );
1354 if ( !theResultFlag )
1355 myErrorMessage =
tr(
"%1 at line %2 column %3" ).arg( myErrorMessage ).arg( line ).arg( column );
1360 myErrorMessage =
tr(
"Unable to open file %1" ).arg( theURI );
1363 if ( !theResultFlag )
1365 return myErrorMessage;
1369 QDomElement myRoot = myDocument.firstChildElement(
"StyledLayerDescriptor" );
1370 if ( myRoot.isNull() )
1372 myErrorMessage = QString(
"Error: StyledLayerDescriptor element not found in %1" ).arg( theURI );
1373 theResultFlag =
false;
1374 return myErrorMessage;
1379 QDomElement namedLayerElem = myRoot.firstChildElement(
"NamedLayer" );
1380 if ( namedLayerElem.isNull() )
1382 myErrorMessage = QString(
"Info: NamedLayer element not found." );
1383 theResultFlag =
false;
1384 return myErrorMessage;
1388 theResultFlag =
readSld( namedLayerElem, errorMsg );
1389 if ( !theResultFlag )
1391 myErrorMessage =
tr(
"Loading style file %1 failed because:\n%2" ).arg( theURI ).arg( errorMsg );
1392 return myErrorMessage;
1407 mCustomProperties.
setValue( key, value );
1412 return mCustomProperties.
value( value, defaultValue );
1417 mCustomProperties.
remove( key );
1439 if ( legend == mLegend )
1446 connect( mLegend, SIGNAL( itemsChanged() ),
this, SIGNAL(
legendChanged() ) );
1458 return mStyleManager;