41 #include <QApplication>
45 #include <QTextStream>
46 #include <QTemporaryFile>
54 #include <sys/utime.h>
72 keyTokens += key.
split(
'/', QString::SkipEmptyParts );
78 for (
int i = 0; i < keyTokens.
size(); ++i )
84 QString nameCharRegexp =
QString(
"[^:A-Z_a-z\\xC0-\\xD6\\xD8-\\xF6\\xF8-\\x2FF\\x370-\\x37D\\x37F-\\x1FFF\\x200C-\\x200D\\x2070-\\x218F\\x2C00-\\x2FEF\\x3001-\\xD7FF\\xF900-\\xFDCF\\xFDF0-\\xFFFD\\-\\.0-9\\xB7\\x0300-\\x036F\\x203F-\\x2040]" );
85 QString nameStartCharRegexp =
QString(
"^[^:A-Z_a-z\\xC0-\\xD6\\xD8-\\xF6\\xF8-\\x2FF\\x370-\\x37D\\x37F-\\x1FFF\\x200C-\\x200D\\x2070-\\x218F\\x2C00-\\x2FEF\\x3001-\\xD7FF\\xF900-\\xFDCF\\xFDF0-\\xFFFD]" );
90 QString errorString =
QObject::tr(
"Entry token invalid : '%1'. The token will not be saved to file." ).
arg( keyToken );
122 while ( !keySequence.
isEmpty() )
126 if ( keySequence.
first() == currentProperty->
name() )
131 if ( 1 == keySequence.
count() )
134 return currentProperty->
find( keySequence.
front() );
136 else if ( keySequence.
isEmpty() )
141 return currentProperty;
143 else if (( nextProperty = currentProperty->
find( keySequence.
first() ) ) )
145 if ( nextProperty->
isKey() )
149 else if ( nextProperty->
isValue() && 1 == keySequence.
count() )
155 return currentProperty;
201 while ( ! keySequence.
isEmpty() )
205 if ( keySequence.
first() == currentProperty->
name() )
212 if ( 1 == keySequence.
count() )
215 return currentProperty;
219 else if ( keySequence.
isEmpty() )
223 return currentProperty;
225 else if (( nextProperty = currentProperty->
find( keySequence.
first() ) ) )
229 if ( currentProperty )
240 if (( newPropertyKey = currentProperty->
addKey( keySequence.
first() ) ) )
242 currentProperty = newPropertyKey;
271 while ( ! keySequence.
isEmpty() )
275 if ( keySequence.
first() == currentProperty->
name() )
282 if ( 1 == keySequence.
count() )
289 else if ( keySequence.
isEmpty() )
291 previousQgsPropertyKey->
removeKey( currentProperty->
name() );
293 else if (( nextProperty = currentProperty->
find( keySequence.
first() ) ) )
295 previousQgsPropertyKey = currentProperty;
298 if ( currentProperty )
335 properties_.
name() =
"properties";
354 QgsProject::QgsProject()
372 delete mBadLayerHandler;
373 delete mRelationManager;
428 imp_->file.setFileName( name );
437 return imp_->file.fileName();
448 mEmbeddedLayers.
clear();
449 mRelationManager->
clear();
457 writeEntry(
"PositionPrecision",
"/Automatic",
true );
458 writeEntry(
"PositionPrecision",
"/DecimalPlaces", 2 );
473 topQgsPropertyKey.
dump();
513 if ( properties.
count() > 1 )
515 QgsDebugMsg(
"there appears to be more than one ``properties'' XML tag ... bailing" );
518 else if ( properties.
count() < 1 )
526 if ( scopes.
count() < 1 )
528 QgsDebugMsg(
"empty ``properties'' XML tag ... bailing" );
534 if ( ! project_properties.
readXML( propertyNode ) )
536 QgsDebugMsg(
"Project_properties.readXML() failed" );
576 if ( !titleTextNode.
isText() )
584 title = titleText.
data();
599 QgsDebugMsg(
" unable to find qgis element in project file" );
607 return projectVersion;
673 if ( 0 == nl.
count() )
675 return qMakePair(
true, brokenNodes );
683 bool returnStatus =
true;
689 if ( depSorter.hasCycle() || depSorter.hasMissingDependency() )
698 Q_FOREACH (
const QDomNode& node, sortedLayerNodes )
706 if ( element.
attribute(
"embedded" ) ==
"1" )
713 if ( !
addLayer( element, brokenNodes, vLayerList ) )
715 returnStatus =
false;
725 for ( ; vIt != vLayerList.
end(); ++vIt )
727 vIt->
first->createJoinCaches();
728 vIt->
first->updateFields();
732 for ( vIt = vLayerList.
begin(); vIt != vLayerList.
end(); ++vIt )
737 notified << vIt->
first;
743 return qMakePair( returnStatus, brokenNodes );
752 if ( type ==
"vector" )
756 else if ( type ==
"raster" )
760 else if ( type ==
"plugin" )
773 Q_CHECK_PTR( mapLayer );
783 vectorLayerList.push_back( qMakePair( vLayer, layerElem ) );
786 myLayers << mapLayer;
795 QgsDebugMsg(
"Unable to load " + type +
" layer" );
807 imp_->file.setFileName( file.
filePath() );
823 if ( !imp_->file.open( QIODevice::ReadOnly | QIODevice::Text ) )
827 setError(
tr(
"Unable to open %1" ).arg( imp_->file.fileName() ) );
836 if ( !doc->setContent( &imp_->file, &errorMsg, &line, &column ) )
841 tr(
"%1 at line %2 column %3" ).arg( errorMsg ).arg( line ).arg( column ) );
844 QString errorString =
tr(
"Project file read error: %1 at line %2 column %3" )
845 .
arg( errorMsg ).
arg( line ).
arg( column );
851 setError(
tr(
"%1 for file %2" ).arg( errorString, imp_->file.fileName() ) );
859 QgsDebugMsg(
"Opened document " + imp_->file.fileName() );
866 if ( thisVersion > fileVersion )
869 "version of qgis (saved in " + fileVersion.
text() +
871 "). Problems may occur." );
877 QgsDebugMsg(
"Emitting oldProjectVersionWarning(oldVersion)." );
879 projectFile.updateRevision( thisVersion );
885 imp_->file.setFileName( fileName );
892 dump_( imp_->properties_ );
901 QDomElement layerTreeElem = doc->documentElement().firstChildElement(
"layer-tree-group" );
902 if ( !layerTreeElem.
isNull() )
913 mLayerTreeRegistryBridge->
setEnabled(
false );
919 bool clean = getMapLayersResults.first;
923 QgsDebugMsg(
"Unable to get map layers from project file." );
925 if ( ! getMapLayersResults.second.isEmpty() )
946 mVisibilityPresetCollection->readXML( *doc );
978 clonedChildren << newGroupChild->
clone();
1014 imp_->file.setFileName( file.
filePath() );
1030 setError(
tr(
"%1 is not writable. Please adjust permissions (if possible) and try again." )
1031 .arg( imp_->file.fileName() ) );
1043 QDomElement qgisNode = doc->createElement(
"qgis" );
1047 doc->appendChild( qgisNode );
1050 QDomElement titleNode = doc->createElement(
"title" );
1071 QDomElement projectLayersNode = doc->createElement(
"projectlayers" );
1074 while ( li != layers.
end() )
1082 if ( emIt == mEmbeddedLayers.
constEnd() )
1085 QDomElement maplayerElem = doc->createElement(
"maplayer" );
1097 if ( emIt.value().second )
1099 QDomElement mapLayerElem = doc->createElement(
"maplayer" );
1114 dump_( imp_->properties_ );
1116 QgsDebugMsg(
QString(
"there are %1 property scopes" ).arg( static_cast<int>( imp_->properties_.count() ) ) );
1118 if ( !imp_->properties_.isEmpty() )
1121 imp_->properties_.writeXML(
"properties", qgisNode, *doc );
1124 mVisibilityPresetCollection->writeXML( *doc );
1134 ok &= backupFile.
open( QIODevice::WriteOnly | QIODevice::Truncate );
1135 ok &= imp_->file.open( QIODevice::ReadOnly );
1138 while ( ok && !imp_->file.atEnd() )
1140 ba = imp_->file.read( 10240 );
1141 ok &= backupFile.
write( ba ) == ba.
size();
1158 if ( !imp_->file.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
1163 setError(
tr(
"Unable to save to file %1" ).arg( imp_->file.fileName() ) );
1168 bool ok = tempFile.
open();
1172 doc->save( projectFileStream, 2 );
1173 ok &= projectFileStream.
pos() > -1;
1175 ok &= tempFile.
seek( 0 );
1178 while ( ok && !tempFile.
atEnd() )
1180 ba = tempFile.
read( 10240 );
1181 ok &= imp_->file.write( ba ) == ba.
size();
1184 ok &= imp_->file.error() == QFile::NoError;
1193 setError(
tr(
"Unable to save to file %1. Your project "
1194 "may be corrupted on disk. Try clearing some space on the volume and "
1195 "check file permissions before pressing save again." )
1196 .arg( imp_->file.fileName() ) );
1223 return addKey_( scope, key, &imp_->properties_, value );
1233 return addKey_( scope, key, &imp_->properties_, value );
1242 return addKey_( scope, key, &imp_->properties_, value );
1252 return addKey_( scope, key, &imp_->properties_, value );
1262 return addKey_( scope, key, &imp_->properties_, value );
1277 value =
property->
value();
1279 bool valid = QVariant::StringList == value.
type();
1305 value =
property->
value();
1307 bool valid = value.
canConvert( QVariant::String );
1329 value =
property->
value();
1332 bool valid = value.
canConvert( QVariant::String );
1341 return value.
toInt();
1358 bool valid = value.
canConvert( QVariant::Double );
1380 bool valid = value.
canConvert( QVariant::Bool );
1398 return !
findKey_( scope, key, imp_->properties_ );
1409 if ( foundProperty )
1427 if ( foundProperty )
1443 dump_( imp_->properties_ );
1461 if ( src.
startsWith(
"/vsi", Qt::CaseInsensitive ) )
1470 #if defined(Q_OS_WIN)
1473 ( src[0].isLetter() && src[1] ==
':' ) )
1476 return vsiPrefix + src;
1479 if ( src[0] ==
'/' )
1482 return vsiPrefix + src;
1492 return vsiPrefix + src;
1498 return vsiPrefix + src;
1511 return vsiPrefix + src;
1514 #if defined(Q_OS_WIN)
1516 projPath.
replace(
'\\',
'/' );
1524 #if defined(Q_OS_WIN)
1527 projElems.
insert( 0,
"" );
1528 projElems.
insert( 0,
"" );
1536 projElems << srcElems;
1541 while (( pos = projElems.
indexOf(
".." ) ) > 0 )
1548 #if !defined(Q_OS_WIN)
1553 return vsiPrefix + projElems.
join(
"/" );
1569 if ( !relativeBasePath.
isNull() )
1571 projPath = relativeBasePath;
1586 #if defined( Q_OS_WIN )
1587 const Qt::CaseSensitivity cs = Qt::CaseInsensitive;
1594 srcPath =
"\\\\" + srcPath.
mid( 2 );
1597 projPath.
replace(
'\\',
'/' );
1601 projPath =
"\\\\" + projPath.
mid( 2 );
1604 const Qt::CaseSensitivity cs = Qt::CaseSensitive;
1618 while ( !srcElems.
isEmpty() &&
1620 srcElems[0].compare( projElems[0], cs ) == 0 )
1636 for (
int i = 0; i < projElems.
size(); i++ )
1638 srcElems.
insert( 0,
".." );
1645 srcElems.
insert( 0,
"." );
1648 return vsiPrefix + srcElems.
join(
"/" );
1653 mErrorMessage = errorMessage;
1658 return mErrorMessage;
1668 delete mBadLayerHandler;
1669 mBadLayerHandler = handler;
1675 if ( it == mEmbeddedLayers.
constEnd() )
1679 return it.
value().first;
1687 static QString prevProjectFilePath;
1688 static QDateTime prevProjectFileTimestamp;
1693 if ( projectFilePath != prevProjectFilePath || projectFileTimestamp != prevProjectFileTimestamp )
1695 prevProjectFilePath.
clear();
1697 QFile projectFile( projectFilePath );
1698 if ( !projectFile.
open( QIODevice::ReadOnly ) )
1703 if ( !projectDocument.
setContent( &projectFile ) )
1708 prevProjectFilePath = projectFilePath;
1709 prevProjectFileTimestamp = projectFileTimestamp;
1713 bool useAbsolutePathes =
true;
1716 if ( !propertiesElem.
isNull() )
1721 useAbsolutePathes = absElem.
text().
compare(
"true", Qt::CaseInsensitive ) == 0;
1726 if ( projectLayersElem.
isNull() )
1732 for (
int i = 0; i < mapLayerNodes.
size(); ++i )
1737 if (
id == layerId )
1740 if ( mapLayerElem.
attribute(
"embedded" ) ==
"1" )
1745 mEmbeddedLayers.
insert( layerId, qMakePair( projectFilePath, saveFlag ) );
1749 if ( !useAbsolutePathes )
1753 QString datasource( dsElem.text() );
1754 if ( provider ==
"spatialite" )
1758 if ( absoluteDs.exists() )
1761 datasource = uri.
uri();
1764 else if ( provider ==
"ogr" )
1766 QStringList theURIParts( datasource.split(
'|' ) );
1767 QFileInfo absoluteDs(
QFileInfo( projectFilePath ).absolutePath() +
'/' + theURIParts[0] );
1768 if ( absoluteDs.exists() )
1770 theURIParts[0] = absoluteDs.absoluteFilePath();
1771 datasource = theURIParts.join(
"|" );
1774 else if ( provider ==
"gpx" )
1776 QStringList theURIParts( datasource.split(
'?' ) );
1777 QFileInfo absoluteDs(
QFileInfo( projectFilePath ).absolutePath() +
'/' + theURIParts[0] );
1778 if ( absoluteDs.exists() )
1780 theURIParts[0] = absoluteDs.absoluteFilePath();
1781 datasource = theURIParts.join(
"?" );
1784 else if ( provider ==
"delimitedtext" )
1788 if ( !datasource.startsWith(
"file:" ) )
1792 urlSource.
setPath( file.path() );
1796 if ( absoluteDs.exists() )
1805 QFileInfo absoluteDs(
QFileInfo( projectFilePath ).absolutePath() +
'/' + datasource );
1806 if ( absoluteDs.
exists() )
1812 dsElem.removeChild( dsElem.childNodes().at( 0 ) );
1813 dsElem.appendChild( projectDocument.
createTextNode( datasource ) );
1816 if (
addLayer( mapLayerElem, brokenNodes, vectorLayerList ) )
1822 mEmbeddedLayers.
remove( layerId );
1835 QFile projectFile( projectFilePath );
1836 if ( !projectFile.
open( QIODevice::ReadOnly ) )
1842 if ( !projectDocument.
setContent( &projectFile ) )
1850 if ( !disabledLayersElem.
isNull() )
1853 for (
int i = 0; i < valueList.
size(); ++i )
1862 if ( !layerTreeElem.
isNull() )
1888 mLayerTreeRegistryBridge->
setEnabled(
false );
1890 mLayerTreeRegistryBridge->
setEnabled(
true );
1895 if ( embeddedIdentifyDisabledLayers.
contains( layerId ) )
1898 thisProjectIdentifyDisabledLayers.
append( layerId );
1905 layer->
setVisible( invisibleLayers.
contains( layerId ) ? Qt::Unchecked : Qt::Checked );
1935 QStringList layerIdList, enabledList, snapTypeList, toleranceUnitList, toleranceList, avoidIntersectionList;
1936 snapSettings( layerIdList, enabledList, snapTypeList, toleranceUnitList, toleranceList, avoidIntersectionList );
1937 int idx = layerIdList.
indexOf( layerId );
1945 avoidIntersectionList.
removeOne( layerId );
1948 layerIdList.
append( layerId );
1951 enabledList.
append( enabled ?
"enabled" :
"disabled" );
1957 typeString =
"to_segment";
1961 typeString =
"to_vertex_and_segment";
1965 typeString =
"to_vertex";
1967 snapTypeList.
append( typeString );
1976 if ( avoidIntersection )
1978 avoidIntersectionList.
append( layerId );
1981 writeEntry(
"Digitizing",
"/LayerSnappingList", layerIdList );
1982 writeEntry(
"Digitizing",
"/LayerSnappingEnabledList", enabledList );
1983 writeEntry(
"Digitizing",
"/LayerSnappingToleranceList", toleranceList );
1984 writeEntry(
"Digitizing",
"/LayerSnappingToleranceUnitList", toleranceUnitList );
1985 writeEntry(
"Digitizing",
"/LayerSnapToList", snapTypeList );
1986 writeEntry(
"Digitizing",
"/AvoidIntersectionsList", avoidIntersectionList );
1991 bool &avoidIntersection )
const
1993 QStringList layerIdList, enabledList, snapTypeList, toleranceUnitList, toleranceList, avoidIntersectionList;
1994 snapSettings( layerIdList, enabledList, snapTypeList, toleranceUnitList, toleranceList, avoidIntersectionList );
1995 int idx = layerIdList.
indexOf( layerId );
2002 int minListEntries = idx + 1;
2003 if ( layerIdList.
size() < minListEntries || enabledList.
size() < minListEntries || snapTypeList.
size() < minListEntries ||
2004 toleranceUnitList.
size() < minListEntries || toleranceList.
size() < minListEntries )
2010 enabled = enabledList.
at( idx ) ==
"enabled";
2013 QString snapType = snapTypeList.
at( idx );
2014 if ( snapType ==
"to_segment" )
2018 else if ( snapType ==
"to_vertex_and_segment" )
2028 if ( toleranceUnitList.
at( idx ) ==
"1" )
2032 else if ( toleranceUnitList.
at( idx ) ==
"2" )
2042 tolerance = toleranceList.
at( idx ).toDouble();
2045 avoidIntersection = ( avoidIntersectionList.
indexOf( layerId ) != -1 );
2053 layerIdList =
readListEntry(
"Digitizing",
"/LayerSnappingList" );
2054 enabledList =
readListEntry(
"Digitizing",
"/LayerSnappingEnabledList" );
2055 toleranceList =
readListEntry(
"Digitizing",
"/LayerSnappingToleranceList" );
2056 toleranceUnitList =
readListEntry(
"Digitizing",
"/LayerSnappingToleranceUnitList" );
2057 snapTypeList =
readListEntry(
"Digitizing",
"/LayerSnapToList" );
2058 avoidIntersectionList =
readListEntry(
"Digitizing",
"/AvoidIntersectionsList" );
2075 if ( !distanceUnitString.
isEmpty() )
2088 if ( !areaUnitString.
isEmpty() )
2107 return QString::null;
2114 return mRelationManager;
2124 return mVisibilityPresetCollection.
data();
QObject * child(const char *objName, const char *inheritsClass, bool recursiveSearch) const
static const char * QGIS_VERSION
bool canConvert(Type t) const
Layer tree group node serves as a container for layers and further groups.
bool topologicalEditing() const
Convenience function to query topological editing status.
static QgsProperty * findKey_(QString const &scope, QString const &key, QgsPropertyKey &rootProperty)
return the property that matches the given key sequence, if any
QString fromAscii(const char *str, int size)
QDomNodeList elementsByTagName(const QString &tagname) const
virtual void handleBadLayers(const QList< QDomNode > &layers, const QDomDocument &projectDom)=0
QString database() const
Returns the database.
virtual void handleBadLayers(const QList< QDomNode > &layers, const QDomDocument &projectDom) override
Base class for all map layer types.
virtual bool seek(qint64 pos)
static void removeInvalidLayers(QgsLayerTreeGroup *group)
Remove layer nodes that refer to invalid layers.
QString writePath(const QString &filename, const QString &relativeBasePath=QString::null) const
Prepare a filename to save it to the project file.
const QList< QgsVectorJoinInfo > vectorJoins() const
QString title() const
Returns title.
iterator insert(const Key &key, const T &value)
QDomNode item(int index) const
void readChildrenFromXML(QDomElement &element)
Read children from XML and append them to the group.
void loadingLayer(const QString &)
QgsPropertyKey properties_
QgsPropertyKey * addKey(const QString &keyName)
add the given property key
QGis::UnitType distanceUnits() const
Convenience function to query default distance measurement units for project.
void setTopologicalEditing(bool enabled)
Convenience function to set topological editing.
QDomNode appendChild(const QDomNode &newChild)
bool snapSettingsForLayer(const QString &layerId, bool &enabled, QgsSnapper::SnappingType &type, QgsTolerance::UnitType &units, double &tolerance, bool &avoidIntersection) const
Convenience function to query snap settings of a layer.
QDateTime lastRead() const
void push_back(const T &value)
QList< QgsMapLayer * > addMapLayers(const QList< QgsMapLayer * > &theMapLayers, bool addToLegend=true, bool takeOwnership=true)
Add a list of layers to the map of loaded layers.
void entryList(QStringList &entries) const
return keys that do not contain other keys
QVariant customProperty(const QString &key, const QVariant &defaultValue=QVariant()) const
Read a custom property from layer.
QString attribute(const QString &name, const QString &defValue) const
static void _getProperties(QDomDocument const &doc, QgsPropertyKey &project_properties)
Restore any optional properties found in "doc" to "properties".
QgsPropertyValue * setValue(const QString &name, const QVariant &value)
Set the value associated with this key.
This class provides qgis with the ability to render raster datasets onto the mapcanvas.
static AreaUnit decodeAreaUnit(const QString &string, bool *ok=0)
Decodes an areal unit from a string.
UnitType
Map units that qgis supports.
void removeAllChildren()
Remove all child nodes. The nodes will be deleted.
Pixels unit of tolerance.
virtual QgsLayerTreeNode * clone() const =0
Create a copy of the node. Returns new instance.
QStringList split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
static void warning(const QString &msg)
Goes to qWarning.
QList< QPair< QString, QString > > queryItems() const
Class used to work with layer dependencies stored in a XML project or layer definition file...
static QGis::UnitType decodeDistanceUnit(const QString &string, bool *ok=0)
Decodes a distance unit from a string.
void setDatabase(const QString &database)
Set database.
const_iterator constBegin() const
const T & at(int i) const
static bool readOldLegend(QgsLayerTreeGroup *root, const QDomElement &legendElem)
Try to load layer tree from.
bool contains(const QString &str, Qt::CaseSensitivity cs) const
void emitVariablesChanged()
Causes the project to emit the variablesChanged() signal.
void setFileName(const QString &name)
Every project has an associated file that contains its XML.
void setFileName(const QString &name)
void push_front(const T &value)
QStringList readListEntry(const QString &scope, const QString &key, const QStringList &def=QStringList(), bool *ok=nullptr) const
Key value accessors.
const_iterator constFind(const Key &key) const
QString layerIsEmbedded(const QString &id) const
Returns project file path if layer is embedded from other project file.
void setSnapSettingsForLayer(const QString &layerId, bool enabled, QgsSnapper::SnappingType type, QgsTolerance::UnitType unit, double tolerance, bool avoidIntersection)
Convenience function to set snap settings per layer.
QDomElement documentElement() const
QString join(const QString &separator) const
void setError(const QString &errorMessage)
Set error message from read/write operation.
QString homePath() const
Return project's home path.
void clear()
Clear project properties when a new project is started.
const_iterator insert(const T &value)
QString & remove(int position, int n)
static void _getTitle(QDomDocument const &doc, QString &title)
Get the project title.
void setDirty(bool b)
Set project as dirty (modified).
void projectSaved()
emitted when the project file has been written and closed
QDomNodeList childNodes() const
bool writeLayerXML(QDomElement &layerElement, QDomDocument &document, const QString &relativeBasePath=QString::null)
Stores state in Dom node.
void loadEmbeddedNodes(QgsLayerTreeGroup *group)
QString tr(const char *sourceText, const char *disambiguation, int n)
QString readPath(QString filename) const
Turn filename read from the project file to an absolute path.
virtual void writeXML(QDomElement &parentElement)=0
Write layer tree to XML.
void clear()
Remove any relation managed by this class.
QgsLayerTreeGroup * toGroup(QgsLayerTreeNode *node)
Cast node to a group. No type checking is done - use isGroup() to find out whether this operation is ...
static QgsProperty * addKey_(QString const &scope, QString const &key, QgsPropertyKey *rootProperty, const QVariant &value)
Add the given key and value.
QString name() const
every key has a name
QDomElement toElement() const
void setPath(const QString &path)
SnappingType
Snap to vertex, to segment or both.
QgsUnitTypes::AreaUnit areaUnits() const
Convenience function to query default area measurement units for project.
const char * name() const
bool writeEntry(const QString &scope, const QString &key, bool value)
QString canonicalFilePath() const
QString readEntry(const QString &scope, const QString &key, const QString &def=QString::null, bool *ok=nullptr) const
QString number(int n, int base)
int count(const T &value) const
bool createEmbeddedLayer(const QString &layerId, const QString &projectFilePath, QList< QDomNode > &brokenNodes, QList< QPair< QgsVectorLayer *, QDomElement > > &vectorLayerList, bool saveFlag=true)
Creates a maplayer instance defined in an arbitrary project file.
bool read()
presuming that the caller has already reset the map canvas, map registry, and legend ...
static QgsProjectVersion _getVersion(QDomDocument const &doc)
Return the version string found in the given Dom document.
void append(const T &value)
void removeKey(const QString &keyName)
remove the given key
QStringList subkeyList(const QString &scope, const QString &key) const
Return keys with keys – do not return keys that contain only values.
void initializeEmbeddedSubtree(const QString &projectFilePath, QgsLayerTreeGroup *group)
QVariant property(const char *name) const
const_iterator constEnd() const
QString canonicalPath() const
int toInt(bool *ok) const
virtual void clearKeys()
delete any sub-nodes
void setAttribute(const QString &name, const QString &value)
A class to describe the version of a project.
QDomNodeList elementsByTagName(const QString &tagname) const
void setBadLayerHandler(QgsProjectBadLayerHandler *handler)
Change handler for missing layers.
QString absoluteFilePath() const
int removeAll(const T &value)
void readProject(const QDomDocument &)
emitted when project is being read
Listens to the updates in map layer registry and does changes in layer tree.
const char * constData() const
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
void setScheme(const QString &scheme)
static void logMessage(const QString &message, const QString &tag=QString::null, MessageLevel level=WARNING)
add a message to the instance (and create it if necessary)
static void replaceChildrenOfEmbeddedGroups(QgsLayerTreeGroup *group)
Remove subtree of embedded groups and replaces it with a custom property embedded-visible-layers.
void variablesChanged()
Emitted whenever the expression variables stored in the project have been changed.
void layerLoaded(int i, int n)
emitted when a layer from a projects was read
QString fileName() const
Returns file name.
This class is a base class for nodes in a layer tree.
QString id() const
Get this layer's unique ID, this ID is used to access this layer from map layer registry.
bool removeEntry(const QString &scope, const QString &key)
Remove the given key.
static void updateEmbeddedGroupsProjectPath(QgsLayerTreeGroup *group)
Reads and writes project states.
qint64 read(char *data, qint64 maxSize)
void setVisible(Qt::CheckState visible)
void writeMapLayer(QgsMapLayer *mapLayer, QDomElement &layerElem, QDomDocument &doc)
Emitted, when a layer is being saved.
QString error() const
Return error message from previous read/write.
QString name() const
Get group's name.
int remove(const Key &key)
QDateTime lastModified() const
QList< QgsLayerTreeNode * > children()
Get list of children of the node. Children are owned by the parent.
void removeCustomProperty(const QString &key)
Remove a custom property from layer.
bool isLayer(QgsLayerTreeNode *node)
Check whether the node is a valid layer node.
bool isValid()
Return the status of the layer.
An Abstract Base Class for QGIS project property hierarchies.
virtual bool open(QFlags< QIODevice::OpenModeFlag > mode)
bool hasChildNodes() const
QgsProperty * find(QString &propertyName)
void insertChildNodes(int index, const QList< QgsLayerTreeNode * > &nodes)
Insert existing nodes at specified position. The nodes must not have a parent yet. The nodes will be owned by this group.
QString toLocalFile() const
QDomText createTextNode(const QString &value)
const T value(const Key &key) const
iterator find(const Key &key)
Class for storing the component parts of a PostgreSQL/RDBMS datasource URI.
void subkeyList(QStringList &entries) const
return keys that contain other keys
QDomNode namedItem(const QString &name) const
QgsLayerTreeGroup * createEmbeddedGroup(const QString &groupName, const QString &projectFilePath, const QStringList &invisibleLayers)
Create layer group instance defined in an arbitrary project file.
int readNumEntry(const QString &scope, const QString &key, int def=0, bool *ok=nullptr) const
bool contains(QChar ch, Qt::CaseSensitivity cs) const
void clearError()
Clear error message.
bool isDirty() const
the dirty flag is true if the project has been modified since the last write()
bool contains(const T &value) const
double readDoubleEntry(const QString &scope, const QString &key, double def=0, bool *ok=nullptr) const
QString & replace(int position, int n, QChar after)
bool addLayer(const QDomElement &layerElem, QList< QDomNode > &brokenNodes, QList< QPair< QgsVectorLayer *, QDomElement > > &vectorLayerList)
Creates layer and adds it to maplayer registry.
QVariant value(const QString &key, const QVariant &defaultValue) const
void setInvalidDataPolicy(InvalidDataPolicy policy)
void writeProject(QDomDocument &)
emitted when project is being written
void oldProjectVersionWarning(const QString &)
emitted when an old project file is read.
virtual QString dump() const override
Return text representation of the tree. For debugging purposes only.
QDomNode firstChild() const
static QgsMapLayerRegistry * instance()
Returns the instance pointer, creating the object on the first call.
QString mid(int position, int n) const
QStringList toStringList() const
virtual QgsLayerTreeGroup * clone() const override
Return a clone of the group. The children are cloned too.
QgsLayerTreeLayer * toLayer(QgsLayerTreeNode *node)
Cast node to a layer. No type checking is done - use isLayer() to find out whether this operation is ...
void insert(int i, const T &value)
This class manages a set of relations between layers.
QStringList findLayerIds() const
Find layer IDs used in all layer nodes. Searches recursively the whole sub-tree.
QgsLayerTreeGroup * findGroup(const QString &name)
Find group node with specified name. Searches recursively the whole sub-tree.
virtual bool atEnd() const
static QgsProject * instance()
access to canonical QgsProject instance
QDomElement firstChildElement(const QString &tagName) const
QString qgsVsiPrefix(const QString &path)
static void removeKey_(QString const &scope, QString const &key, QgsPropertyKey &rootProperty)
void setTitle(const QString &title)
Set project title.
StandardButton critical(QWidget *parent, const QString &title, const QString &text, QFlags< QMessageBox::StandardButton > buttons, StandardButton defaultButton)
const QMap< QString, QgsMapLayer * > & mapLayers()
Retrieve the mapLayers collection (mainly intended for use by projection)
void setEnabled(bool enabled)
bool readXML(QDomNode &keyNode) override
restores property hierarchy to given Dom node
QStringList entryList(const QString &scope, const QString &key) const
Return keys with values – do not return keys that contain other keys.
QgsLayerTreeLayer * findLayer(const QString &layerId) const
Find layer node representing the map layer specified by its ID. Searches recursively the whole sub-tr...
void setQueryItems(const QList< QPair< QString, QString > > &query)
qint64 write(const char *data, qint64 maxSize)
bool readLayerXML(const QDomElement &layerElement)
Sets state from Dom document.
Container class that allows storage of visibility presets consisting of visible map layers and layer ...
int indexOf(const QRegExp &rx, int from) const
void prepend(const T &value)
double toDouble(bool *ok) const
bool readBoolEntry(const QString &scope, const QString &key, bool def=false, bool *ok=nullptr) const
void dumpProperties() const
Dump out current project properties to stderr.
void clearProperties()
removes all project properties
static QgsPluginLayerRegistry * instance()
Means of accessing canonical single instance.
static QStringList makeKeyTokens_(QString const &scope, QString const &key)
Take the given scope and key and convert them to a string list of key tokens that will be used to nav...
void readMapLayer(QgsMapLayer *mapLayer, const QDomElement &layerNode)
Emitted, after the basic initialization of a layer from the project file is done. ...
UnitType
Type of unit of tolerance value from settings.
QFileInfo fileInfo() const
Returns QFileInfo object for the project's associated file.
QgsLayerTreeGroup * layerTreeRoot() const
Return pointer to the root (invisible) node of the project's layer tree.
Default bad layer handler which ignores any missing layers.
QString uri(bool expandAuthConfig=true) const
return complete uri
virtual bool isKey() const =0
Returns true if is a QgsPropertyKey.
QDomDocumentType createDocumentType(const QString &qName, const QString &publicId, const QString &systemId)
QgsVisibilityPresetCollection * visibilityPresetCollection()
Returns pointer to the project's visibility preset collection.
Represents a vector layer which manages a vector based data sets.
int compare(const QString &other) const
QgsRelationManager * relationManager() const
bool isGroup(QgsLayerTreeNode *node)
Check whether the node is a valid group node.
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
bool removeOne(const T &value)
virtual bool isValue() const =0
Returns true if is a QgsPropertyValue.
static void dump_(QgsPropertyKey const &topQgsPropertyKey)
QgsPluginLayer * createLayer(const QString &typeName, const QString &uri=QString())
Return new layer if corresponding plugin has been found, else return NULL.
QUrl fromEncoded(const QByteArray &input)
QByteArray toEncoded(QFlags< QUrl::FormattingOption > options) const
void clear()
Clear the project.
Interface for classes that handle missing layer files when reading project file.
QUrl fromLocalFile(const QString &localFile)
Layer tree node points to a map layer.
void setCustomProperty(const QString &key, const QVariant &value)
Set a custom property for the node.
QDomNode at(int index) const
bool setContent(const QByteArray &data, bool namespaceProcessing, QString *errorMsg, int *errorLine, int *errorColumn)
void dump(int tabs=0) const override
Dumps out the keys and values.
const T value(const Key &key) const
void snapSettingsChanged()
QByteArray toUtf8() const