QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
qgsmaplayer.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsmaplayer.cpp - description
3  -------------------
4  begin : Fri Jun 28 2002
5  copyright : (C) 2002 by Gary E.Sherman
6  email : sherman at mrcc.com
7 ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 
19 #include "qgssqliteutils.h"
20 #include "qgs3drendererregistry.h"
21 #include "qgsabstract3drenderer.h"
22 #include "qgsapplication.h"
24 #include "qgsdatasourceuri.h"
25 #include "qgsfileutils.h"
26 #include "qgslogger.h"
27 #include "qgsauthmanager.h"
28 #include "qgsmaplayer.h"
29 #include "qgsmaplayerlegend.h"
31 #include "qgsmeshlayer.h"
32 #include "qgspathresolver.h"
34 #include "qgsproject.h"
35 #include "qgsproviderregistry.h"
36 #include "qgsrasterlayer.h"
37 #include "qgsreadwritecontext.h"
38 #include "qgsrectangle.h"
39 #include "qgsvectorlayer.h"
40 #include "qgsvectordataprovider.h"
41 #include "qgsxmlutils.h"
42 #include "qgsstringutils.h"
43 #include "qgsmessagelog.h"
46 #include "qgsprovidermetadata.h"
47 #include "qgslayernotesutils.h"
48 #include "qgsdatums.h"
49 #include "qgsprojoperation.h"
50 
51 #include <QDir>
52 #include <QDomDocument>
53 #include <QDomElement>
54 #include <QDomImplementation>
55 #include <QDomNode>
56 #include <QFile>
57 #include <QFileInfo>
58 #include <QLocale>
59 #include <QTextStream>
60 #include <QUrl>
61 #include <QTimer>
62 #include <QStandardPaths>
63 #include <QUuid>
64 #include <QRegularExpression>
65 
66 #include <sqlite3.h>
67 
69 {
70  switch ( type )
71  {
72  case Metadata:
73  return QStringLiteral( ".qmd" );
74 
75  case Style:
76  return QStringLiteral( ".qml" );
77  }
78  return QString();
79 }
80 
82  const QString &lyrname,
83  const QString &source )
84  : mDataSource( source )
85  , mLayerName( lyrname )
86  , mLayerType( type )
87  , mServerProperties( std::make_unique<QgsMapLayerServerProperties>( this ) )
88  , mUndoStack( new QUndoStack( this ) )
89  , mUndoStackStyles( new QUndoStack( this ) )
90  , mStyleManager( new QgsMapLayerStyleManager( this ) )
91  , mRefreshTimer( new QTimer( this ) )
92 {
93  mID = generateId( lyrname );
94  connect( this, &QgsMapLayer::crsChanged, this, &QgsMapLayer::configChanged );
95  connect( this, &QgsMapLayer::nameChanged, this, &QgsMapLayer::configChanged );
96  connect( mRefreshTimer, &QTimer::timeout, this, [ = ] { triggerRepaint( true ); } );
97 }
98 
100 {
101  if ( project() && project()->pathResolver().writePath( mDataSource ).startsWith( "attachment:" ) )
102  {
104  }
105 
106  delete m3DRenderer;
107  delete mLegend;
108  delete mStyleManager;
109 }
110 
111 void QgsMapLayer::clone( QgsMapLayer *layer ) const
112 {
113  layer->setBlendMode( blendMode() );
114 
115  const auto constStyles = styleManager()->styles();
116  for ( const QString &s : constStyles )
117  {
118  layer->styleManager()->addStyle( s, styleManager()->style( s ) );
119  }
120 
121  layer->setName( name() );
122  layer->setShortName( shortName() );
123  layer->setExtent( extent() );
124  layer->setMaximumScale( maximumScale() );
125  layer->setMinimumScale( minimumScale() );
127  layer->setTitle( title() );
128  layer->setAbstract( abstract() );
129  layer->setKeywordList( keywordList() );
130  layer->setDataUrl( dataUrl() );
131  layer->setDataUrlFormat( dataUrlFormat() );
132  layer->setAttribution( attribution() );
133  layer->setAttributionUrl( attributionUrl() );
134  layer->setLegendUrl( legendUrl() );
136  layer->setDependencies( dependencies() );
138  layer->setCrs( crs() );
139  layer->setCustomProperties( mCustomProperties );
140  layer->setOpacity( mLayerOpacity );
141  layer->setMetadata( mMetadata );
142  layer->serverProperties()->copyTo( mServerProperties.get() );
143 }
144 
146 {
147  return mLayerType;
148 }
149 
150 QgsMapLayer::LayerFlags QgsMapLayer::flags() const
151 {
152  return mFlags;
153 }
154 
155 void QgsMapLayer::setFlags( QgsMapLayer::LayerFlags flags )
156 {
157  if ( flags == mFlags )
158  return;
159 
160  mFlags = flags;
161  emit flagsChanged();
162 }
163 
164 Qgis::MapLayerProperties QgsMapLayer::properties() const
165 {
166  return Qgis::MapLayerProperties();
167 }
168 
169 QString QgsMapLayer::id() const
170 {
171  return mID;
172 }
173 
174 void QgsMapLayer::setName( const QString &name )
175 {
176  if ( name == mLayerName )
177  return;
178 
179  mLayerName = name;
180 
181  emit nameChanged();
182 }
183 
184 QString QgsMapLayer::name() const
185 {
186  QgsDebugMsgLevel( "returning name '" + mLayerName + '\'', 4 );
187  return mLayerName;
188 }
189 
191 {
192  return nullptr;
193 }
194 
196 {
197  return nullptr;
198 }
199 
200 QString QgsMapLayer::shortName() const
201 {
202  return mShortName;
203 }
204 
205 void QgsMapLayer::setMetadataUrl( const QString &metaUrl )
206 {
207  QList<QgsMapLayerServerProperties::MetadataUrl> urls = serverProperties()->metadataUrls();
208  if ( urls.isEmpty() )
209  {
210  const QgsMapLayerServerProperties::MetadataUrl newItem = QgsMapLayerServerProperties::MetadataUrl( metaUrl, QLatin1String(), QLatin1String() );
211  urls.prepend( newItem );
212  }
213  else
214  {
215  const QgsMapLayerServerProperties::MetadataUrl old = urls.takeFirst();
216  const QgsMapLayerServerProperties::MetadataUrl newItem( metaUrl, old.type, old.format );
217  urls.prepend( newItem );
218  }
220 }
221 
223 {
224  if ( mServerProperties->metadataUrls().isEmpty() )
225  {
226  return QLatin1String();
227  }
228  else
229  {
230  return mServerProperties->metadataUrls().first().url;
231  }
232 }
233 
234 void QgsMapLayer::setMetadataUrlType( const QString &metaUrlType )
235 {
236  QList<QgsMapLayerServerProperties::MetadataUrl> urls = mServerProperties->metadataUrls();
237  if ( urls.isEmpty() )
238  {
239  const QgsMapLayerServerProperties::MetadataUrl newItem( QLatin1String(), metaUrlType, QLatin1String() );
240  urls.prepend( newItem );
241  }
242  else
243  {
244  const QgsMapLayerServerProperties::MetadataUrl old = urls.takeFirst();
245  const QgsMapLayerServerProperties::MetadataUrl newItem( old.url, metaUrlType, old.format );
246  urls.prepend( newItem );
247  }
248  mServerProperties->setMetadataUrls( urls );
249 }
250 
252 {
253  if ( mServerProperties->metadataUrls().isEmpty() )
254  {
255  return QLatin1String();
256  }
257  else
258  {
259  return mServerProperties->metadataUrls().first().type;
260  }
261 }
262 
263 void QgsMapLayer::setMetadataUrlFormat( const QString &metaUrlFormat )
264 {
265  QList<QgsMapLayerServerProperties::MetadataUrl> urls = mServerProperties->metadataUrls();
266  if ( urls.isEmpty() )
267  {
268  const QgsMapLayerServerProperties::MetadataUrl newItem( QLatin1String(), QLatin1String(), metaUrlFormat );
269  urls.prepend( newItem );
270  }
271  else
272  {
273  const QgsMapLayerServerProperties::MetadataUrl old = urls.takeFirst( );
274  const QgsMapLayerServerProperties::MetadataUrl newItem( old.url, old.type, metaUrlFormat );
275  urls.prepend( newItem );
276  }
277  mServerProperties->setMetadataUrls( urls );
278 }
279 
281 {
282  if ( mServerProperties->metadataUrls().isEmpty() )
283  {
284  return QString();
285  }
286  else
287  {
288  return mServerProperties->metadataUrls().first().format;
289  }
290 }
291 
293 {
294  // Redo this every time we're asked for it, as we don't know if
295  // dataSource has changed.
296  QString safeName = QgsDataSourceUri::removePassword( mDataSource );
297  return safeName;
298 }
299 
300 QString QgsMapLayer::source() const
301 {
302  return mDataSource;
303 }
304 
306 {
307  return mExtent;
308 }
309 
310 void QgsMapLayer::setBlendMode( const QPainter::CompositionMode blendMode )
311 {
312  if ( mBlendMode == blendMode )
313  return;
314 
315  mBlendMode = blendMode;
316  emit blendModeChanged( blendMode );
318 }
319 
320 QPainter::CompositionMode QgsMapLayer::blendMode() const
321 {
322  return mBlendMode;
323 }
324 
325 void QgsMapLayer::setOpacity( double opacity )
326 {
328  return;
330  emit opacityChanged( opacity );
332 }
333 
334 double QgsMapLayer::opacity() const
335 {
336  return mLayerOpacity;
337 }
338 
339 bool QgsMapLayer::readLayerXml( const QDomElement &layerElement, QgsReadWriteContext &context, QgsMapLayer::ReadFlags flags )
340 {
341  bool layerError;
342  mReadFlags = flags;
343 
344  QDomNode mnl;
345  QDomElement mne;
346 
347  // read provider
348  QString provider;
349  mnl = layerElement.namedItem( QStringLiteral( "provider" ) );
350  mne = mnl.toElement();
351  provider = mne.text();
352 
353  // set data source
354  mnl = layerElement.namedItem( QStringLiteral( "datasource" ) );
355  mne = mnl.toElement();
356  mDataSource = context.pathResolver().readPath( mne.text() );
357 
358  // if the layer needs authentication, ensure the master password is set
359  const thread_local QRegularExpression rx( "authcfg=([a-z]|[A-Z]|[0-9]){7}" );
360  if ( rx.match( mDataSource ).hasMatch()
362  {
363  return false;
364  }
365 
366  mDataSource = decodedSource( mDataSource, provider, context );
367 
368  // Set the CRS from project file, asking the user if necessary.
369  // Make it the saved CRS to have WMS layer projected correctly.
370  // We will still overwrite whatever GDAL etc picks up anyway
371  // further down this function.
372  mnl = layerElement.namedItem( QStringLiteral( "layername" ) );
373  mne = mnl.toElement();
374 
376  CUSTOM_CRS_VALIDATION savedValidation;
377 
378  const QDomNode srsNode = layerElement.namedItem( QStringLiteral( "srs" ) );
379  mCRS.readXml( srsNode );
380  mCRS.setValidationHint( tr( "Specify CRS for layer %1" ).arg( mne.text() ) );
382  mCRS.validate();
383  savedCRS = mCRS;
384 
385  // Do not validate any projections in children, they will be overwritten anyway.
386  // No need to ask the user for a projections when it is overwritten, is there?
389 
390  const QgsReadWriteContextCategoryPopper p = context.enterCategory( tr( "Layer" ), mne.text() );
391 
392  // the internal name is just the data source basename
393  //QFileInfo dataSourceFileInfo( mDataSource );
394  //internalName = dataSourceFileInfo.baseName();
395 
396  // set ID
397  mnl = layerElement.namedItem( QStringLiteral( "id" ) );
398  if ( ! mnl.isNull() )
399  {
400  mne = mnl.toElement();
401  if ( ! mne.isNull() && mne.text().length() > 10 ) // should be at least 17 (yyyyMMddhhmmsszzz)
402  {
403  mID = mne.text();
404  }
405  }
406 
407  // set name
408  mnl = layerElement.namedItem( QStringLiteral( "layername" ) );
409  mne = mnl.toElement();
410 
411  //name can be translated
412  setName( context.projectTranslator()->translate( QStringLiteral( "project:layers:%1" ).arg( layerElement.namedItem( QStringLiteral( "id" ) ).toElement().text() ), mne.text() ) );
413 
414  // now let the children grab what they need from the Dom node.
415  layerError = !readXml( layerElement, context );
416 
417  // overwrite CRS with what we read from project file before the raster/vector
418  // file reading functions changed it. They will if projections is specified in the file.
419  // FIXME: is this necessary? Yes, it is (autumn 2019)
421  mCRS = savedCRS;
422 
423  //short name
424  const QDomElement shortNameElem = layerElement.firstChildElement( QStringLiteral( "shortname" ) );
425  if ( !shortNameElem.isNull() )
426  {
427  mShortName = shortNameElem.text();
428  }
429 
430  //title
431  const QDomElement titleElem = layerElement.firstChildElement( QStringLiteral( "title" ) );
432  if ( !titleElem.isNull() )
433  {
434  mTitle = titleElem.text();
435  }
436 
437  //abstract
438  const QDomElement abstractElem = layerElement.firstChildElement( QStringLiteral( "abstract" ) );
439  if ( !abstractElem.isNull() )
440  {
441  mAbstract = abstractElem.text();
442  }
443 
444  //keywordList
445  const QDomElement keywordListElem = layerElement.firstChildElement( QStringLiteral( "keywordList" ) );
446  if ( !keywordListElem.isNull() )
447  {
448  QStringList kwdList;
449  for ( QDomNode n = keywordListElem.firstChild(); !n.isNull(); n = n.nextSibling() )
450  {
451  kwdList << n.toElement().text();
452  }
453  mKeywordList = kwdList.join( QLatin1String( ", " ) );
454  }
455 
456  //dataUrl
457  const QDomElement dataUrlElem = layerElement.firstChildElement( QStringLiteral( "dataUrl" ) );
458  if ( !dataUrlElem.isNull() )
459  {
460  mDataUrl = dataUrlElem.text();
461  mDataUrlFormat = dataUrlElem.attribute( QStringLiteral( "format" ), QString() );
462  }
463 
464  //legendUrl
465  const QDomElement legendUrlElem = layerElement.firstChildElement( QStringLiteral( "legendUrl" ) );
466  if ( !legendUrlElem.isNull() )
467  {
468  mLegendUrl = legendUrlElem.text();
469  mLegendUrlFormat = legendUrlElem.attribute( QStringLiteral( "format" ), QString() );
470  }
471 
472  //attribution
473  const QDomElement attribElem = layerElement.firstChildElement( QStringLiteral( "attribution" ) );
474  if ( !attribElem.isNull() )
475  {
476  mAttribution = attribElem.text();
477  mAttributionUrl = attribElem.attribute( QStringLiteral( "href" ), QString() );
478  }
479 
480  serverProperties()->readXml( layerElement );
481 
482  if ( serverProperties()->metadataUrls().isEmpty() )
483  {
484  // metadataUrl is still empty, maybe it's a QGIS Project < 3.22
485  // keep for legacy
486  const QDomElement metaUrlElem = layerElement.firstChildElement( QStringLiteral( "metadataUrl" ) );
487  if ( !metaUrlElem.isNull() )
488  {
489  const QString url = metaUrlElem.text();
490  const QString type = metaUrlElem.attribute( QStringLiteral( "type" ), QString() );
491  const QString format = metaUrlElem.attribute( QStringLiteral( "format" ), QString() );
492  const QgsMapLayerServerProperties::MetadataUrl newItem( url, type, format );
493  mServerProperties->setMetadataUrls( QList<QgsMapLayerServerProperties::MetadataUrl>() << newItem );
494  }
495  }
496 
497  // mMetadata.readFromLayer( this );
498  const QDomElement metadataElem = layerElement.firstChildElement( QStringLiteral( "resourceMetadata" ) );
499  mMetadata.readMetadataXml( metadataElem );
500 
501  setAutoRefreshInterval( layerElement.attribute( QStringLiteral( "autoRefreshTime" ), QStringLiteral( "0" ) ).toInt() );
502  setAutoRefreshEnabled( layerElement.attribute( QStringLiteral( "autoRefreshEnabled" ), QStringLiteral( "0" ) ).toInt() );
503  setRefreshOnNofifyMessage( layerElement.attribute( QStringLiteral( "refreshOnNotifyMessage" ), QString() ) );
504  setRefreshOnNotifyEnabled( layerElement.attribute( QStringLiteral( "refreshOnNotifyEnabled" ), QStringLiteral( "0" ) ).toInt() );
505 
506  // geographic extent is read only if necessary
507  if ( mReadFlags & QgsMapLayer::ReadFlag::FlagTrustLayerMetadata )
508  {
509  const QDomNode wgs84ExtentNode = layerElement.namedItem( QStringLiteral( "wgs84extent" ) );
510  if ( !wgs84ExtentNode.isNull() )
511  mWgs84Extent = QgsXmlUtils::readRectangle( wgs84ExtentNode.toElement() );
512  }
513 
514  mLegendPlaceholderImage = layerElement.attribute( QStringLiteral( "legendPlaceholderImage" ) );
515 
516  return ! layerError;
517 } // bool QgsMapLayer::readLayerXML
518 
519 
520 bool QgsMapLayer::readXml( const QDomNode &layer_node, QgsReadWriteContext &context )
521 {
522  Q_UNUSED( layer_node )
523  Q_UNUSED( context )
524  // NOP by default; children will over-ride with behavior specific to them
525 
526  // read Extent
528  {
529  const QDomNode extentNode = layer_node.namedItem( QStringLiteral( "extent" ) );
530  if ( !extentNode.isNull() )
531  {
532  mExtent = QgsXmlUtils::readRectangle( extentNode.toElement() );
533  }
534  }
535 
536  return true;
537 } // void QgsMapLayer::readXml
538 
539 
540 bool QgsMapLayer::writeLayerXml( QDomElement &layerElement, QDomDocument &document, const QgsReadWriteContext &context ) const
541 {
542  if ( !extent().isNull() )
543  {
544  layerElement.appendChild( QgsXmlUtils::writeRectangle( mExtent, document ) );
545  layerElement.appendChild( QgsXmlUtils::writeRectangle( wgs84Extent( true ), document, QStringLiteral( "wgs84extent" ) ) );
546  }
547 
548  layerElement.setAttribute( QStringLiteral( "autoRefreshTime" ), QString::number( mRefreshTimer->interval() ) );
549  layerElement.setAttribute( QStringLiteral( "autoRefreshEnabled" ), mRefreshTimer->isActive() ? 1 : 0 );
550  layerElement.setAttribute( QStringLiteral( "refreshOnNotifyEnabled" ), mIsRefreshOnNofifyEnabled ? 1 : 0 );
551  layerElement.setAttribute( QStringLiteral( "refreshOnNotifyMessage" ), mRefreshOnNofifyMessage );
552 
553  // ID
554  QDomElement layerId = document.createElement( QStringLiteral( "id" ) );
555  const QDomText layerIdText = document.createTextNode( id() );
556  layerId.appendChild( layerIdText );
557 
558  layerElement.appendChild( layerId );
559 
560  // data source
561  QDomElement dataSource = document.createElement( QStringLiteral( "datasource" ) );
562  const QString src = context.pathResolver().writePath( encodedSource( source(), context ) );
563  const QDomText dataSourceText = document.createTextNode( src );
564  dataSource.appendChild( dataSourceText );
565  layerElement.appendChild( dataSource );
566 
567  // layer name
568  QDomElement layerName = document.createElement( QStringLiteral( "layername" ) );
569  const QDomText layerNameText = document.createTextNode( name() );
570  layerName.appendChild( layerNameText );
571  layerElement.appendChild( layerName );
572 
573  // layer short name
574  if ( !mShortName.isEmpty() )
575  {
576  QDomElement layerShortName = document.createElement( QStringLiteral( "shortname" ) );
577  const QDomText layerShortNameText = document.createTextNode( mShortName );
578  layerShortName.appendChild( layerShortNameText );
579  layerElement.appendChild( layerShortName );
580  }
581 
582  // layer title
583  if ( !mTitle.isEmpty() )
584  {
585  QDomElement layerTitle = document.createElement( QStringLiteral( "title" ) );
586  const QDomText layerTitleText = document.createTextNode( mTitle );
587  layerTitle.appendChild( layerTitleText );
588  layerElement.appendChild( layerTitle );
589  }
590 
591  // layer abstract
592  if ( !mAbstract.isEmpty() )
593  {
594  QDomElement layerAbstract = document.createElement( QStringLiteral( "abstract" ) );
595  const QDomText layerAbstractText = document.createTextNode( mAbstract );
596  layerAbstract.appendChild( layerAbstractText );
597  layerElement.appendChild( layerAbstract );
598  }
599 
600  // layer keyword list
601  const QStringList keywordStringList = keywordList().split( ',' );
602  if ( !keywordStringList.isEmpty() )
603  {
604  QDomElement layerKeywordList = document.createElement( QStringLiteral( "keywordList" ) );
605  for ( int i = 0; i < keywordStringList.size(); ++i )
606  {
607  QDomElement layerKeywordValue = document.createElement( QStringLiteral( "value" ) );
608  const QDomText layerKeywordText = document.createTextNode( keywordStringList.at( i ).trimmed() );
609  layerKeywordValue.appendChild( layerKeywordText );
610  layerKeywordList.appendChild( layerKeywordValue );
611  }
612  layerElement.appendChild( layerKeywordList );
613  }
614 
615  // layer dataUrl
616  const QString aDataUrl = dataUrl();
617  if ( !aDataUrl.isEmpty() )
618  {
619  QDomElement layerDataUrl = document.createElement( QStringLiteral( "dataUrl" ) );
620  const QDomText layerDataUrlText = document.createTextNode( aDataUrl );
621  layerDataUrl.appendChild( layerDataUrlText );
622  layerDataUrl.setAttribute( QStringLiteral( "format" ), dataUrlFormat() );
623  layerElement.appendChild( layerDataUrl );
624  }
625 
626  // layer legendUrl
627  const QString aLegendUrl = legendUrl();
628  if ( !aLegendUrl.isEmpty() )
629  {
630  QDomElement layerLegendUrl = document.createElement( QStringLiteral( "legendUrl" ) );
631  const QDomText layerLegendUrlText = document.createTextNode( aLegendUrl );
632  layerLegendUrl.appendChild( layerLegendUrlText );
633  layerLegendUrl.setAttribute( QStringLiteral( "format" ), legendUrlFormat() );
634  layerElement.appendChild( layerLegendUrl );
635  }
636 
637  // layer attribution
638  const QString aAttribution = attribution();
639  if ( !aAttribution.isEmpty() )
640  {
641  QDomElement layerAttribution = document.createElement( QStringLiteral( "attribution" ) );
642  const QDomText layerAttributionText = document.createTextNode( aAttribution );
643  layerAttribution.appendChild( layerAttributionText );
644  layerAttribution.setAttribute( QStringLiteral( "href" ), attributionUrl() );
645  layerElement.appendChild( layerAttribution );
646  }
647 
648  // timestamp if supported
649  if ( timestamp() > QDateTime() )
650  {
651  QDomElement stamp = document.createElement( QStringLiteral( "timestamp" ) );
652  const QDomText stampText = document.createTextNode( timestamp().toString( Qt::ISODate ) );
653  stamp.appendChild( stampText );
654  layerElement.appendChild( stamp );
655  }
656 
657  layerElement.appendChild( layerName );
658 
659  // zorder
660  // This is no longer stored in the project file. It is superfluous since the layers
661  // are written and read in the proper order.
662 
663  // spatial reference system id
664  QDomElement mySrsElement = document.createElement( QStringLiteral( "srs" ) );
665  mCRS.writeXml( mySrsElement, document );
666  layerElement.appendChild( mySrsElement );
667 
668  // layer metadata
669  QDomElement myMetadataElem = document.createElement( QStringLiteral( "resourceMetadata" ) );
670  mMetadata.writeMetadataXml( myMetadataElem, document );
671  layerElement.appendChild( myMetadataElem );
672 
673  layerElement.setAttribute( QStringLiteral( "legendPlaceholderImage" ), mLegendPlaceholderImage );
674 
675  // now append layer node to map layer node
676  return writeXml( layerElement, document, context );
677 }
678 
679 void QgsMapLayer::writeCommonStyle( QDomElement &layerElement, QDomDocument &document,
680  const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories ) const
681 {
682  // save categories
683  const QMetaEnum metaEnum = QMetaEnum::fromType<QgsMapLayer::StyleCategories>();
684  const QString categoriesKeys( metaEnum.valueToKeys( static_cast<int>( categories ) ) );
685  layerElement.setAttribute( QStringLiteral( "styleCategories" ), categoriesKeys );
686 
687  if ( categories.testFlag( Rendering ) )
688  {
689  // use scale dependent visibility flag
690  layerElement.setAttribute( QStringLiteral( "hasScaleBasedVisibilityFlag" ), hasScaleBasedVisibility() ? 1 : 0 );
691  layerElement.setAttribute( QStringLiteral( "maxScale" ), QString::number( maximumScale() ) );
692  layerElement.setAttribute( QStringLiteral( "minScale" ), QString::number( minimumScale() ) );
693  }
694 
695  if ( categories.testFlag( Symbology3D ) )
696  {
697  if ( m3DRenderer )
698  {
699  QDomElement renderer3DElem = document.createElement( QStringLiteral( "renderer-3d" ) );
700  renderer3DElem.setAttribute( QStringLiteral( "type" ), m3DRenderer->type() );
701  m3DRenderer->writeXml( renderer3DElem, context );
702  layerElement.appendChild( renderer3DElem );
703  }
704  }
705 
706  if ( categories.testFlag( LayerConfiguration ) )
707  {
708  // flags
709  // this code is saving automatically all the flags entries
710  QDomElement layerFlagsElem = document.createElement( QStringLiteral( "flags" ) );
711  const auto enumMap = qgsEnumMap<QgsMapLayer::LayerFlag>();
712  for ( auto it = enumMap.constBegin(); it != enumMap.constEnd(); ++it )
713  {
714  const bool flagValue = mFlags.testFlag( it.key() );
715  QDomElement flagElem = document.createElement( it.value() );
716  flagElem.appendChild( document.createTextNode( QString::number( flagValue ) ) );
717  layerFlagsElem.appendChild( flagElem );
718  }
719  layerElement.appendChild( layerFlagsElem );
720  }
721 
722  if ( categories.testFlag( Temporal ) )
723  {
724  if ( QgsMapLayerTemporalProperties *properties = const_cast< QgsMapLayer * >( this )->temporalProperties() )
725  properties->writeXml( layerElement, document, context );
726  }
727 
728  if ( categories.testFlag( Elevation ) )
729  {
730  if ( QgsMapLayerElevationProperties *properties = const_cast< QgsMapLayer * >( this )->elevationProperties() )
731  properties->writeXml( layerElement, document, context );
732  }
733 
734  if ( categories.testFlag( Notes ) && QgsLayerNotesUtils::layerHasNotes( this ) )
735  {
736  QDomElement notesElem = document.createElement( QStringLiteral( "userNotes" ) );
737  notesElem.setAttribute( QStringLiteral( "value" ), QgsLayerNotesUtils::layerNotes( this ) );
738  layerElement.appendChild( notesElem );
739  }
740 
741  // custom properties
742  if ( categories.testFlag( CustomProperties ) )
743  {
744  writeCustomProperties( layerElement, document );
745  }
746 }
747 
748 
749 bool QgsMapLayer::writeXml( QDomNode &layer_node, QDomDocument &document, const QgsReadWriteContext &context ) const
750 {
751  Q_UNUSED( layer_node )
752  Q_UNUSED( document )
753  Q_UNUSED( context )
754  // NOP by default; children will over-ride with behavior specific to them
755 
756  return true;
757 }
758 
759 QString QgsMapLayer::encodedSource( const QString &source, const QgsReadWriteContext &context ) const
760 {
761  Q_UNUSED( context )
762  return source;
763 }
764 
765 QString QgsMapLayer::decodedSource( const QString &source, const QString &dataProvider, const QgsReadWriteContext &context ) const
766 {
767  Q_UNUSED( context )
768  Q_UNUSED( dataProvider )
769  return source;
770 }
771 
773 {
775  if ( m3DRenderer )
776  m3DRenderer->resolveReferences( *project );
777 }
778 
779 
780 void QgsMapLayer::readCustomProperties( const QDomNode &layerNode, const QString &keyStartsWith )
781 {
782  const QgsObjectCustomProperties oldKeys = mCustomProperties;
783 
784  mCustomProperties.readXml( layerNode, keyStartsWith );
785 
786  for ( const QString &key : mCustomProperties.keys() )
787  {
788  if ( !oldKeys.contains( key ) || mCustomProperties.value( key ) != oldKeys.value( key ) )
789  {
790  emit customPropertyChanged( key );
791  }
792  }
793 }
794 
795 void QgsMapLayer::writeCustomProperties( QDomNode &layerNode, QDomDocument &doc ) const
796 {
797  mCustomProperties.writeXml( layerNode, doc );
798 }
799 
800 void QgsMapLayer::readStyleManager( const QDomNode &layerNode )
801 {
802  const QDomElement styleMgrElem = layerNode.firstChildElement( QStringLiteral( "map-layer-style-manager" ) );
803  if ( !styleMgrElem.isNull() )
804  mStyleManager->readXml( styleMgrElem );
805  else
806  mStyleManager->reset();
807 }
808 
809 void QgsMapLayer::writeStyleManager( QDomNode &layerNode, QDomDocument &doc ) const
810 {
811  if ( mStyleManager )
812  {
813  QDomElement styleMgrElem = doc.createElement( QStringLiteral( "map-layer-style-manager" ) );
814  mStyleManager->writeXml( styleMgrElem );
815  layerNode.appendChild( styleMgrElem );
816  }
817 }
818 
819 bool QgsMapLayer::isValid() const
820 {
821  return mValid;
822 }
823 
824 #if 0
825 void QgsMapLayer::connectNotify( const char *signal )
826 {
827  Q_UNUSED( signal )
828  QgsDebugMsgLevel( "QgsMapLayer connected to " + QString( signal ), 3 );
829 } // QgsMapLayer::connectNotify
830 #endif
831 
832 bool QgsMapLayer::isInScaleRange( double scale ) const
833 {
834  return !mScaleBasedVisibility ||
835  ( ( mMinScale == 0 || mMinScale * Qgis::SCALE_PRECISION < scale )
836  && ( mMaxScale == 0 || scale < mMaxScale ) );
837 }
838 
840 {
841  return mScaleBasedVisibility;
842 }
843 
845 {
846  return mRefreshTimer->isActive();
847 }
848 
850 {
851  return mRefreshTimer->interval();
852 }
853 
855 {
856  if ( interval <= 0 )
857  {
858  mRefreshTimer->stop();
859  mRefreshTimer->setInterval( 0 );
860  }
861  else
862  {
863  mRefreshTimer->setInterval( interval );
864  }
865  emit autoRefreshIntervalChanged( mRefreshTimer->isActive() ? mRefreshTimer->interval() : 0 );
866 }
867 
869 {
870  if ( !enabled )
871  mRefreshTimer->stop();
872  else if ( mRefreshTimer->interval() > 0 )
873  mRefreshTimer->start();
874 
875  emit autoRefreshIntervalChanged( mRefreshTimer->isActive() ? mRefreshTimer->interval() : 0 );
876 }
877 
879 {
880  return mMetadata;
881 }
882 
883 void QgsMapLayer::setMaximumScale( double scale )
884 {
885  mMinScale = scale;
886 }
887 
889 {
890  return mMinScale;
891 }
892 
893 
894 void QgsMapLayer::setMinimumScale( double scale )
895 {
896  mMaxScale = scale;
897 }
898 
899 void QgsMapLayer::setScaleBasedVisibility( const bool enabled )
900 {
901  mScaleBasedVisibility = enabled;
902 }
903 
905 {
906  return mMaxScale;
907 }
908 
909 QStringList QgsMapLayer::subLayers() const
910 {
911  return QStringList(); // Empty
912 }
913 
914 void QgsMapLayer::setLayerOrder( const QStringList &layers )
915 {
916  Q_UNUSED( layers )
917  // NOOP
918 }
919 
920 void QgsMapLayer::setSubLayerVisibility( const QString &name, bool vis )
921 {
922  Q_UNUSED( name )
923  Q_UNUSED( vis )
924  // NOOP
925 }
926 
928 {
929  return false;
930 }
931 
933 {
934  return mCRS;
935 }
936 
937 void QgsMapLayer::setCrs( const QgsCoordinateReferenceSystem &srs, bool emitSignal )
938 {
939  mCRS = srs;
940 
942  {
943  mCRS.setValidationHint( tr( "Specify CRS for layer %1" ).arg( name() ) );
944  mCRS.validate();
945  }
946 
947  if ( emitSignal )
948  emit crsChanged();
949 }
950 
952 {
953  const QgsDataProvider *lDataProvider = dataProvider();
954  return lDataProvider ? lDataProvider->transformContext() : QgsCoordinateTransformContext();
955 }
956 
957 QString QgsMapLayer::formatLayerName( const QString &name )
958 {
959  QString layerName( name );
960  layerName.replace( '_', ' ' );
962  return layerName;
963 }
964 
965 QString QgsMapLayer::baseURI( PropertyType type ) const
966 {
967  QString myURI = publicSource();
968 
969  // first get base path for delimited text, spatialite and OGR layers,
970  // as in these cases URI may contain layer name and/or additional
971  // information. This also strips prefix in case if VSIFILE mechanism
972  // is used
973  if ( providerType() == QLatin1String( "ogr" ) || providerType() == QLatin1String( "delimitedtext" )
974  || providerType() == QLatin1String( "gdal" ) || providerType() == QLatin1String( "spatialite" ) )
975  {
976  QVariantMap components = QgsProviderRegistry::instance()->decodeUri( providerType(), myURI );
977  myURI = components["path"].toString();
978  }
979 
980  QFileInfo myFileInfo( myURI );
981  QString key;
982 
983  if ( myFileInfo.exists() )
984  {
985  // if file is using the /vsizip/ or /vsigzip/ mechanism, cleanup the name
986  if ( myURI.endsWith( QLatin1String( ".gz" ), Qt::CaseInsensitive ) )
987  myURI.chop( 3 );
988  else if ( myURI.endsWith( QLatin1String( ".zip" ), Qt::CaseInsensitive ) )
989  myURI.chop( 4 );
990  else if ( myURI.endsWith( QLatin1String( ".tar" ), Qt::CaseInsensitive ) )
991  myURI.chop( 4 );
992  else if ( myURI.endsWith( QLatin1String( ".tar.gz" ), Qt::CaseInsensitive ) )
993  myURI.chop( 7 );
994  else if ( myURI.endsWith( QLatin1String( ".tgz" ), Qt::CaseInsensitive ) )
995  myURI.chop( 4 );
996  myFileInfo.setFile( myURI );
997  // get the file name for our .qml style file
998  key = myFileInfo.path() + QDir::separator() + myFileInfo.completeBaseName() + QgsMapLayer::extensionPropertyType( type );
999  }
1000  else
1001  {
1002  key = publicSource();
1003  }
1004 
1005  return key;
1006 }
1007 
1009 {
1010  return baseURI( PropertyType::Metadata );
1011 }
1012 
1013 QString QgsMapLayer::saveDefaultMetadata( bool &resultFlag )
1014 {
1015  if ( const QgsProviderMetadata *metadata = QgsProviderRegistry::instance()->providerMetadata( providerType() ) )
1016  {
1017  if ( metadata->providerCapabilities() & QgsProviderMetadata::SaveLayerMetadata )
1018  {
1019  try
1020  {
1021  QString errorMessage;
1022  resultFlag = QgsProviderRegistry::instance()->saveLayerMetadata( providerType(), mDataSource, mMetadata, errorMessage );
1023  if ( resultFlag )
1024  return tr( "Successfully saved default layer metadata" );
1025  else
1026  return errorMessage;
1027  }
1028  catch ( QgsNotSupportedException &e )
1029  {
1030  resultFlag = false;
1031  return e.what();
1032  }
1033  }
1034  }
1035 
1036  // fallback default metadata saving method, for providers which don't support (or implement) saveLayerMetadata
1037  return saveNamedMetadata( metadataUri(), resultFlag );
1038 }
1039 
1040 QString QgsMapLayer::loadDefaultMetadata( bool &resultFlag )
1041 {
1042  return loadNamedMetadata( metadataUri(), resultFlag );
1043 }
1044 
1045 QString QgsMapLayer::styleURI() const
1046 {
1047  return baseURI( PropertyType::Style );
1048 }
1049 
1050 QString QgsMapLayer::loadDefaultStyle( bool &resultFlag )
1051 {
1052  return loadNamedStyle( styleURI(), resultFlag );
1053 }
1054 
1055 bool QgsMapLayer::loadNamedMetadataFromDatabase( const QString &db, const QString &uri, QString &qmd )
1056 {
1057  return loadNamedPropertyFromDatabase( db, uri, qmd, PropertyType::Metadata );
1058 }
1059 
1060 bool QgsMapLayer::loadNamedStyleFromDatabase( const QString &db, const QString &uri, QString &qml )
1061 {
1062  return loadNamedPropertyFromDatabase( db, uri, qml, PropertyType::Style );
1063 }
1064 
1065 bool QgsMapLayer::loadNamedPropertyFromDatabase( const QString &db, const QString &uri, QString &xml, QgsMapLayer::PropertyType type )
1066 {
1067  QgsDebugMsgLevel( QStringLiteral( "db = %1 uri = %2" ).arg( db, uri ), 4 );
1068 
1069  bool resultFlag = false;
1070 
1071  // read from database
1072  sqlite3_database_unique_ptr database;
1073  sqlite3_statement_unique_ptr statement;
1074 
1075  int myResult;
1076 
1077  QgsDebugMsgLevel( QStringLiteral( "Trying to load style or metadata for \"%1\" from \"%2\"" ).arg( uri, db ), 4 );
1078 
1079  if ( db.isEmpty() || !QFile( db ).exists() )
1080  return false;
1081 
1082  myResult = database.open_v2( db, SQLITE_OPEN_READONLY, nullptr );
1083  if ( myResult != SQLITE_OK )
1084  {
1085  return false;
1086  }
1087 
1088  QString mySql;
1089  switch ( type )
1090  {
1091  case Metadata:
1092  mySql = QStringLiteral( "select qmd from tbl_metadata where metadata=?" );
1093  break;
1094 
1095  case Style:
1096  mySql = QStringLiteral( "select qml from tbl_styles where style=?" );
1097  break;
1098  }
1099 
1100  statement = database.prepare( mySql, myResult );
1101  if ( myResult == SQLITE_OK )
1102  {
1103  QByteArray param = uri.toUtf8();
1104 
1105  if ( sqlite3_bind_text( statement.get(), 1, param.data(), param.length(), SQLITE_STATIC ) == SQLITE_OK &&
1106  sqlite3_step( statement.get() ) == SQLITE_ROW )
1107  {
1108  xml = QString::fromUtf8( reinterpret_cast< const char * >( sqlite3_column_text( statement.get(), 0 ) ) );
1109  resultFlag = true;
1110  }
1111  }
1112  return resultFlag;
1113 }
1114 
1115 
1116 QString QgsMapLayer::loadNamedStyle( const QString &uri, bool &resultFlag, QgsMapLayer::StyleCategories categories )
1117 {
1118  return loadNamedProperty( uri, PropertyType::Style, resultFlag, categories );
1119 }
1120 
1121 QString QgsMapLayer::loadNamedProperty( const QString &uri, QgsMapLayer::PropertyType type, bool &resultFlag, StyleCategories categories )
1122 {
1123  QgsDebugMsgLevel( QStringLiteral( "uri = %1 myURI = %2" ).arg( uri, publicSource() ), 4 );
1124 
1125  resultFlag = false;
1126  if ( uri.isEmpty() )
1127  return QString();
1128 
1129  QDomDocument myDocument( QStringLiteral( "qgis" ) );
1130 
1131  // location of problem associated with errorMsg
1132  int line, column;
1133  QString myErrorMessage;
1134 
1135  QFile myFile( uri );
1136  if ( myFile.open( QFile::ReadOnly ) )
1137  {
1138  QgsDebugMsgLevel( QStringLiteral( "file found %1" ).arg( uri ), 2 );
1139  // read file
1140  resultFlag = myDocument.setContent( &myFile, &myErrorMessage, &line, &column );
1141  if ( !resultFlag )
1142  myErrorMessage = tr( "%1 at line %2 column %3" ).arg( myErrorMessage ).arg( line ).arg( column );
1143  myFile.close();
1144  }
1145  else
1146  {
1147  const QFileInfo project( QgsProject::instance()->fileName() );
1148  QgsDebugMsgLevel( QStringLiteral( "project fileName: %1" ).arg( project.absoluteFilePath() ), 4 );
1149 
1150  QString xml;
1151  switch ( type )
1152  {
1153  case QgsMapLayer::Style:
1154  {
1155  if ( loadNamedStyleFromDatabase( QDir( QgsApplication::qgisSettingsDirPath() ).absoluteFilePath( QStringLiteral( "qgis.qmldb" ) ), uri, xml ) ||
1156  ( project.exists() && loadNamedStyleFromDatabase( project.absoluteDir().absoluteFilePath( project.baseName() + ".qmldb" ), uri, xml ) ) ||
1157  loadNamedStyleFromDatabase( QDir( QgsApplication::pkgDataPath() ).absoluteFilePath( QStringLiteral( "resources/qgis.qmldb" ) ), uri, xml ) )
1158  {
1159  resultFlag = myDocument.setContent( xml, &myErrorMessage, &line, &column );
1160  if ( !resultFlag )
1161  {
1162  myErrorMessage = tr( "%1 at line %2 column %3" ).arg( myErrorMessage ).arg( line ).arg( column );
1163  }
1164  }
1165  else
1166  {
1167  myErrorMessage = tr( "Style not found in database" );
1168  resultFlag = false;
1169  }
1170  break;
1171  }
1172  case QgsMapLayer::Metadata:
1173  {
1174  if ( loadNamedMetadataFromDatabase( QDir( QgsApplication::qgisSettingsDirPath() ).absoluteFilePath( QStringLiteral( "qgis.qmldb" ) ), uri, xml ) ||
1175  ( project.exists() && loadNamedMetadataFromDatabase( project.absoluteDir().absoluteFilePath( project.baseName() + ".qmldb" ), uri, xml ) ) ||
1176  loadNamedMetadataFromDatabase( QDir( QgsApplication::pkgDataPath() ).absoluteFilePath( QStringLiteral( "resources/qgis.qmldb" ) ), uri, xml ) )
1177  {
1178  resultFlag = myDocument.setContent( xml, &myErrorMessage, &line, &column );
1179  if ( !resultFlag )
1180  {
1181  myErrorMessage = tr( "%1 at line %2 column %3" ).arg( myErrorMessage ).arg( line ).arg( column );
1182  }
1183  }
1184  else
1185  {
1186  myErrorMessage = tr( "Metadata not found in database" );
1187  resultFlag = false;
1188  }
1189  break;
1190  }
1191  }
1192  }
1193 
1194  if ( !resultFlag )
1195  {
1196  return myErrorMessage;
1197  }
1198 
1199  switch ( type )
1200  {
1201  case QgsMapLayer::Style:
1202  resultFlag = importNamedStyle( myDocument, myErrorMessage, categories );
1203  if ( !resultFlag )
1204  myErrorMessage = tr( "Loading style file %1 failed because:\n%2" ).arg( uri, myErrorMessage );
1205  break;
1206  case QgsMapLayer::Metadata:
1207  resultFlag = importNamedMetadata( myDocument, myErrorMessage );
1208  if ( !resultFlag )
1209  myErrorMessage = tr( "Loading metadata file %1 failed because:\n%2" ).arg( uri, myErrorMessage );
1210  break;
1211  }
1212  return myErrorMessage;
1213 }
1214 
1215 bool QgsMapLayer::importNamedMetadata( QDomDocument &document, QString &errorMessage )
1216 {
1217  const QDomElement myRoot = document.firstChildElement( QStringLiteral( "qgis" ) );
1218  if ( myRoot.isNull() )
1219  {
1220  errorMessage = tr( "Root <qgis> element could not be found" );
1221  return false;
1222  }
1223 
1224  return mMetadata.readMetadataXml( myRoot );
1225 }
1226 
1227 bool QgsMapLayer::importNamedStyle( QDomDocument &myDocument, QString &myErrorMessage, QgsMapLayer::StyleCategories categories )
1228 {
1229  const QDomElement myRoot = myDocument.firstChildElement( QStringLiteral( "qgis" ) );
1230  if ( myRoot.isNull() )
1231  {
1232  myErrorMessage = tr( "Root <qgis> element could not be found" );
1233  return false;
1234  }
1235 
1236  // get style file version string, if any
1237  const QgsProjectVersion fileVersion( myRoot.attribute( QStringLiteral( "version" ) ) );
1238  const QgsProjectVersion thisVersion( Qgis::version() );
1239 
1240  if ( thisVersion > fileVersion )
1241  {
1242  QgsProjectFileTransform styleFile( myDocument, fileVersion );
1243  styleFile.updateRevision( thisVersion );
1244  }
1245 
1246  // Get source categories
1247  const QgsMapLayer::StyleCategories sourceCategories = QgsXmlUtils::readFlagAttribute( myRoot, QStringLiteral( "styleCategories" ), QgsMapLayer::AllStyleCategories );
1248 
1249  //Test for matching geometry type on vector layers when applying, if geometry type is given in the style
1250  if ( ( sourceCategories.testFlag( QgsMapLayer::Symbology ) || sourceCategories.testFlag( QgsMapLayer::Symbology3D ) ) &&
1251  ( categories.testFlag( QgsMapLayer::Symbology ) || categories.testFlag( QgsMapLayer::Symbology3D ) ) )
1252  {
1253  if ( type() == QgsMapLayerType::VectorLayer && !myRoot.firstChildElement( QStringLiteral( "layerGeometryType" ) ).isNull() )
1254  {
1255  QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( this );
1256  const QgsWkbTypes::GeometryType importLayerGeometryType = static_cast<QgsWkbTypes::GeometryType>( myRoot.firstChildElement( QStringLiteral( "layerGeometryType" ) ).text().toInt() );
1257  if ( importLayerGeometryType != QgsWkbTypes::GeometryType::UnknownGeometry && vl->geometryType() != importLayerGeometryType )
1258  {
1259  myErrorMessage = tr( "Cannot apply style with symbology to layer with a different geometry type" );
1260  return false;
1261  }
1262  }
1263  }
1264 
1266  return readSymbology( myRoot, myErrorMessage, context, categories ); // TODO: support relative paths in QML?
1267 }
1268 
1269 void QgsMapLayer::exportNamedMetadata( QDomDocument &doc, QString &errorMsg ) const
1270 {
1271  QDomImplementation DomImplementation;
1272  const QDomDocumentType documentType = DomImplementation.createDocumentType( QStringLiteral( "qgis" ), QStringLiteral( "http://mrcc.com/qgis.dtd" ), QStringLiteral( "SYSTEM" ) );
1273  QDomDocument myDocument( documentType );
1274 
1275  QDomElement myRootNode = myDocument.createElement( QStringLiteral( "qgis" ) );
1276  myRootNode.setAttribute( QStringLiteral( "version" ), Qgis::version() );
1277  myDocument.appendChild( myRootNode );
1278 
1279  if ( !mMetadata.writeMetadataXml( myRootNode, myDocument ) )
1280  {
1281  errorMsg = QObject::tr( "Could not save metadata" );
1282  return;
1283  }
1284 
1285  doc = myDocument;
1286 }
1287 
1288 void QgsMapLayer::exportNamedStyle( QDomDocument &doc, QString &errorMsg, const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories ) const
1289 {
1290  QDomImplementation DomImplementation;
1291  const QDomDocumentType documentType = DomImplementation.createDocumentType( QStringLiteral( "qgis" ), QStringLiteral( "http://mrcc.com/qgis.dtd" ), QStringLiteral( "SYSTEM" ) );
1292  QDomDocument myDocument( documentType );
1293 
1294  QDomElement myRootNode = myDocument.createElement( QStringLiteral( "qgis" ) );
1295  myRootNode.setAttribute( QStringLiteral( "version" ), Qgis::version() );
1296  myDocument.appendChild( myRootNode );
1297 
1298  if ( !writeSymbology( myRootNode, myDocument, errorMsg, context, categories ) ) // TODO: support relative paths in QML?
1299  {
1300  errorMsg = QObject::tr( "Could not save symbology because:\n%1" ).arg( errorMsg );
1301  return;
1302  }
1303 
1304  /*
1305  * Check to see if the layer is vector - in which case we should also export its geometryType
1306  * to avoid eventually pasting to a layer with a different geometry
1307  */
1309  {
1310  //Getting the selectionLayer geometry
1311  const QgsVectorLayer *vl = qobject_cast<const QgsVectorLayer *>( this );
1312  const QString geoType = QString::number( vl->geometryType() );
1313 
1314  //Adding geometryinformation
1315  QDomElement layerGeometryType = myDocument.createElement( QStringLiteral( "layerGeometryType" ) );
1316  const QDomText type = myDocument.createTextNode( geoType );
1317 
1318  layerGeometryType.appendChild( type );
1319  myRootNode.appendChild( layerGeometryType );
1320  }
1321 
1322  doc = myDocument;
1323 }
1324 
1325 QString QgsMapLayer::saveDefaultStyle( bool &resultFlag )
1326 {
1327  return saveDefaultStyle( resultFlag, AllStyleCategories );
1328 }
1329 
1330 QString QgsMapLayer::saveDefaultStyle( bool &resultFlag, StyleCategories categories )
1331 {
1332  return saveNamedStyle( styleURI(), resultFlag, categories );
1333 }
1334 
1335 QString QgsMapLayer::saveNamedMetadata( const QString &uri, bool &resultFlag )
1336 {
1337  return saveNamedProperty( uri, QgsMapLayer::Metadata, resultFlag );
1338 }
1339 
1340 QString QgsMapLayer::loadNamedMetadata( const QString &uri, bool &resultFlag )
1341 {
1342  return loadNamedProperty( uri, QgsMapLayer::Metadata, resultFlag );
1343 }
1344 
1345 QString QgsMapLayer::saveNamedProperty( const QString &uri, QgsMapLayer::PropertyType type, bool &resultFlag, StyleCategories categories )
1346 {
1347  // check if the uri is a file or ends with .qml/.qmd,
1348  // which indicates that it should become one
1349  // everything else goes to the database
1350  QString filename;
1351 
1352  QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( this );
1353  if ( vlayer && vlayer->providerType() == QLatin1String( "ogr" ) )
1354  {
1355  QStringList theURIParts = uri.split( '|' );
1356  filename = theURIParts[0];
1357  }
1358  else if ( vlayer && vlayer->providerType() == QLatin1String( "gpx" ) )
1359  {
1360  QStringList theURIParts = uri.split( '?' );
1361  filename = theURIParts[0];
1362  }
1363  else if ( vlayer && vlayer->providerType() == QLatin1String( "delimitedtext" ) )
1364  {
1365  filename = QUrl::fromEncoded( uri.toLatin1() ).toLocalFile();
1366  // toLocalFile() returns an empty string if theURI is a plain Windows-path, e.g. "C:/style.qml"
1367  if ( filename.isEmpty() )
1368  filename = uri;
1369  }
1370  else
1371  {
1372  filename = uri;
1373  }
1374 
1375  QString myErrorMessage;
1376  QDomDocument myDocument;
1377  switch ( type )
1378  {
1379  case Metadata:
1380  exportNamedMetadata( myDocument, myErrorMessage );
1381  break;
1382 
1383  case Style:
1384  const QgsReadWriteContext context;
1385  exportNamedStyle( myDocument, myErrorMessage, context, categories );
1386  break;
1387  }
1388 
1389  const QFileInfo myFileInfo( filename );
1390  if ( myFileInfo.exists() || filename.endsWith( QgsMapLayer::extensionPropertyType( type ), Qt::CaseInsensitive ) )
1391  {
1392  const QFileInfo myDirInfo( myFileInfo.path() ); //excludes file name
1393  if ( !myDirInfo.isWritable() )
1394  {
1395  return tr( "The directory containing your dataset needs to be writable!" );
1396  }
1397 
1398  // now construct the file name for our .qml or .qmd file
1399  const QString myFileName = myFileInfo.path() + QDir::separator() + myFileInfo.completeBaseName() + QgsMapLayer::extensionPropertyType( type );
1400 
1401  QFile myFile( myFileName );
1402  if ( myFile.open( QFile::WriteOnly | QFile::Truncate ) )
1403  {
1404  QTextStream myFileStream( &myFile );
1405  // save as utf-8 with 2 spaces for indents
1406  myDocument.save( myFileStream, 2 );
1407  myFile.close();
1408  resultFlag = true;
1409  switch ( type )
1410  {
1411  case Metadata:
1412  return tr( "Created default metadata file as %1" ).arg( myFileName );
1413 
1414  case Style:
1415  return tr( "Created default style file as %1" ).arg( myFileName );
1416  }
1417 
1418  }
1419  else
1420  {
1421  resultFlag = false;
1422  switch ( type )
1423  {
1424  case Metadata:
1425  return tr( "ERROR: Failed to created default metadata file as %1. Check file permissions and retry." ).arg( myFileName );
1426 
1427  case Style:
1428  return tr( "ERROR: Failed to created default style file as %1. Check file permissions and retry." ).arg( myFileName );
1429  }
1430  }
1431  }
1432  else
1433  {
1434  const QString qml = myDocument.toString();
1435 
1436  // read from database
1437  sqlite3_database_unique_ptr database;
1438  sqlite3_statement_unique_ptr statement;
1439 
1440  int myResult = database.open( QDir( QgsApplication::qgisSettingsDirPath() ).absoluteFilePath( QStringLiteral( "qgis.qmldb" ) ) );
1441  if ( myResult != SQLITE_OK )
1442  {
1443  return tr( "User database could not be opened." );
1444  }
1445 
1446  QByteArray param0 = uri.toUtf8();
1447  QByteArray param1 = qml.toUtf8();
1448 
1449  QString mySql;
1450  switch ( type )
1451  {
1452  case Metadata:
1453  mySql = QStringLiteral( "create table if not exists tbl_metadata(metadata varchar primary key,qmd varchar)" );
1454  break;
1455 
1456  case Style:
1457  mySql = QStringLiteral( "create table if not exists tbl_styles(style varchar primary key,qml varchar)" );
1458  break;
1459  }
1460 
1461  statement = database.prepare( mySql, myResult );
1462  if ( myResult == SQLITE_OK )
1463  {
1464  if ( sqlite3_step( statement.get() ) != SQLITE_DONE )
1465  {
1466  resultFlag = false;
1467  switch ( type )
1468  {
1469  case Metadata:
1470  return tr( "The metadata table could not be created." );
1471 
1472  case Style:
1473  return tr( "The style table could not be created." );
1474  }
1475  }
1476  }
1477 
1478  switch ( type )
1479  {
1480  case Metadata:
1481  mySql = QStringLiteral( "insert into tbl_metadata(metadata,qmd) values (?,?)" );
1482  break;
1483 
1484  case Style:
1485  mySql = QStringLiteral( "insert into tbl_styles(style,qml) values (?,?)" );
1486  break;
1487  }
1488  statement = database.prepare( mySql, myResult );
1489  if ( myResult == SQLITE_OK )
1490  {
1491  if ( sqlite3_bind_text( statement.get(), 1, param0.data(), param0.length(), SQLITE_STATIC ) == SQLITE_OK &&
1492  sqlite3_bind_text( statement.get(), 2, param1.data(), param1.length(), SQLITE_STATIC ) == SQLITE_OK &&
1493  sqlite3_step( statement.get() ) == SQLITE_DONE )
1494  {
1495  resultFlag = true;
1496  switch ( type )
1497  {
1498  case Metadata:
1499  myErrorMessage = tr( "The metadata %1 was saved to database" ).arg( uri );
1500  break;
1501 
1502  case Style:
1503  myErrorMessage = tr( "The style %1 was saved to database" ).arg( uri );
1504  break;
1505  }
1506  }
1507  }
1508 
1509  if ( !resultFlag )
1510  {
1511  QString mySql;
1512  switch ( type )
1513  {
1514  case Metadata:
1515  mySql = QStringLiteral( "update tbl_metadata set qmd=? where metadata=?" );
1516  break;
1517 
1518  case Style:
1519  mySql = QStringLiteral( "update tbl_styles set qml=? where style=?" );
1520  break;
1521  }
1522  statement = database.prepare( mySql, myResult );
1523  if ( myResult == SQLITE_OK )
1524  {
1525  if ( sqlite3_bind_text( statement.get(), 2, param0.data(), param0.length(), SQLITE_STATIC ) == SQLITE_OK &&
1526  sqlite3_bind_text( statement.get(), 1, param1.data(), param1.length(), SQLITE_STATIC ) == SQLITE_OK &&
1527  sqlite3_step( statement.get() ) == SQLITE_DONE )
1528  {
1529  resultFlag = true;
1530  switch ( type )
1531  {
1532  case Metadata:
1533  myErrorMessage = tr( "The metadata %1 was updated in the database." ).arg( uri );
1534  break;
1535 
1536  case Style:
1537  myErrorMessage = tr( "The style %1 was updated in the database." ).arg( uri );
1538  break;
1539  }
1540  }
1541  else
1542  {
1543  resultFlag = false;
1544  switch ( type )
1545  {
1546  case Metadata:
1547  myErrorMessage = tr( "The metadata %1 could not be updated in the database." ).arg( uri );
1548  break;
1549 
1550  case Style:
1551  myErrorMessage = tr( "The style %1 could not be updated in the database." ).arg( uri );
1552  break;
1553  }
1554  }
1555  }
1556  else
1557  {
1558  resultFlag = false;
1559  switch ( type )
1560  {
1561  case Metadata:
1562  myErrorMessage = tr( "The metadata %1 could not be inserted into database." ).arg( uri );
1563  break;
1564 
1565  case Style:
1566  myErrorMessage = tr( "The style %1 could not be inserted into database." ).arg( uri );
1567  break;
1568  }
1569  }
1570  }
1571  }
1572 
1573  return myErrorMessage;
1574 }
1575 
1576 QString QgsMapLayer::saveNamedStyle( const QString &uri, bool &resultFlag, StyleCategories categories )
1577 {
1578  return saveNamedProperty( uri, QgsMapLayer::Style, resultFlag, categories );
1579 }
1580 
1581 void QgsMapLayer::exportSldStyle( QDomDocument &doc, QString &errorMsg ) const
1582 {
1583  QDomDocument myDocument = QDomDocument();
1584 
1585  const QDomNode header = myDocument.createProcessingInstruction( QStringLiteral( "xml" ), QStringLiteral( "version=\"1.0\" encoding=\"UTF-8\"" ) );
1586  myDocument.appendChild( header );
1587 
1588  const QgsVectorLayer *vlayer = qobject_cast<const QgsVectorLayer *>( this );
1589  const QgsRasterLayer *rlayer = qobject_cast<const QgsRasterLayer *>( this );
1590  if ( !vlayer && !rlayer )
1591  {
1592  errorMsg = tr( "Could not save symbology because:\n%1" )
1593  .arg( tr( "Only vector and raster layers are supported" ) );
1594  return;
1595  }
1596 
1597  // Create the root element
1598  QDomElement root = myDocument.createElementNS( QStringLiteral( "http://www.opengis.net/sld" ), QStringLiteral( "StyledLayerDescriptor" ) );
1599  QDomElement layerNode;
1600  if ( vlayer )
1601  {
1602  root.setAttribute( QStringLiteral( "version" ), QStringLiteral( "1.1.0" ) );
1603  root.setAttribute( QStringLiteral( "xsi:schemaLocation" ), QStringLiteral( "http://www.opengis.net/sld http://schemas.opengis.net/sld/1.1.0/StyledLayerDescriptor.xsd" ) );
1604  root.setAttribute( QStringLiteral( "xmlns:ogc" ), QStringLiteral( "http://www.opengis.net/ogc" ) );
1605  root.setAttribute( QStringLiteral( "xmlns:se" ), QStringLiteral( "http://www.opengis.net/se" ) );
1606  root.setAttribute( QStringLiteral( "xmlns:xlink" ), QStringLiteral( "http://www.w3.org/1999/xlink" ) );
1607  root.setAttribute( QStringLiteral( "xmlns:xsi" ), QStringLiteral( "http://www.w3.org/2001/XMLSchema-instance" ) );
1608  myDocument.appendChild( root );
1609 
1610  // Create the NamedLayer element
1611  layerNode = myDocument.createElement( QStringLiteral( "NamedLayer" ) );
1612  root.appendChild( layerNode );
1613  }
1614 
1615  // note: Only SLD 1.0 version is generated because seems none is using SE1.1.0 at least for rasters
1616  if ( rlayer )
1617  {
1618  // Create the root element
1619  root.setAttribute( QStringLiteral( "version" ), QStringLiteral( "1.0.0" ) );
1620  root.setAttribute( QStringLiteral( "xmlns:gml" ), QStringLiteral( "http://www.opengis.net/gml" ) );
1621  root.setAttribute( QStringLiteral( "xmlns:ogc" ), QStringLiteral( "http://www.opengis.net/ogc" ) );
1622  root.setAttribute( QStringLiteral( "xmlns:sld" ), QStringLiteral( "http://www.opengis.net/sld" ) );
1623  myDocument.appendChild( root );
1624 
1625  // Create the NamedLayer element
1626  layerNode = myDocument.createElement( QStringLiteral( "UserLayer" ) );
1627  root.appendChild( layerNode );
1628  }
1629 
1630  QVariantMap props;
1631  if ( hasScaleBasedVisibility() )
1632  {
1633  props[ QStringLiteral( "scaleMinDenom" ) ] = QString::number( mMinScale );
1634  props[ QStringLiteral( "scaleMaxDenom" ) ] = QString::number( mMaxScale );
1635  }
1636 
1637  if ( vlayer )
1638  {
1639  if ( !vlayer->writeSld( layerNode, myDocument, errorMsg, props ) )
1640  {
1641  errorMsg = tr( "Could not save symbology because:\n%1" ).arg( errorMsg );
1642  return;
1643  }
1644  }
1645 
1646  if ( rlayer )
1647  {
1648  if ( !rlayer->writeSld( layerNode, myDocument, errorMsg, props ) )
1649  {
1650  errorMsg = tr( "Could not save symbology because:\n%1" ).arg( errorMsg );
1651  return;
1652  }
1653  }
1654 
1655  doc = myDocument;
1656 }
1657 
1658 QString QgsMapLayer::saveSldStyle( const QString &uri, bool &resultFlag ) const
1659 {
1660  const QgsMapLayer *mlayer = qobject_cast<const QgsMapLayer *>( this );
1661 
1662  QString errorMsg;
1663  QDomDocument myDocument;
1664  mlayer->exportSldStyle( myDocument, errorMsg );
1665  if ( !errorMsg.isNull() )
1666  {
1667  resultFlag = false;
1668  return errorMsg;
1669  }
1670  // check if the uri is a file or ends with .sld,
1671  // which indicates that it should become one
1672  QString filename;
1673  if ( mlayer->providerType() == QLatin1String( "ogr" ) )
1674  {
1675  QStringList theURIParts = uri.split( '|' );
1676  filename = theURIParts[0];
1677  }
1678  else if ( mlayer->providerType() == QLatin1String( "gpx" ) )
1679  {
1680  QStringList theURIParts = uri.split( '?' );
1681  filename = theURIParts[0];
1682  }
1683  else if ( mlayer->providerType() == QLatin1String( "delimitedtext" ) )
1684  {
1685  filename = QUrl::fromEncoded( uri.toLatin1() ).toLocalFile();
1686  // toLocalFile() returns an empty string if theURI is a plain Windows-path, e.g. "C:/style.qml"
1687  if ( filename.isEmpty() )
1688  filename = uri;
1689  }
1690  else
1691  {
1692  filename = uri;
1693  }
1694 
1695  const QFileInfo myFileInfo( filename );
1696  if ( myFileInfo.exists() || filename.endsWith( QLatin1String( ".sld" ), Qt::CaseInsensitive ) )
1697  {
1698  const QFileInfo myDirInfo( myFileInfo.path() ); //excludes file name
1699  if ( !myDirInfo.isWritable() )
1700  {
1701  return tr( "The directory containing your dataset needs to be writable!" );
1702  }
1703 
1704  // now construct the file name for our .sld style file
1705  const QString myFileName = myFileInfo.path() + QDir::separator() + myFileInfo.completeBaseName() + ".sld";
1706 
1707  QFile myFile( myFileName );
1708  if ( myFile.open( QFile::WriteOnly | QFile::Truncate ) )
1709  {
1710  QTextStream myFileStream( &myFile );
1711  // save as utf-8 with 2 spaces for indents
1712  myDocument.save( myFileStream, 2 );
1713  myFile.close();
1714  resultFlag = true;
1715  return tr( "Created default style file as %1" ).arg( myFileName );
1716  }
1717  }
1718 
1719  resultFlag = false;
1720  return tr( "ERROR: Failed to created SLD style file as %1. Check file permissions and retry." ).arg( filename );
1721 }
1722 
1723 QString QgsMapLayer::loadSldStyle( const QString &uri, bool &resultFlag )
1724 {
1725  resultFlag = false;
1726 
1727  QDomDocument myDocument;
1728 
1729  // location of problem associated with errorMsg
1730  int line, column;
1731  QString myErrorMessage;
1732 
1733  QFile myFile( uri );
1734  if ( myFile.open( QFile::ReadOnly ) )
1735  {
1736  // read file
1737  resultFlag = myDocument.setContent( &myFile, true, &myErrorMessage, &line, &column );
1738  if ( !resultFlag )
1739  myErrorMessage = tr( "%1 at line %2 column %3" ).arg( myErrorMessage ).arg( line ).arg( column );
1740  myFile.close();
1741  }
1742  else
1743  {
1744  myErrorMessage = tr( "Unable to open file %1" ).arg( uri );
1745  }
1746 
1747  if ( !resultFlag )
1748  {
1749  return myErrorMessage;
1750  }
1751 
1752  // check for root SLD element
1753  const QDomElement myRoot = myDocument.firstChildElement( QStringLiteral( "StyledLayerDescriptor" ) );
1754  if ( myRoot.isNull() )
1755  {
1756  myErrorMessage = QStringLiteral( "Error: StyledLayerDescriptor element not found in %1" ).arg( uri );
1757  resultFlag = false;
1758  return myErrorMessage;
1759  }
1760 
1761  // now get the style node out and pass it over to the layer
1762  // to deserialise...
1763  const QDomElement namedLayerElem = myRoot.firstChildElement( QStringLiteral( "NamedLayer" ) );
1764  if ( namedLayerElem.isNull() )
1765  {
1766  myErrorMessage = QStringLiteral( "Info: NamedLayer element not found." );
1767  resultFlag = false;
1768  return myErrorMessage;
1769  }
1770 
1771  QString errorMsg;
1772  resultFlag = readSld( namedLayerElem, errorMsg );
1773  if ( !resultFlag )
1774  {
1775  myErrorMessage = tr( "Loading style file %1 failed because:\n%2" ).arg( uri, errorMsg );
1776  return myErrorMessage;
1777  }
1778 
1779  return QString();
1780 }
1781 
1782 bool QgsMapLayer::readStyle( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories )
1783 {
1784  Q_UNUSED( node )
1785  Q_UNUSED( errorMessage )
1786  Q_UNUSED( context )
1787  Q_UNUSED( categories )
1788  return false;
1789 }
1790 
1791 bool QgsMapLayer::writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage,
1792  const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories ) const
1793 {
1794  Q_UNUSED( node )
1795  Q_UNUSED( doc )
1796  Q_UNUSED( errorMessage )
1797  Q_UNUSED( context )
1798  Q_UNUSED( categories )
1799  return false;
1800 }
1801 
1802 
1803 void QgsMapLayer::setDataSource( const QString &dataSource, const QString &baseName, const QString &provider,
1804  bool loadDefaultStyleFlag )
1805 {
1806  const QgsDataProvider::ProviderOptions options;
1807 
1808  QgsDataProvider::ReadFlags flags = QgsDataProvider::ReadFlags();
1809  if ( loadDefaultStyleFlag )
1810  {
1812  }
1813 
1815  {
1817  }
1818  setDataSource( dataSource, baseName, provider, options, flags );
1819 }
1820 
1821 void QgsMapLayer::setDataSource( const QString &dataSource, const QString &baseName, const QString &provider,
1822  const QgsDataProvider::ProviderOptions &options, bool loadDefaultStyleFlag )
1823 {
1824  QgsDataProvider::ReadFlags flags = QgsDataProvider::ReadFlags();
1825  if ( loadDefaultStyleFlag )
1826  {
1828  }
1829 
1831  {
1833  }
1834  setDataSource( dataSource, baseName, provider, options, flags );
1835 }
1836 
1837 void QgsMapLayer::setDataSource( const QString &dataSource, const QString &baseName, const QString &provider,
1838  const QgsDataProvider::ProviderOptions &options, QgsDataProvider::ReadFlags flags )
1839 {
1840 
1843  {
1845  }
1846  setDataSourcePrivate( dataSource, baseName, provider, options, flags );
1847  emit dataSourceChanged();
1848  emit dataChanged();
1849  triggerRepaint();
1850 }
1851 
1852 
1853 void QgsMapLayer::setDataSourcePrivate( const QString &dataSource, const QString &baseName, const QString &provider,
1854  const QgsDataProvider::ProviderOptions &options, QgsDataProvider::ReadFlags flags )
1855 {
1856  Q_UNUSED( dataSource )
1857  Q_UNUSED( baseName )
1858  Q_UNUSED( provider )
1859  Q_UNUSED( options )
1860  Q_UNUSED( flags )
1861 }
1862 
1863 
1865 {
1866  return mProviderKey;
1867 }
1868 
1869 void QgsMapLayer::readCommonStyle( const QDomElement &layerElement, const QgsReadWriteContext &context,
1870  QgsMapLayer::StyleCategories categories )
1871 {
1872  if ( categories.testFlag( Symbology3D ) )
1873  {
1874  const QgsReadWriteContextCategoryPopper p = context.enterCategory( tr( "3D Symbology" ) );
1875 
1876  QgsAbstract3DRenderer *r3D = nullptr;
1877  QDomElement renderer3DElem = layerElement.firstChildElement( QStringLiteral( "renderer-3d" ) );
1878  if ( !renderer3DElem.isNull() )
1879  {
1880  const QString type3D = renderer3DElem.attribute( QStringLiteral( "type" ) );
1882  if ( meta3D )
1883  {
1884  r3D = meta3D->createRenderer( renderer3DElem, context );
1885  }
1886  }
1887  setRenderer3D( r3D );
1888  }
1889 
1890  if ( categories.testFlag( CustomProperties ) )
1891  {
1892  // read custom properties before passing reading further to a subclass, so that
1893  // the subclass can also read custom properties
1894  readCustomProperties( layerElement );
1895  }
1896 
1897  // use scale dependent visibility flag
1898  if ( categories.testFlag( Rendering ) )
1899  {
1900  setScaleBasedVisibility( layerElement.attribute( QStringLiteral( "hasScaleBasedVisibilityFlag" ) ).toInt() == 1 );
1901  if ( layerElement.hasAttribute( QStringLiteral( "minimumScale" ) ) )
1902  {
1903  // older element, when scales were reversed
1904  setMaximumScale( layerElement.attribute( QStringLiteral( "minimumScale" ) ).toDouble() );
1905  setMinimumScale( layerElement.attribute( QStringLiteral( "maximumScale" ) ).toDouble() );
1906  }
1907  else
1908  {
1909  setMaximumScale( layerElement.attribute( QStringLiteral( "maxScale" ) ).toDouble() );
1910  setMinimumScale( layerElement.attribute( QStringLiteral( "minScale" ) ).toDouble() );
1911  }
1912  }
1913 
1914  if ( categories.testFlag( LayerConfiguration ) )
1915  {
1916  // flags
1917  const QDomElement flagsElem = layerElement.firstChildElement( QStringLiteral( "flags" ) );
1918  LayerFlags flags = mFlags;
1919  const auto enumMap = qgsEnumMap<QgsMapLayer::LayerFlag>();
1920  for ( auto it = enumMap.constBegin(); it != enumMap.constEnd(); ++it )
1921  {
1922  const QDomNode flagNode = flagsElem.namedItem( it.value() );
1923  if ( flagNode.isNull() )
1924  continue;
1925  const bool flagValue = flagNode.toElement().text() == "1" ? true : false;
1926  if ( flags.testFlag( it.key() ) && !flagValue )
1927  flags &= ~it.key();
1928  else if ( !flags.testFlag( it.key() ) && flagValue )
1929  flags |= it.key();
1930  }
1931  setFlags( flags );
1932  }
1933 
1934  if ( categories.testFlag( Temporal ) )
1935  {
1936  const QgsReadWriteContextCategoryPopper p = context.enterCategory( tr( "Temporal" ) );
1937 
1939  properties->readXml( layerElement.toElement(), context );
1940  }
1941 
1942  if ( categories.testFlag( Elevation ) )
1943  {
1944  const QgsReadWriteContextCategoryPopper p = context.enterCategory( tr( "Elevation" ) );
1945 
1947  properties->readXml( layerElement.toElement(), context );
1948  }
1949 
1950  if ( categories.testFlag( Notes ) )
1951  {
1952  const QDomElement notesElem = layerElement.firstChildElement( QStringLiteral( "userNotes" ) );
1953  if ( !notesElem.isNull() )
1954  {
1955  const QString notes = notesElem.attribute( QStringLiteral( "value" ) );
1956  QgsLayerNotesUtils::setLayerNotes( this, notes );
1957  }
1958  }
1959 }
1960 
1962 {
1963  return mUndoStack;
1964 }
1965 
1967 {
1968  return mUndoStackStyles;
1969 }
1970 
1972 {
1973  return mCustomProperties.keys();
1974 }
1975 
1976 void QgsMapLayer::setCustomProperty( const QString &key, const QVariant &value )
1977 {
1978  if ( !mCustomProperties.contains( key ) || mCustomProperties.value( key ) != value )
1979  {
1980  mCustomProperties.setValue( key, value );
1981  emit customPropertyChanged( key );
1982  }
1983 }
1984 
1986 {
1987  mCustomProperties = properties;
1988  for ( const QString &key : mCustomProperties.keys() )
1989  {
1990  emit customPropertyChanged( key );
1991  }
1992 }
1993 
1995 {
1996  return mCustomProperties;
1997 }
1998 
1999 QVariant QgsMapLayer::customProperty( const QString &value, const QVariant &defaultValue ) const
2000 {
2001  return mCustomProperties.value( value, defaultValue );
2002 }
2003 
2004 void QgsMapLayer::removeCustomProperty( const QString &key )
2005 {
2006 
2007  if ( mCustomProperties.contains( key ) )
2008  {
2009  mCustomProperties.remove( key );
2010  emit customPropertyChanged( key );
2011  }
2012 }
2013 
2015 {
2016  return mError;
2017 }
2018 
2019 
2020 
2022 {
2023  return false;
2024 }
2025 
2027 {
2028  return false;
2029 }
2030 
2032 {
2033  return true;
2034 }
2035 
2037 {
2038  // invalid layers are temporary? -- who knows?!
2039  if ( !isValid() )
2040  return false;
2041 
2042  if ( mProviderKey == QLatin1String( "memory" ) )
2043  return true;
2044 
2045  const QVariantMap sourceParts = QgsProviderRegistry::instance()->decodeUri( mProviderKey, mDataSource );
2046  const QString path = sourceParts.value( QStringLiteral( "path" ) ).toString();
2047  if ( path.isEmpty() )
2048  return false;
2049 
2050  // check if layer path is inside one of the standard temporary file locations for this platform
2051  const QStringList tempPaths = QStandardPaths::standardLocations( QStandardPaths::TempLocation );
2052  for ( const QString &tempPath : tempPaths )
2053  {
2054  if ( path.startsWith( tempPath ) )
2055  return true;
2056  }
2057 
2058  return false;
2059 }
2060 
2061 void QgsMapLayer::setValid( bool valid )
2062 {
2063  if ( mValid == valid )
2064  return;
2065 
2066  mValid = valid;
2067  emit isValidChanged();
2068 }
2069 
2071 {
2072  if ( legend == mLegend )
2073  return;
2074 
2075  delete mLegend;
2076  mLegend = legend;
2077 
2078  if ( mLegend )
2079  {
2080  mLegend->setParent( this );
2081  connect( mLegend, &QgsMapLayerLegend::itemsChanged, this, &QgsMapLayer::legendChanged, Qt::UniqueConnection );
2082  }
2083 
2084  emit legendChanged();
2085 }
2086 
2088 {
2089  return mLegend;
2090 }
2091 
2093 {
2094  return mStyleManager;
2095 }
2096 
2098 {
2099  if ( renderer == m3DRenderer )
2100  return;
2101 
2102  delete m3DRenderer;
2103  m3DRenderer = renderer;
2104  emit renderer3DChanged();
2105  emit repaintRequested();
2106  trigger3DUpdate();
2107 }
2108 
2110 {
2111  return m3DRenderer;
2112 }
2113 
2114 void QgsMapLayer::triggerRepaint( bool deferredUpdate )
2115 {
2116  if ( mRepaintRequestedFired )
2117  return;
2118  mRepaintRequestedFired = true;
2119  emit repaintRequested( deferredUpdate );
2120  mRepaintRequestedFired = false;
2121 }
2122 
2124 {
2125  emit request3DUpdate();
2126 }
2127 
2129 {
2130  mMetadata = metadata;
2131 // mMetadata.saveToLayer( this );
2132  emit metadataChanged();
2133 }
2134 
2136 {
2137  return QString();
2138 }
2139 
2140 QDateTime QgsMapLayer::timestamp() const
2141 {
2142  return QDateTime();
2143 }
2144 
2146 {
2147  if ( !mBlockStyleChangedSignal )
2148  emit styleChanged();
2149 }
2150 
2152 {
2153  updateExtent( extent );
2154 }
2155 
2156 bool QgsMapLayer::isReadOnly() const
2157 {
2158  return true;
2159 }
2160 
2162 {
2163  return mOriginalXmlProperties;
2164 }
2165 
2166 void QgsMapLayer::setOriginalXmlProperties( const QString &originalXmlProperties )
2167 {
2168  mOriginalXmlProperties = originalXmlProperties;
2169 }
2170 
2171 QString QgsMapLayer::generateId( const QString &layerName )
2172 {
2173  // Generate the unique ID of this layer
2174  const QString uuid = QUuid::createUuid().toString();
2175  // trim { } from uuid
2176  QString id = layerName + '_' + uuid.mid( 1, uuid.length() - 2 );
2177  // Tidy the ID up to avoid characters that may cause problems
2178  // elsewhere (e.g in some parts of XML). Replaces every non-word
2179  // character (word characters are the alphabet, numbers and
2180  // underscore) with an underscore.
2181  // Note that the first backslash in the regular expression is
2182  // there for the compiler, so the pattern is actually \W
2183  id.replace( QRegularExpression( "[\\W]" ), QStringLiteral( "_" ) );
2184  return id;
2185 }
2186 
2188 {
2189  return true;
2190 }
2191 
2192 void QgsMapLayer::setProviderType( const QString &providerType )
2193 {
2195 }
2196 
2197 QSet<QgsMapLayerDependency> QgsMapLayer::dependencies() const
2198 {
2199  return mDependencies;
2200 }
2201 
2202 bool QgsMapLayer::setDependencies( const QSet<QgsMapLayerDependency> &oDeps )
2203 {
2204  QSet<QgsMapLayerDependency> deps;
2205  const auto constODeps = oDeps;
2206  for ( const QgsMapLayerDependency &dep : constODeps )
2207  {
2208  if ( dep.origin() == QgsMapLayerDependency::FromUser )
2209  deps << dep;
2210  }
2211 
2212  mDependencies = deps;
2213  emit dependenciesChanged();
2214  return true;
2215 }
2216 
2218 {
2219  QgsDataProvider *lDataProvider = dataProvider();
2220 
2221  if ( !lDataProvider )
2222  return;
2223 
2224  if ( enabled && !isRefreshOnNotifyEnabled() )
2225  {
2226  lDataProvider->setListening( enabled );
2227  connect( lDataProvider, &QgsDataProvider::notify, this, &QgsMapLayer::onNotified );
2228  }
2229  else if ( !enabled && isRefreshOnNotifyEnabled() )
2230  {
2231  // we don't want to disable provider listening because someone else could need it (e.g. actions)
2232  disconnect( lDataProvider, &QgsDataProvider::notify, this, &QgsMapLayer::onNotified );
2233  }
2234  mIsRefreshOnNofifyEnabled = enabled;
2235 }
2236 
2238 {
2239  if ( QgsMapLayerStore *store = qobject_cast<QgsMapLayerStore *>( parent() ) )
2240  {
2241  return qobject_cast<QgsProject *>( store->parent() );
2242  }
2243  return nullptr;
2244 }
2245 
2246 void QgsMapLayer::onNotified( const QString &message )
2247 {
2248  if ( refreshOnNotifyMessage().isEmpty() || refreshOnNotifyMessage() == message )
2249  {
2250  triggerRepaint();
2251  emit dataChanged();
2252  }
2253 }
2254 
2255 QgsRectangle QgsMapLayer::wgs84Extent( bool forceRecalculate ) const
2256 {
2258 
2259  if ( ! forceRecalculate && ! mWgs84Extent.isNull() )
2260  {
2261  wgs84Extent = mWgs84Extent;
2262  }
2263  else if ( ! mExtent.isNull() )
2264  {
2266  transformer.setBallparkTransformsAreAppropriate( true );
2267  try
2268  {
2269  wgs84Extent = transformer.transformBoundingBox( mExtent );
2270  }
2271  catch ( const QgsCsException &cse )
2272  {
2273  QgsMessageLog::logMessage( tr( "Error transforming extent: %1" ).arg( cse.what() ) );
2275  }
2276  }
2277  return wgs84Extent;
2278 }
2279 
2280 void QgsMapLayer::updateExtent( const QgsRectangle &extent ) const
2281 {
2282  if ( extent == mExtent )
2283  return;
2284 
2285  mExtent = extent;
2286 
2287  // do not update the wgs84 extent if we trust layer metadata
2288  if ( mReadFlags & QgsMapLayer::ReadFlag::FlagTrustLayerMetadata )
2289  return;
2290 
2291  mWgs84Extent = wgs84Extent( true );
2292 }
2293 
2295 {
2296  // do not update the wgs84 extent if we trust layer metadata
2297  if ( mReadFlags & QgsMapLayer::ReadFlag::FlagTrustLayerMetadata )
2298  return;
2299 
2300  mWgs84Extent = QgsRectangle();
2301 }
2302 
2304 {
2305  QString metadata = QStringLiteral( "<h1>" ) + tr( "General" ) + QStringLiteral( "</h1>\n<hr>\n" ) + QStringLiteral( "<table class=\"list-view\">\n" );
2306 
2307  // name
2308  metadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Name" ) + QStringLiteral( "</td><td>" ) + name() + QStringLiteral( "</td></tr>\n" );
2309 
2310  QString path;
2311  bool isLocalPath = false;
2312  if ( dataProvider() )
2313  {
2314  // local path
2315  QVariantMap uriComponents = QgsProviderRegistry::instance()->decodeUri( dataProvider()->name(), publicSource() );
2316  if ( uriComponents.contains( QStringLiteral( "path" ) ) )
2317  {
2318  path = uriComponents[QStringLiteral( "path" )].toString();
2319  QFileInfo fi( path );
2320  if ( fi.exists() )
2321  {
2322  isLocalPath = true;
2323  metadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Path" ) + QStringLiteral( "</td><td>%1" ).arg( QStringLiteral( "<a href=\"%1\">%2</a>" ).arg( QUrl::fromLocalFile( path ).toString(), QDir::toNativeSeparators( path ) ) ) + QStringLiteral( "</td></tr>\n" );
2324 
2325  QDateTime lastModified = fi.lastModified();
2326  QString lastModifiedFileName;
2327  QSet<QString> sidecarFiles = QgsFileUtils::sidecarFilesForPath( path );
2328  if ( fi.isFile() )
2329  {
2330  qint64 fileSize = fi.size();
2331  if ( !sidecarFiles.isEmpty() )
2332  {
2333  lastModifiedFileName = fi.fileName();
2334  QStringList sidecarFileNames;
2335  for ( const QString &sidecarFile : sidecarFiles )
2336  {
2337  QFileInfo sidecarFi( sidecarFile );
2338  fileSize += sidecarFi.size();
2339  if ( sidecarFi.lastModified() > lastModified )
2340  {
2341  lastModified = sidecarFi.lastModified();
2342  lastModifiedFileName = sidecarFi.fileName();
2343  }
2344  sidecarFileNames << sidecarFi.fileName();
2345  }
2346  metadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + ( sidecarFiles.size() > 1 ? tr( "Sidecar files" ) : tr( "Sidecar file" ) ) + QStringLiteral( "</td><td>%1" ).arg( sidecarFileNames.join( QLatin1String( ", " ) ) ) + QStringLiteral( "</td></tr>\n" );
2347  }
2348  metadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + ( !sidecarFiles.isEmpty() ? tr( "Total size" ) : tr( "Size" ) ) + QStringLiteral( "</td><td>%1" ).arg( QgsFileUtils::representFileSize( fileSize ) ) + QStringLiteral( "</td></tr>\n" );
2349  }
2350  metadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Last modified" ) + QStringLiteral( "</td><td>%1" ).arg( QLocale().toString( fi.lastModified() ) ) + ( !lastModifiedFileName.isEmpty() ? QStringLiteral( " (%1)" ).arg( lastModifiedFileName ) : QString() ) + QStringLiteral( "</td></tr>\n" );
2351  }
2352  }
2353  if ( uriComponents.contains( QStringLiteral( "url" ) ) )
2354  {
2355  const QString url = uriComponents[QStringLiteral( "url" )].toString();
2356  metadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "URL" ) + QStringLiteral( "</td><td>%1" ).arg( QStringLiteral( "<a href=\"%1\">%2</a>" ).arg( QUrl( url ).toString(), url ) ) + QStringLiteral( "</td></tr>\n" );
2357  }
2358  }
2359 
2360  // data source
2361  if ( publicSource() != path || !isLocalPath )
2362  metadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Source" ) + QStringLiteral( "</td><td>%1" ).arg( publicSource() != path ? publicSource() : path ) + QStringLiteral( "</td></tr>\n" );
2363 
2364  // provider
2365  if ( dataProvider() )
2366  metadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Provider" ) + QStringLiteral( "</td><td>%1" ).arg( dataProvider()->name() ) + QStringLiteral( "</td></tr>\n" );
2367 
2368  metadata += QLatin1String( "</table>\n<br><br>" );
2369  return metadata;
2370 }
2371 
2373 {
2374  QString metadata = QStringLiteral( "<h1>" ) + tr( "Coordinate Reference System (CRS)" ) + QStringLiteral( "</h1>\n<hr>\n" );
2375  metadata += QLatin1String( "<table class=\"list-view\">\n" );
2376 
2377  // Identifier
2379  if ( !c.isValid() )
2380  metadata += QStringLiteral( "<tr><td colspan=\"2\" class=\"highlight\">" ) + tr( "Unknown" ) + QStringLiteral( "</td></tr>\n" );
2381  else
2382  {
2383  metadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Name" ) + QStringLiteral( "</td><td>" ) + c.userFriendlyIdentifier( QgsCoordinateReferenceSystem::FullString ) + QStringLiteral( "</td></tr>\n" );
2384 
2385  // map units
2386  metadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Units" ) + QStringLiteral( "</td><td>" )
2387  + ( c.isGeographic() ? tr( "Geographic (uses latitude and longitude for coordinates)" ) : QgsUnitTypes::toString( c.mapUnits() ) )
2388  + QStringLiteral( "</td></tr>\n" );
2389 
2390 
2391  // operation
2392  const QgsProjOperation operation = c.operation();
2393  metadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Method" ) + QStringLiteral( "</td><td>" ) + operation.description() + QStringLiteral( "</td></tr>\n" );
2394 
2395  // celestial body
2396  try
2397  {
2398  const QString celestialBody = c.celestialBodyName();
2399  if ( !celestialBody.isEmpty() )
2400  {
2401  metadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Celestial body" ) + QStringLiteral( "</td><td>" ) + celestialBody + QStringLiteral( "</td></tr>\n" );
2402  }
2403  }
2404  catch ( QgsNotSupportedException & )
2405  {
2406 
2407  }
2408 
2409  QString accuracyString;
2410  // dynamic crs with no epoch?
2411  if ( c.isDynamic() && std::isnan( c.coordinateEpoch() ) )
2412  {
2413  accuracyString = tr( "Based on a dynamic CRS, but no coordinate epoch is set. Coordinates are ambiguous and of limited accuracy." );
2414  }
2415 
2416  // based on datum ensemble?
2417  try
2418  {
2419  const QgsDatumEnsemble ensemble = c.datumEnsemble();
2420  if ( ensemble.isValid() )
2421  {
2422  QString id;
2423  if ( !ensemble.code().isEmpty() )
2424  id = QStringLiteral( "<i>%1</i> (%2:%3)" ).arg( ensemble.name(), ensemble.authority(), ensemble.code() );
2425  else
2426  id = QStringLiteral( "<i>%</i>”" ).arg( ensemble.name() );
2427 
2428  if ( ensemble.accuracy() > 0 )
2429  {
2430  accuracyString = tr( "Based on %1, which has a limited accuracy of <b>at best %2 meters</b>." ).arg( id ).arg( ensemble.accuracy() );
2431  }
2432  else
2433  {
2434  accuracyString = tr( "Based on %1, which has a limited accuracy." ).arg( id );
2435  }
2436  }
2437  }
2438  catch ( QgsNotSupportedException & )
2439  {
2440 
2441  }
2442 
2443  if ( !accuracyString.isEmpty() )
2444  {
2445  metadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Accuracy" ) + QStringLiteral( "</td><td>" ) + accuracyString + QStringLiteral( "</td></tr>\n" );
2446  }
2447 
2448  // static/dynamic
2449  metadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Reference" ) + QStringLiteral( "</td><td>%1</td></tr>\n" ).arg( c.isDynamic() ? tr( "Dynamic (relies on a datum which is not plate-fixed)" ) : tr( "Static (relies on a datum which is plate-fixed)" ) );
2450 
2451  // coordinate epoch
2452  if ( !std::isnan( c.coordinateEpoch() ) )
2453  {
2454  metadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Coordinate epoch" ) + QStringLiteral( "</td><td>%1</td></tr>\n" ).arg( c.coordinateEpoch() );
2455  }
2456  }
2457 
2458  metadata += QLatin1String( "</table>\n<br><br>\n" );
2459  return metadata;
2460 }
QgsMapLayerStyleManager::styles
QStringList styles() const
Returns list of all defined style names.
Definition: qgsmaplayerstylemanager.cpp:86
QgsMapLayer::setAbstract
void setAbstract(const QString &abstract)
Sets the abstract of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:318
QgsProjectFileTransform::updateRevision
bool updateRevision(const QgsProjectVersion &version)
Definition: qgsprojectfiletransform.cpp:71
QgsMapLayer::crsHtmlMetadata
QString crsHtmlMetadata() const
Returns a HTML fragment containing the layer's CRS metadata, for use in the htmlMetadata() method.
Definition: qgsmaplayer.cpp:2372
QgsMapLayer::Style
@ Style
Definition: qgsmaplayer.h:134
QgsMapLayer::crs
QgsCoordinateReferenceSystem crs
Definition: qgsmaplayer.h:79
QgsMapLayer::emitStyleChanged
void emitStyleChanged()
Triggers an emission of the styleChanged() signal.
Definition: qgsmaplayer.cpp:2145
QgsMapLayer::flagsChanged
void flagsChanged()
Emitted when layer's flags have been modified.
QgsMapLayer::readCommonStyle
void readCommonStyle(const QDomElement &layerElement, const QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories)
Read style data common to all layer types.
Definition: qgsmaplayer.cpp:1869
QgsMapLayer::dependenciesChanged
void dependenciesChanged()
Emitted when dependencies are changed.
QgsMapLayer::loadSldStyle
virtual QString loadSldStyle(const QString &uri, bool &resultFlag)
Attempts to style the layer using the formatting from an SLD type file.
Definition: qgsmaplayer.cpp:1723
QgsMapLayer::request3DUpdate
void request3DUpdate()
Signal emitted when a layer requires an update in any 3D maps.
QgsMapLayer::~QgsMapLayer
~QgsMapLayer() override
Definition: qgsmaplayer.cpp:99
QgsMapLayer::hasAutoRefreshEnabled
bool hasAutoRefreshEnabled() const
Returns true if auto refresh is enabled for the layer.
Definition: qgsmaplayer.cpp:844
QgsMapLayer::resolveReferences
virtual void resolveReferences(QgsProject *project)
Resolve references to other layers (kept as layer IDs after reading XML) into layer objects.
Definition: qgsmaplayer.cpp:772
QgsLayerMetadata::readMetadataXml
bool readMetadataXml(const QDomElement &metadataElement) override
Sets state from DOM document.
Definition: qgslayermetadata.cpp:134
qgsmaplayerstylemanager.h
Qgis::version
static QString version()
Version string.
Definition: qgis.cpp:277
QgsMapLayer::attributionUrl
QString attributionUrl() const
Returns the attribution URL of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:418
sqlite3_database_unique_ptr::open
int open(const QString &path)
Opens the database at the specified file path.
Definition: qgssqliteutils.cpp:78
QgsCoordinateTransformContext
Contains information about the context in which a coordinate transform is executed.
Definition: qgscoordinatetransformcontext.h:57
QgsMapLayer::refreshOnNotifyMessage
QString refreshOnNotifyMessage() const
Returns the message that should be notified by the provider to triggerRepaint.
Definition: qgsmaplayer.h:1452
QgsMapLayer::writeXml
virtual bool writeXml(QDomNode &layer_node, QDomDocument &document, const QgsReadWriteContext &context) const
Called by writeLayerXML(), used by children to write state specific to them to project files.
Definition: qgsmaplayer.cpp:749
QgsStringUtils::capitalize
static QString capitalize(const QString &string, Qgis::Capitalization capitalization)
Converts a string by applying capitalization rules to the string.
Definition: qgsstringutils.cpp:24
qgsrasterlayer.h
QgsMapLayer::FlagTrustLayerMetadata
@ FlagTrustLayerMetadata
Trust layer metadata. Improves layer load time by skipping expensive checks like primary key unicity,...
Definition: qgsmaplayer.h:641
QgsMapLayer::setMetadataUrl
Q_DECL_DEPRECATED void setMetadataUrl(const QString &metaUrl)
Sets the metadata URL of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.cpp:205
QgsMapLayer::configChanged
void configChanged()
Emitted whenever the configuration is changed.
QgsMapLayer::FlagReadExtentFromXml
@ FlagReadExtentFromXml
Read extent from xml and skip get extent from provider.
Definition: qgsmaplayer.h:642
QgsMapLayer::writeLayerXml
bool writeLayerXml(QDomElement &layerElement, QDomDocument &document, const QgsReadWriteContext &context) const
Stores state in DOM node.
Definition: qgsmaplayer.cpp:540
QgsMapLayer::autoRefreshInterval
int autoRefreshInterval
Definition: qgsmaplayer.h:77
QgsMapLayer::dataUrlFormat
QString dataUrlFormat() const
Returns the DataUrl format of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:380
QgsDataProvider::ProviderOptions
Setting options for creating vector data providers.
Definition: qgsdataprovider.h:107
QgsProviderRegistry::saveLayerMetadata
bool saveLayerMetadata(const QString &providerKey, const QString &uri, const QgsLayerMetadata &metadata, QString &errorMessage) SIP_THROW(QgsNotSupportedException)
Saves metadata to the layer corresponding to the specified uri.
Definition: qgsproviderregistry.cpp:710
QgsCoordinateReferenceSystem::customCrsValidation
static CUSTOM_CRS_VALIDATION customCrsValidation()
Gets custom function.
Definition: qgscoordinatereferencesystem.cpp:2122
QgsMapLayer::generateId
static QString generateId(const QString &layerName)
Generates an unique identifier for this layer, the generate ID is prefixed by layerName.
Definition: qgsmaplayer.cpp:2171
QgsReadWriteContext
The class is used as a container of context for various read/write operations on other objects.
Definition: qgsreadwritecontext.h:34
QgsDataProvider
Abstract base class for spatial data provider implementations.
Definition: qgsdataprovider.h:40
qgsrectangle.h
QgsMapLayerType::VectorLayer
@ VectorLayer
Vector layer.
Qgs3DRendererAbstractMetadata::createRenderer
virtual QgsAbstract3DRenderer * createRenderer(QDomElement &elem, const QgsReadWriteContext &context)=0
Returns new instance of the renderer given the DOM element.
QgsMapLayer::mLayerOpacity
double mLayerOpacity
Layer opacity.
Definition: qgsmaplayer.h:2001
QgsDebugMsgLevel
#define QgsDebugMsgLevel(str, level)
Definition: qgslogger.h:39
QgsAbstract3DRenderer::type
virtual QString type() const =0
Returns unique identifier of the renderer class (used to identify subclass)
QgsMapLayer::opacity
double opacity
Definition: qgsmaplayer.h:82
QgsMapLayer::setFlags
void setFlags(QgsMapLayer::LayerFlags flags)
Returns the flags for this layer.
Definition: qgsmaplayer.cpp:155
sqlite3_database_unique_ptr::prepare
sqlite3_statement_unique_ptr prepare(const QString &sql, int &resultCode) const
Prepares a sql statement, returning the result.
Definition: qgssqliteutils.cpp:99
QgsMapLayerElevationProperties
Base class for storage of map layer elevation properties.
Definition: qgsmaplayerelevationproperties.h:41
QgsMapLayer::clone
virtual QgsMapLayer * clone() const =0
Returns a new instance equivalent to this one except for the id which is still unique.
qgsauthmanager.h
QgsMapLayer::blendMode
QPainter::CompositionMode blendMode() const
Returns the current blending mode for a layer.
Definition: qgsmaplayer.cpp:320
QgsMapLayer::mLegendUrlFormat
QString mLegendUrlFormat
Definition: qgsmaplayer.h:1963
QgsMapLayer::setCustomProperty
Q_INVOKABLE void setCustomProperty(const QString &key, const QVariant &value)
Set a custom property for layer.
Definition: qgsmaplayer.cpp:1976
QgsMapLayer::setRefreshOnNotifyEnabled
void setRefreshOnNotifyEnabled(bool enabled)
Set whether provider notification is connected to triggerRepaint.
Definition: qgsmaplayer.cpp:2217
QgsAbstract3DRenderer
Base class for all renderers that may to participate in 3D view.
Definition: qgsabstract3drenderer.h:48
QgsMapLayer::mIsRefreshOnNofifyEnabled
bool mIsRefreshOnNofifyEnabled
Definition: qgsmaplayer.h:1978
QgsMapLayer::mReadFlags
QgsMapLayer::ReadFlags mReadFlags
Read flags. It's up to the subclass to respect these when restoring state from XML.
Definition: qgsmaplayer.h:1987
QgsMapLayer::mAttributionUrl
QString mAttributionUrl
Definition: qgsmaplayer.h:1959
qgsreadwritecontext.h
QgsMapLayer::loadNamedStyleFromDatabase
virtual bool loadNamedStyleFromDatabase(const QString &db, const QString &uri, QString &qml)
Retrieve a named style for this layer from a sqlite database.
Definition: qgsmaplayer.cpp:1060
QgsMapLayer::Symbology3D
@ Symbology3D
3D symbology
Definition: qgsmaplayer.h:162
qgsstringutils.h
QgsMapLayer::dependencies
virtual QSet< QgsMapLayerDependency > dependencies() const
Gets the list of dependencies.
Definition: qgsmaplayer.cpp:2197
QgsMapLayer::isRefreshOnNotifyEnabled
bool isRefreshOnNotifyEnabled() const
Returns true if the refresh on provider nofification is enabled.
Definition: qgsmaplayer.h:1459
QgsCoordinateReferenceSystem::fromOgcWmsCrs
static QgsCoordinateReferenceSystem fromOgcWmsCrs(const QString &ogcCrs)
Creates a CRS from a given OGC WMS-format Coordinate Reference System string.
Definition: qgscoordinatereferencesystem.cpp:195
QgsMapLayer::properties
virtual Qgis::MapLayerProperties properties() const
Returns the map layer properties of this layer.
Definition: qgsmaplayer.cpp:164
QgsMapLayer::importNamedStyle
virtual bool importNamedStyle(QDomDocument &doc, QString &errorMsg, QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories)
Import the properties of this layer from a QDomDocument.
Definition: qgsmaplayer.cpp:1227
QgsMapLayerType::AnnotationLayer
@ AnnotationLayer
Contains freeform, georeferenced annotations. Added in QGIS 3.16.
QgsMapLayer::subLayers
virtual QStringList subLayers() const
Returns the sublayers of this layer.
Definition: qgsmaplayer.cpp:909
QgsDataProvider::FlagTrustDataSource
@ FlagTrustDataSource
Trust datasource config (primary key unicity, geometry type and srid, etc). Improves provider load ti...
Definition: qgsdataprovider.h:123
QgsMapLayer::loadNamedMetadataFromDatabase
bool loadNamedMetadataFromDatabase(const QString &db, const QString &uri, QString &qmd)
Retrieve a named metadata for this layer from a sqlite database.
Definition: qgsmaplayer.cpp:1055
QgsLayerMetadata
A structured metadata store for a map layer.
Definition: qgslayermetadata.h:56
QgsMapLayer::shortName
QString shortName() const
Returns the short name of the layer used by QGIS Server to identify the layer.
Definition: qgsmaplayer.cpp:200
QgsMapLayerType
QgsMapLayerType
Types of layers that can be added to a map.
Definition: qgis.h:46
QgsMapLayer::writeCustomProperties
void writeCustomProperties(QDomNode &layerNode, QDomDocument &doc) const
Write custom properties to project file.
Definition: qgsmaplayer.cpp:795
QgsMapLayer::setCustomProperties
void setCustomProperties(const QgsObjectCustomProperties &properties)
Set custom properties for layer.
Definition: qgsmaplayer.cpp:1985
QgsMapLayer::mDataUrlFormat
QString mDataUrlFormat
Definition: qgsmaplayer.h:1955
QgsMapLayer::setMetadataUrlType
Q_DECL_DEPRECATED void setMetadataUrlType(const QString &metaUrlType)
Set the metadata type of the layer used by QGIS Server in GetCapabilities request MetadataUrlType ind...
Definition: qgsmaplayer.cpp:234
QgsError
QgsError is container for error messages (report). It may contain chain (sort of traceback) of error ...
Definition: qgserror.h:80
QgsMapLayerLegend
The QgsMapLayerLegend class is abstract interface for implementations of legends for one map layer.
Definition: qgsmaplayerlegend.h:47
QgsMapLayer::styleManager
QgsMapLayerStyleManager * styleManager() const
Gets access to the layer's style manager.
Definition: qgsmaplayer.cpp:2092
qgspathresolver.h
QgsMapLayer::formatLayerName
static QString formatLayerName(const QString &name)
A convenience function to capitalize and format a layer name.
Definition: qgsmaplayer.cpp:957
QgsMapLayer::Metadata
@ Metadata
Definition: qgsmaplayer.h:135
Qgs3DRendererAbstractMetadata
Base metadata class for 3D renderers.
Definition: qgs3drendererregistry.h:34
geoEpsgCrsAuthId
CONSTLATIN1STRING geoEpsgCrsAuthId()
Geographic coord sys from EPSG authority.
Definition: qgis.h:2732
QgsProject::instance
static QgsProject * instance()
Returns the QgsProject singleton instance.
Definition: qgsproject.cpp:480
QgsXmlUtils::readFlagAttribute
static T readFlagAttribute(const QDomElement &element, const QString &attributeName, T defaultValue)
Read a flag value from an attribute of the element.
Definition: qgsxmlutils.h:99
QgsStyleEntityVisitorInterface
An interface for classes which can visit style entity (e.g. symbol) nodes (using the visitor pattern)...
Definition: qgsstyleentityvisitor.h:33
QgsMapLayer::PropertyType
PropertyType
Maplayer has a style and a metadata property.
Definition: qgsmaplayer.h:132
qgsprojoperation.h
QgsProjOperation::description
QString description() const
Description.
Definition: qgsprojoperation.h:61
QgsMapLayer::setBlendMode
void setBlendMode(QPainter::CompositionMode blendMode)
Set the blending mode used for rendering a layer.
Definition: qgsmaplayer.cpp:310
QgsObjectCustomProperties::readXml
void readXml(const QDomNode &parentNode, const QString &keyStartsWith=QString())
Read store contents from an XML node.
Definition: qgsobjectcustomproperties.cpp:51
QgsMapLayer::saveDefaultStyle
virtual QString saveDefaultStyle(bool &resultFlag, StyleCategories categories)
Save the properties of this layer as the default style (either as a .qml file on disk or as a record ...
Definition: qgsmaplayer.cpp:1330
QgsMapLayer::readCustomProperties
void readCustomProperties(const QDomNode &layerNode, const QString &keyStartsWith=QString())
Read custom properties from project file.
Definition: qgsmaplayer.cpp:780
QgsMapLayer::isValid
bool isValid
Definition: qgsmaplayer.h:81
QgsServerMetadataUrlProperties::MetadataUrl::url
QString url
URL of the link.
Definition: qgsmaplayerserverproperties.h:64
QgsMapLayer::exportNamedMetadata
void exportNamedMetadata(QDomDocument &doc, QString &errorMsg) const
Export the current metadata of this layer as named metadata in a QDomDocument.
Definition: qgsmaplayer.cpp:1269
QgsMapLayer::saveNamedStyle
virtual QString saveNamedStyle(const QString &uri, bool &resultFlag, StyleCategories categories=AllStyleCategories)
Save the properties of this layer as a named style (either as a .qml file on disk or as a record in t...
Definition: qgsmaplayer.cpp:1576
QgsDataProvider::notify
void notify(const QString &msg)
Emitted when the datasource issues a notification.
qgsabstract3drenderer.h
QgsMapLayer::saveSldStyle
virtual QString saveSldStyle(const QString &uri, bool &resultFlag) const
Saves the properties of this layer to an SLD format file.
Definition: qgsmaplayer.cpp:1658
QgsMapLayerStyleManager::reset
void reset()
Reset the style manager to a basic state - with one default style which is set as current.
Definition: qgsmaplayerstylemanager.cpp:38
QgsServerMetadataUrlProperties::MetadataUrl::type
QString type
Link type.
Definition: qgsmaplayerserverproperties.h:69
QgsMapLayer::crsChanged
void crsChanged()
Emit a signal that layer's CRS has been reset.
QgsCoordinateReferenceSystem::readXml
bool readXml(const QDomNode &node)
Restores state from the given DOM node.
Definition: qgscoordinatereferencesystem.cpp:1860
QgsMapLayer::customPropertyKeys
Q_INVOKABLE QStringList customPropertyKeys() const
Returns list of all keys within custom properties.
Definition: qgsmaplayer.cpp:1971
QgsMapLayer::htmlMetadata
virtual QString htmlMetadata() const
Obtain a formatted HTML string containing assorted metadata for this layer.
Definition: qgsmaplayer.cpp:2135
QgsServerMetadataUrlProperties::setMetadataUrls
void setMetadataUrls(const QList< QgsServerMetadataUrlProperties::MetadataUrl > &metaUrls)
Sets a the list of metadata URL for the layer.
Definition: qgsmaplayerserverproperties.h:96
QgsMapLayer::legend
QgsMapLayerLegend * legend() const
Can be nullptr.
Definition: qgsmaplayer.cpp:2087
QgsMapLayer::accept
virtual bool accept(QgsStyleEntityVisitorInterface *visitor) const
Accepts the specified symbology visitor, causing it to visit all symbols associated with the layer.
Definition: qgsmaplayer.cpp:2187
QgsMapLayer::setMetadata
virtual void setMetadata(const QgsLayerMetadata &metadata)
Sets the layer's metadata store.
Definition: qgsmaplayer.cpp:2128
QgsMapLayer::setCrs
void setCrs(const QgsCoordinateReferenceSystem &srs, bool emitSignal=true)
Sets layer's spatial reference system.
Definition: qgsmaplayer.cpp:937
QgsProjOperation
Contains information about a PROJ operation.
Definition: qgsprojoperation.h:30
QgsMapLayer::mError
QgsError mError
Error.
Definition: qgsmaplayer.h:1966
QgsRectangle
A rectangle specified with double values.
Definition: qgsrectangle.h:41
QgsMapLayer::mShouldValidateCrs
bool mShouldValidateCrs
true if the layer's CRS should be validated and invalid CRSes are not permitted.
Definition: qgsmaplayer.h:1994
QgsMapLayer::dataUrl
QString dataUrl() const
Returns the DataUrl of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:362
QgsLayerMetadata::writeMetadataXml
bool writeMetadataXml(QDomElement &metadataElement, QDomDocument &document) const override
Stores state in a DOM node.
Definition: qgslayermetadata.cpp:242
QgsProject::removeAttachedFile
bool removeAttachedFile(const QString &path)
Removes the attached file.
Definition: qgsproject.cpp:4081
QgsMapLayer::styleURI
virtual QString styleURI() const
Retrieve the style URI for this layer (either as a .qml file on disk or as a record in the users styl...
Definition: qgsmaplayer.cpp:1045
QgsMapLayer::mProviderKey
QString mProviderKey
Data provider key (name of the data provider)
Definition: qgsmaplayer.h:1982
QgsMapLayerStyleManager::readXml
void readXml(const QDomElement &mgrElement)
Read configuration (for project loading)
Definition: qgsmaplayerstylemanager.cpp:44
QgsProject
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition: qgsproject.h:103
QgsMapLayer::saveNamedMetadata
QString saveNamedMetadata(const QString &uri, bool &resultFlag)
Save the current metadata of this layer as a named metadata (either as a .qmd file on disk or as a re...
Definition: qgsmaplayer.cpp:1335
QgsMapLayer::Rendering
@ Rendering
Rendering: scale visibility, simplify method, opacity.
Definition: qgsmaplayer.h:170
QgsDataProvider::transformContext
QgsCoordinateTransformContext transformContext() const
Returns data provider coordinate transform context.
Definition: qgsdataprovider.cpp:81
QgsMapLayer::providerType
QString providerType() const
Returns the provider type (provider key) for this layer.
Definition: qgsmaplayer.cpp:1864
QgsMapLayer::setLegendUrlFormat
void setLegendUrlFormat(const QString &legendUrlFormat)
Sets the format for a URL based layer legend.
Definition: qgsmaplayer.h:1292
QgsApplication::authManager
static QgsAuthManager * authManager()
Returns the application's authentication manager instance.
Definition: qgsapplication.cpp:1436
QgsMapLayer::Elevation
@ Elevation
Elevation settings (since QGIS 3.18)
Definition: qgsmaplayer.h:176
qgsapplication.h
QgsLayerNotesUtils::layerNotes
static QString layerNotes(const QgsMapLayer *layer)
Returns the notes for the specified layer.
Definition: qgslayernotesutils.cpp:19
QgsMapLayer::Temporal
@ Temporal
Temporal properties (since QGIS 3.14)
Definition: qgsmaplayer.h:174
QgsMapLayer::mLayerName
QString mLayerName
Name of the layer - used for display.
Definition: qgsmaplayer.h:1944
QgsMapLayer::saveDefaultMetadata
virtual QString saveDefaultMetadata(bool &resultFlag)
Save the current metadata of this layer as the default metadata (either as a .qmd file on disk or as ...
Definition: qgsmaplayer.cpp:1013
QgsMapLayer::triggerRepaint
void triggerRepaint(bool deferredUpdate=false)
Will advise the map canvas (and any other interested party) that this layer requires to be repainted.
Definition: qgsmaplayer.cpp:2114
QgsMapLayer::dataSourceChanged
void dataSourceChanged()
Emitted whenever the layer's data source has been changed.
QgsMapLayer::customProperties
const QgsObjectCustomProperties & customProperties() const
Read all custom properties from layer.
Definition: qgsmaplayer.cpp:1994
QgsMapLayerStore
A storage object for map layers, in which the layers are owned by the store and have their lifetime b...
Definition: qgsmaplayerstore.h:35
QgsAbstract3DRenderer::resolveReferences
virtual void resolveReferences(const QgsProject &project)
Resolves references to other objects - second phase of loading - after readXml()
Definition: qgsabstract3drenderer.cpp:19
QgsMapLayer::setSubLayerVisibility
virtual void setSubLayerVisibility(const QString &name, bool visible)
Set the visibility of the given sublayer name.
Definition: qgsmaplayer.cpp:920
QgsMapLayer::isInScaleRange
bool isInScaleRange(double scale) const
Tests whether the layer should be visible at the specified scale.
Definition: qgsmaplayer.cpp:832
QgsMapLayer::flags
QgsMapLayer::LayerFlags flags() const
Returns the flags for this layer.
Definition: qgsmaplayer.cpp:150
QgsMapLayer::isModified
virtual bool isModified() const
Returns true if the layer has been modified since last commit/save.
Definition: qgsmaplayer.cpp:2026
QgsPathResolver::writePath
QString writePath(const QString &filename) const
Prepare a filename to save it to the project file.
Definition: qgspathresolver.cpp:225
QgsApplication::qgisSettingsDirPath
static QString qgisSettingsDirPath()
Returns the path to the settings directory in user's home dir.
Definition: qgsapplication.cpp:1099
qgsmaplayertemporalproperties.h
QgsMapLayer::metadata
QgsLayerMetadata metadata
Definition: qgsmaplayer.h:78
QgsReadWriteContextCategoryPopper
Allows entering a context category and takes care of leaving this category on deletion of the class....
Definition: qgsreadwritecontext.h:178
QgsMapLayerStyleManager
Management of styles for use with one map layer.
Definition: qgsmaplayerstylemanager.h:57
qgsprovidermetadata.h
qgsprojectfiletransform.h
qgslayernotesutils.h
QgsCsException
Custom exception class for Coordinate Reference System related exceptions.
Definition: qgsexception.h:65
QgsMapLayer::encodedSource
virtual QString encodedSource(const QString &source, const QgsReadWriteContext &context) const
Called by writeLayerXML(), used by derived classes to encode provider's specific data source to proje...
Definition: qgsmaplayer.cpp:759
QgsMapLayer::mValid
bool mValid
Indicates if the layer is valid and can be drawn.
Definition: qgsmaplayer.h:1938
QgsReadWriteContext::projectTranslator
const QgsProjectTranslator * projectTranslator() const
Returns the project translator.
Definition: qgsreadwritecontext.h:128
QgsMapLayer::setExtent
virtual void setExtent(const QgsRectangle &rect)
Sets the extent.
Definition: qgsmaplayer.cpp:2151
QgsDatumEnsemble::accuracy
double accuracy() const
Positional accuracy (in meters).
Definition: qgsdatums.h:112
QgsMapLayer::dataProvider
virtual Q_INVOKABLE QgsDataProvider * dataProvider()
Returns the layer's data provider, it may be nullptr.
Definition: qgsmaplayer.cpp:190
QgsReadWriteContext::enterCategory
MAYBE_UNUSED NODISCARD QgsReadWriteContextCategoryPopper enterCategory(const QString &category, const QString &details=QString()) const
Push a category to the stack.
Definition: qgsreadwritecontext.cpp:62
QgsMapLayer::keywordList
QString keywordList() const
Returns the keyword list of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:342
QgsMapLayer::renderer3D
QgsAbstract3DRenderer * renderer3D() const
Returns 3D renderer associated with the layer.
Definition: qgsmaplayer.cpp:2109
QgsMapLayer::readSld
virtual bool readSld(const QDomNode &node, QString &errorMessage)
Definition: qgsmaplayer.h:1160
QgsMapLayer::legendUrlFormat
QString legendUrlFormat() const
Returns the format for a URL based layer legend.
Definition: qgsmaplayer.h:1297
qgsproviderregistry.h
QgsLayerNotesUtils::layerHasNotes
static bool layerHasNotes(const QgsMapLayer *layer)
Returns true if the specified layer has notes available.
Definition: qgslayernotesutils.cpp:38
QgsMapLayer::metadataUrlFormat
Q_DECL_DEPRECATED QString metadataUrlFormat() const
Returns the metadata format of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.cpp:280
qgsdatasourceuri.h
QgsCoordinateReferenceSystem::writeXml
bool writeXml(QDomNode &node, QDomDocument &doc) const
Stores state to the given Dom node in the given document.
Definition: qgscoordinatereferencesystem.cpp:1980
QgsDataProvider::FlagLoadDefaultStyle
@ FlagLoadDefaultStyle
Reset the layer's style to the default for the datasource.
Definition: qgsdataprovider.h:125
qgsdatums.h
QgsMapLayer::readStyleManager
void readStyleManager(const QDomNode &layerNode)
Read style manager's configuration (if any). To be called by subclasses.
Definition: qgsmaplayer.cpp:800
QgsUnitTypes::toString
static Q_INVOKABLE QString toString(QgsUnitTypes::DistanceUnit unit)
Returns a translated string representing a distance unit.
Definition: qgsunittypes.cpp:199
QgsMapLayer::writeCommonStyle
void writeCommonStyle(QDomElement &layerElement, QDomDocument &document, const QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories) const
Write style data common to all layer types.
Definition: qgsmaplayer.cpp:679
qgsDoubleNear
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
Definition: qgis.h:2265
QgsMapLayer::styleChanged
void styleChanged()
Signal emitted whenever a change affects the layer's style.
QgsMapLayer::repaintRequested
void repaintRequested(bool deferredUpdate=false)
By emitting this signal the layer tells that either appearance or content have been changed and any v...
QgsMapLayer::extent
virtual QgsRectangle extent() const
Returns the extent of the layer.
Definition: qgsmaplayer.cpp:305
QgsServerMetadataUrlProperties::MetadataUrl::format
QString format
Format specification of online resource.
Definition: qgsmaplayerserverproperties.h:74
QgsMapLayer::mAttribution
QString mAttribution
Attribution of the layer.
Definition: qgsmaplayer.h:1958
QgsMapLayer::setOriginalXmlProperties
void setOriginalXmlProperties(const QString &originalXmlProperties)
Sets the original XML properties for the layer to originalXmlProperties.
Definition: qgsmaplayer.cpp:2166
QgsException::what
QString what() const
Definition: qgsexception.h:48
QgsMapLayer::generalHtmlMetadata
QString generalHtmlMetadata() const
Returns an HTML fragment containing general metadata information, for use in the htmlMetadata() metho...
Definition: qgsmaplayer.cpp:2303
qgsmaplayer.h
QgsAbstract3DRenderer::writeXml
virtual void writeXml(QDomElement &elem, const QgsReadWriteContext &context) const =0
Writes renderer's properties to given XML element.
QgsMapLayer::mDependencies
QSet< QgsMapLayerDependency > mDependencies
List of layers that may modify this layer on modification.
Definition: qgsmaplayer.h:1969
QgsMapLayer::blendModeChanged
void blendModeChanged(QPainter::CompositionMode blendMode)
Signal emitted when the blend mode is changed, through QgsMapLayer::setBlendMode()
CUSTOM_CRS_VALIDATION
void(* CUSTOM_CRS_VALIDATION)(QgsCoordinateReferenceSystem &)
Definition: qgscoordinatereferencesystem.h:70
QgsMapLayer::isValidChanged
void isValidChanged()
Emitted when the validity of this layer changed.
QgsMapLayer::setMaximumScale
void setMaximumScale(double scale)
Sets the maximum map scale (i.e.
Definition: qgsmaplayer.cpp:883
QgsMapLayer::supportsEditing
virtual bool supportsEditing() const
Returns whether the layer supports editing or not.
Definition: qgsmaplayer.cpp:927
QgsMapLayer::setOpacity
virtual void setOpacity(double opacity)
Sets the opacity for the layer, where opacity is a value between 0 (totally transparent) and 1....
Definition: qgsmaplayer.cpp:325
QgsMapLayer::nameChanged
void nameChanged()
Emitted when the name has been changed.
QgsObjectCustomProperties::setValue
void setValue(const QString &key, const QVariant &value)
Add an entry to the store with the specified key.
Definition: qgsobjectcustomproperties.cpp:31
QgsMapLayer::temporalProperties
virtual QgsMapLayerTemporalProperties * temporalProperties()
Returns the layer's temporal properties.
Definition: qgsmaplayer.h:1502
qgsvectordataprovider.h
QgsMapLayer::mTitle
QString mTitle
Definition: qgsmaplayer.h:1947
QgsMapLayer::loadDefaultStyle
virtual QString loadDefaultStyle(bool &resultFlag)
Retrieve the default style for this layer if one exists (either as a .qml file on disk or as a record...
Definition: qgsmaplayer.cpp:1050
QgsMessageLog::logMessage
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
Definition: qgsmessagelog.cpp:27
QgsCoordinateReferenceSystem::isValid
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
Definition: qgscoordinatereferencesystem.cpp:977
QgsMapLayerServerProperties
Manages QGIS Server properties for a map layer.
Definition: qgsmaplayerserverproperties.h:272
QgsProviderRegistry::decodeUri
QVariantMap decodeUri(const QString &providerKey, const QString &uri)
Breaks a provider data source URI into its component paths (e.g.
Definition: qgsproviderregistry.cpp:555
QgsMapLayer::mDataUrl
QString mDataUrl
DataUrl of the layer.
Definition: qgsmaplayer.h:1954
QgsMapLayer::QgsMapLayer
QgsMapLayer(QgsMapLayerType type=QgsMapLayerType::VectorLayer, const QString &name=QString(), const QString &source=QString())
Constructor for QgsMapLayer.
Definition: qgsmaplayer.cpp:81
QgsMapLayer::isEditable
virtual bool isEditable() const
Returns true if the layer can be edited.
Definition: qgsmaplayer.cpp:2021
QgsMapLayer::setKeywordList
void setKeywordList(const QString &keywords)
Sets the keyword list of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:334
QgsMapLayer::wgs84Extent
QgsRectangle wgs84Extent(bool forceRecalculate=false) const
Returns the WGS84 extent (EPSG:4326) of the layer according to ReadFlag::FlagTrustLayerMetadata.
Definition: qgsmaplayer.cpp:2255
QgsMapLayer::id
QString id() const
Returns the layer's unique ID, which is used to access this layer from QgsProject.
Definition: qgsmaplayer.cpp:169
QgsMapLayer::title
QString title() const
Returns the title of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:310
QgsMapLayer::setTitle
void setTitle(const QString &title)
Sets the title of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:302
QgsMapLayerTemporalProperties
Base class for storage of map layer temporal properties.
Definition: qgsmaplayertemporalproperties.h:42
QgsMapLayer::mDataSource
QString mDataSource
Data source description string, varies by layer type.
Definition: qgsmaplayer.h:1941
QgsVectorLayer::writeSld
bool writeSld(QDomNode &node, QDomDocument &doc, QString &errorMessage, const QVariantMap &props=QVariantMap()) const
Writes the symbology of the layer into the document provided in SLD 1.1 format.
Definition: qgsvectorlayer.cpp:3010
QgsApplication::pkgDataPath
static QString pkgDataPath()
Returns the common root path of all application data directories.
Definition: qgsapplication.cpp:645
QgsMapLayer::hasScaleBasedVisibility
bool hasScaleBasedVisibility() const
Returns whether scale based visibility is enabled for the layer.
Definition: qgsmaplayer.cpp:839
QgsMapLayer::exportNamedStyle
virtual void exportNamedStyle(QDomDocument &doc, QString &errorMsg, const QgsReadWriteContext &context=QgsReadWriteContext(), QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories) const
Export the properties of this layer as named style in a QDomDocument.
Definition: qgsmaplayer.cpp:1288
QgsCoordinateReferenceSystem::FullString
@ FullString
Full definition – possibly a very lengthy string, e.g. with no truncation of custom WKT definitions.
Definition: qgscoordinatereferencesystem.h:634
QgsMapLayer::decodedSource
virtual QString decodedSource(const QString &source, const QString &dataProvider, const QgsReadWriteContext &context) const
Called by readLayerXML(), used by derived classes to decode provider's specific data source from proj...
Definition: qgsmaplayer.cpp:765
QgsRasterLayer
Represents a raster layer.
Definition: qgsrasterlayer.h:76
QgsMapLayer::setRenderer3D
void setRenderer3D(QgsAbstract3DRenderer *renderer)
Sets 3D renderer for the layer.
Definition: qgsmaplayer.cpp:2097
QgsMapLayer::originalXmlProperties
QString originalXmlProperties() const
Returns the XML properties of the original layer as they were when the layer was first read from the ...
Definition: qgsmaplayer.cpp:2161
QgsCoordinateReferenceSystem::validate
void validate()
Perform some validation on this CRS.
Definition: qgscoordinatereferencesystem.cpp:502
QgsMapLayer::removeCustomProperty
void removeCustomProperty(const QString &key)
Remove a custom property from layer.
Definition: qgsmaplayer.cpp:2004
QgsMapLayer::opacityChanged
void opacityChanged(double opacity)
Emitted when the layer's opacity is changed, where opacity is a value between 0 (transparent) and 1 (...
QgsServerMetadataUrlProperties::metadataUrls
QList< QgsServerMetadataUrlProperties::MetadataUrl > metadataUrls() const
Returns a list of metadataUrl resources associated for the layer.
Definition: qgsmaplayerserverproperties.h:89
qgs3drendererregistry.h
QgsMapLayer::minimumScale
double minimumScale() const
Returns the minimum map scale (i.e.
Definition: qgsmaplayer.cpp:904
sqlite3_database_unique_ptr::open_v2
int open_v2(const QString &path, int flags, const char *zVfs)
Opens the database at the specified file path.
Definition: qgssqliteutils.cpp:86
QgsMapLayer::maximumScale
double maximumScale() const
Returns the maximum map scale (i.e.
Definition: qgsmaplayer.cpp:888
qgsfileutils.h
QgsCoordinateReferenceSystem
This class represents a coordinate reference system (CRS).
Definition: qgscoordinatereferencesystem.h:211
QgsObjectCustomProperties::remove
void remove(const QString &key)
Removes a key (entry) from the store.
Definition: qgsobjectcustomproperties.cpp:41
QgsMapLayer::beforeResolveReferences
void beforeResolveReferences(QgsProject *project)
Emitted when all layers are loaded and references can be resolved, just before the references of this...
qgsxmlutils.h
QgsServerMetadataUrlProperties::MetadataUrl
MetadataUrl structure.
Definition: qgsmaplayerserverproperties.h:49
QgsMapLayerDependency::FromUser
@ FromUser
Definition: qgsmaplayerdependency.h:64
QgsProviderMetadata
Holds data provider key, description, and associated shared library file or function pointer informat...
Definition: qgsprovidermetadata.h:177
Qgis::Capitalization::ForceFirstLetterToCapital
@ ForceFirstLetterToCapital
Convert just the first letter of each word to uppercase, leave the rest untouched.
QgsProviderMetadata::SaveLayerMetadata
@ SaveLayerMetadata
Indicates that the provider supports saving native layer metadata (since QGIS 3.20)
Definition: qgsprovidermetadata.h:204
QgsProject::absoluteFilePath
QString absoluteFilePath() const
Returns full absolute path to the project file if the project is stored in a file system - derived fr...
Definition: qgsproject.cpp:823
QgsCoordinateReferenceSystem::setCustomCrsValidation
static void setCustomCrsValidation(CUSTOM_CRS_VALIDATION f)
Sets custom function to force valid CRS.
Definition: qgscoordinatereferencesystem.cpp:2117
QgsMapLayer::legendChanged
void legendChanged()
Signal emitted when legend of the layer has changed.
qgsmeshlayer.h
Qgs3DRendererRegistry::rendererMetadata
Qgs3DRendererAbstractMetadata * rendererMetadata(const QString &type) const
Returns metadata for a 3D renderer type (may be used to create a new instance of the type)
Definition: qgs3drendererregistry.cpp:48
qgsvectorlayer.h
QgsMapLayer::setMetadataUrlFormat
Q_DECL_DEPRECATED void setMetadataUrlFormat(const QString &metaUrlFormat)
Sets the metadata format of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.cpp:263
QgsMapLayer::isTemporary
virtual bool isTemporary() const
Returns true if the layer is considered a temporary layer.
Definition: qgsmaplayer.cpp:2036
QgsMapLayer::readSymbology
virtual bool readSymbology(const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories)=0
Read the symbology for the current layer from the DOM node supplied.
QgsMapLayer::setAttributionUrl
void setAttributionUrl(const QString &attribUrl)
Sets the attribution URL of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:409
QgsMapLayer::legendUrl
QString legendUrl() const
Returns the URL for the layer's legend.
Definition: qgsmaplayer.h:1287
QgsMapLayer::dataChanged
void dataChanged()
Data of layer changed.
QgsMapLayer::publicSource
QString publicSource() const
Gets a version of the internal layer definition that has sensitive bits removed (for example,...
Definition: qgsmaplayer.cpp:292
QgsPathResolver::readPath
QString readPath(const QString &filename) const
Turn filename read from the project file to an absolute path.
Definition: qgspathresolver.cpp:37
QgsProjectFileTransform
Class to convert from older project file versions to newer.
Definition: qgsprojectfiletransform.h:37
QgsMapLayer::source
QString source() const
Returns the source for the layer.
Definition: qgsmaplayer.cpp:300
QgsAuthManager::setMasterPassword
bool setMasterPassword(bool verify=false)
Main call to initially set or continually check master password is set.
Definition: qgsauthmanager.cpp:501
QgsMapLayer::setDataSource
void setDataSource(const QString &dataSource, const QString &baseName, const QString &provider, bool loadDefaultStyleFlag=false)
Updates the data source of the layer.
Definition: qgsmaplayer.cpp:1803
QgsMapLayer::mAbstract
QString mAbstract
Description of the layer.
Definition: qgsmaplayer.h:1950
QgsMapLayer::writeStyleManager
void writeStyleManager(QDomNode &layerNode, QDomDocument &doc) const
Write style manager's configuration (if exists). To be called by subclasses.
Definition: qgsmaplayer.cpp:809
QgsMapLayerServerProperties::copyTo
void copyTo(QgsMapLayerServerProperties *properties) const
Copy properties to another instance.
Definition: qgsmaplayerserverproperties.cpp:216
QgsMapLayer::setScaleBasedVisibility
void setScaleBasedVisibility(bool enabled)
Sets whether scale based visibility is enabled for the layer.
Definition: qgsmaplayer.cpp:899
QgsMapLayerStyleManager::addStyle
bool addStyle(const QString &name, const QgsMapLayerStyle &style)
Add a style with given name and data.
Definition: qgsmaplayerstylemanager.cpp:109
QgsMapLayer::writeSymbology
virtual bool writeSymbology(QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories) const =0
Write the style for the layer into the document provided.
QgsMapLayer::extensionPropertyType
static QString extensionPropertyType(PropertyType type)
Returns the extension of a Property.
Definition: qgsmaplayer.cpp:68
QgsMapLayer::customProperty
Q_INVOKABLE QVariant customProperty(const QString &value, const QVariant &defaultValue=QVariant()) const
Read a custom property from layer.
Definition: qgsmaplayer.cpp:1999
QgsMapLayer::transformContext
QgsCoordinateTransformContext transformContext() const
Returns the layer data provider coordinate transform context or a default transform context if the la...
Definition: qgsmaplayer.cpp:951
QgsObjectCustomProperties::contains
bool contains(const QString &key) const
Returns true if the properties contains a key with the specified name.
Definition: qgsobjectcustomproperties.cpp:46
QgsWkbTypes::GeometryType
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
Definition: qgswkbtypes.h:140
QgsProject::baseName
QString baseName() const
Returns the base name of the project file without the path and without extension - derived from fileN...
Definition: qgsproject.cpp:834
QgsApplication::renderer3DRegistry
static Qgs3DRendererRegistry * renderer3DRegistry()
Returns registry of available 3D renderers.
Definition: qgsapplication.cpp:2485
c
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
Definition: porting_processing.dox:1
QgsMapLayer::setRefreshOnNofifyMessage
void setRefreshOnNofifyMessage(const QString &message)
Set the notification message that triggers repaint If refresh on notification is enabled,...
Definition: qgsmaplayer.h:1606
QgsMapLayer::setName
void setName(const QString &name)
Set the display name of the layer.
Definition: qgsmaplayer.cpp:174
QgsMapLayer::setDataUrlFormat
void setDataUrlFormat(const QString &dataUrlFormat)
Sets the DataUrl format of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:371
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:391
QgsObjectCustomProperties
Simple key-value store (keys = strings, values = variants) that supports loading/saving to/from XML i...
Definition: qgsobjectcustomproperties.h:35
QgsMapLayer
Base class for all map layer types. This is the base class for all map layer types (vector,...
Definition: qgsmaplayer.h:72
QgsObjectCustomProperties::keys
QStringList keys() const
Returns a list of all stored keys.
Definition: qgsobjectcustomproperties.cpp:26
QgsMapLayerLegend::itemsChanged
void itemsChanged()
Emitted when existing items/nodes got invalid and should be replaced by new ones.
QgsMapLayerDependency
This class models dependencies with or between map layers.
Definition: qgsmaplayerdependency.h:37
QgsMapLayer::setLegendUrl
void setLegendUrl(const QString &legendUrl)
Sets the URL for the layer's legend.
Definition: qgsmaplayer.h:1282
QgsMapLayer::readLayerXml
bool readLayerXml(const QDomElement &layerElement, QgsReadWriteContext &context, QgsMapLayer::ReadFlags flags=QgsMapLayer::ReadFlags())
Sets state from DOM document.
Definition: qgsmaplayer.cpp:339
QgsObjectCustomProperties::value
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
Returns the value for the given key.
Definition: qgsobjectcustomproperties.cpp:36
QgsMapLayer::setAutoRefreshInterval
void setAutoRefreshInterval(int interval)
Sets the auto refresh interval (in milliseconds) for the layer.
Definition: qgsmaplayer.cpp:854
QgsMapLayer::invalidateWgs84Extent
void invalidateWgs84Extent()
Invalidates the WGS84 extent.
Definition: qgsmaplayer.cpp:2294
QgsFileUtils::representFileSize
static QString representFileSize(qint64 bytes)
Returns the human size from bytes.
Definition: qgsfileutils.cpp:41
QgsMapLayer::readXml
virtual bool readXml(const QDomNode &layer_node, QgsReadWriteContext &context)
Called by readLayerXML(), used by children to read state specific to them from project files.
Definition: qgsmaplayer.cpp:520
QgsMapLayer::Symbology
@ Symbology
Symbology.
Definition: qgsmaplayer.h:161
QgsMapLayer::loadDefaultMetadata
virtual QString loadDefaultMetadata(bool &resultFlag)
Retrieve the default metadata for this layer if one exists (either as a .qmd file on disk or as a rec...
Definition: qgsmaplayer.cpp:1040
QgsMapLayer::metadataUrl
Q_DECL_DEPRECATED QString metadataUrl() const
Returns the metadata URL of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.cpp:222
QgsDatumEnsemble::authority
QString authority() const
Authority name, e.g.
Definition: qgsdatums.h:117
QgsMapLayer::name
QString name
Definition: qgsmaplayer.h:76
QgsLayerNotesUtils::setLayerNotes
static void setLayerNotes(QgsMapLayer *layer, const QString &notes)
Sets the notes for the specified layer, where notes is a HTML formatted string.
Definition: qgslayernotesutils.cpp:27
QgsMapLayer::undoStackStyles
QUndoStack * undoStackStyles()
Returns pointer to layer's style undo stack.
Definition: qgsmaplayer.cpp:1966
qgsmaplayerlegend.h
QgsMapLayer::setAutoRefreshEnabled
void setAutoRefreshEnabled(bool enabled)
Sets whether auto refresh is enabled for the layer.
Definition: qgsmaplayer.cpp:868
QgsMapLayer::Notes
@ Notes
Layer user notes (since QGIS 3.20)
Definition: qgsmaplayer.h:177
QgsMapLayer::LayerConfiguration
@ LayerConfiguration
General configuration: identifiable, removable, searchable, display expression, read-only.
Definition: qgsmaplayer.h:160
Qgis::SCALE_PRECISION
static const double SCALE_PRECISION
Fudge factor used to compare two scales.
Definition: qgis.h:2022
QgsMapLayer::undoStack
QUndoStack * undoStack()
Returns pointer to layer's undo stack.
Definition: qgsmaplayer.cpp:1961
qgssqliteutils.h
QgsMapLayer::CustomProperties
@ CustomProperties
Custom properties (by plugins for instance)
Definition: qgsmaplayer.h:171
QgsMapLayer::setMinimumScale
void setMinimumScale(double scale)
Sets the minimum map scale (i.e.
Definition: qgsmaplayer.cpp:894
QgsMapLayer::setAttribution
void setAttribution(const QString &attrib)
Sets the attribution of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:391
QgsMapLayer::mRefreshOnNofifyMessage
QString mRefreshOnNofifyMessage
Definition: qgsmaplayer.h:1979
QgsMapLayer::readStyle
virtual bool readStyle(const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories)
Read the style for the current layer from the DOM node supplied.
Definition: qgsmaplayer.cpp:1782
QgsMapLayer::mLegendUrl
QString mLegendUrl
WMS legend.
Definition: qgsmaplayer.h:1962
QgsMapLayer::importNamedMetadata
bool importNamedMetadata(QDomDocument &document, QString &errorMessage)
Import the metadata of this layer from a QDomDocument.
Definition: qgsmaplayer.cpp:1215
QgsMapLayer::serverProperties
QgsMapLayerServerProperties * serverProperties()
Returns QGIS Server Properties for the map layer.
Definition: qgsmaplayer.h:426
QgsMapLayer::project
QgsProject * project() const
Returns the parent project if this map layer is added to a project.
Definition: qgsmaplayer.cpp:2237
QgsMapLayer::metadataUri
virtual QString metadataUri() const
Retrieve the metadata URI for this layer (either as a .qmd file on disk or as a record in the users s...
Definition: qgsmaplayer.cpp:1008
QgsMapLayer::setDependencies
virtual bool setDependencies(const QSet< QgsMapLayerDependency > &layers)
Sets the list of dependencies.
Definition: qgsmaplayer.cpp:2202
QgsCoordinateReferenceSystem::setValidationHint
void setValidationHint(const QString &html)
Set user hint for validation.
Definition: qgscoordinatereferencesystem.cpp:2149
QgsFileUtils::sidecarFilesForPath
static QSet< QString > sidecarFilesForPath(const QString &path)
Returns a list of the sidecar files which exist for the dataset a the specified path.
Definition: qgsfileutils.cpp:380
QgsNotSupportedException
Custom exception class which is raised when an operation is not supported.
Definition: qgsexception.h:117
QgsMapLayer::isSpatial
virtual bool isSpatial() const
Returns true if the layer is considered a spatial layer, ie it has some form of geometry associated w...
Definition: qgsmaplayer.cpp:2031
QgsDataSourceUri::removePassword
static QString removePassword(const QString &aUri)
Removes the password element from a URI.
Definition: qgsdatasourceuri.cpp:221
QgsMapLayerStyleManager::writeXml
void writeXml(QDomElement &mgrElement) const
Write configuration (for project saving)
Definition: qgsmaplayerstylemanager.cpp:71
qgslogger.h
QgsMapLayer::setDataUrl
void setDataUrl(const QString &dataUrl)
Sets the DataUrl of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:353
QgsMapLayer::setValid
void setValid(bool valid)
Sets whether layer is valid or not.
Definition: qgsmaplayer.cpp:2061
QgsMapLayer::AllStyleCategories
@ AllStyleCategories
Definition: qgsmaplayer.h:178
QgsMapLayer::trigger3DUpdate
void trigger3DUpdate()
Will advise any 3D maps that this layer requires to be updated in the scene.
Definition: qgsmaplayer.cpp:2123
QgsCoordinateTransform
Class for doing transforms between two map coordinate systems.
Definition: qgscoordinatetransform.h:57
sqlite3_database_unique_ptr
Unique pointer for sqlite3 databases, which automatically closes the database when the pointer goes o...
Definition: qgssqliteutils.h:118
QgsMapLayer::mBlockStyleChangedSignal
int mBlockStyleChangedSignal
If non-zero, the styleChanged signal should not be emitted.
Definition: qgsmaplayer.h:2008
QgsVectorLayer::geometryType
Q_INVOKABLE QgsWkbTypes::GeometryType geometryType() const
Returns point, line or polygon.
Definition: qgsvectorlayer.cpp:720
QgsMapLayer::setShortName
void setShortName(const QString &shortName)
Sets the short name of the layer used by QGIS Server to identify the layer.
Definition: qgsmaplayer.h:288
QgsProviderRegistry::instance
static QgsProviderRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.
Definition: qgsproviderregistry.cpp:73
QgsMapLayer::attribution
QString attribution() const
Returns the attribution of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:400
QgsMapLayer::metadataUrlType
Q_DECL_DEPRECATED QString metadataUrlType() const
Returns the metadata type of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.cpp:251
QgsMapLayer::exportSldStyle
virtual void exportSldStyle(QDomDocument &doc, QString &errorMsg) const
Export the properties of this layer as SLD style in a QDomDocument.
Definition: qgsmaplayer.cpp:1581
QgsMapLayer::customPropertyChanged
void customPropertyChanged(const QString &key)
Emitted when a custom property of the layer has been changed or removed.
QgsMapLayer::loadNamedStyle
virtual QString loadNamedStyle(const QString &uri, bool &resultFlag, QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories)
Retrieve a named style for this layer if one exists (either as a .qml file on disk or as a record in ...
Definition: qgsmaplayer.cpp:1116
QgsMapLayer::setProviderType
void setProviderType(const QString &providerType)
Sets the providerType (provider key)
Definition: qgsmaplayer.cpp:2192
qgscoordinatereferencesystem.h
QgsDatumEnsemble::name
QString name() const
Display name of datum ensemble.
Definition: qgsdatums.h:107
QgsMapLayer::renderer3DChanged
void renderer3DChanged()
Signal emitted when 3D renderer associated with the layer has changed.
QgsMapLayer::loadNamedMetadata
virtual QString loadNamedMetadata(const QString &uri, bool &resultFlag)
Retrieve a named metadata for this layer if one exists (either as a .qmd file on disk or as a record ...
Definition: qgsmaplayer.cpp:1340
QgsMapLayerServerProperties::readXml
void readXml(const QDomNode &layer_node)
Reads server properties from project file.
Definition: qgsmaplayerserverproperties.cpp:228
QgsMapLayer::mKeywordList
QString mKeywordList
Definition: qgsmaplayer.h:1951
QgsRectangle::isNull
bool isNull() const
Test if the rectangle is null (all coordinates zero or after call to setMinimal()).
Definition: qgsrectangle.h:479
qgsproject.h
QgsMapLayer::setLegend
void setLegend(QgsMapLayerLegend *legend)
Assign a legend controller to the map layer.
Definition: qgsmaplayer.cpp:2070
QgsMapLayer::elevationProperties
virtual QgsMapLayerElevationProperties * elevationProperties()
Returns the layer's elevation properties.
Definition: qgsmaplayer.h:1509
QgsDatumEnsemble::isValid
bool isValid() const
Returns true if the datum ensemble is a valid object, or false if it is a null/invalid object.
Definition: qgsdatums.h:102
QgsMapLayer::autoRefreshIntervalChanged
void autoRefreshIntervalChanged(int interval)
Emitted when the auto refresh interval changes.
QgsProjectVersion
A class to describe the version of a project.
Definition: qgsprojectversion.h:32
sqlite3_statement_unique_ptr
Unique pointer for sqlite3 prepared statements, which automatically finalizes the statement when the ...
Definition: qgssqliteutils.h:69
QgsObjectCustomProperties::writeXml
void writeXml(QDomNode &parentNode, QDomDocument &doc) const
Writes the store contents to an XML node.
Definition: qgsobjectcustomproperties.cpp:130
QgsMapLayer::writeStyle
virtual bool writeStyle(QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories) const
Write just the symbology information for the layer into the document.
Definition: qgsmaplayer.cpp:1791
QgsMapLayer::mShortName
QString mShortName
Definition: qgsmaplayer.h:1946
QgsMapLayer::timestamp
virtual QDateTime timestamp() const
Time stamp of data source in the moment when data/metadata were loaded by provider.
Definition: qgsmaplayer.cpp:2140
QgsMapLayer::setLayerOrder
virtual void setLayerOrder(const QStringList &layers)
Reorders the previously selected sublayers of this layer from bottom to top.
Definition: qgsmaplayer.cpp:914
QgsDatumEnsemble
Contains information about a datum ensemble.
Definition: qgsdatums.h:94
QgsDatumEnsemble::code
QString code() const
Identification code, e.g.
Definition: qgsdatums.h:122
QgsRasterLayer::writeSld
bool writeSld(QDomNode &node, QDomDocument &doc, QString &errorMessage, const QVariantMap &props=QVariantMap()) const
Writes the symbology of the layer into the document provided in SLD 1.0.0 format.
Definition: qgsrasterlayer.cpp:1537
QgsProjectTranslator::translate
virtual QString translate(const QString &context, const QString &sourceText, const char *disambiguation=nullptr, int n=-1) const =0
The derived translate() translates with QTranslator and qm file the sourceText.
qgsmaplayerelevationproperties.h
QgsDataProvider::setListening
virtual void setListening(bool isListening)
Set whether the provider will listen to datasource notifications If set, the provider will issue noti...
Definition: qgsdataprovider.cpp:71
QgsReadWriteContext::pathResolver
const QgsPathResolver & pathResolver() const
Returns path resolver for conversion between relative and absolute paths.
Definition: qgsreadwritecontext.cpp:47
QgsMapLayer::metadataChanged
void metadataChanged()
Emitted when the layer's metadata is changed.
QgsXmlUtils::writeRectangle
static QDomElement writeRectangle(const QgsRectangle &rect, QDomDocument &doc, const QString &elementName=QStringLiteral("extent"))
Encodes a rectangle to a DOM element.
Definition: qgsxmlutils.cpp:81
qgsmessagelog.h
QgsMapLayer::error
virtual QgsError error() const
Gets current status error.
Definition: qgsmaplayer.cpp:2014
QgsXmlUtils::readRectangle
static QgsRectangle readRectangle(const QDomElement &element)
Definition: qgsxmlutils.cpp:39
QgsMapLayer::type
QgsMapLayerType type
Definition: qgsmaplayer.h:80