QGIS API Documentation
3.16.0-Hannover (43b64b13f3)
|
Go to the documentation of this file.
30 #include <QPainterPath>
32 #include <QProgressDialog>
36 #include <QStringBuilder>
38 #include <QUndoCommand>
106 #ifdef TESTPROVIDERLIB
112 const QString &qmlStyle,
113 const QString &sldStyle,
114 const QString &styleName,
115 const QString &styleDescription,
116 const QString &uiFileContent,
130 QStringList &descriptions,
148 const QString &baseName,
149 const QString &providerKey,
154 , mAuxiliaryLayer( nullptr )
155 , mAuxiliaryLayerKey( QString() )
156 , mReadExtentFromXml( options.readExtentFromXml )
166 mGeometryOptions = qgis::make_unique<QgsGeometryOptions>();
170 mStoredExpressionManager->setParent(
this );
173 mJoinBuffer->setParent(
this );
178 if ( !vectorLayerPath.isEmpty() && !
mProviderKey.isEmpty() )
186 mAttributeAliasMap.insert(
field.
name(), QString() );
192 if ( !mTemporalProperties->
isActive() )
209 mSimplifyMethod.
setThreshold( settings.
value( QStringLiteral(
"qgis/simplifyDrawingTol" ), mSimplifyMethod.
threshold() ).toFloat() );
221 delete mDataProvider;
224 delete mExpressionFieldBuffer;
226 delete mDiagramLayerSettings;
227 delete mDiagramRenderer;
232 delete mConditionalStyles;
233 delete mStoredExpressionManager;
235 if ( mFeatureCounter )
236 mFeatureCounter->
cancel();
262 QList<QgsVectorLayerJoinInfo> joins =
vectorJoins();
263 const auto constJoins = joins;
283 for (
const QgsAction &action : constActions )
320 auto constraintIt = constraints.constBegin();
321 for ( ; constraintIt != constraints.constEnd(); ++ constraintIt )
397 p.setPen( QColor( 50, 100, 120, 200 ) );
398 p.setBrush( QColor( 200, 200, 210, 120 ) );
399 p.drawEllipse( x - m, y - m, m * 2 + 1, m * 2 + 1 );
403 p.setPen( QColor( 255, 0, 0 ) );
404 p.drawLine( x - m, y + m, x + m, y - m );
405 p.drawLine( x - m, y - m, x + m, y + m );
411 mSelectedFeatureIds.insert( fid );
412 mPreviousSelectedFeatureIds.clear();
419 mSelectedFeatureIds.unite( featureIds );
420 mPreviousSelectedFeatureIds.clear();
427 mSelectedFeatureIds.remove( fid );
428 mPreviousSelectedFeatureIds.clear();
435 mSelectedFeatureIds.subtract( featureIds );
436 mPreviousSelectedFeatureIds.clear();
449 .setFilterRect( rect )
451 .setNoAttributes() );
456 newSelection << feat.
id();
485 newSelection << feat.
id();
507 bool matches = exp.
evaluate( &context ).toBool();
511 newSelection << feat.
id();
515 newSelection << feat.
id();
534 newSelection = mSelectedFeatureIds + ids;
538 newSelection = mSelectedFeatureIds - ids;
542 newSelection = mSelectedFeatureIds.intersect( ids );
546 QgsFeatureIds deselectedFeatures = mSelectedFeatureIds - newSelection;
547 mSelectedFeatureIds = newSelection;
548 mPreviousSelectedFeatureIds.clear();
556 if ( !intersectingIds.isEmpty() )
558 QgsDebugMsgLevel( QStringLiteral(
"Trying to select and deselect the same item at the same time. Unsure what to do. Selecting dubious items." ), 3 );
561 mSelectedFeatureIds -= deselectIds;
562 mSelectedFeatureIds += selectIds;
563 mPreviousSelectedFeatureIds.clear();
571 ids.subtract( mSelectedFeatureIds );
586 .setFilterRect( rect )
588 .setNoAttributes() );
596 if ( mSelectedFeatureIds.contains( fet.
id() ) )
598 deselectIds << fet.
id();
602 selectIds << fet.
id();
611 if ( mSelectedFeatureIds.isEmpty() )
616 mPreviousSelectedFeatureIds = previous;
621 if ( mPreviousSelectedFeatureIds.isEmpty() || !mSelectedFeatureIds.empty() )
629 return mDataProvider;
634 return mDataProvider;
639 return mTemporalProperties;
644 if (
isValid() && mDataProvider && mDataProvider->
encoding() != encoding )
653 delete mDiagramRenderer;
654 mDiagramRenderer = r;
671 if ( !
isValid() || !
isSpatial() || mSelectedFeatureIds.isEmpty() || !mDataProvider )
683 .setFilterFids( mSelectedFeatureIds )
684 .setNoAttributes() );
697 .setNoAttributes() );
701 if ( mSelectedFeatureIds.contains( fet.
id() ) )
712 if ( retval.
width() == 0.0 || retval.
height() == 0.0 )
721 retval.
set( -1.0, -1.0, 1.0, 1.0 );
730 return mLabelsEnabled &&
static_cast< bool >( mLabeling );
735 mLabelsEnabled = enabled;
740 if ( !mDiagramRenderer || !mDiagramLayerSettings )
743 QList<QgsDiagramSettings> settingList = mDiagramRenderer->
diagramSettings();
744 if ( !settingList.isEmpty() )
746 return settingList.at( 0 ).enabled;
753 if ( !mSymbolFeatureCounted )
756 return mSymbolFeatureCountMap.value( legendKey, -1 );
761 if ( !mSymbolFeatureCounted )
764 return mSymbolFeatureIdMap.value( legendKey,
QgsFeatureIds() );
768 if ( ( mSymbolFeatureCounted || mFeatureCounter ) && !( storeSymbolFids && mSymbolFeatureIdMap.isEmpty() ) )
769 return mFeatureCounter;
771 mSymbolFeatureCountMap.clear();
772 mSymbolFeatureIdMap.clear();
777 return mFeatureCounter;
779 if ( !mDataProvider )
782 return mFeatureCounter;
787 return mFeatureCounter;
790 if ( !mFeatureCounter || ( storeSymbolFids && mSymbolFeatureIdMap.isEmpty() ) )
793 connect( mFeatureCounter, &
QgsTask::taskCompleted,
this, &QgsVectorLayer::onFeatureCounterCompleted, Qt::UniqueConnection );
794 connect( mFeatureCounter, &
QgsTask::taskTerminated,
this, &QgsVectorLayer::onFeatureCounterTerminated, Qt::UniqueConnection );
798 return mFeatureCounter;
804 if ( force || !mReadExtentFromXml || ( mReadExtentFromXml && mXmlExtent.
isNull() ) )
805 mValidExtent =
false;
816 if ( !mDefaultValueOnUpdateFields.isEmpty() )
821 int size = mFields.
size();
822 for (
int idx : qgis::as_const( mDefaultValueOnUpdateFields ) )
824 if ( idx < 0 || idx >= size )
841 if ( !mValidExtent && mLazyExtent && mDataProvider && !mDataProvider->
hasMetadata() && mReadExtentFromXml && !mXmlExtent.
isNull() )
848 if ( !mValidExtent && mLazyExtent && mDataProvider && mDataProvider->
isValid() )
865 if ( !
isValid() || !mDataProvider )
867 QgsDebugMsgLevel( QStringLiteral(
"invoked with invalid layer or null mDataProvider" ), 3 );
889 if ( it->hasGeometry() )
900 .setNoAttributes() );
935 if ( !
isValid() || !mDataProvider )
937 QgsDebugMsgLevel( QStringLiteral(
"invoked with invalid layer or null mDataProvider" ), 3 );
938 return customProperty( QStringLiteral(
"storedSubsetString" ) ).toString();
945 if ( !
isValid() || !mDataProvider )
947 QgsDebugMsgLevel( QStringLiteral(
"invoked with invalid layer or null mDataProvider or while editing" ), 3 );
951 else if ( mEditBuffer )
980 double maximumSimplificationScale = mSimplifyMethod.
maximumScale();
983 return !( maximumSimplificationScale > 1 && renderContext.
rendererScale() <= maximumSimplificationScale );
990 return mConditionalStyles;
995 if ( !
isValid() || !mDataProvider )
1013 if ( !
isValid() || !mEditBuffer || !mDataProvider )
1017 if ( mGeometryOptions->isActive() )
1020 mGeometryOptions->apply( geom );
1024 bool success = mEditBuffer->
addFeature( feature );
1031 success = mJoinBuffer->
addFeature( feature );
1039 if ( !mEditBuffer || !mDataProvider )
1045 if ( currentFeature.
isValid() )
1047 bool hasChanged =
false;
1048 bool hasError =
false;
1060 QgsDebugMsgLevel( QStringLiteral(
"geometry of feature %1 could not be changed." ).arg( updatedFeature.
id() ), 3 );
1067 for (
int attr = 0; attr < fa.count(); ++attr )
1069 if ( fa.at( attr ) != ca.at( attr ) )
1077 QgsDebugMsgLevel( QStringLiteral(
"attribute %1 of feature %2 could not be changed." ).arg( attr ).arg( updatedFeature.
id() ), 3 );
1082 if ( hasChanged && !mDefaultValueOnUpdateFields.isEmpty() && !skipDefaultValues )
1083 updateDefaultValues( updatedFeature.
id(), updatedFeature );
1089 QgsDebugMsgLevel( QStringLiteral(
"feature %1 could not be retrieved" ).arg( updatedFeature.
id() ), 3 );
1097 if ( !
isValid() || !mEditBuffer || !mDataProvider )
1101 bool result = utils.
insertVertex( x, y, atFeatureId, beforeVertex );
1110 if ( !
isValid() || !mEditBuffer || !mDataProvider )
1114 bool result = utils.
insertVertex( point, atFeatureId, beforeVertex );
1123 if ( !
isValid() || !mEditBuffer || !mDataProvider )
1127 bool result = utils.
moveVertex( x, y, atFeatureId, atVertex );
1136 if ( !
isValid() || !mEditBuffer || !mDataProvider )
1140 bool result = utils.
moveVertex( p, atFeatureId, atVertex );
1149 if ( !
isValid() || !mEditBuffer || !mDataProvider )
1174 int count = mSelectedFeatureIds.size();
1188 *deletedCount = deleted;
1191 return deleted == count;
1194 static const QgsPointSequence vectorPointXY2pointSequence(
const QVector<QgsPointXY> &points )
1197 pts.reserve( points.size() );
1198 QVector<const QgsPointXY>::iterator it = points.constBegin();
1199 while ( it != points.constEnd() )
1208 return addRing( vectorPointXY2pointSequence( ring ), featureId );
1213 if ( !
isValid() || !mEditBuffer || !mDataProvider )
1214 return QgsGeometry::OperationResult::LayerNotEditable;
1220 if ( !mSelectedFeatureIds.isEmpty() )
1222 result = utils.
addRing( ring, mSelectedFeatureIds, featureId );
1225 if ( result != QgsGeometry::OperationResult::Success )
1236 if ( !
isValid() || !mEditBuffer || !mDataProvider )
1239 return QgsGeometry::OperationResult::LayerNotEditable;
1244 return QgsGeometry::OperationResult::InvalidInputGeometryType;
1250 return QgsGeometry::OperationResult::AddRingNotClosed;
1257 if ( !mSelectedFeatureIds.isEmpty() )
1259 result = utils.
addRing(
static_cast< QgsCurve *
>( ring->
clone() ), mSelectedFeatureIds, featureId );
1262 if ( result != QgsGeometry::OperationResult::Success )
1275 pts.reserve( points.size() );
1276 for ( QList<QgsPointXY>::const_iterator it = points.constBegin(); it != points.constEnd() ; ++it )
1285 return addPart( vectorPointXY2pointSequence( points ) );
1290 if ( !
isValid() || !mEditBuffer || !mDataProvider )
1291 return QgsGeometry::OperationResult::LayerNotEditable;
1295 if ( mSelectedFeatureIds.empty() )
1298 return QgsGeometry::OperationResult::SelectionIsEmpty;
1300 else if ( mSelectedFeatureIds.size() > 1 )
1303 return QgsGeometry::OperationResult::SelectionIsGreaterThanOne;
1309 if ( result == QgsGeometry::OperationResult::Success )
1316 if ( !
isValid() || !mEditBuffer || !mDataProvider )
1317 return QgsGeometry::OperationResult::LayerNotEditable;
1321 if ( mSelectedFeatureIds.empty() )
1324 return QgsGeometry::OperationResult::SelectionIsEmpty;
1326 else if ( mSelectedFeatureIds.size() > 1 )
1329 return QgsGeometry::OperationResult::SelectionIsGreaterThanOne;
1335 if ( result == QgsGeometry::OperationResult::Success )
1342 if ( !
isValid() || !mEditBuffer || !mDataProvider )
1343 return QgsGeometry::OperationResult::LayerNotEditable;
1348 if ( result == QgsGeometry::OperationResult::Success )
1355 return splitParts( vectorPointXY2pointSequence( splitLine ), topologicalEditing );
1359 if ( !
isValid() || !mEditBuffer || !mDataProvider )
1360 return QgsGeometry::OperationResult::LayerNotEditable;
1363 return utils.
splitParts( splitLine, topologicalEditing );
1367 return splitFeatures( vectorPointXY2pointSequence( splitLine ), topologicalEditing );
1374 bool preserveCircular =
false;
1375 return splitFeatures( &splitLineString, topologyTestPoints, preserveCircular, topologicalEditing );
1380 if ( !
isValid() || !mEditBuffer || !mDataProvider )
1381 return QgsGeometry::OperationResult::LayerNotEditable;
1384 return utils.
splitFeatures( curve, topologyTestPoints, preserveCircular, topologicalEditing );
1389 if ( !
isValid() || !mEditBuffer || !mDataProvider )
1403 if ( !
isValid() || !mEditBuffer || !mDataProvider )
1412 if ( !
mValid || !mEditBuffer || !mDataProvider )
1430 if ( !
isValid() || !mDataProvider )
1492 if ( mDataProvider )
1504 if ( !mRenderer->
accept( visitor ) )
1508 if ( !mLabeling->
accept( visitor ) )
1519 QDomNode pkeyNode = layer_node.namedItem( QStringLiteral(
"provider" ) );
1521 if ( pkeyNode.isNull() )
1527 QDomElement pkeyElt = pkeyNode.toElement();
1537 else if (
mDataSource.contains( QLatin1String(
"dbname=" ) ) )
1547 QgsDataProvider::ReadFlags
flags;
1558 const QDomElement elem = layer_node.toElement();
1561 if ( elem.hasAttribute( QStringLiteral(
"wkbType" ) ) )
1562 mWkbType =
qgsEnumKeyToValue( elem.attribute( QStringLiteral(
"wkbType" ) ), mWkbType );
1565 QDomElement pkeyElem = pkeyNode.toElement();
1566 if ( !pkeyElem.isNull() )
1568 QString encodingString = pkeyElem.attribute( QStringLiteral(
"encoding" ) );
1569 if ( mDataProvider && !encodingString.isEmpty() )
1576 mJoinBuffer->
readXml( layer_node );
1581 mSetLegendFromStyle =
false;
1591 QDomNode depsNode = layer_node.namedItem( QStringLiteral(
"dataDependencies" ) );
1592 QDomNodeList depsNodes = depsNode.childNodes();
1593 QSet<QgsMapLayerDependency> sources;
1594 for (
int i = 0; i < depsNodes.count(); i++ )
1596 QString
source = depsNodes.at( i ).toElement().attribute( QStringLiteral(
"id" ) );
1601 if ( !mSetLegendFromStyle )
1605 if ( mReadExtentFromXml )
1607 QDomNode extentNode = layer_node.namedItem( QStringLiteral(
"extent" ) );
1608 if ( !extentNode.isNull() )
1615 const QDomNode asNode = layer_node.namedItem( QStringLiteral(
"auxiliaryLayer" ) );
1616 const QDomElement asElem = asNode.toElement();
1617 if ( !asElem.isNull() )
1619 mAuxiliaryLayerKey = asElem.attribute( QStringLiteral(
"key" ) );
1623 mServerProperties->readXml( layer_node );
1633 setDataSource( dataSource, baseName, provider, options, loadDefaultStyleFlag );
1643 QgsDataProvider::ReadFlags
flags = QgsDataProvider::ReadFlags();
1648 setDataProvider( provider, options,
flags );
1662 std::unique_ptr< QgsScopedRuntimeProfile > profile;
1664 profile = qgis::make_unique< QgsScopedRuntimeProfile >( tr(
"Load layer style" ), QStringLiteral(
"projectload" ) );
1666 bool defaultLoadedFlag =
false;
1671 std::unique_ptr< QgsFeatureRenderer > defaultRenderer( mDataProvider->
createRenderer() );
1672 if ( defaultRenderer )
1674 defaultLoadedFlag =
true;
1681 mSetLegendFromStyle =
false;
1685 if ( !defaultLoadedFlag && loadDefaultStyleFlag )
1691 if ( !defaultLoadedFlag &&
isSpatial() )
1697 if ( !mSetLegendFromStyle )
1702 std::unique_ptr< QgsAbstractVectorLayerLabeling > defaultLabeling( mDataProvider->
createLabeling() );
1703 if ( defaultLabeling )
1720 std::unique_ptr< QgsFeatureRenderer > defaultRenderer( mDataProvider->
createRenderer() );
1721 if ( defaultRenderer )
1736 delete mDataProvider;
1743 if ( provider.compare( QLatin1String(
"postgres" ) ) == 0 )
1745 const QString checkUnicityKey { QStringLiteral(
"checkPrimaryKeyUnicity" ) };
1747 if ( ! uri.hasParam( checkUnicityKey ) )
1749 uri.setParam( checkUnicityKey, mReadExtentFromXml ?
"0" :
"1" );
1754 std::unique_ptr< QgsScopedRuntimeProfile > profile;
1756 profile = qgis::make_unique< QgsScopedRuntimeProfile >( tr(
"Create %1 provider" ).arg( provider ), QStringLiteral(
"projectload" ) );
1759 if ( !mDataProvider )
1766 mDataProvider->setParent(
this );
1769 QgsDebugMsgLevel( QStringLiteral(
"Instantiated the data provider plugin" ), 2 );
1779 profile->switchTask( tr(
"Read layer metadata" ) );
1783 QgsDebugMsgLevel( QStringLiteral(
"Set Data provider QgsLayerMetadata identifier[%1]" ).arg(
metadata().identifier() ), 4 );
1790 mWkbType = mDataProvider->
wkbType();
1793 profile->switchTask( tr(
"Read layer fields" ) );
1804 QRegExp reg( R
"lit("[^"]+"\."([^"] + )"( \([^)]+\))?)lit" );
1805 if ( reg.indexIn(
name() ) >= 0 )
1807 QStringList stuff = reg.capturedTexts();
1808 QString lName = stuff[1];
1812 QMap<QString, QgsMapLayer *>::const_iterator it;
1813 for ( it = layers.constBegin(); it != layers.constEnd() && ( *it )->name() != lName; ++it )
1816 if ( it != layers.constEnd() && stuff.size() > 2 )
1818 lName +=
'.' + stuff[2].mid( 2, stuff[2].length() - 3 );
1821 if ( !lName.isEmpty() )
1831 else if ( provider == QLatin1String(
"ogr" ) )
1835 if (
mDataSource.right( 10 ) == QLatin1String(
"|layerid=0" ) )
1838 else if ( provider == QLatin1String(
"memory" ) )
1855 QDomDocument &document,
1860 QDomElement mapLayerNode = layer_node.toElement();
1862 if ( mapLayerNode.isNull() || (
"maplayer" != mapLayerNode.nodeName() ) )
1868 mapLayerNode.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"vector" ) );
1875 if ( mDataProvider )
1877 QDomElement provider = document.createElement( QStringLiteral(
"provider" ) );
1878 provider.setAttribute( QStringLiteral(
"encoding" ), mDataProvider->
encoding() );
1879 QDomText providerText = document.createTextNode(
providerType() );
1880 provider.appendChild( providerText );
1881 layer_node.appendChild( provider );
1885 mJoinBuffer->
writeXml( layer_node, document );
1888 QDomElement dependenciesElement = document.createElement( QStringLiteral(
"layerDependencies" ) );
1894 QDomElement depElem = document.createElement( QStringLiteral(
"layer" ) );
1895 depElem.setAttribute( QStringLiteral(
"id" ), dep.layerId() );
1896 dependenciesElement.appendChild( depElem );
1898 layer_node.appendChild( dependenciesElement );
1901 QDomElement dataDependenciesElement = document.createElement( QStringLiteral(
"dataDependencies" ) );
1906 QDomElement depElem = document.createElement( QStringLiteral(
"layer" ) );
1907 depElem.setAttribute( QStringLiteral(
"id" ), dep.layerId() );
1908 dataDependenciesElement.appendChild( depElem );
1910 layer_node.appendChild( dataDependenciesElement );
1913 mExpressionFieldBuffer->
writeXml( layer_node, document );
1918 QDomElement asElem = document.createElement( QStringLiteral(
"auxiliaryLayer" ) );
1919 if ( mAuxiliaryLayer )
1921 const QString pkField = mAuxiliaryLayer->joinInfo().targetFieldName();
1922 asElem.setAttribute( QStringLiteral(
"key" ), pkField );
1924 layer_node.appendChild( asElem );
1927 mServerProperties->writeXml( layer_node, document );
1931 return writeSymbology( layer_node, document, errorMsg, context );
1948 QStringList theURIParts = src.split(
'|' );
1950 src = theURIParts.join( QLatin1Char(
'|' ) );
1954 QStringList theURIParts = src.split(
'?' );
1956 src = theURIParts.join( QLatin1Char(
'?' ) );
1958 else if (
providerType() == QLatin1String(
"delimitedtext" ) )
1960 QUrl urlSource = QUrl::fromEncoded( src.toLatin1() );
1962 urlDest.setQuery( urlSource.query() );
1963 src = QString::fromLatin1( urlDest.toEncoded() );
1965 else if (
providerType() == QLatin1String(
"memory" ) )
1970 else if (
providerType() == QLatin1String(
"virtual" ) )
1972 QUrl urlSource = QUrl::fromEncoded( src.toLatin1() );
1973 QStringList theURIParts;
1975 QUrlQuery query = QUrlQuery( urlSource.query() );
1976 QList<QPair<QString, QString> > queryItems = query.queryItems();
1978 for (
int i = 0; i < queryItems.size(); i++ )
1980 QString key = queryItems.at( i ).first;
1981 QString value = queryItems.at( i ).second;
1982 if ( key == QLatin1String(
"layer" ) )
1985 theURIParts = value.split(
':' );
1986 theURIParts[1] = QUrl::fromPercentEncoding( theURIParts[1].toUtf8() );
1988 if ( theURIParts[0] == QLatin1String(
"delimitedtext" ) )
1990 QUrl urlSource = QUrl( theURIParts[1] );
1992 urlDest.setQuery( urlSource.query() );
1993 theURIParts[1] = QUrl::toPercentEncoding( urlDest.toString(), QByteArray(
"" ), QByteArray(
":" ) );
1998 theURIParts[1] = QUrl::toPercentEncoding( theURIParts[1] );
2001 queryItems[i].second = theURIParts.join( QLatin1Char(
':' ) ) ;
2005 query.setQueryItems( queryItems );
2007 QUrl urlDest = QUrl( urlSource );
2008 urlDest.setQuery( query.query() );
2009 src = QString::fromLatin1( urlDest.toEncoded() );
2023 if ( provider == QLatin1String(
"spatialite" ) )
2029 else if ( provider == QLatin1String(
"ogr" ) )
2031 QStringList theURIParts = src.split(
'|' );
2033 src = theURIParts.join( QLatin1Char(
'|' ) );
2035 else if ( provider == QLatin1String(
"gpx" ) )
2037 QStringList theURIParts = src.split(
'?' );
2039 src = theURIParts.join( QLatin1Char(
'?' ) );
2041 else if ( provider == QLatin1String(
"delimitedtext" ) )
2043 QUrl urlSource = QUrl::fromEncoded( src.toLatin1() );
2045 if ( !src.startsWith( QLatin1String(
"file:" ) ) )
2047 QUrl file = QUrl::fromLocalFile( src.left( src.indexOf(
'?' ) ) );
2048 urlSource.setScheme( QStringLiteral(
"file" ) );
2049 urlSource.setPath( file.path() );
2052 QUrl urlDest = QUrl::fromLocalFile( context.
pathResolver().
readPath( urlSource.toLocalFile() ) );
2053 urlDest.setQuery( urlSource.query() );
2054 src = QString::fromLatin1( urlDest.toEncoded() );
2056 else if ( provider == QLatin1String(
"virtual" ) )
2058 QUrl urlSource = QUrl::fromEncoded( src.toLatin1() );
2059 QStringList theURIParts;
2061 QUrlQuery query = QUrlQuery( urlSource.query() );
2062 QList<QPair<QString, QString> > queryItems = query.queryItems();
2064 for (
int i = 0; i < queryItems.size(); i++ )
2066 QString key = queryItems.at( i ).first;
2067 QString value = queryItems.at( i ).second;
2068 if ( key == QLatin1String(
"layer" ) )
2071 theURIParts = value.split(
':' );
2072 theURIParts[1] = QUrl::fromPercentEncoding( theURIParts[1].toUtf8() );
2074 if ( theURIParts[0] == QLatin1String(
"delimitedtext" ) )
2076 QUrl urlSource = QUrl( theURIParts[1] );
2078 if ( !theURIParts[1].startsWith( QLatin1String(
"file:" ) ) )
2080 QUrl file = QUrl::fromLocalFile( theURIParts[1].left( theURIParts[1].indexOf(
'?' ) ) );
2081 urlSource.setScheme( QStringLiteral(
"file" ) );
2082 urlSource.setPath( file.path() );
2085 QUrl urlDest = QUrl::fromLocalFile( context.
pathResolver().
readPath( urlSource.toLocalFile() ) );
2086 urlDest.setQuery( urlSource.query() );
2088 theURIParts[1] = urlDest.toString();
2095 theURIParts[1] = QUrl::toPercentEncoding( theURIParts[1] );
2096 queryItems[i].second = theURIParts.join( QLatin1Char(
':' ) ) ;
2100 query.setQueryItems( queryItems );
2102 QUrl urlDest = QUrl( urlSource );
2103 urlDest.setQuery( query.query() );
2104 src = QString::fromLatin1( urlDest.toEncoded() );
2128 if ( categories.testFlag(
Fields ) )
2130 if ( !mExpressionFieldBuffer )
2132 mExpressionFieldBuffer->
readXml( layerNode );
2143 QDomNodeList referencedLayersNodeList = layerNode.toElement().elementsByTagName( QStringLiteral(
"referencedLayers" ) );
2144 if ( referencedLayersNodeList.size() > 0 )
2146 const QDomNodeList relationNodes { referencedLayersNodeList.at( 0 ).childNodes() };
2147 for (
int i = 0; i < relationNodes.length(); ++i )
2149 const QDomElement relationElement = relationNodes.at( i ).toElement();
2156 QDomNodeList referencingLayersNodeList = layerNode.toElement().elementsByTagName( QStringLiteral(
"referencingLayers" ) );
2157 if ( referencingLayersNodeList.size() > 0 )
2159 const QDomNodeList relationNodes { referencingLayersNodeList.at( 0 ).childNodes() };
2160 for (
int i = 0; i < relationNodes.length(); ++i )
2162 const QDomElement relationElement = relationNodes.at( i ).toElement();
2168 QDomElement layerElement = layerNode.toElement();
2172 readStyle( layerNode, errorMessage, context, categories );
2174 if ( categories.testFlag(
MapTips ) )
2175 mMapTipTemplate = layerNode.namedItem( QStringLiteral(
"mapTip" ) ).toElement().text();
2178 mDisplayExpression = layerNode.namedItem( QStringLiteral(
"previewExpression" ) ).toElement().text();
2181 QString
displayField = layerNode.namedItem( QStringLiteral(
"displayfield" ) ).toElement().text();
2185 if ( mMapTipTemplate.isEmpty() && categories.testFlag(
MapTips ) )
2195 if ( categories.testFlag(
Actions ) )
2196 mActions->
readXml( layerNode );
2198 if ( categories.testFlag(
Fields ) )
2200 mAttributeAliasMap.clear();
2201 QDomNode aliasesNode = layerNode.namedItem( QStringLiteral(
"aliases" ) );
2202 if ( !aliasesNode.isNull() )
2204 QDomElement aliasElem;
2206 QDomNodeList aliasNodeList = aliasesNode.toElement().elementsByTagName( QStringLiteral(
"alias" ) );
2207 for (
int i = 0; i < aliasNodeList.size(); ++i )
2209 aliasElem = aliasNodeList.at( i ).toElement();
2212 if ( aliasElem.hasAttribute( QStringLiteral(
"field" ) ) )
2214 field = aliasElem.attribute( QStringLiteral(
"field" ) );
2218 int index = aliasElem.attribute( QStringLiteral(
"index" ) ).toInt();
2220 if ( index >= 0 && index <
fields().count() )
2226 if ( !aliasElem.attribute( QStringLiteral(
"name" ) ).isEmpty() )
2229 alias = context.
projectTranslator()->
translate( QStringLiteral(
"project:layers:%1:fieldaliases" ).arg( layerNode.namedItem( QStringLiteral(
"id" ) ).toElement().text() ), aliasElem.attribute( QStringLiteral(
"name" ) ) );
2230 QgsDebugMsgLevel(
"context" + QStringLiteral(
"project:layers:%1:fieldaliases" ).arg( layerNode.namedItem( QStringLiteral(
"id" ) ).toElement().text() ) +
" source " + aliasElem.attribute( QStringLiteral(
"name" ) ), 3 );
2235 alias = context.
projectTranslator()->
translate( QStringLiteral(
"project:layers:%1:fieldaliases" ).arg( layerNode.namedItem( QStringLiteral(
"id" ) ).toElement().text() ),
field );
2236 QgsDebugMsgLevel(
"context" + QStringLiteral(
"project:layers:%1:fieldaliases" ).arg( layerNode.namedItem( QStringLiteral(
"id" ) ).toElement().text() ) +
" source " +
field, 3 );
2238 if ( alias == aliasElem.attribute( QStringLiteral(
"field" ) ) )
2242 QgsDebugMsgLevel(
"field " +
field +
" origalias " + aliasElem.attribute( QStringLiteral(
"name" ) ) +
" trans " + alias, 3 );
2243 mAttributeAliasMap.insert(
field, alias );
2248 mDefaultExpressionMap.clear();
2249 QDomNode defaultsNode = layerNode.namedItem( QStringLiteral(
"defaults" ) );
2250 if ( !defaultsNode.isNull() )
2252 QDomNodeList defaultNodeList = defaultsNode.toElement().elementsByTagName( QStringLiteral(
"default" ) );
2253 for (
int i = 0; i < defaultNodeList.size(); ++i )
2255 QDomElement defaultElem = defaultNodeList.at( i ).toElement();
2257 QString
field = defaultElem.attribute( QStringLiteral(
"field" ), QString() );
2258 QString expression = defaultElem.attribute( QStringLiteral(
"expression" ), QString() );
2259 bool applyOnUpdate = defaultElem.attribute( QStringLiteral(
"applyOnUpdate" ), QStringLiteral(
"0" ) ) == QLatin1String(
"1" );
2260 if (
field.isEmpty() || expression.isEmpty() )
2268 mFieldConstraints.clear();
2269 mFieldConstraintStrength.clear();
2270 QDomNode constraintsNode = layerNode.namedItem( QStringLiteral(
"constraints" ) );
2271 if ( !constraintsNode.isNull() )
2273 QDomNodeList constraintNodeList = constraintsNode.toElement().elementsByTagName( QStringLiteral(
"constraint" ) );
2274 for (
int i = 0; i < constraintNodeList.size(); ++i )
2276 QDomElement constraintElem = constraintNodeList.at( i ).toElement();
2278 QString
field = constraintElem.attribute( QStringLiteral(
"field" ), QString() );
2279 int constraints = constraintElem.attribute( QStringLiteral(
"constraints" ), QStringLiteral(
"0" ) ).toInt();
2280 if (
field.isEmpty() || constraints == 0 )
2283 mFieldConstraints.insert(
field,
static_cast< QgsFieldConstraints::Constraints
>( constraints ) );
2285 int uniqueStrength = constraintElem.attribute( QStringLiteral(
"unique_strength" ), QStringLiteral(
"1" ) ).toInt();
2286 int notNullStrength = constraintElem.attribute( QStringLiteral(
"notnull_strength" ), QStringLiteral(
"1" ) ).toInt();
2287 int expStrength = constraintElem.attribute( QStringLiteral(
"exp_strength" ), QStringLiteral(
"1" ) ).toInt();
2294 mFieldConstraintExpressions.clear();
2295 QDomNode constraintExpressionsNode = layerNode.namedItem( QStringLiteral(
"constraintExpressions" ) );
2296 if ( !constraintExpressionsNode.isNull() )
2298 QDomNodeList constraintNodeList = constraintExpressionsNode.toElement().elementsByTagName( QStringLiteral(
"constraint" ) );
2299 for (
int i = 0; i < constraintNodeList.size(); ++i )
2301 QDomElement constraintElem = constraintNodeList.at( i ).toElement();
2303 QString
field = constraintElem.attribute( QStringLiteral(
"field" ), QString() );
2304 QString exp = constraintElem.attribute( QStringLiteral(
"exp" ), QString() );
2305 QString desc = constraintElem.attribute( QStringLiteral(
"desc" ), QString() );
2306 if (
field.isEmpty() || exp.isEmpty() )
2309 mFieldConstraintExpressions.insert(
field, qMakePair( exp, desc ) );
2317 if ( categories.testFlag(
Fields ) || categories.testFlag(
Forms ) )
2319 QDomElement widgetsElem = layerNode.namedItem( QStringLiteral(
"fieldConfiguration" ) ).toElement();
2320 QDomNodeList fieldConfigurationElementList = widgetsElem.elementsByTagName( QStringLiteral(
"field" ) );
2321 for (
int i = 0; i < fieldConfigurationElementList.size(); ++i )
2323 const QDomElement fieldConfigElement = fieldConfigurationElementList.at( i ).toElement();
2324 const QDomElement fieldWidgetElement = fieldConfigElement.elementsByTagName( QStringLiteral(
"editWidget" ) ).at( 0 ).toElement();
2326 QString fieldName = fieldConfigElement.attribute( QStringLiteral(
"name" ) );
2328 if ( categories.testFlag(
Fields ) )
2332 if ( categories.testFlag(
Forms ) )
2334 const QString widgetType = fieldWidgetElement.attribute( QStringLiteral(
"type" ) );
2335 const QDomElement cfgElem = fieldConfigElement.elementsByTagName( QStringLiteral(
"config" ) ).at( 0 ).toElement();
2336 const QDomElement optionsElem = cfgElem.childNodes().at( 0 ).toElement();
2338 if ( widgetType == QLatin1String(
"ValueRelation" ) )
2340 optionsMap[ QStringLiteral(
"Value" ) ] = context.
projectTranslator()->
translate( QStringLiteral(
"project:layers:%1:fields:%2:valuerelationvalue" ).arg( layerNode.namedItem( QStringLiteral(
"id" ) ).toElement().text(), fieldName ), optionsMap[ QStringLiteral(
"Value" ) ].toString() );
2343 mFieldWidgetSetups[fieldName] = setup;
2350 if ( categories.testFlag(
Fields ) )
2352 const QList<QPair<QString, QgsField::ConfigurationFlag>> legacyConfig
2357 for (
const auto &config : legacyConfig )
2359 QDomNode excludeNode = layerNode.namedItem( config.first );
2360 if ( !excludeNode.isNull() )
2362 QDomNodeList attributeNodeList = excludeNode.toElement().elementsByTagName( QStringLiteral(
"attribute" ) );
2363 for (
int i = 0; i < attributeNodeList.size(); ++i )
2365 QString fieldName = attributeNodeList.at( i ).toElement().text();
2374 mGeometryOptions->readXml( layerNode.namedItem( QStringLiteral(
"geometryOptions" ) ) );
2376 if ( categories.testFlag(
Forms ) )
2377 mEditFormConfig.
readXml( layerNode, context );
2381 mAttributeTableConfig.
readXml( layerNode );
2382 mConditionalStyles->
readXml( layerNode, context );
2383 mStoredExpressionManager->
readXml( layerNode );
2389 QDomElement mapLayerNode = layerNode.toElement();
2391 && mapLayerNode.attribute( QStringLiteral(
"readOnly" ), QStringLiteral(
"0" ) ).toInt() == 1 )
2396 if ( categories.testFlag(
Legend ) )
2398 const QDomElement legendElem = layerNode.firstChildElement( QStringLiteral(
"legend" ) );
2399 if ( !legendElem.isNull() )
2404 mSetLegendFromStyle =
true;
2426 if ( !rendererElement.isNull() )
2446 if ( categories.testFlag(
Labeling ) )
2448 QDomElement labelingElement = node.firstChildElement( QStringLiteral(
"labeling" ) );
2450 if ( labelingElement.isNull() ||
2451 ( labelingElement.attribute( QStringLiteral(
"type" ) ) == QLatin1String(
"simple" ) && labelingElement.firstChildElement( QStringLiteral(
"settings" ) ).isNull() ) )
2459 labeling = readLabelingFromCustomProperties();
2467 if ( node.toElement().hasAttribute( QStringLiteral(
"labelsEnabled" ) ) )
2468 mLabelsEnabled = node.toElement().attribute( QStringLiteral(
"labelsEnabled" ) ).toInt();
2470 mLabelsEnabled =
true;
2476 QDomNode blendModeNode = node.namedItem( QStringLiteral(
"blendMode" ) );
2477 if ( !blendModeNode.isNull() )
2479 QDomElement e = blendModeNode.toElement();
2484 QDomNode featureBlendModeNode = node.namedItem( QStringLiteral(
"featureBlendMode" ) );
2485 if ( !featureBlendModeNode.isNull() )
2487 QDomElement e = featureBlendModeNode.toElement();
2495 QDomNode layerTransparencyNode = node.namedItem( QStringLiteral(
"layerTransparency" ) );
2496 if ( !layerTransparencyNode.isNull() )
2498 QDomElement e = layerTransparencyNode.toElement();
2499 setOpacity( 1.0 - e.text().toInt() / 100.0 );
2501 QDomNode layerOpacityNode = node.namedItem( QStringLiteral(
"layerOpacity" ) );
2502 if ( !layerOpacityNode.isNull() )
2504 QDomElement e = layerOpacityNode.toElement();
2508 const bool hasScaleBasedVisibiliy { node.attributes().namedItem( QStringLiteral(
"hasScaleBasedVisibilityFlag" ) ).nodeValue() ==
'1' };
2511 const double maxScale { node.attributes().namedItem( QStringLiteral(
"maxScale" ) ).nodeValue().toDouble( &ok ) };
2516 const double minScale { node.attributes().namedItem( QStringLiteral(
"minScale" ) ).nodeValue().toDouble( &ok ) };
2525 QDomElement e = node.toElement();
2528 mSimplifyMethod.
setSimplifyHints(
static_cast< QgsVectorSimplifyMethod::SimplifyHints
>( e.attribute( QStringLiteral(
"simplifyDrawingHints" ), QStringLiteral(
"1" ) ).toInt() ) );
2530 mSimplifyMethod.
setThreshold( e.attribute( QStringLiteral(
"simplifyDrawingTol" ), QStringLiteral(
"1" ) ).toFloat() );
2531 mSimplifyMethod.
setForceLocalOptimization( e.attribute( QStringLiteral(
"simplifyLocal" ), QStringLiteral(
"1" ) ).toInt() );
2532 mSimplifyMethod.
setMaximumScale( e.attribute( QStringLiteral(
"simplifyMaxScale" ), QStringLiteral(
"1" ) ).toFloat() );
2536 if ( categories.testFlag(
Diagrams ) )
2538 delete mDiagramRenderer;
2539 mDiagramRenderer =
nullptr;
2540 QDomElement singleCatDiagramElem = node.firstChildElement( QStringLiteral(
"SingleCategoryDiagramRenderer" ) );
2541 if ( !singleCatDiagramElem.isNull() )
2544 mDiagramRenderer->
readXml( singleCatDiagramElem, context );
2546 QDomElement linearDiagramElem = node.firstChildElement( QStringLiteral(
"LinearlyInterpolatedDiagramRenderer" ) );
2547 if ( !linearDiagramElem.isNull() )
2549 if ( linearDiagramElem.hasAttribute( QStringLiteral(
"classificationAttribute" ) ) )
2552 int idx = linearDiagramElem.attribute( QStringLiteral(
"classificationAttribute" ) ).toInt();
2553 if ( idx >= 0 && idx < mFields.
count() )
2554 linearDiagramElem.setAttribute( QStringLiteral(
"classificationField" ), mFields.
at( idx ).
name() );
2558 mDiagramRenderer->
readXml( linearDiagramElem, context );
2561 if ( mDiagramRenderer )
2563 QDomElement diagramSettingsElem = node.firstChildElement( QStringLiteral(
"DiagramLayerSettings" ) );
2564 if ( !diagramSettingsElem.isNull() )
2566 bool oldXPos = diagramSettingsElem.hasAttribute( QStringLiteral(
"xPosColumn" ) );
2567 bool oldYPos = diagramSettingsElem.hasAttribute( QStringLiteral(
"yPosColumn" ) );
2568 bool oldShow = diagramSettingsElem.hasAttribute( QStringLiteral(
"showColumn" ) );
2569 if ( oldXPos || oldYPos || oldShow )
2575 int xPosColumn = diagramSettingsElem.attribute( QStringLiteral(
"xPosColumn" ) ).toInt();
2576 if ( xPosColumn >= 0 && xPosColumn < mFields.
count() )
2581 int yPosColumn = diagramSettingsElem.attribute( QStringLiteral(
"yPosColumn" ) ).toInt();
2582 if ( yPosColumn >= 0 && yPosColumn < mFields.
count() )
2587 int showColumn = diagramSettingsElem.attribute( QStringLiteral(
"showColumn" ) ).toInt();
2588 if ( showColumn >= 0 && showColumn < mFields.
count() )
2591 QDomElement propertiesElem = diagramSettingsElem.ownerDocument().createElement( QStringLiteral(
"properties" ) );
2598 ddp.
writeXml( propertiesElem, defs );
2599 diagramSettingsElem.appendChild( propertiesElem );
2602 delete mDiagramLayerSettings;
2604 mDiagramLayerSettings->
readXml( diagramSettingsElem );
2617 QDomElement layerElement = node.toElement();
2620 ( void )
writeStyle( node, doc, errorMessage, context, categories );
2623 mGeometryOptions->writeXml( node );
2628 if ( !legendElement.isNull() )
2629 node.appendChild( legendElement );
2636 QDomElement referencedLayersElement = doc.createElement( QStringLiteral(
"referencedLayers" ) );
2637 node.appendChild( referencedLayersElement );
2640 for (
const auto &rel : constReferencingRelations )
2646 QDomElement referencingLayersElement = doc.createElement( QStringLiteral(
"referencingLayers" ) );
2647 node.appendChild( referencedLayersElement );
2650 for (
const auto &rel : constReferencedRelations )
2658 if ( categories.testFlag(
Fields ) || categories.testFlag(
Forms ) )
2660 QDomElement fieldConfigurationElement;
2662 fieldConfigurationElement = doc.createElement( QStringLiteral(
"fieldConfiguration" ) );
2663 node.appendChild( fieldConfigurationElement );
2667 QDomElement fieldElement = doc.createElement( QStringLiteral(
"field" ) );
2668 fieldElement.setAttribute( QStringLiteral(
"name" ),
field.
name() );
2669 fieldConfigurationElement.appendChild( fieldElement );
2671 if ( categories.testFlag(
Fields ) )
2676 if ( categories.testFlag(
Forms ) )
2681 QDomElement editWidgetElement = doc.createElement( QStringLiteral(
"editWidget" ) );
2682 fieldElement.appendChild( editWidgetElement );
2684 QDomElement editWidgetConfigElement = doc.createElement( QStringLiteral(
"config" ) );
2687 editWidgetElement.appendChild( editWidgetConfigElement );
2693 if ( categories.testFlag(
Fields ) )
2696 QDomElement aliasElem = doc.createElement( QStringLiteral(
"aliases" ) );
2699 QDomElement aliasEntryElem = doc.createElement( QStringLiteral(
"alias" ) );
2700 aliasEntryElem.setAttribute( QStringLiteral(
"field" ),
field.
name() );
2702 aliasEntryElem.setAttribute( QStringLiteral(
"name" ),
field.
alias() );
2703 aliasElem.appendChild( aliasEntryElem );
2705 node.appendChild( aliasElem );
2708 QDomElement defaultsElem = doc.createElement( QStringLiteral(
"defaults" ) );
2711 QDomElement defaultElem = doc.createElement( QStringLiteral(
"default" ) );
2712 defaultElem.setAttribute( QStringLiteral(
"field" ),
field.
name() );
2715 defaultsElem.appendChild( defaultElem );
2717 node.appendChild( defaultsElem );
2720 QDomElement constraintsElem = doc.createElement( QStringLiteral(
"constraints" ) );
2723 QDomElement constraintElem = doc.createElement( QStringLiteral(
"constraint" ) );
2724 constraintElem.setAttribute( QStringLiteral(
"field" ),
field.
name() );
2729 constraintsElem.appendChild( constraintElem );
2731 node.appendChild( constraintsElem );
2734 QDomElement constraintExpressionsElem = doc.createElement( QStringLiteral(
"constraintExpressions" ) );
2737 QDomElement constraintExpressionElem = doc.createElement( QStringLiteral(
"constraint" ) );
2738 constraintExpressionElem.setAttribute( QStringLiteral(
"field" ),
field.
name() );
2741 constraintExpressionsElem.appendChild( constraintExpressionElem );
2743 node.appendChild( constraintExpressionsElem );
2746 if ( !mExpressionFieldBuffer )
2754 mExpressionFieldBuffer->
writeXml( node, doc );
2759 if ( categories.testFlag(
Actions ) )
2764 mAttributeTableConfig.
writeXml( node );
2765 mConditionalStyles->
writeXml( node, doc, context );
2766 mStoredExpressionManager->
writeXml( node );
2769 if ( categories.testFlag(
Forms ) )
2770 mEditFormConfig.
writeXml( node, context );
2774 node.toElement().setAttribute( QStringLiteral(
"readOnly" ), mReadOnly );
2779 QDomElement prevExpElem = doc.createElement( QStringLiteral(
"previewExpression" ) );
2780 QDomText prevExpText = doc.createTextNode( mDisplayExpression );
2781 prevExpElem.appendChild( prevExpText );
2782 node.appendChild( prevExpElem );
2786 if ( categories.testFlag(
MapTips ) )
2788 QDomElement mapTipElem = doc.createElement( QStringLiteral(
"mapTip" ) );
2789 QDomText mapTipText = doc.createTextNode( mMapTipTemplate );
2790 mapTipElem.appendChild( mapTipText );
2791 node.toElement().appendChild( mapTipElem );
2800 QDomElement mapLayerNode = node.toElement();
2813 QDomElement rendererElement = mRenderer->
save( doc, context );
2814 node.appendChild( rendererElement );
2818 if ( categories.testFlag(
Labeling ) )
2822 QDomElement labelingElement = mLabeling->
save( doc, context );
2823 node.appendChild( labelingElement );
2825 mapLayerNode.setAttribute( QStringLiteral(
"labelsEnabled" ), mLabelsEnabled ? QStringLiteral(
"1" ) : QStringLiteral(
"0" ) );
2831 mapLayerNode.setAttribute( QStringLiteral(
"simplifyDrawingHints" ), QString::number( mSimplifyMethod.
simplifyHints() ) );
2832 mapLayerNode.setAttribute( QStringLiteral(
"simplifyAlgorithm" ), QString::number( mSimplifyMethod.
simplifyAlgorithm() ) );
2833 mapLayerNode.setAttribute( QStringLiteral(
"simplifyDrawingTol" ), QString::number( mSimplifyMethod.
threshold() ) );
2834 mapLayerNode.setAttribute( QStringLiteral(
"simplifyLocal" ), mSimplifyMethod.
forceLocalOptimization() ? 1 : 0 );
2835 mapLayerNode.setAttribute( QStringLiteral(
"simplifyMaxScale" ), QString::number( mSimplifyMethod.
maximumScale() ) );
2847 QDomElement blendModeElem = doc.createElement( QStringLiteral(
"blendMode" ) );
2849 blendModeElem.appendChild( blendModeText );
2850 node.appendChild( blendModeElem );
2853 QDomElement featureBlendModeElem = doc.createElement( QStringLiteral(
"featureBlendMode" ) );
2855 featureBlendModeElem.appendChild( featureBlendModeText );
2856 node.appendChild( featureBlendModeElem );
2862 QDomElement layerOpacityElem = doc.createElement( QStringLiteral(
"layerOpacity" ) );
2863 QDomText layerOpacityText = doc.createTextNode( QString::number(
opacity() ) );
2864 layerOpacityElem.appendChild( layerOpacityText );
2865 node.appendChild( layerOpacityElem );
2866 mapLayerNode.setAttribute( QStringLiteral(
"hasScaleBasedVisibilityFlag" ),
hasScaleBasedVisibility() ? 1 : 0 );
2867 mapLayerNode.setAttribute( QStringLiteral(
"maxScale" ),
maximumScale() );
2868 mapLayerNode.setAttribute( QStringLiteral(
"minScale" ),
minimumScale() );
2871 if ( categories.testFlag(
Diagrams ) && mDiagramRenderer )
2873 mDiagramRenderer->
writeXml( mapLayerNode, doc, context );
2874 if ( mDiagramLayerSettings )
2875 mDiagramLayerSettings->
writeXml( mapLayerNode, doc );
2884 QDomElement nameElem = node.firstChildElement( QStringLiteral(
"Name" ) );
2885 if ( nameElem.isNull() )
2887 errorMessage = QStringLiteral(
"Warning: Name element not found within NamedLayer while it's required." );
2899 readSldLabeling( node );
2906 Q_UNUSED( errorMessage )
2917 QDomElement nameNode = doc.createElement( QStringLiteral(
"se:Name" ) );
2918 nameNode.appendChild( doc.createTextNode(
name() ) );
2919 node.appendChild( nameNode );
2921 QDomElement userStyleElem = doc.createElement( QStringLiteral(
"UserStyle" ) );
2922 node.appendChild( userStyleElem );
2924 QDomElement nameElem = doc.createElement( QStringLiteral(
"se:Name" ) );
2925 nameElem.appendChild( doc.createTextNode(
name() ) );
2927 userStyleElem.appendChild( nameElem );
2929 QDomElement featureTypeStyleElem = doc.createElement( QStringLiteral(
"se:FeatureTypeStyle" ) );
2930 userStyleElem.appendChild( featureTypeStyleElem );
2932 mRenderer->
toSld( doc, featureTypeStyleElem, localProps );
2935 mLabeling->
toSld( featureTypeStyleElem, localProps );
2944 if ( !mEditBuffer || !mDataProvider )
2949 if ( mGeometryOptions->isActive() )
2950 mGeometryOptions->apply( geom );
2959 if ( !skipDefaultValue && !mDefaultValueOnUpdateFields.isEmpty() )
2960 updateDefaultValues( fid );
2968 bool result =
false;
2982 if ( mEditBuffer && mDataProvider )
2991 if ( result && !skipDefaultValues && !mDefaultValueOnUpdateFields.isEmpty() )
2992 updateDefaultValues( fid );
3007 for (
auto it = newValues.constBegin(); it != newValues.constEnd(); ++it )
3009 const int field = it.key();
3010 const QVariant newValue = it.value();
3013 if ( oldValues.contains(
field ) )
3014 oldValue = oldValues[
field];
3019 newValuesJoin[
field] = newValue;
3020 oldValuesJoin[
field] = oldValue;
3027 newValuesNotJoin[
field] = newValue;
3028 oldValuesNotJoin[
field] = oldValue;
3037 if ( ! newValuesJoin.isEmpty() && mJoinBuffer )
3042 if ( ! newValuesNotJoin.isEmpty() && mEditBuffer && mDataProvider )
3047 if ( result && !skipDefaultValues && !mDefaultValueOnUpdateFields.isEmpty() )
3049 updateDefaultValues( fid );
3057 if ( !mEditBuffer || !mDataProvider )
3065 if ( attIndex < 0 || attIndex >=
fields().count() )
3069 mFields[ attIndex ].setAlias( QString() );
3070 if ( mAttributeAliasMap.contains(
name ) )
3072 mAttributeAliasMap.remove(
name );
3074 mEditFormConfig.setFields( mFields );
3081 if ( index < 0 || index >=
fields().count() )
3088 if ( mExpressionFieldBuffer )
3104 if ( !mEditBuffer || !mDataProvider )
3120 if ( attIndex < 0 || attIndex >=
fields().count() )
3125 mAttributeAliasMap.insert(
name, aliasString );
3126 mFields[ attIndex ].setAlias( aliasString );
3127 mEditFormConfig.setFields( mFields );
3133 if ( index < 0 || index >=
fields().count() )
3141 if ( index >= 0 && index < mFields.
count() )
3149 return mAttributeAliasMap;
3154 if ( index < 0 || index >=
fields().count() )
3163 if ( !mEditBuffer || !mDataProvider )
3171 bool deleted =
false;
3174 QList<int> attrList = qgis::setToList( qgis::listToSet( attrs ) );
3176 std::sort( attrList.begin(), attrList.end(), std::greater<int>() );
3178 for (
int attr : qgis::as_const( attrList ) )
3194 if ( context && context->
cascade )
3197 const bool hasRelationsOrJoins = !relations.empty() || mJoinBuffer->
containsJoins();
3198 if ( hasRelationsOrJoins )
3203 if ( handledFeatureIds.contains( fid ) )
3211 handledFeatureIds << fid;
3229 while ( relatedFeaturesIt.
nextFeature( childFeature ) )
3231 childFeatureIds.insert( childFeature.
id() );
3233 if ( childFeatureIds.count() > 0 )
3235 relation.referencingLayer()->startEditing();
3236 relation.referencingLayer()->deleteFeatures( childFeatureIds, context );
3256 bool res = deleteFeatureCascade( fid, context );
3260 mSelectedFeatureIds.remove( fid );
3270 const auto constFids = fids;
3272 res = deleteFeatureCascade( fid, context ) && res;
3276 mSelectedFeatureIds.subtract( fids );
3291 if ( !mDataProvider )
3292 return pkAttributesList;
3295 for (
int i = 0; i < mFields.
count(); ++i )
3299 pkAttributesList << i;
3302 return pkAttributesList;
3307 if ( ! mDataProvider )
3318 if ( mEditBuffer && !deletedFeatures.empty() )
3320 if ( addedFeatures.size() > deletedFeatures.size() )
3321 return QgsFeatureSource::FeatureAvailability::FeaturesAvailable;
3323 return QgsFeatureSource::FeatureAvailability::FeaturesMaybeAvailable;
3326 if ( ( !mEditBuffer || addedFeatures.empty() ) && mDataProvider && mDataProvider->
empty() )
3327 return QgsFeatureSource::FeatureAvailability::NoFeaturesAvailable;
3329 return QgsFeatureSource::FeatureAvailability::FeaturesAvailable;
3334 mCommitErrors.clear();
3336 if ( !mDataProvider )
3338 mCommitErrors << tr(
"ERROR: no provider" );
3344 mCommitErrors << tr(
"ERROR: layer not editable" );
3350 if ( !mAllowCommit )
3360 mEditBuffer =
nullptr;
3384 return mCommitErrors;
3394 if ( !mDataProvider )
3396 mCommitErrors << tr(
"ERROR: no provider" );
3422 mEditBuffer =
nullptr;
3427 if ( rollbackExtent )
3438 return mSelectedFeatureIds.size();
3443 return mSelectedFeatureIds;
3449 features.reserve( mSelectedFeatureIds.count() );
3452 if ( mSelectedFeatureIds.count() <= 8 )
3456 const auto constMSelectedFeatureIds = mSelectedFeatureIds;
3469 features.push_back( f );
3478 if ( mSelectedFeatureIds.isEmpty() )
3484 if ( mSelectedFeatureIds.count() == 1 )
3485 request.
setFilterFid( *mSelectedFeatureIds.constBegin() );
3494 if ( !mEditBuffer || !mDataProvider )
3497 if ( mGeometryOptions->isActive() )
3499 for (
auto feature = features.begin(); feature != features.end(); ++feature )
3502 mGeometryOptions->apply( geom );
3544 if ( !mDisplayExpression.isEmpty() || mFields.
isEmpty() )
3546 return mDisplayExpression;
3559 static QStringList sCandidates{ QStringLiteral(
"name" ),
3560 QStringLiteral(
"title" ),
3561 QStringLiteral(
"heibt" ),
3562 QStringLiteral(
"desc" ),
3563 QStringLiteral(
"nom" ),
3564 QStringLiteral(
"street" ),
3565 QStringLiteral(
"road" ),
3566 QStringLiteral(
"id" )};
3567 for (
const QString &candidate : sCandidates )
3572 if ( fldName.indexOf( candidate, 0, Qt::CaseInsensitive ) > -1 )
3579 if ( !idxName.isEmpty() )
3583 if ( !idxName.isNull() )
3596 return ( mEditBuffer && mDataProvider );
3605 bool QgsVectorLayer::isReadOnly()
const
3613 if ( readonly && mEditBuffer )
3616 mReadOnly = readonly;
3624 return mEditBuffer && mEditBuffer->
isModified();
3629 bool auxiliaryField =
false;
3633 return auxiliaryField;
3640 auxiliaryField =
true;
3643 return auxiliaryField;
3654 if ( r != mRenderer )
3658 mSymbolFeatureCounted =
false;
3659 mSymbolFeatureCountMap.clear();
3660 mSymbolFeatureIdMap.clear();
3669 if ( !mDataProvider )
3675 QString ignoredError;
3679 mEditCommandActive =
true;
3685 if ( !mDataProvider )
3690 mEditCommandActive =
false;
3691 if ( !mDeletedFids.isEmpty() )
3694 mDeletedFids.clear();
3701 if ( !mDataProvider )
3712 std::unique_ptr< QUndoCommand > command = qgis::make_unique< QUndoCommand >();
3713 command->setObsolete(
true );
3716 mEditCommandActive =
false;
3717 mDeletedFids.clear();
3723 return mJoinBuffer->
addJoin( joinInfo );
3729 return mJoinBuffer->
removeJoin( joinLayerId );
3759 if ( oi < 0 || oi >= mExpressionFieldBuffer->
expressions().size() )
3762 return mExpressionFieldBuffer->
expressions().at( oi ).cachedExpression.expression();
3773 if ( !mDataProvider )
3778 mFields = mDataProvider->
fields();
3788 if ( mExpressionFieldBuffer )
3792 QMap< QString, QString >::const_iterator aliasIt = mAttributeAliasMap.constBegin();
3793 for ( ; aliasIt != mAttributeAliasMap.constEnd(); ++aliasIt )
3799 mFields[ index ].setAlias( aliasIt.value() );
3803 QMap< QString, QgsField::ConfigurationFlags >::const_iterator flagsIt = mFieldConfigurationFlags.constBegin();
3804 for ( ; flagsIt != mFieldConfigurationFlags.constEnd(); ++flagsIt )
3810 mFields[index].setConfigurationFlags( flagsIt.value() );
3814 mDefaultValueOnUpdateFields.clear();
3815 QMap< QString, QgsDefaultValue >::const_iterator defaultIt = mDefaultExpressionMap.constBegin();
3816 for ( ; defaultIt != mDefaultExpressionMap.constEnd(); ++defaultIt )
3818 int index = mFields.
lookupField( defaultIt.key() );
3822 mFields[ index ].setDefaultValueDefinition( defaultIt.value() );
3823 if ( defaultIt.value().applyOnUpdate() )
3824 mDefaultValueOnUpdateFields.insert( index );
3827 QMap< QString, QgsFieldConstraints::Constraints >::const_iterator constraintIt = mFieldConstraints.constBegin();
3828 for ( ; constraintIt != mFieldConstraints.constEnd(); ++constraintIt )
3830 int index = mFields.
lookupField( constraintIt.key() );
3843 mFields[ index ].setConstraints( constraints );
3846 QMap< QString, QPair< QString, QString > >::const_iterator constraintExpIt = mFieldConstraintExpressions.constBegin();
3847 for ( ; constraintExpIt != mFieldConstraintExpressions.constEnd(); ++constraintExpIt )
3849 int index = mFields.
lookupField( constraintExpIt.key() );
3860 mFields[ index ].setConstraints( constraints );
3864 for ( ; constraintStrengthIt != mFieldConstraintStrength.constEnd(); ++constraintStrengthIt )
3866 int index = mFields.
lookupField( constraintStrengthIt.key().first );
3876 constraints.
setConstraintStrength( constraintStrengthIt.key().second, constraintStrengthIt.value() );
3877 mFields[ index ].setConstraints( constraints );
3880 auto fieldWidgetIterator = mFieldWidgetSetups.constBegin();
3881 for ( ; fieldWidgetIterator != mFieldWidgetSetups.constEnd(); ++ fieldWidgetIterator )
3883 int index = mFields.
indexOf( fieldWidgetIterator.key() );
3887 mFields[index].setEditorWidgetSetup( fieldWidgetIterator.value() );
3890 if ( oldFields != mFields )
3893 mEditFormConfig.setFields( mFields );
3900 if ( index < 0 || index >= mFields.
count() || !mDataProvider )
3904 if ( expression.isEmpty() )
3908 std::unique_ptr< QgsExpressionContext > tempContext;
3913 evalContext = tempContext.get();
3946 if ( index < 0 || index >= mFields.
count() )
3951 mDefaultExpressionMap.insert( mFields.
at( index ).
name(), definition );
3955 mDefaultExpressionMap.remove( mFields.
at( index ).
name() );
3962 if ( index < 0 || index >= mFields.
count() )
3971 if ( !mDataProvider )
3990 for (
const QVariant &v : constUniqueValues )
3992 vals << v.toString();
3996 QMapIterator< QgsFeatureId, QgsFeature > addedIt( added );
3997 while ( addedIt.hasNext() && ( limit < 0 ||
uniqueValues.count() < limit ) )
4000 QVariant v = addedIt.value().attribute( index );
4003 QString vs = v.toString();
4004 if ( !vals.contains( vs ) )
4013 while ( it.hasNext() && ( limit < 0 ||
uniqueValues.count() < limit ) )
4016 QVariant v = it.value().value( index );
4019 QString vs = v.toString();
4020 if ( !vals.contains( vs ) )
4052 .setSubsetOfAttributes( attList ) );
4055 QVariant currentValue;
4056 QHash<QString, QVariant> val;
4060 val.insert( currentValue.toString(), currentValue );
4061 if ( limit >= 0 && val.size() >= limit )
4067 return qgis::listToSet( val.values() );
4071 Q_ASSERT_X(
false,
"QgsVectorLayer::uniqueValues()",
"Unknown source of the field!" );
4077 QStringList results;
4078 if ( !mDataProvider )
4096 QMapIterator< QgsFeatureId, QgsFeature > addedIt( added );
4097 while ( addedIt.hasNext() && ( limit < 0 || results.count() < limit ) && ( !feedback || !feedback->
isCanceled() ) )
4100 QVariant v = addedIt.value().attribute( index );
4103 QString vs = v.toString();
4104 if ( vs.contains( substring, Qt::CaseInsensitive ) && !results.contains( vs ) )
4112 while ( it.hasNext() && ( limit < 0 || results.count() < limit ) && ( !feedback || !feedback->
isCanceled() ) )
4115 QVariant v = it.value().value( index );
4118 QString vs = v.toString();
4119 if ( vs.contains( substring, Qt::CaseInsensitive ) && !results.contains( vs ) )
4150 QString fieldName = mFields.
at( index ).
name();
4151 request.
setFilterExpression( QStringLiteral(
"\"%1\" ILIKE '%%2%'" ).arg( fieldName, substring ) );
4155 QString currentValue;
4158 currentValue = f.
attribute( index ).toString();
4159 if ( !results.contains( currentValue ) )
4160 results << currentValue;
4162 if ( ( limit >= 0 && results.size() >= limit ) || ( feedback && feedback->
isCanceled() ) )
4172 Q_ASSERT_X(
false,
"QgsVectorLayer::uniqueStringsMatching()",
"Unknown source of the field!" );
4178 return minimumOrMaximumValue( index,
true );
4183 return minimumOrMaximumValue( index,
false );
4186 QVariant QgsVectorLayer::minimumOrMaximumValue(
int index,
bool minimum )
const
4188 if ( !mDataProvider )
4206 QMapIterator< QgsFeatureId, QgsFeature > addedIt( added );
4207 while ( addedIt.hasNext() )
4210 QVariant v = addedIt.value().attribute( index );
4219 while ( it.hasNext() )
4222 QVariant v = it.value().value( index );
4255 .setSubsetOfAttributes( attList ) );
4259 QVariant currentValue;
4260 bool firstValue =
true;
4264 if ( currentValue.isNull() )
4268 value = currentValue;
4275 value = currentValue;
4283 Q_ASSERT_X(
false,
"QgsVectorLayer::minimumOrMaximum()",
"Unknown source of the field!" );
4294 if ( !mDataProvider )
4300 int attrIndex = mFields.
lookupField( fieldOrExpression );
4301 if ( attrIndex >= 0 )
4308 bool providerOk =
false;
4309 QVariant val = mDataProvider->
aggregate(
aggregate, attrIndex, parameters, context, providerOk, fids );
4323 c.setFidsFilter( *fids );
4324 c.setParameters( parameters );
4325 return c.calculate(
aggregate, fieldOrExpression, context, ok );
4340 return mFeatureBlendMode;
4354 return mLayerOpacity;
4359 void QgsVectorLayer::readSldLabeling(
const QDomNode &node )
4364 QDomElement element = node.toElement();
4365 if ( element.isNull() )
4368 QDomElement userStyleElem = element.firstChildElement( QStringLiteral(
"UserStyle" ) );
4369 if ( userStyleElem.isNull() )
4371 QgsDebugMsgLevel( QStringLiteral(
"Info: UserStyle element not found." ), 4 );
4375 QDomElement featTypeStyleElem = userStyleElem.firstChildElement( QStringLiteral(
"FeatureTypeStyle" ) );
4376 if ( featTypeStyleElem.isNull() )
4378 QgsDebugMsgLevel( QStringLiteral(
"Info: FeatureTypeStyle element not found." ), 4 );
4383 QDomElement mergedFeatTypeStyle = featTypeStyleElem.cloneNode(
false ).toElement();
4388 bool needRuleBasedLabeling =
false;
4391 while ( !featTypeStyleElem.isNull() )
4393 QDomElement ruleElem = featTypeStyleElem.firstChildElement( QStringLiteral(
"Rule" ) );
4394 while ( !ruleElem.isNull() )
4398 bool hasTextSymbolizer =
false;
4399 bool hasRuleBased =
false;
4400 QDomElement ruleChildElem = ruleElem.firstChildElement();
4401 while ( !ruleChildElem.isNull() )
4404 if ( ruleChildElem.localName() == QLatin1String(
"Filter" ) ||
4405 ruleChildElem.localName() == QLatin1String(
"MinScaleDenominator" ) ||
4406 ruleChildElem.localName() == QLatin1String(
"MaxScaleDenominator" ) )
4408 hasRuleBased =
true;
4411 else if ( ruleChildElem.localName() == QLatin1String(
"TextSymbolizer" ) )
4413 QgsDebugMsgLevel( QStringLiteral(
"Info: TextSymbolizer element found" ), 4 );
4414 hasTextSymbolizer =
true;
4417 ruleChildElem = ruleChildElem.nextSiblingElement();
4420 if ( hasTextSymbolizer )
4425 mergedFeatTypeStyle.appendChild( ruleElem.cloneNode().toElement() );
4429 QgsDebugMsgLevel( QStringLiteral(
"Info: Filter or Min/MaxScaleDenominator element found: need a RuleBasedLabeling" ), 4 );
4430 needRuleBasedLabeling =
true;
4435 if ( ruleCount > 1 )
4437 QgsDebugMsgLevel( QStringLiteral(
"Info: More Rule elements found: need a RuleBasedLabeling" ), 4 );
4438 needRuleBasedLabeling =
true;
4442 if ( ruleCount == 0 )
4444 needRuleBasedLabeling =
false;
4447 ruleElem = ruleElem.nextSiblingElement( QStringLiteral(
"Rule" ) );
4449 featTypeStyleElem = featTypeStyleElem.nextSiblingElement( QStringLiteral(
"FeatureTypeStyle" ) );
4452 if ( ruleCount == 0 )
4454 QgsDebugMsgLevel( QStringLiteral(
"Info: No TextSymbolizer element." ), 4 );
4458 QDomElement ruleElem = mergedFeatTypeStyle.firstChildElement( QStringLiteral(
"Rule" ) );
4460 if ( needRuleBasedLabeling )
4464 while ( !ruleElem.isNull() )
4467 QString label, description, filterExp;
4468 int scaleMinDenom = 0, scaleMaxDenom = 0;
4472 QDomElement childElem = ruleElem.firstChildElement();
4473 while ( !childElem.isNull() )
4475 if ( childElem.localName() == QLatin1String(
"Name" ) )
4479 if ( label.isEmpty() )
4480 label = childElem.firstChild().nodeValue();
4482 else if ( childElem.localName() == QLatin1String(
"Description" ) )
4485 QDomElement titleElem = childElem.firstChildElement( QStringLiteral(
"Title" ) );
4486 if ( !titleElem.isNull() )
4488 label = titleElem.firstChild().nodeValue();
4491 QDomElement abstractElem = childElem.firstChildElement( QStringLiteral(
"Abstract" ) );
4492 if ( !abstractElem.isNull() )
4494 description = abstractElem.firstChild().nodeValue();
4497 else if ( childElem.localName() == QLatin1String(
"Abstract" ) )
4500 description = childElem.firstChild().nodeValue();
4502 else if ( childElem.localName() == QLatin1String(
"Title" ) )
4505 label = childElem.firstChild().nodeValue();
4507 else if ( childElem.localName() == QLatin1String(
"Filter" ) )
4523 else if ( childElem.localName() == QLatin1String(
"MinScaleDenominator" ) )
4526 int v = childElem.firstChild().nodeValue().toInt( &ok );
4530 else if ( childElem.localName() == QLatin1String(
"MaxScaleDenominator" ) )
4533 int v = childElem.firstChild().nodeValue().toInt( &ok );
4537 else if ( childElem.localName() == QLatin1String(
"TextSymbolizer" ) )
4539 readSldTextSymbolizer( childElem, settings );
4542 childElem = childElem.nextSiblingElement();
4548 ruleElem = ruleElem.nextSiblingElement();
4558 QDomElement textSymbolizerElem = ruleElem.firstChildElement( QStringLiteral(
"TextSymbolizer" ) );
4560 if ( readSldTextSymbolizer( textSymbolizerElem, s ) )
4568 bool QgsVectorLayer::readSldTextSymbolizer(
const QDomNode &node,
QgsPalLayerSettings &settings )
const
4570 if ( node.localName() != QLatin1String(
"TextSymbolizer" ) )
4572 QgsDebugMsgLevel( QStringLiteral(
"Not a TextSymbolizer element: %1" ).arg( node.localName() ), 3 );
4575 QDomElement textSymbolizerElem = node.toElement();
4577 QDomElement labelElem = textSymbolizerElem.firstChildElement( QStringLiteral(
"Label" ) );
4578 if ( !labelElem.isNull() )
4580 QDomElement propertyNameElem = labelElem.firstChildElement( QStringLiteral(
"PropertyName" ) );
4581 if ( !propertyNameElem.isNull() )
4586 QString labelAttribute = propertyNameElem.text();
4590 int fieldIndex = mFields.
lookupField( labelAttribute );
4591 if ( fieldIndex == -1 )
4595 if ( !exp.hasEvalError() )
4601 QgsDebugMsgLevel( QStringLiteral(
"SLD label attribute error: %1" ).arg( exp.evalErrorString() ), 3 );
4607 QgsDebugMsgLevel( QStringLiteral(
"Info: PropertyName element not found." ), 4 );
4618 if ( textSymbolizerElem.hasAttribute( QStringLiteral(
"uom" ) ) )
4623 QString fontFamily = QStringLiteral(
"Sans-Serif" );
4624 int fontPointSize = 10;
4626 int fontWeight = -1;
4627 bool fontItalic =
false;
4628 bool fontUnderline =
false;
4631 QDomElement fontElem = textSymbolizerElem.firstChildElement( QStringLiteral(
"Font" ) );
4632 if ( !fontElem.isNull() )
4635 for ( QgsStringMap::iterator it = fontSvgParams.begin(); it != fontSvgParams.end(); ++it )
4637 QgsDebugMsgLevel( QStringLiteral(
"found fontSvgParams %1: %2" ).arg( it.key(), it.value() ), 4 );
4639 if ( it.key() == QLatin1String(
"font-family" ) )
4641 fontFamily = it.value();
4643 else if ( it.key() == QLatin1String(
"font-style" ) )
4645 fontItalic = ( it.value() == QLatin1String(
"italic" ) ) || ( it.value() == QLatin1String(
"Italic" ) );
4647 else if ( it.key() == QLatin1String(
"font-size" ) )
4650 int fontSize = it.value().toInt( &ok );
4653 fontPointSize = fontSize;
4654 fontUnitSize = sldUnitSize;
4657 else if ( it.key() == QLatin1String(
"font-weight" ) )
4659 if ( ( it.value() == QLatin1String(
"bold" ) ) || ( it.value() == QLatin1String(
"Bold" ) ) )
4660 fontWeight = QFont::Bold;
4662 else if ( it.key() == QLatin1String(
"font-underline" ) )
4664 fontUnderline = ( it.value() == QLatin1String(
"underline" ) ) || ( it.value() == QLatin1String(
"Underline" ) );
4670 QFont font( fontFamily, fontPointSize, fontWeight, fontItalic );
4671 font.setUnderline( fontUnderline );
4673 format.
setSize( fontPointSize );
4677 QDomElement fillElem = textSymbolizerElem.firstChildElement( QStringLiteral(
"Fill" ) );
4679 Qt::BrushStyle textBrush = Qt::SolidPattern;
4681 if ( textColor.isValid() )
4683 QgsDebugMsgLevel( QStringLiteral(
"Info: textColor %1." ).arg( QVariant( textColor ).toString() ), 4 );
4690 QDomElement haloElem = textSymbolizerElem.firstChildElement( QStringLiteral(
"Halo" ) );
4691 if ( !haloElem.isNull() )
4696 QDomElement radiusElem = haloElem.firstChildElement( QStringLiteral(
"Radius" ) );
4697 if ( !radiusElem.isNull() )
4700 double bufferSize = radiusElem.text().toDouble( &ok );
4703 bufferSettings.
setSize( bufferSize );
4708 QDomElement haloFillElem = haloElem.firstChildElement( QStringLiteral(
"Fill" ) );
4710 Qt::BrushStyle bufferBrush = Qt::SolidPattern;
4712 if ( bufferColor.isValid() )
4714 QgsDebugMsgLevel( QStringLiteral(
"Info: bufferColor %1." ).arg( QVariant( bufferColor ).toString() ), 4 );
4715 bufferSettings.
setColor( bufferColor );
4720 QDomElement labelPlacementElem = textSymbolizerElem.firstChildElement( QStringLiteral(
"LabelPlacement" ) );
4721 if ( !labelPlacementElem.isNull() )
4724 QDomElement pointPlacementElem = labelPlacementElem.firstChildElement( QStringLiteral(
"PointPlacement" ) );
4725 if ( !pointPlacementElem.isNull() )
4733 QDomElement displacementElem = pointPlacementElem.firstChildElement( QStringLiteral(
"Displacement" ) );
4734 if ( !displacementElem.isNull() )
4736 QDomElement displacementXElem = displacementElem.firstChildElement( QStringLiteral(
"DisplacementX" ) );
4737 if ( !displacementXElem.isNull() )
4740 double xOffset = displacementXElem.text().toDouble( &ok );
4747 QDomElement displacementYElem = displacementElem.firstChildElement( QStringLiteral(
"DisplacementY" ) );
4748 if ( !displacementYElem.isNull() )
4751 double yOffset = displacementYElem.text().toDouble( &ok );
4759 QDomElement anchorPointElem = pointPlacementElem.firstChildElement( QStringLiteral(
"AnchorPoint" ) );
4760 if ( !anchorPointElem.isNull() )
4762 QDomElement anchorPointXElem = anchorPointElem.firstChildElement( QStringLiteral(
"AnchorPointX" ) );
4763 if ( !anchorPointXElem.isNull() )
4766 double xOffset = anchorPointXElem.text().toDouble( &ok );
4773 QDomElement anchorPointYElem = anchorPointElem.firstChildElement( QStringLiteral(
"AnchorPointY" ) );
4774 if ( !anchorPointYElem.isNull() )
4777 double yOffset = anchorPointYElem.text().toDouble( &ok );
4786 QDomElement rotationElem = pointPlacementElem.firstChildElement( QStringLiteral(
"Rotation" ) );
4787 if ( !rotationElem.isNull() )
4790 double rotation = rotationElem.text().toDouble( &ok );
4800 QDomElement linePlacementElem = labelPlacementElem.firstChildElement( QStringLiteral(
"LinePlacement" ) );
4801 if ( !linePlacementElem.isNull() )
4810 QDomElement vendorOptionElem = textSymbolizerElem.firstChildElement( QStringLiteral(
"VendorOption" ) );
4811 while ( !vendorOptionElem.isNull() && vendorOptionElem.localName() == QLatin1String(
"VendorOption" ) )
4813 QString optionName = vendorOptionElem.attribute( QStringLiteral(
"name" ) );
4814 QString optionValue;
4815 if ( vendorOptionElem.firstChild().nodeType() == QDomNode::TextNode )
4817 optionValue = vendorOptionElem.firstChild().nodeValue();
4821 if ( vendorOptionElem.firstChild().nodeType() == QDomNode::ElementNode &&
4822 vendorOptionElem.firstChild().localName() == QLatin1String(
"Literal" ) )
4824 QgsDebugMsg( vendorOptionElem.firstChild().localName() );
4825 optionValue = vendorOptionElem.firstChild().firstChild().nodeValue();
4829 QgsDebugMsg( QStringLiteral(
"unexpected child of %1 named %2" ).arg( vendorOptionElem.localName(), optionName ) );
4833 if ( !optionName.isEmpty() && !optionValue.isEmpty() )
4835 vendorOptions[ optionName ] = optionValue;
4838 vendorOptionElem = vendorOptionElem.nextSiblingElement();
4840 if ( !vendorOptions.isEmpty() )
4842 for ( QgsStringMap::iterator it = vendorOptions.begin(); it != vendorOptions.end(); ++it )
4844 if ( it.key() == QLatin1String(
"underlineText" ) && it.value() == QLatin1String(
"true" ) )
4846 font.setUnderline(
true );
4849 else if ( it.key() == QLatin1String(
"strikethroughText" ) && it.value() == QLatin1String(
"true" ) )
4851 font.setStrikeOut(
true );
4854 else if ( it.key() == QLatin1String(
"maxDisplacement" ) )
4858 else if ( it.key() == QLatin1String(
"followLine" ) && it.value() == QLatin1String(
"true" ) )
4869 else if ( it.key() == QLatin1String(
"maxAngleDelta" ) )
4872 double angle = it.value().toDouble( &ok );
4880 else if ( it.key() == QLatin1String(
"conflictResolution" ) && it.value() == QLatin1String(
"false" ) )
4884 else if ( it.key() == QLatin1String(
"forceLeftToRight" ) && it.value() == QLatin1String(
"false" ) )
4888 else if ( it.key() == QLatin1String(
"group" ) && it.value() == QLatin1String(
"yes" ) )
4892 else if ( it.key() == QLatin1String(
"labelAllGroup" ) && it.value() == QLatin1String(
"true" ) )
4906 return mEditFormConfig;
4915 mEditFormConfig.onRelationsLoaded();
4921 return mMapTipTemplate;
4926 if ( mMapTipTemplate == mapTip )
4929 mMapTipTemplate = mapTip;
4964 if ( !mDiagramLayerSettings )
4966 *mDiagramLayerSettings = s;
4972 QString myMetadata = QStringLiteral(
"<html>\n<body>\n" );
4975 myMetadata += QStringLiteral(
"<h1>" ) + tr(
"Information from provider" ) + QStringLiteral(
"</h1>\n<hr>\n" );
4976 myMetadata += QLatin1String(
"<table class=\"list-view\">\n" );
4979 myMetadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"Name" ) + QStringLiteral(
"</td><td>" ) +
name() + QStringLiteral(
"</td></tr>\n" );
4984 if ( uriComponents.contains( QStringLiteral(
"path" ) ) )
4986 path = uriComponents[QStringLiteral(
"path" )].toString();
4987 if ( QFile::exists( path ) )
4988 myMetadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"Path" ) + QStringLiteral(
"</td><td>%1" ).arg( QStringLiteral(
"<a href=\"%1\">%2</a>" ).arg( QUrl::fromLocalFile( path ).toString(), QDir::toNativeSeparators( path ) ) ) + QStringLiteral(
"</td></tr>\n" );
4990 if ( uriComponents.contains( QStringLiteral(
"url" ) ) )
4992 const QString url = uriComponents[QStringLiteral(
"url" )].toString();
4993 myMetadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"URL" ) + QStringLiteral(
"</td><td>%1" ).arg( QStringLiteral(
"<a href=\"%1\">%2</a>" ).arg( QUrl( url ).toString(), url ) ) + QStringLiteral(
"</td></tr>\n" );
4998 myMetadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"Source" ) + QStringLiteral(
"</td><td>%1" ).arg(
publicSource() ) + QStringLiteral(
"</td></tr>\n" );
5001 myMetadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"Storage" ) + QStringLiteral(
"</td><td>" ) +
storageType() + QStringLiteral(
"</td></tr>\n" );
5004 myMetadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"Comment" ) + QStringLiteral(
"</td><td>" ) +
dataComment() + QStringLiteral(
"</td></tr>\n" );
5010 myMetadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"Encoding" ) + QStringLiteral(
"</td><td>" ) + provider->
encoding() + QStringLiteral(
"</td></tr>\n" );
5025 myMetadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"Geometry" ) + QStringLiteral(
"</td><td>" ) + typeString + QStringLiteral(
"</td></tr>\n" );
5029 myMetadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"CRS" ) + QStringLiteral(
"</td><td>" );
5033 if (
crs().isGeographic() )
5034 myMetadata += tr(
"Geographic" );
5036 myMetadata += tr(
"Projected" );
5038 myMetadata += QLatin1String(
"</td></tr>\n" );
5041 myMetadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"Extent" ) + QStringLiteral(
"</td><td>" ) +
extent().
toString() + QStringLiteral(
"</td></tr>\n" );
5044 myMetadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"Unit" ) + QStringLiteral(
"</td><td>" ) +
QgsUnitTypes::toString(
crs().mapUnits() ) + QStringLiteral(
"</td></tr>\n" );
5049 QLocale locale = QLocale();
5050 locale.setNumberOptions( locale.numberOptions() &= ~QLocale::NumberOption::OmitGroupSeparator );
5051 myMetadata += QStringLiteral(
"<tr><td class=\"highlight\">" )
5052 + tr(
"Feature count" ) + QStringLiteral(
"</td><td>" )
5054 + QStringLiteral(
"</td></tr>\n" );
5057 myMetadata += QLatin1String(
"</table>\n<br><br>" );
5060 myMetadata += QStringLiteral(
"<h1>" ) + tr(
"Identification" ) + QStringLiteral(
"</h1>\n<hr>\n" );
5062 myMetadata += QLatin1String(
"<br><br>\n" );
5065 myMetadata += QStringLiteral(
"<h1>" ) + tr(
"Extent" ) + QStringLiteral(
"</h1>\n<hr>\n" );
5067 myMetadata += QLatin1String(
"<br><br>\n" );
5070 myMetadata += QStringLiteral(
"<h1>" ) + tr(
"Access" ) + QStringLiteral(
"</h1>\n<hr>\n" );
5072 myMetadata += QLatin1String(
"<br><br>\n" );
5075 myMetadata += QStringLiteral(
"<h1>" ) + tr(
"Fields" ) + QStringLiteral(
"</h1>\n<hr>\n<table class=\"list-view\">\n" );
5079 if ( !pkAttrList.isEmpty() )
5081 myMetadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"Primary key attributes" ) + QStringLiteral(
"</td><td>" );
5082 const auto constPkAttrList = pkAttrList;
5083 for (
int idx : constPkAttrList )
5087 myMetadata += QLatin1String(
"</td></tr>\n" );
5093 myMetadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"Count" ) + QStringLiteral(
"</td><td>" ) + QString::number( myFields.
size() ) + QStringLiteral(
"</td></tr>\n" );
5095 myMetadata += QLatin1String(
"</table>\n<br><table width=\"100%\" class=\"tabular-view\">\n" );
5096 myMetadata += QLatin1String(
"<tr><th>" ) + tr(
"Field" ) + QLatin1String(
"</th><th>" ) + tr(
"Type" ) + QLatin1String(
"</th><th>" ) + tr(
"Length" ) + QLatin1String(
"</th><th>" ) + tr(
"Precision" ) + QLatin1String(
"</th><th>" ) + tr(
"Comment" ) + QLatin1String(
"</th></tr>\n" );
5098 for (
int i = 0; i < myFields.
size(); ++i )
5103 rowClass = QStringLiteral(
"class=\"odd-row\"" );
5104 myMetadata += QLatin1String(
"<tr " ) + rowClass + QLatin1String(
"><td>" ) + myField.
name() + QLatin1String(
"</td><td>" ) + myField.
typeName() + QLatin1String(
"</td><td>" ) + QString::number( myField.
length() ) + QLatin1String(
"</td><td>" ) + QString::number( myField.
precision() ) + QLatin1String(
"</td><td>" ) + myField.
comment() + QLatin1String(
"</td></tr>\n" );
5108 myMetadata += QLatin1String(
"</table>\n<br><br>" );
5111 myMetadata += QStringLiteral(
"<h1>" ) + tr(
"Contacts" ) + QStringLiteral(
"</h1>\n<hr>\n" );
5113 myMetadata += QLatin1String(
"<br><br>\n" );
5116 myMetadata += QStringLiteral(
"<h1>" ) + tr(
"Links" ) + QStringLiteral(
"</h1>\n<hr>\n" );
5118 myMetadata += QLatin1String(
"<br><br>\n" );
5121 myMetadata += QStringLiteral(
"<h1>" ) + tr(
"History" ) + QStringLiteral(
"</h1>\n<hr>\n" );
5123 myMetadata += QLatin1String(
"<br><br>\n" );
5125 myMetadata += QLatin1String(
"\n</body>\n</html>\n" );
5129 void QgsVectorLayer::invalidateSymbolCountedFlag()
5131 mSymbolFeatureCounted =
false;
5134 void QgsVectorLayer::onFeatureCounterCompleted()
5137 mFeatureCounter =
nullptr;
5140 void QgsVectorLayer::onFeatureCounterTerminated()
5142 mFeatureCounter =
nullptr;
5145 void QgsVectorLayer::onJoinedFieldsChanged()
5151 void QgsVectorLayer::onFeatureDeleted(
QgsFeatureId fid )
5153 if ( mEditCommandActive )
5154 mDeletedFids << fid;
5161 void QgsVectorLayer::onRelationsLoaded()
5163 mEditFormConfig.onRelationsLoaded();
5166 void QgsVectorLayer::onSymbolsCounted()
5168 if ( mFeatureCounter )
5170 mSymbolFeatureCounted =
true;
5184 return mWeakRelations;
5204 bool useAsDefault,
const QString &uiFileContent, QString &msgError )
5207 QString sldStyle, qmlStyle;
5208 QDomDocument qmlDocument, sldDocument;
5211 if ( !msgError.isNull() )
5215 qmlStyle = qmlDocument.toString();
5218 if ( !msgError.isNull() )
5222 sldStyle = sldDocument.toString();
5226 description, uiFileContent, useAsDefault, msgError );
5240 QString joinKey = mAuxiliaryLayerKey;
5241 if ( !key.isEmpty() )
5244 if ( storage.
isValid() && !joinKey.isEmpty() )
5267 mAuxiliaryLayerKey.clear();
5269 if ( mAuxiliaryLayer )
5282 mAuxiliaryLayer.reset( alayer );
5283 if ( mAuxiliaryLayer )
5284 mAuxiliaryLayer->setParent(
this );
5290 return mAuxiliaryLayer.get();
5295 return mAuxiliaryLayer.get();
5301 QString returnMessage;
5302 QString qml, errorMsg;
5307 if ( !qml.isEmpty() )
5309 QDomDocument myDocument( QStringLiteral(
"qgis" ) );
5310 myDocument.setContent( qml );
5312 returnMessage = QObject::tr(
"Loaded from Provider" );
5322 return returnMessage;
5327 if ( mDataProvider )
5332 void QgsVectorLayer::emitDataChanged()
5334 if ( mDataChangedFired )
5339 mDataChangedFired =
true;
5341 mDataChangedFired =
false;
5344 void QgsVectorLayer::onAfterCommitChangesDependency()
5346 mDataChangedFired =
true;
5352 QSet<QgsMapLayerDependency> deps;
5353 const auto constODeps = oDeps;
5360 QSet<QgsMapLayerDependency> toAdd = deps -
dependencies();
5377 if ( mDataProvider )
5398 if ( ! toAdd.isEmpty() )
5406 if ( fieldIndex < 0 || fieldIndex >= mFields.
count() || !mDataProvider )
5407 return QgsFieldConstraints::Constraints();
5422 QMap< QgsFieldConstraints::Constraint, QgsFieldConstraints::ConstraintStrength > m;
5424 if ( fieldIndex < 0 || fieldIndex >= mFields.
count() )
5427 QString
name = mFields.
at( fieldIndex ).
name();
5430 for ( ; conIt != mFieldConstraintStrength.constEnd(); ++conIt )
5432 if ( conIt.key().first ==
name )
5434 m[ conIt.key().second ] = mFieldConstraintStrength.value( conIt.key() );
5443 if ( index < 0 || index >= mFields.
count() )
5449 QgsFieldConstraints::Constraints constraints = mFieldConstraints.value(
name, QgsFieldConstraints::Constraints() );
5450 constraints |= constraint;
5451 mFieldConstraints.insert(
name, constraints );
5453 mFieldConstraintStrength.insert( qMakePair(
name, constraint ), strength );
5460 if ( index < 0 || index >= mFields.
count() )
5466 QgsFieldConstraints::Constraints constraints = mFieldConstraints.value(
name, QgsFieldConstraints::Constraints() );
5467 constraints &= ~constraint;
5468 mFieldConstraints.insert(
name, constraints );
5470 mFieldConstraintStrength.remove( qMakePair(
name, constraint ) );
5477 if ( index < 0 || index >= mFields.
count() )
5485 if ( index < 0 || index >= mFields.
count() )
5493 if ( index < 0 || index >= mFields.
count() )
5496 if ( expression.isEmpty() )
5498 mFieldConstraintExpressions.remove( mFields.
at( index ).
name() );
5502 mFieldConstraintExpressions.insert( mFields.
at( index ).
name(), qMakePair( expression, description ) );
5509 if ( index < 0 || index >= mFields.
count() )
5512 mFieldConfigurationFlags.insert( mFields.
at( index ).
name(),
flags );
5518 if ( index < 0 || index >= mFields.
count() )
5521 flags.setFlag( flag, active );
5528 if ( index < 0 || index >= mFields.
count() )
5536 if ( index < 0 || index >= mFields.
count() )
5540 mFieldWidgetSetups.remove( mFields.
at( index ).
name() );
5542 mFieldWidgetSetups.insert( mFields.
at( index ).
name(), setup );
5549 if ( index < 0 || index >= mFields.
count() )
5558 if (
customProperty( QStringLiteral(
"labeling" ) ).toString() == QLatin1String(
"pal" ) )
5560 if (
customProperty( QStringLiteral(
"labeling/enabled" ), QVariant(
false ) ).toBool() )
5564 settings.readFromLayerCustomProperties(
this );
5571 for (
const QString &key : constCustomPropertyKeys )
5573 if ( key.startsWith( QLatin1String(
"labeling/" ) ) )
5583 return mAllowCommit;
5597 return mGeometryOptions.get();
5607 return mReadExtentFromXml;
5610 void QgsVectorLayer::onDirtyTransaction(
const QString &sql,
const QString &name )
5613 if ( tr && mEditBuffer )
5615 qobject_cast<QgsVectorLayerEditPassthrough *>( mEditBuffer )->update( tr, sql,
name );
5621 QList<QgsVectorLayer *> layers;
5622 QMap<QgsVectorLayer *, QgsFeatureIds>::const_iterator i;
5625 if ( includeAuxiliaryLayers || !qobject_cast< QgsAuxiliaryLayer * >( i.key() ) )
5626 layers.append( i.key() );
5633 return mHandledFeatures[layer];
Abstract base class for curved geometry type.
void setRenderer(QgsFeatureRenderer *r)
Sets renderer which will be invoked to represent this layer.
QString sourceName() const FINAL
Returns a friendly display name for the source.
@ OriginProvider
Field comes from the underlying data provider of the vector layer (originIndex = index in provider's ...
@ NoGeometry
Geometry is not required. It may still be returned if e.g. required for a filter condition.
Counts the features in a QgsVectorLayer in task.
void setDiagramRenderer(QgsDiagramRenderer *r)
Sets diagram rendering object (takes ownership)
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const FINAL
Queries the layer for features specified in request.
void willBeDeleted()
Emitted in the destructor when the layer is about to be deleted, but it is still in a perfectly valid...
VertexMarkerType
Editing vertex markers.
void setSizeUnit(QgsUnitTypes::RenderUnit unit)
Sets the units used for the buffer size.
bool loadDefaultStyle
Set to true if the default layer style should be loaded.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
static void writeXml(const QgsVectorLayer *layer, WeakRelationType type, const QgsRelation &relation, QDomNode &node, QDomDocument &doc)
Writes a weak relation infoto an XML structure.
QgsRelationManager * relationManager
QgsCoordinateReferenceSystem crs
bool addFeatures(QgsFeatureList &features, QgsFeatureSink::Flags flags=QgsFeatureSink::Flags()) FINAL
Adds a list of features to the sink.
void beforeRemovingExpressionField(int idx)
Will be emitted, when an expression field is going to be deleted from this vector layer.
void writeXml(QDomNode &layer_node, QDomDocument &document) const
Saves expressions to xml under the layer node.
Q_INVOKABLE void removeSelection()
Clear selection.
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the scope.
bool useEstimatedMetadata() const
Returns true if estimated metadata should be used for the connection.
virtual QString getStyleFromDatabase(const QString &styleId, QString &msgError)
Returns the named style corresponding to style id provided.
void setReadExtentFromXml(bool readExtentFromXml)
Flag allowing to indicate if the extent has to be read from the XML document when data source has no ...
void setForceLocalOptimization(bool localOptimization)
Sets where the simplification executes, after fetch the geometries from provider, or when supported,...
void readCommonStyle(const QDomElement &layerElement, const QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories)
Read style data common to all layer types.
void dependenciesChanged()
Emitted when dependencies are changed.
virtual void saveStyleToDatabase(const QString &name, const QString &description, bool useAsDefault, const QString &uiFileContent, QString &msgError)
Saves named and sld style of the layer to the style table in the db.
bool diagramsEnabled() const
Returns whether the layer contains diagrams which are enabled and should be drawn.
@ OriginEdit
Field has been temporarily added in editing mode (originIndex = index in the list of added attributes...
QUuid addAction(QgsAction::ActionType type, const QString &name, const QString &command, bool capture=false)
Add an action with the given name and action details.
double height() const SIP_HOLDGIL
Returns the height of the rectangle.
@ DeleteFeatures
Allows deletion of features.
QPainter::CompositionMode featureBlendMode() const
Returns the current blending mode for features.
static QgsProperty fromField(const QString &fieldName, bool isActive=true)
Returns a new FieldBasedProperty created from the specified field name.
static QgsFeatureRenderer * defaultRenderer(QgsWkbTypes::GeometryType geomType)
Returns a new renderer - used by default in vector layers.
virtual SpatialIndexPresence hasSpatialIndex() const
Returns an enum value representing the presence of a valid spatial index on the source,...
QgsExpressionContextScope * createExpressionContextScope() const FINAL
This method needs to be reimplemented in all classes which implement this interface and return an exp...
virtual void resolveReferences(QgsProject *project)
Resolve references to other layers (kept as layer IDs after reading XML) into layer objects.
QgsFeatureIds symbolFeatureIds(const QString &legendKey) const
Ids of features rendered with specified legend key.
Class for storing the component parts of a RDBMS data source URI (e.g.
@ PerimeterCurved
Arranges candidates following the curvature of a polygon's boundary. Applies to polygon layers only.
QString qgsFlagValueToKeys(const T &value)
Returns the value for the given keys of a flag.
static QgsExpression * expressionFromOgcFilter(const QDomElement &element, QgsVectorLayer *layer=nullptr)
Parse XML with OGC filter into QGIS expression.
Utility class for calculating aggregates for a field (or expression) over the features from a vector ...
@ CreateRenderer
Provider can create feature renderers using backend-specific formatting information....
Contains information about the context in which a coordinate transform is executed.
void setConstraintExpression(const QString &expression, const QString &description=QString())
Set the constraint expression for the field.
Q_INVOKABLE QgsWkbTypes::Type wkbType() const FINAL
Returns the WKBType or WKBUnknown in case of error.
static QString displayString(Type type) SIP_HOLDGIL
Returns a display string type for a WKB type, e.g., the geometry name used in WKT geometry representa...
@ FlagTrustLayerMetadata
Trust layer metadata. Improves layer load time by skipping expensive checks like primary key unicity,...
Q_INVOKABLE void selectAll()
Select all the features.
QString password() const
Returns the password stored in the URI.
double angleOffset
Label rotation, in degrees clockwise.
void setFont(const QFont &font)
Sets the font used for rendering text.
virtual QString dataComment() const override
Returns a short comment for the data that this provider is providing access to (e....
void configChanged()
Emitted whenever the configuration is changed.
RenderUnit
Rendering size units.
bool moveVertex(double x, double y, QgsFeatureId atFeatureId, int atVertex)
Moves the vertex at the given position number, ring and item (first number is index 0),...
virtual QgsAttributeList pkAttributeIndexes() const
Returns list of indexes of fields that make up the primary key.
The QgsDefaultValue class provides a container for managing client side default values for fields.
virtual void updateExtents(bool force=false)
Update the extents for the layer.
QStringList uniqueStringsMatching(int index, const QString &substring, int limit=-1, QgsFeedback *feedback=nullptr) const
Returns unique string values of an attribute which contain a specified subset string.
@ AroundPoint
Arranges candidates in a circle around a point (or centroid of a polygon). Applies to point or polygo...
virtual bool isModified() const
Returns true if the provider has been modified since the last commit.
void setConstraint(Constraint constraint, ConstraintOrigin origin=ConstraintOriginLayer)
Sets a constraint on the field.
Setting options for creating vector data providers.
void combineExtentWith(const QgsRectangle &rect)
Expands the rectangle so that it covers both the original rectangle and the given rectangle.
Q_DECL_DEPRECATED QgsGeometry::OperationResult splitParts(const QVector< QgsPointXY > &splitLine, bool topologicalEditing=false)
Splits parts cut by the given line.
BlendMode
Blending modes enum defining the available composition modes that can be used when rendering a layer.
QgsExpressionContextScope * popScope()
Removes the last scope from the expression context and return it.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
void updateFields()
Will regenerate the fields property of this layer by obtaining all fields from the dataProvider,...
The class is used as a container of context for various read/write operations on other objects.
@ ExactIntersect
Use exact geometry intersection (slower) instead of bounding boxes.
double maxCurvedCharAngleOut
Maximum angle between outside curved label characters (valid range -20.0 to -95.0)
QString evalErrorString() const
Returns evaluation error.
Class allowing to manage the auxiliary storage for a vector layer.
void featuresDeleted(const QgsFeatureIds &fids)
Emitted when features have been deleted.
void raiseError(const QString &msg) const
Signals an error in this provider.
ConfigurationFlag
Configuration flags for fields These flags are meant to be user-configurable and are not describing a...
QSet< QString > referencedColumns() const
Gets list of columns referenced by the expression.
void layerModified()
Emitted when modifications has been done on layer.
Point geometry type, with support for z-dimension and m-values.
QgsFeatureIds mDeletedFeatureIds
Deleted feature IDs which are not committed.
QString userFriendlyIdentifier(IdentifierType type=MediumString) const
Returns a user friendly identifier for the CRS.
bool isEmpty() const
Checks whether the container is empty.
void writeXml(QDomNode &layer_node, QDomDocument &document) const
Saves mVectorJoins to xml under the layer node.
void setMapTipTemplate(const QString &mapTipTemplate)
The mapTip is a pretty, html representation for feature information.
bool insertVertex(double x, double y, QgsFeatureId atFeatureId, int beforeVertex)
Inserts a new vertex before the given vertex number, in the given ring, item (first number is index 0...
void committedAttributesAdded(const QString &layerId, const QList< QgsField > &addedAttributes)
Emitted when attributes are added to the provider.
QString attributeAlias(int index) const
Returns the alias of an attribute name or a null string if there is no alias.
void setDefaultValueDefinition(int index, const QgsDefaultValue &definition)
Sets the definition of the expression to use when calculating the default value for a field.
#define QgsDebugMsgLevel(str, level)
virtual bool addAttribute(const QgsField &field)
Add an attribute field (but does not commit it) returns true if the field was added.
void setFlags(QgsMapLayer::LayerFlags flags)
Returns the flags for this layer.
void committedGeometriesChanges(const QString &layerId, const QgsGeometryMap &changedGeometries)
virtual QgsMapLayer * clone() const =0
Returns a new instance equivalent to this one except for the id which is still unique.
QMap< QString, QgsMapLayer * > mapLayers(const bool validOnly=false) const
Returns a map of all registered layers by layer ID.
QPainter::CompositionMode blendMode() const
Returns the current blending mode for a layer.
QHash< QString, QgsFeatureIds > symbolFeatureIdMap() const
Returns the QgsFeatureIds for each symbol.
virtual bool accept(QgsStyleEntityVisitorInterface *visitor) const
Accepts the specified symbology visitor, causing it to visit all symbols associated with the renderer...
Q_INVOKABLE void setCustomProperty(const QString &key, const QVariant &value)
Set a custom property for layer.
@ RemoveFromSelection
Remove from current selection.
void setEnabled(bool enabled)
Sets whether the text buffer will be drawn.
virtual void handlePostCloneOperations(QgsVectorDataProvider *source)
Handles any post-clone operations required after this vector data provider was cloned from the source...
A bundle of parameters controlling aggregate calculation.
Stores information about constraints which may be present on a field.
bool qgsVariantLessThan(const QVariant &lhs, const QVariant &rhs)
Compares two QVariant values and returns whether the first is less than the second.
QgsMapLayer::ReadFlags mReadFlags
Read flags. It's up to the subclass to respect these when restoring state from XML.
QString encoding() const
Returns the encoding which is used for accessing data.
QgsFields fields() const override=0
Returns the fields associated with this data provider.
void beforeRollBack()
Emitted before changes are rolled back.
void setThreshold(float threshold)
Sets the simplification threshold of the vector layer managed.
SimplifyHint
Simplification flags for fast rendering of features.
virtual bool setSubsetString(const QString &subset, bool updateFeatureCount=true)
Set the subset string used to create a subset of features in the layer.
Context for cascade delete features.
bool writeXml(QDomNode &node, QDomDocument &doc, const QgsReadWriteContext &context) const
Writes the condition styles state to a DOM node.
Q_DECL_DEPRECATED QgsGeometry::OperationResult splitParts(const QVector< QgsPointXY > &splitLine, bool topologicalEditing=false)
Splits parts cut by the given line.
QgsCoordinateTransformContext transformContext
Coordinate transform context.
virtual bool importNamedStyle(QDomDocument &doc, QString &errorMsg, QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories)
Import the properties of this layer from a QDomDocument.
@ None
No flag is defined.
const QgsExpressionNode * rootNode() const
Returns the root node of the expression.
An expression node which takes it value from a feature's field.
virtual bool addFeature(QgsFeature &feature, QgsFeatureSink::Flags flags=QgsFeatureSink::Flags())
Adds a single feature to the sink.
Q_DECL_DEPRECATED QgsGeometry::OperationResult splitFeatures(const QVector< QgsPointXY > &splitLine, bool topologicalEditing=false)
Splits features cut by the given line.
@ FlagTrustDataSource
Trust datasource config (primary key unicity, geometry type and srid, etc). Improves provider load ti...
QgsPathResolver pathResolver() const
Returns path resolver object with considering whether the project uses absolute or relative paths and...
@ RenderPoints
Points (e.g., for font sizes)
UpsideDownLabels upsidedownLabels
Controls whether upside down labels are displayed and how they are handled.
void beforeEditingStarted()
Emitted before editing on this layer is started.
QgsMapLayerType
Types of layers that can be added to a map.
int addExpressionField(const QString &exp, const QgsField &fld)
Add a new field which is calculated by the expression specified.
int count() const
Returns number of items.
Container of fields for a vector layer.
long featureCount() const FINAL
Returns feature count including changes which have not yet been committed If you need only the count ...
double yMinimum() const SIP_HOLDGIL
Returns the y minimum value (bottom side of rectangle).
int listStyles(const QString &providerKey, const QString &uri, QStringList &ids, QStringList &names, QStringList &descriptions, QString &errCause)
Lists stored layer styles in the provider defined by providerKey and uri.
void writeCustomProperties(QDomNode &layerNode, QDomDocument &doc) const
Write custom properties to project file.
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
QgsGeometryOptions * geometryOptions() const
Configuration and logic to apply automatically on any edit happening on this layer.
QSet< QgsMapLayerDependency > dependencies() const FINAL
Gets the list of dependencies.
Manages QGIS Server properties for a vector layer.
bool isAuxiliaryField(int index, int &srcIndex) const
Returns true if the field comes from the auxiliary layer, false otherwise.
void opacityChanged(double opacity)
Emitted when the layer's opacity is changed, where opacity is a value between 0 (transparent) and 1 (...
QgsAttributeList mDeletedAttributeIds
Deleted attributes fields which are not committed. The list is kept sorted.
double yOffset
Vertical offset of label.
void attributeDeleted(int idx)
Will be emitted, when an attribute has been deleted from this vector layer.
@ AttributeTable
Attribute table settings: choice and order of columns, conditional styling.
QString constraintExpression() const
Returns the constraint expression for the field, if set.
SimplifyAlgorithm simplifyAlgorithm() const
Gets the local simplification algorithm of the vector layer managed.
virtual QString loadNamedStyle(const QString &theURI, bool &resultFlag, bool loadFromLocalDb, QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories)
Loads a named style from file/local db/datasource db.
void setAllowCommit(bool allowCommit)
Controls, if the layer is allowed to commit changes.
QVariant aggregate(QgsAggregateCalculator::Aggregate aggregate, const QString &fieldOrExpression, const QgsAggregateCalculator::AggregateParameters ¶meters=QgsAggregateCalculator::AggregateParameters(), QgsExpressionContext *context=nullptr, bool *ok=nullptr, QgsFeatureIds *fids=nullptr) const
Calculates an aggregated value from the layer's features.
static QString geometryDisplayString(GeometryType type) SIP_HOLDGIL
Returns a display string for a geometry type.
QString constraintExpression(int index) const
Returns the constraint expression for for a specified field index, if set.
virtual bool empty() const
Returns true if the layer does not contain any feature.
Q_INVOKABLE void selectByRect(QgsRectangle &rect, QgsVectorLayer::SelectBehavior behavior=QgsVectorLayer::SetSelection)
Selects features found within the search rectangle (in layer's coordinates)
The QgsGeometryOptions class contains options to automatically adjust geometries to constraints on a ...
Contains information about the context of a rendering operation.
void setMinimal() SIP_HOLDGIL
Set a rectangle so that min corner is at max and max corner is at min.
virtual QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context) const
Writes configuration to a DOM element, to be used later with readXml()
static QgsProject * instance()
Returns the QgsProject singleton instance.
void beforeCommitChanges(bool stopEditing)
Emitted before changes are committed to the data provider.
const QgsVectorLayerJoinInfo * joinForFieldIndex(int index, const QgsFields &fields, int &sourceFieldIndex) const
Finds the vector join for a layer field index.
@ Composition
Fix relation, related elements are part of the parent and a parent copy will copy any children or del...
Q_INVOKABLE void selectByExpression(const QString &expression, QgsVectorLayer::SelectBehavior behavior=QgsVectorLayer::SetSelection)
Selects matching features using an expression.
QString typeName() const
Gets the field type.
void setDatabase(const QString &database)
Sets the URI database name.
An interface for classes which can visit style entity (e.g.
bool writeXml(QDomNode &layer_node) const
Writes the actions out in XML format.
bool isSpatial() const FINAL
Returns true if this is a geometry layer and false in case of NoGeometry (table only) or UnknownGeome...
@ Double
Double value (including negative values)
void readXml(const QDomNode &layer_node)
Reads joins from project file.
bool isValid() const
Returns if this default value should be applied.
virtual QgsTransaction * transaction() const
Returns the transaction this data provider is included in, if any.
bool deleteStyleById(const QString &providerKey, const QString &uri, QString styleId, QString &errCause)
Deletes a layer style defined by styleId.
virtual bool deleteStyleFromDatabase(const QString &styleId, QString &msgError)
Deletes a style from the database.
QgsAuxiliaryLayer * auxiliaryLayer()
Returns the current auxiliary layer.
virtual void toSld(QDomNode &parent, const QgsStringMap &props) const
Writes the SE 1.1 TextSymbolizer element based on the current layer labeling settings.
static QList< QgsExpressionContextScope * > globalProjectLayerScopes(const QgsMapLayer *layer)
Creates a list of three scopes: global, layer's project and layer.
void setDiagramLayerSettings(const QgsDiagramLayerSettings &s)
void guessDefaultsFromFields(const QgsFields &fields)
Attempts to setup the temporal properties by scanning a set of fields and looking for standard naming...
This class is a composition of two QSettings instances:
@ Fields
Aliases, widgets, WMS/WFS, expressions, constraints, virtual fields.
Q_INVOKABLE void selectByIds(const QgsFeatureIds &ids, QgsVectorLayer::SelectBehavior behavior=QgsVectorLayer::SetSelection)
Selects matching features using a list of feature IDs.
Type
The WKB type describes the number of dimensions a geometry has.
virtual QSet< QVariant > uniqueValues(int fieldIndex, int limit=-1) const
Returns the set of unique values contained within the specified fieldIndex from this source.
void setBlendMode(QPainter::CompositionMode blendMode)
Set the blending mode used for rendering a layer.
void allowCommitChanged()
Emitted whenever the allowCommitChanged() property of this layer changes.
void featureDeleted(QgsFeatureId fid)
Emitted when a feature has been deleted.
virtual bool addFeature(QgsFeature &f)
Adds a feature.
Q_INVOKABLE bool startEditing()
Makes the layer editable.
bool readStyle(const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories) FINAL
Reads the style for the current layer from the Dom node supplied.
void readCustomProperties(const QDomNode &layerNode, const QString &keyStartsWith=QString())
Read custom properties from project file.
void setSimplifyHints(SimplifyHints simplifyHints)
Sets the simplification hints of the vector layer managed.
virtual bool isSaveAndLoadStyleToDatabaseSupported() const
It returns false by default.
This class allows including a set of layers in a database-side transaction, provided the layer data p...
OperationResult
Success or failure of a geometry operation.
void subsetStringChanged()
Emitted when the layer's subset string has changed.
QgsFeatureRequest & setSubsetOfAttributes(const QgsAttributeList &attrs)
Set a subset of attributes that will be fetched.
void setFields(const QgsFields &fields)
Convenience function for setting a fields for the scope.
const QgsDiagramRenderer * diagramRenderer() const
QString capabilitiesString() const
Capabilities for this layer, comma separated and translated.
Constraint
Constraints which may be present on a field.
void updateExpression(int index, const QString &exp)
Changes the expression at a given index.
void editFormConfigChanged()
Will be emitted whenever the edit form configuration of this layer changes.
void dataChanged()
Emitted whenever a change is made to the data provider which may have caused changes in the provider'...
QString htmlMetadata() const FINAL
Obtain a formatted HTML string containing assorted metadata for this layer.
The QgsConditionalLayerStyles class holds conditional style information for a layer.
Line string geometry type, with support for z-dimension and m-values.
QgsCoordinateTransformContext transformContext() const
Returns data provider coordinate transform context.
void layerModified()
Emitted when modifications has been done on layer.
void fullExtentCalculated()
Emitted whenever a deferred extent calculation is completed by the provider.
Q_INVOKABLE QgsMapLayer * mapLayer(const QString &layerId) const
Retrieve a pointer to a registered layer by layer ID.
virtual QString dataSourceUri(bool expandAuthConfig=false) const
Gets the data source specification.
QgsFieldConstraints::Constraints fieldConstraints(int fieldIndex) const
Returns any constraints which are present at the provider for a specified field index.
@ Line
Arranges candidates parallel to a generalised line representing the feature or parallel to a polygon'...
void setConstraintExpression(int index, const QString &expression, const QString &description=QString())
Sets the constraint expression for the specified field index.
Q_INVOKABLE QStringList customPropertyKeys() const
Returns list of all keys within custom properties.
void afterCommitChanges()
Emitted after changes are committed to the data provider.
void updateExpressionField(int index, const QString &exp)
Changes the expression used to define an expression based (virtual) field.
virtual bool hasMetadata() const
Returns true if the data source has metadata, false otherwise.
QList< int > QgsAttributeList
void setAuxiliaryLayer(QgsAuxiliaryLayer *layer=nullptr)
Sets the current auxiliary layer.
QgsMapLayerLegend * legend() const
Can be nullptr.
void updateFields(QgsFields &fields)
Updates field map with joined attributes.
MAYBE_UNUSED NODISCARD QgsReadWriteContextCategoryPopper enterCategory(const QString &category, const QString &details=QString())
Push a category to the stack.
bool accept(QgsStyleEntityVisitorInterface *visitor) const override
void setLabelsEnabled(bool enabled)
Sets whether labels should be enabled for the layer.
virtual bool deleteAttribute(int attr)
Delete an attribute field (but does not commit it)
QMap< QgsFieldConstraints::Constraint, QgsFieldConstraints::ConstraintStrength > fieldConstraintsAndStrength(int fieldIndex) const
Returns a map of constraint with their strength for a specific field of the layer.
virtual void toSld(QDomDocument &doc, QDomElement &element, const QgsStringMap &props=QgsStringMap()) const
used from subclasses to create SLD Rule elements following SLD v1.1 specs
static QgsFeatureRenderer * load(QDomElement &symbologyElem, const QgsReadWriteContext &context)
create a renderer from XML element
virtual void setMetadata(const QgsLayerMetadata &metadata)
Sets the layer's metadata store.
void setMergeLines(bool merge)
Sets whether connected line features with identical label text should be merged prior to generating l...
QString joinLayerId() const
ID of the joined layer - may be used to resolve reference to the joined layer.
@ Show
Whether to show the diagram.
void beginEditCommand(const QString &text)
Create edit command for undo/redo operations.
void removeExpression(int index)
Remove an expression from the buffer.
void setCrs(const QgsCoordinateReferenceSystem &srs, bool emitSignal=true)
Sets layer's spatial reference system.
void attributeValueChanged(QgsFeatureId fid, int idx, const QVariant &)
A rectangle specified with double values.
@ ConstraintNotNull
Field may not be null.
@ SubsetOfAttributes
Fetch only a subset of attributes (setSubsetOfAttributes sets this flag)
void committedFeaturesAdded(const QString &layerId, const QgsFeatureList &addedFeatures)
Emitted when features are added to the provider.
bool deleteStyleById_t(const QString &uri, QString styleID, QString &errCause)
bool isValid() const
Returns the status of the auxiliary storage currently defined.
@ OverPoint
Arranges candidates over a point (or centroid of a polygon), or at a preset offset from the point....
void committedAttributesAdded(const QString &layerId, const QList< QgsField > &addedAttributes)
void setFieldConstraint(int index, QgsFieldConstraints::Constraint constraint, QgsFieldConstraints::ConstraintStrength strength=QgsFieldConstraints::ConstraintStrengthHard)
Sets a constraint for a specified field index.
virtual void setEncoding(const QString &e)
Set encoding used for accessing data from layer.
QVariant defaultValue(int index, const QgsFeature &feature=QgsFeature(), QgsExpressionContext *context=nullptr) const
Returns the calculated default value for the specified field index.
bool changeAttributeValue(QgsFeatureId fid, int field, const QVariant &newValue, const QVariant &oldValue=QVariant(), bool skipDefaultValues=false)
Changes an attribute value for a feature (but does not immediately commit the changes).
void geometryChanged(QgsFeatureId fid, const QgsGeometry &geom)
Emitted when a feature's geometry is changed.
bool mShouldValidateCrs
true if the layer's CRS should be validated and invalid CRSes are not permitted.
QString port() const
Returns the port stored in the URI.
virtual QVariant defaultValue(int fieldIndex) const
Returns any literal default values which are present at the provider for a specified field index.
bool isEditable() const FINAL
Returns true if the provider is in editing mode.
QString mProviderKey
Data provider key (name of the data provider)
static void mergeScaleDependencies(double mScaleMinDenom, double mScaleMaxDenom, QgsStringMap &props)
Merges the local scale limits, if any, with the ones already in the map, if any.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
QgsCoordinateReferenceSystem fallbackCrs
Fallback layer coordinate reference system.
int addTopologicalPoints(const QgsGeometry &geom)
Adds topological points for every vertex of the geometry.
QgsFeatureRequest & setExpressionContext(const QgsExpressionContext &context)
Sets the expression context used to evaluate filter expressions.
@ Rendering
Rendering: scale visibility, simplify method, opacity.
QgsFeatureRequest & setFilterFid(QgsFeatureId fid)
Sets feature ID that should be fetched.
QgsCoordinateTransformContext transformContext() const
Returns data provider coordinate transform context.
@ PositionY
Y-coordinate data defined diagram position.
Base class for utility classes that encapsulate information necessary for rendering of map layers.
void setEditorWidgetSetup(int index, const QgsEditorWidgetSetup &setup)
The editor widget setup defines which QgsFieldFormatter and editor widget will be used for the field ...
QString providerType() const
Returns the provider type (provider key) for this layer.
long addTask(QgsTask *task, int priority=0)
Adds a task to the manager.
QHash< QString, long > symbolFeatureCountMap() const
Returns the count for each symbol.
void readXml(const QDomNode &layer_node)
Reads expressions from project file.
QString encodedSource(const QString &source, const QgsReadWriteContext &context) const FINAL
Called by writeLayerXML(), used by derived classes to encode provider's specific data source to proje...
QgsFeatureRequest & setFilterExpression(const QString &expression)
Set the filter expression.
void taskCompleted()
Will be emitted by task to indicate its successful completion.
bool changeAttributeValues(QgsFeatureId fid, const QgsAttributeMap &newValues, const QgsAttributeMap &oldValues=QgsAttributeMap(), bool skipDefaultValues=false)
Changes attributes' values for a feature (but does not immediately commit the changes).
void removeFieldAlias(int index)
Removes an alias (a display name) for attributes to display in dialogs.
void setConstraintStrength(Constraint constraint, ConstraintStrength strength)
Sets the strength of a constraint.
float maximumScale() const
Gets the maximum scale at which the layer should be simplified.
QgsAuxiliaryLayer * createAuxiliaryLayer(const QgsField &field, QgsVectorLayer *layer) const
Creates an auxiliary layer for a vector layer.
bool qgsVariantGreaterThan(const QVariant &lhs, const QVariant &rhs)
Compares two QVariant values and returns whether the first is greater than the second.
virtual bool changeGeometry(QgsFeatureId fid, const QgsGeometry &geom)
Change feature's geometry.
bool renameAttribute(int index, const QString &newName)
Renames an attribute field (but does not commit it).
static QgsPainting::BlendMode getBlendModeEnum(QPainter::CompositionMode blendMode)
Returns a BlendMode corresponding to a QPainter::CompositionMode.
@ SelectAtId
Fast access to features using their ID.
virtual QgsFeatureIds allFeatureIds() const
Returns a list of all feature IDs for features present in the source.
void normalize()
Normalize the rectangle so it has non-negative width/height.
@ GeometryOptions
Geometry validation configuration.
bool writeXml(QDomNode &layer_node, QDomDocument &doc, const QgsReadWriteContext &context) const FINAL
Writes vector layer specific state to project file Dom node.
void writeXml(QDomElement &layerElem, QDomDocument &doc) const
Writes the diagram settings to a DOM element.
bool simplifyDrawingCanbeApplied(const QgsRenderContext &renderContext, QgsVectorSimplifyMethod::SimplifyHint simplifyHint) const
Returns whether the VectorLayer can apply the specified simplification hint.
QString targetFieldName() const
Returns name of the field of our layer that will be used for join.
virtual void cancel()
Notifies the task that it should terminate.
QgsVectorLayer(const QString &path=QString(), const QString &baseName=QString(), const QString &providerLib="ogr", const QgsVectorLayer::LayerOptions &options=QgsVectorLayer::LayerOptions())
Constructor - creates a vector layer.
QgsEditorWidgetSetup editorWidgetSetup(int index) const
The editor widget setup defines which QgsFieldFormatter and editor widget will be used for the field ...
void triggerRepaint(bool deferredUpdate=false)
Will advise the map canvas (and any other interested party) that this layer requires to be repainted.
void dataSourceChanged()
Emitted whenever the layer's data source has been changed.
QgsFeatureIds handledFeatures(QgsVectorLayer *layer) const
Returns a list of feature IDs from the specified layer affected by the delete operation.
double xOffset
Horizontal offset of label.
bool displayAll
If true, all features will be labelled even when overlaps occur.
This is a container for configuration of the attribute table.
@ ReadLayerMetadata
Provider can read layer metadata from data store. Since QGIS 3.0. See QgsDataProvider::layerMetadata(...
QgsFields fields() const FINAL
Returns the list of fields of this layer.
bool changeGeometry(QgsFeatureId fid, QgsGeometry &geometry, bool skipDefaultValue=false)
Changes a feature's geometry within the layer's edit buffer (but does not immediately commit the chan...
double xMaximum() const SIP_HOLDGIL
Returns the x maximum value (right side of rectangle).
@ FlagDontResolveLayers
Don't resolve layer paths or create data providers for layers.
Container for all settings relating to text rendering.
void setColor(const QColor &color)
Sets the color that text will be rendered in.
This class wraps a request for features to a vector layer (or directly its vector data provider).
virtual QDomElement save(QDomDocument &doc, const QgsReadWriteContext &context)
store renderer info to XML element
QgsMapLayer::LayerFlags flags() const
Returns the flags for this layer.
void setLabeling(QgsAbstractVectorLayerLabeling *labeling)
Sets labeling configuration.
QString getStyleById(const QString &providerKey, const QString &uri, QString styleId, QString &errCause)
Gets a layer style defined by styleId.
QMap< int, QgsPropertyDefinition > QgsPropertiesDefinition
Definition of available properties.
virtual QgsVectorDataProvider::Capabilities capabilities() const
Returns flags containing the supported capabilities.
QString writePath(const QString &filename) const
Prepare a filename to save it to the project file.
void committedFeaturesAdded(const QString &layerId, const QgsFeatureList &addedFeatures)
QString dataComment() const
Returns a description for this layer as defined in the data provider.
static QgsAbstractVectorLayerLabeling * create(const QDomElement &element, const QgsReadWriteContext &context)
Try to create instance of an implementation based on the XML data.
static const int EditingCapabilities
Bitmask of all provider's editing capabilities.
Allows entering a context category and takes care of leaving this category on deletion of the class.
EditResult deleteVertex(QgsFeatureId featureId, int vertex)
Deletes a vertex from a feature.
bool hasEvalError() const
Returns true if an error occurred when evaluating last input.
void editingStarted()
Emitted when editing on this layer has started.
virtual QVariant aggregate(QgsAggregateCalculator::Aggregate aggregate, int index, const QgsAggregateCalculator::AggregateParameters ¶meters, QgsExpressionContext *context, bool &ok, QgsFeatureIds *fids=nullptr) const
Calculates an aggregated value from the layer's features.
@ Curved
Arranges candidates following the curvature of a line feature. Applies to line layers only.
void featureBlendModeChanged(QPainter::CompositionMode blendMode)
Signal emitted when setFeatureBlendMode() is called.
virtual void reloadData()
Reloads the data from the source by calling reloadProviderData() implemented by providers with data c...
QVariant minimumValue(int index) const override
Returns the minimum value of an attribute.
bool mValid
Indicates if the layer is valid and can be drawn.
const QgsProjectTranslator * projectTranslator() const
Returns the project translator.
void endEditCommand()
Finish edit command and add it to undo/redo stack.
@ AddToSelection
Add selection to current selection.
void removeFieldConstraint(int index, QgsFieldConstraints::Constraint constraint)
Removes a constraint for a specified field index.
void committedAttributeValuesChanges(const QString &layerId, const QgsChangedAttributesMap &changedAttributesValues)
Emitted when attribute value changes are saved to the provider.
QString decodedSource(const QString &source, const QString &provider, const QgsReadWriteContext &context) const FINAL
Called by readLayerXML(), used by derived classes to decode provider's specific data source from proj...
virtual void setExtent(const QgsRectangle &rect)
Sets the extent.
long featureCount() const override=0
Number of features in the layer.
QgsRectangle mExtent
Extent of the layer.
void readXml(const QDomElement &elem)
Reads the diagram settings from a DOM element.
Q_INVOKABLE bool commitChanges(bool stopEditing=true)
Attempts to commit to the underlying data provider any buffered changes made since the last to call t...
void setFieldConfigurationFlags(int index, QgsField::ConfigurationFlags flags)
Sets the configuration flags of the field at given index.
int addTopologicalPoints(const QgsGeometry &geom)
Adds topological points for every vertex of the geometry.
Q_DECL_DEPRECATED QgsGeometry::OperationResult addPart(const QVector< QgsPointXY > &ring, QgsFeatureId featureId)
Adds a new part polygon to a multipart feature.
QgsMapLayerTemporalProperties * temporalProperties() override
Returns temporal properties associated with the vector layer.
QString username() const
Returns the username stored in the URI.
QgsFeatureMap mAddedFeatures
New features which are not committed.
virtual bool deleteFeature(QgsFeatureId fid)
Delete a feature from the layer (but does not commit it)
void featureDeleted(QgsFeatureId fid)
QStringList commitErrors() const
Returns a list containing any error messages generated when attempting to commit changes to the layer...
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
int translateFeature(QgsFeatureId featureId, double dx, double dy)
Translates feature by dx, dy.
bool moveVertex(double x, double y, QgsFeatureId atFeatureId, int atVertex)
Moves the vertex at the given position number, ring and item (first number is index 0),...
bool isActive() const
Returns true if the temporal property is active.
QList< QgsRelation > referencedRelations(const QgsVectorLayer *layer=nullptr) const
Gets all relations where this layer is the referenced part (i.e.
void committedAttributeValuesChanges(const QString &layerId, const QgsChangedAttributesMap &changedAttributesValues)
bool changeAttributeValues(QgsFeatureId fid, const QgsAttributeMap &newValues, const QgsAttributeMap &oldValues=QgsAttributeMap())
Changes attributes' values in joined layers.
QString parserErrorString() const
Returns parser error.
bool saveStyle_t(const QString &uri, const QString &qmlStyle, const QString &sldStyle, const QString &styleName, const QString &styleDescription, const QString &uiFileContent, bool useAsDefault, QString &errCause)
void setExtent(const QgsRectangle &rect) FINAL
Sets the extent.
void reselect()
Reselects the previous set of selected features.
void writeCustomSymbology(QDomElement &element, QDomDocument &doc, QString &errorMessage) const
Signal emitted whenever the symbology (QML-file) for this layer is being written.
static QVariant readVariant(const QDomElement &element)
Read a QVariant from a QDomElement.
bool isValid() const
Returns the validity of this feature.
void selectionChanged(const QgsFeatureIds &selected, const QgsFeatureIds &deselected, bool clearAndSelect)
Emitted when selection was changed.
Q_INVOKABLE bool rollBack(bool deleteBuffer=true)
Stops a current editing operation and discards any uncommitted edits.
QList< QgsWeakRelation > weakRelations() const
Returns the layer's weak relations as specified in the layer's style.
void readStyleManager(const QDomNode &layerNode)
Read style manager's configuration (if any). To be called by subclasses.
const QList< QgsVectorLayerJoinInfo > vectorJoins() const
static Q_INVOKABLE QString toString(QgsUnitTypes::DistanceUnit unit)
Returns a translated string representing a distance unit.
void writeCommonStyle(QDomElement &layerElement, QDomDocument &document, const QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories) const
Write style data common to all layer types.
void featureAdded(QgsFeatureId fid)
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
QgsRectangle sourceExtent() const FINAL
Returns the extent of all geometries from the source.
friend class QgsVectorLayerEditBuffer
Base class for feedback objects to be used for cancellation of something running in a worker thread.
@ OriginUnknown
It has not been specified where the field comes from.
virtual bool enterUpdateMode()
Enter update mode.
void styleChanged()
Signal emitted whenever a change affects the layer's style.
bool equals(const QgsGeometry &geometry) const
Test if this geometry is exactly equal to another geometry.
void writeXml(QDomNode &node) const
Serialize to XML on layer save.
void repaintRequested(bool deferredUpdate=false)
By emitting this signal the layer tells that either appearance or content have been changed and any v...
const QgsAbstractVectorLayerLabeling * labeling() const
Access to const labeling configuration.
void relationsLoaded()
Emitted when the relations were loaded after reading a project.
Q_INVOKABLE int translateFeature(QgsFeatureId featureId, double dx, double dy)
Translates feature by dx, dy.
virtual QgsRectangle extent() const
Returns the extent of the layer.
@ ConstraintOriginLayer
Constraint was set by layer.
bool readXml(const QDomNode &layerNode)
Reads the stored expressions in in XML format.
void readOnlyChanged()
Emitted when the read only state of this layer is changed.
Q_INVOKABLE void invertSelectionInRectangle(QgsRectangle &rect)
Inverts selection of features found within the search rectangle (in layer's coordinates)
static QgsMapLayerLegend * defaultVectorLegend(QgsVectorLayer *vl)
Create new legend implementation for vector layer.
T flagValue(const QString &key, const T &defaultValue, const Section section=NoSection)
Returns the setting value for a setting based on a flag.
QgsChangedAttributesMap changedAttributeValues() const
Returns a map of features with changed attributes values which are not committed.
virtual QSet< QgsMapLayerDependency > dependencies() const
Gets the list of layer ids on which this layer depends.
void attributeValueChanged(QgsFeatureId fid, int idx, const QVariant &value)
Emitted whenever an attribute value change is done in the edit buffer.
SpatialIndexPresence
Enumeration of spatial index presence states.
Manages joined fields for a vector layer.
Q_INVOKABLE const QgsFeatureIds & selectedFeatureIds() const
Returns a list of the selected features IDs in this layer.
static QPainter::CompositionMode getCompositionMode(QgsPainting::BlendMode blendMode)
Returns a QPainter::CompositionMode corresponding to a BlendMode.
QSet< QgsMapLayerDependency > mDependencies
List of layers that may modify this layer on modification.
QList< QgsAction > actions(const QString &actionScope=QString()) const
Returns a list of actions that are available in the given action scope.
void setMaximumScale(double scale)
Sets the maximum map scale (i.e.
QgsDefaultValue defaultValueDefinition
QString constraintDescription(int index) const
Returns the descriptive name for the constraint expression for a specified field index.
void afterRollBack()
Emitted after changes are rolled back.
static QgsTaskManager * taskManager()
Returns the application's task manager, used for managing application wide background task handling.
QMap< QgsVectorLayer *, QgsFeatureIds > mHandledFeatures
QSet< QVariant > uniqueValues(int fieldIndex, int limit=-1) const FINAL
Calculates a list of unique values contained within an attribute in the layer.
#define RENDERER_TAG_NAME
void setFormat(const QgsTextFormat &format)
Sets the label text formatting settings, e.g., font settings, buffer settings, etc.
bool writeSld(QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsStringMap &props=QgsStringMap()) const
Writes the symbology of the layer into the document provided in SLD 1.1 format.
~QgsVectorLayer() override
int size() const
Returns number of items.
FieldOrigin fieldOrigin(int fieldIdx) const
Gets field's origin (value from an enumeration)
void reload() FINAL
Synchronises with changes in the datasource.
void addExpression(const QString &exp, const QgsField &fld)
Add an expression to the buffer.
QList< QgsFeature > QgsFeatureList
QMap< int, QVariant > QgsAttributeMap
virtual void setTransformContext(const QgsCoordinateTransformContext &transformContext) override
Sets the coordinate transform context to transformContext.
void attributeDeleted(int idx)
QList< QgsRelation > referencingRelations(int idx) const
Returns the layer's relations, where the foreign key is on this layer.
void setDefaultsFromDataProviderTemporalCapabilities(const QgsDataProviderTemporalCapabilities *capabilities) override
Sets the layers temporal settings to appropriate defaults based on a provider's temporal capabilities...
Stores the settings for rendering of all diagrams for a layer.
void committedFeaturesRemoved(const QString &layerId, const QgsFeatureIds &deletedFeatureIds)
virtual QString loadDefaultStyle(bool &resultFlag)
Retrieve the default style for this layer if one exists (either as a .qml file on disk or as a record...
static Q_DECL_DEPRECATED void drawVertexMarker(double x, double y, QPainter &p, QgsVectorLayer::VertexMarkerType type, int vertexSize)
Draws a vertex symbol at (screen) coordinates x, y.
@ ConstraintUnique
Field must have a unique value.
bool addFeatures(QgsFeatureList &features, QgsFeatureSink::Flags flags=QgsFeatureSink::Flags()) override
Adds a list of features in joined layers.
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
bool writeXml(QDomNode &layerNode) const
Writes the stored expressions out in XML format.
QVariantMap decodeUri(const QString &providerKey, const QString &uri)
Breaks a provider data source URI into its component paths (e.g.
bool readExtentFromXml() const
Returns true if the extent is read from the XML document when data source has no metadata,...
Implementation of map layer temporal properties for vector layers.
static QgsRuntimeProfiler * profiler()
Returns the application runtime profiler.
static void warning(const QString &msg)
Goes to qWarning.
void removeExpressionField(int index)
Removes an expression field.
const QgsVectorJoinList & vectorJoins() const
Definition for a property.
virtual QgsFeatureRenderer * createRenderer(const QVariantMap &configuration=QVariantMap()) const
Creates a new vector layer feature renderer, using provider backend specific information.
virtual QString storageType() const
Returns the permanent storage type for this layer as a friendly name.
QgsVectorLayerJoinInfo joinInfo() const
Returns information to use for joining with primary key and so on.
const QgsLabelLineSettings & lineSettings() const
Returns the label line settings, which contain settings related to how the label engine places and fo...
QVariant attribute(const QString &name) const
Lookup attribute value from attribute name.
QVariant maximumValue(int index) const FINAL
Returns the maximum value for an attribute column or an invalid variant in case of error.
float threshold() const
Gets the simplification threshold of the vector layer managed.
virtual void rollBack()
Stop editing and discard the edits.
void taskTerminated()
Will be emitted by task if it has terminated for any reason other then completion (e....
QgsFeatureRequest & setFilterFids(const QgsFeatureIds &fids)
Sets feature IDs that should be fetched.
Evaluates and returns the diagram settings relating to a diagram for a specific feature.
QgsActionManager * actions()
Returns all layer actions defined on this layer.
Q_GADGET QString expression
Base class for storage of map layer temporal properties.
QString mDataSource
Data source description string, varies by layer type.
void setDisplayExpression(const QString &displayExpression)
Set the preview expression, used to create a human readable preview string.
QList< QgsExpressionFieldBuffer::ExpressionField > expressions() const
void attributeAdded(int idx)
QgsAttributeList primaryKeyAttributes() const
Returns the list of attributes which make up the layer's primary keys.
QgsVectorDataProviderTemporalCapabilities * temporalCapabilities() override
Returns the provider's temporal capabilities.
static QgsStringMap getSvgParameterList(QDomElement &element)
void setMaximumScale(float maximumScale)
Sets the maximum scale at which the layer should be simplified.
Defines left outer join from our vector layer to some other vector layer.
Buffers information about expression fields for a vector layer.
bool hasScaleBasedVisibility() const
Returns whether scale based visibility is enabled for the layer.
virtual void exportNamedStyle(QDomDocument &doc, QString &errorMsg, const QgsReadWriteContext &context=QgsReadWriteContext(), QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories) const
Export the properties of this layer as named style in a QDomDocument.
double xMinimum() const SIP_HOLDGIL
Returns the x minimum value (left side of rectangle).
ConstraintStrength constraintStrength(Constraint constraint) const
Returns the strength of a field constraint, or ConstraintStrengthNotSet if the constraint is not pres...
virtual bool renameAttribute(int attr, const QString &newName)
Renames an attribute field (but does not commit it)
@ FullString
Full definition – possibly a very lengthy string, e.g. with no truncation of custom WKT definitions.
SpatialIndexPresence hasSpatialIndex() const override
QString constraintDescription() const
Returns the descriptive name for the constraint expression.
bool readSld(const QDomNode &node, QString &errorMessage) FINAL
friend class QgsVectorLayerEditPassthrough
SelectBehavior
Selection behavior.
QMap< QgsFeatureId, QgsFeature > QgsFeatureMap
Container for settings relating to a text buffer.
Q_INVOKABLE QgsFeatureList selectedFeatures() const
Returns a copy of the user-selected features.
void mapTipTemplateChanged()
Emitted when the map tip changes.
void removeCustomProperty(const QString &key)
Remove a custom property from layer.
virtual QList< QgsDiagramSettings > diagramSettings() const =0
Returns list with all diagram settings in the renderer.
QgsFeatureRequest & setNoAttributes()
Set that no attributes will be fetched.
bool prepare(const QgsExpressionContext *context)
Gets the expression ready for evaluation - find out column indexes.
QString host() const
Returns the host name stored in the URI.
QSet< QgsFeatureId > QgsFeatureIds
double minimumScale() const
Returns the minimum map scale (i.e.
void rendererChanged()
Signal emitted when renderer is changed.
bool forceLocalOptimization() const
Gets where the simplification executes, after fetch the geometries from provider, or when supported,...
QgsDefaultValue defaultValueDefinition(int index) const
Returns the definition of the expression used when calculating the default value for a field.
double maximumScale() const
Returns the maximum map scale (i.e.
bool removeJoin(const QString &joinLayerId)
Removes a vector layer join.
virtual void writeXml(QDomElement &layerElem, QDomDocument &doc, const QgsReadWriteContext &context) const =0
Writes diagram state to a DOM element.
This class represents a coordinate reference system (CRS).
QgsFieldConstraints::Constraints fieldConstraints(int fieldIndex) const
Returns any constraints which are present for a specified field index.
QVariant evaluate()
Evaluate the feature and return the result.
Q_INVOKABLE void invertSelection()
Selects not selected features and deselects selected ones.
Abstract base class - its implementations define different approaches to the labeling of a vector lay...
Single scope for storing variables and functions for use within a QgsExpressionContext.
void raiseError(const QString &msg)
Signals an error related to this vector layer.
const QgsVectorSimplifyMethod & simplifyMethod() const
Returns the simplification settings for fast rendering of features.
Utility class that encapsulates an action based on vector attributes.
QVariant minimumValue(int index) const FINAL
Returns the minimum value for an attribute column or an invalid variant in case of error.
@ Horizontal
Arranges horizontal candidates scattered throughout a polygon feature. Applies to polygon layers only...
Q_DECL_DEPRECATED QgsGeometry::OperationResult splitFeatures(const QVector< QgsPointXY > &splitLine, bool topologicalEditing=false)
Splits features cut by the given line.
static QgsUnitTypes::RenderUnit decodeSldUom(const QString &str, double *scaleFactor=nullptr)
Decodes a SLD unit of measure string to a render unit.
QgsRectangle extent() const FINAL
Returns the extent of the layer.
bool readXml(const QDomNode &layer_node)
Reads the actions in in XML format.
QString toString(int precision=16) const
Returns a string representation of form xmin,ymin : xmax,ymax Coordinates will be truncated to the sp...
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
T qgsEnumKeyToValue(const QString &key, const T &defaultValue, bool tryValueAsKey=true)
Returns the value corresponding to the given key of an enum.
A class to represent a 2D point.
void beforeAddingExpressionField(const QString &fieldName)
Will be emitted, when an expression field is going to be added to this vector layer.
void committedAttributesDeleted(const QString &layerId, const QgsAttributeList &deletedAttributes)
Signals emitted after committing changes.
bool isEmpty() const
Returns true if the configuration is empty, ie it contains no columns.
QgsCurve * clone() const override=0
Clones the geometry by performing a deep copy.
QgsFeatureIterator getSelectedFeatures(QgsFeatureRequest request=QgsFeatureRequest()) const
Returns an iterator of the selected features.
bool isCanceled() const
Tells whether the operation has been canceled already.
void dataChanged()
Data of layer changed.
QString loadStyle(const QString &providerKey, const QString &uri, QString &errCause)
Loads a layer style defined by uri.
bool readXml(const QDomNode &layer_node, QgsReadWriteContext &context) FINAL
Reads vector layer specific state from project file Dom node.
A grouped map of multiple QgsProperty objects, each referenced by a integer key value.
void deselect(QgsFeatureId featureId)
Deselects feature by its ID.
@ SetSelection
Set selection, removing any existing selection.
Setting options for loading vector layers.
QgsFeatureIds deletedFeatureIds() const
Returns a list of deleted feature IDs which are not committed.
const QgsDiagramLayerSettings * diagramLayerSettings() const
Renders the diagrams for all features with the same settings.
virtual void setTransformContext(const QgsCoordinateTransformContext &transformContext)
Sets data coordinate transform context to transformContext.
QString publicSource() const
Gets a version of the internal layer definition that has sensitive bits removed (for example,...
FeatureAvailability
Possible return value for hasFeatures() to determine if a source is empty.
QString readPath(const QString &filename) const
Turn filename read from the project file to an absolute path.
bool setAttribute(int field, const QVariant &attr)
Set an attribute's value by field index.
void displayExpressionChanged()
Emitted when the display expression changes.
QString source() const
Returns the source for the layer.
void editCommandDestroyed()
Signal emitted, when an edit command is destroyed.
ConfigurationFlags configurationFlags
QMap< QString, QString > QgsStringMap
void writeStyleManager(QDomNode &layerNode, QDomDocument &doc) const
Write style manager's configuration (if exists). To be called by subclasses.
void setBuffer(const QgsTextBufferSettings &bufferSettings)
Sets the text's buffer settings.
QString fieldName
Name of field (or an expression) to use for label text.
void setScaleBasedVisibility(bool enabled)
Sets whether scale based visibility is enabled for the layer.
@ Legend
Legend settings (since QGIS 3.16)
void editingStopped()
Emitted when edited changes have been successfully written to the data provider.
Q_DECL_DEPRECATED QgsGeometry::OperationResult addPart(const QList< QgsPointXY > &ring)
Adds a new part polygon to a multipart feature.
SimplifyAlgorithm
Types of local simplification algorithms that can be used.
void setSimplifyAlgorithm(SimplifyAlgorithm simplifyAlgorithm)
Sets the local simplification algorithm of the vector layer managed.
void setCoordinateSystem()
Setup the coordinate system transformation for the layer.
double yMaximum() const SIP_HOLDGIL
Returns the y maximum value (top side of rectangle).
Q_INVOKABLE QVariant customProperty(const QString &value, const QVariant &defaultValue=QVariant()) const
Read a custom property from layer.
QgsCoordinateTransformContext transformContext() const
Returns the layer data provider coordinate transform context or a default transform context if the la...
Basic implementation of the labeling interface.
bool readXml(const QDomNode &node, const QgsReadWriteContext &context)
Reads the condition styles state from a DOM node.
@ OriginExpression
Field is calculated from an expression.
Aggregate
Available aggregates to calculate.
bool saveStyle(const QString &providerKey, const QString &uri, const QString &qmlStyle, const QString &sldStyle, const QString &styleName, const QString &styleDescription, const QString &uiFileContent, bool useAsDefault, QString &errCause)
Saves a layer style to provider.
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
void updateFields(QgsFields &flds)
Adds fields with the expressions buffered in this object to a QgsFields object.
static bool fillFromSld(QDomElement &element, Qt::BrushStyle &brushStyle, QColor &color)
void setAttributeTableConfig(const QgsAttributeTableConfig &attributeTableConfig)
Sets the attribute table configuration object.
@ IntersectSelection
Modify current selection to include only select features which match.
bool nextFeature(QgsFeature &f)
bool deleteFeatures(const QgsFeatureIds &fids, DeleteContext *context=nullptr)
Deletes a set of features from the layer (but does not commit it)
bool addJoin(const QgsVectorLayerJoinInfo &joinInfo)
Joins another vector layer to this layer.
virtual int listStylesInDatabase(QStringList &ids, QStringList &names, QStringList &descriptions, QString &msgError)
Lists all the style in db split into related to the layer and not related to.
QVector< QgsPoint > QgsPointSequence
QString attributeDisplayName(int index) const
Convenience function that returns the attribute alias if defined or the field name else.
int listStyles_t(const QString &uri, QStringList &ids, QStringList &names, QStringList &descriptions, QString &errCause)
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
A geometry is the spatial representation of a feature.
virtual void readXml(const QDomElement &elem, const QgsReadWriteContext &context)=0
Reads diagram state from a DOM element.
@ Referencing
The layer is referencing.
void destroyEditCommand()
Destroy active command and reverts all changes in it.
@ SpatialIndexUnknown
Spatial index presence cannot be determined, index may or may not exist.
void setName(const QString &name)
Set the display name of the layer.
virtual QgsAbstractVectorLayerLabeling * createLabeling(const QVariantMap &configuration=QVariantMap()) const
Creates labeling settings, using provider backend specific information.
Represents a vector layer which manages a vector based data sets.
bool hasGeometry() const
Returns true if the feature has an associated geometry.
Q_INVOKABLE bool deleteSelectedFeatures(int *deletedCount=nullptr, DeleteContext *context=nullptr)
Deletes the selected features.
double width() const SIP_HOLDGIL
Returns the width of the rectangle.
QList< QgsVectorLayer * > handledLayers(bool includeAuxiliaryLayers=true) const
Returns a list of all layers affected by the delete operation.
void committedAttributesDeleted(const QString &layerId, const QgsAttributeList &deletedAttributes)
Emitted when attributes are deleted from the provider.
bool insertVertex(double x, double y, QgsFeatureId atFeatureId, int beforeVertex)
Insert a new vertex before the given vertex number, in the given ring, item (first number is index 0)...
void appendChild(QgsRuleBasedLabeling::Rule *rule)
add child rule, take ownership, sets this as parent
void geometryChanged(QgsFeatureId fid, const QgsGeometry &geometry)
Emitted whenever a geometry change is done in the edit buffer.
QgsEditFormConfig editFormConfig
bool setReadOnly(bool readonly=true)
Makes layer read-only (editing disabled) or not.
QVariant maximumValue(int index) const override
Returns the maximum value of an attribute.
Base class for all map layer types.
void set(const QgsPointXY &p1, const QgsPointXY &p2)
Sets the rectangle from two QgsPoints.
QList< QgsRelation > referencingRelations(const QgsVectorLayer *layer=nullptr, int fieldIdx=-2) const
Gets all relations where the specified layer (and field) is the referencing part (i....
void editCommandStarted(const QString &text)
Signal emitted when a new edit command has been started.
This class models dependencies with or between map layers.
void setConnection(const QString &aHost, const QString &aPort, const QString &aDatabase, const QString &aUsername, const QString &aPassword, SslMode sslmode=SslPrefer, const QString &authConfigId=QString())
Sets all connection related members at once.
virtual QgsRectangle extent() const =0
Returns the extent of the layer.
QgsAttributeTableConfig attributeTableConfig() const
Returns the attribute table configuration object.
QgsGeometry getGeometry(QgsFeatureId fid) const
Queries the layer for the geometry at the given id.
virtual bool changeAttributeValue(QgsFeatureId fid, int field, const QVariant &newValue, const QVariant &oldValue=QVariant())
Changed an attribute value (but does not commit it)
void dirtied(const QString &sql, const QString &name)
Emitted if a sql query is executed and the underlying data is modified.
static QgsWeakRelation readXml(const QgsVectorLayer *layer, WeakRelationType type, const QDomNode &node, const QgsPathResolver resolver)
Returns a weak relation for the given layer.
void setSize(double size)
Sets the size of the buffer.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
void recalculateExtents() const
This is used to send a request that any mapcanvas using this layer update its extents.
double maxCurvedCharAngleIn
Maximum angle between inside curved label characters (valid range 20.0 to 60.0).
void setFieldConfigurationFlag(int index, QgsField::ConfigurationFlag flag, bool active)
Sets the given configuration flag for the field at given index to be active or not.
@ ConstraintExpression
Field has an expression constraint set. See constraintExpression().
QString capabilitiesString() const
Returns the above in friendly format.
void select(QgsFeatureId featureId)
Selects feature by its ID.
QgsVectorDataProvider * dataProvider() FINAL
Returns the layer's data provider, it may be nullptr.
Manages stored expressions regarding creation, modification and storing in the project.
QgsFieldConstraints constraints
QgsConditionalLayerStyles * conditionalStyles() const
Returns the conditional styles that are set for this layer.
static QString quotedColumnRef(QString name)
Returns a quoted column reference (in double quotes)
bool setDependencies(const QSet< QgsMapLayerDependency > &layers) FINAL
Sets the list of dependencies.
bool isExpression
true if this label is made from a expression string, e.g., FieldName || 'mm'
QString database() const
Returns the database name stored in the URI.
FeatureAvailability hasFeatures() const FINAL
Determines if this vector layer has features.
int fieldOriginIndex(int fieldIdx) const
Gets field's origin index (its meaning is specific to each type of origin)
virtual bool commitChanges(QStringList &commitErrors)
Attempts to commit any changes to disk.
static GeometryType geometryType(Type type) SIP_HOLDGIL
Returns the geometry type for a WKB type, e.g., both MultiPolygon and CurvePolygon would have a Polyg...
void styleLoaded(QgsMapLayer::StyleCategories categories)
Emitted when a style has been loaded.
void symbolFeatureCountMapChanged()
Emitted when the feature count for symbols on this layer has been recalculated.
void beforeModifiedCheck() const
Emitted when the layer is checked for modifications. Use for last-minute additions.
void setColor(const QColor &color)
Sets the color for the buffer.
@ LayerConfiguration
General configuration: identifiable, removable, searchable, display expression, read-only.
bool containsJoins() const
Quick way to test if there is any join at all.
Class providing some utility methods to manage auxiliary storage.
QgsVectorLayerFeatureCounter * countSymbolFeatures(bool storeSymbolFids=false)
Count features for symbols.
QgsUnitTypes::RenderUnit offsetUnits
Units for offsets of label.
@ Referenced
The layer is referenced.
@ InvalidLayer
Edit failed due to invalid layer.
QString uri(bool expandAuthConfig=true) const
Returns the complete URI as a string.
bool deleteFeature(QgsFeatureId fid, QgsVectorLayer::DeleteContext *context=nullptr) const
Deletes a feature from joined layers.
QUndoStack * undoStack()
Returns pointer to layer's undo stack.
bool needsGeometry() const
Returns true if the expression uses feature geometry for some computation.
@ CustomProperties
Custom properties (by plugins for instance)
void setMinimumScale(double scale)
Sets the minimum map scale (i.e.
void setEditFormConfig(const QgsEditFormConfig &editFormConfig)
Sets the editFormConfig (configuration) of the form used to represent this vector layer.
QString storageType() const
Returns the permanent storage type for this layer as a friendly name.
void setSizeUnit(QgsUnitTypes::RenderUnit unit)
Sets the units for the size of rendered text.
QgsRectangle boundingBox() const
Returns the bounding box of the geometry.
virtual bool isModified() const
Returns true if the provider has been modified since the last commit.
QString createSavepoint(QString &error)
creates a save point returns empty string on error returns the last created savepoint if it's not dir...
SimplifyHints simplifyHints() const
Gets the simplification hints of the vector layer managed.
This is the base class for vector data providers.
QString displayName() const
Returns the name to use when displaying this field.
virtual bool deleteAttribute(int attr)
Deletes an attribute field (but does not commit it).
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Q_INVOKABLE QgsRectangle boundingBoxOfSelected() const
Returns the bounding box of the selected features. If there is no selection, QgsRectangle(0,...
void setProperty(int key, const QgsProperty &property)
Adds a property to the collection and takes ownership of it.
Q_GADGET Constraints constraints
bool deleteFeature(QgsFeatureId fid, DeleteContext *context=nullptr)
Deletes a feature from the layer (but does not commit it).
virtual bool leaveUpdateMode()
Leave update mode.
bool isField() const
Checks whether an expression consists only of a single field reference.
virtual QString subsetString() const
Returns the subset definition string (typically sql) currently in use by the layer and used by the pr...
QString loadStyle_t(const QString &uri, QString &errCause)
QgsGeometryMap mChangedGeometries
Changed geometries which are not committed.
bool readSymbology(const QDomNode &layerNode, QString &errorMessage, QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories) FINAL
Reads the symbology for the current layer from the Dom node supplied.
Storage and management of actions associated with a layer.
bool writeSymbology(QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories) const FINAL
Writes the symbology for the layer into the document provided.
virtual QgsLayerMetadata layerMetadata() const
Returns layer metadata collected from the provider's source.
bool changeAttributeValue(QgsFeatureId fid, int field, const QVariant &newValue, const QVariant &oldValue=QVariant())
Changes attribute value in joined layers.
bool hasParserError() const
Returns true if an error occurred when parsing the input expression.
void updatedFields()
Emitted whenever the fields available from this layer have been changed.
QgsFeature getFeature(QgsFeatureId fid) const
Queries the layer for the feature with the given id.
@ ConstraintOriginProvider
Constraint was set at data provider.
Q_DECL_DEPRECATED QgsGeometry::OperationResult addRing(const QVector< QgsPointXY > &ring, const QgsFeatureIds &targetFeatureIds=QgsFeatureIds(), QgsFeatureId *modifiedFeatureId=nullptr)
Adds a ring to polygon/multipolygon features.
void attributeAdded(int idx)
Will be emitted, when a new attribute has been added to this vector layer.
int selectedFeatureCount() const
Returns the number of features that are selected in this layer.
T enumValue(const QString &key, const T &defaultValue, const Section section=NoSection)
Returns the setting value for a setting based on an enum.
EditResult
Result of an edit operation.
@ PositionX
X-coordinate data defined diagram position.
ConstraintStrength
Strength of constraints.
bool deleteAttributes(const QList< int > &attrs)
Deletes a list of attribute fields (but does not commit it)
void setSize(double size)
Sets the size for rendered text.
virtual bool isClosed() const SIP_HOLDGIL
Returns true if the curve is closed.
int lookupField(const QString &fieldName) const
Looks up field's index from the field name.
double rendererScale() const
Returns the renderer map scale.
bool allowCommit() const
Controls, if the layer is allowed to commit changes.
void setValid(bool valid)
Sets whether layer is valid or not.
QgsEditorWidgetSetup editorWidgetSetup() const
Gets the editor widget setup for the field.
QgsExpressionContext createExpressionContext() const FINAL
This method needs to be reimplemented in all classes which implement this interface and return an exp...
QgsField at(int i) const
Gets field at particular index (must be in range 0..N-1)
void renameExpression(int index, const QString &name)
Renames an expression field at a given index.
Class for parsing and evaluation of expressions (formerly called "search strings").
QgsWkbTypes::Type fallbackWkbType
Fallback geometry type.
QString qgsEnumValueToKey(const T &value)
Returns the value for the given key of an enum.
bool updateFeature(QgsFeature &feature, bool skipDefaultValues=false)
Updates an existing feature in the layer, replacing the attributes and geometry for the feature with ...
QString displayExpression
virtual QStringList uniqueStringsMatching(int index, const QString &substring, int limit=-1, QgsFeedback *feedback=nullptr) const
Returns unique string values of an attribute which contain a specified subset string.
QgsCoordinateReferenceSystem sourceCrs() const FINAL
Returns the coordinate reference system for features in the source.
@ Success
Edit operation was successful.
static QDomElement writeVariant(const QVariant &value, QDomDocument &doc)
Write a QVariant to a QDomElement.
QgsWkbTypes::GeometryType type
void updateFields(QgsFields &fields)
Wrapper for iterator of features from vector data provider or vector layer.
QString displayField() const
This is a shorthand for accessing the displayExpression if it is a simple field.
QgsVectorLayer * clone() const override
Returns a new instance equivalent to this one.
static QgsFeatureRenderer * loadSld(const QDomNode &node, QgsWkbTypes::GeometryType geomType, QString &errorMessage)
Create a new renderer according to the information contained in the UserStyle element of a SLD style ...
Q_INVOKABLE QgsWkbTypes::GeometryType geometryType() const
Returns point, line or polygon.
bool addFeature(QgsFeature &feature, QgsFeatureSink::Flags flags=QgsFeatureSink::Flags()) FINAL
Adds a single feature to the sink.
Q_INVOKABLE void modifySelection(const QgsFeatureIds &selectIds, const QgsFeatureIds &deselectIds)
Modifies the current selection on this layer.
virtual bool accept(QgsStyleEntityVisitorInterface *visitor) const
Accepts the specified symbology visitor, causing it to visit all symbols associated with the labeling...
static QgsProviderRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.
Q_DECL_DEPRECATED QgsGeometry::OperationResult addRing(const QVector< QgsPointXY > &ring, QgsFeatureId *featureId=nullptr)
Adds a ring to polygon/multipolygon features.
double ANALYSIS_EXPORT angle(QgsPoint *p1, QgsPoint *p2, QgsPoint *p3, QgsPoint *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored)
@ HideFromWfs
Fields is available if layer is served as WFS from QGIS server.
virtual void exportSldStyle(QDomDocument &doc, QString &errorMsg) const
Export the properties of this layer as SLD style in a QDomDocument.
bool useRenderingOptimization() const
Returns true if the rendering optimization (geometry simplification) can be executed.
virtual QString loadNamedStyle(const QString &uri, bool &resultFlag, QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories)
Retrieve a named style for this layer if one exists (either as a .qml file on disk or as a record in ...
void joinedFieldsChanged()
Emitted whenever the list of joined fields changes (e.g.
void setProviderType(const QString &providerType)
Sets the providerType (provider key)
void resolveReferences(QgsProject *project) FINAL
Resolves references to other layers (kept as layer IDs after reading XML) into layer objects.
QgsMapLayerRenderer * createMapRenderer(QgsRenderContext &rendererContext) FINAL
Returns new instance of QgsMapLayerRenderer that will be used for rendering of given context.
virtual bool changeAttributeValues(QgsFeatureId fid, const QgsAttributeMap &newValues, const QgsAttributeMap &oldValues)
Changes values of attributes (but does not commit it).
bool removeJoin(const QString &joinLayerId)
Removes a vector layer join.
QgsFeatureRequest & setFlags(QgsFeatureRequest::Flags flags)
Sets flags that affect how features will be fetched.
T qgsFlagKeysToValue(const QString &keys, const T &defaultValue)
Returns the value corresponding to the given keys of a flag.
QString expression() const
Returns the original, unmodified expression string.
Q_DECL_DEPRECATED void setDataSource(const QString &dataSource, const QString &baseName, const QString &provider, bool loadDefaultStyleFlag=false)
Update the data source of the layer.
QString expressionField(int index) const
Returns the expression used for a given expression field.
Resolves relative paths into absolute paths and vice versa.
void readXml(const QDomNode &node)
Deserialize to XML on layer load.
QgsFeatureMap addedFeatures() const
Returns a map of new features which are not committed.
bool skipCrsValidation
Controls whether the layer is allowed to have an invalid/unknown CRS.
bool isNull() const
Test if the rectangle is null (all coordinates zero or after call to setMinimal()).
@ CreateLabeling
Provider can set labeling settings using backend-specific formatting information. Since QGIS 3....
@ HideFromWms
Fields is available if layer is served as WMS from QGIS server.
void setLegend(QgsMapLayerLegend *legend)
Assign a legend controller to the map layer.
int indexFromName(const QString &fieldName) const
Gets the field index from the field name.
QgsField::ConfigurationFlags fieldConfigurationFlags(int index) const
Returns the configuration flags of the field at given index.
QString loadDefaultStyle(bool &resultFlag) FINAL
Retrieve the default style for this layer if one exists (either as a .qml file on disk or as a record...
QgsLayerMetadata metadata
void setProviderEncoding(const QString &encoding)
Sets the text encoding of the data provider.
QgsVectorLayer::EditResult deleteVertex(QgsFeatureId featureId, int vertex)
Deletes a vertex from a feature.
friend class QgsVectorLayerFeatureSource
@ OriginJoin
Field comes from a joined layer (originIndex / 1000 = index of the join, originIndex % 1000 = index w...
virtual bool addFeatures(QgsFeatureList &features)
Insert a copy of the given features into the layer (but does not commit it)
void setFieldAlias(int index, const QString &aliasString)
Sets an alias (a display name) for attributes to display in dialogs.
QgsWkbTypes::Type wkbType() const override=0
Returns the geometry type which is returned by this layer.
void setOpacity(double opacity)
Sets the opacity for the vector layer, where opacity is a value between 0 (totally transparent) and 1...
void resolveReferences(QgsProject *project)
Resolves layer IDs of joined layers using given project's available layers.
virtual bool isValid() const =0
Returns true if this is a valid layer.
virtual void updateExtents()
Update the extents of the layer.
bool loadAuxiliaryLayer(const QgsAuxiliaryStorage &storage, const QString &key=QString())
Loads the auxiliary layer for this vector layer.
bool labelsEnabled() const
Returns whether the layer contains labels which are enabled and should be drawn.
virtual void readXml(const QDomElement &elem, const QgsReadWriteContext &context)
Reads configuration from a DOM element previously written by writeXml()
virtual QString translate(const QString &context, const QString &sourceText, const char *disambiguation=nullptr, int n=-1) const =0
The derived translate() translates with QTranslator and qm file the sourceText.
Implementation of threaded rendering for vector layers.
ConstraintOrigin constraintOrigin(Constraint constraint) const
Returns the origin of a field constraint, or ConstraintOriginNotSet if the constraint is not present ...
void committedFeaturesRemoved(const QString &layerId, const QgsFeatureIds &deletedFeatureIds)
Emitted when features are deleted from the provider.
virtual bool writeXml(QDomElement &collectionElem, const QgsPropertiesDefinition &definitions) const
Writes the current state of the property collection into an XML element.
void committedGeometriesChanges(const QString &layerId, const QgsGeometryMap &changedGeometries)
Emitted when geometry changes are saved to the provider.
void setFeatureBlendMode(QPainter::CompositionMode blendMode)
Sets the blending mode used for rendering each feature.
QString getStyleById_t(const QString &uri, QString styleID, QString &errCause)
int indexOf(const QString &fieldName) const
Gets the field index from the field name.
const QgsPathResolver & pathResolver() const
Returns path resolver for conversion between relative and absolute paths.
virtual bool setSubsetString(const QString &subset)
Sets the string (typically sql) used to define a subset of the layer.
@ ShowAll
Show upside down for all labels, including dynamic ones.
QgsChangedAttributesMap mChangedAttributeValues
Changed attributes values which are not committed.
QgsStringMap attributeAliases() const
Returns a map of field name to attribute alias.
bool writeStyle(QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories) const FINAL
Writes just the style information for the layer into the document.
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
void editCommandEnded()
Signal emitted, when an edit command successfully ended.
virtual QDomElement save(QDomDocument &doc, const QgsReadWriteContext &context) const =0
Returns labeling configuration as XML element.
virtual QgsCoordinateReferenceSystem crs() const =0
Returns the coordinate system for the data source.
void setSimplifyMethod(const QgsVectorSimplifyMethod &simplifyMethod)
Sets the simplification settings for fast rendering of features.
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
QgsFeatureRenderer * renderer()
Returns renderer.
bool addAttribute(const QgsField &field)
Add an attribute field (but does not commit it) returns true if the field was added.
static QgsRectangle readRectangle(const QDomElement &element)
void readCustomSymbology(const QDomElement &element, QString &errorMessage)
Signal emitted whenever the symbology (QML-file) for this layer is being read.
bool addJoin(const QgsVectorLayerJoinInfo &joinInfo)
Joins another vector layer to this layer.
Encapsulate a field in an attribute table or data source.
void update(const QgsFields &fields)
Update the configuration with the given fields.
void featureAdded(QgsFeatureId fid)
Emitted when a new feature has been added to the layer.