21 #include "qgis_core.h"
64 #define QGSCLIPBOARD_MAPLAYER_MIME "application/qgis.maplayer"
76 Q_PROPERTY( QString name READ name WRITE setName NOTIFY nameChanged )
77 Q_PROPERTY(
int autoRefreshInterval READ autoRefreshInterval WRITE setAutoRefreshInterval NOTIFY autoRefreshIntervalChanged )
78 Q_PROPERTY(
QgsLayerMetadata metadata READ metadata WRITE setMetadata NOTIFY metadataChanged )
81 Q_PROPERTY(
bool isValid READ isValid NOTIFY isValidChanged )
82 Q_PROPERTY(
double opacity READ opacity WRITE setOpacity NOTIFY opacityChanged )
86 QgsMapLayer *layer = qobject_cast<QgsMapLayer *>( sipCpp );
92 switch ( layer->type() )
95 sipType = sipType_QgsVectorLayer;
98 sipType = sipType_QgsRasterLayer;
101 sipType = sipType_QgsPluginLayer;
104 sipType = sipType_QgsMeshLayer;
107 sipType = sipType_QgsVectorTileLayer;
110 sipType = sipType_QgsAnnotationLayer;
113 sipType = sipType_QgsPointCloudLayer;
116 sipType = sipType_QgsGroupLayer;
145 Identifiable = 1 << 0,
151 Q_DECLARE_FLAGS( LayerFlags, LayerFlag )
160 LayerConfiguration = 1 << 0,
162 Symbology3D = 1 << 2,
169 AttributeTable = 1 << 9,
171 CustomProperties = 1 << 11,
172 GeometryOptions = 1 << 12,
178 AllStyleCategories = LayerConfiguration | Symbology | Symbology3D | Labeling | Fields | Forms | Actions |
179 MapTips | Diagrams | AttributeTable | Rendering | CustomProperties | GeometryOptions | Relations | Temporal | Legend | Elevation | Notes,
181 Q_ENUM( StyleCategory )
182 Q_DECLARE_FLAGS( StyleCategories, StyleCategory )
183 Q_FLAG( StyleCategories )
223 QgsMapLayer::LayerFlags flags()
const;
235 void setFlags( QgsMapLayer::LayerFlags flags );
246 virtual Qgis::MapLayerProperties properties()
const;
253 static QString extensionPropertyType( PropertyType type );
263 void setName(
const QString &name );
269 QString name()
const;
288 void setShortName( const QString &shortName ) { mShortName = shortName; }
295 QString shortName()
const;
302 void setTitle(
const QString &title ) { mTitle = title; }
310 QString
title()
const {
return mTitle; }
318 void setAbstract(
const QString &
abstract ) { mAbstract =
abstract; }
326 QString
abstract()
const {
return mAbstract; }
353 void setDataUrl(
const QString &dataUrl ) { mDataUrl = dataUrl; }
442 Q_DECL_DEPRECATED
void setMetadataUrl(
const QString &metaUrl )
SIP_DEPRECATED;
464 Q_DECL_DEPRECATED
void setMetadataUrlType( const QString &metaUrlType )
SIP_DEPRECATED;
485 Q_DECL_DEPRECATED
void setMetadataUrlFormat( const QString &metaUrlFormat )
SIP_DEPRECATED;
496 Q_DECL_DEPRECATED QString metadataUrlFormat() const
SIP_DEPRECATED;
503 void setBlendMode( QPainter::CompositionMode blendMode );
509 QPainter::CompositionMode blendMode() const;
519 virtual
void setOpacity(
double opacity );
529 virtual
double opacity() const;
532 bool readOnly()
const {
return isReadOnly(); }
556 QgsRectangle wgs84Extent(
bool forceRecalculate =
false )
const;
563 bool isValid()
const;
571 QString publicSource()
const;
578 QString source()
const;
584 virtual QStringList subLayers()
const;
590 virtual void setLayerOrder(
const QStringList &layers );
597 virtual void setSubLayerVisibility(
const QString &name,
bool visible );
605 virtual bool supportsEditing()
const;
608 virtual bool isEditable()
const;
615 virtual bool isModified()
const;
621 virtual bool isSpatial()
const;
632 virtual bool isTemporary()
const;
640 FlagDontResolveLayers = 1 << 0,
641 FlagTrustLayerMetadata = 1 << 1,
642 FlagReadExtentFromXml = 1 << 2,
644 Q_DECLARE_FLAGS( ReadFlags, ReadFlag )
663 bool readLayerXml(
const QDomElement &layerElement,
QgsReadWriteContext &context, QgsMapLayer::ReadFlags flags = QgsMapLayer::ReadFlags() );
682 bool writeLayerXml( QDomElement &layerElement, QDomDocument &document,
const QgsReadWriteContext &context )
const;
688 virtual void resolveReferences(
QgsProject *project );
695 Q_INVOKABLE QStringList customPropertyKeys()
const;
702 Q_INVOKABLE
void setCustomProperty(
const QString &key,
const QVariant &value );
708 Q_INVOKABLE QVariant customProperty(
const QString &value,
const QVariant &defaultValue = QVariant() )
const;
738 const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
739 Q_ASSERT( metaEnum.isValid() );
740 if ( !metaEnum.isValid() )
742 QgsDebugMsg( QStringLiteral(
"Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." ) );
748 if ( metaEnum.isValid() )
751 QByteArray ba = customProperty( key, metaEnum.valueToKey(
static_cast<int>( defaultValue ) ) ).toString().toUtf8();
752 const char *vs = ba.data();
753 v =
static_cast<T
>( metaEnum.keyToValue( vs, &ok ) );
761 v =
static_cast<T
>( customProperty( key,
static_cast<int>( defaultValue ) ).toInt( &ok ) );
762 if ( metaEnum.isValid() )
764 if ( !ok || !metaEnum.valueToKey(
static_cast<int>( v ) ) )
772 setCustomEnumProperty( key, v );
790 const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
791 Q_ASSERT( metaEnum.isValid() );
792 if ( metaEnum.isValid() )
794 setCustomProperty( key, metaEnum.valueToKey(
static_cast<int>( value ) ) );
798 QgsDebugMsg( QStringLiteral(
"Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." ) );
816 const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
817 Q_ASSERT( metaEnum.isValid() );
818 if ( !metaEnum.isValid() )
820 QgsDebugMsg( QStringLiteral(
"Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." ) );
826 if ( metaEnum.isValid() )
829 QByteArray ba = customProperty( key, metaEnum.valueToKeys( defaultValue ) ).toString().toUtf8();
830 const char *vs = ba.data();
831 v =
static_cast<T
>( metaEnum.keysToValue( vs, &ok ) );
836 const int intValue = customProperty( key,
static_cast<int>( defaultValue ) ).toInt( &ok );
837 if ( metaEnum.isValid() )
843 const QByteArray keys = metaEnum.valueToKeys( intValue );
844 const int intValueCheck = metaEnum.keysToValue( keys );
845 if ( intValue != intValueCheck )
856 setCustomFlagProperty( key, v );
880 const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
881 Q_ASSERT( metaEnum.isValid() );
882 if ( metaEnum.isValid() )
884 setCustomProperty( key, metaEnum.valueToKeys( value ) );
888 QgsDebugMsg( QStringLiteral(
"Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." ) );
898 void removeCustomProperty(
const QString &key );
929 static QString formatLayerName(
const QString &name );
938 virtual QString metadataUri()
const;
946 void exportNamedMetadata( QDomDocument &doc, QString &errorMsg )
const;
957 virtual QString saveDefaultMetadata(
bool &resultFlag
SIP_OUT );
973 QString saveNamedMetadata(
const QString &uri,
bool &resultFlag );
989 virtual QString loadNamedMetadata(
const QString &uri,
bool &resultFlag
SIP_OUT );
1000 virtual QString loadDefaultMetadata(
bool &resultFlag );
1010 bool loadNamedMetadataFromDatabase(
const QString &db,
const QString &uri, QString &qmd );
1019 bool importNamedMetadata( QDomDocument &document, QString &errorMessage );
1028 virtual QString styleURI()
const;
1039 virtual QString loadDefaultStyle(
bool &resultFlag
SIP_OUT );
1065 virtual bool loadNamedStyleFromDatabase(
const QString &db,
const QString &uri, QString &qml
SIP_OUT );
1076 virtual bool importNamedStyle( QDomDocument &doc, QString &errorMsg
SIP_OUT,
1097 virtual void exportSldStyle( QDomDocument &doc, QString &errorMsg )
const;
1109 virtual QString saveDefaultStyle(
bool &resultFlag
SIP_OUT, StyleCategories categories );
1138 virtual QString saveNamedStyle(
const QString &uri,
bool &resultFlag
SIP_OUT, StyleCategories categories = AllStyleCategories );
1148 virtual QString saveSldStyle(
const QString &uri,
bool &resultFlag )
const;
1158 virtual QString loadSldStyle(
const QString &uri,
bool &resultFlag );
1160 virtual bool readSld(
const QDomNode &node, QString &errorMessage )
1161 { Q_UNUSED( node ) errorMessage = QStringLiteral(
"Layer type %1 not supported" ).arg(
static_cast<int>( type() ) );
return false; }
1173 virtual bool readSymbology(
const QDomNode &node, QString &errorMessage,
1186 virtual bool readStyle(
const QDomNode &node, QString &errorMessage,
1199 virtual bool writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage,
const QgsReadWriteContext &context,
1200 StyleCategories categories = AllStyleCategories )
const = 0;
1214 virtual bool writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage,
const QgsReadWriteContext &context,
1215 StyleCategories categories = AllStyleCategories )
const;
1232 void setDataSource(
const QString &dataSource,
const QString &baseName,
const QString &provider,
bool loadDefaultStyleFlag =
false );
1247 void setDataSource(
const QString &dataSource,
const QString &baseName,
const QString &provider,
const QgsDataProvider::ProviderOptions &options,
bool loadDefaultStyleFlag =
false );
1263 void setDataSource(
const QString &dataSource,
const QString &baseName,
const QString &provider,
const QgsDataProvider::ProviderOptions &options, QgsDataProvider::ReadFlags flags );
1268 QString providerType()
const;
1271 QUndoStack *undoStack();
1277 QUndoStack *undoStackStyles();
1339 bool isInScaleRange(
double scale )
const;
1351 double minimumScale()
const;
1363 double maximumScale()
const;
1373 bool hasScaleBasedVisibility()
const;
1381 bool hasAutoRefreshEnabled()
const;
1390 int autoRefreshInterval()
const;
1403 void setAutoRefreshInterval(
int interval );
1411 void setAutoRefreshEnabled(
bool enabled );
1433 virtual QString htmlMetadata()
const;
1436 virtual QDateTime timestamp()
const;
1445 virtual QSet<QgsMapLayerDependency> dependencies()
const;
1469 QString originalXmlProperties()
const;
1478 void setOriginalXmlProperties(
const QString &originalXmlProperties );
1484 static QString generateId(
const QString &layerName );
1536 void setMinimumScale(
double scale );
1547 void setMaximumScale(
double scale );
1556 void setScaleBasedVisibility(
bool enabled );
1566 void triggerRepaint(
bool deferredUpdate =
false );
1574 void trigger3DUpdate();
1580 void emitStyleChanged();
1590 virtual bool setDependencies(
const QSet<QgsMapLayerDependency> &layers );
1597 void setRefreshOnNotifyEnabled(
bool enabled );
1616 SIP_PYOBJECT __repr__();
1618 QString
str = QStringLiteral(
"<QgsMapLayer: '%1' (%2)>" ).arg( sipCpp->name(), sipCpp->dataProvider() ? sipCpp->dataProvider()->name() : QStringLiteral(
"Invalid" ) );
1619 sipRes = PyUnicode_FromString(
str.toUtf8().constData() );
1639 void beforeResolveReferences(
QgsProject *project );
1642 void statusChanged(
const QString &status );
1660 void repaintRequested(
bool deferredUpdate =
false );
1663 void recalculateExtents()
const;
1669 void blendModeChanged( QPainter::CompositionMode blendMode );
1679 void opacityChanged(
double opacity );
1685 void rendererChanged();
1698 void styleChanged();
1704 void legendChanged();
1710 void renderer3DChanged();
1717 void request3DUpdate();
1723 void configChanged();
1728 void dependenciesChanged();
1736 void willBeDeleted();
1743 void autoRefreshIntervalChanged(
int interval );
1751 void metadataChanged();
1759 void flagsChanged();
1768 void dataSourceChanged();
1775 void styleLoaded( QgsMapLayer::StyleCategories categories );
1782 void isValidChanged();
1789 void customPropertyChanged(
const QString &key );
1795 void editingStarted();
1801 void editingStopped();
1807 void layerModified();
1811 void onNotified(
const QString &message );
1828 virtual void setDataSourcePrivate(
const QString &dataSource,
const QString &baseName,
const QString &provider,
const QgsDataProvider::ProviderOptions &options, QgsDataProvider::ReadFlags flags );
1843 void setValid(
bool valid );
1855 virtual bool writeXml( QDomNode &layer_node, QDomDocument &document,
const QgsReadWriteContext &context )
const;
1868 virtual QString encodedSource(
const QString &source,
const QgsReadWriteContext &context )
const;
1882 virtual QString decodedSource(
const QString &source,
const QString &dataProvider,
const QgsReadWriteContext &context )
const;
1889 void readCustomProperties(
const QDomNode &layerNode,
const QString &keyStartsWith = QString() );
1892 void writeCustomProperties( QDomNode &layerNode, QDomDocument &doc )
const;
1895 void readStyleManager(
const QDomNode &layerNode );
1897 void writeStyleManager( QDomNode &layerNode, QDomDocument &doc )
const;
1903 void writeCommonStyle( QDomElement &layerElement, QDomDocument &document,
1905 StyleCategories categories = AllStyleCategories )
const;
1911 void readCommonStyle(
const QDomElement &layerElement,
const QgsReadWriteContext &context,
1912 StyleCategories categories = AllStyleCategories );
1915 void setProviderType(
const QString &providerType );
1919 void connectNotify(
const char *signal )
override;
1935 void invalidateWgs84Extent();
1938 bool mValid =
false;
1978 bool mIsRefreshOnNofifyEnabled =
false;
1987 QgsMapLayer::ReadFlags mReadFlags = QgsMapLayer::ReadFlags();
1994 bool mShouldValidateCrs =
true;
2001 double mLayerOpacity = 1.0;
2008 int mBlockStyleChangedSignal = 0;
2020 QString crsHtmlMetadata()
const;
2033 QString generalHtmlMetadata()
const;
2040 bool &resultFlag, StyleCategories categories = AllStyleCategories );
2042 bool &resultFlag, StyleCategories categories = AllStyleCategories );
2043 bool loadNamedPropertyFromDatabase(
const QString &db,
const QString &uri, QString &xml,
QgsMapLayer::PropertyType type );
2052 virtual bool isReadOnly()
const;
2066 LayerFlags mFlags = LayerFlags( Identifiable | Removable | Searchable );
2069 QPainter::CompositionMode mBlendMode = QPainter::CompositionMode_SourceOver;
2077 double mMinScale = 0;
2079 double mMaxScale = 100000000;
2081 bool mScaleBasedVisibility =
false;
2086 std::unique_ptr< QgsMapLayerServerProperties > mServerProperties;
2089 QUndoStack *mUndoStack =
nullptr;
2091 QUndoStack *mUndoStackStyles =
nullptr;
2103 QTimer *mRefreshTimer =
nullptr;
2121 QString mOriginalXmlProperties;
2124 bool mRepaintRequestedFired =
false;
2127 QString mLegendPlaceholderImage;
2130 friend class TestQgsMapLayer;