QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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 <QDir>
20 #include <QDomDocument>
21 #include <QDomElement>
22 #include <QDomImplementation>
23 #include <QDomNode>
24 #include <QFile>
25 #include <QFileInfo>
26 #include <QTextStream>
27 #include <QUrl>
28 
29 #include <sqlite3.h>
30 
31 #include "qgssqliteutils.h"
32 
33 #include "qgssqliteutils.h"
34 #include "qgs3drendererregistry.h"
35 #include "qgsabstract3drenderer.h"
36 #include "qgsapplication.h"
38 #include "qgsdatasourceuri.h"
39 #include "qgslogger.h"
40 #include "qgsauthmanager.h"
41 #include "qgsmaplayer.h"
42 #include "qgsmaplayerlegend.h"
44 #include "qgsmeshlayer.h"
45 #include "qgspathresolver.h"
47 #include "qgsproject.h"
48 #include "qgsproviderregistry.h"
49 #include "qgsrasterlayer.h"
50 #include "qgsreadwritecontext.h"
51 #include "qgsrectangle.h"
52 #include "qgsvectorlayer.h"
53 #include "qgsvectordataprovider.h"
54 #include "qgsxmlutils.h"
55 #include "qgsstringutils.h"
57 
59 {
60  switch ( type )
61  {
62  case Metadata:
63  return QStringLiteral( ".qmd" );
64 
65  case Style:
66  return QStringLiteral( ".qml" );
67  }
68  return QString();
69 }
70 
72  const QString &lyrname,
73  const QString &source )
74  : mDataSource( source )
75  , mLayerName( lyrname )
76  , mLayerType( type )
77  , mUndoStack( new QUndoStack( this ) )
78  , mUndoStackStyles( new QUndoStack( this ) )
79  , mStyleManager( new QgsMapLayerStyleManager( this ) )
80  , mRefreshTimer( new QTimer( this ) )
81 {
82  mID = generateId( lyrname );
83  connect( this, &QgsMapLayer::crsChanged, this, &QgsMapLayer::configChanged );
84  connect( this, &QgsMapLayer::nameChanged, this, &QgsMapLayer::configChanged );
85  connect( mRefreshTimer, &QTimer::timeout, this, [ = ] { triggerRepaint( true ); } );
86 }
87 
89 {
90  delete m3DRenderer;
91  delete mLegend;
92  delete mStyleManager;
93 }
94 
95 void QgsMapLayer::clone( QgsMapLayer *layer ) const
96 {
97  layer->setBlendMode( blendMode() );
98 
99  const auto constStyles = styleManager()->styles();
100  for ( const QString &s : constStyles )
101  {
102  layer->styleManager()->addStyle( s, styleManager()->style( s ) );
103  }
104 
105  layer->setName( name() );
106  layer->setShortName( shortName() );
107  layer->setExtent( extent() );
108  layer->setMaximumScale( maximumScale() );
109  layer->setMinimumScale( minimumScale() );
111  layer->setTitle( title() );
112  layer->setAbstract( abstract() );
113  layer->setKeywordList( keywordList() );
114  layer->setDataUrl( dataUrl() );
115  layer->setDataUrlFormat( dataUrlFormat() );
116  layer->setAttribution( attribution() );
117  layer->setAttributionUrl( attributionUrl() );
118  layer->setMetadataUrl( metadataUrl() );
121  layer->setLegendUrl( legendUrl() );
123  layer->setDependencies( dependencies() );
125  layer->setCrs( crs() );
126  layer->setCustomProperties( mCustomProperties );
127 }
128 
130 {
131  return mLayerType;
132 }
133 
134 QgsMapLayer::LayerFlags QgsMapLayer::flags() const
135 {
136  return mFlags;
137 }
138 
139 void QgsMapLayer::setFlags( QgsMapLayer::LayerFlags flags )
140 {
141  if ( flags == mFlags )
142  return;
143 
144  mFlags = flags;
145  emit flagsChanged();
146 }
147 
148 QString QgsMapLayer::id() const
149 {
150  return mID;
151 }
152 
153 void QgsMapLayer::setName( const QString &name )
154 {
155  if ( name == mLayerName )
156  return;
157 
158  mLayerName = name;
159 
160  emit nameChanged();
161 }
162 
163 QString QgsMapLayer::name() const
164 {
165  QgsDebugMsgLevel( "returning name '" + mLayerName + '\'', 4 );
166  return mLayerName;
167 }
168 
170 {
171  return nullptr;
172 }
173 
175 {
176  return nullptr;
177 }
178 
179 QString QgsMapLayer::shortName() const
180 {
181  return mShortName;
182 }
183 
185 {
186  // Redo this every time we're asked for it, as we don't know if
187  // dataSource has changed.
188  QString safeName = QgsDataSourceUri::removePassword( mDataSource );
189  return safeName;
190 }
191 
192 QString QgsMapLayer::source() const
193 {
194  return mDataSource;
195 }
196 
198 {
199  return mExtent;
200 }
201 
202 void QgsMapLayer::setBlendMode( const QPainter::CompositionMode blendMode )
203 {
204  if ( mBlendMode == blendMode )
205  return;
206 
207  mBlendMode = blendMode;
208  emit blendModeChanged( blendMode );
209  emit styleChanged();
210 }
211 
212 QPainter::CompositionMode QgsMapLayer::blendMode() const
213 {
214  return mBlendMode;
215 }
216 
217 
218 bool QgsMapLayer::readLayerXml( const QDomElement &layerElement, QgsReadWriteContext &context, QgsMapLayer::ReadFlags flags )
219 {
220  bool layerError;
221  mReadFlags = flags;
222 
223  QDomNode mnl;
224  QDomElement mne;
225 
226  // read provider
227  QString provider;
228  mnl = layerElement.namedItem( QStringLiteral( "provider" ) );
229  mne = mnl.toElement();
230  provider = mne.text();
231 
232  // set data source
233  mnl = layerElement.namedItem( QStringLiteral( "datasource" ) );
234  mne = mnl.toElement();
235  mDataSource = mne.text();
236 
237  // if the layer needs authentication, ensure the master password is set
238  QRegExp rx( "authcfg=([a-z]|[A-Z]|[0-9]){7}" );
239  if ( ( rx.indexIn( mDataSource ) != -1 )
241  {
242  return false;
243  }
244 
245  mDataSource = decodedSource( mDataSource, provider, context );
246 
247  // Set the CRS from project file, asking the user if necessary.
248  // Make it the saved CRS to have WMS layer projected correctly.
249  // We will still overwrite whatever GDAL etc picks up anyway
250  // further down this function.
251  mnl = layerElement.namedItem( QStringLiteral( "layername" ) );
252  mne = mnl.toElement();
253 
255  CUSTOM_CRS_VALIDATION savedValidation;
256 
257  QDomNode srsNode = layerElement.namedItem( QStringLiteral( "srs" ) );
258  mCRS.readXml( srsNode );
259  mCRS.setValidationHint( tr( "Specify CRS for layer %1" ).arg( mne.text() ) );
261  mCRS.validate();
262  savedCRS = mCRS;
263 
264  // Do not validate any projections in children, they will be overwritten anyway.
265  // No need to ask the user for a projections when it is overwritten, is there?
268 
269  QgsReadWriteContextCategoryPopper p = context.enterCategory( tr( "Layer" ), mne.text() );
270 
271  // the internal name is just the data source basename
272  //QFileInfo dataSourceFileInfo( mDataSource );
273  //internalName = dataSourceFileInfo.baseName();
274 
275  // set ID
276  mnl = layerElement.namedItem( QStringLiteral( "id" ) );
277  if ( ! mnl.isNull() )
278  {
279  mne = mnl.toElement();
280  if ( ! mne.isNull() && mne.text().length() > 10 ) // should be at least 17 (yyyyMMddhhmmsszzz)
281  {
282  mID = mne.text();
283  }
284  }
285 
286  setAutoRefreshInterval( layerElement.attribute( QStringLiteral( "autoRefreshTime" ), QStringLiteral( "0" ) ).toInt() );
287  setAutoRefreshEnabled( layerElement.attribute( QStringLiteral( "autoRefreshEnabled" ), QStringLiteral( "0" ) ).toInt() );
288  setRefreshOnNofifyMessage( layerElement.attribute( QStringLiteral( "refreshOnNotifyMessage" ), QString() ) );
289  setRefreshOnNotifyEnabled( layerElement.attribute( QStringLiteral( "refreshOnNotifyEnabled" ), QStringLiteral( "0" ) ).toInt() );
290 
291  // set name
292  mnl = layerElement.namedItem( QStringLiteral( "layername" ) );
293  mne = mnl.toElement();
294 
295  //name can be translated
296  setName( context.projectTranslator()->translate( QStringLiteral( "project:layers:%1" ).arg( layerElement.namedItem( QStringLiteral( "id" ) ).toElement().text() ), mne.text() ) );
297 
298  // now let the children grab what they need from the Dom node.
299  layerError = !readXml( layerElement, context );
300 
301  // overwrite CRS with what we read from project file before the raster/vector
302  // file reading functions changed it. They will if projections is specified in the file.
303  // FIXME: is this necessary? Yes, it is (autumn 2019)
305  mCRS = savedCRS;
306 
307  //short name
308  QDomElement shortNameElem = layerElement.firstChildElement( QStringLiteral( "shortname" ) );
309  if ( !shortNameElem.isNull() )
310  {
311  mShortName = shortNameElem.text();
312  }
313 
314  //title
315  QDomElement titleElem = layerElement.firstChildElement( QStringLiteral( "title" ) );
316  if ( !titleElem.isNull() )
317  {
318  mTitle = titleElem.text();
319  }
320 
321  //abstract
322  QDomElement abstractElem = layerElement.firstChildElement( QStringLiteral( "abstract" ) );
323  if ( !abstractElem.isNull() )
324  {
325  mAbstract = abstractElem.text();
326  }
327 
328  //keywordList
329  QDomElement keywordListElem = layerElement.firstChildElement( QStringLiteral( "keywordList" ) );
330  if ( !keywordListElem.isNull() )
331  {
332  QStringList kwdList;
333  for ( QDomNode n = keywordListElem.firstChild(); !n.isNull(); n = n.nextSibling() )
334  {
335  kwdList << n.toElement().text();
336  }
337  mKeywordList = kwdList.join( QLatin1String( ", " ) );
338  }
339 
340  //metadataUrl
341  QDomElement dataUrlElem = layerElement.firstChildElement( QStringLiteral( "dataUrl" ) );
342  if ( !dataUrlElem.isNull() )
343  {
344  mDataUrl = dataUrlElem.text();
345  mDataUrlFormat = dataUrlElem.attribute( QStringLiteral( "format" ), QString() );
346  }
347 
348  //legendUrl
349  QDomElement legendUrlElem = layerElement.firstChildElement( QStringLiteral( "legendUrl" ) );
350  if ( !legendUrlElem.isNull() )
351  {
352  mLegendUrl = legendUrlElem.text();
353  mLegendUrlFormat = legendUrlElem.attribute( QStringLiteral( "format" ), QString() );
354  }
355 
356  //attribution
357  QDomElement attribElem = layerElement.firstChildElement( QStringLiteral( "attribution" ) );
358  if ( !attribElem.isNull() )
359  {
360  mAttribution = attribElem.text();
361  mAttributionUrl = attribElem.attribute( QStringLiteral( "href" ), QString() );
362  }
363 
364  //metadataUrl
365  QDomElement metaUrlElem = layerElement.firstChildElement( QStringLiteral( "metadataUrl" ) );
366  if ( !metaUrlElem.isNull() )
367  {
368  mMetadataUrl = metaUrlElem.text();
369  mMetadataUrlType = metaUrlElem.attribute( QStringLiteral( "type" ), QString() );
370  mMetadataUrlFormat = metaUrlElem.attribute( QStringLiteral( "format" ), QString() );
371  }
372 
373  // mMetadata.readFromLayer( this );
374  QDomElement metadataElem = layerElement.firstChildElement( QStringLiteral( "resourceMetadata" ) );
375  mMetadata.readMetadataXml( metadataElem );
376 
377  return ! layerError;
378 } // bool QgsMapLayer::readLayerXML
379 
380 
381 bool QgsMapLayer::readXml( const QDomNode &layer_node, QgsReadWriteContext &context )
382 {
383  Q_UNUSED( layer_node )
384  Q_UNUSED( context )
385  // NOP by default; children will over-ride with behavior specific to them
386 
387  return true;
388 } // void QgsMapLayer::readXml
389 
390 
391 bool QgsMapLayer::writeLayerXml( QDomElement &layerElement, QDomDocument &document, const QgsReadWriteContext &context ) const
392 {
393  if ( !extent().isNull() )
394  {
395  layerElement.appendChild( QgsXmlUtils::writeRectangle( mExtent, document ) );
396  }
397 
398  layerElement.setAttribute( QStringLiteral( "autoRefreshTime" ), QString::number( mRefreshTimer->interval() ) );
399  layerElement.setAttribute( QStringLiteral( "autoRefreshEnabled" ), mRefreshTimer->isActive() ? 1 : 0 );
400  layerElement.setAttribute( QStringLiteral( "refreshOnNotifyEnabled" ), mIsRefreshOnNofifyEnabled ? 1 : 0 );
401  layerElement.setAttribute( QStringLiteral( "refreshOnNotifyMessage" ), mRefreshOnNofifyMessage );
402 
403 
404  // ID
405  QDomElement layerId = document.createElement( QStringLiteral( "id" ) );
406  QDomText layerIdText = document.createTextNode( id() );
407  layerId.appendChild( layerIdText );
408 
409  layerElement.appendChild( layerId );
410 
411  // data source
412  QDomElement dataSource = document.createElement( QStringLiteral( "datasource" ) );
413  QString src = encodedSource( source(), context );
414  QDomText dataSourceText = document.createTextNode( src );
415  dataSource.appendChild( dataSourceText );
416  layerElement.appendChild( dataSource );
417 
418  // layer name
419  QDomElement layerName = document.createElement( QStringLiteral( "layername" ) );
420  QDomText layerNameText = document.createTextNode( name() );
421  layerName.appendChild( layerNameText );
422  layerElement.appendChild( layerName );
423 
424  // layer short name
425  if ( !mShortName.isEmpty() )
426  {
427  QDomElement layerShortName = document.createElement( QStringLiteral( "shortname" ) );
428  QDomText layerShortNameText = document.createTextNode( mShortName );
429  layerShortName.appendChild( layerShortNameText );
430  layerElement.appendChild( layerShortName );
431  }
432 
433  // layer title
434  if ( !mTitle.isEmpty() )
435  {
436  QDomElement layerTitle = document.createElement( QStringLiteral( "title" ) );
437  QDomText layerTitleText = document.createTextNode( mTitle );
438  layerTitle.appendChild( layerTitleText );
439  layerElement.appendChild( layerTitle );
440  }
441 
442  // layer abstract
443  if ( !mAbstract.isEmpty() )
444  {
445  QDomElement layerAbstract = document.createElement( QStringLiteral( "abstract" ) );
446  QDomText layerAbstractText = document.createTextNode( mAbstract );
447  layerAbstract.appendChild( layerAbstractText );
448  layerElement.appendChild( layerAbstract );
449  }
450 
451  // layer keyword list
452  QStringList keywordStringList = keywordList().split( ',' );
453  if ( !keywordStringList.isEmpty() )
454  {
455  QDomElement layerKeywordList = document.createElement( QStringLiteral( "keywordList" ) );
456  for ( int i = 0; i < keywordStringList.size(); ++i )
457  {
458  QDomElement layerKeywordValue = document.createElement( QStringLiteral( "value" ) );
459  QDomText layerKeywordText = document.createTextNode( keywordStringList.at( i ).trimmed() );
460  layerKeywordValue.appendChild( layerKeywordText );
461  layerKeywordList.appendChild( layerKeywordValue );
462  }
463  layerElement.appendChild( layerKeywordList );
464  }
465 
466  // layer metadataUrl
467  QString aDataUrl = dataUrl();
468  if ( !aDataUrl.isEmpty() )
469  {
470  QDomElement layerDataUrl = document.createElement( QStringLiteral( "dataUrl" ) );
471  QDomText layerDataUrlText = document.createTextNode( aDataUrl );
472  layerDataUrl.appendChild( layerDataUrlText );
473  layerDataUrl.setAttribute( QStringLiteral( "format" ), dataUrlFormat() );
474  layerElement.appendChild( layerDataUrl );
475  }
476 
477  // layer legendUrl
478  QString aLegendUrl = legendUrl();
479  if ( !aLegendUrl.isEmpty() )
480  {
481  QDomElement layerLegendUrl = document.createElement( QStringLiteral( "legendUrl" ) );
482  QDomText layerLegendUrlText = document.createTextNode( aLegendUrl );
483  layerLegendUrl.appendChild( layerLegendUrlText );
484  layerLegendUrl.setAttribute( QStringLiteral( "format" ), legendUrlFormat() );
485  layerElement.appendChild( layerLegendUrl );
486  }
487 
488  // layer attribution
489  QString aAttribution = attribution();
490  if ( !aAttribution.isEmpty() )
491  {
492  QDomElement layerAttribution = document.createElement( QStringLiteral( "attribution" ) );
493  QDomText layerAttributionText = document.createTextNode( aAttribution );
494  layerAttribution.appendChild( layerAttributionText );
495  layerAttribution.setAttribute( QStringLiteral( "href" ), attributionUrl() );
496  layerElement.appendChild( layerAttribution );
497  }
498 
499  // layer metadataUrl
500  QString aMetadataUrl = metadataUrl();
501  if ( !aMetadataUrl.isEmpty() )
502  {
503  QDomElement layerMetadataUrl = document.createElement( QStringLiteral( "metadataUrl" ) );
504  QDomText layerMetadataUrlText = document.createTextNode( aMetadataUrl );
505  layerMetadataUrl.appendChild( layerMetadataUrlText );
506  layerMetadataUrl.setAttribute( QStringLiteral( "type" ), metadataUrlType() );
507  layerMetadataUrl.setAttribute( QStringLiteral( "format" ), metadataUrlFormat() );
508  layerElement.appendChild( layerMetadataUrl );
509  }
510 
511  // timestamp if supported
512  if ( timestamp() > QDateTime() )
513  {
514  QDomElement stamp = document.createElement( QStringLiteral( "timestamp" ) );
515  QDomText stampText = document.createTextNode( timestamp().toString( Qt::ISODate ) );
516  stamp.appendChild( stampText );
517  layerElement.appendChild( stamp );
518  }
519 
520  layerElement.appendChild( layerName );
521 
522  // zorder
523  // This is no longer stored in the project file. It is superfluous since the layers
524  // are written and read in the proper order.
525 
526  // spatial reference system id
527  QDomElement mySrsElement = document.createElement( QStringLiteral( "srs" ) );
528  mCRS.writeXml( mySrsElement, document );
529  layerElement.appendChild( mySrsElement );
530 
531  // layer metadata
532  QDomElement myMetadataElem = document.createElement( QStringLiteral( "resourceMetadata" ) );
533  mMetadata.writeMetadataXml( myMetadataElem, document );
534  layerElement.appendChild( myMetadataElem );
535 
536  // now append layer node to map layer node
537  return writeXml( layerElement, document, context );
538 }
539 
540 void QgsMapLayer::writeCommonStyle( QDomElement &layerElement, QDomDocument &document,
541  const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories ) const
542 {
543  // save categories
544  QMetaEnum metaEnum = QMetaEnum::fromType<QgsMapLayer::StyleCategories>();
545  QString categoriesKeys( metaEnum.valueToKeys( static_cast<int>( categories ) ) );
546  layerElement.setAttribute( QStringLiteral( "styleCategories" ), categoriesKeys );
547 
548  if ( categories.testFlag( Rendering ) )
549  {
550  // use scale dependent visibility flag
551  layerElement.setAttribute( QStringLiteral( "hasScaleBasedVisibilityFlag" ), hasScaleBasedVisibility() ? 1 : 0 );
552  layerElement.setAttribute( QStringLiteral( "maxScale" ), QString::number( maximumScale() ) );
553  layerElement.setAttribute( QStringLiteral( "minScale" ), QString::number( minimumScale() ) );
554  }
555 
556  if ( categories.testFlag( Symbology3D ) )
557  {
558  if ( m3DRenderer )
559  {
560  QDomElement renderer3DElem = document.createElement( QStringLiteral( "renderer-3d" ) );
561  renderer3DElem.setAttribute( QStringLiteral( "type" ), m3DRenderer->type() );
562  m3DRenderer->writeXml( renderer3DElem, context );
563  layerElement.appendChild( renderer3DElem );
564  }
565  }
566 
567  if ( categories.testFlag( LayerConfiguration ) )
568  {
569  // flags
570  // this code is saving automatically all the flags entries
571  QDomElement layerFlagsElem = document.createElement( QStringLiteral( "flags" ) );
572  auto enumMap = qgsEnumMap<QgsMapLayer::LayerFlag>();
573  for ( auto it = enumMap.constBegin(); it != enumMap.constEnd(); ++it )
574  {
575  bool flagValue = mFlags.testFlag( it.key() );
576  QDomElement flagElem = document.createElement( it.value() );
577  flagElem.appendChild( document.createTextNode( QString::number( flagValue ) ) );
578  layerFlagsElem.appendChild( flagElem );
579  }
580  layerElement.appendChild( layerFlagsElem );
581  }
582 
583  if ( categories.testFlag( Temporal ) )
584  {
585  QgsMapLayerTemporalProperties *lTemporalProperties = const_cast< QgsMapLayer * >( this )->temporalProperties();
586  if ( lTemporalProperties )
587  lTemporalProperties->writeXml( layerElement, document, context );
588  }
589 
590  // custom properties
591  if ( categories.testFlag( CustomProperties ) )
592  {
593  writeCustomProperties( layerElement, document );
594  }
595 }
596 
597 
598 bool QgsMapLayer::writeXml( QDomNode &layer_node, QDomDocument &document, const QgsReadWriteContext &context ) const
599 {
600  Q_UNUSED( layer_node )
601  Q_UNUSED( document )
602  Q_UNUSED( context )
603  // NOP by default; children will over-ride with behavior specific to them
604 
605  return true;
606 }
607 
608 QString QgsMapLayer::encodedSource( const QString &source, const QgsReadWriteContext &context ) const
609 {
610  Q_UNUSED( context )
611  return source;
612 }
613 
614 QString QgsMapLayer::decodedSource( const QString &source, const QString &dataProvider, const QgsReadWriteContext &context ) const
615 {
616  Q_UNUSED( context )
617  Q_UNUSED( dataProvider )
618  return source;
619 }
620 
622 {
623  emit beforeResolveReferences( project );
624  if ( m3DRenderer )
625  m3DRenderer->resolveReferences( *project );
626 }
627 
628 
629 void QgsMapLayer::readCustomProperties( const QDomNode &layerNode, const QString &keyStartsWith )
630 {
631  mCustomProperties.readXml( layerNode, keyStartsWith );
632 }
633 
634 void QgsMapLayer::writeCustomProperties( QDomNode &layerNode, QDomDocument &doc ) const
635 {
636  mCustomProperties.writeXml( layerNode, doc );
637 }
638 
639 void QgsMapLayer::readStyleManager( const QDomNode &layerNode )
640 {
641  QDomElement styleMgrElem = layerNode.firstChildElement( QStringLiteral( "map-layer-style-manager" ) );
642  if ( !styleMgrElem.isNull() )
643  mStyleManager->readXml( styleMgrElem );
644  else
645  mStyleManager->reset();
646 }
647 
648 void QgsMapLayer::writeStyleManager( QDomNode &layerNode, QDomDocument &doc ) const
649 {
650  if ( mStyleManager )
651  {
652  QDomElement styleMgrElem = doc.createElement( QStringLiteral( "map-layer-style-manager" ) );
653  mStyleManager->writeXml( styleMgrElem );
654  layerNode.appendChild( styleMgrElem );
655  }
656 }
657 
659 {
660  return mValid;
661 }
662 
663 #if 0
664 void QgsMapLayer::connectNotify( const char *signal )
665 {
666  Q_UNUSED( signal )
667  QgsDebugMsgLevel( "QgsMapLayer connected to " + QString( signal ), 3 );
668 } // QgsMapLayer::connectNotify
669 #endif
670 
671 bool QgsMapLayer::isInScaleRange( double scale ) const
672 {
673  return !mScaleBasedVisibility ||
674  ( ( mMinScale == 0 || mMinScale * Qgis::SCALE_PRECISION < scale )
675  && ( mMaxScale == 0 || scale < mMaxScale ) );
676 }
677 
679 {
680  return mScaleBasedVisibility;
681 }
682 
684 {
685  return mRefreshTimer->isActive();
686 }
687 
689 {
690  return mRefreshTimer->interval();
691 }
692 
694 {
695  if ( interval <= 0 )
696  {
697  mRefreshTimer->stop();
698  mRefreshTimer->setInterval( 0 );
699  }
700  else
701  {
702  mRefreshTimer->setInterval( interval );
703  }
704  emit autoRefreshIntervalChanged( mRefreshTimer->isActive() ? mRefreshTimer->interval() : 0 );
705 }
706 
708 {
709  if ( !enabled )
710  mRefreshTimer->stop();
711  else if ( mRefreshTimer->interval() > 0 )
712  mRefreshTimer->start();
713 
714  emit autoRefreshIntervalChanged( mRefreshTimer->isActive() ? mRefreshTimer->interval() : 0 );
715 }
716 
718 {
719  return mMetadata;
720 }
721 
722 void QgsMapLayer::setMaximumScale( double scale )
723 {
724  mMinScale = scale;
725 }
726 
728 {
729  return mMinScale;
730 }
731 
732 
733 void QgsMapLayer::setMinimumScale( double scale )
734 {
735  mMaxScale = scale;
736 }
737 
738 void QgsMapLayer::setScaleBasedVisibility( const bool enabled )
739 {
740  mScaleBasedVisibility = enabled;
741 }
742 
744 {
745  return mMaxScale;
746 }
747 
748 QStringList QgsMapLayer::subLayers() const
749 {
750  return QStringList(); // Empty
751 }
752 
753 void QgsMapLayer::setLayerOrder( const QStringList &layers )
754 {
755  Q_UNUSED( layers )
756  // NOOP
757 }
758 
759 void QgsMapLayer::setSubLayerVisibility( const QString &name, bool vis )
760 {
761  Q_UNUSED( name )
762  Q_UNUSED( vis )
763  // NOOP
764 }
765 
767 {
768  return mCRS;
769 }
770 
771 void QgsMapLayer::setCrs( const QgsCoordinateReferenceSystem &srs, bool emitSignal )
772 {
773  mCRS = srs;
774 
776  {
777  mCRS.setValidationHint( tr( "Specify CRS for layer %1" ).arg( name() ) );
778  mCRS.validate();
779  }
780 
781  if ( emitSignal )
782  emit crsChanged();
783 }
784 
786 {
787  const QgsDataProvider *lDataProvider = dataProvider();
788  return lDataProvider ? lDataProvider->transformContext() : QgsCoordinateTransformContext();
789 }
790 
791 QString QgsMapLayer::formatLayerName( const QString &name )
792 {
793  QString layerName( name );
794  layerName.replace( '_', ' ' );
796  return layerName;
797 }
798 
799 QString QgsMapLayer::baseURI( PropertyType type ) const
800 {
801  QString myURI = publicSource();
802 
803  // first get base path for delimited text, spatialite and OGR layers,
804  // as in these cases URI may contain layer name and/or additional
805  // information. This also strips prefix in case if VSIFILE mechanism
806  // is used
807  if ( providerType() == QLatin1String( "ogr" ) || providerType() == QLatin1String( "delimitedtext" ) ||
808  providerType() == QLatin1String( "spatialite" ) )
809  {
810  QVariantMap components = QgsProviderRegistry::instance()->decodeUri( providerType(), myURI );
811  myURI = components["path"].toString();
812  }
813 
814  QFileInfo myFileInfo( myURI );
815  QString key;
816 
817  if ( myFileInfo.exists() )
818  {
819  // if file is using the /vsizip/ or /vsigzip/ mechanism, cleanup the name
820  if ( myURI.endsWith( QLatin1String( ".gz" ), Qt::CaseInsensitive ) )
821  myURI.chop( 3 );
822  else if ( myURI.endsWith( QLatin1String( ".zip" ), Qt::CaseInsensitive ) )
823  myURI.chop( 4 );
824  else if ( myURI.endsWith( QLatin1String( ".tar" ), Qt::CaseInsensitive ) )
825  myURI.chop( 4 );
826  else if ( myURI.endsWith( QLatin1String( ".tar.gz" ), Qt::CaseInsensitive ) )
827  myURI.chop( 7 );
828  else if ( myURI.endsWith( QLatin1String( ".tgz" ), Qt::CaseInsensitive ) )
829  myURI.chop( 4 );
830  myFileInfo.setFile( myURI );
831  // get the file name for our .qml style file
832  key = myFileInfo.path() + QDir::separator() + myFileInfo.completeBaseName() + QgsMapLayer::extensionPropertyType( type );
833  }
834  else
835  {
836  key = publicSource();
837  }
838 
839  return key;
840 }
841 
843 {
844  return baseURI( PropertyType::Metadata );
845 }
846 
847 QString QgsMapLayer::saveDefaultMetadata( bool &resultFlag )
848 {
849  return saveNamedMetadata( metadataUri(), resultFlag );
850 }
851 
852 QString QgsMapLayer::loadDefaultMetadata( bool &resultFlag )
853 {
854  return loadNamedMetadata( metadataUri(), resultFlag );
855 }
856 
857 QString QgsMapLayer::styleURI() const
858 {
859  return baseURI( PropertyType::Style );
860 }
861 
862 QString QgsMapLayer::loadDefaultStyle( bool &resultFlag )
863 {
864  return loadNamedStyle( styleURI(), resultFlag );
865 }
866 
867 bool QgsMapLayer::loadNamedMetadataFromDatabase( const QString &db, const QString &uri, QString &qmd )
868 {
869  return loadNamedPropertyFromDatabase( db, uri, qmd, PropertyType::Metadata );
870 }
871 
872 bool QgsMapLayer::loadNamedStyleFromDatabase( const QString &db, const QString &uri, QString &qml )
873 {
874  return loadNamedPropertyFromDatabase( db, uri, qml, PropertyType::Style );
875 }
876 
877 bool QgsMapLayer::loadNamedPropertyFromDatabase( const QString &db, const QString &uri, QString &xml, QgsMapLayer::PropertyType type )
878 {
879  QgsDebugMsgLevel( QStringLiteral( "db = %1 uri = %2" ).arg( db, uri ), 4 );
880 
881  bool resultFlag = false;
882 
883  // read from database
886 
887  int myResult;
888 
889  QgsDebugMsgLevel( QStringLiteral( "Trying to load style or metadata for \"%1\" from \"%2\"" ).arg( uri, db ), 4 );
890 
891  if ( db.isEmpty() || !QFile( db ).exists() )
892  return false;
893 
894  myResult = database.open_v2( db, SQLITE_OPEN_READONLY, nullptr );
895  if ( myResult != SQLITE_OK )
896  {
897  return false;
898  }
899 
900  QString mySql;
901  switch ( type )
902  {
903  case Metadata:
904  mySql = QStringLiteral( "select qmd from tbl_metadata where metadata=?" );
905  break;
906 
907  case Style:
908  mySql = QStringLiteral( "select qml from tbl_styles where style=?" );
909  break;
910  }
911 
912  statement = database.prepare( mySql, myResult );
913  if ( myResult == SQLITE_OK )
914  {
915  QByteArray param = uri.toUtf8();
916 
917  if ( sqlite3_bind_text( statement.get(), 1, param.data(), param.length(), SQLITE_STATIC ) == SQLITE_OK &&
918  sqlite3_step( statement.get() ) == SQLITE_ROW )
919  {
920  xml = QString::fromUtf8( reinterpret_cast< const char * >( sqlite3_column_text( statement.get(), 0 ) ) );
921  resultFlag = true;
922  }
923  }
924  return resultFlag;
925 }
926 
927 
928 QString QgsMapLayer::loadNamedStyle( const QString &uri, bool &resultFlag, QgsMapLayer::StyleCategories categories )
929 {
930  return loadNamedProperty( uri, PropertyType::Style, resultFlag, categories );
931 }
932 
933 QString QgsMapLayer::loadNamedProperty( const QString &uri, QgsMapLayer::PropertyType type, bool &resultFlag, StyleCategories categories )
934 {
935  QgsDebugMsgLevel( QStringLiteral( "uri = %1 myURI = %2" ).arg( uri, publicSource() ), 4 );
936 
937  resultFlag = false;
938 
939  QDomDocument myDocument( QStringLiteral( "qgis" ) );
940 
941  // location of problem associated with errorMsg
942  int line, column;
943  QString myErrorMessage;
944 
945  QFile myFile( uri );
946  if ( myFile.open( QFile::ReadOnly ) )
947  {
948  QgsDebugMsgLevel( QStringLiteral( "file found %1" ).arg( uri ), 2 );
949  // read file
950  resultFlag = myDocument.setContent( &myFile, &myErrorMessage, &line, &column );
951  if ( !resultFlag )
952  myErrorMessage = tr( "%1 at line %2 column %3" ).arg( myErrorMessage ).arg( line ).arg( column );
953  myFile.close();
954  }
955  else
956  {
957  QFileInfo project( QgsProject::instance()->fileName() );
958  QgsDebugMsgLevel( QStringLiteral( "project fileName: %1" ).arg( project.absoluteFilePath() ), 4 );
959 
960  QString xml;
961  switch ( type )
962  {
963  case QgsMapLayer::Style:
964  {
965  if ( loadNamedStyleFromDatabase( QDir( QgsApplication::qgisSettingsDirPath() ).absoluteFilePath( QStringLiteral( "qgis.qmldb" ) ), uri, xml ) ||
966  ( project.exists() && loadNamedStyleFromDatabase( project.absoluteDir().absoluteFilePath( project.baseName() + ".qmldb" ), uri, xml ) ) ||
967  loadNamedStyleFromDatabase( QDir( QgsApplication::pkgDataPath() ).absoluteFilePath( QStringLiteral( "resources/qgis.qmldb" ) ), uri, xml ) )
968  {
969  resultFlag = myDocument.setContent( xml, &myErrorMessage, &line, &column );
970  if ( !resultFlag )
971  {
972  myErrorMessage = tr( "%1 at line %2 column %3" ).arg( myErrorMessage ).arg( line ).arg( column );
973  }
974  }
975  else
976  {
977  myErrorMessage = tr( "Style not found in database" );
978  resultFlag = false;
979  }
980  break;
981  }
983  {
984  if ( loadNamedMetadataFromDatabase( QDir( QgsApplication::qgisSettingsDirPath() ).absoluteFilePath( QStringLiteral( "qgis.qmldb" ) ), uri, xml ) ||
985  ( project.exists() && loadNamedMetadataFromDatabase( project.absoluteDir().absoluteFilePath( project.baseName() + ".qmldb" ), uri, xml ) ) ||
986  loadNamedMetadataFromDatabase( QDir( QgsApplication::pkgDataPath() ).absoluteFilePath( QStringLiteral( "resources/qgis.qmldb" ) ), uri, xml ) )
987  {
988  resultFlag = myDocument.setContent( xml, &myErrorMessage, &line, &column );
989  if ( !resultFlag )
990  {
991  myErrorMessage = tr( "%1 at line %2 column %3" ).arg( myErrorMessage ).arg( line ).arg( column );
992  }
993  }
994  else
995  {
996  myErrorMessage = tr( "Metadata not found in database" );
997  resultFlag = false;
998  }
999  break;
1000  }
1001  }
1002  }
1003 
1004  if ( !resultFlag )
1005  {
1006  return myErrorMessage;
1007  }
1008 
1009  switch ( type )
1010  {
1011  case QgsMapLayer::Style:
1012  resultFlag = importNamedStyle( myDocument, myErrorMessage, categories );
1013  if ( !resultFlag )
1014  myErrorMessage = tr( "Loading style file %1 failed because:\n%2" ).arg( uri, myErrorMessage );
1015  break;
1016  case QgsMapLayer::Metadata:
1017  resultFlag = importNamedMetadata( myDocument, myErrorMessage );
1018  if ( !resultFlag )
1019  myErrorMessage = tr( "Loading metadata file %1 failed because:\n%2" ).arg( uri, myErrorMessage );
1020  break;
1021  }
1022  return myErrorMessage;
1023 }
1024 
1025 bool QgsMapLayer::importNamedMetadata( QDomDocument &document, QString &errorMessage )
1026 {
1027  QDomElement myRoot = document.firstChildElement( QStringLiteral( "qgis" ) );
1028  if ( myRoot.isNull() )
1029  {
1030  errorMessage = tr( "Root <qgis> element could not be found" );
1031  return false;
1032  }
1033 
1034  return mMetadata.readMetadataXml( myRoot );
1035 }
1036 
1037 bool QgsMapLayer::importNamedStyle( QDomDocument &myDocument, QString &myErrorMessage, QgsMapLayer::StyleCategories categories )
1038 {
1039  QDomElement myRoot = myDocument.firstChildElement( QStringLiteral( "qgis" ) );
1040  if ( myRoot.isNull() )
1041  {
1042  myErrorMessage = tr( "Root <qgis> element could not be found" );
1043  return false;
1044  }
1045 
1046  // get style file version string, if any
1047  QgsProjectVersion fileVersion( myRoot.attribute( QStringLiteral( "version" ) ) );
1048  QgsProjectVersion thisVersion( Qgis::version() );
1049 
1050  if ( thisVersion > fileVersion )
1051  {
1052  QgsProjectFileTransform styleFile( myDocument, fileVersion );
1053  styleFile.updateRevision( thisVersion );
1054  }
1055 
1056  // Get source categories
1057  QgsMapLayer::StyleCategories sourceCategories = QgsXmlUtils::readFlagAttribute( myRoot, QStringLiteral( "styleCategories" ), QgsMapLayer::AllStyleCategories );
1058 
1059  //Test for matching geometry type on vector layers when applying, if geometry type is given in the style
1060  if ( ( sourceCategories.testFlag( QgsMapLayer::Symbology ) || sourceCategories.testFlag( QgsMapLayer::Symbology3D ) ) &&
1061  ( categories.testFlag( QgsMapLayer::Symbology ) || categories.testFlag( QgsMapLayer::Symbology3D ) ) )
1062  {
1063  if ( type() == QgsMapLayerType::VectorLayer && !myRoot.firstChildElement( QStringLiteral( "layerGeometryType" ) ).isNull() )
1064  {
1065  QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( this );
1066  QgsWkbTypes::GeometryType importLayerGeometryType = static_cast<QgsWkbTypes::GeometryType>( myRoot.firstChildElement( QStringLiteral( "layerGeometryType" ) ).text().toInt() );
1067  if ( importLayerGeometryType != QgsWkbTypes::GeometryType::UnknownGeometry && vl->geometryType() != importLayerGeometryType )
1068  {
1069  myErrorMessage = tr( "Cannot apply style with symbology to layer with a different geometry type" );
1070  return false;
1071  }
1072  }
1073  }
1074 
1076  return readSymbology( myRoot, myErrorMessage, context, categories ); // TODO: support relative paths in QML?
1077 }
1078 
1079 void QgsMapLayer::exportNamedMetadata( QDomDocument &doc, QString &errorMsg ) const
1080 {
1081  QDomImplementation DomImplementation;
1082  QDomDocumentType documentType = DomImplementation.createDocumentType( QStringLiteral( "qgis" ), QStringLiteral( "http://mrcc.com/qgis.dtd" ), QStringLiteral( "SYSTEM" ) );
1083  QDomDocument myDocument( documentType );
1084 
1085  QDomElement myRootNode = myDocument.createElement( QStringLiteral( "qgis" ) );
1086  myRootNode.setAttribute( QStringLiteral( "version" ), Qgis::version() );
1087  myDocument.appendChild( myRootNode );
1088 
1089  if ( !mMetadata.writeMetadataXml( myRootNode, myDocument ) )
1090  {
1091  errorMsg = QObject::tr( "Could not save metadata" );
1092  return;
1093  }
1094 
1095  doc = myDocument;
1096 }
1097 
1098 void QgsMapLayer::exportNamedStyle( QDomDocument &doc, QString &errorMsg, const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories ) const
1099 {
1100  QDomImplementation DomImplementation;
1101  QDomDocumentType documentType = DomImplementation.createDocumentType( QStringLiteral( "qgis" ), QStringLiteral( "http://mrcc.com/qgis.dtd" ), QStringLiteral( "SYSTEM" ) );
1102  QDomDocument myDocument( documentType );
1103 
1104  QDomElement myRootNode = myDocument.createElement( QStringLiteral( "qgis" ) );
1105  myRootNode.setAttribute( QStringLiteral( "version" ), Qgis::version() );
1106  myDocument.appendChild( myRootNode );
1107 
1108  if ( !writeSymbology( myRootNode, myDocument, errorMsg, context, categories ) ) // TODO: support relative paths in QML?
1109  {
1110  errorMsg = QObject::tr( "Could not save symbology because:\n%1" ).arg( errorMsg );
1111  return;
1112  }
1113 
1114  /*
1115  * Check to see if the layer is vector - in which case we should also export its geometryType
1116  * to avoid eventually pasting to a layer with a different geometry
1117  */
1119  {
1120  //Getting the selectionLayer geometry
1121  const QgsVectorLayer *vl = qobject_cast<const QgsVectorLayer *>( this );
1122  QString geoType = QString::number( vl->geometryType() );
1123 
1124  //Adding geometryinformation
1125  QDomElement layerGeometryType = myDocument.createElement( QStringLiteral( "layerGeometryType" ) );
1126  QDomText type = myDocument.createTextNode( geoType );
1127 
1128  layerGeometryType.appendChild( type );
1129  myRootNode.appendChild( layerGeometryType );
1130  }
1131 
1132  doc = myDocument;
1133 }
1134 
1135 QString QgsMapLayer::saveDefaultStyle( bool &resultFlag )
1136 {
1137  return saveNamedStyle( styleURI(), resultFlag );
1138 }
1139 
1140 QString QgsMapLayer::saveNamedMetadata( const QString &uri, bool &resultFlag )
1141 {
1142  return saveNamedProperty( uri, QgsMapLayer::Metadata, resultFlag );
1143 }
1144 
1145 QString QgsMapLayer::loadNamedMetadata( const QString &uri, bool &resultFlag )
1146 {
1147  return loadNamedProperty( uri, QgsMapLayer::Metadata, resultFlag );
1148 }
1149 
1150 QString QgsMapLayer::saveNamedProperty( const QString &uri, QgsMapLayer::PropertyType type, bool &resultFlag, StyleCategories categories )
1151 {
1152  // check if the uri is a file or ends with .qml/.qmd,
1153  // which indicates that it should become one
1154  // everything else goes to the database
1155  QString filename;
1156 
1157  QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( this );
1158  if ( vlayer && vlayer->providerType() == QLatin1String( "ogr" ) )
1159  {
1160  QStringList theURIParts = uri.split( '|' );
1161  filename = theURIParts[0];
1162  }
1163  else if ( vlayer && vlayer->providerType() == QLatin1String( "gpx" ) )
1164  {
1165  QStringList theURIParts = uri.split( '?' );
1166  filename = theURIParts[0];
1167  }
1168  else if ( vlayer && vlayer->providerType() == QLatin1String( "delimitedtext" ) )
1169  {
1170  filename = QUrl::fromEncoded( uri.toLatin1() ).toLocalFile();
1171  // toLocalFile() returns an empty string if theURI is a plain Windows-path, e.g. "C:/style.qml"
1172  if ( filename.isEmpty() )
1173  filename = uri;
1174  }
1175  else
1176  {
1177  filename = uri;
1178  }
1179 
1180  QString myErrorMessage;
1181  QDomDocument myDocument;
1182  switch ( type )
1183  {
1184  case Metadata:
1185  exportNamedMetadata( myDocument, myErrorMessage );
1186  break;
1187 
1188  case Style:
1189  QgsReadWriteContext context;
1190  exportNamedStyle( myDocument, myErrorMessage, context, categories );
1191  break;
1192  }
1193 
1194  QFileInfo myFileInfo( filename );
1195  if ( myFileInfo.exists() || filename.endsWith( QgsMapLayer::extensionPropertyType( type ), Qt::CaseInsensitive ) )
1196  {
1197  QFileInfo myDirInfo( myFileInfo.path() ); //excludes file name
1198  if ( !myDirInfo.isWritable() )
1199  {
1200  return tr( "The directory containing your dataset needs to be writable!" );
1201  }
1202 
1203  // now construct the file name for our .qml or .qmd file
1204  QString myFileName = myFileInfo.path() + QDir::separator() + myFileInfo.completeBaseName() + QgsMapLayer::extensionPropertyType( type );
1205 
1206  QFile myFile( myFileName );
1207  if ( myFile.open( QFile::WriteOnly | QFile::Truncate ) )
1208  {
1209  QTextStream myFileStream( &myFile );
1210  // save as utf-8 with 2 spaces for indents
1211  myDocument.save( myFileStream, 2 );
1212  myFile.close();
1213  resultFlag = true;
1214  switch ( type )
1215  {
1216  case Metadata:
1217  return tr( "Created default metadata file as %1" ).arg( myFileName );
1218 
1219  case Style:
1220  return tr( "Created default style file as %1" ).arg( myFileName );
1221  }
1222 
1223  }
1224  else
1225  {
1226  resultFlag = false;
1227  switch ( type )
1228  {
1229  case Metadata:
1230  return tr( "ERROR: Failed to created default metadata file as %1. Check file permissions and retry." ).arg( myFileName );
1231 
1232  case Style:
1233  return tr( "ERROR: Failed to created default style file as %1. Check file permissions and retry." ).arg( myFileName );
1234  }
1235  }
1236  }
1237  else
1238  {
1239  QString qml = myDocument.toString();
1240 
1241  // read from database
1242  sqlite3_database_unique_ptr database;
1243  sqlite3_statement_unique_ptr statement;
1244 
1245  int myResult = database.open( QDir( QgsApplication::qgisSettingsDirPath() ).absoluteFilePath( QStringLiteral( "qgis.qmldb" ) ) );
1246  if ( myResult != SQLITE_OK )
1247  {
1248  return tr( "User database could not be opened." );
1249  }
1250 
1251  QByteArray param0 = uri.toUtf8();
1252  QByteArray param1 = qml.toUtf8();
1253 
1254  QString mySql;
1255  switch ( type )
1256  {
1257  case Metadata:
1258  mySql = QStringLiteral( "create table if not exists tbl_metadata(metadata varchar primary key,qmd varchar)" );
1259  break;
1260 
1261  case Style:
1262  mySql = QStringLiteral( "create table if not exists tbl_styles(style varchar primary key,qml varchar)" );
1263  break;
1264  }
1265 
1266  statement = database.prepare( mySql, myResult );
1267  if ( myResult == SQLITE_OK )
1268  {
1269  if ( sqlite3_step( statement.get() ) != SQLITE_DONE )
1270  {
1271  resultFlag = false;
1272  switch ( type )
1273  {
1274  case Metadata:
1275  return tr( "The metadata table could not be created." );
1276 
1277  case Style:
1278  return tr( "The style table could not be created." );
1279  }
1280  }
1281  }
1282 
1283  switch ( type )
1284  {
1285  case Metadata:
1286  mySql = QStringLiteral( "insert into tbl_metadata(metadata,qmd) values (?,?)" );
1287  break;
1288 
1289  case Style:
1290  mySql = QStringLiteral( "insert into tbl_styles(style,qml) values (?,?)" );
1291  break;
1292  }
1293  statement = database.prepare( mySql, myResult );
1294  if ( myResult == SQLITE_OK )
1295  {
1296  if ( sqlite3_bind_text( statement.get(), 1, param0.data(), param0.length(), SQLITE_STATIC ) == SQLITE_OK &&
1297  sqlite3_bind_text( statement.get(), 2, param1.data(), param1.length(), SQLITE_STATIC ) == SQLITE_OK &&
1298  sqlite3_step( statement.get() ) == SQLITE_DONE )
1299  {
1300  resultFlag = true;
1301  switch ( type )
1302  {
1303  case Metadata:
1304  myErrorMessage = tr( "The metadata %1 was saved to database" ).arg( uri );
1305  break;
1306 
1307  case Style:
1308  myErrorMessage = tr( "The style %1 was saved to database" ).arg( uri );
1309  break;
1310  }
1311  }
1312  }
1313 
1314  if ( !resultFlag )
1315  {
1316  QString mySql;
1317  switch ( type )
1318  {
1319  case Metadata:
1320  mySql = QStringLiteral( "update tbl_metadata set qmd=? where metadata=?" );
1321  break;
1322 
1323  case Style:
1324  mySql = QStringLiteral( "update tbl_styles set qml=? where style=?" );
1325  break;
1326  }
1327  statement = database.prepare( mySql, myResult );
1328  if ( myResult == SQLITE_OK )
1329  {
1330  if ( sqlite3_bind_text( statement.get(), 2, param0.data(), param0.length(), SQLITE_STATIC ) == SQLITE_OK &&
1331  sqlite3_bind_text( statement.get(), 1, param1.data(), param1.length(), SQLITE_STATIC ) == SQLITE_OK &&
1332  sqlite3_step( statement.get() ) == SQLITE_DONE )
1333  {
1334  resultFlag = true;
1335  switch ( type )
1336  {
1337  case Metadata:
1338  myErrorMessage = tr( "The metadata %1 was updated in the database." ).arg( uri );
1339  break;
1340 
1341  case Style:
1342  myErrorMessage = tr( "The style %1 was updated in the database." ).arg( uri );
1343  break;
1344  }
1345  }
1346  else
1347  {
1348  resultFlag = false;
1349  switch ( type )
1350  {
1351  case Metadata:
1352  myErrorMessage = tr( "The metadata %1 could not be updated in the database." ).arg( uri );
1353  break;
1354 
1355  case Style:
1356  myErrorMessage = tr( "The style %1 could not be updated in the database." ).arg( uri );
1357  break;
1358  }
1359  }
1360  }
1361  else
1362  {
1363  resultFlag = false;
1364  switch ( type )
1365  {
1366  case Metadata:
1367  myErrorMessage = tr( "The metadata %1 could not be inserted into database." ).arg( uri );
1368  break;
1369 
1370  case Style:
1371  myErrorMessage = tr( "The style %1 could not be inserted into database." ).arg( uri );
1372  break;
1373  }
1374  }
1375  }
1376  }
1377 
1378  return myErrorMessage;
1379 }
1380 
1381 QString QgsMapLayer::saveNamedStyle( const QString &uri, bool &resultFlag, StyleCategories categories )
1382 {
1383  return saveNamedProperty( uri, QgsMapLayer::Style, resultFlag, categories );
1384 }
1385 
1386 void QgsMapLayer::exportSldStyle( QDomDocument &doc, QString &errorMsg ) const
1387 {
1388  QDomDocument myDocument = QDomDocument();
1389 
1390  QDomNode header = myDocument.createProcessingInstruction( QStringLiteral( "xml" ), QStringLiteral( "version=\"1.0\" encoding=\"UTF-8\"" ) );
1391  myDocument.appendChild( header );
1392 
1393  const QgsVectorLayer *vlayer = qobject_cast<const QgsVectorLayer *>( this );
1394  const QgsRasterLayer *rlayer = qobject_cast<const QgsRasterLayer *>( this );
1395  if ( !vlayer && !rlayer )
1396  {
1397  errorMsg = tr( "Could not save symbology because:\n%1" )
1398  .arg( tr( "Only vector and raster layers are supported" ) );
1399  return;
1400  }
1401 
1402  // Create the root element
1403  QDomElement root = myDocument.createElementNS( QStringLiteral( "http://www.opengis.net/sld" ), QStringLiteral( "StyledLayerDescriptor" ) );
1404  QDomElement layerNode;
1405  if ( vlayer )
1406  {
1407  root.setAttribute( QStringLiteral( "version" ), QStringLiteral( "1.1.0" ) );
1408  root.setAttribute( QStringLiteral( "xsi:schemaLocation" ), QStringLiteral( "http://www.opengis.net/sld http://schemas.opengis.net/sld/1.1.0/StyledLayerDescriptor.xsd" ) );
1409  root.setAttribute( QStringLiteral( "xmlns:ogc" ), QStringLiteral( "http://www.opengis.net/ogc" ) );
1410  root.setAttribute( QStringLiteral( "xmlns:se" ), QStringLiteral( "http://www.opengis.net/se" ) );
1411  root.setAttribute( QStringLiteral( "xmlns:xlink" ), QStringLiteral( "http://www.w3.org/1999/xlink" ) );
1412  root.setAttribute( QStringLiteral( "xmlns:xsi" ), QStringLiteral( "http://www.w3.org/2001/XMLSchema-instance" ) );
1413  myDocument.appendChild( root );
1414 
1415  // Create the NamedLayer element
1416  layerNode = myDocument.createElement( QStringLiteral( "NamedLayer" ) );
1417  root.appendChild( layerNode );
1418  }
1419 
1420  // note: Only SLD 1.0 version is generated because seems none is using SE1.1.0 at least for rasters
1421  if ( rlayer )
1422  {
1423  // Create the root element
1424  root.setAttribute( QStringLiteral( "version" ), QStringLiteral( "1.0.0" ) );
1425  root.setAttribute( QStringLiteral( "xmlns:gml" ), QStringLiteral( "http://www.opengis.net/gml" ) );
1426  root.setAttribute( QStringLiteral( "xmlns:ogc" ), QStringLiteral( "http://www.opengis.net/ogc" ) );
1427  root.setAttribute( QStringLiteral( "xmlns:sld" ), QStringLiteral( "http://www.opengis.net/sld" ) );
1428  myDocument.appendChild( root );
1429 
1430  // Create the NamedLayer element
1431  layerNode = myDocument.createElement( QStringLiteral( "UserLayer" ) );
1432  root.appendChild( layerNode );
1433  }
1434 
1435  QgsStringMap props;
1436  if ( hasScaleBasedVisibility() )
1437  {
1438  props[ QStringLiteral( "scaleMinDenom" ) ] = QString::number( mMinScale );
1439  props[ QStringLiteral( "scaleMaxDenom" ) ] = QString::number( mMaxScale );
1440  }
1441 
1442  if ( vlayer )
1443  {
1444  if ( !vlayer->writeSld( layerNode, myDocument, errorMsg, props ) )
1445  {
1446  errorMsg = tr( "Could not save symbology because:\n%1" ).arg( errorMsg );
1447  return;
1448  }
1449  }
1450 
1451  if ( rlayer )
1452  {
1453  if ( !rlayer->writeSld( layerNode, myDocument, errorMsg, props ) )
1454  {
1455  errorMsg = tr( "Could not save symbology because:\n%1" ).arg( errorMsg );
1456  return;
1457  }
1458  }
1459 
1460  doc = myDocument;
1461 }
1462 
1463 QString QgsMapLayer::saveSldStyle( const QString &uri, bool &resultFlag ) const
1464 {
1465  const QgsMapLayer *mlayer = qobject_cast<const QgsMapLayer *>( this );
1466 
1467  QString errorMsg;
1468  QDomDocument myDocument;
1469  mlayer->exportSldStyle( myDocument, errorMsg );
1470  if ( !errorMsg.isNull() )
1471  {
1472  resultFlag = false;
1473  return errorMsg;
1474  }
1475  // check if the uri is a file or ends with .sld,
1476  // which indicates that it should become one
1477  QString filename;
1478  if ( mlayer->providerType() == QLatin1String( "ogr" ) )
1479  {
1480  QStringList theURIParts = uri.split( '|' );
1481  filename = theURIParts[0];
1482  }
1483  else if ( mlayer->providerType() == QLatin1String( "gpx" ) )
1484  {
1485  QStringList theURIParts = uri.split( '?' );
1486  filename = theURIParts[0];
1487  }
1488  else if ( mlayer->providerType() == QLatin1String( "delimitedtext" ) )
1489  {
1490  filename = QUrl::fromEncoded( uri.toLatin1() ).toLocalFile();
1491  // toLocalFile() returns an empty string if theURI is a plain Windows-path, e.g. "C:/style.qml"
1492  if ( filename.isEmpty() )
1493  filename = uri;
1494  }
1495  else
1496  {
1497  filename = uri;
1498  }
1499 
1500  QFileInfo myFileInfo( filename );
1501  if ( myFileInfo.exists() || filename.endsWith( QLatin1String( ".sld" ), Qt::CaseInsensitive ) )
1502  {
1503  QFileInfo myDirInfo( myFileInfo.path() ); //excludes file name
1504  if ( !myDirInfo.isWritable() )
1505  {
1506  return tr( "The directory containing your dataset needs to be writable!" );
1507  }
1508 
1509  // now construct the file name for our .sld style file
1510  QString myFileName = myFileInfo.path() + QDir::separator() + myFileInfo.completeBaseName() + ".sld";
1511 
1512  QFile myFile( myFileName );
1513  if ( myFile.open( QFile::WriteOnly | QFile::Truncate ) )
1514  {
1515  QTextStream myFileStream( &myFile );
1516  // save as utf-8 with 2 spaces for indents
1517  myDocument.save( myFileStream, 2 );
1518  myFile.close();
1519  resultFlag = true;
1520  return tr( "Created default style file as %1" ).arg( myFileName );
1521  }
1522  }
1523 
1524  resultFlag = false;
1525  return tr( "ERROR: Failed to created SLD style file as %1. Check file permissions and retry." ).arg( filename );
1526 }
1527 
1528 QString QgsMapLayer::loadSldStyle( const QString &uri, bool &resultFlag )
1529 {
1530  resultFlag = false;
1531 
1532  QDomDocument myDocument;
1533 
1534  // location of problem associated with errorMsg
1535  int line, column;
1536  QString myErrorMessage;
1537 
1538  QFile myFile( uri );
1539  if ( myFile.open( QFile::ReadOnly ) )
1540  {
1541  // read file
1542  resultFlag = myDocument.setContent( &myFile, true, &myErrorMessage, &line, &column );
1543  if ( !resultFlag )
1544  myErrorMessage = tr( "%1 at line %2 column %3" ).arg( myErrorMessage ).arg( line ).arg( column );
1545  myFile.close();
1546  }
1547  else
1548  {
1549  myErrorMessage = tr( "Unable to open file %1" ).arg( uri );
1550  }
1551 
1552  if ( !resultFlag )
1553  {
1554  return myErrorMessage;
1555  }
1556 
1557  // check for root SLD element
1558  QDomElement myRoot = myDocument.firstChildElement( QStringLiteral( "StyledLayerDescriptor" ) );
1559  if ( myRoot.isNull() )
1560  {
1561  myErrorMessage = QStringLiteral( "Error: StyledLayerDescriptor element not found in %1" ).arg( uri );
1562  resultFlag = false;
1563  return myErrorMessage;
1564  }
1565 
1566  // now get the style node out and pass it over to the layer
1567  // to deserialise...
1568  QDomElement namedLayerElem = myRoot.firstChildElement( QStringLiteral( "NamedLayer" ) );
1569  if ( namedLayerElem.isNull() )
1570  {
1571  myErrorMessage = QStringLiteral( "Info: NamedLayer element not found." );
1572  resultFlag = false;
1573  return myErrorMessage;
1574  }
1575 
1576  QString errorMsg;
1577  resultFlag = readSld( namedLayerElem, errorMsg );
1578  if ( !resultFlag )
1579  {
1580  myErrorMessage = tr( "Loading style file %1 failed because:\n%2" ).arg( uri, errorMsg );
1581  return myErrorMessage;
1582  }
1583 
1584  return QString();
1585 }
1586 
1587 bool QgsMapLayer::readStyle( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories )
1588 {
1589  Q_UNUSED( node )
1590  Q_UNUSED( errorMessage )
1591  Q_UNUSED( context )
1592  Q_UNUSED( categories )
1593  return false;
1594 }
1595 
1596 bool QgsMapLayer::writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage,
1597  const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories ) const
1598 {
1599  Q_UNUSED( node )
1600  Q_UNUSED( doc )
1601  Q_UNUSED( errorMessage )
1602  Q_UNUSED( context )
1603  Q_UNUSED( categories )
1604  return false;
1605 }
1606 
1607 void QgsMapLayer::setDataSource( const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, bool loadDefaultStyleFlag )
1608 {
1609  Q_UNUSED( dataSource )
1610  Q_UNUSED( baseName )
1611  Q_UNUSED( provider )
1612  Q_UNUSED( options )
1613  Q_UNUSED( loadDefaultStyleFlag )
1614 }
1615 
1616 
1618 {
1619  return mProviderKey;
1620 }
1621 
1622 void QgsMapLayer::readCommonStyle( const QDomElement &layerElement, const QgsReadWriteContext &context,
1623  QgsMapLayer::StyleCategories categories )
1624 {
1625  if ( categories.testFlag( Symbology3D ) )
1626  {
1627  QgsAbstract3DRenderer *r3D = nullptr;
1628  QDomElement renderer3DElem = layerElement.firstChildElement( QStringLiteral( "renderer-3d" ) );
1629  if ( !renderer3DElem.isNull() )
1630  {
1631  QString type3D = renderer3DElem.attribute( QStringLiteral( "type" ) );
1633  if ( meta3D )
1634  {
1635  r3D = meta3D->createRenderer( renderer3DElem, context );
1636  }
1637  }
1638  setRenderer3D( r3D );
1639  }
1640 
1641  if ( categories.testFlag( CustomProperties ) )
1642  {
1643  // read custom properties before passing reading further to a subclass, so that
1644  // the subclass can also read custom properties
1645  readCustomProperties( layerElement );
1646  }
1647 
1648  // use scale dependent visibility flag
1649  if ( categories.testFlag( Rendering ) )
1650  {
1651  setScaleBasedVisibility( layerElement.attribute( QStringLiteral( "hasScaleBasedVisibilityFlag" ) ).toInt() == 1 );
1652  if ( layerElement.hasAttribute( QStringLiteral( "minimumScale" ) ) )
1653  {
1654  // older element, when scales were reversed
1655  setMaximumScale( layerElement.attribute( QStringLiteral( "minimumScale" ) ).toDouble() );
1656  setMinimumScale( layerElement.attribute( QStringLiteral( "maximumScale" ) ).toDouble() );
1657  }
1658  else
1659  {
1660  setMaximumScale( layerElement.attribute( QStringLiteral( "maxScale" ) ).toDouble() );
1661  setMinimumScale( layerElement.attribute( QStringLiteral( "minScale" ) ).toDouble() );
1662  }
1663  }
1664 
1665  if ( categories.testFlag( LayerConfiguration ) )
1666  {
1667  // flags
1668  QDomElement flagsElem = layerElement.firstChildElement( QStringLiteral( "flags" ) );
1669  LayerFlags flags = mFlags;
1670  auto enumMap = qgsEnumMap<QgsMapLayer::LayerFlag>();
1671  for ( auto it = enumMap.constBegin(); it != enumMap.constEnd(); ++it )
1672  {
1673  QDomNode flagNode = flagsElem.namedItem( it.value() );
1674  if ( flagNode.isNull() )
1675  continue;
1676  bool flagValue = flagNode.toElement().text() == "1" ? true : false;
1677  if ( flags.testFlag( it.key() ) && !flagValue )
1678  flags &= ~it.key();
1679  else if ( !flags.testFlag( it.key() ) && flagValue )
1680  flags |= it.key();
1681  }
1682  setFlags( flags );
1683  }
1684 
1685  if ( categories.testFlag( Temporal ) )
1686  {
1687  QgsMapLayerTemporalProperties *lTemporalProperties = temporalProperties();
1688  if ( lTemporalProperties )
1689  lTemporalProperties->readXml( layerElement.toElement(), context );
1690  }
1691 }
1692 
1694 {
1695  return mUndoStack;
1696 }
1697 
1699 {
1700  return mUndoStackStyles;
1701 }
1702 
1704 {
1705  return mCustomProperties.keys();
1706 }
1707 
1708 void QgsMapLayer::setCustomProperty( const QString &key, const QVariant &value )
1709 {
1710  mCustomProperties.setValue( key, value );
1711 }
1712 
1714 {
1715  mCustomProperties = properties;
1716 }
1717 
1719 {
1720  return mCustomProperties;
1721 }
1722 
1723 QVariant QgsMapLayer::customProperty( const QString &value, const QVariant &defaultValue ) const
1724 {
1725  return mCustomProperties.value( value, defaultValue );
1726 }
1727 
1728 void QgsMapLayer::removeCustomProperty( const QString &key )
1729 {
1730  mCustomProperties.remove( key );
1731 }
1732 
1734 {
1735  return mError;
1736 }
1737 
1738 
1739 
1741 {
1742  return false;
1743 }
1744 
1746 {
1747  return true;
1748 }
1749 
1751 {
1752  // invalid layers are temporary? -- who knows?!
1753  if ( !isValid() )
1754  return false;
1755 
1756  if ( mProviderKey == QLatin1String( "memory" ) )
1757  return true;
1758 
1759  const QVariantMap sourceParts = QgsProviderRegistry::instance()->decodeUri( mProviderKey, mDataSource );
1760  const QString path = sourceParts.value( QStringLiteral( "path" ) ).toString();
1761  if ( path.isEmpty() )
1762  return false;
1763 
1764  // check if layer path is inside one of the standard temporary file locations for this platform
1765  const QStringList tempPaths = QStandardPaths::standardLocations( QStandardPaths::TempLocation );
1766  for ( const QString &tempPath : tempPaths )
1767  {
1768  if ( path.startsWith( tempPath ) )
1769  return true;
1770  }
1771 
1772  return false;
1773 }
1774 
1775 void QgsMapLayer::setValid( bool valid )
1776 {
1777  if ( mValid == valid )
1778  return;
1779 
1780  mValid = valid;
1781  emit isValidChanged();
1782 }
1783 
1785 {
1786  if ( legend == mLegend )
1787  return;
1788 
1789  delete mLegend;
1790  mLegend = legend;
1791 
1792  if ( mLegend )
1793  {
1794  mLegend->setParent( this );
1795  connect( mLegend, &QgsMapLayerLegend::itemsChanged, this, &QgsMapLayer::legendChanged );
1796  }
1797 
1798  emit legendChanged();
1799 }
1800 
1802 {
1803  return mLegend;
1804 }
1805 
1807 {
1808  return mStyleManager;
1809 }
1810 
1812 {
1813  if ( renderer == m3DRenderer )
1814  return;
1815 
1816  delete m3DRenderer;
1817  m3DRenderer = renderer;
1818  emit renderer3DChanged();
1819 }
1820 
1822 {
1823  return m3DRenderer;
1824 }
1825 
1826 void QgsMapLayer::triggerRepaint( bool deferredUpdate )
1827 {
1828  if ( mRepaintRequestedFired )
1829  return;
1830 
1831  mRepaintRequestedFired = true;
1832  emit repaintRequested( deferredUpdate );
1833  mRepaintRequestedFired = false;
1834 }
1835 
1837 {
1838  mMetadata = metadata;
1839 // mMetadata.saveToLayer( this );
1840  emit metadataChanged();
1841 }
1842 
1844 {
1845  return QString();
1846 }
1847 
1848 QDateTime QgsMapLayer::timestamp() const
1849 {
1850  return QDateTime();
1851 }
1852 
1854 {
1855  emit styleChanged();
1856 }
1857 
1859 {
1860  mExtent = r;
1861 }
1862 
1863 bool QgsMapLayer::isReadOnly() const
1864 {
1865  return true;
1866 }
1867 
1869 {
1870  return mOriginalXmlProperties;
1871 }
1872 
1873 void QgsMapLayer::setOriginalXmlProperties( const QString &originalXmlProperties )
1874 {
1875  mOriginalXmlProperties = originalXmlProperties;
1876 }
1877 
1878 QString QgsMapLayer::generateId( const QString &layerName )
1879 {
1880  // Generate the unique ID of this layer
1881  QString uuid = QUuid::createUuid().toString();
1882  // trim { } from uuid
1883  QString id = layerName + '_' + uuid.mid( 1, uuid.length() - 2 );
1884  // Tidy the ID up to avoid characters that may cause problems
1885  // elsewhere (e.g in some parts of XML). Replaces every non-word
1886  // character (word characters are the alphabet, numbers and
1887  // underscore) with an underscore.
1888  // Note that the first backslash in the regular expression is
1889  // there for the compiler, so the pattern is actually \W
1890  id.replace( QRegExp( "[\\W]" ), QStringLiteral( "_" ) );
1891  return id;
1892 }
1893 
1895 {
1896  return true;
1897 }
1898 
1899 void QgsMapLayer::setProviderType( const QString &providerType )
1900 {
1902 }
1903 
1904 QSet<QgsMapLayerDependency> QgsMapLayer::dependencies() const
1905 {
1906  return mDependencies;
1907 }
1908 
1909 bool QgsMapLayer::setDependencies( const QSet<QgsMapLayerDependency> &oDeps )
1910 {
1911  QSet<QgsMapLayerDependency> deps;
1912  const auto constODeps = oDeps;
1913  for ( const QgsMapLayerDependency &dep : constODeps )
1914  {
1915  if ( dep.origin() == QgsMapLayerDependency::FromUser )
1916  deps << dep;
1917  }
1918 
1919  mDependencies = deps;
1920  emit dependenciesChanged();
1921  return true;
1922 }
1923 
1925 {
1926  QgsDataProvider *lDataProvider = dataProvider();
1927  if ( !lDataProvider )
1928  return;
1929 
1930  if ( enabled && !isRefreshOnNotifyEnabled() )
1931  {
1932  lDataProvider->setListening( enabled );
1933  connect( lDataProvider, &QgsVectorDataProvider::notify, this, &QgsMapLayer::onNotifiedTriggerRepaint );
1934  }
1935  else if ( !enabled && isRefreshOnNotifyEnabled() )
1936  {
1937  // we don't want to disable provider listening because someone else could need it (e.g. actions)
1938  disconnect( lDataProvider, &QgsVectorDataProvider::notify, this, &QgsMapLayer::onNotifiedTriggerRepaint );
1939  }
1940  mIsRefreshOnNofifyEnabled = enabled;
1941 }
1942 
1943 void QgsMapLayer::onNotifiedTriggerRepaint( const QString &message )
1944 {
1945  if ( refreshOnNotifyMessage().isEmpty() || refreshOnNotifyMessage() == message )
1946  triggerRepaint();
1947 }
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:301
QgsProjectFileTransform::updateRevision
bool updateRevision(const QgsProjectVersion &version)
Definition: qgsprojectfiletransform.cpp:69
QgsMapLayer::Style
@ Style
Definition: qgsmaplayer.h:137
QgsMapLayer::crs
QgsCoordinateReferenceSystem crs
Definition: qgsmaplayer.h:89
QgsMapLayer::emitStyleChanged
void emitStyleChanged()
Triggers an emission of the styleChanged() signal.
Definition: qgsmaplayer.cpp:1853
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:1622
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:1528
QgsMapLayer::~QgsMapLayer
~QgsMapLayer() override
Definition: qgsmaplayer.cpp:88
QgsMapLayer::hasAutoRefreshEnabled
bool hasAutoRefreshEnabled() const
Returns true if auto refresh is enabled for the layer.
Definition: qgsmaplayer.cpp:683
QgsMapLayerTemporalProperties::writeXml
virtual QDomElement writeXml(QDomElement &element, QDomDocument &doc, const QgsReadWriteContext &context)=0
Writes the properties to a DOM element, to be used later with readXml().
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:621
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:276
QgsMapLayer::attributionUrl
QString attributionUrl() const
Returns the attribution URL of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:401
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:58
QgsXmlUtils::writeRectangle
static QDomElement writeRectangle(const QgsRectangle &rect, QDomDocument &doc)
Definition: qgsxmlutils.cpp:81
QgsMapLayer::refreshOnNotifyMessage
QString refreshOnNotifyMessage() const
Returns the message that should be notified by the provider to triggerRepaint.
Definition: qgsmaplayer.h:1153
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:598
qgsrasterlayer.h
QgsMapLayer::setMetadataUrl
void setMetadataUrl(const QString &metaUrl)
Sets the metadata URL of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:412
QgsMapLayer::configChanged
void configChanged()
Emitted whenever the configuration is changed.
QgsMapLayer::writeLayerXml
bool writeLayerXml(QDomElement &layerElement, QDomDocument &document, const QgsReadWriteContext &context) const
Stores state in DOM node.
Definition: qgsmaplayer.cpp:391
QgsMapLayer::autoRefreshInterval
int autoRefreshInterval
Definition: qgsmaplayer.h:87
QgsMapLayer::dataUrlFormat
QString dataUrlFormat() const
Returns the DataUrl format of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:363
QgsDataProvider::ProviderOptions
Setting options for creating vector data providers.
Definition: qgsdataprovider.h:105
QgsCoordinateReferenceSystem::customCrsValidation
static CUSTOM_CRS_VALIDATION customCrsValidation()
Gets custom function.
Definition: qgscoordinatereferencesystem.cpp:2258
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:1878
QgsReadWriteContext
The class is used as a container of context for various read/write operations on other objects.
Definition: qgsreadwritecontext.h:35
QgsDataProvider
Abstract base class for spatial data provider implementations.
Definition: qgsdataprovider.h:42
qgsrectangle.h
QgsMapLayerType::VectorLayer
@ VectorLayer
QgsRasterLayer::writeSld
bool writeSld(QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsStringMap &props=QgsStringMap()) const
Writes the symbology of the layer into the document provided in SLD 1.0.0 format.
Definition: qgsrasterlayer.cpp:1456
Qgs3DRendererAbstractMetadata::createRenderer
virtual QgsAbstract3DRenderer * createRenderer(QDomElement &elem, const QgsReadWriteContext &context)=0
Returns new instance of the renderer given the DOM element.
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::setFlags
void setFlags(QgsMapLayer::LayerFlags flags)
Returns the flags for this layer.
Definition: qgsmaplayer.cpp:139
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
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:212
QgsMapLayer::mLegendUrlFormat
QString mLegendUrlFormat
Definition: qgsmaplayer.h:1565
QgsMapLayer::setCustomProperty
Q_INVOKABLE void setCustomProperty(const QString &key, const QVariant &value)
Set a custom property for layer.
Definition: qgsmaplayer.cpp:1708
QgsMapLayer::setRefreshOnNotifyEnabled
void setRefreshOnNotifyEnabled(bool enabled)
Set whether provider notification is connected to triggerRepaint.
Definition: qgsmaplayer.cpp:1924
QgsAbstract3DRenderer
Base class for all renderers that may to participate in 3D view.
Definition: qgsabstract3drenderer.h:49
QgsMapLayer::mIsRefreshOnNofifyEnabled
bool mIsRefreshOnNofifyEnabled
Definition: qgsmaplayer.h:1580
QgsMapLayer::mReadFlags
QgsMapLayer::ReadFlags mReadFlags
Read flags. It's up to the subclass to respect these when restoring state from XML.
Definition: qgsmaplayer.h:1589
QgsMapLayer::mAttributionUrl
QString mAttributionUrl
Definition: qgsmaplayer.h:1556
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:872
QgsMapLayer::Symbology3D
@ Symbology3D
3D symbology
Definition: qgsmaplayer.h:164
qgsstringutils.h
QgsMapLayer::dependencies
virtual QSet< QgsMapLayerDependency > dependencies() const
Gets the list of dependencies.
Definition: qgsmaplayer.cpp:1904
QgsMapLayer::isRefreshOnNotifyEnabled
bool isRefreshOnNotifyEnabled() const
Returns true if the refresh on provider nofification is enabled.
Definition: qgsmaplayer.h:1160
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:1037
QgsMapLayer::subLayers
virtual QStringList subLayers() const
Returns the sublayers of this layer.
Definition: qgsmaplayer.cpp:748
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:867
QgsLayerMetadata
A structured metadata store for a map layer.
Definition: qgslayermetadata.h:57
QgsMapLayer::shortName
QString shortName() const
Returns the short name of the layer used by QGIS Server to identify the layer.
Definition: qgsmaplayer.cpp:179
QgsMapLayerType
QgsMapLayerType
Types of layers that can be added to a map.
Definition: qgsmaplayer.h:68
QgsMapLayer::writeCustomProperties
void writeCustomProperties(QDomNode &layerNode, QDomDocument &doc) const
Write custom properties to project file.
Definition: qgsmaplayer.cpp:634
QgsMapLayer::setCustomProperties
void setCustomProperties(const QgsObjectCustomProperties &properties)
Set custom properties for layer.
Definition: qgsmaplayer.cpp:1713
QgsMapLayer::mDataUrlFormat
QString mDataUrlFormat
Definition: qgsmaplayer.h:1552
QgsMapLayer::setMetadataUrlType
void setMetadataUrlType(const QString &metaUrlType)
Set the metadata type of the layer used by QGIS Server in GetCapabilities request MetadataUrlType ind...
Definition: qgsmaplayer.h:430
QgsError
QgsError is container for error messages (report).
Definition: qgserror.h:81
QgsMapLayerLegend
The QgsMapLayerLegend class is abstract interface for implementations of legends for one map layer.
Definition: qgsmaplayerlegend.h:46
QgsMapLayer::styleManager
QgsMapLayerStyleManager * styleManager() const
Gets access to the layer's style manager.
Definition: qgsmaplayer.cpp:1806
qgspathresolver.h
QgsMapLayer::formatLayerName
static QString formatLayerName(const QString &name)
A convenience function to capitalize and format a layer name.
Definition: qgsmaplayer.cpp:791
QgsMapLayer::Metadata
@ Metadata
Definition: qgsmaplayer.h:138
Qgs3DRendererAbstractMetadata
Base metadata class for 3D renderers.
Definition: qgs3drendererregistry.h:35
QgsProject::instance
static QgsProject * instance()
Returns the QgsProject singleton instance.
Definition: qgsproject.cpp:468
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:92
QgsStyleEntityVisitorInterface
An interface for classes which can visit style entity (e.g.
Definition: qgsstyleentityvisitor.h:34
QgsMapLayer::PropertyType
PropertyType
Maplayer has a style and a metadata property.
Definition: qgsmaplayer.h:136
QgsMapLayer::setBlendMode
void setBlendMode(QPainter::CompositionMode blendMode)
Set the blending mode used for rendering a layer.
Definition: qgsmaplayer.cpp:202
QgsObjectCustomProperties::readXml
void readXml(const QDomNode &parentNode, const QString &keyStartsWith=QString())
Read store contents from an XML node.
Definition: qgsobjectcustomproperties.cpp:50
QgsMapLayer::readCustomProperties
void readCustomProperties(const QDomNode &layerNode, const QString &keyStartsWith=QString())
Read custom properties from project file.
Definition: qgsmaplayer.cpp:629
QgsMapLayer::isValid
bool isValid
Definition: qgsmaplayer.h:91
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:1079
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:1381
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:1463
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
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:2018
QgsMapLayer::customPropertyKeys
Q_INVOKABLE QStringList customPropertyKeys() const
Returns list of all keys within custom properties.
Definition: qgsmaplayer.cpp:1703
QgsMapLayer::htmlMetadata
virtual QString htmlMetadata() const
Obtain a formatted HTML string containing assorted metadata for this layer.
Definition: qgsmaplayer.cpp:1843
QgsMapLayer::legend
QgsMapLayerLegend * legend() const
Can be nullptr.
Definition: qgsmaplayer.cpp:1801
QgsReadWriteContext::enterCategory
MAYBE_UNUSED NODISCARD QgsReadWriteContextCategoryPopper enterCategory(const QString &category, const QString &details=QString())
Push a category to the stack.
Definition: qgsreadwritecontext.cpp:62
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:1894
QgsMapLayer::setMetadata
virtual void setMetadata(const QgsLayerMetadata &metadata)
Sets the layer's metadata store.
Definition: qgsmaplayer.cpp:1836
QgsMapLayer::setCrs
void setCrs(const QgsCoordinateReferenceSystem &srs, bool emitSignal=true)
Sets layer's spatial reference system.
Definition: qgsmaplayer.cpp:771
QgsMapLayer::mError
QgsError mError
Error.
Definition: qgsmaplayer.h:1568
QgsRectangle
A rectangle specified with double values.
Definition: qgsrectangle.h:42
QgsMapLayer::mShouldValidateCrs
bool mShouldValidateCrs
true if the layer's CRS should be validated and invalid CRSes are not permitted.
Definition: qgsmaplayer.h:1596
QgsMapLayer::dataUrl
QString dataUrl() const
Returns the DataUrl of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:345
QgsLayerMetadata::writeMetadataXml
bool writeMetadataXml(QDomElement &metadataElement, QDomDocument &document) const override
Stores state in a DOM node.
Definition: qgslayermetadata.cpp:242
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:857
QgsMapLayer::mProviderKey
QString mProviderKey
Data provider key (name of the data provider)
Definition: qgsmaplayer.h:1584
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:95
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:1140
QgsMapLayer::Rendering
@ Rendering
Rendering: scale visibility, simplify method, opacity.
Definition: qgsmaplayer.h:172
QgsDataProvider::transformContext
QgsCoordinateTransformContext transformContext() const
Returns data provider coordinate transform context.
Definition: qgsdataprovider.cpp:76
QgsMapLayer::providerType
QString providerType() const
Returns the provider type (provider key) for this layer.
Definition: qgsmaplayer.cpp:1617
QgsMapLayer::setLegendUrlFormat
void setLegendUrlFormat(const QString &legendUrlFormat)
Sets the format for a URL based layer legend.
Definition: qgsmaplayer.h:993
QgsApplication::authManager
static QgsAuthManager * authManager()
Returns the application's authentication manager instance.
Definition: qgsapplication.cpp:1282
QgsMapLayerTemporalProperties::readXml
virtual bool readXml(const QDomElement &element, const QgsReadWriteContext &context)=0
Reads temporal properties from a DOM element previously written by writeXml().
qgsapplication.h
QgsMapLayer::Temporal
@ Temporal
Temporal properties.
Definition: qgsmaplayer.h:176
QgsMapLayer::mLayerName
QString mLayerName
Name of the layer - used for display.
Definition: qgsmaplayer.h:1541
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:847
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:1826
QgsMapLayer::customProperties
const QgsObjectCustomProperties & customProperties() const
Read all custom properties from layer.
Definition: qgsmaplayer.cpp:1718
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:759
QgsMapLayer::isInScaleRange
bool isInScaleRange(double scale) const
Tests whether the layer should be visible at the specified scale.
Definition: qgsmaplayer.cpp:671
QgsMapLayer::flags
QgsMapLayer::LayerFlags flags() const
Returns the flags for this layer.
Definition: qgsmaplayer.cpp:134
QgsApplication::qgisSettingsDirPath
static QString qgisSettingsDirPath()
Returns the path to the settings directory in user's home dir.
Definition: qgsapplication.cpp:993
qgsmaplayertemporalproperties.h
QgsReadWriteContextCategoryPopper
Allows entering a context category and takes care of leaving this category on deletion of the class.
Definition: qgsreadwritecontext.h:159
QgsMapLayerStyleManager
Management of styles for use with one map layer.
Definition: qgsmaplayerstylemanager.h:56
qgsprojectfiletransform.h
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:608
QgsMapLayer::mValid
bool mValid
Indicates if the layer is valid and can be drawn.
Definition: qgsmaplayer.h:1535
QgsReadWriteContext::projectTranslator
const QgsProjectTranslator * projectTranslator() const
Returns the project translator.
Definition: qgsreadwritecontext.h:108
QgsMapLayer::setExtent
virtual void setExtent(const QgsRectangle &rect)
Sets the extent.
Definition: qgsmaplayer.cpp:1858
QgsMapLayer::mExtent
QgsRectangle mExtent
Extent of the layer.
Definition: qgsmaplayer.h:1532
QgsMapLayer::keywordList
QString keywordList() const
Returns the keyword list of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:325
QgsMapLayer::renderer3D
QgsAbstract3DRenderer * renderer3D() const
Returns 3D renderer associated with the layer.
Definition: qgsmaplayer.cpp:1821
QgsMapLayer::readSld
virtual bool readSld(const QDomNode &node, QString &errorMessage)
Definition: qgsmaplayer.h:891
QgsMapLayer::legendUrlFormat
QString legendUrlFormat() const
Returns the format for a URL based layer legend.
Definition: qgsmaplayer.h:998
qgsproviderregistry.h
QgsMapLayer::mMetadataUrl
QString mMetadataUrl
MetadataUrl of the layer.
Definition: qgsmaplayer.h:1559
QgsMapLayer::metadataUrlFormat
QString metadataUrlFormat() const
Returns the metadata format of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:457
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:2123
QgsMapLayer::readStyleManager
void readStyleManager(const QDomNode &layerNode)
Read style manager's configuration (if any). To be called by subclasses.
Definition: qgsmaplayer.cpp:639
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:540
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:197
QgsMapLayer::mAttribution
QString mAttribution
Attribution of the layer.
Definition: qgsmaplayer.h:1555
QgsMapLayer::setOriginalXmlProperties
void setOriginalXmlProperties(const QString &originalXmlProperties)
Sets the original XML properties for the layer to originalXmlProperties.
Definition: qgsmaplayer.cpp:1873
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:1571
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:64
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:722
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:30
QgsVectorLayer::writeSld
bool writeSld(QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsStringMap &props=QgsStringMap()) const
Writes the symbology of the layer into the document provided in SLD 1.1 format.
Definition: qgsvectorlayer.cpp:2904
QgsMapLayer::temporalProperties
virtual QgsMapLayerTemporalProperties * temporalProperties()
Returns the layer's temporal properties.
Definition: qgsmaplayer.h:1203
qgsvectordataprovider.h
QgsMapLayer::mTitle
QString mTitle
Definition: qgsmaplayer.h:1544
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:862
QgsCoordinateReferenceSystem::isValid
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
Definition: qgscoordinatereferencesystem.cpp:924
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:433
QgsMapLayer::mDataUrl
QString mDataUrl
DataUrl of the layer.
Definition: qgsmaplayer.h:1551
QgsMapLayer::mMetadataUrlFormat
QString mMetadataUrlFormat
Definition: qgsmaplayer.h:1561
QgsMapLayer::QgsMapLayer
QgsMapLayer(QgsMapLayerType type=QgsMapLayerType::VectorLayer, const QString &name=QString(), const QString &source=QString())
Constructor for QgsMapLayer.
Definition: qgsmaplayer.cpp:71
QgsMapLayer::isEditable
virtual bool isEditable() const
Returns true if the layer can be edited.
Definition: qgsmaplayer.cpp:1740
QgsMapLayer::setKeywordList
void setKeywordList(const QString &keywords)
Sets the keyword list of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:317
QgsMapLayer::id
QString id() const
Returns the layer's unique ID, which is used to access this layer from QgsProject.
Definition: qgsmaplayer.cpp:148
QgsMapLayer::title
QString title() const
Returns the title of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:293
QgsMapLayer::setTitle
void setTitle(const QString &title)
Sets the title of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:285
QgsMapLayerTemporalProperties
Base class for storage of map layer temporal properties.
Definition: qgsmaplayertemporalproperties.h:43
QgsMapLayer::mDataSource
QString mDataSource
Data source description string, varies by layer type.
Definition: qgsmaplayer.h:1538
QgsApplication::pkgDataPath
static QString pkgDataPath()
Returns the common root path of all application data directories.
Definition: qgsapplication.cpp:578
QgsMapLayer::hasScaleBasedVisibility
bool hasScaleBasedVisibility() const
Returns whether scale based visibility is enabled for the layer.
Definition: qgsmaplayer.cpp:678
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:1098
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:614
QgsRasterLayer
Represents a raster layer.
Definition: qgsrasterlayer.h:71
QgsMapLayer::setRenderer3D
void setRenderer3D(QgsAbstract3DRenderer *renderer)
Sets 3D renderer for the layer.
Definition: qgsmaplayer.cpp:1811
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:1868
QgsCoordinateReferenceSystem::validate
void validate()
Perform some validation on this CRS.
Definition: qgscoordinatereferencesystem.cpp:501
QgsMapLayer::removeCustomProperty
void removeCustomProperty(const QString &key)
Remove a custom property from layer.
Definition: qgsmaplayer.cpp:1728
QgsStringUtils::capitalize
static QString capitalize(const QString &string, Capitalization capitalization)
Converts a string by applying capitalization rules to the string.
Definition: qgsstringutils.cpp:25
qgs3drendererregistry.h
QgsMapLayer::minimumScale
double minimumScale() const
Returns the minimum map scale (i.e.
Definition: qgsmaplayer.cpp:743
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:727
QgsCoordinateReferenceSystem
This class represents a coordinate reference system (CRS).
Definition: qgscoordinatereferencesystem.h:206
QgsObjectCustomProperties::remove
void remove(const QString &key)
Removes a key (entry) from the store.
Definition: qgsobjectcustomproperties.cpp:40
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
QgsMapLayerDependency::FromUser
@ FromUser
Definition: qgsmaplayerdependency.h:50
QgsCoordinateReferenceSystem::setCustomCrsValidation
static void setCustomCrsValidation(CUSTOM_CRS_VALIDATION f)
Sets custom function to force valid CRS.
Definition: qgscoordinatereferencesystem.cpp:2253
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
void setMetadataUrlFormat(const QString &metaUrlFormat)
Sets the metadata format of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:448
QgsMapLayer::isTemporary
virtual bool isTemporary() const
Returns true if the layer is considered a temporary layer.
Definition: qgsmaplayer.cpp:1750
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:392
QgsMapLayer::legendUrl
QString legendUrl() const
Returns the URL for the layer's legend.
Definition: qgsmaplayer.h:988
QgsMapLayer::publicSource
QString publicSource() const
Gets a version of the internal layer definition that has sensitive bits removed (for example,...
Definition: qgsmaplayer.cpp:184
QgsProjectFileTransform
Definition: qgsprojectfiletransform.h:42
QgsMapLayer::source
QString source() const
Returns the source for the layer.
Definition: qgsmaplayer.cpp:192
QgsAuthManager::setMasterPassword
bool setMasterPassword(bool verify=false)
Main call to initially set or continually check master password is set.
Definition: qgsauthmanager.cpp:493
QgsMapLayer::setDataSource
virtual void setDataSource(const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, bool loadDefaultStyleFlag=false)
Updates the data source of the layer.
Definition: qgsmaplayer.cpp:1607
QgsStringMap
QMap< QString, QString > QgsStringMap
Definition: qgis.h:758
QgsMapLayer::mAbstract
QString mAbstract
Description of the layer.
Definition: qgsmaplayer.h:1547
QgsMapLayer::writeStyleManager
void writeStyleManager(QDomNode &layerNode, QDomDocument &doc) const
Write style manager's configuration (if exists). To be called by subclasses.
Definition: qgsmaplayer.cpp:648
QgsMapLayer::setScaleBasedVisibility
void setScaleBasedVisibility(bool enabled)
Sets whether scale based visibility is enabled for the layer.
Definition: qgsmaplayer.cpp:738
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 docment provided.
QgsMapLayer::extensionPropertyType
static QString extensionPropertyType(PropertyType type)
Returns the extension of a Property.
Definition: qgsmaplayer.cpp:58
QgsMapLayer::customProperty
Q_INVOKABLE QVariant customProperty(const QString &value, const QVariant &defaultValue=QVariant()) const
Read a custom property from layer.
Definition: qgsmaplayer.cpp:1723
QgsMapLayer::transformContext
QgsCoordinateTransformContext transformContext() const
Returns the layer data provider coordinate transform context or a default transform context if the la...
Definition: qgsmaplayer.cpp:785
QgsStringUtils::ForceFirstLetterToCapital
@ ForceFirstLetterToCapital
Convert just the first letter of each word to uppercase, leave the rest untouched.
Definition: qgsstringutils.h:193
QgsWkbTypes::GeometryType
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
Definition: qgswkbtypes.h:141
QgsApplication::renderer3DRegistry
static Qgs3DRendererRegistry * renderer3DRegistry()
Returns registry of available 3D renderers.
Definition: qgsapplication.cpp:2283
QgsMapLayer::setRefreshOnNofifyMessage
void setRefreshOnNofifyMessage(const QString &message)
Set the notification message that triggers repaint If refresh on notification is enabled,...
Definition: qgsmaplayer.h:1278
QgsMapLayer::setName
void setName(const QString &name)
Set the display name of the layer.
Definition: qgsmaplayer.cpp:153
QgsMapLayer::setDataUrlFormat
void setDataUrlFormat(const QString &dataUrlFormat)
Sets the DataUrl format of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:354
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:387
QgsObjectCustomProperties
Simple key-value store (keys = strings, values = variants) that supports loading/saving to/from XML i...
Definition: qgsobjectcustomproperties.h:36
QgsMapLayer
Base class for all map layer types.
Definition: qgsmaplayer.h:83
QgsObjectCustomProperties::keys
QStringList keys() const
Returns a list of all stored keys.
Definition: qgsobjectcustomproperties.cpp:25
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:983
QgsMapLayer::readLayerXml
bool readLayerXml(const QDomElement &layerElement, QgsReadWriteContext &context, QgsMapLayer::ReadFlags flags=QgsMapLayer::ReadFlags())
Sets state from DOM document.
Definition: qgsmaplayer.cpp:218
QgsObjectCustomProperties::value
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
Returns the value for the given key.
Definition: qgsobjectcustomproperties.cpp:35
QgsMapLayer::setAutoRefreshInterval
void setAutoRefreshInterval(int interval)
Sets the auto refresh interval (in milliseconds) for the layer.
Definition: qgsmaplayer.cpp:693
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:381
QgsMapLayer::Symbology
@ Symbology
Symbology.
Definition: qgsmaplayer.h:163
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:852
QgsMapLayer::metadataUrl
QString metadataUrl() const
Returns the metadata URL of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:421
QgsMapLayer::name
QString name
Definition: qgsmaplayer.h:86
QgsMapLayer::undoStackStyles
QUndoStack * undoStackStyles()
Returns pointer to layer's style undo stack.
Definition: qgsmaplayer.cpp:1698
qgsmaplayerlegend.h
QgsMapLayer::setAutoRefreshEnabled
void setAutoRefreshEnabled(bool enabled)
Sets whether auto refresh is enabled for the layer.
Definition: qgsmaplayer.cpp:707
QgsMapLayer::LayerConfiguration
@ LayerConfiguration
General configuration: identifiable, removable, searchable, display expression, read-only.
Definition: qgsmaplayer.h:162
Qgis::SCALE_PRECISION
static const double SCALE_PRECISION
Fudge factor used to compare two scales.
Definition: qgis.h:168
QgsMapLayer::undoStack
QUndoStack * undoStack()
Returns pointer to layer's undo stack.
Definition: qgsmaplayer.cpp:1693
qgssqliteutils.h
QgsMapLayer::CustomProperties
@ CustomProperties
Custom properties (by plugins for instance)
Definition: qgsmaplayer.h:173
QgsMapLayer::setMinimumScale
void setMinimumScale(double scale)
Sets the minimum map scale (i.e.
Definition: qgsmaplayer.cpp:733
QgsMapLayer::setAttribution
void setAttribution(const QString &attrib)
Sets the attribution of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:374
QgsMapLayer::mRefreshOnNofifyMessage
QString mRefreshOnNofifyMessage
Definition: qgsmaplayer.h:1581
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:1587
QgsMapLayer::mLegendUrl
QString mLegendUrl
WMS legend.
Definition: qgsmaplayer.h:1564
QgsMapLayer::importNamedMetadata
bool importNamedMetadata(QDomDocument &document, QString &errorMessage)
Import the metadata of this layer from a QDomDocument.
Definition: qgsmaplayer.cpp:1025
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:842
QgsMapLayer::setDependencies
virtual bool setDependencies(const QSet< QgsMapLayerDependency > &layers)
Sets the list of dependencies.
Definition: qgsmaplayer.cpp:1909
QgsCoordinateReferenceSystem::setValidationHint
void setValidationHint(const QString &html)
Set user hint for validation.
Definition: qgscoordinatereferencesystem.cpp:2285
QgsMapLayer::saveDefaultStyle
virtual QString saveDefaultStyle(bool &resultFlag)
Save the properties of this layer as the default style (either as a .qml file on disk or as a record ...
Definition: qgsmaplayer.cpp:1135
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:1745
QgsDataSourceUri::removePassword
static QString removePassword(const QString &aUri)
Removes the password element from a URI.
Definition: qgsdatasourceuri.cpp:220
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:336
QgsMapLayer::setValid
void setValid(bool valid)
Sets whether layer is valid or not.
Definition: qgsmaplayer.cpp:1775
QgsMapLayer::AllStyleCategories
@ AllStyleCategories
Definition: qgsmaplayer.h:178
sqlite3_database_unique_ptr
Unique pointer for sqlite3 databases, which automatically closes the database when the pointer goes o...
Definition: qgssqliteutils.h:119
QgsVectorLayer::geometryType
Q_INVOKABLE QgsWkbTypes::GeometryType geometryType() const
Returns point, line or polygon.
Definition: qgsvectorlayer.cpp:659
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:271
QgsProviderRegistry::instance
static QgsProviderRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.
Definition: qgsproviderregistry.cpp:48
QgsMapLayer::attribution
QString attribution() const
Returns the attribution of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:383
QgsMapLayer::metadataUrlType
QString metadataUrlType() const
Returns the metadata type of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:439
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:1386
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:928
QgsMapLayer::setProviderType
void setProviderType(const QString &providerType)
Sets the providerType (provider key)
Definition: qgsmaplayer.cpp:1899
qgscoordinatereferencesystem.h
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:1145
QgsMapLayer::mKeywordList
QString mKeywordList
Definition: qgsmaplayer.h:1548
qgsproject.h
QgsMapLayer::setLegend
void setLegend(QgsMapLayerLegend *legend)
Assign a legend controller to the map layer.
Definition: qgsmaplayer.cpp:1784
QgsMapLayer::metadata
QgsLayerMetadata metadata
Definition: qgsmaplayer.h:88
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
QgsMapLayer::dataProvider
virtual QgsDataProvider * dataProvider()
Returns the layer's data provider, it may be nullptr.
Definition: qgsmaplayer.cpp:169
sqlite3_statement_unique_ptr
Unique pointer for sqlite3 prepared statements, which automatically finalizes the statement when the ...
Definition: qgssqliteutils.h:70
QgsObjectCustomProperties::writeXml
void writeXml(QDomNode &parentNode, QDomDocument &doc) const
Writes the store contents to an XML node.
Definition: qgsobjectcustomproperties.cpp:115
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:1596
QgsMapLayer::mShortName
QString mShortName
Definition: qgsmaplayer.h:1543
QgsMapLayer::timestamp
virtual QDateTime timestamp() const
Time stamp of data source in the moment when data/metadata were loaded by provider.
Definition: qgsmaplayer.cpp:1848
QgsMapLayer::setLayerOrder
virtual void setLayerOrder(const QStringList &layers)
Reorders the previously selected sublayers of this layer from bottom to top.
Definition: qgsmaplayer.cpp:753
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.
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:66
QgsMapLayer::metadataChanged
void metadataChanged()
Emitted when the layer's metadata is changed.
QgsMapLayer::error
virtual QgsError error() const
Gets current status error.
Definition: qgsmaplayer.cpp:1733
QgsMapLayer::mMetadataUrlType
QString mMetadataUrlType
Definition: qgsmaplayer.h:1560
QgsMapLayer::type
QgsMapLayerType type
Definition: qgsmaplayer.h:90