24 #include "qgis_core.h"
32 #include <QStringList>
33 #include <QTranslator>
97 Q_PROPERTY( QStringList nonIdentifiableLayers READ nonIdentifiableLayers WRITE setNonIdentifiableLayers NOTIFY nonIdentifiableLayersChanged )
98 Q_PROPERTY( QString fileName READ fileName WRITE setFileName NOTIFY fileNameChanged )
99 Q_PROPERTY( QString homePath READ homePath WRITE setPresetHomePath NOTIFY homePathChanged )
102 Q_PROPERTY( QString ellipsoid READ ellipsoid WRITE setEllipsoid NOTIFY ellipsoidChanged )
103 Q_PROPERTY(
QgsMapThemeCollection *mapThemeCollection READ mapThemeCollection NOTIFY mapThemeCollectionChanged )
104 Q_PROPERTY(
QgsSnappingConfig snappingConfig READ snappingConfig WRITE setSnappingConfig NOTIFY snappingConfigChanged )
106 Q_PROPERTY(
AvoidIntersectionsMode avoidIntersectionsMode READ avoidIntersectionsMode WRITE setAvoidIntersectionsMode NOTIFY avoidIntersectionsModeChanged )
107 Q_PROPERTY( QList<QgsVectorLayer *> avoidIntersectionsLayers READ avoidIntersectionsLayers WRITE setAvoidIntersectionsLayers NOTIFY avoidIntersectionsLayersChanged )
108 Q_PROPERTY(
QgsProjectMetadata metadata READ metadata WRITE setMetadata NOTIFY metadataChanged )
109 Q_PROPERTY( QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged )
110 Q_PROPERTY( QColor selectionColor READ selectionColor WRITE setSelectionColor NOTIFY selectionColorChanged )
111 Q_PROPERTY(
bool topologicalEditing READ topologicalEditing WRITE setTopologicalEditing NOTIFY topologicalEditingChanged )
121 FlagDontResolveLayers = 1 << 0,
122 FlagDontLoadLayouts = 1 << 1,
123 FlagTrustLayerMetadata = 1 << 2,
125 Q_DECLARE_FLAGS( ReadFlags, ReadFlag )
145 AvoidIntersectionsCurrentLayer,
146 AvoidIntersectionsLayers,
148 Q_ENUM( AvoidIntersectionsMode )
162 WMSOnlineResource = 2,
176 static void setInstance(
QgsProject *project ) ;
197 void setTitle(
const QString &title );
205 QString title()
const;
214 QString saveUser()
const;
223 QString saveUserFullName()
const;
230 QDateTime lastSaveDateTime()
const;
242 bool isDirty()
const;
250 void setFileName(
const QString &name );
258 QString fileName()
const;
271 void setOriginalPath(
const QString &path );
284 QString originalPath()
const;
310 QDateTime lastModified() const;
317 QString absoluteFilePath() const;
324 QString absolutePath() const;
330 QString baseName() const;
357 QString ellipsoid() const;
365 void setEllipsoid( const QString &ellipsoid );
424 bool readLayer( const QDomNode &layerNode );
434 bool write( const QString &filename );
454 bool writeEntry( const QString &scope, const QString &key,
bool value )
SIP_PYNAME( writeEntryBool );
467 bool writeEntry( const QString &scope, const QString &key,
double value )
SIP_PYNAME( writeEntryDouble );
479 bool writeEntry( const QString &scope, const QString &key,
int value );
491 bool writeEntry( const QString &scope, const QString &key, const QString &value );
503 bool writeEntry( const QString &scope, const QString &key, const QStringList &value );
515 QStringList readListEntry( const QString &scope, const QString &key, const QStringList &def = QStringList(),
bool *ok
SIP_OUT =
nullptr ) const;
527 QString readEntry( const QString &scope, const QString &key, const QString &def = QString(),
bool *ok
SIP_OUT =
nullptr ) const;
539 int readNumEntry( const QString &scope, const QString &key,
int def = 0,
bool *ok
SIP_OUT =
nullptr ) const;
551 double readDoubleEntry( const QString &scope, const QString &key,
double def = 0,
bool *ok
SIP_OUT =
nullptr ) const;
563 bool readBoolEntry( const QString &scope, const QString &key,
bool def = false,
bool *ok
SIP_OUT =
nullptr ) const;
568 bool removeEntry( const QString &scope, const QString &key );
578 QStringList entryList( const QString &scope, const QString &key ) const;
588 QStringList subkeyList( const QString &scope, const QString &key ) const;
596 void dumpProperties() const;
610 QString writePath( const QString &filename ) const;
615 QString readPath( const QString &filename ) const;
618 QString error() const;
631 QString layerIsEmbedded( const QString &
id ) const;
641 bool createEmbeddedLayer( const QString &layerId, const QString &projectFilePath, QList<QDomNode> &brokenNodes,
651 QgsLayerTreeGroup *createEmbeddedGroup( const QString &groupName, const QString &projectFilePath, const QStringList &invisibleLayers,
QgsProject::ReadFlags flags =
QgsProject::ReadFlags() );
654 void setTopologicalEditing(
bool enabled );
657 bool topologicalEditing() const;
673 void setDistanceUnits(
QgsUnitTypes::DistanceUnit unit );
702 QString homePath() const;
716 QString presetHomePath() const;
834 Q_DECL_DEPRECATED
void setNonIdentifiableLayers( const QList<
QgsMapLayer *> &layers );
840 Q_DECL_DEPRECATED
void setNonIdentifiableLayers( const QStringList &layerIds );
846 Q_DECL_DEPRECATED QStringList nonIdentifiableLayers() const;
855 bool autoTransaction() const;
866 void setAutoTransaction(
bool autoTransaction );
885 QgsTransactionGroup *transactionGroup( const QString &providerKey, const QString &connString );
892 bool evaluateDefaultValues() const;
899 void setEvaluateDefaultValues(
bool evaluateDefaultValues );
924 void setAvoidIntersectionsLayers( const QList<
QgsVectorLayer *> &layers );
945 QVariantMap customVariables()
const;
951 void setCustomVariables(
const QVariantMap &customVariables );
985 int validCount()
const;
994 Q_INVOKABLE
QgsMapLayer *mapLayer(
const QString &layerId )
const;
1016 return qobject_cast<T>( mapLayer( layerId ) );
1027 QList<QgsMapLayer *> mapLayersByName(
const QString &layerName )
const;
1038 QList<QgsMapLayer *> mapLayersByShortName(
const QString &shortName )
const;
1049 QMap<QString, QgsMapLayer *> mapLayers(
const bool validOnly =
false )
const;
1054 bool isZipped()
const;
1069 template <
typename T>
1072 return mLayerStore->layers<T>();
1086 template <
typename T>
1090 const auto constMapLayers { mLayerStore->layers<T>() };
1091 for (
const auto l : constMapLayers )
1093 if ( ! l->shortName().isEmpty() )
1095 if ( l->shortName() == shortName )
1098 else if ( l->name() == shortName )
1133 QList<QgsMapLayer *> addMapLayers(
const QList<QgsMapLayer *> &mapLayers
SIP_TRANSFER,
1134 bool addToLegend =
true,
1165 bool addToLegend =
true,
1182 void removeMapLayers(
const QStringList &layerIds );
1199 void removeMapLayers(
const QList<QgsMapLayer *> &layers );
1214 void removeMapLayer(
const QString &layerId );
1263 void removeAllMapLayers();
1270 void reloadAllLayers();
1289 void setTrustLayerMetadata(
bool trust );
1325 QString attachedFile( const QString &fileName ) const
SIP_SKIP;
1362 Q_DECL_DEPRECATED QSet<
QgsMapLayer *> requiredLayers() const;
1372 Q_DECL_DEPRECATED
void setRequiredLayers( const QSet<
QgsMapLayer *> &layers );
1388 void setBackgroundColor( const QColor &color );
1396 QColor backgroundColor() const;
1404 void setSelectionColor( const QColor &color );
1412 QColor selectionColor() const;
1425 Q_DECL_DEPRECATED
void setMapScales( const QVector<
double> &scales )
SIP_DEPRECATED;
1438 Q_DECL_DEPRECATED QVector<
double> mapScales() const
SIP_DEPRECATED;
1448 Q_DECL_DEPRECATED
void setUseProjectScales(
bool enabled )
SIP_DEPRECATED;
1464 void generateTsFile( const QString &locale );
1476 QString translate( const QString &context, const QString &sourceText, const
char *disambiguation =
nullptr,
int n = -1 ) const override;
1490 SIP_PYOBJECT __repr__();
1492 QString str = QStringLiteral(
"<QgsProject: '%1'%2>" ).arg( sipCpp->fileName(),
1494 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
1865 void setDirty(
bool b = true );
1875 void setPresetHomePath( const QString &path );
1913 void onMapLayersAdded( const QList<
QgsMapLayer *> &layers );
1914 void onMapLayersRemoved( const QList<
QgsMapLayer *> &layers );
1915 void cleanTransactionGroups(
bool force = false );
1930 bool _getMapLayers( const QDomDocument &doc, QList<QDomNode> &brokenNodes,
QgsProject::ReadFlags flags =
QgsProject::ReadFlags() );
1936 void setError( const QString &errorMessage )
SIP_SKIP;
1967 bool readProjectFile( const QString &filename,
QgsProject::ReadFlags flags =
QgsProject::ReadFlags() );
1970 bool writeProjectFile( const QString &filename );
1976 bool zip( const QString &filename );
1979 bool saveAuxiliaryStorage( const QString &filename = QString() );
1986 QString mErrorMessage;
1995 QHash< QString, QPair< QString,
bool> > mEmbeddedLayers;
2026 QVariantMap mCustomVariables;
2034 QString mOriginalPath;
2037 QString mSaveUserFull;
2038 QDateTime mSaveDateTime;
2046 mutable QString mCachedHomePath;
2048 QColor mBackgroundColor;
2049 QColor mSelectionColor;
2052 bool mAutoTransaction = false;
2053 bool mEvaluateDefaultValues = false;
2055 bool mDirty = false;
2056 int mDirtyBlockCount = 0;
2057 bool mTrustLayerMetadata = false;
2067 bool mIsBeingDeleted = false;
2079 friend class TestQgsProject;
2117 : mProject( project )
2119 mProject->mDirtyBlockCount++;
2130 mProject->mDirtyBlockCount--;
2155 GetNamedProjectColor(
const QgsProject *project );
2161 GetNamedProjectColor(
const QHash< QString, QColor > &colors );
2168 QHash< QString, QColor > mColors;