79 Q_PROPERTY( QString
id READ
id WRITE setId NOTIFY idChanged )
80 Q_PROPERTY( QString name READ name WRITE setName NOTIFY nameChanged )
81 Q_PROPERTY(
int autoRefreshInterval READ autoRefreshInterval WRITE setAutoRefreshInterval NOTIFY autoRefreshIntervalChanged )
82 Q_PROPERTY(
QgsLayerMetadata metadata READ metadata WRITE setMetadata NOTIFY metadataChanged )
86 Q_PROPERTY(
Qgis::LayerType type READ type CONSTANT )
87 Q_PROPERTY(
bool isValid READ isValid NOTIFY isValidChanged )
88 Q_PROPERTY(
double opacity READ opacity WRITE setOpacity NOTIFY opacityChanged )
89 Q_PROPERTY( QString mapTipTemplate READ mapTipTemplate WRITE setMapTipTemplate NOTIFY mapTipTemplateChanged )
90 Q_PROPERTY(
bool mapTipsEnabled READ mapTipsEnabled WRITE setMapTipsEnabled NOTIFY mapTipsEnabledChanged )
94 QgsMapLayer *layer = qobject_cast<QgsMapLayer *>( sipCpp );
100 switch ( layer->type() )
103 sipType = sipType_QgsVectorLayer;
106 sipType = sipType_QgsRasterLayer;
109 sipType = sipType_QgsPluginLayer;
112 sipType = sipType_QgsMeshLayer;
115 sipType = sipType_QgsVectorTileLayer;
118 sipType = sipType_QgsAnnotationLayer;
121 sipType = sipType_QgsPointCloudLayer;
124 sipType = sipType_QgsGroupLayer;
127 sipType = sipType_QgsTiledSceneLayer;
155 Identifiable = 1 << 0,
170 LayerConfiguration = 1 << 0,
172 Symbology3D = 1 << 2,
179 AttributeTable = 1 << 9,
181 CustomProperties = 1 << 11,
182 GeometryOptions = 1 << 12,
188 AllStyleCategories = LayerConfiguration | Symbology | Symbology3D | Labeling | Fields | Forms | Actions |
189 MapTips | Diagrams | AttributeTable | Rendering | CustomProperties | GeometryOptions | Relations | Temporal | Legend | Elevation | Notes,
191 Q_ENUM( StyleCategory )
201 QgsMapLayer(
Qgis::LayerType type =
Qgis::LayerType::Vector, const QString &name = QString(), const QString &source = QString() );
218 Qgis::LayerType type() const;
253 virtual
Qgis::MapLayerProperties properties() const;
259 static QString extensionPropertyType(
PropertyType type );
284 bool setId( const QString &
id );
290 void setName( const QString &name );
296 QString name() const;
320 Q_DECL_DEPRECATED
void setShortName( const QString &shortName )
SIP_DEPRECATED;
334 Q_DECL_DEPRECATED
void setTitle( const QString &title )
SIP_DEPRECATED;
348 Q_DECL_DEPRECATED
void setAbstract( const QString &abstract )
SIP_DEPRECATED;
362 Q_DECL_DEPRECATED
void setKeywordList( const QString &keywords )
SIP_DEPRECATED;
376 Q_DECL_DEPRECATED
void setDataUrl( const QString &dataUrl )
SIP_DEPRECATED;
390 Q_DECL_DEPRECATED
void setDataUrlFormat( const QString &dataUrlFormat )
SIP_DEPRECATED;
404 Q_DECL_DEPRECATED
void setAttribution( const QString &attrib )
SIP_DEPRECATED;
418 Q_DECL_DEPRECATED
void setAttributionUrl( const QString &attribUrl )
SIP_DEPRECATED;
449 Q_DECL_DEPRECATED
void setMetadataUrl(
const QString &metaUrl )
SIP_DEPRECATED;
470 Q_DECL_DEPRECATED
void setMetadataUrlType( const QString &metaUrlType )
SIP_DEPRECATED;
491 Q_DECL_DEPRECATED
void setMetadataUrlFormat( const QString &metaUrlFormat )
SIP_DEPRECATED;
502 Q_DECL_DEPRECATED QString metadataUrlFormat() const
SIP_DEPRECATED;
509 void setBlendMode( QPainter::CompositionMode blendMode );
515 QPainter::CompositionMode blendMode() const;
525 virtual
void setOpacity(
double opacity );
535 virtual
double opacity() const;
538 bool readOnly()
const {
return isReadOnly(); }
567 QgsRectangle wgs84Extent(
bool forceRecalculate =
false )
const;
574 bool isValid()
const;
583 QString publicSource(
bool hidePassword =
false )
const;
590 QString source()
const;
596 virtual QStringList subLayers()
const;
602 virtual void setLayerOrder(
const QStringList &layers );
609 virtual void setSubLayerVisibility(
const QString &name,
bool visible );
617 virtual bool supportsEditing()
const;
620 virtual bool isEditable()
const;
627 virtual bool isModified()
const;
632 virtual bool isSpatial()
const;
643 virtual bool isTemporary()
const;
651 FlagDontResolveLayers = 1 << 0,
652 FlagTrustLayerMetadata = 1 << 1,
653 FlagReadExtentFromXml = 1 << 2,
654 FlagForceReadOnly = 1 << 3,
693 bool writeLayerXml( QDomElement &layerElement, QDomDocument &document,
const QgsReadWriteContext &context )
const;
698 virtual void resolveReferences(
QgsProject *project );
704 Q_INVOKABLE QStringList customPropertyKeys()
const;
711 Q_INVOKABLE
void setCustomProperty(
const QString &key,
const QVariant &value );
717 Q_INVOKABLE QVariant customProperty(
const QString &value,
const QVariant &defaultValue = QVariant() )
const;
740 virtual int listStylesInDatabase( QStringList &ids
SIP_OUT, QStringList &names
SIP_OUT,
746 virtual QString getStyleFromDatabase(
const QString &styleId, QString &msgError
SIP_OUT );
754 virtual bool deleteStyleFromDatabase(
const QString &styleId, QString &msgError
SIP_OUT );
772 virtual void saveStyleToDatabase(
const QString &name,
const QString &description,
773 bool useAsDefault,
const QString &uiFileContent,
791 virtual QString loadNamedStyle(
const QString &theURI,
bool &resultFlag
SIP_OUT,
bool loadFromLocalDb,
810 const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
811 Q_ASSERT( metaEnum.isValid() );
812 if ( !metaEnum.isValid() )
814 QgsDebugError( QStringLiteral(
"Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." ) );
820 if ( metaEnum.isValid() )
823 QByteArray ba = customProperty( key, metaEnum.valueToKey(
static_cast<int>( defaultValue ) ) ).toString().toUtf8();
824 const char *vs = ba.data();
825 v =
static_cast<T
>( metaEnum.keyToValue( vs, &ok ) );
833 v =
static_cast<T
>( customProperty( key,
static_cast<int>( defaultValue ) ).toInt( &ok ) );
834 if ( metaEnum.isValid() )
836 if ( !ok || !metaEnum.valueToKey(
static_cast<int>( v ) ) )
844 setCustomEnumProperty( key, v );
862 const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
863 Q_ASSERT( metaEnum.isValid() );
864 if ( metaEnum.isValid() )
866 setCustomProperty( key, metaEnum.valueToKey(
static_cast<int>( value ) ) );
870 QgsDebugError( QStringLiteral(
"Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." ) );
888 const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
889 Q_ASSERT( metaEnum.isValid() );
890 if ( !metaEnum.isValid() )
892 QgsDebugError( QStringLiteral(
"Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." ) );
898 if ( metaEnum.isValid() )
901 QByteArray ba = customProperty( key, metaEnum.valueToKeys( defaultValue ) ).toString().toUtf8();
902 const char *vs = ba.data();
903 v =
static_cast<T
>( metaEnum.keysToValue( vs, &ok ) );
908 const int intValue = customProperty( key,
static_cast<int>( defaultValue ) ).toInt( &ok );
909 if ( metaEnum.isValid() )
915 const QByteArray keys = metaEnum.valueToKeys( intValue );
916 const int intValueCheck = metaEnum.keysToValue( keys );
917 if ( intValue != intValueCheck )
928 setCustomFlagProperty( key, v );
952 const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
953 Q_ASSERT( metaEnum.isValid() );
954 if ( metaEnum.isValid() )
956 setCustomProperty( key, metaEnum.valueToKeys( value ) );
960 QgsDebugError( QStringLiteral(
"Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." ) );
970 void removeCustomProperty(
const QString &key );
1077 static QString formatLayerName(
const QString &name );
1085 virtual QString metadataUri()
const;
1092 void exportNamedMetadata( QDomDocument &doc, QString &errorMsg )
const;
1102 virtual QString saveDefaultMetadata(
bool &resultFlag
SIP_OUT );
1117 QString saveNamedMetadata(
const QString &uri,
bool &resultFlag );
1135 virtual QString loadNamedMetadata(
const QString &uri,
bool &resultFlag
SIP_OUT );
1148 virtual QString loadDefaultMetadata(
bool &resultFlag );
1157 bool loadNamedMetadataFromDatabase(
const QString &db,
const QString &uri, QString &qmd );
1165 bool importNamedMetadata( QDomDocument &document, QString &errorMessage );
1175 virtual QString styleURI()
const;
1189 virtual QString loadDefaultStyle(
bool &resultFlag
SIP_OUT );
1219 virtual bool loadNamedStyleFromDatabase(
const QString &db,
const QString &uri, QString &qml
SIP_OUT );
1229 virtual bool importNamedStyle( QDomDocument &doc, QString &errorMsg
SIP_OUT,
1251 virtual void exportSldStyle( QDomDocument &doc, QString &errorMsg )
const;
1261 virtual void exportSldStyleV2( QDomDocument &doc, QString &errorMsg,
const QgsSldExportContext &exportContext )
const;
1274 virtual QString saveDefaultStyle(
bool &resultFlag
SIP_OUT, StyleCategories categories );
1304 virtual QString saveNamedStyle(
const QString &uri,
bool &resultFlag
SIP_OUT, StyleCategories categories = AllStyleCategories );
1315 virtual QString saveSldStyle(
const QString &uri,
bool &resultFlag )
const;
1337 virtual QString loadSldStyle(
const QString &uri,
bool &resultFlag );
1339 virtual bool readSld(
const QDomNode &node, QString &errorMessage )
1340 { Q_UNUSED( node ) errorMessage = QStringLiteral(
"Layer type %1 not supported" ).arg(
static_cast<int>( type() ) );
return false; }
1364 virtual bool readStyle(
const QDomNode &node, QString &errorMessage,
1391 virtual bool writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage,
const QgsReadWriteContext &context,
1425 void setDataSource(
const QString &dataSource,
const QString &baseName = QString(),
const QString &provider = QString(),
bool loadDefaultStyleFlag =
false );
1456 void setDataSource(
const QString &dataSource,
const QString &baseName,
const QString &provider,
const QgsDataProvider::ProviderOptions &options,
bool loadDefaultStyleFlag =
false );
1492 QString providerType()
const;
1495 QUndoStack *undoStack();
1500 QUndoStack *undoStackStyles();
1556 bool isInScaleRange(
double scale )
const;
1568 double minimumScale()
const;
1580 double maximumScale()
const;
1590 bool hasScaleBasedVisibility()
const;
1598 Q_DECL_DEPRECATED
bool hasAutoRefreshEnabled() const
SIP_DEPRECATED;
1606 Qgis::AutoRefreshMode autoRefreshMode() const;
1614 int autoRefreshInterval() const;
1626 void setAutoRefreshInterval(
int interval );
1634 Q_DECL_DEPRECATED
void setAutoRefreshEnabled(
bool enabled )
SIP_DEPRECATED;
1642 void setAutoRefreshMode(
Qgis::AutoRefreshMode mode );
1661 virtual QString htmlMetadata() const;
1664 virtual QDateTime timestamp() const;
1678 QString refreshOnNotifyMessage()
const {
return mRefreshOnNofifyMessage; }
1694 QString originalXmlProperties()
const;
1703 void setOriginalXmlProperties(
const QString &originalXmlProperties );
1709 static QString generateId(
const QString &layerName );
1763 virtual bool hasMapTips()
const;
1772 QString mapTipTemplate()
const;
1781 void setMapTipTemplate(
const QString &mapTipTemplate );
1789 void setMapTipsEnabled(
bool enabled );
1795 bool mapTipsEnabled()
const;
1817 void setMinimumScale(
double scale );
1828 void setMaximumScale(
double scale );
1837 void setScaleBasedVisibility(
bool enabled );
1847 void triggerRepaint(
bool deferredUpdate =
false );
1855 void trigger3DUpdate();
1860 void emitStyleChanged();
1869 virtual bool setDependencies(
const QSet<QgsMapLayerDependency> &layers );
1875 void setRefreshOnNotifyEnabled(
bool enabled );
1893 SIP_PYOBJECT __repr__();
1895 QString str = QStringLiteral(
"<QgsMapLayer: '%1' (%2)>" ).arg( sipCpp->name(), sipCpp->dataProvider() ? sipCpp->dataProvider()->name() : QStringLiteral(
"Invalid" ) );
1896 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
2140 void onNotified(
const QString &message );
2174 virtual void setExtent3D(
const QgsBox3D &box );
2177 void setValid(
bool valid );
2189 virtual bool writeXml( QDomNode &layer_node, QDomDocument &document,
const QgsReadWriteContext &context )
const;
2202 virtual QString encodedSource(
const QString &source,
const QgsReadWriteContext &context )
const;
2216 virtual QString decodedSource(
const QString &source,
const QString &dataProvider,
const QgsReadWriteContext &context )
const;
2223 void readCustomProperties(
const QDomNode &layerNode,
const QString &keyStartsWith = QString() );
2226 void writeCustomProperties( QDomNode &layerNode, QDomDocument &doc )
const;
2229 void readStyleManager(
const QDomNode &layerNode );
2231 void writeStyleManager( QDomNode &layerNode, QDomDocument &doc )
const;
2236 void writeCommonStyle( QDomElement &layerElement, QDomDocument &document,
2243 void readCommonStyle(
const QDomElement &layerElement,
const QgsReadWriteContext &context,
2247 void setProviderType(
const QString &providerType );
2252 void connectNotify(
const char *signal )
override;
2267 void invalidateWgs84Extent();
2270 bool mValid =
false;
2295 bool mIsRefreshOnNofifyEnabled =
false;
2311 bool mShouldValidateCrs =
true;
2318 double mLayerOpacity = 1.0;
2325 int mBlockStyleChangedSignal = 0;
2337 QString crsHtmlMetadata()
const;
2350 QString generalHtmlMetadata()
const;
2360 QString customPropertyHtmlMetadata()
const;
2382 bool loadNamedPropertyFromDatabase(
const QString &db,
const QString &uri, QString &xml,
QgsMapLayer::PropertyType type );
2386 void updateExtent(
const QgsBox3D &extent )
const;
2388 bool rebuildCrs3D( QString *error =
nullptr );
2394 virtual bool isReadOnly()
const;
2413 QPainter::CompositionMode mBlendMode = QPainter::CompositionMode_SourceOver;
2421 double mMinScale = 0;
2423 double mMaxScale = 100000000;
2425 bool mScaleBasedVisibility =
false;
2430 std::unique_ptr< QgsMapLayerServerProperties > mServerProperties;
2433 QUndoStack *mUndoStack =
nullptr;
2435 QUndoStack *mUndoStackStyles =
nullptr;
2449 QTimer *mRefreshTimer =
nullptr;
2470 QString mOriginalXmlProperties;
2473 bool mRepaintRequestedFired =
false;
2476 QString mLegendPlaceholderImage;
2479 QString mMapTipTemplate;
2482 bool mMapTipsEnabled =
true;
2485 friend class TestQgsProject;
2486 friend class TestQgsMapLayer;