24 #include "qgis_core.h"
32 #include <QStringList>
33 #include <QTranslator>
50 #include "qgssettings.h"
81 class QgsAttributeEditorContainer;
101 Q_PROPERTY( QStringList nonIdentifiableLayers READ nonIdentifiableLayers WRITE setNonIdentifiableLayers NOTIFY nonIdentifiableLayersChanged )
102 Q_PROPERTY( QString fileName READ fileName WRITE setFileName NOTIFY fileNameChanged )
103 Q_PROPERTY( QString homePath READ homePath WRITE setPresetHomePath NOTIFY homePathChanged )
106 Q_PROPERTY( QString ellipsoid READ ellipsoid WRITE setEllipsoid NOTIFY ellipsoidChanged )
107 Q_PROPERTY(
QgsMapThemeCollection *mapThemeCollection READ mapThemeCollection NOTIFY mapThemeCollectionChanged )
108 Q_PROPERTY(
QgsSnappingConfig snappingConfig READ snappingConfig WRITE setSnappingConfig NOTIFY snappingConfigChanged )
110 Q_PROPERTY(
AvoidIntersectionsMode avoidIntersectionsMode READ avoidIntersectionsMode WRITE setAvoidIntersectionsMode NOTIFY avoidIntersectionsModeChanged )
111 Q_PROPERTY( QList<QgsVectorLayer *> avoidIntersectionsLayers READ avoidIntersectionsLayers WRITE setAvoidIntersectionsLayers NOTIFY avoidIntersectionsLayersChanged )
112 Q_PROPERTY(
QgsProjectMetadata metadata READ metadata WRITE setMetadata NOTIFY metadataChanged )
113 Q_PROPERTY( QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged )
114 Q_PROPERTY( QColor selectionColor READ selectionColor WRITE setSelectionColor NOTIFY selectionColorChanged )
115 Q_PROPERTY(
bool topologicalEditing READ topologicalEditing WRITE setTopologicalEditing NOTIFY topologicalEditingChanged )
125 FlagDontResolveLayers = 1 << 0,
126 FlagDontLoadLayouts = 1 << 1,
127 FlagTrustLayerMetadata = 1 << 2,
128 FlagDontStoreOriginalStyles = 1 << 3,
130 Q_DECLARE_FLAGS( ReadFlags, ReadFlag )
150 AvoidIntersectionsCurrentLayer,
151 AvoidIntersectionsLayers,
153 Q_ENUM( AvoidIntersectionsMode )
167 WMSOnlineResource = 2,
181 static void setInstance(
QgsProject *project ) ;
202 void setTitle(
const QString &title );
210 QString title()
const;
219 QString saveUser()
const;
228 QString saveUserFullName()
const;
235 QDateTime lastSaveDateTime()
const;
247 bool isDirty()
const;
255 void setFileName(
const QString &name );
263 QString fileName()
const;
276 void setOriginalPath(
const QString &path );
289 QString originalPath()
const;
315 QDateTime lastModified() const;
322 QString absoluteFilePath() const;
329 QString absolutePath() const;
335 QString baseName() const;
362 QString ellipsoid() const;
370 void setEllipsoid( const QString &ellipsoid );
429 bool readLayer( const QDomNode &layerNode );
439 bool write( const QString &filename );
459 bool writeEntry( const QString &scope, const QString &key,
bool value )
SIP_PYNAME( writeEntryBool );
472 bool writeEntry( const QString &scope, const QString &key,
double value )
SIP_PYNAME( writeEntryDouble );
484 bool writeEntry( const QString &scope, const QString &key,
int value );
496 bool writeEntry( const QString &scope, const QString &key, const QString &value );
508 bool writeEntry( const QString &scope, const QString &key, const QStringList &value );
520 QStringList readListEntry( const QString &scope, const QString &key, const QStringList &def = QStringList(),
bool *ok
SIP_OUT =
nullptr ) const;
532 QString readEntry( const QString &scope, const QString &key, const QString &def = QString(),
bool *ok
SIP_OUT =
nullptr ) const;
544 int readNumEntry( const QString &scope, const QString &key,
int def = 0,
bool *ok
SIP_OUT =
nullptr ) const;
556 double readDoubleEntry( const QString &scope, const QString &key,
double def = 0,
bool *ok
SIP_OUT =
nullptr ) const;
568 bool readBoolEntry( const QString &scope, const QString &key,
bool def = false,
bool *ok
SIP_OUT =
nullptr ) const;
573 bool removeEntry( const QString &scope, const QString &key );
583 QStringList entryList( const QString &scope, const QString &key ) const;
593 QStringList subkeyList( const QString &scope, const QString &key ) const;
601 void dumpProperties() const;
615 QString writePath( const QString &filename ) const;
620 QString readPath( const QString &filename ) const;
623 QString error() const;
636 QString layerIsEmbedded( const QString &
id ) const;
646 bool createEmbeddedLayer( const QString &layerId, const QString &projectFilePath, QList<QDomNode> &brokenNodes,
656 QgsLayerTreeGroup *createEmbeddedGroup( const QString &groupName, const QString &projectFilePath, const QStringList &invisibleLayers,
QgsProject::ReadFlags flags =
QgsProject::ReadFlags() );
659 void setTopologicalEditing(
bool enabled );
662 bool topologicalEditing() const;
678 void setDistanceUnits(
QgsUnitTypes::DistanceUnit unit );
707 QString homePath() const;
721 QString presetHomePath() const;
839 Q_DECL_DEPRECATED
void setNonIdentifiableLayers( const QList<
QgsMapLayer *> &layers );
845 Q_DECL_DEPRECATED
void setNonIdentifiableLayers( const QStringList &layerIds );
851 Q_DECL_DEPRECATED QStringList nonIdentifiableLayers() const;
860 bool autoTransaction() const;
871 void setAutoTransaction(
bool autoTransaction );
890 QgsTransactionGroup *transactionGroup( const QString &providerKey, const QString &connString );
897 bool evaluateDefaultValues() const;
904 void setEvaluateDefaultValues(
bool evaluateDefaultValues );
929 void setAvoidIntersectionsLayers( const QList<
QgsVectorLayer *> &layers );
950 QVariantMap customVariables()
const;
956 void setCustomVariables(
const QVariantMap &customVariables );
990 int validCount()
const;
999 Q_INVOKABLE
QgsMapLayer *mapLayer(
const QString &layerId )
const;
1021 return qobject_cast<T>( mapLayer( layerId ) );
1032 QList<QgsMapLayer *> mapLayersByName(
const QString &layerName )
const;
1043 QList<QgsMapLayer *> mapLayersByShortName(
const QString &shortName )
const;
1054 QMap<QString, QgsMapLayer *> mapLayers(
const bool validOnly =
false )
const;
1059 bool isZipped()
const;
1074 template <
typename T>
1077 return mLayerStore->layers<T>();
1091 template <
typename T>
1095 const auto constMapLayers { mLayerStore->layers<T>() };
1096 for (
const auto l : constMapLayers )
1098 if ( ! l->shortName().isEmpty() )
1100 if ( l->shortName() == shortName )
1103 else if ( l->name() == shortName )
1138 QList<QgsMapLayer *> addMapLayers(
const QList<QgsMapLayer *> &mapLayers
SIP_TRANSFER,
1139 bool addToLegend =
true,
1170 bool addToLegend =
true,
1187 void removeMapLayers(
const QStringList &layerIds );
1204 void removeMapLayers(
const QList<QgsMapLayer *> &layers );
1219 void removeMapLayer(
const QString &layerId );
1268 void removeAllMapLayers();
1275 void reloadAllLayers();
1294 void setTrustLayerMetadata(
bool trust );
1330 QString attachedFile( const QString &fileName ) const
SIP_SKIP;
1367 Q_DECL_DEPRECATED QSet<
QgsMapLayer *> requiredLayers() const;
1377 Q_DECL_DEPRECATED
void setRequiredLayers( const QSet<
QgsMapLayer *> &layers );
1393 void setBackgroundColor( const QColor &color );
1401 QColor backgroundColor() const;
1409 void setSelectionColor( const QColor &color );
1417 QColor selectionColor() const;
1430 Q_DECL_DEPRECATED
void setMapScales( const QVector<
double> &scales )
SIP_DEPRECATED;
1443 Q_DECL_DEPRECATED QVector<
double> mapScales() const
SIP_DEPRECATED;
1453 Q_DECL_DEPRECATED
void setUseProjectScales(
bool enabled )
SIP_DEPRECATED;
1469 void generateTsFile( const QString &locale );
1481 QString translate( const QString &context, const QString &sourceText, const
char *disambiguation =
nullptr,
int n = -1 ) const override;
1495 SIP_PYOBJECT __repr__();
1497 QString
str = QStringLiteral(
"<QgsProject: '%1'%2>" ).arg( sipCpp->fileName(),
1499 sipRes = PyUnicode_FromString(
str.toUtf8().constData() );
1879 void setDirty(
bool b = true );
1889 void setPresetHomePath( const QString &path );
1900 void registerTranslatableContainers(
QgsTranslationContext *translationContext, QgsAttributeEditorContainer *parent, const QString &layerId );
1927 void onMapLayersAdded( const QList<
QgsMapLayer *> &layers );
1928 void onMapLayersRemoved( const QList<
QgsMapLayer *> &layers );
1929 void cleanTransactionGroups(
bool force = false );
1944 bool _getMapLayers( const QDomDocument &doc, QList<QDomNode> &brokenNodes,
QgsProject::ReadFlags flags =
QgsProject::ReadFlags() );
1950 void setError( const QString &errorMessage )
SIP_SKIP;
1981 bool readProjectFile( const QString &filename,
QgsProject::ReadFlags flags =
QgsProject::ReadFlags() );
1984 bool writeProjectFile( const QString &filename );
1990 bool zip( const QString &filename );
1993 bool saveAuxiliaryStorage( const QString &filename = QString() );
2000 QString mErrorMessage;
2009 QHash< QString, QPair< QString,
bool> > mEmbeddedLayers;
2040 QVariantMap mCustomVariables;
2048 QString mOriginalPath;
2051 QString mSaveUserFull;
2052 QDateTime mSaveDateTime;
2060 mutable QString mCachedHomePath;
2062 QColor mBackgroundColor;
2063 QColor mSelectionColor;
2066 bool mAutoTransaction = false;
2067 bool mEvaluateDefaultValues = false;
2069 bool mDirty = false;
2070 int mDirtyBlockCount = 0;
2071 bool mTrustLayerMetadata = false;
2081 bool mIsBeingDeleted = false;
2083 QgsSettings mSettings;
2087 int mBlockSnappingUpdates = 0;
2097 friend class TestQgsProject;
2135 : mProject( project )
2137 mProject->mDirtyBlockCount++;
2148 mProject->mDirtyBlockCount--;
2173 GetNamedProjectColor(
const QgsProject *project );
2179 GetNamedProjectColor(
const QHash< QString, QColor > &colors );
2186 QHash< QString, QColor > mColors;
Represents a map layer containing a set of georeferenced annotations, e.g.
Manages storage of a set of QgsAnnotation annotation objects.
Class providing some utility methods to manage auxiliary storage.
Manages storage of a set of bookmarks.
This class represents a coordinate reference system (CRS).
Contains information about the context in which a coordinate transform is executed.
Abstract interface for generating an expression context.
Abstract interface for generating an expression context scope.
Single scope for storing variables and functions for use within a QgsExpressionContext.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
An expression node for expression functions.
Class for parsing and evaluation of expressions (formerly called "search strings").
Stores global configuration for labeling engine.
Layer tree group node serves as a container for layers and further groups.
Listens to the updates in map layer registry and does changes in layer tree.
Namespace with helper functions for layer tree operations.
Manages storage of a set of layouts.
A storage object for map layers, in which the layers are owned by the store and have their lifetime b...
Base class for all map layer types.
Container class that allows storage of map themes consisting of visible map layers and layer styles.
Resolves relative paths into absolute paths and vice versa.
Class allowing to manage the zip/unzip actions on project file.
Interface for classes that handle missing layer files when reading project file.
Temporarily blocks QgsProject "dirtying" for the lifetime of the object.
QgsProjectDirtyBlocker & operator=(const QgsProjectDirtyBlocker &other)=delete
QgsProjectDirtyBlocker cannot be copied.
QgsProjectDirtyBlocker(QgsProject *project)
Constructor for QgsProjectDirtyBlocker.
~QgsProjectDirtyBlocker()
QgsProjectDirtyBlocker(const QgsProjectDirtyBlocker &other)=delete
QgsProjectDirtyBlocker cannot be copied.
Contains settings and properties relating to how a QgsProject should display values such as map coord...
Project property key node.
Abstract interface for project storage - to be implemented by various backends and registered in QgsP...
Contains temporal settings and properties for the project, this may be used when animating maps or sh...
Wherever an object of this class is available, the derived translate function can be called from.
A class to describe the version of a project.
Contains settings and properties relating to how a QgsProject should be displayed inside map canvas,...
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
void layersRemoved(const QStringList &layerIds)
Emitted after one or more layers were removed from the registry.
void mapThemeCollectionChanged()
Emitted when the map theme collection changes.
static QgsProject * instance()
Returns the QgsProject singleton instance.
Q_DECL_DEPRECATED void mapScalesChanged()
Emitted when the list of custom project map scales changes.
void fileNameChanged()
Emitted when the file name of the project changes.
void writeMapLayer(QgsMapLayer *mapLayer, QDomElement &layerElem, QDomDocument &doc)
Emitted when a layer is being saved.
Q_DECL_DEPRECATED void nonIdentifiableLayersChanged(QStringList nonIdentifiableLayers)
Emitted when the list of layer which are excluded from map identification changes.
void layersWillBeRemoved(const QStringList &layerIds)
Emitted when one or more layers are about to be removed from the registry.
void snappingConfigChanged(const QgsSnappingConfig &config)
Emitted whenever the configuration for snapping has changed.
void layerWasAdded(QgsMapLayer *layer)
Emitted when a layer was added to the registry.
void crsChanged()
Emitted when the CRS of the project has changed.
void avoidIntersectionsLayersChanged()
Emitted whenever avoidIntersectionsLayers has changed.
void layerWillBeRemoved(const QString &layerId)
Emitted when a layer is about to be removed from the registry.
void readMapLayer(QgsMapLayer *mapLayer, const QDomElement &layerNode)
Emitted after the basic initialization of a layer from the project file is done.
QgsMapThemeCollection * mapThemeCollection()
Returns pointer to the project's map theme collection.
void cleared()
Emitted when the project is cleared (and additionally when an open project is cleared just before a n...
DataDefinedServerProperty
Data defined properties.
void metadataChanged()
Emitted when the project's metadata is changed.
QVector< T > layers() const
Returns a list of registered map layers with a specified layer type.
AvoidIntersectionsMode
Flags which control how intersections of pre-existing feature are handled when digitizing new feature...
void ellipsoidChanged(const QString &ellipsoid)
Emitted when the project ellipsoid is changed.
void collectAttachedFiles(QgsStringMap &files)
Emitted whenever the project is saved to a qgz file.
void projectColorsChanged()
Emitted whenever the project's color scheme has been changed.
void labelingEngineSettingsChanged()
Emitted when global configuration of the labeling engine changes.
void customVariablesChanged()
Emitted whenever the expression variables stored in the project have been changed.
void readProject(const QDomDocument &)
Emitted when a project is being read.
T mapLayer(const QString &layerId) const
Retrieve a pointer to a registered layer by layerId converted to type T.
void missingDatumTransforms(const QStringList &missingTransforms)
Emitted when datum transforms stored in the project are not available locally.
void readProjectWithContext(const QDomDocument &, QgsReadWriteContext &context)
Emitted when a project is being read.
void layerWillBeRemoved(QgsMapLayer *layer)
Emitted when a layer is about to be removed from the registry.
void transactionGroupsChanged()
Emitted whenever a new transaction group has been created or a transaction group has been removed.
void loadingLayerMessageReceived(const QString &layerName, const QList< QgsReadWriteContext::ReadWriteMessage > &messages)
Emitted when loading layers has produced some messages.
FileFormat
Flags which control project read behavior.
void writeProject(QDomDocument &)
Emitted when the project is being written.
void projectSaved()
Emitted when the project file has been written and closed.
void layersWillBeRemoved(const QList< QgsMapLayer * > &layers)
Emitted when one or more layers are about to be removed from the registry.
bool trustLayerMetadata() const
Returns true if the trust option is activated, false otherwise.
void layerLoaded(int i, int n)
Emitted when a layer from a projects was read.
void selectionColorChanged()
Emitted whenever the project's selection color has been changed.
void removeAll()
Emitted when all layers are removed, before layersWillBeRemoved() and layerWillBeRemoved() signals ar...
QVector< T > mapLayersByShortName(const QString &shortName) const
Retrieves a list of matching registered layers by layer shortName with a specified layer type,...
void backgroundColorChanged()
Emitted whenever the project's canvas background color has been changed.
ReadFlag
Flags which control project read behavior.
void oldProjectVersionWarning(const QString &)
Emitted when an old project file is read.
void transformContextChanged()
Emitted when the project transformContext() is changed.
void legendLayersAdded(const QList< QgsMapLayer * > &layers)
Emitted, when a layer was added to the registry and the legend.
void layerRemoved(const QString &layerId)
Emitted after a layer was removed from the registry.
void homePathChanged()
Emitted when the home path of the project changes.
void dirtySet()
Emitted when setDirty(true) is called.
void layersAdded(const QList< QgsMapLayer * > &layers)
Emitted when one or more layers were added to the registry.
void isDirtyChanged(bool dirty)
Emitted when the project dirty status changes.
void topologicalEditingChanged()
Emitted when the topological editing flag has changed.
void avoidIntersectionsModeChanged()
Emitted whenever the avoid intersections mode has changed.
void loadingLayer(const QString &layerName)
Emitted when a layer is loaded.
A grouped map of multiple QgsProperty objects, each referenced by a integer key value.
A registry / canonical manager of data providers.
The class is used as a container of context for various read/write operations on other objects.
This class manages a set of relations between layers.
Expression function for use within a QgsExpressionContextScope.
The QgsServer class provides OGC web services.
This is a container for configuration of the snapping of the project.
An interface for classes which can visit style entity (e.g.
This is the class is providing tolerance value in map unit values.
Used for the collecting of strings from projects for translation and creation of ts files.
Helper functions for various unit types.
Represents a vector layer which manages a vector based data sets.
QList< QPair< QColor, QString > > QgsNamedColorList
List of colors paired with a friendly display name identifying the color.
CORE_EXPORT bool unzip(const QString &zip, const QString &dir, QStringList &files)
Unzip a zip file in an output directory.
CORE_EXPORT bool zip(const QString &zip, const QStringList &files)
Zip the list of files in the zip file.
std::unique_ptr< GEOSGeometry, GeosDeleter > unique_ptr
Scoped GEOS pointer.
QMap< QString, QString > QgsStringMap
#define SIP_MONKEYPATCH_SCOPEENUM
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsField::ConfigurationFlags) CORE_EXPORT QDataStream &operator<<(QDataStream &out
Writes the field to stream out. QGIS version compatibility is not guaranteed.
CORE_EXPORT QgsProjectVersion getVersion(QDomDocument const &doc)
Returns the version string found in the given DOM document.
QMap< int, QgsPropertyDefinition > QgsPropertiesDefinition
Definition of available properties.
const QgsCoordinateReferenceSystem & crs