44 #include <QApplication> 48 #include <QTextStream> 49 #include <QTemporaryFile> 57 #include <sys/utime.h> 74 keyTokens += key.
split(
'/', QString::SkipEmptyParts );
80 for (
int i = 0; i < keyTokens.
size(); ++i )
86 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]" );
87 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]" );
92 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;
200 while ( ! keySequence.
isEmpty() )
204 if ( keySequence.
first() == currentProperty->
name() )
211 if ( 1 == keySequence.
count() )
214 return currentProperty;
218 else if ( keySequence.
isEmpty() )
222 return currentProperty;
224 else if (( nextProperty = currentProperty->
find( keySequence.
first() ) ) )
228 if ( currentProperty )
239 if (( newPropertyKey = currentProperty->
addKey( keySequence.
first() ) ) )
241 currentProperty = newPropertyKey;
268 while ( ! keySequence.
isEmpty() )
272 if ( keySequence.
first() == currentProperty->
name() )
279 if ( 1 == keySequence.
count() )
286 else if ( keySequence.
isEmpty() )
288 previousQgsPropertyKey->
removeKey( currentProperty->
name() );
290 else if (( nextProperty = currentProperty->
find( keySequence.
first() ) ) )
292 previousQgsPropertyKey = currentProperty;
295 if ( currentProperty )
331 , autoTransaction( false )
332 , evaluateDefaultValues( false )
337 properties_.
name() =
"properties";
349 autoTransaction =
false;
350 evaluateDefaultValues =
false;
357 QgsProject::QgsProject()
376 delete mBadLayerHandler;
377 delete mRelationManager;
422 if ( name == imp_->file.fileName() )
427 imp_->file.setFileName( name );
431 if ( newHomePath != oldHomePath )
439 return imp_->file.fileName();
450 mEmbeddedLayers.clear();
451 mRelationManager->clear();
455 mRootGroup->removeAllChildren();
459 writeEntry(
"PositionPrecision",
"/Automatic",
true );
460 writeEntry(
"PositionPrecision",
"/DecimalPlaces", 2 );
475 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" );
567 if ( !titleTextNode.
isText() )
575 title = titleText.
data();
585 QgsDebugMsg(
" unable to find qgis element in project file" );
593 return projectVersion;
614 if ( 0 == nl.
count() )
624 bool returnStatus =
true;
630 if ( depSorter.hasCycle() || depSorter.hasMissingDependency() )
639 Q_FOREACH (
const QDomNode& node, sortedLayerNodes )
647 if ( element.
attribute(
"embedded" ) ==
"1" )
654 if ( !
addLayer( element, brokenNodes, vLayerList ) )
656 returnStatus =
false;
666 for ( ; vIt != vLayerList.
end(); ++vIt )
668 processLayerJoins( vIt->
first );
672 for ( vIt = vLayerList.
begin(); vIt != vLayerList.
end(); ++vIt )
677 notified << vIt->
first;
690 if ( type ==
"vector" )
694 else if ( type ==
"raster" )
698 else if ( type ==
"plugin" )
711 Q_CHECK_PTR( mapLayer );
721 vectorLayerList.push_back( qMakePair( vLayer, layerElem ) );
724 myLayers << mapLayer;
733 QgsDebugMsg(
"Unable to load " + type +
" layer" );
741 imp_->file.setFileName( file.
filePath() );
752 if ( !imp_->file.open( QIODevice::ReadOnly | QIODevice::Text ) )
756 setError(
tr(
"Unable to open %1" ).arg( imp_->file.fileName() ) );
765 if ( !doc->setContent( &imp_->file, &errorMsg, &line, &column ) )
770 tr(
"%1 at line %2 column %3" ).arg( errorMsg ).arg( line ).arg( column ) );
773 QString errorString =
tr(
"Project file read error: %1 at line %2 column %3" )
774 .
arg( errorMsg ).
arg( line ).
arg( column );
780 setError(
tr(
"%1 for file %2" ).arg( errorString, imp_->file.fileName() ) );
788 QgsDebugMsg(
"Opened document " + imp_->file.fileName() );
795 if ( thisVersion > fileVersion )
798 "version of qgis (saved in " + fileVersion.
text() +
800 "). Problems may occur." );
806 QgsDebugMsg(
"Emitting oldProjectVersionWarning(oldVersion)." );
808 projectFile.updateRevision( thisVersion );
814 imp_->file.setFileName( fileName );
821 dump_( imp_->properties_ );
826 QDomNodeList nl = doc->elementsByTagName(
"autotransaction" );
831 imp_->autoTransaction =
true;
834 nl = doc->elementsByTagName(
"evaluateDefaultValues" );
838 if ( evaluateDefaultValuesElement.
attribute(
"active",
"0" ).
toInt() == 1 )
839 imp_->evaluateDefaultValues =
true;
844 mRootGroup->setCustomProperty(
"loading", 1 );
846 QDomElement layerTreeElem = doc->documentElement().firstChildElement(
"layer-tree-group" );
847 if ( !layerTreeElem.
isNull() )
849 mRootGroup->readChildrenFromXML( layerTreeElem );
856 QgsDebugMsg(
"Loaded layer tree:\n " + mRootGroup->dump() );
858 mLayerTreeRegistryBridge->setEnabled(
false );
862 bool clean = _getMapLayers( *doc, brokenNodes );
867 QgsDebugMsg(
"Unable to get map layers from project file." );
876 mBadLayerHandler->handleBadLayers( brokenNodes, *doc );
879 mLayerTreeRegistryBridge->setEnabled(
true );
887 mRootGroup->removeCustomProperty(
"loading" );
890 mVisibilityPresetCollection->readXML( *doc );
924 clonedChildren << newGroupChild->
clone();
967 mTransactionGroups.insert( qMakePair( key, connString ), tg );
981 void QgsProject::cleanTransactionGroups(
bool force )
985 if ( tg.value()->isEmpty() || force )
988 tg = mTransactionGroups.erase( tg );
1008 processLayerJoins( layer );
1011 if ( !vectorLayerList.
isEmpty() )
1013 emit
readMapLayer( vectorLayerList.
at( 0 ).first, vectorLayerList.
at( 0 ).second );
1023 imp_->file.setFileName( file.
filePath() );
1038 setError(
tr(
"%1 is not writable. Please adjust permissions (if possible) and try again." )
1039 .arg( imp_->file.fileName() ) );
1051 QDomElement qgisNode = doc->createElement(
"qgis" );
1055 doc->appendChild( qgisNode );
1058 QDomElement titleNode = doc->createElement(
"title" );
1061 QDomElement transactionNode = doc->createElement(
"autotransaction" );
1062 transactionNode.
setAttribute(
"active", imp_->autoTransaction ?
"1" :
"0" );
1065 QDomElement evaluateDefaultValuesNode = doc->createElement(
"evaluateDefaultValues" );
1066 evaluateDefaultValuesNode.
setAttribute(
"active", imp_->evaluateDefaultValues ?
"1" :
"0" );
1067 qgisNode.
appendChild( evaluateDefaultValuesNode );
1087 QDomElement projectLayersNode = doc->createElement(
"projectlayers" );
1090 while ( li != layers.
end() )
1097 if ( emIt == mEmbeddedLayers.
constEnd() )
1100 QDomElement maplayerElem = doc->createElement(
"maplayer" );
1112 if ( emIt.
value().second )
1114 QDomElement mapLayerElem = doc->createElement(
"maplayer" );
1129 dump_( imp_->properties_ );
1131 QgsDebugMsg(
QString(
"there are %1 property scopes" ).arg( static_cast<int>( imp_->properties_.count() ) ) );
1133 if ( !imp_->properties_.isEmpty() )
1136 imp_->properties_.writeXML(
"properties", qgisNode, *doc );
1139 mVisibilityPresetCollection->writeXML( *doc );
1149 ok &= backupFile.
open( QIODevice::WriteOnly | QIODevice::Truncate );
1150 ok &= imp_->file.open( QIODevice::ReadOnly );
1153 while ( ok && !imp_->file.atEnd() )
1155 ba = imp_->file.read( 10240 );
1156 ok &= backupFile.
write( ba ) == ba.
size();
1173 if ( !imp_->file.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
1178 setError(
tr(
"Unable to save to file %1" ).arg( imp_->file.fileName() ) );
1183 bool ok = tempFile.
open();
1187 doc->save( projectFileStream, 2 );
1188 ok &= projectFileStream.
pos() > -1;
1190 ok &= tempFile.
seek( 0 );
1193 while ( ok && !tempFile.
atEnd() )
1195 ba = tempFile.
read( 10240 );
1196 ok &= imp_->file.write( ba ) == ba.
size();
1199 ok &= imp_->file.error() == QFile::NoError;
1208 setError(
tr(
"Unable to save to file %1. Your project " 1209 "may be corrupted on disk. Try clearing some space on the volume and " 1210 "check file permissions before pressing save again." )
1211 .arg( imp_->file.fileName() ) );
1233 return addKey_( scope, key, &imp_->properties_, value );
1241 return addKey_( scope, key, &imp_->properties_, value );
1248 return addKey_( scope, key, &imp_->properties_, value );
1256 return addKey_( scope, key, &imp_->properties_, value );
1264 return addKey_( scope, key, &imp_->properties_, value );
1278 value =
property->
value();
1280 bool valid = QVariant::StringList == value.
type();
1305 value =
property->
value();
1307 bool valid = value.
canConvert( QVariant::String );
1327 value =
property->
value();
1330 bool valid = value.
canConvert( QVariant::String );
1339 return value.
toInt();
1354 bool valid = value.
canConvert( QVariant::Double );
1374 bool valid = value.
canConvert( QVariant::Bool );
1392 return !
findKey_( scope, key, imp_->properties_ );
1402 if ( foundProperty )
1419 if ( foundProperty )
1432 dump_( imp_->properties_ );
1448 if ( src.
startsWith(
"/vsi", Qt::CaseInsensitive ) )
1457 #if defined(Q_OS_WIN) 1460 ( src[0].isLetter() && src[1] ==
':' ) )
1463 return vsiPrefix + src;
1466 if ( src[0] ==
'/' )
1469 return vsiPrefix + src;
1479 return vsiPrefix + src;
1485 return vsiPrefix + src;
1496 if ( !relativeBasePath.
isNull() )
1498 projPath = relativeBasePath;
1503 return vsiPrefix + src;
1506 #if defined(Q_OS_WIN) 1508 projPath.
replace(
'\\',
'/' );
1516 #if defined(Q_OS_WIN) 1519 projElems.
insert( 0,
"" );
1520 projElems.
insert( 0,
"" );
1528 projElems << srcElems;
1533 while (( pos = projElems.
indexOf(
".." ) ) > 0 )
1540 #if !defined(Q_OS_WIN) 1545 return vsiPrefix + projElems.
join(
"/" );
1560 if ( !relativeBasePath.
isNull() )
1562 projPath = relativeBasePath;
1577 #if defined( Q_OS_WIN ) 1578 const Qt::CaseSensitivity cs = Qt::CaseInsensitive;
1585 srcPath =
"\\\\" + srcPath.
mid( 2 );
1588 projPath.
replace(
'\\',
'/' );
1592 projPath =
"\\\\" + projPath.
mid( 2 );
1595 const Qt::CaseSensitivity cs = Qt::CaseSensitive;
1609 while ( !srcElems.
isEmpty() &&
1611 srcElems[0].compare( projElems[0], cs ) == 0 )
1627 for (
int i = 0; i < projElems.
size(); i++ )
1629 srcElems.
insert( 0,
".." );
1636 srcElems.
insert( 0,
"." );
1639 return vsiPrefix + srcElems.
join(
"/" );
1644 mErrorMessage = errorMessage;
1649 return mErrorMessage;
1659 delete mBadLayerHandler;
1660 mBadLayerHandler = handler;
1666 if ( it == mEmbeddedLayers.
constEnd() )
1670 return it.
value().first;
1678 static QString prevProjectFilePath;
1679 static QDateTime prevProjectFileTimestamp;
1684 if ( projectFilePath != prevProjectFilePath || projectFileTimestamp != prevProjectFileTimestamp )
1686 prevProjectFilePath.
clear();
1688 QFile projectFile( projectFilePath );
1689 if ( !projectFile.
open( QIODevice::ReadOnly ) )
1694 if ( !projectDocument.
setContent( &projectFile ) )
1699 prevProjectFilePath = projectFilePath;
1700 prevProjectFileTimestamp = projectFileTimestamp;
1704 bool useAbsolutePathes =
true;
1707 if ( !propertiesElem.
isNull() )
1712 useAbsolutePathes = absElem.
text().
compare(
"true", Qt::CaseInsensitive ) == 0;
1717 if ( projectLayersElem.
isNull() )
1723 for (
int i = 0; i < mapLayerNodes.
size(); ++i )
1728 if (
id == layerId )
1731 if ( mapLayerElem.
attribute(
"embedded" ) ==
"1" )
1736 mEmbeddedLayers.
insert( layerId, qMakePair( projectFilePath, saveFlag ) );
1740 if ( !useAbsolutePathes )
1744 QString datasource( dsElem.text() );
1745 if ( provider ==
"spatialite" )
1749 if ( absoluteDs.exists() )
1752 datasource = uri.
uri();
1755 else if ( provider ==
"ogr" )
1757 QStringList theURIParts( datasource.split(
'|' ) );
1758 QFileInfo absoluteDs(
QFileInfo( projectFilePath ).absolutePath() +
'/' + theURIParts[0] );
1759 if ( absoluteDs.exists() )
1761 theURIParts[0] = absoluteDs.absoluteFilePath();
1762 datasource = theURIParts.join(
"|" );
1765 else if ( provider ==
"gpx" )
1767 QStringList theURIParts( datasource.split(
'?' ) );
1768 QFileInfo absoluteDs(
QFileInfo( projectFilePath ).absolutePath() +
'/' + theURIParts[0] );
1769 if ( absoluteDs.exists() )
1771 theURIParts[0] = absoluteDs.absoluteFilePath();
1772 datasource = theURIParts.join(
"?" );
1775 else if ( provider ==
"delimitedtext" )
1779 if ( !datasource.startsWith(
"file:" ) )
1787 if ( absoluteDs.exists() )
1796 QFileInfo absoluteDs(
QFileInfo( projectFilePath ).absolutePath() +
'/' + datasource );
1797 if ( absoluteDs.
exists() )
1803 dsElem.removeChild( dsElem.childNodes().at( 0 ) );
1804 dsElem.appendChild( projectDocument.
createTextNode( datasource ) );
1807 if (
addLayer( mapLayerElem, brokenNodes, vectorLayerList ) )
1813 mEmbeddedLayers.
remove( layerId );
1826 QFile projectFile( projectFilePath );
1827 if ( !projectFile.
open( QIODevice::ReadOnly ) )
1833 if ( !projectDocument.
setContent( &projectFile ) )
1841 if ( !disabledLayersElem.
isNull() )
1844 for (
int i = 0; i < valueList.
size(); ++i )
1853 if ( !layerTreeElem.
isNull() )
1863 if ( !group || group->customProperty(
"embedded" ).toBool() )
1879 mLayerTreeRegistryBridge->setEnabled(
false );
1881 mLayerTreeRegistryBridge->setEnabled(
true );
1888 if ( embeddedIdentifyDisabledLayers.
contains( layerId ) )
1890 thisProjectIdentifyDisabledLayers.
append( layerId );
1896 layer->
setVisible( invisibleLayers.
contains( layerId ) ? Qt::Unchecked : Qt::Checked );
1928 QStringList layerIdList, enabledList, snapTypeList, toleranceUnitList, toleranceList, avoidIntersectionList;
1929 snapSettings( layerIdList, enabledList, snapTypeList, toleranceUnitList, toleranceList, avoidIntersectionList );
1930 int idx = layerIdList.
indexOf( layerId );
1938 avoidIntersectionList.
removeOne( layerId );
1941 layerIdList.
append( layerId );
1944 enabledList.
append( enabled ?
"enabled" :
"disabled" );
1950 typeString =
"to_segment";
1954 typeString =
"to_vertex_and_segment";
1958 typeString =
"to_vertex";
1960 snapTypeList.
append( typeString );
1969 if ( avoidIntersection )
1971 avoidIntersectionList.
append( layerId );
1974 writeEntry(
"Digitizing",
"/LayerSnappingList", layerIdList );
1975 writeEntry(
"Digitizing",
"/LayerSnappingEnabledList", enabledList );
1976 writeEntry(
"Digitizing",
"/LayerSnappingToleranceList", toleranceList );
1977 writeEntry(
"Digitizing",
"/LayerSnappingToleranceUnitList", toleranceUnitList );
1978 writeEntry(
"Digitizing",
"/LayerSnapToList", snapTypeList );
1979 writeEntry(
"Digitizing",
"/AvoidIntersectionsList", avoidIntersectionList );
1984 bool &avoidIntersection )
const 1986 QStringList layerIdList, enabledList, snapTypeList, toleranceUnitList, toleranceList, avoidIntersectionList;
1987 snapSettings( layerIdList, enabledList, snapTypeList, toleranceUnitList, toleranceList, avoidIntersectionList );
1988 int idx = layerIdList.
indexOf( layerId );
1995 int minListEntries = idx + 1;
1996 if ( layerIdList.
size() < minListEntries || enabledList.
size() < minListEntries || snapTypeList.
size() < minListEntries ||
1997 toleranceUnitList.
size() < minListEntries || toleranceList.
size() < minListEntries )
2003 enabled = enabledList.
at( idx ) ==
"enabled";
2006 QString snapType = snapTypeList.
at( idx );
2007 if ( snapType ==
"to_segment" )
2011 else if ( snapType ==
"to_vertex_and_segment" )
2021 if ( toleranceUnitList.
at( idx ) ==
"1" )
2025 else if ( toleranceUnitList.
at( idx ) ==
"2" )
2035 tolerance = toleranceList.
at( idx ).toDouble();
2038 avoidIntersection = ( avoidIntersectionList.
indexOf( layerId ) != -1 );
2046 layerIdList =
readListEntry(
"Digitizing",
"/LayerSnappingList" );
2047 enabledList =
readListEntry(
"Digitizing",
"/LayerSnappingEnabledList" );
2048 toleranceList =
readListEntry(
"Digitizing",
"/LayerSnappingToleranceList" );
2049 toleranceUnitList =
readListEntry(
"Digitizing",
"/LayerSnappingToleranceUnitList" );
2050 snapTypeList =
readListEntry(
"Digitizing",
"/LayerSnapToList" );
2051 avoidIntersectionList =
readListEntry(
"Digitizing",
"/AvoidIntersectionsList" );
2056 return imp_->evaluateDefaultValues;
2087 if ( !distanceUnitString.
isEmpty() )
2100 if ( !areaUnitString.
isEmpty() )
2119 return QString::null;
2126 return mRelationManager;
2136 return mVisibilityPresetCollection.data();
2146 newLayers << l->
id();
2149 if ( newLayers == currentLayers )
2156 disabledLayerIds << l->
id();
2164 writeEntry(
"Identify",
"/disabledLayers", layerIds );
2176 return imp_->autoTransaction;
2181 if ( autoTransaction != imp_->autoTransaction )
2185 if ( autoTransaction )
2188 cleanTransactionGroups(
true );
2194 return mTransactionGroups;
QObject * child(const char *objName, const char *inheritsClass, bool recursiveSearch) const
bool canConvert(Type t) const
void updateFields()
Assembles mUpdatedFields considering provider fields, joined fields and added fields.
Layer tree group node serves as a container for layers and further groups.
void setDirty(bool b=true)
Flag the project as dirty (modified).
QString fromAscii(const char *str, int size)
QDomNodeList elementsByTagName(const QString &tagname) const
virtual void handleBadLayers(const QList< QDomNode > &layers, const QDomDocument &projectDom) override
QString error() const
Return error message from previous read/write.
bool isDirty() const
Returns true if the project has been modified since the last write()
Base class for all map layer types.
void setNonIdentifiableLayers(QList< QgsMapLayer *> layers)
Set a list of layers which should not be taken into account on map identification.
virtual bool seek(qint64 pos)
static void removeInvalidLayers(QgsLayerTreeGroup *group)
Remove layer nodes that refer to invalid layers.
QDomNode item(int index) const
QString readEntry(const QString &scope, const QString &key, const QString &def=QString::null, bool *ok=nullptr) const
void loadingLayer(const QString &)
QgsPropertyKey properties_
QgsPropertyKey * addKey(const QString &keyName)
add the given property key
void setTopologicalEditing(bool enabled)
Convenience function to set topological editing.
bool readBoolEntry(const QString &scope, const QString &key, bool def=false, bool *ok=nullptr) const
QDomNode appendChild(const QDomNode &newChild)
QDateTime lastRead() const
void push_back(const T &value)
QString attribute(const QString &name, const QString &defValue) const
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.
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)
Sets the file name associated with the project.
UnitType
Type of unit of tolerance value from settings.
void setFileName(const QString &name)
void push_front(const T &value)
QMap< QString, QgsMapLayer * > mapLayers() const
Returns a map of all registered layers by layer ID.
const_iterator constFind(const Key &key) const
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
QgsLayerTreeGroup * layerTreeRoot() const
Return pointer to the root (invisible) node of the project's layer tree.
QString join(const QString &separator) const
void setError(const QString &errorMessage)
Set error message from read/write operation.
void clear()
Clear project properties when a new project is started.
const_iterator insert(const T &value)
QString & remove(int position, int n)
QgsRelationManager * relationManager() const
const QList< QgsVectorJoinInfo > vectorJoins() const
bool readLayerXML(const QDomElement &layerElement, const QString &relativeBasePath=QString())
Sets state from Dom document.
void projectSaved()
emitted when the project file has been written and closed
QDomNodeList childNodes() const
QStringList nonIdentifiableLayers() const
Get the list of layers which currently should not be taken into account on map identification.
void loadEmbeddedNodes(QgsLayerTreeGroup *group)
QString tr(const char *sourceText, const char *disambiguation, int n)
virtual void writeXML(QDomElement &parentElement)=0
Write layer tree to XML.
QVector< T > layers() const
Returns a list of registered map layers with a specified layer type.
int readNumEntry(const QString &scope, const QString &key, int def=0, bool *ok=nullptr) const
QgsLayerTreeGroup * toGroup(QgsLayerTreeNode *node)
Cast node to a group. No type checking is done - use isGroup() to find out whether this operation is ...
QgsProjectVersion getVersion(const QDomDocument &doc)
Return the version string found in the given DOM document.
void fileNameChanged()
Emitted when the file name of the project changes.
QDomElement toElement() const
void setPath(const QString &path)
SnappingType
Snap to vertex, to segment or both.
const char * name() const
bool writeEntry(const QString &scope, const QString &key, bool value)
QGis::UnitType distanceUnits() const
Convenience function to query default distance measurement units for project.
QString canonicalFilePath() 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()
Reads the current project file.
void append(const T &value)
QString id() const
Get this layer's unique ID, this ID is used to access this layer from map layer registry.
bool evaluateDefaultValues() const
Should default values be evaluated on provider side when requested and not when committed.
void removeKey(const QString &keyName)
remove the given key
QString & insert(int position, QChar ch)
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
Pixels unit of tolerance.
static void _getTitle(const QDomDocument &doc, QString &title)
Get the project title.
QList< QgsMapLayer * > addMapLayers(const QList< QgsMapLayer *> &theMapLayers, bool addToLegend=true, bool takeOwnership=true)
Add a list of layers to the map of loaded layers.
QgsUnitTypes::AreaUnit areaUnits() const
Convenience function to query default area measurement units for project.
QString database() const
Returns the database.
virtual void clearKeys()
delete any sub-nodes
void setAttribute(const QString &name, const QString &value)
A class to describe the version of a project.
QString layerIsEmbedded(const QString &id) const
Returns project file path if layer is embedded from other project file.
int toInt(bool *ok, int base) const
QDomNodeList elementsByTagName(const QString &tagname) const
void setBadLayerHandler(QgsProjectBadLayerHandler *handler)
Change handler for missing layers.
void dumpProperties() const
Dump out current project properties to stderr.
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 addLayer(QgsVectorLayer *layer)
Add a layer to this transaction group.
QVariant customProperty(const QString &key, const QVariant &defaultValue=QVariant()) const
Read a custom property from layer.
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
QStringList subkeyList(const QString &scope, const QString &key) const
Return keys with keys – do not return keys that contain only values.
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
QStringList readListEntry(const QString &scope, const QString &key, const QStringList &def=QStringList(), bool *ok=nullptr) const
Key value accessors.
This class is a base class for nodes in a layer tree.
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 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.
static bool supportsTransaction(const QgsVectorLayer *layer)
Checks if a the provider of a give layer supports transactions.
QString uri(bool expandAuthConfig=true) const
return complete uri
bool evaluateDefaultValues
void writeMapLayer(QgsMapLayer *mapLayer, QDomElement &layerElem, QDomDocument &doc)
Emitted, when a layer is being saved.
QDateTime lastModified() const
QList< QgsLayerTreeNode * > children()
Get list of children of the node. Children are owned by the parent.
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
static QString QGIS_VERSION
void subkeyList(QStringList &entries) const
return keys that contain other keys
void setProviderProperty(ProviderProperty property, const QVariant &value)
Allows setting arbitrary properties on the provider.
QgsProperty * find(QString &propertyName)
bool write()
Writes the project to its current associated file (see fileName() ).
QString toLocalFile() const
QDomText createTextNode(const QString &value)
const T value(const Key &key) const
iterator find(const Key &key)
QStringList makeKeyTokens_(const QString &scope, const QString &key)
Take the given scope and key and convert them to a string list of key tokens that will be used to nav...
Class for storing the component parts of a PostgreSQL/RDBMS datasource URI.
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.
bool contains(QChar ch, Qt::CaseSensitivity cs) const
void clearError()
Clear error message.
bool topologicalEditing() const
Convenience function to query topological editing status.
QString homePath() const
Return project's home path.
QString fileName() const
Returns the project's file name.
bool contains(const T &value) const
QgsLayerTreeLayer * findLayer(const QString &layerId) const
Find layer node representing the map layer specified by its ID. Searches recursively the whole sub-tr...
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.
void _getProperties(const QDomDocument &doc, QgsPropertyKey &project_properties)
Restore any optional properties found in "doc" to "properties".
QString & replace(int position, int n, QChar after)
bool writeLayerXML(QDomElement &layerElement, QDomDocument &document, const QString &relativeBasePath=QString())
Stores state in Dom node.
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.
QFileInfo fileInfo() const
Returns QFileInfo object for the project's associated file.
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
bool autoTransaction() const
Transactional editing means that on supported datasources (postgres databases) the edit state of all ...
void setAutoTransaction(bool autoTransaction)
Transactional editing means that on supported datasources (postgres databases) the edit state of all ...
QString source() const
Returns the source for the layer.
QgsLayerTreeLayer * toLayer(QgsLayerTreeNode *node)
Cast node to a layer. No type checking is done - use isLayer() to find out whether this operation is ...
QMap< QPair< QString, QString >, QgsTransactionGroup * > transactionGroups()
Map of transaction groups.
void dump_(const QgsPropertyKey &topQgsPropertyKey)
QString name() const
every key has a name
void insert(int i, const T &value)
This class manages a set of relations between layers.
void nonIdentifiableLayersChanged(QStringList nonIdentifiableLayers)
Emitted when the list of layer which are excluded from map identification changes.
QgsProperty * addKey_(const QString &scope, const QString &key, QgsPropertyKey *rootProperty, const QVariant &value)
Add the given key and value.
QgsLayerTreeGroup * findGroup(const QString &name)
Find group node with specified name. Searches recursively the whole sub-tree.
QString readPath(QString filename, const QString &relativeBasePath=QString()) const
Turn filename read from the project file to an absolute path.
virtual bool atEnd() const
static QgsProject * instance()
Returns the QgsProject singleton instance.
QDomElement firstChildElement(const QString &tagName) const
QString qgsVsiPrefix(const QString &path)
void setTitle(const QString &title)
Sets the project's title.
StandardButton critical(QWidget *parent, const QString &title, const QString &text, QFlags< QMessageBox::StandardButton > buttons, StandardButton defaultButton)
void entryList(QStringList &entries) const
return keys that do not contain other keys
UnitType
Map units that qgis supports.
bool readXML(QDomNode &keyNode) override
restores property hierarchy to given Dom node
void setQueryItems(const QList< QPair< QString, QString > > &query)
qint64 write(const char *data, qint64 maxSize)
Container class that allows storage of visibility presets consisting of visible map layers and layer ...
void homePathChanged()
Emitted when the home path of the project changes.
double readDoubleEntry(const QString &scope, const QString &key, double def=0, bool *ok=nullptr) const
int indexOf(const QRegExp &rx, int from) const
void prepend(const T &value)
double toDouble(bool *ok) const
QString name() const override
Get group's name.
QStringList findLayerIds() const
Find layer IDs used in all layer nodes. Searches recursively the whole sub-tree.
Q_DECL_DEPRECATED void clearProperties()
Removes all project properties.
static QgsPluginLayerRegistry * instance()
Means of accessing canonical single instance.
QString title() const
Returns the project's title.
QgsVectorDataProvider * dataProvider()
Returns the data provider.
void readMapLayer(QgsMapLayer *mapLayer, const QDomElement &layerNode)
Emitted, after the basic initialization of a layer from the project file is done. ...
QString providerType() const
Return the provider type for this layer.
void readChildrenFromXML(QDomElement &element, bool looseMatch=false)
Read children from XML and append them to the group.
QgsProperty * findKey_(const QString &scope, const QString &key, QgsPropertyKey &rootProperty)
return the property that matches the given key sequence, if any
Default bad layer handler which ignores any missing layers.
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
virtual bool isKey() const =0
Returns true if is a QgsPropertyKey.
void setEvaluateDefaultValues(bool evaluateDefaultValues)
Defines if default values should be evaluated on provider side when requested and not when committed...
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.
void removeKey_(const QString &scope, const QString &key, QgsPropertyKey &rootProperty)
int compare(const QString &other) 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.
Evaluate default values on provider side when calling QgsVectorDataProvider::defaultValue( int index ...
QStringList entryList(const QString &scope, const QString &key) const
Return keys with values – do not return keys that contain other keys.
QgsPluginLayer * createLayer(const QString &typeName, const QString &uri=QString())
Return new layer if corresponding plugin has been found, else return NULL.
void createJoinCaches()
Caches joined attributes if required (and not already done)
QUrl fromEncoded(const QByteArray &input)
QByteArray toEncoded(QFlags< QUrl::FormattingOption > options) const
void clear()
Clear the project - removes all settings and resets it back to an empty, default state.
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.
bool setContent(const QByteArray &data, bool namespaceProcessing, QString *errorMsg, int *errorLine, int *errorColumn)
QDomNode at(int index) const
void dump(int tabs=0) const override
Dumps out the keys and values.
const T value(const Key &key) const
QString writePath(const QString &filename, const QString &relativeBasePath=QString()) const
Prepare a filename to save it to the project file.
void snapSettingsChanged()
QByteArray toUtf8() const