30 #include <QPainterPath> 32 #include <QProgressDialog> 36 #include <QStringBuilder> 38 #include <QUndoCommand> 102 #ifdef TESTPROVIDERLIB 108 const QString &qmlStyle,
109 const QString &sldStyle,
110 const QString &styleName,
111 const QString &styleDescription,
112 const QString &uiFileContent,
126 QStringList &descriptions,
144 const QString &baseName,
145 const QString &providerKey,
149 , mAuxiliaryLayer( nullptr )
150 , mAuxiliaryLayerKey( QString() )
151 , mReadExtentFromXml( options.readExtentFromXml )
161 mGeometryOptions = qgis::make_unique<QgsGeometryOptions>();
165 mStoredExpressionManager->setParent(
this );
168 mJoinBuffer->setParent(
this );
173 if ( !vectorLayerPath.isEmpty() && !
mProviderKey.isEmpty() )
188 mSimplifyMethod.
setThreshold( settings.
value( QStringLiteral(
"qgis/simplifyDrawingTol" ), mSimplifyMethod.
threshold() ).toFloat() );
201 delete mDataProvider;
204 delete mExpressionFieldBuffer;
206 delete mDiagramLayerSettings;
207 delete mDiagramRenderer;
212 delete mConditionalStyles;
213 delete mStoredExpressionManager;
215 if ( mFeatureCounter )
216 mFeatureCounter->
cancel();
233 QList<QgsVectorLayerJoinInfo> joins =
vectorJoins();
234 const auto constJoins = joins;
256 for (
const QgsAction &action : constActions )
292 auto constraintIt = constraints.constBegin();
293 for ( ; constraintIt != constraints.constEnd(); ++ constraintIt )
369 p.setPen( QColor( 50, 100, 120, 200 ) );
370 p.setBrush( QColor( 200, 200, 210, 120 ) );
371 p.drawEllipse( x - m, y - m, m * 2 + 1, m * 2 + 1 );
375 p.setPen( QColor( 255, 0, 0 ) );
376 p.drawLine( x - m, y + m, x + m, y - m );
377 p.drawLine( x - m, y - m, x + m, y + m );
383 mSelectedFeatureIds.insert( fid );
384 mPreviousSelectedFeatureIds.clear();
391 mSelectedFeatureIds.unite( featureIds );
392 mPreviousSelectedFeatureIds.clear();
399 mSelectedFeatureIds.remove( fid );
400 mPreviousSelectedFeatureIds.clear();
407 mSelectedFeatureIds.subtract( featureIds );
408 mPreviousSelectedFeatureIds.clear();
421 .setFilterRect( rect )
423 .setNoAttributes() );
428 newSelection << feat.
id();
457 newSelection << feat.
id();
479 bool matches = exp.
evaluate( &context ).toBool();
483 newSelection << feat.
id();
487 newSelection << feat.
id();
506 newSelection = mSelectedFeatureIds + ids;
510 newSelection = mSelectedFeatureIds - ids;
514 newSelection = mSelectedFeatureIds.intersect( ids );
518 QgsFeatureIds deselectedFeatures = mSelectedFeatureIds - newSelection;
519 mSelectedFeatureIds = newSelection;
520 mPreviousSelectedFeatureIds.clear();
528 if ( !intersectingIds.isEmpty() )
530 QgsDebugMsgLevel( QStringLiteral(
"Trying to select and deselect the same item at the same time. Unsure what to do. Selecting dubious items." ), 3 );
533 mSelectedFeatureIds -= deselectIds;
534 mSelectedFeatureIds += selectIds;
535 mPreviousSelectedFeatureIds.clear();
543 ids.subtract( mSelectedFeatureIds );
558 .setFilterRect( rect )
560 .setNoAttributes() );
568 if ( mSelectedFeatureIds.contains( fet.
id() ) )
570 deselectIds << fet.
id();
574 selectIds << fet.
id();
583 if ( mSelectedFeatureIds.isEmpty() )
588 mPreviousSelectedFeatureIds = previous;
593 if ( mPreviousSelectedFeatureIds.isEmpty() || !mSelectedFeatureIds.empty() )
601 return mDataProvider;
606 return mDataProvider;
611 if (
mValid && mDataProvider && mDataProvider->
encoding() != encoding )
620 delete mDiagramRenderer;
621 mDiagramRenderer = r;
650 .setFilterFids( mSelectedFeatureIds )
651 .setNoAttributes() );
664 .setNoAttributes() );
668 if ( mSelectedFeatureIds.contains( fet.
id() ) )
679 if ( retval.
width() == 0.0 || retval.
height() == 0.0 )
688 retval.
set( -1.0, -1.0, 1.0, 1.0 );
697 return mLabelsEnabled &&
static_cast< bool >( mLabeling );
702 mLabelsEnabled = enabled;
707 if ( !mDiagramRenderer || !mDiagramLayerSettings )
710 QList<QgsDiagramSettings> settingList = mDiagramRenderer->
diagramSettings();
711 if ( !settingList.isEmpty() )
713 return settingList.at( 0 ).enabled;
720 if ( !mSymbolFeatureCounted )
723 return mSymbolFeatureCountMap.value( legendKey, -1 );
728 if ( !mSymbolFeatureCounted )
731 return mSymbolFeatureIdMap.value( legendKey,
QgsFeatureIds() );
736 if ( mSymbolFeatureCounted || mFeatureCounter )
737 return mFeatureCounter;
739 mSymbolFeatureCountMap.clear();
740 mSymbolFeatureIdMap.clear();
745 return mFeatureCounter;
747 if ( !mDataProvider )
750 return mFeatureCounter;
755 return mFeatureCounter;
758 if ( !mFeatureCounter )
767 return mFeatureCounter;
773 if ( force || !mReadExtentFromXml || ( mReadExtentFromXml && mXmlExtent.
isNull() ) )
774 mValidExtent =
false;
785 if ( !mDefaultValueOnUpdateFields.isEmpty() )
790 int size = mFields.
size();
791 for (
int idx : qgis::as_const( mDefaultValueOnUpdateFields ) )
793 if ( idx < 0 || idx >= size )
810 if ( !mValidExtent && mLazyExtent && mDataProvider && !mDataProvider->
hasMetadata() && mReadExtentFromXml && !mXmlExtent.
isNull() )
817 if ( !mValidExtent && mLazyExtent && mDataProvider && mDataProvider->
isValid() )
834 if ( !
mValid || !mDataProvider )
836 QgsDebugMsgLevel( QStringLiteral(
"invoked with invalid layer or null mDataProvider" ), 3 );
858 if ( it->hasGeometry() )
869 .setNoAttributes() );
904 if ( !
mValid || !mDataProvider )
906 QgsDebugMsgLevel( QStringLiteral(
"invoked with invalid layer or null mDataProvider" ), 3 );
914 if ( !
mValid || !mDataProvider || mEditBuffer )
916 QgsDebugMsgLevel( QStringLiteral(
"invoked with invalid layer or null mDataProvider or while editing" ), 3 );
943 double maximumSimplificationScale = mSimplifyMethod.
maximumScale();
946 return !( maximumSimplificationScale > 1 && renderContext.
rendererScale() <= maximumSimplificationScale );
953 return mConditionalStyles;
958 if ( !
mValid || !mDataProvider )
976 if ( !
mValid || !mEditBuffer || !mDataProvider )
980 if ( mGeometryOptions->isActive() )
983 mGeometryOptions->apply( geom );
987 bool success = mEditBuffer->
addFeature( feature );
1002 if ( !mEditBuffer || !mDataProvider )
1008 if ( currentFeature.
isValid() )
1010 bool hasChanged =
false;
1011 bool hasError =
false;
1023 QgsDebugMsgLevel( QStringLiteral(
"geometry of feature %1 could not be changed." ).arg( updatedFeature.
id() ), 3 );
1030 for (
int attr = 0; attr < fa.count(); ++attr )
1032 if ( fa.at( attr ) != ca.at( attr ) )
1040 QgsDebugMsgLevel( QStringLiteral(
"attribute %1 of feature %2 could not be changed." ).arg( attr ).arg( updatedFeature.
id() ), 3 );
1045 if ( hasChanged && !mDefaultValueOnUpdateFields.isEmpty() && !skipDefaultValues )
1046 updateDefaultValues( updatedFeature.
id(), updatedFeature );
1052 QgsDebugMsgLevel( QStringLiteral(
"feature %1 could not be retrieved" ).arg( updatedFeature.
id() ), 3 );
1060 if ( !
mValid || !mEditBuffer || !mDataProvider )
1064 bool result = utils.
insertVertex( x, y, atFeatureId, beforeVertex );
1073 if ( !
mValid || !mEditBuffer || !mDataProvider )
1077 bool result = utils.
insertVertex( point, atFeatureId, beforeVertex );
1086 if ( !
mValid || !mEditBuffer || !mDataProvider )
1090 bool result = utils.
moveVertex( x, y, atFeatureId, atVertex );
1099 if ( !
mValid || !mEditBuffer || !mDataProvider )
1103 bool result = utils.
moveVertex( p, atFeatureId, atVertex );
1112 if ( !
mValid || !mEditBuffer || !mDataProvider )
1137 int count = mSelectedFeatureIds.size();
1151 *deletedCount = deleted;
1154 return deleted == count;
1157 static const QgsPointSequence vectorPointXY2pointSequence(
const QVector<QgsPointXY> &points )
1160 pts.reserve( points.size() );
1161 QVector<const QgsPointXY>::iterator it = points.constBegin();
1162 while ( it != points.constEnd() )
1171 return addRing( vectorPointXY2pointSequence( ring ), featureId );
1176 if ( !
mValid || !mEditBuffer || !mDataProvider )
1177 return QgsGeometry::OperationResult::LayerNotEditable;
1183 if ( !mSelectedFeatureIds.isEmpty() )
1185 result = utils.
addRing( ring, mSelectedFeatureIds, featureId );
1188 if ( result != QgsGeometry::OperationResult::Success )
1199 if ( !
mValid || !mEditBuffer || !mDataProvider )
1202 return QgsGeometry::OperationResult::LayerNotEditable;
1207 return QgsGeometry::OperationResult::InvalidInputGeometryType;
1213 return QgsGeometry::OperationResult::AddRingNotClosed;
1220 if ( !mSelectedFeatureIds.isEmpty() )
1222 result = utils.
addRing( static_cast< QgsCurve * >( ring->
clone() ), mSelectedFeatureIds, featureId );
1225 if ( result != QgsGeometry::OperationResult::Success )
1238 pts.reserve( points.size() );
1239 for ( QList<QgsPointXY>::const_iterator it = points.constBegin(); it != points.constEnd() ; ++it )
1248 return addPart( vectorPointXY2pointSequence( points ) );
1253 if ( !
mValid || !mEditBuffer || !mDataProvider )
1254 return QgsGeometry::OperationResult::LayerNotEditable;
1258 if ( mSelectedFeatureIds.empty() )
1261 return QgsGeometry::OperationResult::SelectionIsEmpty;
1263 else if ( mSelectedFeatureIds.size() > 1 )
1266 return QgsGeometry::OperationResult::SelectionIsGreaterThanOne;
1272 if ( result == QgsGeometry::OperationResult::Success )
1279 if ( !
mValid || !mEditBuffer || !mDataProvider )
1280 return QgsGeometry::OperationResult::LayerNotEditable;
1284 if ( mSelectedFeatureIds.empty() )
1287 return QgsGeometry::OperationResult::SelectionIsEmpty;
1289 else if ( mSelectedFeatureIds.size() > 1 )
1292 return QgsGeometry::OperationResult::SelectionIsGreaterThanOne;
1298 if ( result == QgsGeometry::OperationResult::Success )
1305 if ( !
mValid || !mEditBuffer || !mDataProvider )
1306 return QgsGeometry::OperationResult::LayerNotEditable;
1311 if ( result == QgsGeometry::OperationResult::Success )
1318 return splitParts( vectorPointXY2pointSequence( splitLine ), topologicalEditing );
1322 if ( !
mValid || !mEditBuffer || !mDataProvider )
1323 return QgsGeometry::OperationResult::LayerNotEditable;
1326 return utils.
splitParts( splitLine, topologicalEditing );
1330 return splitFeatures( vectorPointXY2pointSequence( splitLine ), topologicalEditing );
1335 if ( !
mValid || !mEditBuffer || !mDataProvider )
1336 return QgsGeometry::OperationResult::LayerNotEditable;
1339 return utils.
splitFeatures( splitLine, topologicalEditing );
1344 if ( !
mValid || !mEditBuffer || !mDataProvider )
1358 if ( !
mValid || !mEditBuffer || !mDataProvider )
1367 if ( mLabeling == labeling )
1376 if ( !
mValid || !mDataProvider )
1438 if ( mDataProvider )
1445 if ( !mRenderer->
accept( visitor ) )
1449 if ( !mLabeling->
accept( visitor ) )
1460 QDomNode pkeyNode = layer_node.namedItem( QStringLiteral(
"provider" ) );
1462 if ( pkeyNode.isNull() )
1468 QDomElement pkeyElt = pkeyNode.toElement();
1478 else if (
mDataSource.contains( QLatin1String(
"dbname=" ) ) )
1490 if ( !(
mReadFlags & QgsMapLayer::FlagDontResolveLayers ) )
1494 const QDomElement elem = layer_node.toElement();
1497 if ( elem.hasAttribute( QStringLiteral(
"wkbType" ) ) )
1498 mWkbType =
qgsEnumKeyToValue( elem.attribute( QStringLiteral(
"wkbType" ) ), mWkbType );
1501 QDomElement pkeyElem = pkeyNode.toElement();
1502 if ( !pkeyElem.isNull() )
1504 QString encodingString = pkeyElem.attribute( QStringLiteral(
"encoding" ) );
1505 if ( mDataProvider && !encodingString.isEmpty() )
1512 mJoinBuffer->
readXml( layer_node );
1524 QDomNode depsNode = layer_node.namedItem( QStringLiteral(
"dataDependencies" ) );
1525 QDomNodeList depsNodes = depsNode.childNodes();
1526 QSet<QgsMapLayerDependency> sources;
1527 for (
int i = 0; i < depsNodes.count(); i++ )
1529 QString
source = depsNodes.at( i ).toElement().attribute( QStringLiteral(
"id" ) );
1535 QDomElement legendElem = layer_node.firstChildElement( QStringLiteral(
"legend" ) );
1536 if ( !legendElem.isNull() )
1537 legend->
readXml( legendElem, context );
1541 if ( mReadExtentFromXml )
1543 QDomNode extentNode = layer_node.namedItem( QStringLiteral(
"extent" ) );
1544 if ( !extentNode.isNull() )
1551 const QDomNode asNode = layer_node.namedItem( QStringLiteral(
"auxiliaryLayer" ) );
1552 const QDomElement asElem = asNode.toElement();
1553 if ( !asElem.isNull() )
1555 mAuxiliaryLayerKey = asElem.attribute( QStringLiteral(
"key" ) );
1559 mServerProperties->readXml( layer_node );
1569 setDataSource( dataSource, baseName, provider, options, loadDefaultStyleFlag );
1578 setDataProvider( provider, options );
1592 bool defaultLoadedFlag =
false;
1597 std::unique_ptr< QgsFeatureRenderer > defaultRenderer( mDataProvider->
createRenderer() );
1598 if ( defaultRenderer )
1600 defaultLoadedFlag =
true;
1607 if ( !defaultLoadedFlag && loadDefaultStyleFlag )
1613 if ( !defaultLoadedFlag &&
isSpatial() )
1623 std::unique_ptr< QgsAbstractVectorLayerLabeling > defaultLabeling( mDataProvider->
createLabeling() );
1624 if ( defaultLabeling )
1641 std::unique_ptr< QgsFeatureRenderer > defaultRenderer( mDataProvider->
createRenderer() );
1642 if ( defaultRenderer )
1657 delete mDataProvider;
1664 if ( provider.compare( QLatin1String(
"postgres" ) ) == 0 )
1666 const QString checkUnicityKey { QStringLiteral(
"checkPrimaryKeyUnicity" ) };
1668 if ( ! uri.
hasParam( checkUnicityKey ) )
1670 uri.
setParam( checkUnicityKey, mReadExtentFromXml ?
"0" :
"1" );
1676 if ( !mDataProvider )
1683 mDataProvider->setParent(
this );
1686 QgsDebugMsgLevel( QStringLiteral(
"Instantiated the data provider plugin" ), 2 );
1698 QgsDebugMsgLevel( QStringLiteral(
"Set Data provider QgsLayerMetadata identifier[%1]" ).arg(
metadata().identifier() ), 4 );
1705 mWkbType = mDataProvider->
wkbType();
1717 QRegExp reg( R
"lit("[^"]+"\."([^"] + )"( \([^)]+\))?)lit" ); 1718 if ( reg.indexIn(
name() ) >= 0 )
1720 QStringList stuff = reg.capturedTexts();
1721 QString lName = stuff[1];
1725 QMap<QString, QgsMapLayer *>::const_iterator it;
1726 for ( it = layers.constBegin(); it != layers.constEnd() && ( *it )->name() != lName; ++it )
1729 if ( it != layers.constEnd() && stuff.size() > 2 )
1731 lName +=
'.' + stuff[2].mid( 2, stuff[2].length() - 3 );
1734 if ( !lName.isEmpty() )
1744 else if ( provider == QLatin1String(
"ogr" ) )
1748 if (
mDataSource.right( 10 ) == QLatin1String(
"|layerid=0" ) )
1751 else if ( provider == QStringLiteral(
"memory" ) )
1768 QDomDocument &document,
1773 QDomElement mapLayerNode = layer_node.toElement();
1775 if ( mapLayerNode.isNull() || (
"maplayer" != mapLayerNode.nodeName() ) )
1781 mapLayerNode.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"vector" ) );
1788 if ( mDataProvider )
1790 QDomElement provider = document.createElement( QStringLiteral(
"provider" ) );
1791 provider.setAttribute( QStringLiteral(
"encoding" ), mDataProvider->
encoding() );
1792 QDomText providerText = document.createTextNode(
providerType() );
1793 provider.appendChild( providerText );
1794 layer_node.appendChild( provider );
1798 mJoinBuffer->
writeXml( layer_node, document );
1801 QDomElement dependenciesElement = document.createElement( QStringLiteral(
"layerDependencies" ) );
1807 QDomElement depElem = document.createElement( QStringLiteral(
"layer" ) );
1808 depElem.setAttribute( QStringLiteral(
"id" ), dep.layerId() );
1809 dependenciesElement.appendChild( depElem );
1811 layer_node.appendChild( dependenciesElement );
1814 QDomElement dataDependenciesElement = document.createElement( QStringLiteral(
"dataDependencies" ) );
1819 QDomElement depElem = document.createElement( QStringLiteral(
"layer" ) );
1820 depElem.setAttribute( QStringLiteral(
"id" ), dep.layerId() );
1821 dataDependenciesElement.appendChild( depElem );
1823 layer_node.appendChild( dataDependenciesElement );
1828 QDomElement legendElement =
legend()->
writeXml( document, context );
1829 if ( !legendElement.isNull() )
1830 layer_node.appendChild( legendElement );
1834 mExpressionFieldBuffer->
writeXml( layer_node, document );
1839 QDomElement asElem = document.createElement( QStringLiteral(
"auxiliaryLayer" ) );
1840 if ( mAuxiliaryLayer )
1842 const QString pkField = mAuxiliaryLayer->joinInfo().targetFieldName();
1843 asElem.setAttribute( QStringLiteral(
"key" ), pkField );
1845 layer_node.appendChild( asElem );
1848 mServerProperties->writeXml( layer_node, document );
1852 return writeSymbology( layer_node, document, errorMsg, context );
1857 QString src( source );
1869 QStringList theURIParts = src.split(
'|' );
1871 src = theURIParts.join( QStringLiteral(
"|" ) );
1875 QStringList theURIParts = src.split(
'?' );
1877 src = theURIParts.join( QStringLiteral(
"?" ) );
1879 else if (
providerType() == QLatin1String(
"delimitedtext" ) )
1881 QUrl urlSource = QUrl::fromEncoded( src.toLatin1() );
1883 urlDest.setQueryItems( urlSource.queryItems() );
1884 src = QString::fromLatin1( urlDest.toEncoded() );
1886 else if (
providerType() == QLatin1String(
"memory" ) )
1891 else if (
providerType() == QLatin1String(
"virtual" ) )
1893 QUrl urlSource = QUrl::fromEncoded( src.toLatin1() );
1894 QStringList theURIParts;
1896 QUrlQuery query = QUrlQuery( urlSource.query() );
1897 QList<QPair<QString, QString> > queryItems = query.queryItems();
1899 for (
int i = 0; i < queryItems.size(); i++ )
1901 QString key = queryItems.at( i ).first;
1902 QString value = queryItems.at( i ).second;
1903 if ( key == QLatin1String(
"layer" ) )
1906 theURIParts = value.split(
':' );
1907 theURIParts[1] = QUrl::fromPercentEncoding( theURIParts[1].toUtf8() );
1909 theURIParts[1] = QUrl::toPercentEncoding( theURIParts[1] );
1910 queryItems[i].second = theURIParts.join( QStringLiteral(
":" ) ) ;
1914 query.setQueryItems( queryItems );
1916 QUrl urlDest = QUrl( urlSource );
1917 urlDest.setQuery( query.query() );
1918 src = QString::fromLatin1( urlDest.toEncoded() );
1930 QString src( source );
1932 if ( provider == QLatin1String(
"spatialite" ) )
1938 else if ( provider == QLatin1String(
"ogr" ) )
1940 QStringList theURIParts = src.split(
'|' );
1942 src = theURIParts.join( QStringLiteral(
"|" ) );
1944 else if ( provider == QLatin1String(
"gpx" ) )
1946 QStringList theURIParts = src.split(
'?' );
1948 src = theURIParts.join( QStringLiteral(
"?" ) );
1950 else if ( provider == QLatin1String(
"delimitedtext" ) )
1952 QUrl urlSource = QUrl::fromEncoded( src.toLatin1() );
1954 if ( !src.startsWith( QLatin1String(
"file:" ) ) )
1956 QUrl file = QUrl::fromLocalFile( src.left( src.indexOf(
'?' ) ) );
1957 urlSource.setScheme( QStringLiteral(
"file" ) );
1958 urlSource.setPath( file.path() );
1961 QUrl urlDest = QUrl::fromLocalFile( context.
pathResolver().
readPath( urlSource.toLocalFile() ) );
1962 urlDest.setQueryItems( urlSource.queryItems() );
1963 src = QString::fromLatin1( urlDest.toEncoded() );
1965 else if ( provider == QLatin1String(
"virtual" ) )
1967 QUrl urlSource = QUrl::fromEncoded( src.toLatin1() );
1968 QStringList theURIParts;
1970 QUrlQuery query = QUrlQuery( urlSource.query() );
1971 QList<QPair<QString, QString> > queryItems = query.queryItems();
1973 for (
int i = 0; i < queryItems.size(); i++ )
1975 QString key = queryItems.at( i ).first;
1976 QString value = queryItems.at( i ).second;
1977 if ( key == QLatin1String(
"layer" ) )
1980 theURIParts = value.split(
':' );
1981 theURIParts[1] = QUrl::fromPercentEncoding( theURIParts[1].toUtf8() );
1983 theURIParts[1] = QUrl::toPercentEncoding( theURIParts[1] );
1984 queryItems[i].second = theURIParts.join( QStringLiteral(
":" ) ) ;
1988 query.setQueryItems( queryItems );
1990 QUrl urlDest = QUrl( urlSource );
1991 urlDest.setQuery( query.query() );
1992 src = QString::fromLatin1( urlDest.toEncoded() );
2016 if ( categories.testFlag(
Fields ) )
2018 if ( !mExpressionFieldBuffer )
2020 mExpressionFieldBuffer->
readXml( layerNode );
2025 QDomElement layerElement = layerNode.toElement();
2029 readStyle( layerNode, errorMessage, context, categories );
2031 if ( categories.testFlag(
MapTips ) )
2032 mMapTipTemplate = layerNode.namedItem( QStringLiteral(
"mapTip" ) ).toElement().text();
2035 mDisplayExpression = layerNode.namedItem( QStringLiteral(
"previewExpression" ) ).toElement().text();
2038 QString
displayField = layerNode.namedItem( QStringLiteral(
"displayfield" ) ).toElement().text();
2042 if ( mMapTipTemplate.isEmpty() && categories.testFlag(
MapTips ) )
2043 mMapTipTemplate = displayField;
2052 if ( categories.testFlag(
Actions ) )
2053 mActions->
readXml( layerNode );
2055 if ( categories.testFlag(
Fields ) )
2057 mAttributeAliasMap.clear();
2058 QDomNode aliasesNode = layerNode.namedItem( QStringLiteral(
"aliases" ) );
2059 if ( !aliasesNode.isNull() )
2061 QDomElement aliasElem;
2063 QDomNodeList aliasNodeList = aliasesNode.toElement().elementsByTagName( QStringLiteral(
"alias" ) );
2064 for (
int i = 0; i < aliasNodeList.size(); ++i )
2066 aliasElem = aliasNodeList.at( i ).toElement();
2069 if ( aliasElem.hasAttribute( QStringLiteral(
"field" ) ) )
2071 field = aliasElem.attribute( QStringLiteral(
"field" ) );
2075 int index = aliasElem.attribute( QStringLiteral(
"index" ) ).toInt();
2077 if ( index >= 0 && index <
fields().count() )
2083 if ( !aliasElem.attribute( QStringLiteral(
"name" ) ).isEmpty() )
2086 alias = context.
projectTranslator()->
translate( QStringLiteral(
"project:layers:%1:fieldaliases" ).arg( layerNode.namedItem( QStringLiteral(
"id" ) ).toElement().text() ), aliasElem.attribute( QStringLiteral(
"name" ) ) );
2087 QgsDebugMsgLevel(
"context" + QStringLiteral(
"project:layers:%1:fieldaliases" ).arg( layerNode.namedItem( QStringLiteral(
"id" ) ).toElement().text() ) +
" source " + aliasElem.attribute( QStringLiteral(
"name" ) ), 3 );
2092 alias = context.
projectTranslator()->
translate( QStringLiteral(
"project:layers:%1:fieldaliases" ).arg( layerNode.namedItem( QStringLiteral(
"id" ) ).toElement().text() ), field );
2093 QgsDebugMsgLevel(
"context" + QStringLiteral(
"project:layers:%1:fieldaliases" ).arg( layerNode.namedItem( QStringLiteral(
"id" ) ).toElement().text() ) +
" source " + field, 3 );
2095 if ( alias == aliasElem.attribute( QStringLiteral(
"field" ) ) )
2099 QgsDebugMsgLevel(
"field " + field +
" origalias " + aliasElem.attribute( QStringLiteral(
"name" ) ) +
" trans " + alias, 3 );
2100 mAttributeAliasMap.insert( field, alias );
2105 mDefaultExpressionMap.clear();
2106 QDomNode defaultsNode = layerNode.namedItem( QStringLiteral(
"defaults" ) );
2107 if ( !defaultsNode.isNull() )
2109 QDomNodeList defaultNodeList = defaultsNode.toElement().elementsByTagName( QStringLiteral(
"default" ) );
2110 for (
int i = 0; i < defaultNodeList.size(); ++i )
2112 QDomElement defaultElem = defaultNodeList.at( i ).toElement();
2114 QString field = defaultElem.attribute( QStringLiteral(
"field" ), QString() );
2115 QString expression = defaultElem.attribute( QStringLiteral(
"expression" ), QString() );
2116 bool applyOnUpdate = defaultElem.attribute( QStringLiteral(
"applyOnUpdate" ), QStringLiteral(
"0" ) ) == QLatin1String(
"1" );
2117 if ( field.isEmpty() || expression.isEmpty() )
2120 mDefaultExpressionMap.insert( field,
QgsDefaultValue( expression, applyOnUpdate ) );
2125 mFieldConstraints.clear();
2126 mFieldConstraintStrength.clear();
2127 QDomNode constraintsNode = layerNode.namedItem( QStringLiteral(
"constraints" ) );
2128 if ( !constraintsNode.isNull() )
2130 QDomNodeList constraintNodeList = constraintsNode.toElement().elementsByTagName( QStringLiteral(
"constraint" ) );
2131 for (
int i = 0; i < constraintNodeList.size(); ++i )
2133 QDomElement constraintElem = constraintNodeList.at( i ).toElement();
2135 QString field = constraintElem.attribute( QStringLiteral(
"field" ), QString() );
2136 int constraints = constraintElem.attribute( QStringLiteral(
"constraints" ), QStringLiteral(
"0" ) ).toInt();
2137 if ( field.isEmpty() || constraints == 0 )
2140 mFieldConstraints.insert( field, static_cast< QgsFieldConstraints::Constraints >( constraints ) );
2142 int uniqueStrength = constraintElem.attribute( QStringLiteral(
"unique_strength" ), QStringLiteral(
"1" ) ).toInt();
2143 int notNullStrength = constraintElem.attribute( QStringLiteral(
"notnull_strength" ), QStringLiteral(
"1" ) ).toInt();
2144 int expStrength = constraintElem.attribute( QStringLiteral(
"exp_strength" ), QStringLiteral(
"1" ) ).toInt();
2151 mFieldConstraintExpressions.clear();
2152 QDomNode constraintExpressionsNode = layerNode.namedItem( QStringLiteral(
"constraintExpressions" ) );
2153 if ( !constraintExpressionsNode.isNull() )
2155 QDomNodeList constraintNodeList = constraintExpressionsNode.toElement().elementsByTagName( QStringLiteral(
"constraint" ) );
2156 for (
int i = 0; i < constraintNodeList.size(); ++i )
2158 QDomElement constraintElem = constraintNodeList.at( i ).toElement();
2160 QString field = constraintElem.attribute( QStringLiteral(
"field" ), QString() );
2161 QString exp = constraintElem.attribute( QStringLiteral(
"exp" ), QString() );
2162 QString desc = constraintElem.attribute( QStringLiteral(
"desc" ), QString() );
2163 if ( field.isEmpty() || exp.isEmpty() )
2166 mFieldConstraintExpressions.insert( field, qMakePair( exp, desc ) );
2173 mExcludeAttributesWMS.clear();
2174 QDomNode excludeWMSNode = layerNode.namedItem( QStringLiteral(
"excludeAttributesWMS" ) );
2175 if ( !excludeWMSNode.isNull() )
2177 QDomNodeList attributeNodeList = excludeWMSNode.toElement().elementsByTagName( QStringLiteral(
"attribute" ) );
2178 for (
int i = 0; i < attributeNodeList.size(); ++i )
2180 mExcludeAttributesWMS.insert( attributeNodeList.at( i ).toElement().text() );
2184 mExcludeAttributesWFS.clear();
2185 QDomNode excludeWFSNode = layerNode.namedItem( QStringLiteral(
"excludeAttributesWFS" ) );
2186 if ( !excludeWFSNode.isNull() )
2188 QDomNodeList attributeNodeList = excludeWFSNode.toElement().elementsByTagName( QStringLiteral(
"attribute" ) );
2189 for (
int i = 0; i < attributeNodeList.size(); ++i )
2191 mExcludeAttributesWFS.insert( attributeNodeList.at( i ).toElement().text() );
2196 QDomElement widgetsElem = layerNode.namedItem( QStringLiteral(
"fieldConfiguration" ) ).toElement();
2197 QDomNodeList fieldConfigurationElementList = widgetsElem.elementsByTagName( QStringLiteral(
"field" ) );
2198 for (
int i = 0; i < fieldConfigurationElementList.size(); ++i )
2200 const QDomElement fieldConfigElement = fieldConfigurationElementList.at( i ).toElement();
2201 const QDomElement fieldWidgetElement = fieldConfigElement.elementsByTagName( QStringLiteral(
"editWidget" ) ).at( 0 ).toElement();
2203 QString fieldName = fieldConfigElement.attribute( QStringLiteral(
"name" ) );
2205 const QString widgetType = fieldWidgetElement.attribute( QStringLiteral(
"type" ) );
2206 const QDomElement cfgElem = fieldConfigElement.elementsByTagName( QStringLiteral(
"config" ) ).at( 0 ).toElement();
2207 const QDomElement optionsElem = cfgElem.childNodes().at( 0 ).toElement();
2209 if ( widgetType == QStringLiteral(
"ValueRelation" ) )
2211 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() );
2214 mFieldWidgetSetups[fieldName] = setup;
2219 mGeometryOptions->readXml( layerNode.namedItem( QStringLiteral(
"geometryOptions" ) ) );
2221 if ( categories.testFlag(
Forms ) )
2222 mEditFormConfig.
readXml( layerNode, context );
2226 mAttributeTableConfig.
readXml( layerNode );
2227 mConditionalStyles->
readXml( layerNode, context );
2228 mStoredExpressionManager->
readXml( layerNode );
2234 QDomElement mapLayerNode = layerNode.toElement();
2236 && mapLayerNode.attribute( QStringLiteral(
"readOnly" ), QStringLiteral(
"0" ) ).toInt() == 1 )
2259 if ( !rendererElement.isNull() )
2279 if ( categories.testFlag(
Labeling ) )
2281 QDomElement labelingElement = node.firstChildElement( QStringLiteral(
"labeling" ) );
2283 if ( labelingElement.isNull() ||
2284 ( labelingElement.attribute( QStringLiteral(
"type" ) ) == QLatin1String(
"simple" ) && labelingElement.firstChildElement( QStringLiteral(
"settings" ) ).isNull() ) )
2292 labeling = readLabelingFromCustomProperties();
2300 if ( node.toElement().hasAttribute( QStringLiteral(
"labelsEnabled" ) ) )
2301 mLabelsEnabled = node.toElement().attribute( QStringLiteral(
"labelsEnabled" ) ).toInt();
2303 mLabelsEnabled =
true;
2309 QDomNode blendModeNode = node.namedItem( QStringLiteral(
"blendMode" ) );
2310 if ( !blendModeNode.isNull() )
2312 QDomElement e = blendModeNode.toElement();
2317 QDomNode featureBlendModeNode = node.namedItem( QStringLiteral(
"featureBlendMode" ) );
2318 if ( !featureBlendModeNode.isNull() )
2320 QDomElement e = featureBlendModeNode.toElement();
2328 QDomNode layerTransparencyNode = node.namedItem( QStringLiteral(
"layerTransparency" ) );
2329 if ( !layerTransparencyNode.isNull() )
2331 QDomElement e = layerTransparencyNode.toElement();
2332 setOpacity( 1.0 - e.text().toInt() / 100.0 );
2334 QDomNode layerOpacityNode = node.namedItem( QStringLiteral(
"layerOpacity" ) );
2335 if ( !layerOpacityNode.isNull() )
2337 QDomElement e = layerOpacityNode.toElement();
2344 QDomElement e = node.toElement();
2347 mSimplifyMethod.
setSimplifyHints( static_cast< QgsVectorSimplifyMethod::SimplifyHints >( e.attribute( QStringLiteral(
"simplifyDrawingHints" ), QStringLiteral(
"1" ) ).toInt() ) );
2348 mSimplifyMethod.
setSimplifyAlgorithm( static_cast< QgsVectorSimplifyMethod::SimplifyAlgorithm >( e.attribute( QStringLiteral(
"simplifyAlgorithm" ), QStringLiteral(
"0" ) ).toInt() ) );
2349 mSimplifyMethod.
setThreshold( e.attribute( QStringLiteral(
"simplifyDrawingTol" ), QStringLiteral(
"1" ) ).toFloat() );
2350 mSimplifyMethod.
setForceLocalOptimization( e.attribute( QStringLiteral(
"simplifyLocal" ), QStringLiteral(
"1" ) ).toInt() );
2351 mSimplifyMethod.
setMaximumScale( e.attribute( QStringLiteral(
"simplifyMaxScale" ), QStringLiteral(
"1" ) ).toFloat() );
2355 if ( categories.testFlag(
Diagrams ) )
2357 delete mDiagramRenderer;
2358 mDiagramRenderer =
nullptr;
2359 QDomElement singleCatDiagramElem = node.firstChildElement( QStringLiteral(
"SingleCategoryDiagramRenderer" ) );
2360 if ( !singleCatDiagramElem.isNull() )
2363 mDiagramRenderer->
readXml( singleCatDiagramElem, context );
2365 QDomElement linearDiagramElem = node.firstChildElement( QStringLiteral(
"LinearlyInterpolatedDiagramRenderer" ) );
2366 if ( !linearDiagramElem.isNull() )
2368 if ( linearDiagramElem.hasAttribute( QStringLiteral(
"classificationAttribute" ) ) )
2371 int idx = linearDiagramElem.attribute( QStringLiteral(
"classificationAttribute" ) ).toInt();
2372 if ( idx >= 0 && idx < mFields.
count() )
2373 linearDiagramElem.setAttribute( QStringLiteral(
"classificationField" ), mFields.
at( idx ).
name() );
2377 mDiagramRenderer->
readXml( linearDiagramElem, context );
2380 if ( mDiagramRenderer )
2382 QDomElement diagramSettingsElem = node.firstChildElement( QStringLiteral(
"DiagramLayerSettings" ) );
2383 if ( !diagramSettingsElem.isNull() )
2385 bool oldXPos = diagramSettingsElem.hasAttribute( QStringLiteral(
"xPosColumn" ) );
2386 bool oldYPos = diagramSettingsElem.hasAttribute( QStringLiteral(
"yPosColumn" ) );
2387 bool oldShow = diagramSettingsElem.hasAttribute( QStringLiteral(
"showColumn" ) );
2388 if ( oldXPos || oldYPos || oldShow )
2394 int xPosColumn = diagramSettingsElem.attribute( QStringLiteral(
"xPosColumn" ) ).toInt();
2395 if ( xPosColumn >= 0 && xPosColumn < mFields.
count() )
2400 int yPosColumn = diagramSettingsElem.attribute( QStringLiteral(
"yPosColumn" ) ).toInt();
2401 if ( yPosColumn >= 0 && yPosColumn < mFields.
count() )
2406 int showColumn = diagramSettingsElem.attribute( QStringLiteral(
"showColumn" ) ).toInt();
2407 if ( showColumn >= 0 && showColumn < mFields.
count() )
2410 QDomElement propertiesElem = diagramSettingsElem.ownerDocument().createElement( QStringLiteral(
"properties" ) );
2417 ddp.
writeXml( propertiesElem, defs );
2418 diagramSettingsElem.appendChild( propertiesElem );
2421 delete mDiagramLayerSettings;
2423 mDiagramLayerSettings->
readXml( diagramSettingsElem );
2436 QDomElement layerElement = node.toElement();
2439 ( void )
writeStyle( node, doc, errorMessage, context, categories );
2442 mGeometryOptions->writeXml( node );
2444 if ( categories.testFlag(
Fields ) )
2446 QDomElement fieldConfigurationElement = doc.createElement( QStringLiteral(
"fieldConfiguration" ) );
2447 node.appendChild( fieldConfigurationElement );
2450 for (
const QgsField &field : mFields )
2452 QDomElement fieldElement = doc.createElement( QStringLiteral(
"field" ) );
2453 fieldElement.setAttribute( QStringLiteral(
"name" ), field.name() );
2455 fieldConfigurationElement.appendChild( fieldElement );
2460 QDomElement editWidgetElement = doc.createElement( QStringLiteral(
"editWidget" ) );
2461 fieldElement.appendChild( editWidgetElement );
2462 editWidgetElement.setAttribute( QStringLiteral(
"type" ), field.editorWidgetSetup().type() );
2463 QDomElement editWidgetConfigElement = doc.createElement( QStringLiteral(
"config" ) );
2466 editWidgetElement.appendChild( editWidgetConfigElement );
2473 QDomElement aliasElem = doc.createElement( QStringLiteral(
"aliases" ) );
2474 for (
const QgsField &field : mFields )
2476 QDomElement aliasEntryElem = doc.createElement( QStringLiteral(
"alias" ) );
2477 aliasEntryElem.setAttribute( QStringLiteral(
"field" ), field.name() );
2478 aliasEntryElem.setAttribute( QStringLiteral(
"index" ), mFields.indexFromName( field.name() ) );
2479 aliasEntryElem.setAttribute( QStringLiteral(
"name" ), field.alias() );
2480 aliasElem.appendChild( aliasEntryElem );
2482 node.appendChild( aliasElem );
2485 QDomElement excludeWMSElem = doc.createElement( QStringLiteral(
"excludeAttributesWMS" ) );
2486 QSet<QString>::const_iterator attWMSIt = mExcludeAttributesWMS.constBegin();
2487 for ( ; attWMSIt != mExcludeAttributesWMS.constEnd(); ++attWMSIt )
2489 QDomElement attrElem = doc.createElement( QStringLiteral(
"attribute" ) );
2490 QDomText attrText = doc.createTextNode( *attWMSIt );
2491 attrElem.appendChild( attrText );
2492 excludeWMSElem.appendChild( attrElem );
2494 node.appendChild( excludeWMSElem );
2497 QDomElement excludeWFSElem = doc.createElement( QStringLiteral(
"excludeAttributesWFS" ) );
2498 QSet<QString>::const_iterator attWFSIt = mExcludeAttributesWFS.constBegin();
2499 for ( ; attWFSIt != mExcludeAttributesWFS.constEnd(); ++attWFSIt )
2501 QDomElement attrElem = doc.createElement( QStringLiteral(
"attribute" ) );
2502 QDomText attrText = doc.createTextNode( *attWFSIt );
2503 attrElem.appendChild( attrText );
2504 excludeWFSElem.appendChild( attrElem );
2506 node.appendChild( excludeWFSElem );
2509 QDomElement defaultsElem = doc.createElement( QStringLiteral(
"defaults" ) );
2510 for (
const QgsField &field : mFields )
2512 QDomElement defaultElem = doc.createElement( QStringLiteral(
"default" ) );
2513 defaultElem.setAttribute( QStringLiteral(
"field" ), field.name() );
2514 defaultElem.setAttribute( QStringLiteral(
"expression" ), field.defaultValueDefinition().expression() );
2515 defaultElem.setAttribute( QStringLiteral(
"applyOnUpdate" ), field.defaultValueDefinition().applyOnUpdate() ? QStringLiteral(
"1" ) : QStringLiteral(
"0" ) );
2516 defaultsElem.appendChild( defaultElem );
2518 node.appendChild( defaultsElem );
2521 QDomElement constraintsElem = doc.createElement( QStringLiteral(
"constraints" ) );
2522 for (
const QgsField &field : mFields )
2524 QDomElement constraintElem = doc.createElement( QStringLiteral(
"constraint" ) );
2525 constraintElem.setAttribute( QStringLiteral(
"field" ), field.name() );
2526 constraintElem.setAttribute( QStringLiteral(
"constraints" ), field.constraints().constraints() );
2530 constraintsElem.appendChild( constraintElem );
2532 node.appendChild( constraintsElem );
2535 QDomElement constraintExpressionsElem = doc.createElement( QStringLiteral(
"constraintExpressions" ) );
2536 for (
const QgsField &field : mFields )
2538 QDomElement constraintExpressionElem = doc.createElement( QStringLiteral(
"constraint" ) );
2539 constraintExpressionElem.setAttribute( QStringLiteral(
"field" ), field.name() );
2540 constraintExpressionElem.setAttribute( QStringLiteral(
"exp" ), field.constraints().constraintExpression() );
2541 constraintExpressionElem.setAttribute( QStringLiteral(
"desc" ), field.constraints().constraintDescription() );
2542 constraintExpressionsElem.appendChild( constraintExpressionElem );
2544 node.appendChild( constraintExpressionsElem );
2547 if ( !mExpressionFieldBuffer )
2555 mExpressionFieldBuffer->
writeXml( node, doc );
2560 if ( categories.testFlag(
Actions ) )
2565 mAttributeTableConfig.
writeXml( node );
2566 mConditionalStyles->
writeXml( node, doc, context );
2567 mStoredExpressionManager->
writeXml( node );
2570 if ( categories.testFlag(
Forms ) )
2571 mEditFormConfig.
writeXml( node, context );
2575 node.toElement().setAttribute( QStringLiteral(
"readOnly" ), mReadOnly );
2580 QDomElement prevExpElem = doc.createElement( QStringLiteral(
"previewExpression" ) );
2581 QDomText prevExpText = doc.createTextNode( mDisplayExpression );
2582 prevExpElem.appendChild( prevExpText );
2583 node.appendChild( prevExpElem );
2587 if ( categories.testFlag(
MapTips ) )
2589 QDomElement mapTipElem = doc.createElement( QStringLiteral(
"mapTip" ) );
2590 QDomText mapTipText = doc.createTextNode( mMapTipTemplate );
2591 mapTipElem.appendChild( mapTipText );
2592 node.toElement().appendChild( mapTipElem );
2601 QDomElement mapLayerNode = node.toElement();
2611 QDomElement rendererElement = mRenderer->
save( doc, context );
2612 node.appendChild( rendererElement );
2616 if ( categories.testFlag(
Labeling ) )
2620 QDomElement labelingElement = mLabeling->
save( doc, context );
2621 node.appendChild( labelingElement );
2623 mapLayerNode.setAttribute( QStringLiteral(
"labelsEnabled" ), mLabelsEnabled ? QStringLiteral(
"1" ) : QStringLiteral(
"0" ) );
2629 mapLayerNode.setAttribute( QStringLiteral(
"simplifyDrawingHints" ), QString::number( mSimplifyMethod.
simplifyHints() ) );
2630 mapLayerNode.setAttribute( QStringLiteral(
"simplifyAlgorithm" ), QString::number( mSimplifyMethod.
simplifyAlgorithm() ) );
2631 mapLayerNode.setAttribute( QStringLiteral(
"simplifyDrawingTol" ), QString::number( mSimplifyMethod.
threshold() ) );
2632 mapLayerNode.setAttribute( QStringLiteral(
"simplifyLocal" ), mSimplifyMethod.
forceLocalOptimization() ? 1 : 0 );
2633 mapLayerNode.setAttribute( QStringLiteral(
"simplifyMaxScale" ), QString::number( mSimplifyMethod.
maximumScale() ) );
2645 QDomElement blendModeElem = doc.createElement( QStringLiteral(
"blendMode" ) );
2647 blendModeElem.appendChild( blendModeText );
2648 node.appendChild( blendModeElem );
2651 QDomElement featureBlendModeElem = doc.createElement( QStringLiteral(
"featureBlendMode" ) );
2653 featureBlendModeElem.appendChild( featureBlendModeText );
2654 node.appendChild( featureBlendModeElem );
2660 QDomElement layerOpacityElem = doc.createElement( QStringLiteral(
"layerOpacity" ) );
2661 QDomText layerOpacityText = doc.createTextNode( QString::number(
opacity() ) );
2662 layerOpacityElem.appendChild( layerOpacityText );
2663 node.appendChild( layerOpacityElem );
2666 if ( categories.testFlag(
Diagrams ) && mDiagramRenderer )
2668 mDiagramRenderer->
writeXml( mapLayerNode, doc, context );
2669 if ( mDiagramLayerSettings )
2670 mDiagramLayerSettings->
writeXml( mapLayerNode, doc );
2679 QDomElement nameElem = node.firstChildElement( QStringLiteral(
"Name" ) );
2680 if ( nameElem.isNull() )
2682 errorMessage = QStringLiteral(
"Warning: Name element not found within NamedLayer while it's required." );
2694 readSldLabeling( node );
2701 Q_UNUSED( errorMessage )
2712 QDomElement nameNode = doc.createElement( QStringLiteral(
"se:Name" ) );
2713 nameNode.appendChild( doc.createTextNode(
name() ) );
2714 node.appendChild( nameNode );
2716 QDomElement userStyleElem = doc.createElement( QStringLiteral(
"UserStyle" ) );
2717 node.appendChild( userStyleElem );
2719 QDomElement nameElem = doc.createElement( QStringLiteral(
"se:Name" ) );
2720 nameElem.appendChild( doc.createTextNode(
name() ) );
2722 userStyleElem.appendChild( nameElem );
2724 QDomElement featureTypeStyleElem = doc.createElement( QStringLiteral(
"se:FeatureTypeStyle" ) );
2725 userStyleElem.appendChild( featureTypeStyleElem );
2727 mRenderer->
toSld( doc, featureTypeStyleElem, localProps );
2730 mLabeling->
toSld( featureTypeStyleElem, localProps );
2739 if ( !mEditBuffer || !mDataProvider )
2744 if ( mGeometryOptions->isActive() )
2745 mGeometryOptions->apply( geom );
2754 if ( !skipDefaultValue && !mDefaultValueOnUpdateFields.isEmpty() )
2755 updateDefaultValues( fid );
2763 bool result =
false;
2765 switch (
fields().fieldOrigin( field ) )
2777 if ( mEditBuffer && mDataProvider )
2786 if ( result && !skipDefaultValues && !mDefaultValueOnUpdateFields.isEmpty() )
2787 updateDefaultValues( fid );
2802 for (
auto it = newValues.constBegin(); it != newValues.constEnd(); ++it )
2804 const int field = it.key();
2805 const QVariant newValue = it.value();
2808 if ( oldValues.contains( field ) )
2809 oldValue = oldValues[field];
2814 newValuesJoin[field] = newValue;
2815 oldValuesJoin[field] = oldValue;
2822 newValuesNotJoin[field] = newValue;
2823 oldValuesNotJoin[field] = oldValue;
2832 if ( ! newValuesJoin.isEmpty() && mJoinBuffer )
2837 if ( ! newValuesNotJoin.isEmpty() && mEditBuffer && mDataProvider )
2842 if ( result && !skipDefaultValues && !mDefaultValueOnUpdateFields.isEmpty() )
2844 updateDefaultValues( fid );
2852 if ( !mEditBuffer || !mDataProvider )
2860 if ( attIndex < 0 || attIndex >=
fields().count() )
2864 mFields[ attIndex ].setAlias( QString() );
2865 if ( mAttributeAliasMap.contains( name ) )
2867 mAttributeAliasMap.remove( name );
2869 mEditFormConfig.setFields( mFields );
2876 if ( index < 0 || index >=
fields().count() )
2883 if ( mExpressionFieldBuffer )
2899 if ( !mEditBuffer || !mDataProvider )
2915 if ( attIndex < 0 || attIndex >=
fields().count() )
2920 mAttributeAliasMap.insert( name, aliasString );
2921 mFields[ attIndex ].setAlias( aliasString );
2922 mEditFormConfig.setFields( mFields );
2928 if ( index < 0 || index >=
fields().count() )
2936 if ( index >= 0 && index < mFields.
count() )
2944 return mAttributeAliasMap;
2949 if ( index < 0 || index >=
fields().count() )
2958 if ( !mEditBuffer || !mDataProvider )
2966 bool deleted =
false;
2969 QList<int> attrList = attrs.toSet().toList();
2971 std::sort( attrList.begin(), attrList.end(), std::greater<int>() );
2973 for (
int attr : qgis::as_const( attrList ) )
2995 mSelectedFeatureIds.remove( fid );
3006 QgsDebugMsgLevel( QStringLiteral(
"Cannot delete features (mEditBuffer==NULL)" ), 1 );
3017 mSelectedFeatureIds.subtract( fids );
3034 for (
int i = 0; i < mFields.
count(); ++i )
3038 pkAttributesList << i;
3041 return pkAttributesList;
3046 if ( ! mDataProvider )
3057 if ( mEditBuffer && !deletedFeatures.empty() )
3059 if ( addedFeatures.size() > deletedFeatures.size() )
3060 return QgsFeatureSource::FeatureAvailability::FeaturesAvailable;
3062 return QgsFeatureSource::FeatureAvailability::FeaturesMaybeAvailable;
3065 if ( ( !mEditBuffer || addedFeatures.empty() ) && mDataProvider->
empty() )
3066 return QgsFeatureSource::FeatureAvailability::NoFeaturesAvailable;
3068 return QgsFeatureSource::FeatureAvailability::FeaturesAvailable;
3073 mCommitErrors.clear();
3075 if ( !mDataProvider )
3077 mCommitErrors << tr(
"ERROR: no provider" );
3083 mCommitErrors << tr(
"ERROR: layer not editable" );
3089 if ( !mAllowCommit )
3097 mEditBuffer =
nullptr;
3118 return mCommitErrors;
3150 mEditBuffer =
nullptr;
3155 if ( rollbackExtent )
3166 return mSelectedFeatureIds.size();
3171 return mSelectedFeatureIds;
3177 features.reserve( mSelectedFeatureIds.count() );
3180 if ( mSelectedFeatureIds.count() <= 8 )
3184 const auto constMSelectedFeatureIds = mSelectedFeatureIds;
3197 features.push_back( f );
3206 if ( mSelectedFeatureIds.isEmpty() )
3212 if ( mSelectedFeatureIds.count() == 1 )
3213 request.
setFilterFid( *mSelectedFeatureIds.constBegin() );
3222 if ( !mEditBuffer || !mDataProvider )
3225 if ( mGeometryOptions->isActive() )
3227 for (
auto feature = features.begin(); feature != features.end(); ++feature )
3230 mGeometryOptions->apply( geom );
3263 if ( mDisplayExpression == displayExpression )
3272 if ( !mDisplayExpression.isEmpty() || mFields.
isEmpty() )
3274 return mDisplayExpression;
3287 static QStringList sCandidates{ QStringLiteral(
"name" ),
3288 QStringLiteral(
"title" ),
3289 QStringLiteral(
"heibt" ),
3290 QStringLiteral(
"desc" ),
3291 QStringLiteral(
"nom" ),
3292 QStringLiteral(
"street" ),
3293 QStringLiteral(
"road" ),
3294 QStringLiteral(
"id" )};
3295 for (
const QString &candidate : sCandidates )
3297 for (
const QgsField &field : mFields )
3299 QString fldName = field.name();
3300 if ( fldName.indexOf( candidate, 0, Qt::CaseInsensitive ) > -1 )
3307 if ( !idxName.isEmpty() )
3311 if ( !idxName.isNull() )
3324 return ( mEditBuffer && mDataProvider );
3333 bool QgsVectorLayer::isReadOnly()
const 3341 if ( readonly && mEditBuffer )
3344 mReadOnly = readonly;
3352 return mEditBuffer && mEditBuffer->
isModified();
3357 bool auxiliaryField =
false;
3361 return auxiliaryField;
3368 auxiliaryField =
true;
3371 return auxiliaryField;
3382 if ( r != mRenderer )
3386 mSymbolFeatureCounted =
false;
3387 mSymbolFeatureCountMap.clear();
3388 mSymbolFeatureIdMap.clear();
3397 if ( !mDataProvider )
3403 QString ignoredError;
3407 mEditCommandActive =
true;
3413 if ( !mDataProvider )
3418 mEditCommandActive =
false;
3419 if ( !mDeletedFids.isEmpty() )
3422 mDeletedFids.clear();
3429 if ( !mDataProvider )
3440 std::unique_ptr< QUndoCommand > command = qgis::make_unique< QUndoCommand >();
3441 command->setObsolete(
true );
3444 mEditCommandActive =
false;
3445 mDeletedFids.clear();
3451 return mJoinBuffer->
addJoin( joinInfo );
3457 return mJoinBuffer->
removeJoin( joinLayerId );
3487 if ( oi < 0 || oi >= mExpressionFieldBuffer->
expressions().size() )
3490 return mExpressionFieldBuffer->
expressions().at( oi ).cachedExpression.expression();
3501 if ( !mDataProvider )
3506 mFields = mDataProvider->
fields();
3516 if ( mExpressionFieldBuffer )
3520 QMap< QString, QString >::const_iterator aliasIt = mAttributeAliasMap.constBegin();
3521 for ( ; aliasIt != mAttributeAliasMap.constEnd(); ++aliasIt )
3527 mFields[ index ].setAlias( aliasIt.value() );
3531 mDefaultValueOnUpdateFields.clear();
3532 QMap< QString, QgsDefaultValue >::const_iterator defaultIt = mDefaultExpressionMap.constBegin();
3533 for ( ; defaultIt != mDefaultExpressionMap.constEnd(); ++defaultIt )
3535 int index = mFields.
lookupField( defaultIt.key() );
3539 mFields[ index ].setDefaultValueDefinition( defaultIt.value() );
3540 if ( defaultIt.value().applyOnUpdate() )
3541 mDefaultValueOnUpdateFields.insert( index );
3544 QMap< QString, QgsFieldConstraints::Constraints >::const_iterator constraintIt = mFieldConstraints.constBegin();
3545 for ( ; constraintIt != mFieldConstraints.constEnd(); ++constraintIt )
3547 int index = mFields.
lookupField( constraintIt.key() );
3560 mFields[ index ].setConstraints( constraints );
3563 QMap< QString, QPair< QString, QString > >::const_iterator constraintExpIt = mFieldConstraintExpressions.constBegin();
3564 for ( ; constraintExpIt != mFieldConstraintExpressions.constEnd(); ++constraintExpIt )
3566 int index = mFields.
lookupField( constraintExpIt.key() );
3577 mFields[ index ].setConstraints( constraints );
3581 for ( ; constraintStrengthIt != mFieldConstraintStrength.constEnd(); ++constraintStrengthIt )
3583 int index = mFields.
lookupField( constraintStrengthIt.key().first );
3593 constraints.
setConstraintStrength( constraintStrengthIt.key().second, constraintStrengthIt.value() );
3594 mFields[ index ].setConstraints( constraints );
3597 auto fieldWidgetIterator = mFieldWidgetSetups.constBegin();
3598 for ( ; fieldWidgetIterator != mFieldWidgetSetups.constEnd(); ++ fieldWidgetIterator )
3600 int index = mFields.
indexOf( fieldWidgetIterator.key() );
3604 mFields[index].setEditorWidgetSetup( fieldWidgetIterator.value() );
3607 if ( oldFields != mFields )
3610 mEditFormConfig.setFields( mFields );
3617 if ( index < 0 || index >= mFields.
count() )
3621 if ( expression.isEmpty() )
3625 std::unique_ptr< QgsExpressionContext > tempContext;
3630 evalContext = tempContext.get();
3663 if ( index < 0 || index >= mFields.
count() )
3668 mDefaultExpressionMap.insert( mFields.
at( index ).
name(), definition );
3672 mDefaultExpressionMap.remove( mFields.
at( index ).
name() );
3679 if ( index < 0 || index >= mFields.
count() )
3688 if ( !mDataProvider )
3701 uniqueValues = mDataProvider->
uniqueValues( index, limit );
3707 for (
const QVariant &v : constUniqueValues )
3709 vals << v.toString();
3713 QMapIterator< QgsFeatureId, QgsFeature > addedIt( added );
3714 while ( addedIt.hasNext() && ( limit < 0 || uniqueValues.count() < limit ) )
3717 QVariant v = addedIt.value().attribute( index );
3720 QString vs = v.toString();
3721 if ( !vals.contains( vs ) )
3730 while ( it.hasNext() && ( limit < 0 || uniqueValues.count() < limit ) )
3733 QVariant v = it.value().value( index );
3736 QString vs = v.toString();
3737 if ( !vals.contains( vs ) )
3756 uniqueValues = mDataProvider->
uniqueValues( index, limit );
3769 .setSubsetOfAttributes( attList ) );
3772 QVariant currentValue;
3773 QHash<QString, QVariant> val;
3777 val.insert( currentValue.toString(), currentValue );
3778 if ( limit >= 0 && val.size() >= limit )
3784 return val.values().toSet();
3788 Q_ASSERT_X(
false,
"QgsVectorLayer::uniqueValues()",
"Unknown source of the field!" );
3794 QStringList results;
3795 if ( !mDataProvider )
3813 QMapIterator< QgsFeatureId, QgsFeature > addedIt( added );
3814 while ( addedIt.hasNext() && ( limit < 0 || results.count() < limit ) && ( !feedback || !feedback->
isCanceled() ) )
3817 QVariant v = addedIt.value().attribute( index );
3820 QString vs = v.toString();
3821 if ( vs.contains( substring, Qt::CaseInsensitive ) && !results.contains( vs ) )
3829 while ( it.hasNext() && ( limit < 0 || results.count() < limit ) && ( !feedback || !feedback->
isCanceled() ) )
3832 QVariant v = it.value().value( index );
3835 QString vs = v.toString();
3836 if ( vs.contains( substring, Qt::CaseInsensitive ) && !results.contains( vs ) )
3867 QString fieldName = mFields.
at( index ).
name();
3868 request.
setFilterExpression( QStringLiteral(
"\"%1\" ILIKE '%%2%'" ).arg( fieldName, substring ) );
3872 QString currentValue;
3875 currentValue = f.
attribute( index ).toString();
3876 if ( !results.contains( currentValue ) )
3877 results << currentValue;
3879 if ( ( limit >= 0 && results.size() >= limit ) || ( feedback && feedback->
isCanceled() ) )
3889 Q_ASSERT_X(
false,
"QgsVectorLayer::uniqueStringsMatching()",
"Unknown source of the field!" );
3895 return minimumOrMaximumValue( index,
true );
3900 return minimumOrMaximumValue( index,
false );
3903 QVariant QgsVectorLayer::minimumOrMaximumValue(
int index,
bool minimum )
const 3905 if ( !mDataProvider )
3923 QMapIterator< QgsFeatureId, QgsFeature > addedIt( added );
3924 while ( addedIt.hasNext() )
3927 QVariant v = addedIt.value().attribute( index );
3936 while ( it.hasNext() )
3939 QVariant v = it.value().value( index );
3972 .setSubsetOfAttributes( attList ) );
3975 double value = minimum ? std::numeric_limits<double>::max() : -std::numeric_limits<double>::max();
3976 double currentValue = 0;
3979 currentValue = f.
attribute( index ).toDouble();
3980 if ( ( minimum && currentValue < value ) || ( !minimum && currentValue > value ) )
3982 value = currentValue;
3985 return QVariant( value );
3989 Q_ASSERT_X(
false,
"QgsVectorLayer::minOrMax()",
"Unknown source of the field!" );
4000 if ( !mDataProvider )
4006 int attrIndex = mFields.
lookupField( fieldOrExpression );
4007 if ( attrIndex >= 0 )
4014 bool providerOk =
false;
4015 QVariant val = mDataProvider->
aggregate( aggregate, attrIndex, parameters, context, providerOk, fids );
4031 return c.
calculate( aggregate, fieldOrExpression, context, ok );
4036 if ( mFeatureBlendMode == featureBlendMode )
4046 return mFeatureBlendMode;
4060 return mLayerOpacity;
4065 void QgsVectorLayer::readSldLabeling(
const QDomNode &node )
4070 QDomElement element = node.toElement();
4071 if ( element.isNull() )
4074 QDomElement userStyleElem = element.firstChildElement( QStringLiteral(
"UserStyle" ) );
4075 if ( userStyleElem.isNull() )
4077 QgsDebugMsgLevel( QStringLiteral(
"Info: UserStyle element not found." ), 4 );
4081 QDomElement featureTypeStyleElem = userStyleElem.firstChildElement( QStringLiteral(
"FeatureTypeStyle" ) );
4082 if ( featureTypeStyleElem.isNull() )
4084 QgsDebugMsgLevel( QStringLiteral(
"Info: FeatureTypeStyle element not found." ), 4 );
4089 QDomElement ruleElem = featureTypeStyleElem.lastChildElement( QStringLiteral(
"Rule" ) );
4090 if ( ruleElem.isNull() )
4097 QDomElement textSymbolizerElem = ruleElem.lastChildElement( QStringLiteral(
"TextSymbolizer" ) );
4098 if ( textSymbolizerElem.isNull() )
4100 QgsDebugMsgLevel( QStringLiteral(
"Info: TextSymbolizer element not found." ), 4 );
4107 QDomElement labelElem = textSymbolizerElem.firstChildElement( QStringLiteral(
"Label" ) );
4108 if ( !labelElem.isNull() )
4110 QDomElement propertyNameElem = labelElem.firstChildElement( QStringLiteral(
"PropertyName" ) );
4111 if ( !propertyNameElem.isNull() )
4116 QString labelAttribute = propertyNameElem.text();
4120 int fieldIndex = mFields.
lookupField( labelAttribute );
4121 if ( fieldIndex == -1 )
4137 QgsDebugMsgLevel( QStringLiteral(
"Info: PropertyName element not found." ), 4 );
4147 QString fontFamily = QStringLiteral(
"Sans-Serif" );
4148 int fontPointSize = 10;
4149 int fontWeight = -1;
4150 bool fontItalic =
false;
4151 bool fontUnderline =
false;
4154 QDomElement fontElem = textSymbolizerElem.firstChildElement( QStringLiteral(
"Font" ) );
4155 if ( !fontElem.isNull() )
4159 QDomElement cssElem = fontElem.firstChildElement( QStringLiteral(
"CssParameter" ) );
4160 while ( !cssElem.isNull() )
4162 cssName = cssElem.attribute( QStringLiteral(
"name" ), QStringLiteral(
"not_found" ) );
4163 if ( cssName != QLatin1String(
"not_found" ) )
4165 elemText = cssElem.text();
4166 if ( cssName == QLatin1String(
"font-family" ) )
4168 fontFamily = elemText;
4170 else if ( cssName == QLatin1String(
"font-style" ) )
4172 fontItalic = ( elemText == QLatin1String(
"italic" ) ) || ( elemText == QLatin1String(
"Italic" ) );
4174 else if ( cssName == QLatin1String(
"font-size" ) )
4177 int fontSize = elemText.toInt( &ok );
4180 fontPointSize = fontSize;
4183 else if ( cssName == QLatin1String(
"font-weight" ) )
4185 if ( ( elemText == QLatin1String(
"bold" ) ) || ( elemText == QLatin1String(
"Bold" ) ) )
4186 fontWeight = QFont::Bold;
4188 else if ( cssName == QLatin1String(
"font-underline" ) )
4190 fontUnderline = ( elemText == QLatin1String(
"underline" ) ) || ( elemText == QLatin1String(
"Underline" ) );
4194 cssElem = cssElem.nextSiblingElement( QStringLiteral(
"CssParameter" ) );
4199 QFont font( fontFamily, fontPointSize, fontWeight, fontItalic );
4200 font.setUnderline( fontUnderline );
4202 format.
setSize( fontPointSize );
4206 if ( textColor.isValid() )
4214 QDomElement haloElem = textSymbolizerElem.firstChildElement( QStringLiteral(
"Halo" ) );
4215 if ( !haloElem.isNull() )
4220 QDomElement radiusElem = haloElem.firstChildElement( QStringLiteral(
"Radius" ) );
4221 if ( !radiusElem.isNull() )
4224 double bufferSize = radiusElem.text().toDouble( &ok );
4227 bufferSettings.
setSize( bufferSize );
4232 if ( bufferColor.isValid() )
4234 bufferSettings.
setColor( bufferColor );
4239 QDomElement labelPlacementElem = textSymbolizerElem.firstChildElement( QStringLiteral(
"LabelPlacement" ) );
4240 if ( !labelPlacementElem.isNull() )
4243 QDomElement pointPlacementElem = labelPlacementElem.firstChildElement( QStringLiteral(
"PointPlacement" ) );
4244 if ( !pointPlacementElem.isNull() )
4248 QDomElement displacementElem = pointPlacementElem.firstChildElement( QStringLiteral(
"Displacement" ) );
4249 if ( !displacementElem.isNull() )
4251 QDomElement displacementXElem = displacementElem.firstChildElement( QStringLiteral(
"DisplacementX" ) );
4252 if ( !displacementXElem.isNull() )
4255 double xOffset = displacementXElem.text().toDouble( &ok );
4261 QDomElement displacementYElem = displacementElem.firstChildElement( QStringLiteral(
"DisplacementY" ) );
4262 if ( !displacementYElem.isNull() )
4265 double yOffset = displacementYElem.text().toDouble( &ok );
4273 QDomElement rotationElem = pointPlacementElem.firstChildElement( QStringLiteral(
"Rotation" ) );
4274 if ( !rotationElem.isNull() )
4277 double rotation = rotationElem.text().toDouble( &ok );
4294 return mEditFormConfig;
4299 if ( mEditFormConfig == editFormConfig )
4303 mEditFormConfig.onRelationsLoaded();
4309 return mMapTipTemplate;
4314 if ( mMapTipTemplate == mapTip )
4317 mMapTipTemplate = mapTip;
4333 if ( mAttributeTableConfig != attributeTableConfig )
4352 if ( !mDiagramLayerSettings )
4354 *mDiagramLayerSettings = s;
4360 QString myMetadata = QStringLiteral(
"<html>\n<body>\n" );
4363 myMetadata += QStringLiteral(
"<h1>" ) + tr(
"Information from provider" ) + QStringLiteral(
"</h1>\n<hr>\n" );
4364 myMetadata += QLatin1String(
"<table class=\"list-view\">\n" );
4367 myMetadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"Name" ) + QStringLiteral(
"</td><td>" ) +
name() + QStringLiteral(
"</td></tr>\n" );
4372 if ( uriComponents.contains( QStringLiteral(
"path" ) ) )
4374 path = uriComponents[QStringLiteral(
"path" )].toString();
4375 if ( QFile::exists( path ) )
4376 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" );
4378 if ( uriComponents.contains( QStringLiteral(
"url" ) ) )
4380 const QString url = uriComponents[QStringLiteral(
"url" )].toString();
4381 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" );
4386 myMetadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"Source" ) + QStringLiteral(
"</td><td>%1" ).arg(
publicSource() ) + QStringLiteral(
"</td></tr>\n" );
4389 myMetadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"Storage" ) + QStringLiteral(
"</td><td>" ) +
storageType() + QStringLiteral(
"</td></tr>\n" );
4392 myMetadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"Comment" ) + QStringLiteral(
"</td><td>" ) +
dataComment() + QStringLiteral(
"</td></tr>\n" );
4395 myMetadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"Encoding" ) + QStringLiteral(
"</td><td>" ) +
dataProvider()->
encoding() + QStringLiteral(
"</td></tr>\n" );
4409 myMetadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"Geometry" ) + QStringLiteral(
"</td><td>" ) + typeString + QStringLiteral(
"</td></tr>\n" );
4413 myMetadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"CRS" ) + QStringLiteral(
"</td><td>" );
4416 myMetadata +=
crs().
authid() + QStringLiteral(
" - " );
4418 if (
crs().isGeographic() )
4419 myMetadata += tr(
"Geographic" );
4421 myMetadata += tr(
"Projected" );
4423 myMetadata += QLatin1String(
"</td></tr>\n" );
4426 myMetadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"Extent" ) + QStringLiteral(
"</td><td>" ) +
extent().
toString() + QStringLiteral(
"</td></tr>\n" );
4429 myMetadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"Unit" ) + QStringLiteral(
"</td><td>" ) +
QgsUnitTypes::toString(
crs().mapUnits() ) + QStringLiteral(
"</td></tr>\n" );
4434 QLocale locale = QLocale();
4435 locale.setNumberOptions( locale.numberOptions() &= ~QLocale::NumberOption::OmitGroupSeparator );
4436 myMetadata += QStringLiteral(
"<tr><td class=\"highlight\">" )
4437 + tr(
"Feature count" ) + QStringLiteral(
"</td><td>" )
4439 + QStringLiteral(
"</td></tr>\n" );
4442 myMetadata += QLatin1String(
"</table>\n<br><br>" );
4445 myMetadata += QStringLiteral(
"<h1>" ) + tr(
"Identification" ) + QStringLiteral(
"</h1>\n<hr>\n" );
4447 myMetadata += QLatin1String(
"<br><br>\n" );
4450 myMetadata += QStringLiteral(
"<h1>" ) + tr(
"Extent" ) + QStringLiteral(
"</h1>\n<hr>\n" );
4452 myMetadata += QLatin1String(
"<br><br>\n" );
4455 myMetadata += QStringLiteral(
"<h1>" ) + tr(
"Access" ) + QStringLiteral(
"</h1>\n<hr>\n" );
4457 myMetadata += QLatin1String(
"<br><br>\n" );
4460 myMetadata += QStringLiteral(
"<h1>" ) + tr(
"Fields" ) + QStringLiteral(
"</h1>\n<hr>\n<table class=\"list-view\">\n" );
4464 if ( !pkAttrList.isEmpty() )
4466 myMetadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"Primary key attributes" ) + QStringLiteral(
"</td><td>" );
4467 const auto constPkAttrList = pkAttrList;
4468 for (
int idx : constPkAttrList )
4472 myMetadata += QLatin1String(
"</td></tr>\n" );
4478 myMetadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"Count" ) + QStringLiteral(
"</td><td>" ) + QString::number( myFields.
size() ) + QStringLiteral(
"</td></tr>\n" );
4480 myMetadata += QLatin1String(
"</table>\n<br><table width=\"100%\" class=\"tabular-view\">\n" );
4481 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" );
4483 for (
int i = 0; i < myFields.
size(); ++i )
4488 rowClass = QStringLiteral(
"class=\"odd-row\"" );
4489 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" );
4493 myMetadata += QLatin1String(
"</table>\n<br><br>" );
4496 myMetadata += QStringLiteral(
"<h1>" ) + tr(
"Contacts" ) + QStringLiteral(
"</h1>\n<hr>\n" );
4498 myMetadata += QLatin1String(
"<br><br>\n" );
4501 myMetadata += QStringLiteral(
"<h1>" ) + tr(
"Links" ) + QStringLiteral(
"</h1>\n<hr>\n" );
4503 myMetadata += QLatin1String(
"<br><br>\n" );
4506 myMetadata += QStringLiteral(
"<h1>" ) + tr(
"History" ) + QStringLiteral(
"</h1>\n<hr>\n" );
4508 myMetadata += QLatin1String(
"<br><br>\n" );
4510 myMetadata += QStringLiteral(
"\n</body>\n</html>\n" );
4514 void QgsVectorLayer::invalidateSymbolCountedFlag()
4516 mSymbolFeatureCounted =
false;
4519 void QgsVectorLayer::onFeatureCounterCompleted()
4522 mFeatureCounter =
nullptr;
4525 void QgsVectorLayer::onFeatureCounterTerminated()
4527 mFeatureCounter =
nullptr;
4530 void QgsVectorLayer::onJoinedFieldsChanged()
4536 void QgsVectorLayer::onFeatureDeleted(
QgsFeatureId fid )
4538 if ( mEditCommandActive )
4539 mDeletedFids << fid;
4546 void QgsVectorLayer::onRelationsLoaded()
4548 mEditFormConfig.onRelationsLoaded();
4551 void QgsVectorLayer::onSymbolsCounted()
4553 if ( mFeatureCounter )
4555 mSymbolFeatureCounted =
true;
4584 bool useAsDefault,
const QString &uiFileContent, QString &msgError )
4587 QString sldStyle, qmlStyle;
4588 QDomDocument qmlDocument, sldDocument;
4591 if ( !msgError.isNull() )
4595 qmlStyle = qmlDocument.toString();
4598 if ( !msgError.isNull() )
4602 sldStyle = sldDocument.toString();
4606 description, uiFileContent, useAsDefault, msgError );
4620 QString joinKey = mAuxiliaryLayerKey;
4621 if ( !key.isEmpty() )
4624 if ( storage.
isValid() && !joinKey.isEmpty() )
4647 mAuxiliaryLayerKey.clear();
4649 if ( mAuxiliaryLayer )
4662 mAuxiliaryLayer.reset( alayer );
4663 if ( mAuxiliaryLayer )
4664 mAuxiliaryLayer->setParent(
this );
4670 return mAuxiliaryLayer.get();
4675 return mAuxiliaryLayer.get();
4683 QString qml, errorMsg;
4685 if ( !qml.isEmpty() )
4687 QDomDocument myDocument( QStringLiteral(
"qgis" ) );
4688 myDocument.setContent( qml );
4690 return QObject::tr(
"Loaded from Provider" );
4698 if ( mDataProvider )
4703 void QgsVectorLayer::emitDataChanged()
4705 if ( mDataChangedFired )
4708 mDataChangedFired =
true;
4710 mDataChangedFired =
false;
4715 QSet<QgsMapLayerDependency> deps;
4716 const auto constODeps = oDeps;
4723 QSet<QgsMapLayerDependency> toAdd = deps -
dependencies();
4739 if ( mDataProvider )
4759 if ( ! toAdd.isEmpty() )
4767 if ( fieldIndex < 0 || fieldIndex >= mFields.
count() )
4783 QMap< QgsFieldConstraints::Constraint, QgsFieldConstraints::ConstraintStrength > m;
4785 if ( fieldIndex < 0 || fieldIndex >= mFields.
count() )
4788 QString
name = mFields.
at( fieldIndex ).
name();
4791 for ( ; conIt != mFieldConstraintStrength.constEnd(); ++conIt )
4793 if ( conIt.key().first ==
name )
4795 m[ conIt.key().second ] = mFieldConstraintStrength.value( conIt.key() );
4804 if ( index < 0 || index >= mFields.
count() )
4810 QgsFieldConstraints::Constraints constraints = mFieldConstraints.value( name,
nullptr );
4811 constraints |= constraint;
4812 mFieldConstraints.insert( name, constraints );
4814 mFieldConstraintStrength.insert( qMakePair( name, constraint ), strength );
4821 if ( index < 0 || index >= mFields.
count() )
4827 QgsFieldConstraints::Constraints constraints = mFieldConstraints.value( name,
nullptr );
4828 constraints &= ~constraint;
4829 mFieldConstraints.insert( name, constraints );
4831 mFieldConstraintStrength.remove( qMakePair( name, constraint ) );
4838 if ( index < 0 || index >= mFields.
count() )
4846 if ( index < 0 || index >= mFields.
count() )
4854 if ( index < 0 || index >= mFields.
count() )
4857 if ( expression.isEmpty() )
4859 mFieldConstraintExpressions.remove( mFields.
at( index ).
name() );
4863 mFieldConstraintExpressions.insert( mFields.
at( index ).
name(), qMakePair( expression, description ) );
4870 if ( index < 0 || index >= mFields.
count() )
4874 mFieldWidgetSetups.remove( mFields.
at( index ).
name() );
4876 mFieldWidgetSetups.insert( mFields.
at( index ).
name(), setup );
4883 if ( index < 0 || index >= mFields.
count() )
4892 if (
customProperty( QStringLiteral(
"labeling" ) ).toString() == QLatin1String(
"pal" ) )
4894 if (
customProperty( QStringLiteral(
"labeling/enabled" ), QVariant(
false ) ).toBool() )
4898 settings.readFromLayerCustomProperties(
this );
4905 for (
const QString &key : constCustomPropertyKeys )
4907 if ( key.startsWith( QLatin1String(
"labeling/" ) ) )
4917 return mAllowCommit;
4922 if ( mAllowCommit == allowCommit )
4931 return mGeometryOptions.get();
4941 return mReadExtentFromXml;
4944 void QgsVectorLayer::onDirtyTransaction(
const QString &sql,
const QString &
name )
4947 if ( tr && mEditBuffer )
void setProperty(int key, const QgsProperty &property)
Adds a property to the collection and takes ownership of it.
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.
int lookupField(const QString &fieldName) const
Looks up field's index from the field name.
bool writeXml(QDomNode &layer_node, QDomDocument &doc, const QgsReadWriteContext &context) const FINAL
Writes vector layer specific state to project file Dom node.
bool addFeatures(QgsFeatureList &features, QgsFeatureSink::Flags flags=nullptr) override
Adds a list of features in joined layers.
QList< QgsExpressionFieldBuffer::ExpressionField > expressions() const
bool labelsEnabled() const
Returns whether the layer contains labels which are enabled and should be drawn.
QgsFeatureIds symbolFeatureIds(const QString &legendKey) const
Ids of features rendered with specified legend key.
QgsGeometryOptions * geometryOptions() const
Configuration and logic to apply automatically on any edit happening on this layer.
bool isValid() const
Returns the validity of this feature.
void writeXml(QDomNode &layer_node, QDomDocument &document) const
Saves mVectorJoins to xml under the layer node.
Class for parsing and evaluation of expressions (formerly called "search strings").
void updateFields()
Will regenerate the fields property of this layer by obtaining all fields from the dataProvider...
void opacityChanged(double opacity)
Emitted when the layer's opacity is changed, where opacity is a value between 0 (transparent) and 1 (...
Q_DECL_DEPRECATED QgsGeometry::OperationResult addPart(const QList< QgsPointXY > &ring)
Adds a new part polygon to a multipart feature.
QgsRectangle sourceExtent() const FINAL
Returns the extent of all geometries from the source.
QgsActionManager * actions()
Returns all layer actions defined on this layer.
double xOffset
Horizontal offset of label.
QString encoding() const
Gets encoding which is used for accessing data.
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.
The class is used as a container of context for various read/write operations on other objects...
Wrapper for iterator of features from vector data provider or vector layer.
void featuresDeleted(const QgsFeatureIds &fids)
Emitted when features have been deleted.
void selectAll()
Select all the features.
void setConstraintStrength(Constraint constraint, ConstraintStrength strength)
Sets the strength of a constraint.
Constraint was set by layer.
bool addJoin(const QgsVectorLayerJoinInfo &joinInfo)
Joins another vector layer to this layer.
void taskTerminated()
Will be emitted by task if it has terminated for any reason other then completion (e...
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.
virtual bool setSubsetString(const QString &subset, bool updateFeatureCount=true)
Set the subset string used to create a subset of features in the layer.
A rectangle specified with double values.
QString targetFieldName() const
Returns name of the field of our layer that will be used for join.
bool readSld(const QDomNode &node, QString &errorMessage) FINAL
Base class for all map layer types.
Q_DECL_DEPRECATED QgsGeometry::OperationResult splitParts(const QVector< QgsPointXY > &splitLine, bool topologicalEditing=false)
Splits parts cut by the given line.
double rendererScale() const
Returns the renderer map scale.
void geometryChanged(QgsFeatureId fid, const QgsGeometry &geom)
Emitted when a feature's geometry is changed.
void renameExpression(int index, const QString &name)
Renames an expression field at a given index.
virtual void writeXml(QDomElement &layerElem, QDomDocument &doc, const QgsReadWriteContext &context) const =0
Writes diagram state to a DOM element.
void setDiagramLayerSettings(const QgsDiagramLayerSettings &s)
bool loadDefaultStyle
Set to true if the default layer style should be loaded.
QVariant maximumValue(int index) const override
Returns the maximum value of an attribute.
QgsVectorLayerFeatureCounter * countSymbolFeatures()
Count features for symbols.
bool containsJoins() const
Quick way to test if there is any join at all.
void update(const QgsFields &fields)
Update the configuration with the given fields.
virtual QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context) const
Writes configuration to a DOM element, to be used later with readXml()
void setRenderer(QgsFeatureRenderer *r)
Sets renderer which will be invoked to represent this layer.
Field comes from a joined layer (originIndex / 1000 = index of the join, originIndex % 1000 = index w...
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.
QSet< QgsFeatureId > QgsFeatureIds
void setExcludeAttributesWms(const QSet< QString > &att)
A set of attributes that are not advertised in WMS requests with QGIS server.
virtual bool renameAttribute(int attr, const QString &newName)
Renames an attribute field (but does not commit it)
virtual bool addAttribute(const QgsField &field)
Add an attribute field (but does not commit it) returns true if the field was added.
int size() const
Returns number of items.
virtual void exportSldStyle(QDomDocument &doc, QString &errorMsg) const
Export the properties of this layer as SLD style in a QDomDocument.
FieldOrigin fieldOrigin(int fieldIdx) const
Gets field's origin (value from an enumeration)
void setMinimal()
Set a rectangle so that min corner is at max and max corner is at min.
virtual QString subsetString() const
Returns the subset definition string (typically sql) currently in use by the layer and used by the pr...
void setProviderType(const QString &providerType)
Sets the providerType (provider key)
void taskCompleted()
Will be emitted by task to indicate its successful completion.
virtual QgsMapLayer * clone() const =0
Returns a new instance equivalent to this one except for the id which is still unique.
virtual QgsVectorDataProvider::Capabilities capabilities() const
Returns flags containing the supported capabilities.
void dependenciesChanged()
Emitted when dependencies are changed.
QgsWkbTypes::Type wkbType() const override=0
Returns the geometry type which is returned by this layer.
static QString quotedColumnRef(QString name)
Returns a quoted column reference (in double quotes)
void committedAttributesDeleted(const QString &layerId, const QgsAttributeList &deletedAttributes)
Signals emitted after committing changes.
bool isValid() const
Returns the status of the auxiliary storage currently defined.
virtual QString subsetString() const
Returns the string (typically sql) used to define a subset of the layer.
QgsMapLayerType type() const
Returns the type of the layer.
static Q_INVOKABLE QString toString(QgsUnitTypes::DistanceUnit unit)
Returns a translated string representing a distance unit.
void editFormConfigChanged()
Will be emitted whenever the edit form configuration of this layer changes.
void modifySelection(const QgsFeatureIds &selectIds, const QgsFeatureIds &deselectIds)
Modifies the current selection on this layer.
bool writeXml(QDomNode &layer_node) const
Writes the actions out in XML format.
virtual void updateExtents()
Update the extents of the layer.
The QgsGeometryOptions class contains options to automatically adjust geometries to constraints on a ...
void addExpression(const QString &exp, const QgsField &fld)
Add an expression to the buffer.
QVariant minimumValue(int index) const override
Returns the minimum value of an attribute.
void setFidsFilter(const QgsFeatureIds &fids)
Sets a filter to limit the features used during the aggregate calculation.
void removeFieldConstraint(int index, QgsFieldConstraints::Constraint constraint)
Removes a constraint for a specified field index.
bool isValid() const
Returns if this default value should be applied.
virtual bool importNamedStyle(QDomDocument &doc, QString &errorMsg, QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories)
Import the properties of this layer from a QDomDocument.
bool writeXml(QDomNode &node, QDomDocument &doc, const QgsReadWriteContext &context) const
Writes the condition styles state to a DOM node.
void beforeRollBack()
Emitted before changes are rolled back.
virtual bool addFeatures(QgsFeatureList &features)
Insert a copy of the given features into the layer (but does not commit it)
bool hasParam(const QString &key) const
Returns true if a parameter with the specified key exists.
void beginEditCommand(const QString &text)
Create edit command for undo/redo operations.
Use exact geometry intersection (slower) instead of bounding boxes.
QSet< QString > excludeAttributesWms() const
A set of attributes that are not advertised in WMS requests with QGIS server.
This class is a composition of two QSettings instances:
Q_DECL_DEPRECATED QgsGeometry::OperationResult splitParts(const QVector< QgsPointXY > &splitLine, bool topologicalEditing=false)
Splits parts cut by the given line.
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...
QStringList customPropertyKeys() const
Returns list of all keys within custom properties.
MAYBE_UNUSED NODISCARD QgsReadWriteContextCategoryPopper enterCategory(const QString &category, const QString &details=QString())
Push a category to the stack.
double angleOffset
Label rotation, in degrees clockwise.
QString mapTipTemplate() const
The mapTip is a pretty, html representation for feature information.
QString readPath(const QString &filename) const
Turn filename read from the project file to an absolute path.
int translateFeature(QgsFeatureId featureId, double dx, double dy)
Translates feature by dx, dy.
QgsMapLayerLegend * legend() const
Can be nullptr.
QString storageType() const
Returns the permanent storage type for this layer as a friendly name.
Renders the diagrams for all features with the same settings.
FeatureAvailability
Possible return value for hasFeatures() to determine if a source is empty.
void setExtent(const QgsRectangle &rect) FINAL
Sets the extent.
The QgsDefaultValue class provides a container for managing client side default values for fields...
Q_DECL_DEPRECATED QgsGeometry::OperationResult addRing(const QVector< QgsPointXY > &ring, QgsFeatureId *featureId=nullptr)
Adds a ring to polygon/multipolygon features.
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
Constraint
Constraints which may be present on a field.
QSet< QString > excludeAttributesWfs() const
A set of attributes that are not advertised in WFS requests with QGIS server.
virtual bool addFeature(QgsFeature &f)
Adds a feature.
Field has been temporarily added in editing mode (originIndex = index in the list of added attributes...
QgsWkbTypes::Type wkbType() const FINAL
Returns the WKBType or WKBUnknown in case of error.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
Setting options for loading vector layers.
SimplifyAlgorithm simplifyAlgorithm() const
Gets the local simplification algorithm of the vector layer managed.
bool deleteFeature(QgsFeatureId fid)
Deletes a feature from the layer (but does not commit it).
void committedAttributesAdded(const QString &layerId, const QList< QgsField > &addedAttributes)
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
QSet< QgsMapLayerDependency > dependencies() const FINAL
Gets the list of dependencies.
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.e.
void mapTipTemplateChanged()
Emitted when the map tip changes.
Class allowing to manage the auxiliary storage for a vector layer.
QString qgsEnumValueToKey(const T &value)
Returns the value for the given key of an enum.
bool mShouldValidateCrs
true if the layer's CRS should be validated and invalid CRSes are not permitted.
QgsFieldConstraints::Constraints fieldConstraints(int fieldIndex) const
Returns any constraints which are present at the provider for a specified field index.
Arranges candidates over a point (or centroid of a polygon), or at a preset offset from the point...
void attributeDeleted(int idx)
QList< QgsFeature > QgsFeatureList
virtual void readXml(const QDomElement &elem, const QgsReadWriteContext &context)=0
Reads diagram state from a DOM element.
QString mProviderKey
Data provider key (name of the data provider)
bool deleteStyleById_t(const QString &uri, QString styleID, QString &errCause)
static void warning(const QString &msg)
Goes to qWarning.
Counts the features in a QgsVectorLayer in task.
void willBeDeleted()
Emitted in the destructor when the layer is about to be deleted, but it is still in a perfectly valid...
void setSize(double size)
Sets the size of the buffer.
A class to represent a 2D point.
friend class QgsVectorLayerFeatureSource
void setForceLocalOptimization(bool localOptimization)
Sets where the simplification executes, after fetch the geometries from provider, or when supported...
void readOnlyChanged()
Emitted when the read only state of this layer is changed.
bool renameAttribute(int index, const QString &newName)
Renames an attribute field (but does not commit it).
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
void invertSelectionInRectangle(QgsRectangle &rect)
Inverts selection of features found within the search rectangle (in layer's coordinates) ...
void subsetStringChanged()
Emitted when the layer's subset string has changed.
QgsFeature getFeature(QgsFeatureId fid) const
Queries the layer for the feature with the given id.
bool commitChanges()
Attempts to commit to the underlying data provider any buffered changes made since the last to call t...
virtual QSet< QgsMapLayerDependency > dependencies() const
Gets the list of layer ids on which this layer depends.
int selectedFeatureCount() const
Returns the number of features that are selected in this layer.
QString providerType() const
Returns the provider type (provider key) for this layer.
virtual QDomElement save(QDomDocument &doc, const QgsReadWriteContext &context)
store renderer info to XML element
EditResult deleteVertex(QgsFeatureId featureId, int vertex)
Deletes a vertex from a feature.
virtual void setEncoding(const QString &e)
Set encoding used for accessing data from layer.
bool startEditing()
Makes the layer editable.
void setSimplifyHints(SimplifyHints simplifyHints)
Sets the simplification hints of the vector layer managed.
void setFont(const QFont &font)
Sets the font used for rendering text.
QgsVectorLayer(const QString &path=QString(), const QString &baseName=QString(), const QString &providerLib="ogr", const QgsVectorLayer::LayerOptions &options=QgsVectorLayer::LayerOptions())
Constructor - creates a vector layer.
bool deleteAttributes(const QList< int > &attrs)
Deletes a list of attribute fields (but does not commit it)
VertexMarkerType
Editing vertex markers.
void removeExpressionField(int index)
Removes an expression field.
void setFeatureBlendMode(QPainter::CompositionMode blendMode)
Sets the blending mode used for rendering each feature.
QVariant evaluate()
Evaluate the feature and return the result.
void readCustomProperties(const QDomNode &layerNode, const QString &keyStartsWith=QString())
Read custom properties from project file.
static QgsPainting::BlendMode getBlendModeEnum(QPainter::CompositionMode blendMode)
Returns a BlendMode corresponding to a QPainter::CompositionMode.
static QgsProperty fromField(const QString &fieldName, bool isActive=true)
Returns a new FieldBasedProperty created from the specified field name.
virtual QgsAttributeList pkAttributeIndexes() const
Returns list of indexes of fields that make up the primary key.
Remove from current selection.
void writeXml(QDomElement &layerElem, QDomDocument &doc) const
Writes the diagram settings to a DOM element.
virtual void resolveReferences(QgsProject *project)
Resolve references to other layers (kept as layer IDs after reading XML) into layer objects...
QgsFeatureRequest & setSubsetOfAttributes(const QgsAttributeList &attrs)
Set a subset of attributes that will be fetched.
~QgsVectorLayer() override
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.
Class providing some utility methods to manage auxiliary storage.
SimplifyHint
Simplification flags for fast rendering of features.
Utility class for calculating aggregates for a field (or expression) over the features from a vector ...
double yOffset
Vertical offset of label.
void setLabeling(QgsAbstractVectorLayerLabeling *labeling)
Sets labeling configuration.
Provider can create feature renderers using backend-specific formatting information. Since QGIS 3.2. See QgsVectorDataProvider::createRenderer().
void readCustomSymbology(const QDomElement &element, QString &errorMessage)
Signal emitted whenever the symbology (QML-file) for this layer is being read.
QString evalErrorString() const
Returns evaluation error.
Aliases, widgets, WMS/WFS, expressions, constraints, virtual fields.
QgsWkbTypes::GeometryType geometryType() const
Returns point, line or polygon.
bool deleteFeatures(const QgsFeatureIds &fids)
Deletes a set of features from the layer (but does not commit it)
virtual const QgsLayerMetadata & metadata() const
Returns a reference to the layer's metadata store.
void readXml(const QDomNode &layer_node)
Reads joins from project file.
void raiseError(const QString &msg) const
Signals an error in this provider.
void configChanged()
Emitted whenever the configuration is changed.
void setDiagramRenderer(QgsDiagramRenderer *r)
Sets diagram rendering object (takes ownership)
Container of fields for a vector layer.
virtual void rollBack()
Stop editing and discard the edits.
A geometry is the spatial representation of a feature.
void selectByIds(const QgsFeatureIds &ids, SelectBehavior behavior=SetSelection)
Selects matching features using a list of feature IDs.
bool setAttribute(int field, const QVariant &attr)
Set an attribute's value by field index.
virtual QgsFeatureRenderer * createRenderer(const QVariantMap &configuration=QVariantMap()) const
Creates a new vector layer feature renderer, using provider backend specific information.
#define RENDERER_TAG_NAME
void beforeRemovingExpressionField(int idx)
Will be emitted, when an expression field is going to be deleted from this vector layer...
long featureCount() const FINAL
Returns feature count including changes which have not yet been committed If you need only the count ...
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...
static QPainter::CompositionMode getCompositionMode(QgsPainting::BlendMode blendMode)
Returns a QPainter::CompositionMode corresponding to a BlendMode.
QgsChangedAttributesMap mChangedAttributeValues
Changed attributes values which are not committed.
bool needsGeometry() const
Returns true if the expression uses feature geometry for some computation.
Allows entering a context category and takes care of leaving this category on deletion of the class...
QgsEditorWidgetSetup editorWidgetSetup() const
Gets the editor widget setup for the field.
QList< QgsAction > actions(const QString &actionScope=QString()) const
Returns a list of actions that are available in the given action scope.
QVariantMap decodeUri(const QString &providerKey, const QString &uri)
Breaks a provider data source URI into its component paths (e.g.
QMap< QgsFieldConstraints::Constraint, QgsFieldConstraints::ConstraintStrength > fieldConstraintsAndStrength(int fieldIndex) const
Returns a map of constraint with their strength for a specific field of the layer.
void setFields(const QgsFields &fields)
Convenience function for setting a fields for the scope.
bool skipCrsValidation
Controls whether the layer is allowed to have an invalid/unknown CRS.
QString getStyleById(const QString &providerKey, const QString &uri, QString styleId, QString &errCause)
Gets a layer style defined by styleId.
void setDisplayExpression(const QString &displayExpression)
Set the preview expression, used to create a human readable preview string.
Stores information about constraints which may be present on a field.
Field comes from the underlying data provider of the vector layer (originIndex = index in provider's ...
int addTopologicalPoints(const QgsGeometry &geom)
Adds topological points for every vertex of the geometry.
bool isAuxiliaryField(int index, int &srcIndex) const
Returns true if the field comes from the auxiliary layer, false otherwise.
QSet< QString > referencedColumns() const
Gets list of columns referenced by the expression.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
static const int EditingCapabilities
Bitmask of all provider's editing capabilities.
void resolveReferences(QgsProject *project) FINAL
Resolves references to other layers (kept as layer IDs after reading XML) into layer objects...
bool isValid() const
Returns the status of the layer.
An interface for classes which can visit style entity (e.g.
QgsChangedAttributesMap changedAttributeValues() const
Returns a map of features with changed attributes values which are not committed. ...
void beforeCommitChanges()
Emitted before changes are committed to the data provider.
bool qgsVariantGreaterThan(const QVariant &lhs, const QVariant &rhs)
Compares two QVariant values and returns whether the first is greater than the second.
QgsFeatureList selectedFeatures() const
Returns a copy of the user-selected features.
bool hasGeometry() const
Returns true if the feature has an associated geometry.
void committedFeaturesRemoved(const QString &layerId, const QgsFeatureIds &deletedFeatureIds)
Emitted when features are deleted from the provider.
QUuid addAction(QgsAction::ActionType type, const QString &name, const QString &command, bool capture=false)
Add an action with the given name and action details.
void committedAttributesDeleted(const QString &layerId, const QgsAttributeList &deletedAttributes)
Emitted when attributes are deleted from the provider.
void setBlendMode(QPainter::CompositionMode blendMode)
Set the blending mode used for rendering a layer.
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.
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...
int count() const
Returns number of items.
void featureDeleted(QgsFeatureId fid)
Emitted when a feature has been deleted.
QMap< QString, QString > QgsStringMap
void editCommandEnded()
Signal emitted, when an edit command successfully ended.
bool isSpatial() const FINAL
Returns true if this is a geometry layer and false in case of NoGeometry (table only) or UnknownGeome...
OperationResult
Success or failure of a geometry operation.
QString username() const
Returns the username stored in the URI.
QgsFieldConstraints::Constraints fieldConstraints(int fieldIndex) const
Returns any constraints which are present for a specified field index.
QgsFeatureIds deletedFeatureIds() const
Returns a list of deleted feature IDs which are not committed.
void invertSelection()
Selects not selected features and deselects selected ones.
void setParameters(const AggregateParameters ¶meters)
Sets all aggregate parameters from a parameter bundle.
bool qgsVariantLessThan(const QVariant &lhs, const QVariant &rhs)
Compares two QVariant values and returns whether the first is less than the second.
Attribute table settings: choice and order of columns, conditional styling.
It has not been specified where the field comes from.
void deselect(QgsFeatureId featureId)
Deselects feature by its ID.
Constraint was set at data provider.
void styleChanged()
Signal emitted whenever a change affects the layer's style.
Field has an expression constraint set. See constraintExpression().
void setFormat(const QgsTextFormat &format)
Sets the label text formatting settings, e.g., font settings, buffer settings, etc.
bool writeXml(QDomNode &layerNode) const
Writes the stored expressions out in XML format.
virtual QgsRectangle extent() const
Returns the extent of the layer.
void setMapTipTemplate(const QString &mapTipTemplate)
The mapTip is a pretty, html representation for feature information.
void writeCustomProperties(QDomNode &layerNode, QDomDocument &doc) const
Write custom properties to project file.
void removeSelection()
Clear selection.
QString attributeAlias(int index) const
Returns the alias of an attribute name or a null string if there is no alias.
Manages joined fields for a vector layer.
QgsConditionalLayerStyles * conditionalStyles() const
Returns the conditional styles that are set for this layer.
virtual QgsLayerMetadata layerMetadata() const
Returns layer metadata collected from the provider's source.
QgsField at(int i) const
Gets field at particular index (must be in range 0..N-1)
void setAuxiliaryLayer(QgsAuxiliaryLayer *layer=nullptr)
Sets the current auxiliary layer.
QgsDataProvider * createProvider(const QString &providerKey, const QString &dataSource, const QgsDataProvider::ProviderOptions &options=QgsDataProvider::ProviderOptions())
Creates a new instance of a provider.
const QgsProjectTranslator * projectTranslator() const
Returns the project translator.
int fieldOriginIndex(int fieldIdx) const
Gets field's origin index (its meaning is specific to each type of origin)
bool updateFeature(QgsFeature &feature, bool skipDefaultValues=false)
Updates an existing feature in the layer, replacing the attributes and geometry for the feature with ...
static QgsTaskManager * taskManager()
Returns the application's task manager, used for managing application wide background task handling...
void dataChanged()
Emitted whenever a change is made to the data provider which may have caused changes in the provider'...
Base class for feedback objects to be used for cancellation of something running in a worker thread...
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
void setFieldConstraint(int index, QgsFieldConstraints::Constraint constraint, QgsFieldConstraints::ConstraintStrength strength=QgsFieldConstraints::ConstraintStrengthHard)
Sets a constraint for a specified field index.
void featureAdded(QgsFeatureId fid)
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.
QgsFeatureRequest & setExpressionContext(const QgsExpressionContext &context)
Sets the expression context used to evaluate filter expressions.
QgsRectangle mExtent
Extent of the layer.
bool isEditable() const FINAL
Returns true if the provider is in editing mode.
void setExcludeAttributesWfs(const QSet< QString > &att)
A set of attributes that are not advertised in WFS requests with QGIS server.
QgsFeatureRequest & setFilterFid(QgsFeatureId fid)
Sets feature ID that should be fetched.
bool changeAttributeValue(QgsFeatureId fid, int field, const QVariant &newValue, const QVariant &oldValue=QVariant())
Changes attribute value in joined layers.
Q_DECL_DEPRECATED void setDataSource(const QString &dataSource, const QString &baseName, const QString &provider, bool loadDefaultStyleFlag=false)
Update the data source of the layer.
void committedGeometriesChanges(const QString &layerId, const QgsGeometryMap &changedGeometries)
QString host() const
Returns the host name stored in the URI.
void setEditorWidgetSetup(int index, const QgsEditorWidgetSetup &setup)
The editor widget setup defines which QgsFieldFormatter and editor widget will be used for the field ...
QgsRectangle boundingBoxOfSelected() const
Returns the bounding box of the selected features. If there is no selection, QgsRectangle(0,0,0,0) is returned.
QgsFeatureRequest & setFilterExpression(const QString &expression)
Set the filter expression.
float maximumScale() const
Gets the maximum scale at which the layer should be simplified.
virtual void updateExtents(bool force=false)
Update the extents for the layer.
Type
The WKB type describes the number of dimensions a geometry has.
static QgsProviderRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.
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.
bool readXml(const QDomNode &layer_node)
Reads the actions in in XML format.
int indexFromName(const QString &fieldName) const
Gets the field index from the field name.
static QVariant readVariant(const QDomElement &element)
Read a QVariant from a QDomElement.
void setSize(double size)
Sets the size for rendered text.
T qgsEnumKeyToValue(const QString &key, const T &defaultValue)
Returns the value corresponding to the given key of an enum.
const QList< QgsVectorLayerJoinInfo > vectorJoins() const
QString id() const
Returns the layer's unique ID, which is used to access this layer from QgsProject.
void reselect()
Reselects the previous set of selected features.
QgsGeometry getGeometry(QgsFeatureId fid) const
Queries the layer for the geometry at the given id.
QgsFields fields() const FINAL
Returns the list of fields of this layer.
QgsCoordinateTransformContext transformContext() const
Returns data provider coordinate transform context.
void writeCommonStyle(QDomElement &layerElement, QDomDocument &document, const QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories) const
Write style data common to all layer types.
const QgsFeatureIds & selectedFeatureIds() const
Returns a list of the selected features IDs in 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...
void readStyleManager(const QDomNode &layerNode)
Read style manager's configuration (if any). To be called by subclasses.
void triggerRepaint(bool deferredUpdate=false)
Will advise the map canvas (and any other interested party) that this layer requires to be repainted...
bool rollBack(bool deleteBuffer=true)
Stops a current editing operation and discards any uncommitted edits.
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 attributeAdded(int idx)
bool equals(const QgsGeometry &geometry) const
Test if this geometry is exactly equal to another geometry.
bool deleteFeature(QgsFeatureId fid) const
Deletes a feature from joined layers.
void select(QgsFeatureId featureId)
Selects feature by its ID.
#define QgsDebugMsgLevel(str, level)
bool allowCommit() const
Controls, if the layer is allowed to commit changes.
QString typeName() const
Gets the field type.
Rendering: scale visibility, simplify method, opacity.
void featureBlendModeChanged(QPainter::CompositionMode blendMode)
Signal emitted when setFeatureBlendMode() is called.
QString displayName() const
Returns the name to use when displaying this field.
virtual void setMetadata(const QgsLayerMetadata &metadata)
Sets the layer's metadata store.
static QgsFeatureRenderer * load(QDomElement &symbologyElem, const QgsReadWriteContext &context)
create a renderer from XML element
bool changeAttributeValues(QgsFeatureId fid, const QgsAttributeMap &newValues, const QgsAttributeMap &oldValues=QgsAttributeMap())
Changes attributes' values in joined layers.
Evaluates and returns the diagram settings relating to a diagram for a specific feature.
void setCrs(const QgsCoordinateReferenceSystem &srs, bool emitSignal=true)
Sets layer's spatial reference system.
QSet< QgsMapLayerDependency > mDependencies
List of layers that may modify this layer on modification.
void beforeModifiedCheck() const
Emitted when the layer is checked for modifications. Use for last-minute additions.
QgsFeatureIterator getSelectedFeatures(QgsFeatureRequest request=QgsFeatureRequest()) const
Returns an iterator of the selected features.
void reload() FINAL
Synchronises with changes in the datasource.
QgsFeatureRequest & setNoAttributes()
Set that no attributes will be fetched.
virtual bool isValid() const =0
Returns true if this is a valid layer.
virtual QgsCoordinateReferenceSystem crs() const =0
Returns the coordinate system for the data source.
QString dataComment() const
Returns a description for this layer as defined in the data provider.
QList< QgsRelation > referencingRelations(int idx) const
Returns the layer's relations, where the foreign key is on this layer.
QgsFields fields() const override=0
Returns the fields associated with this data provider.
QString constraintDescription() const
Returns the descriptive name for the constraint expression.
static QString geometryDisplayString(GeometryType type)
Returns a display string for a geometry type.
double width() const
Returns the width of the rectangle.
bool deleteFeatures(const QgsFeatureIds &fids) const
Deletes a list of features from joined layers.
void afterRollBack()
Emitted after changes are rolled back.
virtual void setExtent(const QgsRectangle &rect)
Sets the extent.
Utility class that encapsulates an action based on vector attributes.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
double opacity() const
Returns the opacity for the vector layer, where opacity is a value between 0 (totally transparent) an...
Geometry validation configuration.
void committedFeaturesAdded(const QString &layerId, const QgsFeatureList &addedFeatures)
Emitted when features are added to the provider.
QgsMapLayerRenderer * createMapRenderer(QgsRenderContext &rendererContext) FINAL
Returns new instance of QgsMapLayerRenderer that will be used for rendering of given context...
void readXml(const QDomElement &elem)
Reads the diagram settings from a DOM element.
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.
bool setDependencies(const QSet< QgsMapLayerDependency > &layers) FINAL
Sets the list of dependencies.
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).
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.
virtual QString dataSourceUri(bool expandAuthConfig=false) const
Gets the data source specification.
Q_DECL_DEPRECATED QgsGeometry::OperationResult addPart(const QVector< QgsPointXY > &ring, QgsFeatureId featureId)
Adds a new part polygon to a multipart feature.
Q_DECL_DEPRECATED QgsGeometry::OperationResult splitFeatures(const QVector< QgsPointXY > &splitLine, bool topologicalEditing=false)
Splits features cut by the given line.
virtual bool accept(QgsStyleEntityVisitorInterface *visitor) const
Accepts the specified symbology visitor, causing it to visit all symbols associated with the labeling...
Defines left outer join from our vector layer to some other vector layer.
Q_DECL_DEPRECATED QgsGeometry::OperationResult splitFeatures(const QVector< QgsPointXY > &splitLine, bool topologicalEditing=false)
Splits features cut by the given line.
QMap< int, QVariant > QgsAttributeMap
virtual bool deleteAttribute(int attr)
Deletes an attribute field (but does not commit it).
void editingStopped()
Emitted when edited changes have been successfully written to the data provider.
void beforeEditingStarted()
Emitted before editing on this layer is started.
static GeometryType geometryType(Type type)
Returns the geometry type for a WKB type, e.g., both MultiPolygon and CurvePolygon would have a Polyg...
QgsGeometryMap mChangedGeometries
Changed geometries which are not committed.
int translateFeature(QgsFeatureId featureId, double dx, double dy)
Translates feature by dx, dy.
void setEnabled(bool enabled)
Sets whether the text buffer will be drawn.
long addTask(QgsTask *task, int priority=0)
Adds a task to the manager.
QString toString(int precision=16) const
Returns a string representation of form xmin,ymin : xmax,ymax Coordinates will be truncated to the sp...
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)...
Don't resolve layer paths or create data providers for layers.
void setColor(const QColor &color)
Sets the color that text will be rendered in.
virtual bool isModified() const
Returns true if the provider has been modified since the last commit.
This class wraps a request for features to a vector layer (or directly its vector data provider)...
QgsAttributeList primaryKeyAttributes() const
Returns the list of attributes which make up the layer's primary keys.
void setLabelsEnabled(bool enabled)
Sets whether labels should be enabled for the layer.
void writeXml(QDomNode &layer_node, QDomDocument &document) const
Saves expressions to xml under the layer node.
QgsVectorLayerJoinInfo joinInfo() const
Returns information to use for joining with primary key and so on.
virtual bool changeGeometry(QgsFeatureId fid, const QgsGeometry &geom)
Change feature's geometry.
The QgsMapLayerLegend class is abstract interface for implementations of legends for one map layer...
virtual QDomElement save(QDomDocument &doc, const QgsReadWriteContext &context) const =0
Returns labeling configuration as XML element.
void setFieldAlias(int index, const QString &aliasString)
Sets an alias (a display name) for attributes to display in dialogs.
QString description() const
Returns the descriptive name of the CRS, e.g., "WGS 84" or "GDA 94 / Vicgrid94".
float threshold() const
Gets the simplification threshold of the vector layer managed.
bool removeJoin(const QString &joinLayerId)
Removes a vector layer join.
void destroyEditCommand()
Destroy active command and rev