24 #include "qgis_core.h"
34 #include <QStringList>
35 #include <QTranslator>
106 Q_PROPERTY( QStringList nonIdentifiableLayers READ nonIdentifiableLayers WRITE setNonIdentifiableLayers NOTIFY nonIdentifiableLayersChanged )
107 Q_PROPERTY( QString fileName READ fileName WRITE setFileName NOTIFY fileNameChanged )
108 Q_PROPERTY( QString homePath READ homePath WRITE setPresetHomePath NOTIFY homePathChanged )
111 Q_PROPERTY( QString ellipsoid READ ellipsoid WRITE setEllipsoid NOTIFY ellipsoidChanged )
113 Q_PROPERTY(
QgsSnappingConfig snappingConfig READ snappingConfig WRITE setSnappingConfig NOTIFY snappingConfigChanged )
115 Q_PROPERTY(
Qgis::AvoidIntersectionsMode avoidIntersectionsMode READ avoidIntersectionsMode WRITE setAvoidIntersectionsMode NOTIFY avoidIntersectionsModeChanged )
116 Q_PROPERTY( QList<
QgsVectorLayer *> avoidIntersectionsLayers READ avoidIntersectionsLayers WRITE setAvoidIntersectionsLayers NOTIFY avoidIntersectionsLayersChanged )
118 Q_PROPERTY( QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged )
119 Q_PROPERTY( QColor selectionColor READ selectionColor WRITE setSelectionColor NOTIFY selectionColorChanged )
120 Q_PROPERTY(
bool topologicalEditing READ topologicalEditing WRITE setTopologicalEditing NOTIFY topologicalEditingChanged )
136 WMSOnlineResource = 2,
150 static void setInstance(
QgsProject *project ) ;
173 void setTitle(
const QString &title );
181 QString title()
const;
189 Qgis::ProjectCapabilities
capabilities()
const {
return mCapabilities; }
199 Qgis::ProjectFlags
flags()
const {
return mFlags; }
209 void setFlags( Qgis::ProjectFlags flags );
228 QString saveUser()
const;
237 QString saveUserFullName()
const;
244 QDateTime lastSaveDateTime()
const;
256 bool isDirty()
const;
264 void setFileName(
const QString &name );
272 QString fileName()
const;
285 void setOriginalPath(
const QString &path );
298 QString originalPath()
const;
324 QDateTime lastModified() const;
331 QString absoluteFilePath() const;
338 QString absolutePath() const;
344 QString baseName() const;
352 Qgis::FilePathType filePathStorage() const;
360 void setFilePathStorage(
Qgis::FilePathType type );
387 QString ellipsoid() const;
395 void setEllipsoid( const QString &ellipsoid );
433 bool read( const QString &filename,
Qgis::ProjectReadFlags flags =
Qgis::ProjectReadFlags() );
443 bool read(
Qgis::ProjectReadFlags flags =
Qgis::ProjectReadFlags() );
454 bool readLayer( const QDomNode &layerNode );
464 bool write( const QString &filename );
484 bool writeEntry( const QString &scope, const QString &key,
bool value )
SIP_PYNAME( writeEntryBool );
497 bool writeEntry( const QString &scope, const QString &key,
double value )
SIP_PYNAME( writeEntryDouble );
509 bool writeEntry( const QString &scope, const QString &key,
int value );
521 bool writeEntry( const QString &scope, const QString &key, const QString &value );
533 bool writeEntry( const QString &scope, const QString &key, const QStringList &value );
545 QStringList readListEntry( const QString &scope, const QString &key, const QStringList &def = QStringList(),
bool *ok
SIP_OUT =
nullptr ) const;
557 QString readEntry( const QString &scope, const QString &key, const QString &def = QString(),
bool *ok
SIP_OUT =
nullptr ) const;
569 int readNumEntry( const QString &scope, const QString &key,
int def = 0,
bool *ok
SIP_OUT =
nullptr ) const;
581 double readDoubleEntry( const QString &scope, const QString &key,
double def = 0,
bool *ok
SIP_OUT =
nullptr ) const;
593 bool readBoolEntry( const QString &scope, const QString &key,
bool def = false,
bool *ok
SIP_OUT =
nullptr ) const;
598 bool removeEntry( const QString &scope, const QString &key );
608 QStringList entryList( const QString &scope, const QString &key ) const;
618 QStringList subkeyList( const QString &scope, const QString &key ) const;
626 void dumpProperties() const;
640 QString writePath( const QString &filename ) const;
645 QString readPath( const QString &filename ) const;
648 QString error() const;
661 QString layerIsEmbedded( const QString &
id ) const;
671 bool createEmbeddedLayer( const QString &layerId, const QString &projectFilePath, QList<QDomNode> &brokenNodes,
672 bool saveFlag = true,
Qgis::ProjectReadFlags flags =
Qgis::ProjectReadFlags() )
SIP_SKIP;
681 QgsLayerTreeGroup *createEmbeddedGroup( const QString &groupName, const QString &projectFilePath, const QStringList &invisibleLayers,
Qgis::ProjectReadFlags flags =
Qgis::ProjectReadFlags() );
684 void setTopologicalEditing(
bool enabled );
687 bool topologicalEditing() const;
703 void setDistanceUnits(
QgsUnitTypes::DistanceUnit unit );
732 QString homePath() const;
746 QString presetHomePath() const;
911 Q_DECL_DEPRECATED
void setNonIdentifiableLayers( const QList<
QgsMapLayer *> &layers );
917 Q_DECL_DEPRECATED
void setNonIdentifiableLayers( const QStringList &layerIds );
923 Q_DECL_DEPRECATED QStringList nonIdentifiableLayers() const;
945 Q_DECL_DEPRECATED
void setAutoTransaction(
bool autoTransaction )
SIP_DEPRECATED;
953 Qgis::TransactionMode transactionMode() const;
964 bool setTransactionMode(
Qgis::TransactionMode transactionMode );
983 QgsTransactionGroup *transactionGroup( const QString &providerKey, const QString &connString );
997 Q_DECL_DEPRECATED
bool evaluateDefaultValues() const
SIP_DEPRECATED;
1004 Q_DECL_DEPRECATED
void setEvaluateDefaultValues(
bool evaluateDefaultValues )
SIP_DEPRECATED;
1029 void setAvoidIntersectionsLayers( const QList<
QgsVectorLayer *> &layers );
1036 void setAvoidIntersectionsMode( const
Qgis::AvoidIntersectionsMode mode );
1043 Qgis::AvoidIntersectionsMode avoidIntersectionsMode()
const {
return mAvoidIntersectionsMode; }
1050 QVariantMap customVariables()
const;
1056 void setCustomVariables(
const QVariantMap &customVariables );
1090 int validCount()
const;
1099 Q_INVOKABLE
QgsMapLayer *mapLayer(
const QString &layerId )
const;
1121 return qobject_cast<T>( mapLayer( layerId ) );
1132 QList<QgsMapLayer *> mapLayersByName(
const QString &layerName )
const;
1143 QList<QgsMapLayer *> mapLayersByShortName(
const QString &shortName )
const;
1154 QMap<QString, QgsMapLayer *> mapLayers(
const bool validOnly =
false )
const;
1159 bool isZipped()
const;
1174 template <
typename T>
1177 return mLayerStore->layers<T>();
1191 template <
typename T>
1195 const auto constMapLayers { mLayerStore->layers<T>() };
1196 for (
const auto l : constMapLayers )
1198 if ( ! l->shortName().isEmpty() )
1200 if ( l->shortName() == shortName )
1203 else if ( l->name() == shortName )
1238 QList<QgsMapLayer *> addMapLayers(
const QList<QgsMapLayer *> &mapLayers
SIP_TRANSFER,
1239 bool addToLegend =
true,
1270 bool addToLegend =
true,
1287 void removeMapLayers(
const QStringList &layerIds );
1304 void removeMapLayers(
const QList<QgsMapLayer *> &layers );
1319 void removeMapLayer(
const QString &layerId );
1368 void removeAllMapLayers();
1375 void reloadAllLayers();
1394 Q_DECL_DEPRECATED
void setTrustLayerMetadata(
bool trust )
SIP_DEPRECATED;
1406 Q_DECL_DEPRECATED
bool trustLayerMetadata() const
SIP_DEPRECATED;
1430 QString createAttachedFile( const QString &nameTemplate );
1438 QStringList attachedFiles() const;
1447 bool removeAttachedFile( const QString &path );
1457 QString attachmentIdentifier( const QString &attachedFile ) const;
1465 QString resolveAttachmentIdentifier( const QString &identifier ) const;
1491 Q_DECL_DEPRECATED QSet<
QgsMapLayer *> requiredLayers() const;
1501 Q_DECL_DEPRECATED
void setRequiredLayers( const QSet<
QgsMapLayer *> &layers );
1517 void setBackgroundColor( const QColor &color );
1525 QColor backgroundColor() const;
1533 void setSelectionColor( const QColor &color );
1541 QColor selectionColor() const;
1554 Q_DECL_DEPRECATED
void setMapScales( const QVector<
double> &scales )
SIP_DEPRECATED;
1567 Q_DECL_DEPRECATED QVector<
double> mapScales() const
SIP_DEPRECATED;
1577 Q_DECL_DEPRECATED
void setUseProjectScales(
bool enabled )
SIP_DEPRECATED;
1593 void generateTsFile( const QString &locale );
1605 QString translate( const QString &context, const QString &sourceText, const
char *disambiguation =
nullptr,
int n = -1 ) const override;
1619 SIP_PYOBJECT __repr__();
1621 QString
str = QStringLiteral(
"<QgsProject: '%1'%2>" ).arg( sipCpp->fileName(),
1623 sipRes = PyUnicode_FromString(
str.toUtf8().constData() );
1641 void readProject(
const QDomDocument & );
1651 void writeProject( QDomDocument & );
1661 void readMapLayer(
QgsMapLayer *mapLayer,
const QDomElement &layerNode );
1671 void writeMapLayer(
QgsMapLayer *mapLayer, QDomElement &layerElem, QDomDocument &doc );
1676 void projectSaved();
1683 Q_DECL_DEPRECATED
void oldProjectVersionWarning(
const QString & )
SIP_DEPRECATED;
1695 void readVersionMismatchOccurred(
const QString &fileVersion );
1702 void layerLoaded(
int i,
int n );
1705 void loadingLayer(
const QString &layerName );
1713 void loadingLayerMessageReceived(
const QString &layerName,
const QList<QgsReadWriteContext::ReadWriteMessage> &messages );
1719 Q_DECL_DEPRECATED
void nonIdentifiableLayersChanged( QStringList nonIdentifiableLayers );
1722 void fileNameChanged();
1730 void homePathChanged();
1742 void avoidIntersectionsModeChanged();
1748 void customVariablesChanged();
1764 void ellipsoidChanged(
const QString &ellipsoid );
1773 void transformContextChanged();
1779 void missingDatumTransforms(
const QStringList &missingTransforms );
1787 void transactionGroupsChanged();
1794 void topologicalEditingChanged();
1801 void avoidIntersectionsLayersChanged();
1814 void mapThemeCollectionChanged();
1820 void labelingEngineSettingsChanged();
1828 void metadataChanged();
1836 void projectColorsChanged();
1844 void backgroundColorChanged();
1852 void selectionColorChanged();
1865 void layersWillBeRemoved(
const QStringList &layerIds );
1874 void layersWillBeRemoved(
const QList<QgsMapLayer *> &layers );
1885 void layerWillBeRemoved(
const QString &layerId );
1904 void layersRemoved(
const QStringList &layerIds );
1914 void layerRemoved(
const QString &layerId );
1936 void layersAdded(
const QList<QgsMapLayer *> &layers );
1954 void legendLayersAdded(
const QList<QgsMapLayer *> &layers );
1963 void isDirtyChanged(
bool dirty );
2002 void setDirty(
bool b = true );
2012 void setPresetHomePath( const QString &path );
2094 bool commitChanges( QStringList &commitErrors
SIP_OUT,
bool stopEditing = true,
QgsVectorLayer *vectorLayer =
nullptr );
2110 bool rollBack( QStringList &rollbackErrors
SIP_OUT,
bool stopEditing = true,
QgsVectorLayer *vectorLayer =
nullptr );
2113 void onMapLayersAdded( const QList<
QgsMapLayer *> &layers );
2114 void onMapLayersRemoved( const QList<
QgsMapLayer *> &layers );
2115 void cleanTransactionGroups(
bool force = false );
2116 void updateTransactionGroups();
2131 bool _getMapLayers( const QDomDocument &doc, QList<QDomNode> &brokenNodes,
Qgis::ProjectReadFlags flags =
Qgis::ProjectReadFlags() );
2137 void setError( const QString &errorMessage )
SIP_SKIP;
2152 bool addLayer( const QDomElement &layerElem, QList<QDomNode> &brokenNodes,
QgsReadWriteContext &context,
Qgis::ProjectReadFlags flags =
Qgis::ProjectReadFlags() )
SIP_SKIP;
2168 bool readProjectFile( const QString &filename,
Qgis::ProjectReadFlags flags =
Qgis::ProjectReadFlags() );
2171 bool writeProjectFile( const QString &filename );
2174 bool unzip( const QString &filename,
Qgis::ProjectReadFlags flags =
Qgis::ProjectReadFlags() );
2177 bool zip( const QString &filename );
2180 bool saveAuxiliaryStorage( const QString &filename = QString() );
2185 Qgis::ProjectCapabilities mCapabilities;
2189 QString mErrorMessage;
2198 QHash< QString, QPair< QString,
bool> > mEmbeddedLayers;
2201 Qgis::AvoidIntersectionsMode mAvoidIntersectionsMode =
Qgis::AvoidIntersectionsMode::AllowIntersections;
2236 QVariantMap mCustomVariables;
2244 QString mOriginalPath;
2247 QString mSaveUserFull;
2248 QDateTime mSaveDateTime;
2256 mutable QString mCachedHomePath;
2258 QColor mBackgroundColor;
2259 QColor mSelectionColor;
2262 Qgis::TransactionMode mTransactionMode =
Qgis::TransactionMode::Disabled;
2264 Qgis::ProjectFlags mFlags;
2266 bool mDirty = false;
2267 int mDirtyBlockCount = 0;
2277 bool mIsBeingDeleted = false;
2283 int mBlockSnappingUpdates = 0;
2293 friend class TestQgsProject;
2329 : mProject( project )
2331 mProject->mDirtyBlockCount++;
2342 mProject->mDirtyBlockCount--;
2367 GetNamedProjectColor(
const QgsProject *project );
2373 GetNamedProjectColor(
const QHash< QString, QColor > &colors );
2380 QHash< QString, QColor > mColors;