24 #include "qgis_core.h"
32 #include <QStringList>
33 #include <QTranslator>
95 Q_PROPERTY( QStringList nonIdentifiableLayers READ nonIdentifiableLayers WRITE setNonIdentifiableLayers NOTIFY nonIdentifiableLayersChanged )
96 Q_PROPERTY( QString fileName READ fileName WRITE setFileName NOTIFY fileNameChanged )
97 Q_PROPERTY( QString homePath READ homePath WRITE setPresetHomePath NOTIFY homePathChanged )
100 Q_PROPERTY( QString ellipsoid READ ellipsoid WRITE setEllipsoid NOTIFY ellipsoidChanged )
102 Q_PROPERTY(
QgsSnappingConfig snappingConfig READ snappingConfig WRITE setSnappingConfig NOTIFY snappingConfigChanged )
104 Q_PROPERTY(
AvoidIntersectionsMode avoidIntersectionsMode READ avoidIntersectionsMode WRITE setAvoidIntersectionsMode NOTIFY avoidIntersectionsModeChanged )
105 Q_PROPERTY( QList<
QgsVectorLayer *> avoidIntersectionsLayers READ avoidIntersectionsLayers WRITE setAvoidIntersectionsLayers NOTIFY avoidIntersectionsLayersChanged )
107 Q_PROPERTY( QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged )
108 Q_PROPERTY( QColor selectionColor READ selectionColor WRITE setSelectionColor NOTIFY selectionColorChanged )
109 Q_PROPERTY(
bool topologicalEditing READ topologicalEditing WRITE setTopologicalEditing NOTIFY topologicalEditingChanged )
119 FlagDontResolveLayers = 1 << 0,
120 FlagDontLoadLayouts = 1 << 1,
122 Q_DECLARE_FLAGS( ReadFlags, ReadFlag )
142 AvoidIntersectionsCurrentLayer,
143 AvoidIntersectionsLayers,
145 Q_ENUM( AvoidIntersectionsMode )
159 WMSOnlineResource = 2,
183 void setTitle(
const QString &title );
191 QString title()
const;
200 QString saveUser()
const;
209 QString saveUserFullName()
const;
216 QDateTime lastSaveDateTime()
const;
221 bool isDirty()
const;
229 void setFileName(
const QString &name );
237 QString fileName()
const;
250 void setOriginalPath(
const QString &path );
263 QString originalPath()
const;
289 QDateTime lastModified() const;
296 QString absoluteFilePath() const;
303 QString absolutePath() const;
309 QString baseName() const;
336 QString ellipsoid() const;
344 void setEllipsoid( const QString &ellipsoid );
403 bool readLayer( const QDomNode &layerNode );
413 bool write( const QString &filename );
431 bool writeEntry( const QString &scope, const QString &key,
bool value )
SIP_PYNAME( writeEntryBool );
442 bool writeEntry( const QString &scope, const QString &key,
double value )
SIP_PYNAME( writeEntryDouble );
452 bool writeEntry( const QString &scope, const QString &key,
int value );
462 bool writeEntry( const QString &scope, const QString &key, const QString &value );
472 bool writeEntry( const QString &scope, const QString &key, const QStringList &value );
480 QStringList readListEntry( const QString &scope, const QString &key, const QStringList &def = QStringList(),
bool *ok =
nullptr ) const;
482 QString readEntry( const QString &scope, const QString &key, const QString &def = QString(),
bool *ok =
nullptr ) const;
483 int readNumEntry( const QString &scope, const QString &key,
int def = 0,
bool *ok =
nullptr ) const;
484 double readDoubleEntry( const QString &scope, const QString &key,
double def = 0,
bool *ok =
nullptr ) const;
485 bool readBoolEntry( const QString &scope, const QString &key,
bool def = false,
bool *ok =
nullptr ) const;
488 bool removeEntry( const QString &scope, const QString &key );
496 QStringList entryList( const QString &scope, const QString &key ) const;
503 QStringList subkeyList( const QString &scope, const QString &key ) const;
511 void dumpProperties() const;
525 QString writePath( const QString &filename ) const;
528 QString readPath( const QString &filename ) const;
531 QString error() const;
540 QString layerIsEmbedded( const QString &
id ) const;
550 bool createEmbeddedLayer( const QString &layerId, const QString &projectFilePath, QList<QDomNode> &brokenNodes,
560 QgsLayerTreeGroup *createEmbeddedGroup( const QString &groupName, const QString &projectFilePath, const QStringList &invisibleLayers,
QgsProject::ReadFlags flags =
QgsProject::ReadFlags() );
563 void setTopologicalEditing(
bool enabled );
566 bool topologicalEditing() const;
582 void setDistanceUnits(
QgsUnitTypes::DistanceUnit unit );
611 QString homePath() const;
625 QString presetHomePath() const;
743 Q_DECL_DEPRECATED
void setNonIdentifiableLayers( const QList<
QgsMapLayer *> &layers );
749 Q_DECL_DEPRECATED
void setNonIdentifiableLayers( const QStringList &layerIds );
755 Q_DECL_DEPRECATED QStringList nonIdentifiableLayers() const;
764 bool autoTransaction() const;
775 void setAutoTransaction(
bool autoTransaction );
794 QgsTransactionGroup *transactionGroup( const QString &providerKey, const QString &connString );
801 bool evaluateDefaultValues() const;
808 void setEvaluateDefaultValues(
bool evaluateDefaultValues );
833 void setAvoidIntersectionsLayers( const QList<
QgsVectorLayer *> &layers );
840 void setAvoidIntersectionsMode( const AvoidIntersectionsMode mode );
854 QVariantMap customVariables()
const;
860 void setCustomVariables(
const QVariantMap &customVariables );
894 int validCount()
const;
903 Q_INVOKABLE
QgsMapLayer *mapLayer(
const QString &layerId )
const;
925 return qobject_cast<T>( mapLayer( layerId ) );
936 QList<QgsMapLayer *> mapLayersByName(
const QString &layerName )
const;
947 QList<QgsMapLayer *> mapLayersByShortName(
const QString &shortName )
const;
958 QMap<QString, QgsMapLayer *> mapLayers(
const bool validOnly =
false )
const;
963 bool isZipped()
const;
978 template <
typename T>
981 return mLayerStore->layers<T>();
995 template <
typename T>
999 const auto constMapLayers { mLayerStore->layers<T>() };
1000 for (
const auto l : constMapLayers )
1002 if ( ! l->shortName().isEmpty() )
1004 if ( l->shortName() == shortName )
1007 else if ( l->name() == shortName )
1042 QList<QgsMapLayer *> addMapLayers(
const QList<QgsMapLayer *> &mapLayers
SIP_TRANSFER,
1043 bool addToLegend =
true,
1074 bool addToLegend =
true,
1091 void removeMapLayers(
const QStringList &layerIds );
1108 void removeMapLayers(
const QList<QgsMapLayer *> &layers );
1123 void removeMapLayer(
const QString &layerId );
1159 void removeAllMapLayers();
1166 void reloadAllLayers();
1185 void setTrustLayerMetadata(
bool trust );
1221 QString attachedFile( const QString &fileName ) const
SIP_SKIP;
1258 Q_DECL_DEPRECATED QSet<
QgsMapLayer *> requiredLayers() const;
1268 Q_DECL_DEPRECATED
void setRequiredLayers( const QSet<
QgsMapLayer *> &layers );
1284 void setBackgroundColor( const QColor &color );
1292 QColor backgroundColor() const;
1300 void setSelectionColor( const QColor &color );
1308 QColor selectionColor() const;
1321 Q_DECL_DEPRECATED
void setMapScales( const QVector<
double> &scales )
SIP_DEPRECATED;
1334 Q_DECL_DEPRECATED QVector<
double> mapScales() const
SIP_DEPRECATED;
1344 Q_DECL_DEPRECATED
void setUseProjectScales(
bool enabled )
SIP_DEPRECATED;
1360 void generateTsFile( const QString &locale );
1372 QString translate( const QString &context, const QString &sourceText, const
char *disambiguation =
nullptr,
int n = -1 ) const override;
1386 SIP_PYOBJECT __repr__();
1388 QString str = QStringLiteral(
"<QgsProject: '%1'%2>" ).arg( sipCpp->fileName(),
1390 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
1408 void readProject(
const QDomDocument & );
1418 void writeProject( QDomDocument & );
1428 void readMapLayer(
QgsMapLayer *mapLayer,
const QDomElement &layerNode );
1438 void writeMapLayer(
QgsMapLayer *mapLayer, QDomElement &layerElem, QDomDocument &doc );
1443 void projectSaved();
1448 void oldProjectVersionWarning(
const QString & );
1455 void layerLoaded(
int i,
int n );
1458 void loadingLayer(
const QString &layerName );
1466 void loadingLayerMessageReceived(
const QString &layerName,
const QList<QgsReadWriteContext::ReadWriteMessage> &messages );
1472 Q_DECL_DEPRECATED
void nonIdentifiableLayersChanged( QStringList nonIdentifiableLayers );
1475 void fileNameChanged();
1483 void homePathChanged();
1495 void avoidIntersectionsModeChanged();
1501 void customVariablesChanged();
1517 void ellipsoidChanged(
const QString &ellipsoid );
1526 void transformContextChanged();
1532 void missingDatumTransforms(
const QStringList &missingTransforms );
1540 void transactionGroupsChanged();
1547 void topologicalEditingChanged();
1554 void avoidIntersectionsLayersChanged();
1567 void mapThemeCollectionChanged();
1573 void labelingEngineSettingsChanged();
1581 void metadataChanged();
1589 void projectColorsChanged();
1597 void backgroundColorChanged();
1605 void selectionColorChanged();
1618 void layersWillBeRemoved(
const QStringList &layerIds );
1627 void layersWillBeRemoved(
const QList<QgsMapLayer *> &layers );
1638 void layerWillBeRemoved(
const QString &layerId );
1657 void layersRemoved(
const QStringList &layerIds );
1667 void layerRemoved(
const QString &layerId );
1689 void layersAdded(
const QList<QgsMapLayer *> &layers );
1707 void legendLayersAdded(
const QList<QgsMapLayer *> &layers );
1716 void isDirtyChanged(
bool dirty );
1761 void setDirty(
bool b = true );
1771 void setPresetHomePath( const QString &path );
1809 void onMapLayersAdded( const QList<
QgsMapLayer *> &layers );
1810 void onMapLayersRemoved( const QList<
QgsMapLayer *> &layers );
1811 void cleanTransactionGroups(
bool force = false );
1835 bool _getMapLayers( const QDomDocument &doc, QList<QDomNode> &brokenNodes,
QgsProject::ReadFlags flags =
QgsProject::ReadFlags() );
1841 void setError( const QString &errorMessage )
SIP_SKIP;
1872 bool readProjectFile( const QString &filename,
QgsProject::ReadFlags flags =
QgsProject::ReadFlags() );
1875 bool writeProjectFile( const QString &filename );
1881 bool zip( const QString &filename );
1884 bool saveAuxiliaryStorage( const QString &filename = QString() );
1891 QString mErrorMessage;
1900 QHash< QString, QPair< QString,
bool> > mEmbeddedLayers;
1903 AvoidIntersectionsMode mAvoidIntersectionsMode = AvoidIntersectionsMode::AllowIntersections;
1929 QVariantMap mCustomVariables;
1937 QString mOriginalPath;
1940 QString mSaveUserFull;
1941 QDateTime mSaveDateTime;
1948 mutable QString mCachedHomePath;
1950 QColor mBackgroundColor;
1951 QColor mSelectionColor;
1954 bool mAutoTransaction = false;
1955 bool mEvaluateDefaultValues = false;
1957 bool mDirty = false;
1958 int mDirtyBlockCount = 0;
1959 bool mTrustLayerMetadata = false;
1969 bool mIsBeingDeleted = false;
1981 friend class TestQgsProject;
1984 Q_DECLARE_OPERATORS_FOR_FLAGS(
QgsProject::ReadFlags )
2017 : mProject( project )
2019 mProject->mDirtyBlockCount++;
2030 mProject->mDirtyBlockCount--;
2055 GetNamedProjectColor(
const QgsProject *project );
2061 GetNamedProjectColor(
const QHash< QString, QColor > &colors );
2068 QHash< QString, QColor > mColors;