24 #include "qgis_core.h" 32 #include <QStringList> 33 #include <QTranslator> 92 Q_PROPERTY( QStringList nonIdentifiableLayers READ nonIdentifiableLayers WRITE setNonIdentifiableLayers NOTIFY nonIdentifiableLayersChanged )
93 Q_PROPERTY( QString fileName READ fileName WRITE setFileName NOTIFY fileNameChanged )
94 Q_PROPERTY( QString homePath READ homePath WRITE setPresetHomePath NOTIFY homePathChanged )
97 Q_PROPERTY( QString ellipsoid READ ellipsoid WRITE setEllipsoid NOTIFY ellipsoidChanged )
98 Q_PROPERTY(
QgsMapThemeCollection *mapThemeCollection READ mapThemeCollection NOTIFY mapThemeCollectionChanged )
99 Q_PROPERTY(
QgsSnappingConfig snappingConfig READ snappingConfig WRITE setSnappingConfig NOTIFY snappingConfigChanged )
101 Q_PROPERTY( QList<
QgsVectorLayer *> avoidIntersectionsLayers READ avoidIntersectionsLayers WRITE setAvoidIntersectionsLayers NOTIFY avoidIntersectionsLayersChanged )
103 Q_PROPERTY( QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged )
104 Q_PROPERTY( QColor selectionColor READ selectionColor WRITE setSelectionColor NOTIFY selectionColorChanged )
128 void setTitle( const QString &title );
136 QString title() const;
141 bool isDirty() const;
149 void setFileName( const QString &name );
157 QString fileName() const;
183 QDateTime lastModified() const;
190 QString absoluteFilePath() const;
197 QString absolutePath() const;
203 QString baseName() const;
230 QString ellipsoid() const;
238 void setEllipsoid( const QString &ellipsoid );
276 FlagDontResolveLayers = 1 << 0,
277 FlagDontLoadLayouts = 1 << 1,
279 Q_DECLARE_FLAGS( ReadFlags,
ReadFlag )
287 bool read(
const QString &filename, QgsProject::ReadFlags flags =
nullptr );
297 bool read( QgsProject::ReadFlags flags =
nullptr );
308 bool readLayer(
const QDomNode &layerNode );
318 bool write(
const QString &filename );
336 bool writeEntry(
const QString &scope,
const QString &key,
bool value )
SIP_PYNAME( writeEntryBool );
347 bool writeEntry(
const QString &scope,
const QString &key,
double value )
SIP_PYNAME( writeEntryDouble );
357 bool writeEntry(
const QString &scope,
const QString &key,
int value );
367 bool writeEntry(
const QString &scope,
const QString &key,
const QString &value );
377 bool writeEntry(
const QString &scope,
const QString &key,
const QStringList &value );
385 QStringList readListEntry(
const QString &scope,
const QString &key,
const QStringList &def = QStringList(),
bool *ok =
nullptr )
const;
387 QString readEntry(
const QString &scope,
const QString &key,
const QString &def = QString(),
bool *ok =
nullptr )
const;
388 int readNumEntry(
const QString &scope,
const QString &key,
int def = 0,
bool *ok =
nullptr )
const;
389 double readDoubleEntry(
const QString &scope,
const QString &key,
double def = 0,
bool *ok =
nullptr )
const;
390 bool readBoolEntry(
const QString &scope,
const QString &key,
bool def =
false,
bool *ok =
nullptr )
const;
394 bool removeEntry(
const QString &scope,
const QString &key );
402 QStringList entryList(
const QString &scope,
const QString &key )
const;
409 QStringList subkeyList(
const QString &scope,
const QString &key )
const;
417 void dumpProperties()
const;
431 QString writePath(
const QString &filename )
const;
434 QString readPath(
const QString &filename )
const;
437 QString error()
const;
446 QString layerIsEmbedded(
const QString &
id )
const;
456 bool createEmbeddedLayer(
const QString &layerId,
const QString &projectFilePath, QList<QDomNode> &brokenNodes,
457 bool saveFlag =
true, QgsProject::ReadFlags flags =
nullptr )
SIP_SKIP;
466 QgsLayerTreeGroup *createEmbeddedGroup( const QString &groupName, const QString &projectFilePath, const QStringList &invisibleLayers,
QgsProject::ReadFlags flags =
nullptr );
469 void setTopologicalEditing(
bool enabled );
472 bool topologicalEditing() const;
488 void setDistanceUnits(
QgsUnitTypes::DistanceUnit unit );
517 QString homePath() const;
531 QString presetHomePath() const;
600 Q_DECL_DEPRECATED
void setNonIdentifiableLayers(
const QList<QgsMapLayer *> &layers );
606 Q_DECL_DEPRECATED
void setNonIdentifiableLayers(
const QStringList &layerIds );
612 Q_DECL_DEPRECATED QStringList nonIdentifiableLayers()
const;
621 bool autoTransaction()
const;
632 void setAutoTransaction(
bool autoTransaction );
651 QgsTransactionGroup *transactionGroup(
const QString &providerKey,
const QString &connString );
658 bool evaluateDefaultValues()
const;
665 void setEvaluateDefaultValues(
bool evaluateDefaultValues );
682 QList<QgsVectorLayer *> avoidIntersectionsLayers()
const;
689 void setAvoidIntersectionsLayers(
const QList<QgsVectorLayer *> &layers );
696 QVariantMap customVariables()
const;
702 void setCustomVariables(
const QVariantMap &customVariables );
736 int validCount()
const;
745 Q_INVOKABLE
QgsMapLayer *mapLayer(
const QString &layerId )
const;
767 return qobject_cast<T>( mapLayer( layerId ) );
778 QList<QgsMapLayer *> mapLayersByName(
const QString &layerName )
const;
789 QList<QgsMapLayer *> mapLayersByShortName(
const QString &shortName )
const;
800 QMap<QString, QgsMapLayer *> mapLayers(
const bool validOnly =
false )
const;
805 bool isZipped()
const;
820 template <
typename T>
823 return mLayerStore->layers<T>();
837 template <
typename T>
841 const auto constMapLayers { mLayerStore->layers<T>() };
842 for (
const auto l : constMapLayers )
844 if ( ! l->shortName().isEmpty() )
846 if ( l->shortName() == shortName )
849 else if ( l->name() == shortName )
884 QList<QgsMapLayer *> addMapLayers(
const QList<QgsMapLayer *> &mapLayers
SIP_TRANSFER,
885 bool addToLegend =
true,
916 bool addToLegend =
true,
933 void removeMapLayers(
const QStringList &layerIds );
950 void removeMapLayers(
const QList<QgsMapLayer *> &layers );
965 void removeMapLayer(
const QString &layerId );
1001 void removeAllMapLayers();
1008 void reloadAllLayers();
1027 void setTrustLayerMetadata(
bool trust );
1063 QString attachedFile(
const QString &fileName )
const SIP_SKIP;
1100 Q_DECL_DEPRECATED QSet<QgsMapLayer *> requiredLayers()
const;
1110 Q_DECL_DEPRECATED
void setRequiredLayers(
const QSet<QgsMapLayer *> &layers );
1126 void setBackgroundColor(
const QColor &color );
1134 QColor backgroundColor()
const;
1142 void setSelectionColor(
const QColor &color );
1150 QColor selectionColor()
const;
1163 void setMapScales(
const QVector<double> &scales );
1176 QVector<double> mapScales()
const;
1186 void setUseProjectScales(
bool enabled );
1196 bool useProjectScales()
const;
1202 void generateTsFile(
const QString &locale );
1214 QString
translate(
const QString &context,
const QString &sourceText,
const char *disambiguation =
nullptr,
int n = -1 )
const override;
1228 SIP_PYOBJECT __repr__();
1230 QString str = QStringLiteral(
"<QgsProject: '%1'%2>" ).arg( sipCpp->fileName(),
1232 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
1250 void readProject(
const QDomDocument & );
1260 void writeProject( QDomDocument & );
1270 void readMapLayer(
QgsMapLayer *mapLayer,
const QDomElement &layerNode );
1280 void writeMapLayer(
QgsMapLayer *mapLayer, QDomElement &layerElem, QDomDocument &doc );
1285 void projectSaved();
1290 void oldProjectVersionWarning(
const QString & );
1297 void layerLoaded(
int i,
int n );
1300 void loadingLayer(
const QString &layerName );
1308 void loadingLayerMessageReceived(
const QString &layerName,
const QList<QgsReadWriteContext::ReadWriteMessage> &messages );
1314 Q_DECL_DEPRECATED
void nonIdentifiableLayersChanged( QStringList nonIdentifiableLayers );
1317 void fileNameChanged();
1325 void homePathChanged();
1336 void customVariablesChanged();
1352 void ellipsoidChanged(
const QString &ellipsoid );
1361 void transformContextChanged();
1367 void missingDatumTransforms(
const QStringList &missingTransforms );
1375 void transactionGroupsChanged();
1382 void topologicalEditingChanged();
1389 void avoidIntersectionsLayersChanged();
1402 void mapThemeCollectionChanged();
1408 void labelingEngineSettingsChanged();
1416 void metadataChanged();
1424 void projectColorsChanged();
1432 void backgroundColorChanged();
1440 void selectionColorChanged();
1453 void layersWillBeRemoved(
const QStringList &layerIds );
1462 void layersWillBeRemoved(
const QList<QgsMapLayer *> &layers );
1473 void layerWillBeRemoved(
const QString &layerId );
1492 void layersRemoved(
const QStringList &layerIds );
1502 void layerRemoved(
const QString &layerId );
1524 void layersAdded(
const QList<QgsMapLayer *> &layers );
1542 void legendLayersAdded(
const QList<QgsMapLayer *> &layers );
1551 void isDirtyChanged(
bool dirty );
1576 void mapScalesChanged();
1596 void setDirty(
bool b =
true );
1606 void setPresetHomePath(
const QString &path );
1628 void onMapLayersAdded(
const QList<QgsMapLayer *> &layers );
1629 void onMapLayersRemoved(
const QList<QgsMapLayer *> &layers );
1630 void cleanTransactionGroups(
bool force =
false );
1654 bool _getMapLayers(
const QDomDocument &doc, QList<QDomNode> &brokenNodes, QgsProject::ReadFlags flags =
nullptr );
1660 void setError(
const QString &errorMessage )
SIP_SKIP;
1675 bool addLayer(
const QDomElement &layerElem, QList<QDomNode> &brokenNodes,
QgsReadWriteContext &context, QgsProject::ReadFlags flags =
nullptr )
SIP_SKIP;
1682 void initializeEmbeddedSubtree(
const QString &projectFilePath,
QgsLayerTreeGroup *group, QgsProject::ReadFlags flags =
nullptr )
SIP_SKIP;
1691 bool readProjectFile(
const QString &filename, QgsProject::ReadFlags flags =
nullptr );
1694 bool writeProjectFile(
const QString &filename );
1697 bool unzip(
const QString &filename, QgsProject::ReadFlags flags =
nullptr );
1700 bool zip(
const QString &filename );
1703 bool saveAuxiliaryStorage(
const QString &filename = QString() );
1705 std::unique_ptr< QgsMapLayerStore > mLayerStore;
1707 QString mErrorMessage;
1716 QHash< QString, QPair< QString, bool> > mEmbeddedLayers;
1722 std::unique_ptr<QgsAnnotationManager> mAnnotationManager;
1723 std::unique_ptr<QgsLayoutManager> mLayoutManager;
1734 std::unique_ptr<QgsMapThemeCollection> mMapThemeCollection;
1736 std::unique_ptr<QgsLabelingEngineSettings> mLabelingEngineSettings;
1738 QVariantMap mCustomVariables;
1740 std::unique_ptr<QgsProjectArchive> mArchive;
1742 std::unique_ptr<QgsAuxiliaryStorage> mAuxiliaryStorage;
1751 mutable QString mCachedHomePath;
1753 QColor mBackgroundColor;
1754 QColor mSelectionColor;
1757 bool mAutoTransaction =
false;
1758 bool mEvaluateDefaultValues =
false;
1760 bool mDirty =
false;
1761 int mDirtyBlockCount = 0;
1762 bool mTrustLayerMetadata =
false;
1768 std::unique_ptr< QTranslator > mTranslator;
1770 bool mIsBeingDeleted =
false;
1772 mutable std::unique_ptr< QgsExpressionContextScope > mProjectScope;
1783 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsProject::ReadFlags )
1816 : mProject( project )
1818 mProject->mDirtyBlockCount++;
1822 QgsProjectDirtyBlocker(
const QgsProjectDirtyBlocker &other ) =
delete;
1825 QgsProjectDirtyBlocker &operator=(
const QgsProjectDirtyBlocker &other ) =
delete;
1829 mProject->mDirtyBlockCount--;
1836 QgsProjectDirtyBlocker(
const QgsProjectDirtyBlocker &other );
1854 GetNamedProjectColor(
const QgsProject *project );
1860 GetNamedProjectColor(
const QHash< QString, QColor > &colors );
1867 QHash< QString, QColor > mColors;
Class for parsing and evaluation of expressions (formerly called "search strings").
Layer tree group node serves as a container for layers and further groups.
The class is used as a container of context for various read/write operations on other objects...
Base class for all map layer types.
Manages storage of a set of QgsAnnotation annotation objects.
Helper functions for various unit types.
Class providing some utility methods to manage auxiliary storage.
Manages storage of a set of bookmarks.
const QgsCoordinateReferenceSystem & crs
An interface for classes which can visit style entity (e.g.
QMap< QString, QString > QgsStringMap
virtual QgsExpressionContext createExpressionContext() const =0
This method needs to be reimplemented in all classes which implement this interface and return an exp...
T mapLayer(const QString &layerId) const
Retrieve a pointer to a registered layer by layerId converted to type T.
bool trustLayerMetadata() const
Returns true if the trust option is activated, false otherwise.
ReadFlag
Flags which control project read behavior.
Namespace with helper functions for layer tree operations.
CORE_EXPORT bool unzip(const QString &zip, const QString &dir, QStringList &files)
Unzip a zip file in an output directory.
CORE_EXPORT QgsProjectVersion getVersion(QDomDocument const &doc)
Returns the version string found in the given DOM document.
A class to describe the version of a project.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
This is the class is providing tolerance value in map unit values.
Listens to the updates in map layer registry and does changes in layer tree.
QList< QPair< QColor, QString > > QgsNamedColorList
List of colors paired with a friendly display name identifying the color.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts, annotations, canvases, etc.
Single scope for storing variables and functions for use within a QgsExpressionContext.
An expression node for expression functions.
Contains information about the context in which a coordinate transform is executed.
const QgsProject * project(const QString &path)
If the project is not cached yet, then the project is read thanks to the path.
Wherever an object of this class is available, the derived translate function can be called from...
Manages storage of a set of layouts.
Used for the collecting of strings from projects for translation and creation of ts files...
Abstract interface for generating an expression context.
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.
A registry / canonical manager of data providers.
Project property key node.
Cache for server configuration.
QVector< T > layers() const
Returns a list of registered map layers with a specified layer type.
virtual QgsExpressionContextScope * createExpressionContextScope() const =0
This method needs to be reimplemented in all classes which implement this interface and return an exp...
~QgsProjectDirtyBlocker()
Abstract interface for generating an expression context scope.
This class manages a set of relations between layers.
Stores global configuration for labeling engine.
static QgsProject * instance()
Returns the QgsProject singleton instance.
This class represents a coordinate reference system (CRS).
This is a container for attribute editors, used to group them visually in the attribute form if it is...
Abstract interface for project storage - to be implemented by various backends and registered in QgsP...
QgsProjectDirtyBlocker(QgsProject *project)
Constructor for QgsProjectDirtyBlocker.
Temporarily blocks QgsProject "dirtying" for the lifetime of the object.
A storage object for map layers, in which the layers are owned by the store and have their lifetime b...
Container class that allows storage of map themes consisting of visible map layers and layer styles...
This is a container for configuration of the snapping of the project.
Resolves relative paths into absolute paths and vice versa.
Represents a vector layer which manages a vector based data sets.
CORE_EXPORT bool zip(const QString &zip, const QStringList &files)
Zip the list of files in the zip file.
Expression function for use within a QgsExpressionContextScope.
Interface for classes that handle missing layer files when reading project file.
QVector< T > mapLayersByShortName(const QString &shortName) const
Retrieves a list of matching registered layers by layer shortName with a specified layer type...