25 #include <QDomDocument>
26 #include <QDomElement>
27 #include <QDomImplementation>
28 #include <QTextStream>
51 mDataSource( source ),
52 mLayerOrigName( lyrname ),
55 mBlendMode( QPainter::CompositionMode_SourceOver )
65 QDateTime dt = QDateTime::currentDateTime();
66 mID = lyrname + dt.toString(
"yyyyMMddhhmmsszzz" );
73 mID.replace( QRegExp(
"[\\W]" ),
"_" );
100 QgsDebugMsg(
"new original name: '" + name +
"'" );
149 Q_UNUSED( rendererContext );
155 Q_UNUSED( rendererContext );
169 mnl = layerElement.namedItem(
"provider" );
170 mne = mnl.toElement();
171 provider = mne.text();
174 mnl = layerElement.namedItem(
"datasource" );
175 mne = mnl.toElement();
179 if ( provider ==
"spatialite" )
185 else if ( provider ==
"ogr" )
187 QStringList theURIParts =
mDataSource.split(
"|" );
191 else if ( provider ==
"delimitedtext" )
193 QUrl urlSource = QUrl::fromEncoded(
mDataSource.toAscii() );
198 urlSource.setScheme(
"file" );
199 urlSource.setPath( file.path() );
202 QUrl urlDest = QUrl::fromLocalFile(
QgsProject::instance()->readPath( urlSource.toLocalFile() ) );
203 urlDest.setQueryItems( urlSource.queryItems() );
204 mDataSource = QString::fromAscii( urlDest.toEncoded() );
206 else if ( provider ==
"wms" )
221 QgsDebugMsg(
"Old WMS URI format detected -> converting to new format" );
226 QStringListIterator iter( parts );
227 while ( iter.hasNext() )
229 QString item = iter.next();
230 if ( item.startsWith(
"username=" ) )
232 uri.
setParam(
"username", item.mid( 9 ) );
234 else if ( item.startsWith(
"password=" ) )
236 uri.
setParam(
"password", item.mid( 9 ) );
238 else if ( item.startsWith(
"tiled=" ) )
244 QStringList params = item.mid( 6 ).split(
";" );
246 if ( params.size() == 2 )
248 uri.
setParam(
"maxWidth", params.takeFirst() );
249 uri.
setParam(
"maxHeight", params.takeFirst() );
251 else if ( params.size() > 2 )
255 uri.
setParam(
"tileMatrixSet",
"" );
258 else if ( item.startsWith(
"featureCount=" ) )
260 uri.
setParam(
"featureCount", item.mid( 13 ) );
262 else if ( item.startsWith(
"url=" ) )
264 uri.
setParam(
"url", item.mid( 4 ) );
266 else if ( item.startsWith(
"ignoreUrl=" ) )
268 uri.
setParam(
"ignoreUrl", item.mid( 10 ).split(
";" ) );
291 mnl = layerElement.namedItem(
"layername" );
292 mne = mnl.toElement();
294 QDomNode srsNode = layerElement.namedItem(
"srs" );
306 layerError = !
readXml( layerElement );
325 mnl = layerElement.namedItem(
"id" );
326 if ( ! mnl.isNull() )
328 mne = mnl.toElement();
329 if ( ! mne.isNull() && mne.text().length() > 10 )
341 mnl = layerElement.namedItem(
"layername" );
342 mne = mnl.toElement();
346 QDomElement titleElem = layerElement.firstChildElement(
"title" );
347 if ( !titleElem.isNull() )
349 mTitle = titleElem.text();
353 QDomElement abstractElem = layerElement.firstChildElement(
"abstract" );
354 if ( !abstractElem.isNull() )
360 QDomElement keywordListElem = layerElement.firstChildElement(
"keywordList" );
361 if ( !keywordListElem.isNull() )
364 for ( QDomNode n = keywordListElem.firstChild(); !n.isNull(); n = n.nextSibling() )
366 kwdList << n.toElement().text();
372 QDomElement dataUrlElem = layerElement.firstChildElement(
"dataUrl" );
373 if ( !dataUrlElem.isNull() )
380 QDomElement legendUrlElem = layerElement.firstChildElement(
"legendUrl" );
381 if ( !legendUrlElem.isNull() )
388 QDomElement attribElem = layerElement.firstChildElement(
"attribution" );
389 if ( !attribElem.isNull() )
396 QDomElement metaUrlElem = layerElement.firstChildElement(
"metadataUrl" );
397 if ( !metaUrlElem.isNull() )
406 QDomNode transparencyNode = layer_node.namedItem(
"transparencyLevelInt" );
407 if ( ! transparencyNode.isNull() )
411 QDomElement myElement = transparencyNode.toElement();
412 setTransparency( myElement.text().toInt() );
424 Q_UNUSED( layer_node );
436 layerElement.setAttribute(
"minimumScale", QString::number(
minimumScale() ) );
437 layerElement.setAttribute(
"maximumScale", QString::number(
maximumScale() ) );
440 QDomElement layerId = document.createElement(
"id" );
441 QDomText layerIdText = document.createTextNode(
id() );
442 layerId.appendChild( layerIdText );
444 layerElement.appendChild( layerId );
447 QDomElement dataSource = document.createElement(
"datasource" );
462 QStringList theURIParts = src.split(
"|" );
464 src = theURIParts.join(
"|" );
466 else if ( vlayer && vlayer->
providerType() ==
"delimitedtext" )
468 QUrl urlSource = QUrl::fromEncoded( src.toAscii() );
469 QUrl urlDest = QUrl::fromLocalFile(
QgsProject::instance()->writePath( urlSource.toLocalFile() ) );
470 urlDest.setQueryItems( urlSource.queryItems() );
471 src = QString::fromAscii( urlDest.toEncoded() );
478 QDomText dataSourceText = document.createTextNode( src );
479 dataSource.appendChild( dataSourceText );
481 layerElement.appendChild( dataSource );
485 QDomElement layerName = document.createElement(
"layername" );
486 QDomText layerNameText = document.createTextNode(
originalName() );
487 layerName.appendChild( layerNameText );
490 QDomElement layerTitle = document.createElement(
"title" ) ;
491 QDomText layerTitleText = document.createTextNode(
title() );
492 layerTitle.appendChild( layerTitleText );
495 QDomElement layerAbstract = document.createElement(
"abstract" );
496 QDomText layerAbstractText = document.createTextNode(
abstract() );
497 layerAbstract.appendChild( layerAbstractText );
499 layerElement.appendChild( layerName );
500 layerElement.appendChild( layerTitle );
501 layerElement.appendChild( layerAbstract );
504 QStringList keywordStringList =
keywordList().split(
"," );
505 if ( keywordStringList.size() > 0 )
507 QDomElement layerKeywordList = document.createElement(
"keywordList" );
508 for (
int i = 0; i < keywordStringList.size(); ++i )
510 QDomElement layerKeywordValue = document.createElement(
"value" );
511 QDomText layerKeywordText = document.createTextNode( keywordStringList.at( i ).trimmed() );
512 layerKeywordValue.appendChild( layerKeywordText );
513 layerKeywordList.appendChild( layerKeywordValue );
515 layerElement.appendChild( layerKeywordList );
520 if ( !aDataUrl.isEmpty() )
522 QDomElement layerDataUrl = document.createElement(
"dataUrl" ) ;
523 QDomText layerDataUrlText = document.createTextNode( aDataUrl );
524 layerDataUrl.appendChild( layerDataUrlText );
526 layerElement.appendChild( layerDataUrl );
531 if ( !aLegendUrl.isEmpty() )
533 QDomElement layerLegendUrl = document.createElement(
"legendUrl" ) ;
534 QDomText layerLegendUrlText = document.createTextNode( aLegendUrl );
535 layerLegendUrl.appendChild( layerLegendUrlText );
537 layerElement.appendChild( layerLegendUrl );
542 if ( !aAttribution.isEmpty() )
544 QDomElement layerAttribution = document.createElement(
"attribution" ) ;
545 QDomText layerAttributionText = document.createTextNode( aAttribution );
546 layerAttribution.appendChild( layerAttributionText );
548 layerElement.appendChild( layerAttribution );
553 if ( !aMetadataUrl.isEmpty() )
555 QDomElement layerMetadataUrl = document.createElement(
"metadataUrl" ) ;
556 QDomText layerMetadataUrlText = document.createTextNode( aMetadataUrl );
557 layerMetadataUrl.appendChild( layerMetadataUrlText );
560 layerElement.appendChild( layerMetadataUrl );
566 QDomElement stamp = document.createElement(
"timestamp" );
567 QDomText stampText = document.createTextNode(
timestamp().toString( Qt::ISODate ) );
568 stamp.appendChild( stampText );
569 layerElement.appendChild( stamp );
572 layerElement.appendChild( layerName );
579 QDomElement mySrsElement = document.createElement(
"srs" );
581 layerElement.appendChild( mySrsElement );
585 QDomElement transparencyLevelIntElement = document.createElement(
"transparencyLevelInt" );
586 QDomText transparencyLevelIntText = document.createTextNode( QString::number( getTransparency() ) );
587 transparencyLevelIntElement.appendChild( transparencyLevelIntText );
588 maplayer.appendChild( transparencyLevelIntElement );
595 return writeXml( layerElement, document );
601 QDomDocument doc(
"qgis-layer-definition" );
602 QDomElement layerselm = doc.createElement(
"maplayers" );
605 QDomElement layerelm = doc.createElement(
"maplayer" );
607 layerelm.removeChild( layerelm.firstChildElement(
"id" ) );
608 layerselm.appendChild( layerelm );
610 doc.appendChild( layerselm );
616 QList<QgsMapLayer*> layers;
617 QDomNodeList layernodes = document.elementsByTagName(
"maplayer" );
618 for (
int i = 0; i < layernodes.size(); ++i )
620 QDomNode layernode = layernodes.at( i );
621 QDomElement layerElem = layernode.toElement();
623 QString
type = layerElem.attribute(
"type" );
627 if ( type ==
"vector" )
631 else if ( type ==
"raster" )
635 else if ( type ==
"plugin" )
637 QString typeName = layerElem.attribute(
"name" );
650 QFile
file( qlrfile );
651 if ( !file.open( QIODevice::ReadOnly ) )
654 return QList<QgsMapLayer*>();
658 if ( !doc.setContent( &file ) )
661 return QList<QgsMapLayer*>();
670 Q_UNUSED( layer_node );
671 Q_UNUSED( document );
756 return QStringList();
796 settings.value(
"/qgis/capitaliseLayerName", QVariant(
false ) ).toBool();
798 QString layerName( name );
800 if ( capitaliseLayerName )
801 layerName = layerName.left( 1 ).toUpper() + layerName.mid( 1 );
811 if ( myURI.startsWith(
"/vsigzip/", Qt::CaseInsensitive ) )
813 myURI.remove( 0, 9 );
815 else if ( myURI.startsWith(
"/vsizip/", Qt::CaseInsensitive ) &&
816 myURI.endsWith(
".zip", Qt::CaseInsensitive ) )
819 myURI.remove( 0, 8 );
821 else if ( myURI.startsWith(
"/vsitar/", Qt::CaseInsensitive ) &&
822 ( myURI.endsWith(
".tar", Qt::CaseInsensitive ) ||
823 myURI.endsWith(
".tar.gz", Qt::CaseInsensitive ) ||
824 myURI.endsWith(
".tgz", Qt::CaseInsensitive ) ) )
827 myURI.remove( 0, 8 );
830 QFileInfo myFileInfo( myURI );
833 if ( myFileInfo.exists() )
836 if ( myURI.endsWith(
".gz", Qt::CaseInsensitive ) )
838 else if ( myURI.endsWith(
".zip", Qt::CaseInsensitive ) )
840 else if ( myURI.endsWith(
".tar", Qt::CaseInsensitive ) )
842 else if ( myURI.endsWith(
".tar.gz", Qt::CaseInsensitive ) )
844 else if ( myURI.endsWith(
".tgz", Qt::CaseInsensitive ) )
846 else if ( myURI.endsWith(
".gz", Qt::CaseInsensitive ) )
848 myFileInfo.setFile( myURI );
850 key = myFileInfo.path() + QDir::separator() + myFileInfo.completeBaseName() +
".qml";
867 QgsDebugMsg( QString(
"db = %1 uri = %2" ).arg( db ).arg( theURI ) );
869 bool theResultFlag =
false;
873 sqlite3_stmt *myPreparedStatement;
877 QgsDebugMsg( QString(
"Trying to load style for \"%1\" from \"%2\"" ).arg( theURI ).arg( db ) );
879 if ( !QFile( db ).exists() )
882 myResult = sqlite3_open_v2( db.toUtf8().data(), &myDatabase, SQLITE_OPEN_READONLY, NULL );
883 if ( myResult != SQLITE_OK )
888 QString mySql =
"select qml from tbl_styles where style=?";
889 myResult = sqlite3_prepare( myDatabase, mySql.toUtf8().data(), mySql.toUtf8().length(), &myPreparedStatement, &myTail );
890 if ( myResult == SQLITE_OK )
892 QByteArray param = theURI.toUtf8();
894 if ( sqlite3_bind_text( myPreparedStatement, 1, param.data(), param.length(), SQLITE_STATIC ) == SQLITE_OK &&
895 sqlite3_step( myPreparedStatement ) == SQLITE_ROW )
897 qml = QString::fromUtf8((
char * )sqlite3_column_text( myPreparedStatement, 0 ) );
898 theResultFlag =
true;
901 sqlite3_finalize( myPreparedStatement );
904 sqlite3_close( myDatabase );
906 return theResultFlag;
913 theResultFlag =
false;
915 QDomDocument myDocument(
"qgis" );
919 QString myErrorMessage;
921 QFile myFile( theURI );
922 if ( myFile.open( QFile::ReadOnly ) )
925 theResultFlag = myDocument.setContent( &myFile, &myErrorMessage, &line, &column );
926 if ( !theResultFlag )
927 myErrorMessage =
tr(
"%1 at line %2 column %3" ).arg( myErrorMessage ).arg( line ).arg( column );
933 QgsDebugMsg( QString(
"project fileName: %1" ).arg( project.absoluteFilePath() ) );
937 ( project.exists() &&
loadNamedStyleFromDb( project.absoluteDir().absoluteFilePath( project.baseName() +
".qmldb" ), theURI, qml ) ) ||
940 theResultFlag = myDocument.setContent( qml, &myErrorMessage, &line, &column );
941 if ( !theResultFlag )
943 myErrorMessage =
tr(
"%1 at line %2 column %3" ).arg( myErrorMessage ).arg( line ).arg( column );
948 myErrorMessage =
tr(
"Style not found in database" );
952 if ( !theResultFlag )
954 return myErrorMessage;
958 QgsProjectVersion fileVersion( myDocument.firstChildElement(
"qgis" ).attribute(
"version" ) );
961 if ( thisVersion > fileVersion )
964 "version of qgis (saved in " + fileVersion.text() +
966 "). Problems may occur." );
970 styleFile.updateRevision( thisVersion );
976 QDomElement myRoot = myDocument.firstChildElement(
"qgis" );
977 if ( myRoot.isNull() )
979 myErrorMessage =
tr(
"Error: qgis element could not be found in %1" ).arg( theURI );
980 theResultFlag =
false;
981 return myErrorMessage;
991 QDomNode transparencyNode = myRoot.namedItem(
"transparencyLevelInt" );
992 if ( ! transparencyNode.isNull() )
996 QDomElement myElement = transparencyNode.toElement();
997 setTransparency( myElement.text().toInt() );
1003 if ( !theResultFlag )
1005 myErrorMessage =
tr(
"Loading style file %1 failed because:\n%2" ).arg( theURI ).arg( errorMsg );
1006 return myErrorMessage;
1014 QDomImplementation DomImplementation;
1015 QDomDocumentType documentType = DomImplementation.createDocumentType(
"qgis",
"http://mrcc.com/qgis.dtd",
"SYSTEM" );
1016 QDomDocument myDocument( documentType );
1018 QDomElement myRootNode = myDocument.createElement(
"qgis" );
1020 myDocument.appendChild( myRootNode );
1023 myRootNode.setAttribute(
"minimumScale", QString::number(
minimumScale() ) );
1024 myRootNode.setAttribute(
"maximumScale", QString::number(
maximumScale() ) );
1028 QDomElement transparencyLevelIntElement = myDocument.createElement(
"transparencyLevelInt" );
1029 QDomText transparencyLevelIntText = myDocument.createTextNode( QString::number( getTransparency() ) );
1030 transparencyLevelIntElement.appendChild( transparencyLevelIntText );
1031 myRootNode.appendChild( transparencyLevelIntElement );
1036 errorMsg =
QObject::tr(
"Could not save symbology because:\n%1" ).arg( errorMsg );
1049 QString myErrorMessage;
1050 QDomDocument myDocument;
1061 QStringList theURIParts = theURI.split(
"|" );
1062 filename = theURIParts[0];
1064 else if ( vlayer && vlayer->
providerType() ==
"delimitedtext" )
1066 filename = QUrl::fromEncoded( theURI.toAscii() ).toLocalFile();
1073 QFileInfo myFileInfo( filename );
1074 if ( myFileInfo.exists() || filename.endsWith(
".qml", Qt::CaseInsensitive ) )
1076 QFileInfo myDirInfo( myFileInfo.path() );
1077 if ( !myDirInfo.isWritable() )
1079 return tr(
"The directory containing your dataset needs to be writable!" );
1083 QString myFileName = myFileInfo.path() + QDir::separator() + myFileInfo.completeBaseName() +
".qml";
1085 QFile myFile( myFileName );
1086 if ( myFile.open( QFile::WriteOnly | QFile::Truncate ) )
1088 QTextStream myFileStream( &myFile );
1090 myDocument.save( myFileStream, 2 );
1092 theResultFlag =
true;
1093 return tr(
"Created default style file as %1" ).arg( myFileName );
1097 theResultFlag =
false;
1098 return tr(
"ERROR: Failed to created default style file as %1. Check file permissions and retry." ).arg( myFileName );
1103 QString qml = myDocument.toString();
1107 sqlite3_stmt *myPreparedStatement;
1112 if ( myResult != SQLITE_OK )
1114 return tr(
"User database could not be opened." );
1117 QByteArray param0 = theURI.toUtf8();
1118 QByteArray param1 = qml.toUtf8();
1120 QString mySql =
"create table if not exists tbl_styles(style varchar primary key,qml varchar)";
1121 myResult = sqlite3_prepare( myDatabase, mySql.toUtf8().data(), mySql.toUtf8().length(), &myPreparedStatement, &myTail );
1122 if ( myResult == SQLITE_OK )
1124 if ( sqlite3_step( myPreparedStatement ) != SQLITE_DONE )
1126 sqlite3_finalize( myPreparedStatement );
1127 sqlite3_close( myDatabase );
1128 theResultFlag =
false;
1129 return tr(
"The style table could not be created." );
1133 sqlite3_finalize( myPreparedStatement );
1135 mySql =
"insert into tbl_styles(style,qml) values (?,?)";
1136 myResult = sqlite3_prepare( myDatabase, mySql.toUtf8().data(), mySql.toUtf8().length(), &myPreparedStatement, &myTail );
1137 if ( myResult == SQLITE_OK )
1139 if ( sqlite3_bind_text( myPreparedStatement, 1, param0.data(), param0.length(), SQLITE_STATIC ) == SQLITE_OK &&
1140 sqlite3_bind_text( myPreparedStatement, 2, param1.data(), param1.length(), SQLITE_STATIC ) == SQLITE_OK &&
1141 sqlite3_step( myPreparedStatement ) == SQLITE_DONE )
1143 theResultFlag =
true;
1144 myErrorMessage =
tr(
"The style %1 was saved to database" ).arg( theURI );
1148 sqlite3_finalize( myPreparedStatement );
1150 if ( !theResultFlag )
1152 QString mySql =
"update tbl_styles set qml=? where style=?";
1153 myResult = sqlite3_prepare( myDatabase, mySql.toUtf8().data(), mySql.toUtf8().length(), &myPreparedStatement, &myTail );
1154 if ( myResult == SQLITE_OK )
1156 if ( sqlite3_bind_text( myPreparedStatement, 2, param0.data(), param0.length(), SQLITE_STATIC ) == SQLITE_OK &&
1157 sqlite3_bind_text( myPreparedStatement, 1, param1.data(), param1.length(), SQLITE_STATIC ) == SQLITE_OK &&
1158 sqlite3_step( myPreparedStatement ) == SQLITE_DONE )
1160 theResultFlag =
true;
1161 myErrorMessage =
tr(
"The style %1 was updated in the database." ).arg( theURI );
1165 theResultFlag =
false;
1166 myErrorMessage =
tr(
"The style %1 could not be updated in the database." ).arg( theURI );
1171 theResultFlag =
false;
1172 myErrorMessage =
tr(
"The style %1 could not be inserted into database." ).arg( theURI );
1175 sqlite3_finalize( myPreparedStatement );
1178 sqlite3_close( myDatabase );
1181 return myErrorMessage;
1186 QDomDocument myDocument = QDomDocument();
1188 QDomNode header = myDocument.createProcessingInstruction(
"xml",
"version=\"1.0\" encoding=\"UTF-8\"" );
1189 myDocument.appendChild( header );
1192 QDomElement root = myDocument.createElementNS(
"http://www.opengis.net/sld",
"StyledLayerDescriptor" );
1193 root.setAttribute(
"version",
"1.1.0" );
1194 root.setAttribute(
"xsi:schemaLocation",
"http://www.opengis.net/sld http://schemas.opengis.net/sld/1.1.0/StyledLayerDescriptor.xsd" );
1195 root.setAttribute(
"xmlns:ogc",
"http://www.opengis.net/ogc" );
1196 root.setAttribute(
"xmlns:se",
"http://www.opengis.net/se" );
1197 root.setAttribute(
"xmlns:xlink",
"http://www.w3.org/1999/xlink" );
1198 root.setAttribute(
"xmlns:xsi",
"http://www.w3.org/2001/XMLSchema-instance" );
1199 myDocument.appendChild( root );
1202 QDomElement namedLayerNode = myDocument.createElement(
"NamedLayer" );
1203 root.appendChild( namedLayerNode );
1208 errorMsg =
tr(
"Could not save symbology because:\n%1" )
1209 .arg(
"Non-vector layers not supported yet" );
1213 if ( !vlayer->
writeSld( namedLayerNode, myDocument, errorMsg ) )
1215 errorMsg =
tr(
"Could not save symbology because:\n%1" ).arg( errorMsg );
1225 QDomDocument myDocument;
1227 if ( !errorMsg.isNull() )
1229 theResultFlag =
false;
1239 QStringList theURIParts = theURI.split(
"|" );
1240 filename = theURIParts[0];
1244 filename = QUrl::fromEncoded( theURI.toAscii() ).toLocalFile();
1251 QFileInfo myFileInfo( filename );
1252 if ( myFileInfo.exists() || filename.endsWith(
".sld", Qt::CaseInsensitive ) )
1254 QFileInfo myDirInfo( myFileInfo.path() );
1255 if ( !myDirInfo.isWritable() )
1257 return tr(
"The directory containing your dataset needs to be writable!" );
1261 QString myFileName = myFileInfo.path() + QDir::separator() + myFileInfo.completeBaseName() +
".sld";
1263 QFile myFile( myFileName );
1264 if ( myFile.open( QFile::WriteOnly | QFile::Truncate ) )
1266 QTextStream myFileStream( &myFile );
1268 myDocument.save( myFileStream, 2 );
1270 theResultFlag =
true;
1271 return tr(
"Created default style file as %1" ).arg( myFileName );
1275 theResultFlag =
false;
1276 return tr(
"ERROR: Failed to created SLD style file as %1. Check file permissions and retry." ).arg( filename );
1283 theResultFlag =
false;
1285 QDomDocument myDocument;
1289 QString myErrorMessage;
1291 QFile myFile( theURI );
1292 if ( myFile.open( QFile::ReadOnly ) )
1295 theResultFlag = myDocument.setContent( &myFile,
true, &myErrorMessage, &line, &column );
1296 if ( !theResultFlag )
1297 myErrorMessage =
tr(
"%1 at line %2 column %3" ).arg( myErrorMessage ).arg( line ).arg( column );
1302 myErrorMessage =
tr(
"Unable to open file %1" ).arg( theURI );
1305 if ( !theResultFlag )
1307 return myErrorMessage;
1311 QDomElement myRoot = myDocument.firstChildElement(
"StyledLayerDescriptor" );
1312 if ( myRoot.isNull() )
1314 myErrorMessage = QString(
"Error: StyledLayerDescriptor element not found in %1" ).arg( theURI );
1315 theResultFlag =
false;
1316 return myErrorMessage;
1321 QDomElement namedLayerElem = myRoot.firstChildElement(
"NamedLayer" );
1322 if ( namedLayerElem.isNull() )
1324 myErrorMessage = QString(
"Info: NamedLayer element not found." );
1325 theResultFlag =
false;
1326 return myErrorMessage;
1330 theResultFlag =
readSld( namedLayerElem, errorMsg );
1331 if ( !theResultFlag )
1333 myErrorMessage =
tr(
"Loading style file %1 failed because:\n%2" ).arg( theURI ).arg( errorMsg );
1334 return myErrorMessage;
static const char * QGIS_VERSION
virtual QStringList subLayers() const
Returns the sublayers of this layer (Useful for providers that manage their own layers, such as WMS)
virtual bool isEditable() const
True if the layer can be edited.
static const QString pkgDataPath()
Returns the common root path of all application data directories.
virtual QString saveNamedStyle(const QString &theURI, bool &theResultFlag)
Save the properties of this layer as a named style (either as a .qml file on disk or as a record in t...
A rectangle specified with double values.
Base class for all map layer types.
QString mID
Unique ID of this layer - used to refer to this layer in map layer registry.
QgsPluginLayer * createLayer(QString typeName)
return new layer if corresponding plugin has been found, else return NULL
QgsMapLayer::LayerType type() const
Get the type of the layer.
virtual QString metadata()
Obtain Metadata for this layer.
void setValidationHint(QString html)
virtual void drawLabels(QgsRenderContext &rendererContext)
Draw labels.
virtual QString loadSldStyle(const QString &theURI, bool &theResultFlag)
void readCustomProperties(const QDomNode &layerNode, const QString &keyStartsWith="")
Read custom properties from project file.
QString publicSource() const
void readXml(const QDomNode &parentNode, const QString &keyStartsWith=QString())
Read store contents from XML.
virtual ~QgsMapLayer()
Destructor.
This class provides qgis with the ability to render raster datasets onto the mapcanvas.
static QString removePassword(const QString &aUri)
Removes password element from uris.
virtual Q_DECL_DEPRECATED QString lastError()
const QString & originalName() const
Get the original name of the layer.
static void warning(const QString &msg)
Goes to qWarning.
virtual bool readSymbology(const QDomNode &node, QString &errorMessage)=0
Read the symbology for the current layer from the Dom node supplied.
void layerNameChanged()
Emit a signal that the layer name has been changed.
void setDatabase(const QString &database)
Set database.
void setCustomProperty(const QString &key, const QVariant &value)
Set a custom property for layer.
bool mScaleBasedVisibility
A flag that tells us whether to use the above vars to restrict layer visibility.
float minimumScale() const
void blendModeChanged(const QPainter::CompositionMode &blendMode)
Signal emitted when the blend mode is changed, through QgsMapLayer::setBlendMode() ...
const QString & attribution() const
static CUSTOM_CRS_VALIDATION customSrsValidation()
Gets custom function.
virtual QString saveDefaultStyle(bool &theResultFlag)
Save the properties of this layer as the default style (either as a .qml file on disk or as a record ...
QUndoStack mUndoStack
Collection of undoable operations for this layer.
static const QString qgisSettingsDirPath()
Returns the path to the settings directory in user's home dir.
QString readPath(QString filename) const
turn filename read from the project file to an absolute path
void remove(const QString &key)
Remove a key (entry) from the store.
void setBlendMode(const QPainter::CompositionMode &blendMode)
Write blend mode for layer.
QString mLayerName
Name of the layer - used for display.
void setMaximumScale(float theMaxScale)
Accessor and mutator for the maximum scale denominator member.
virtual bool writeSymbology(QDomNode &node, QDomDocument &doc, QString &errorMessage) const =0
Write the symbology for the layer into the docment provided.
static void setCustomSrsValidation(CUSTOM_CRS_VALIDATION f)
Sets custom function to force valid CRS QGIS uses implementation in QgisGui::customSrsValidation.
virtual bool draw(QgsRenderContext &rendererContext)
This is the method that does the actual work of drawing the layer onto a paint device.
const QString & legendUrl() const
static QString capitaliseLayerName(const QString &name)
A convenience function to (un)capitalise the layer name.
void setConnection(const QString &aHost, const QString &aPort, const QString &aDatabase, const QString &aUsername, const QString &aPassword, SSLmode sslmode=SSLprefer)
Set all connection related members at once.
const QString & name() const
Get the display name of the layer.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
Return value for the given key. If the key is not stored, default value will be used.
QgsRectangle mExtent
Extent of the layer.
QPainter::CompositionMode mBlendMode
Blend mode for the layer.
QString mMetadataUrl
MetadataUrl of the layer.
QPainter::CompositionMode blendMode() const
Read blend mode for layer.
void setValue(const QString &key, const QVariant &value)
Add an entry to the store. If the entry with the keys exists already, it will be overwritten.
bool hasScaleBasedVisibility() const
bool writeSld(QDomNode &node, QDomDocument &doc, QString &errorMessage) const
void layerCrsChanged()
Emit a signal that layer's CRS has been reset added in 1.4.
const QString & dataUrl() const
virtual bool loadNamedStyleFromDb(const QString &db, const QString &theURI, QString &qml)
virtual bool writeXml(QDomNode &layer_node, QDomDocument &document)
called by writeLayerXML(), used by children to write state specific to them to project files...
QString uri() const
return complete uri
bool writeLayerXML(QDomElement &layerElement, QDomDocument &document)
stores state in Dom node
const QString & metadataUrlType() const
#define QgsDebugMsgLevel(str, level)
Q_DECL_DEPRECATED void setCacheImage(QImage *)
const QString & source() const
Returns the source for the layer.
LayerType
Layers enum defining the types of layers that can be added to a map.
void setParam(const QString &key, const QString &value)
Set generic param (generic mode)
void setCrs(const QgsCoordinateReferenceSystem &srs, bool emitSignal=true)
Sets layer's spatial reference system.
A class to describe the version of a project.
float maximumScale() const
virtual void setExtent(const QgsRectangle &rect)
Set the extent.
QgsObjectCustomProperties mCustomProperties
Layer's persistent storage of additional properties (may be used by plugins)
QString mDataUrl
DataUrl of the layer.
const QString & metadataUrl() const
QString writePath(QString filename) const
prepare a filename to save it to the project file
QString id() const
Get this layer's unique ID, this ID is used to access this layer from map layer registry.
virtual void setSubLayerVisibility(QString name, bool vis)
Set the visibility of the given sublayer name.
void writeCustomProperties(QDomNode &layerNode, QDomDocument &doc) const
Write custom properties to project file.
virtual Q_DECL_DEPRECATED QString lastErrorTitle()
void removeCustomProperty(const QString &key)
Remove a custom property from layer.
QVariant customProperty(const QString &value, const QVariant &defaultValue=QVariant()) const
Read a custom property from layer.
virtual QString saveSldStyle(const QString &theURI, bool &theResultFlag)
bool mValid
Indicates if the layer is valid and can be drawn.
virtual bool readSld(const QDomNode &node, QString &errorMessage)
QString mMetadataUrlFormat
Class for storing the component parts of a PostgreSQL/RDBMS datasource URI.
QString mAttribution
Attribution of the layer.
QString mAbstract
Description of the layer.
virtual void exportNamedStyle(QDomDocument &doc, QString &errorMsg)
Export the properties of this layer as named style in a QDomDocument.
QString providerType() const
Return the provider type for this layer.
static QList< QgsMapLayer * > fromLayerDefinitionFile(const QString qlrfile)
void connectNotify(const char *signal)
debugging member - invoked when a connect() is made to this object
bool writeXML(QDomNode &theNode, QDomDocument &theDoc) const
Contains information about the context of a rendering operation.
Q_DECL_DEPRECATED void clearCacheImage()
Clear cached image.
QString mDataSource
data source description string, varies by layer type
virtual QString loadDefaultStyle(bool &theResultFlag)
Retrieve the default style for this layer if one exists (either as a .qml file on disk or as a record...
void writeXml(QDomNode &parentNode, QDomDocument &doc) const
Write store contents to XML.
virtual void invalidTransformInput()
Event handler for when a coordinate transform fails due to bad vertex error.
void repaintRequested()
By emitting this signal the layer tells that either appearance or content have been changed and any v...
static QgsProject * instance()
access to canonical QgsProject instance
virtual bool readXml(const QDomNode &layer_node)
called by readLayerXML(), used by children to read state specific to them from project files...
float mMaxScale
Maximum scale denominator at which this layer should be displayed.
QString mLegendUrl
WMS legend.
Class for storing a coordinate reference system (CRS)
bool readLayerXML(const QDomElement &layerElement)
sets state from Dom document
void setLayerName(const QString &name)
Set the display name of the layer.
const QgsCoordinateReferenceSystem & crs() const
Returns layer's spatial reference system.
static QDomDocument asLayerDefinition(QList< QgsMapLayer * > layers)
Returns the given layer as a layer definition document Layer definitions store the data source as wel...
virtual QString loadNamedStyle(const QString &theURI, bool &theResultFlag)
Retrieve a named style for this layer if one exists (either as a .qml file on disk or as a record in ...
QByteArray encodedUri() const
return complete encoded uri (generic mode)
bool readXML(QDomNode &theNode)
QgsMapLayer::LayerType mLayerType
Type of the layer (eg.
QgsCoordinateReferenceSystem * mCRS
layer's spatial reference system.
static QList< QgsMapLayer * > fromLayerDefinition(QDomDocument &document)
Creates a new layer from a layer defininition document.
static QgsPluginLayerRegistry * instance()
means of accessing canonical single instance
QUndoStack * undoStack()
Return pointer to layer's undo stack.
virtual QDateTime timestamp() const
Time stamp of data source in the moment when data/metadata were loaded by provider.
const QString & attributionUrl() const
void(* CUSTOM_CRS_VALIDATION)(QgsCoordinateReferenceSystem &)
virtual QString styleURI()
Retrieve the style URI for this layer (either as a .qml file on disk or as a record in the users styl...
const QString & metadataUrlFormat() const
const QString & legendUrlFormat() const
virtual QgsRectangle extent()
Return the extent of the layer.
Represents a vector layer which manages a vector based data sets.
virtual void setLayerOrder(const QStringList &layers)
Reorders the previously selected sublayers of this layer from bottom to top (Useful for providers tha...
const QString & title() const
QString mLayerOrigName
Original name of the layer.
void setValid(bool valid)
set whether layer is valid or not - should be used in constructor.
const QString & keywordList() const
float mMinScale
Minimum scale denominator at which this layer should be displayed.
virtual void exportSldStyle(QDomDocument &doc, QString &errorMsg)
Export the properties of this layer as SLD style in a QDomDocument.
const QString & dataUrlFormat() const
void toggleScaleBasedVisibility(bool theVisibilityFlag)
Accessor and mutator for the scale based visilibility flag.
QgsMapLayer(QgsMapLayer::LayerType type=VectorLayer, QString lyrname=QString::null, QString source=QString::null)
Constructor.
void setMinimumScale(float theMinScale)
Accessor and mutator for the minimum scale denominator member.