28 #include <QPainterPath> 30 #include <QProgressDialog> 87 #ifdef TESTPROVIDERLIB 93 const QString& qmlStyle,
94 const QString& sldStyle,
95 const QString& styleName,
96 const QString& styleDescription,
97 const QString& uiFileContent,
111 QStringList &descriptions,
124 bool loadDefaultStyleFlag )
125 :
QgsMapLayer( VectorLayer, baseName, vectorLayerPath )
126 , mDataProvider( NULL )
127 , mProviderKey( providerKey )
129 , mWkbType(
QGis::WKBUnknown )
130 , mRendererV2( NULL )
133 , mLabelFontNotFoundNotified( false )
134 , mFeatureBlendMode( QPainter::CompositionMode_SourceOver )
135 , mLayerTransparency( 0 )
136 , mVertexMarkerOnlyForSelection( false )
137 , mEditorLayout( GeneratedLayout )
138 , mFeatureFormSuppress( SuppressDefault )
142 , mExpressionFieldBuffer( 0 )
143 , mDiagramRenderer( 0 )
144 , mDiagramLayerSettings( 0 )
145 , mValidExtent( false )
146 , mLazyExtent( true )
147 , mSymbolFeatureCounted( false )
152 if ( ! mProviderKey.isEmpty() )
154 setDataProvider( mProviderKey );
163 bool defaultLoadedFlag =
false;
164 if ( loadDefaultStyleFlag )
183 connect(
QgsProject::instance()->relationManager(), SIGNAL( relationsLoaded() ),
this, SLOT( onRelationsLoaded() ) );
187 mSimplifyMethod.
setSimplifyHints(( QgsVectorSimplifyMethod::SimplifyHints ) settings.value(
"/qgis/simplifyDrawingHints", (
int ) mSimplifyMethod.
simplifyHints() ).toInt() );
188 mSimplifyMethod.
setThreshold( settings.value(
"/qgis/simplifyDrawingTol", mSimplifyMethod.
threshold() ).toFloat() );
203 delete mDataProvider;
206 delete mExpressionFieldBuffer;
209 delete mDiagramLayerSettings;
263 QString idxName =
"";
266 if ( !fldName.isEmpty() )
268 mDisplayField = fldName;
273 int fieldsSize = fields.
size();
275 for (
int idx = 0; idx < fields.
count(); ++idx )
277 QString fldName = fields[idx].name();
278 QgsDebugMsg(
"Checking field " + fldName +
" of " + QString::number( fieldsSize ) +
" total" );
284 if ( fldName.indexOf(
"name", 0, Qt::CaseInsensitive ) > -1 )
286 if ( idxName.isEmpty() )
291 if ( fldName.indexOf(
"descrip", 0, Qt::CaseInsensitive ) > -1 )
293 if ( idxName.isEmpty() )
298 if ( fldName.indexOf(
"id", 0, Qt::CaseInsensitive ) > -1 )
300 if ( idxId.isEmpty() )
308 if ( fieldsSize == 0 )
311 if ( idxName.length() > 0 )
313 mDisplayField = idxName;
317 if ( idxId.length() > 0 )
319 mDisplayField = idxId;
323 mDisplayField = fields[0].name();
340 if ( mRendererV2 && mLabelOn && mLabel &&
349 attributes.append( attrNum );
357 QgsDebugMsg(
"Selecting features based on view extent" );
366 .setFilterRect( rendererContext.
extent() )
367 .setSubsetOfAttributes( attributes ) );
374 bool sel = mSelectedFeatureIds.contains( fet.id() );
375 mLabel->
renderLabel( rendererContext, fet, sel, 0 );
391 QgsDebugMsg( QString(
"Total features processed %1" ).arg( featureCount ) );
418 p.setPen( QColor( 50, 100, 120, 200 ) );
419 p.setBrush( QColor( 200, 200, 210, 120 ) );
420 p.drawEllipse( x - m, y - m, m * 2 + 1, m * 2 + 1 );
424 p.setPen( QColor( 255, 0, 0 ) );
425 p.drawLine( x - m, y + m, x + m, y - m );
426 p.drawLine( x - m, y - m, x + m, y + m );
432 mSelectedFeatureIds.insert( fid );
439 mSelectedFeatureIds.unite( featureIds );
446 mSelectedFeatureIds.remove( fid );
453 mSelectedFeatureIds.subtract( featureIds );
465 .setFilterRect( rect )
477 if ( !addToSelection )
490 if ( intersectingIds.count() > 0 )
492 QgsDebugMsg(
"Trying to select and deselect the same item at the same time. Unsure what to do. Selecting dubious items." );
495 mSelectedFeatureIds -= deselectIds;
496 mSelectedFeatureIds += selectIds;
504 ids.subtract( mSelectedFeatureIds );
536 .setFilterRect( rect )
546 if ( mSelectedFeatureIds.contains( fet.
id() ) )
548 deselectIds << fet.
id();
552 selectIds << fet.
id();
561 if ( mSelectedFeatureIds.size() == 0 )
569 return mDataProvider;
574 return mDataProvider;
579 if ( mDataProvider && mDataProvider->
encoding() != encoding )
588 delete mDiagramRenderer;
589 mDiagramRenderer = r;
626 QgsDebugMsg( QString(
"Data Provider Geometry type is not recognised, is %1" ).arg( type ) );
638 QgsDebugMsg(
"WARNING: This code should never be reached. Problems may occur..." );
656 if ( mSelectedFeatureIds.size() == 0 )
687 if ( mSelectedFeatureIds.contains( fet.
id() ) )
698 if ( retval.
width() == 0.0 || retval.
height() == 0.0 )
707 retval.
set( -1.0, -1.0, 1.0, 1.0 );
716 if ( !mDataProvider )
727 if ( !mSymbolFeatureCounted )
return -1;
728 return mSymbolFeatureCountMap.value( symbol );
733 if ( mSymbolFeatureCounted )
return true;
734 mSymbolFeatureCountMap.clear();
736 if ( !mDataProvider )
748 QgsLegendSymbolList::const_iterator symbolIt = symbolList.constBegin();
750 for ( ; symbolIt != symbolList.constEnd(); ++symbolIt )
752 mSymbolFeatureCountMap.insert( symbolIt->second, 0 );
756 QProgressDialog progressDialog(
tr(
"Updating feature count for layer %1" ).arg(
name() ),
tr(
"Abort" ), 0, nFeatures );
757 progressDialog.setWindowModality( Qt::WindowModal );
758 int featuresCounted = 0;
771 for ( QgsSymbolV2List::iterator symbolIt = featureSymbolList.begin(); symbolIt != featureSymbolList.end(); ++symbolIt )
773 mSymbolFeatureCountMap[*symbolIt] += 1;
779 if ( featuresCounted % 50 == 0 )
781 if ( featuresCounted > nFeatures )
783 progressDialog.setMaximum( 0 );
785 progressDialog.setValue( featuresCounted );
786 if ( progressDialog.wasCanceled() )
788 mSymbolFeatureCountMap.clear();
796 progressDialog.setValue( nFeatures );
797 mSymbolFeatureCounted =
true;
803 mValidExtent =
false;
820 if ( !mValidExtent && mLazyExtent && mDataProvider )
838 if ( !mDataProvider )
857 if ( it->geometry() )
896 if ( ! mDataProvider )
906 if ( ! mDataProvider )
928 double maximumSimplificationScale = mSimplifyMethod.
maximumScale();
931 if ( maximumSimplificationScale > 1 && renderContext.
rendererScale() <= maximumSimplificationScale )
941 if ( !mDataProvider )
950 Q_UNUSED( alsoUpdateExtent );
951 if ( !mEditBuffer || !mDataProvider )
974 QgsDebugMsg( QString(
"feature %1 could not be retrieved" ).arg( f.
id() ) );
982 QgsDebugMsg( QString(
"geometry of feature %1 could not be changed." ).arg( f.
id() ) );
990 for (
int attr = 0; attr < fa.count(); ++attr )
992 if ( fa[attr] != ca[attr] )
996 QgsDebugMsg( QString(
"attribute %1 of feature %2 could not be changed." ).arg( attr ).arg( f.
id() ) );
1008 if ( !mEditBuffer || !mDataProvider )
1012 return utils.
insertVertex( x, y, atFeatureId, beforeVertex );
1018 if ( !mEditBuffer || !mDataProvider )
1022 return utils.
moveVertex( x, y, atFeatureId, atVertex );
1028 if ( !mEditBuffer || !mDataProvider )
1049 int count = mSelectedFeatureIds.size();
1062 *deletedCount = deleted;
1065 return deleted == count;
1070 if ( !mEditBuffer || !mDataProvider )
1074 return utils.
addRing( ring, featureId );
1079 if ( !mEditBuffer || !mDataProvider )
1084 if ( mSelectedFeatureIds.size() < 1 )
1089 else if ( mSelectedFeatureIds.size() > 1 )
1096 return utils.
addPart( points, *mSelectedFeatureIds.constBegin() );
1102 if ( !mEditBuffer || !mDataProvider )
1111 if ( !mEditBuffer || !mDataProvider )
1115 return utils.
splitParts( splitLine, topologicalEditing );
1120 if ( !mEditBuffer || !mDataProvider )
1124 return utils.
splitFeatures( splitLine, topologicalEditing );
1132 int returnValue = 0;
1145 .setFilterRect( geomBBox )
1152 if ( ignoreFeatures.contains( f.
id() ) )
1173 if ( !mEditBuffer || !mDataProvider )
1182 if ( !mEditBuffer || !mDataProvider )
1211 if ( !mDataProvider )
1279 QDomNode pkeyNode = layer_node.namedItem(
"provider" );
1281 if ( pkeyNode.isNull() )
1287 QDomElement pkeyElt = pkeyNode.toElement();
1288 mProviderKey = pkeyElt.text();
1292 if ( ! mProviderKey.isNull() )
1299 mProviderKey =
"postgres";
1303 mProviderKey =
"ogr";
1306 if ( ! setDataProvider( mProviderKey ) )
1311 QDomElement pkeyElem = pkeyNode.toElement();
1312 if ( !pkeyElem.isNull() )
1314 QString encodingString = pkeyElem.attribute(
"encoding" );
1315 if ( !encodingString.isEmpty() )
1325 connect( mJoinBuffer, SIGNAL( joinedFieldsChanged() ),
this, SLOT( onJoinedFieldsChanged() ) );
1327 mJoinBuffer->
readXml( layer_node );
1329 if ( !mExpressionFieldBuffer )
1331 mExpressionFieldBuffer->
readXml( layer_node );
1336 QDomNode prevExpNode = layer_node.namedItem(
"previewExpression" );
1338 if ( prevExpNode.isNull() )
1340 mDisplayExpression =
"";
1344 QDomElement prevExpElem = prevExpNode.toElement();
1345 mDisplayExpression = prevExpElem.text();
1363 bool QgsVectorLayer::setDataProvider( QString
const & provider )
1368 mProviderKey = provider;
1376 if ( mDataProvider )
1378 QgsDebugMsg(
"Instantiated the data provider plugin" );
1384 connect( mDataProvider, SIGNAL( fullExtentCalculated() ),
this, SLOT(
updateExtents() ) );
1390 connect( mJoinBuffer, SIGNAL( joinedFieldsChanged() ),
this, SLOT( onJoinedFieldsChanged() ) );
1398 if ( mProviderKey ==
"postgres" )
1403 QRegExp reg(
"\"[^\"]+\"\\.\"([^\"]+)\"( \\([^)]+\\))?" );
1404 if ( reg.indexIn(
name() ) >= 0 )
1406 QStringList stuff = reg.capturedTexts();
1407 QString lName = stuff[1];
1411 QMap<QString, QgsMapLayer*>::const_iterator it;
1412 for ( it = layers.constBegin(); it != layers.constEnd() && ( *it )->name() != lName; ++it )
1415 if ( it != layers.constEnd() && stuff.size() > 2 )
1417 lName +=
"." + stuff[2].mid( 2, stuff[2].length() - 3 );
1420 if ( !lName.isEmpty() )
1429 else if ( mProviderKey ==
"osm" )
1434 else if ( provider ==
"ogr" )
1467 QDomDocument & document )
1471 QDomElement mapLayerNode = layer_node.toElement();
1473 if ( mapLayerNode.isNull() || (
"maplayer" != mapLayerNode.nodeName() ) )
1479 mapLayerNode.setAttribute(
"type",
"vector" );
1485 if ( mDataProvider )
1487 QDomElement provider = document.createElement(
"provider" );
1488 provider.setAttribute(
"encoding", mDataProvider->
encoding() );
1489 QDomText providerText = document.createTextNode(
providerType() );
1490 provider.appendChild( providerText );
1491 layer_node.appendChild( provider );
1495 QDomElement prevExpElem = document.createElement(
"previewExpression" );
1496 QDomText prevExpText = document.createTextNode( mDisplayExpression );
1497 prevExpElem.appendChild( prevExpText );
1498 layer_node.appendChild( prevExpElem );
1501 mJoinBuffer->
writeXml( layer_node, document );
1504 mExpressionFieldBuffer->
writeXml( layer_node, document );
1521 if ( !rendererElement.isNull() )
1539 QDomNode displayFieldNode = node.namedItem(
"displayfield" );
1540 if ( !displayFieldNode.isNull() )
1542 QDomElement e = displayFieldNode.toElement();
1547 QDomNode blendModeNode = node.namedItem(
"blendMode" );
1548 if ( !blendModeNode.isNull() )
1550 QDomElement e = blendModeNode.toElement();
1555 QDomNode featureBlendModeNode = node.namedItem(
"featureBlendMode" );
1556 if ( !featureBlendModeNode.isNull() )
1558 QDomElement e = featureBlendModeNode.toElement();
1563 QDomNode layerTransparencyNode = node.namedItem(
"layerTransparency" );
1564 if ( !layerTransparencyNode.isNull() )
1566 QDomElement e = layerTransparencyNode.toElement();
1571 QDomElement e = node.toElement();
1575 mLabel->
setMinScale( e.attribute(
"minLabelScale",
"1" ).toFloat() );
1576 mLabel->
setMaxScale( e.attribute(
"maxLabelScale",
"100000000" ).toFloat() );
1580 mSimplifyMethod.
setSimplifyHints(( QgsVectorSimplifyMethod::SimplifyHints ) e.attribute(
"simplifyDrawingHints",
"1" ).toInt() );
1581 mSimplifyMethod.
setThreshold( e.attribute(
"simplifyDrawingTol",
"1" ).toFloat() );
1583 mSimplifyMethod.
setMaximumScale( e.attribute(
"simplifyMaxScale",
"1" ).toFloat() );
1589 QDomNode labelnode = node.namedItem(
"label" );
1590 QDomElement element = labelnode.toElement();
1592 if ( hasLabelsEnabled < 1 )
1601 QDomNode labelattributesnode = node.namedItem(
"labelattributes" );
1603 if ( !labelattributesnode.isNull() && mLabel )
1606 mLabel->
readXML( labelattributesnode );
1610 delete mDiagramRenderer; mDiagramRenderer = 0;
1611 QDomElement singleCatDiagramElem = node.firstChildElement(
"SingleCategoryDiagramRenderer" );
1612 if ( !singleCatDiagramElem.isNull() )
1614 QDomElement catElem = singleCatDiagramElem.firstChildElement(
"DiagramCategory" );
1615 if ( !catElem.isNull() && catElem.attribute(
"enabled",
"1" ) !=
"0" )
1618 mDiagramRenderer->
readXML( singleCatDiagramElem,
this );
1621 QDomElement linearDiagramElem = node.firstChildElement(
"LinearlyInterpolatedDiagramRenderer" );
1622 if ( !linearDiagramElem.isNull() )
1624 QDomElement catElem = linearDiagramElem.firstChildElement(
"DiagramCategory" );
1625 if ( !catElem.isNull() && catElem.attribute(
"enabled",
"1" ) !=
"0" )
1628 mDiagramRenderer->
readXML( linearDiagramElem,
this );
1632 if ( mDiagramRenderer )
1634 QDomElement diagramSettingsElem = node.firstChildElement(
"DiagramLayerSettings" );
1635 if ( !diagramSettingsElem.isNull() )
1638 mDiagramLayerSettings->
readXML( diagramSettingsElem,
this );
1647 QDomNode editFormNode = node.namedItem(
"editform" );
1648 if ( !editFormNode.isNull() )
1650 QDomElement e = editFormNode.toElement();
1654 QDomNode editFormInitNode = node.namedItem(
"editforminit" );
1655 if ( !editFormInitNode.isNull() )
1657 mEditFormInit = editFormInitNode.toElement().text();
1660 QDomNode fFSuppNode = node.namedItem(
"featformsuppress" );
1661 if ( fFSuppNode.isNull() )
1667 QDomElement e = fFSuppNode.toElement();
1671 QDomNode annotationFormNode = node.namedItem(
"annotationform" );
1672 if ( !annotationFormNode.isNull() )
1674 QDomElement e = annotationFormNode.toElement();
1678 mAttributeAliasMap.clear();
1679 QDomNode aliasesNode = node.namedItem(
"aliases" );
1680 if ( !aliasesNode.isNull() )
1682 QDomElement aliasElem;
1684 QDomNodeList aliasNodeList = aliasesNode.toElement().elementsByTagName(
"alias" );
1685 for (
int i = 0; i < aliasNodeList.size(); ++i )
1687 aliasElem = aliasNodeList.at( i ).toElement();
1690 if ( aliasElem.hasAttribute(
"field" ) )
1692 field = aliasElem.attribute(
"field" );
1696 int index = aliasElem.attribute(
"index" ).toInt();
1702 mAttributeAliasMap.insert( field, aliasElem.attribute(
"name" ) );
1707 QDomNode editorLayoutNode = node.namedItem(
"editorlayout" );
1708 if ( editorLayoutNode.isNull() )
1714 if ( editorLayoutNode.toElement().text() ==
"uifilelayout" )
1718 else if ( editorLayoutNode.toElement().text() ==
"tablayout" )
1729 mExcludeAttributesWMS.clear();
1730 QDomNode excludeWMSNode = node.namedItem(
"excludeAttributesWMS" );
1731 if ( !excludeWMSNode.isNull() )
1733 QDomNodeList attributeNodeList = excludeWMSNode.toElement().elementsByTagName(
"attribute" );
1734 for (
int i = 0; i < attributeNodeList.size(); ++i )
1736 mExcludeAttributesWMS.insert( attributeNodeList.at( i ).toElement().text() );
1740 mExcludeAttributesWFS.clear();
1741 QDomNode excludeWFSNode = node.namedItem(
"excludeAttributesWFS" );
1742 if ( !excludeWFSNode.isNull() )
1744 QDomNodeList attributeNodeList = excludeWFSNode.toElement().elementsByTagName(
"attribute" );
1745 for (
int i = 0; i < attributeNodeList.size(); ++i )
1747 mExcludeAttributesWFS.insert( attributeNodeList.at( i ).toElement().text() );
1752 mAttributeEditorElements.clear();
1753 QDomNode attributeEditorFormNode = node.namedItem(
"attributeEditorForm" );
1754 QDomNodeList attributeEditorFormNodeList = attributeEditorFormNode.toElement().childNodes();
1756 for (
int i = 0; i < attributeEditorFormNodeList.size(); i++ )
1758 QDomElement elem = attributeEditorFormNodeList.at( i ).toElement();
1761 mAttributeEditorElements.append( attributeEditorWidget );
1771 if ( elem.tagName() ==
"attributeEditorContainer" )
1775 QDomNodeList childNodeList = elem.childNodes();
1777 for (
int i = 0; i < childNodeList.size(); i++ )
1779 QDomElement childElem = childNodeList.at( i ).toElement();
1785 newElement = container;
1787 else if ( elem.tagName() ==
"attributeEditorField" )
1789 QString
name = elem.attribute(
"name" );
1793 else if ( elem.tagName() ==
"attributeEditorRelation" )
1797 QString
name = elem.attribute(
"name" );
1805 QDomElement mapLayerNode = node.toElement();
1811 QDomElement rendererElement = mRendererV2->
save( doc );
1812 node.appendChild( rendererElement );
1817 mapLayerNode.setAttribute(
"scaleBasedLabelVisibilityFlag", mLabel->
scaleBasedVisibility() ? 1 : 0 );
1818 mapLayerNode.setAttribute(
"minLabelScale", QString::number( mLabel->
minScale() ) );
1819 mapLayerNode.setAttribute(
"maxLabelScale", QString::number( mLabel->
maxScale() ) );
1823 mapLayerNode.setAttribute(
"simplifyDrawingHints", QString::number( mSimplifyMethod.
simplifyHints() ) );
1824 mapLayerNode.setAttribute(
"simplifyDrawingTol", QString::number( mSimplifyMethod.
threshold() ) );
1826 mapLayerNode.setAttribute(
"simplifyMaxScale", QString::number( mSimplifyMethod.
maximumScale() ) );
1832 QDomElement blendModeElem = doc.createElement(
"blendMode" );
1834 blendModeElem.appendChild( blendModeText );
1835 node.appendChild( blendModeElem );
1838 QDomElement featureBlendModeElem = doc.createElement(
"featureBlendMode" );
1840 featureBlendModeElem.appendChild( featureBlendModeText );
1841 node.appendChild( featureBlendModeElem );
1844 QDomElement layerTransparencyElem = doc.createElement(
"layerTransparency" );
1845 QDomText layerTransparencyText = doc.createTextNode( QString::number(
layerTransparency() ) );
1846 layerTransparencyElem.appendChild( layerTransparencyText );
1847 node.appendChild( layerTransparencyElem );
1850 QDomElement dField = doc.createElement(
"displayfield" );
1851 QDomText dFieldText = doc.createTextNode(
displayField() );
1852 dField.appendChild( dFieldText );
1853 node.appendChild( dField );
1856 QDomElement labelElem = doc.createElement(
"label" );
1857 QDomText labelText = doc.createTextNode(
"" );
1861 labelText.setData(
"1" );
1865 labelText.setData(
"0" );
1867 labelElem.appendChild( labelText );
1869 node.appendChild( labelElem );
1876 if ( fieldname !=
"" )
1878 dField = doc.createElement(
"labelfield" );
1879 dFieldText = doc.createTextNode( fieldname );
1880 dField.appendChild( dFieldText );
1881 node.appendChild( dField );
1887 if ( mDiagramRenderer )
1889 mDiagramRenderer->
writeXML( mapLayerNode, doc,
this );
1890 if ( mDiagramLayerSettings )
1891 mDiagramLayerSettings->
writeXML( mapLayerNode, doc,
this );
1902 QDomElement efField = doc.createElement(
"editform" );
1904 efField.appendChild( efText );
1905 node.appendChild( efField );
1907 QDomElement efiField = doc.createElement(
"editforminit" );
1908 if ( !mEditFormInit.isEmpty() )
1909 efiField.appendChild( doc.createTextNode( mEditFormInit ) );
1910 node.appendChild( efiField );
1912 QDomElement fFSuppElem = doc.createElement(
"featformsuppress" );
1914 fFSuppElem.appendChild( fFSuppText );
1915 node.appendChild( fFSuppElem );
1917 QDomElement afField = doc.createElement(
"annotationform" );
1919 afField.appendChild( afText );
1920 node.appendChild( afField );
1923 QDomElement editorLayoutElem = doc.createElement(
"editorlayout" );
1924 switch ( mEditorLayout )
1927 editorLayoutElem.appendChild( doc.createTextNode(
"uifilelayout" ) );
1931 editorLayoutElem.appendChild( doc.createTextNode(
"tablayout" ) );
1936 editorLayoutElem.appendChild( doc.createTextNode(
"generatedlayout" ) );
1940 node.appendChild( editorLayoutElem );
1943 if ( mAttributeAliasMap.size() > 0 )
1945 QDomElement aliasElem = doc.createElement(
"aliases" );
1946 QMap<QString, QString>::const_iterator a_it = mAttributeAliasMap.constBegin();
1947 for ( ; a_it != mAttributeAliasMap.constEnd(); ++a_it )
1953 QDomElement aliasEntryElem = doc.createElement(
"alias" );
1954 aliasEntryElem.setAttribute(
"field", a_it.key() );
1955 aliasEntryElem.setAttribute(
"index", idx );
1956 aliasEntryElem.setAttribute(
"name", a_it.value() );
1957 aliasElem.appendChild( aliasEntryElem );
1959 node.appendChild( aliasElem );
1963 QDomElement excludeWMSElem = doc.createElement(
"excludeAttributesWMS" );
1964 QSet<QString>::const_iterator attWMSIt = mExcludeAttributesWMS.constBegin();
1965 for ( ; attWMSIt != mExcludeAttributesWMS.constEnd(); ++attWMSIt )
1967 QDomElement attrElem = doc.createElement(
"attribute" );
1968 QDomText attrText = doc.createTextNode( *attWMSIt );
1969 attrElem.appendChild( attrText );
1970 excludeWMSElem.appendChild( attrElem );
1972 node.appendChild( excludeWMSElem );
1975 QDomElement excludeWFSElem = doc.createElement(
"excludeAttributesWFS" );
1976 QSet<QString>::const_iterator attWFSIt = mExcludeAttributesWFS.constBegin();
1977 for ( ; attWFSIt != mExcludeAttributesWFS.constEnd(); ++attWFSIt )
1979 QDomElement attrElem = doc.createElement(
"attribute" );
1980 QDomText attrText = doc.createTextNode( *attWFSIt );
1981 attrElem.appendChild( attrText );
1982 excludeWFSElem.appendChild( attrElem );
1984 node.appendChild( excludeWFSElem );
1987 if ( mAttributeEditorElements.size() > 0 )
1989 QDomElement tabsElem = doc.createElement(
"attributeEditorForm" );
1991 for ( QList< QgsAttributeEditorElement* >::const_iterator it = mAttributeEditorElements.begin(); it != mAttributeEditorElements.end(); ++it )
1993 QDomElement attributeEditorWidgetElem = ( *it )->toDomElement( doc );
1994 tabsElem.appendChild( attributeEditorWidgetElem );
1997 node.appendChild( tabsElem );
2009 QDomElement nameElem = node.firstChildElement(
"Name" );
2010 if ( nameElem.isNull() )
2012 errorMessage =
"Warning: Name element not found within NamedLayer while it's required.";
2024 readSldLabeling( node );
2032 Q_UNUSED( errorMessage );
2035 QDomElement nameNode = doc.createElement(
"se:Name" );
2036 nameNode.appendChild( doc.createTextNode(
name() ) );
2037 node.appendChild( nameNode );
2041 node.appendChild( mRendererV2->
writeSld( doc,
name() ) );
2049 if ( !mEditBuffer || !mDataProvider )
2062 Q_UNUSED( emitSignal );
2068 if ( !mEditBuffer || !mDataProvider )
2076 if ( !mEditBuffer || !mDataProvider )
2088 if ( mAttributeAliasMap.contains( name ) )
2090 mAttributeAliasMap.remove( name );
2102 mAttributeAliasMap.insert( name, aliasString );
2108 mAttributeEditorElements.append( data );
2113 if ( fieldIdx < 0 || fieldIdx >= mUpdatedFields.
count() )
2116 return mEditorWidgetV2Types.value( mUpdatedFields[fieldIdx].
name(),
"TextEdit" );
2121 return mEditorWidgetV2Types.value( fieldName,
"TextEdit" );
2126 if ( fieldIdx < 0 || fieldIdx >= mUpdatedFields.
count() )
2129 return mEditorWidgetV2Configs.value( mUpdatedFields[fieldIdx].
name() );
2134 return mEditorWidgetV2Configs.value( fieldName );
2139 if ( attributeIndex < 0 || attributeIndex >=
pendingFields().count() )
2144 return mAttributeAliasMap.value( name,
"" );
2150 if ( displayName.isEmpty() )
2153 if ( attributeIndex >= 0 && attributeIndex < fields.
count() )
2155 displayName = fields[attributeIndex].name();
2172 if ( !mEditBuffer || !mDataProvider )
2180 bool deleted =
false;
2183 attrs = attrs.toSet().toList();
2185 qSort( attrs.begin(), attrs.end(), qGreater<int>() );
2187 Q_FOREACH (
int attr, attrs )
2205 mSelectedFeatureIds.remove( fid );
2214 return mUpdatedFields;
2227 for (
int i = 0; i < mUpdatedFields.
count(); ++i )
2231 pkAttributesList << i;
2234 return pkAttributesList;
2245 mCommitErrors.clear();
2247 if ( !mDataProvider )
2249 mCommitErrors <<
tr(
"ERROR: no provider" );
2255 mCommitErrors <<
tr(
"ERROR: layer not editable" );
2290 return mCommitErrors;
2332 QgsFeatureIds deselectedFeatures = mSelectedFeatureIds - ids;
2334 mSelectedFeatureIds = ids;
2341 return mSelectedFeatureIds.size();
2346 return mSelectedFeatureIds;
2354 if ( mSelectedFeatureIds.count() <= 8 )
2370 features.push_back( f );
2379 if ( mSelectedFeatureIds.count() == 0 )
2385 if ( mSelectedFeatureIds.count() == 1 )
2386 request.
setFilterFid( *mSelectedFeatureIds.constBegin() );
2395 if ( !mEditBuffer || !mDataProvider )
2404 for ( QgsFeatureList::iterator iter = features.begin(); iter != features.end(); ++iter )
2421 QMultiMap<double, QgsSnappingResult> snapResults;
2429 if ( snapResults.size() < 1 )
2434 QMultiMap<double, QgsSnappingResult>::const_iterator snap_it = snapResults.constBegin();
2435 point.
setX( snap_it.value().snappedVertex.x() );
2436 point.
setY( snap_it.value().snappedVertex.y() );
2442 QMultiMap<double, QgsSnappingResult>& snappingResults,
2448 if ( snappingTolerance <= 0 || !mDataProvider )
2453 QList<QgsFeature> featureList;
2454 QgsRectangle searchRect( startPoint.
x() - snappingTolerance, startPoint.
y() - snappingTolerance,
2455 startPoint.
x() + snappingTolerance, startPoint.
y() + snappingTolerance );
2456 double sqrSnappingTolerance = snappingTolerance * snappingTolerance;
2464 for ( QgsGeometryMap::iterator it = cachedGeometries.begin(); it != cachedGeometries.end() ; ++it )
2469 snapToGeometry( startPoint, it.key(), g, sqrSnappingTolerance, snappingResults, snap_to );
2479 .setFilterRect( searchRect )
2485 snapToGeometry( startPoint, f.
id(), f.
geometry(), sqrSnappingTolerance, snappingResults, snap_to );
2490 return n == 0 ? 2 : 0;
2493 void QgsVectorLayer::snapToGeometry(
const QgsPoint& startPoint,
2496 double sqrSnappingTolerance,
2497 QMultiMap<double, QgsSnappingResult>& snappingResults,
2505 int atVertex, beforeVertex, afterVertex;
2506 double sqrDistVertexSnap, sqrDistSegmentSnap;
2513 snappedPoint = geom->
closestVertex( startPoint, atVertex, beforeVertex, afterVertex, sqrDistVertexSnap );
2514 if ( sqrDistVertexSnap < sqrSnappingTolerance )
2519 if ( beforeVertex != -1 )
2524 if ( afterVertex != -1 )
2529 snappingResultVertex.
layer =
this;
2530 snappingResults.insert( sqrt( sqrDistVertexSnap ), snappingResultVertex );
2538 sqrDistSegmentSnap = geom->
closestSegmentWithContext( startPoint, snappedPoint, afterVertex, NULL,
crs().geographicFlag() ? 1e-12 : 1e-8 );
2540 if ( sqrDistSegmentSnap < sqrSnappingTolerance )
2549 snappingResultSegment.
layer =
this;
2550 snappingResults.insert( sqrt( sqrDistSegmentSnap ), snappingResultSegment );
2565 QgsDebugMsg(
"----- Computing Coordinate System" );
2586 return mDisplayField;
2596 return mDisplayExpression;
2601 return ( mEditBuffer && mDataProvider );
2612 if ( readonly && mEditBuffer )
2615 mReadOnly = readonly;
2622 return mEditBuffer && mEditBuffer->
isModified();
2627 if ( idx < 0 || idx >= mUpdatedFields.
count() )
2637 if ( idx < 0 || idx >= mUpdatedFields.
count() )
2652 return mEditorLayout;
2662 if ( attrIdx < 0 || attrIdx >= mUpdatedFields.
count() )
2665 mEditorWidgetV2Types[ mUpdatedFields[ attrIdx ].name()] = widgetType;
2670 if ( attrIdx < 0 || attrIdx >= mUpdatedFields.
count() )
2673 mEditorWidgetV2Configs[ mUpdatedFields[ attrIdx ].name()] = config;
2683 if ( ui.isEmpty() || ui.isNull() )
2696 mAnnotationForm = ui;
2701 return mEditFormInit;
2706 mEditFormInit =
function;
2732 return QSize( cfg.value(
"Width" ).toInt(), cfg.value(
"Height" ).toInt() );
2738 if ( idx >= 0 && idx < fields.
count() )
2743 return mFieldEditables.value( fields[idx].
name(),
true );
2752 if ( idx >= 0 && idx < fields.
count() )
2753 return mLabelOnTop.value( fields[idx].name(), false );
2761 if ( idx >= 0 && idx < fields.
count() )
2762 mFieldEditables[ fields[idx].
name()] = editable;
2768 if ( idx >= 0 && idx < fields.
count() )
2769 mLabelOnTop[ fields[idx].
name()] = onTop;
2782 if ( r != mRendererV2 )
2786 mSymbolFeatureCounted =
false;
2787 mSymbolFeatureCountMap.clear();
2797 if ( !mDataProvider )
2810 if ( !mDataProvider )
2823 if ( !mDataProvider )
2839 cfg[
"CheckedState"] = checked;
2840 cfg[
"UncheckedState"] = unchecked;
2851 return mJoinBuffer && mJoinBuffer->
addJoin( joinInfo );
2870 return QList< QgsVectorJoinInfo >();
2891 if ( !mDataProvider )
2896 mUpdatedFields = mDataProvider->
fields();
2906 if ( mExpressionFieldBuffer )
2907 mExpressionFieldBuffer->
updateFields( mUpdatedFields );
2909 if ( oldFields != mUpdatedFields )
2924 uniqueValues.clear();
2925 if ( !mDataProvider )
2938 mDataProvider->
uniqueValues( index, uniqueValues, limit );
2943 Q_FOREACH (
const QVariant& v, uniqueValues )
2945 vals << v.toString();
2949 while ( it.hasNext() && ( limit < 0 || uniqueValues.count() < limit ) )
2952 QVariant v = it.value().value( index );
2955 QString vs = v.toString();
2956 if ( !vals.contains( vs ) )
2969 int sourceLayerIndex;
2985 mDataProvider->
uniqueValues( index, uniqueValues, limit );
2995 .setSubsetOfAttributes( attList ) );
2998 QVariant currentValue;
2999 QHash<QString, QVariant> val;
3003 val.insert( currentValue.toString(), currentValue );
3004 if ( limit >= 0 && val.size() >= limit )
3010 uniqueValues = val.values();
3014 Q_ASSERT_X(
false,
"QgsVectorLayer::uniqueValues()",
"Unknown source of the field!" );
3019 if ( !mDataProvider )
3036 int sourceLayerIndex;
3063 .setSubsetOfAttributes( attList ) );
3067 double currentValue = 0;
3070 currentValue = f.
attribute( index ).toDouble();
3071 if ( currentValue < minimumValue )
3073 minimumValue = currentValue;
3076 return QVariant( minimumValue );
3079 Q_ASSERT_X(
false,
"QgsVectorLayer::minimumValue()",
"Unknown source of the field!" );
3085 if ( !mDataProvider )
3102 int sourceLayerIndex;
3129 .setSubsetOfAttributes( attList ) );
3133 double currentValue = 0;
3136 currentValue = f.
attribute( index ).toDouble();
3137 if ( currentValue > maximumValue )
3139 maximumValue = currentValue;
3142 return QVariant( maximumValue );
3145 Q_ASSERT_X(
false,
"QgsVectorLayer::maximumValue()",
"Unknown source of the field!" );
3159 return mFeatureBlendMode;
3172 return mLayerTransparency;
3177 void QgsVectorLayer::readSldLabeling(
const QDomNode& node )
3179 QDomElement element = node.toElement();
3180 if ( element.isNull() )
3183 QDomElement userStyleElem = element.firstChildElement(
"UserStyle" );
3184 if ( userStyleElem.isNull() )
3186 QgsDebugMsg(
"Info: UserStyle element not found." );
3190 QDomElement featureTypeStyleElem = userStyleElem.firstChildElement(
"FeatureTypeStyle" );
3191 if ( featureTypeStyleElem.isNull() )
3193 QgsDebugMsg(
"Info: FeatureTypeStyle element not found." );
3198 QDomElement ruleElem = featureTypeStyleElem.lastChildElement(
"Rule" );
3199 if ( ruleElem.isNull() )
3206 QDomElement textSymbolizerElem = ruleElem.lastChildElement(
"TextSymbolizer" );
3207 if ( textSymbolizerElem.isNull() )
3209 QgsDebugMsg(
"Info: TextSymbolizer element not found." );
3215 QDomElement labelElem = textSymbolizerElem.firstChildElement(
"Label" );
3216 if ( !labelElem.isNull() )
3218 QDomElement propertyNameElem = labelElem.firstChildElement(
"PropertyName" );
3219 if ( !propertyNameElem.isNull() )
3250 QString labelAttribute = propertyNameElem.text();
3255 if ( fieldIndex == -1 )
3271 QgsDebugMsg(
"Info: PropertyName element not found." );
3282 QDomElement fontElem = textSymbolizerElem.firstChildElement(
"Font" );
3283 if ( !fontElem.isNull() )
3287 QDomElement cssElem = fontElem.firstChildElement(
"CssParameter" );
3288 while ( !cssElem.isNull() )
3290 cssName = cssElem.attribute(
"name",
"not_found" );
3291 if ( cssName !=
"not_found" )
3293 elemText = cssElem.text();
3294 if ( cssName ==
"font-family" )
3298 else if ( cssName ==
"font-style" )
3300 setCustomProperty(
"labeling/fontItalic", ( elemText ==
"italic" ) || ( elemText ==
"Italic" ) );
3302 else if ( cssName ==
"font-size" )
3305 int fontSize = elemText.toInt( &ok );
3311 else if ( cssName ==
"font-weight" )
3313 setCustomProperty(
"labeling/fontBold", ( elemText ==
"bold" ) || ( elemText ==
"Bold" ) );
3315 else if ( cssName ==
"font-underline" )
3317 setCustomProperty(
"labeling/fontUnderline", ( elemText ==
"underline" ) || ( elemText ==
"Underline" ) );
3321 cssElem = cssElem.nextSiblingElement(
"CssParameter" );
3327 if ( textColor.isValid() )
3332 setCustomProperty(
"labeling/textTransp", 100 - (
int )( 100 * textColor.alphaF() ) );
3336 QDomElement haloElem = textSymbolizerElem.firstChildElement(
"Halo" );
3337 if ( !haloElem.isNull() )
3342 QDomElement radiusElem = haloElem.firstChildElement(
"Radius" );
3343 if ( !radiusElem.isNull() )
3346 double bufferSize = radiusElem.text().toDouble( &ok );
3354 if ( bufferColor.isValid() )
3359 setCustomProperty(
"labeling/bufferTransp", 100 - (
int )( 100 * bufferColor.alphaF() ) );
3364 QDomElement labelPlacementElem = textSymbolizerElem.firstChildElement(
"LabelPlacement" );
3365 if ( !labelPlacementElem.isNull() )
3368 QDomElement pointPlacementElem = labelPlacementElem.firstChildElement(
"PointPlacement" );
3369 if ( !pointPlacementElem.isNull() )
3373 QDomElement displacementElem = pointPlacementElem.firstChildElement(
"Displacement" );
3374 if ( !displacementElem.isNull() )
3376 QDomElement displacementXElem = displacementElem.firstChildElement(
"DisplacementX" );
3377 if ( !displacementXElem.isNull() )
3380 double xOffset = displacementXElem.text().toDouble( &ok );
3386 QDomElement displacementYElem = displacementElem.firstChildElement(
"DisplacementY" );
3387 if ( !displacementYElem.isNull() )
3390 double yOffset = displacementYElem.text().toDouble( &ok );
3398 QDomElement rotationElem = pointPlacementElem.firstChildElement(
"Rotation" );
3399 if ( !rotationElem.isNull() )
3402 double rotation = rotationElem.text().toDouble( &ok );
3414 if ( !mDiagramLayerSettings )
3416 *mDiagramLayerSettings = s;
3421 QString myMetadata =
"<html><body>";
3425 myMetadata +=
"<p class=\"subheaderglossy\">";
3426 myMetadata +=
tr(
"General" );
3427 myMetadata +=
"</p>\n";
3432 myMetadata +=
"<p class=\"glossy\">" +
tr(
"Layer comment" ) +
"</p>\n";
3433 myMetadata +=
"<p>";
3435 myMetadata +=
"</p>\n";
3439 myMetadata +=
"<p class=\"glossy\">" +
tr(
"Storage type of this layer" ) +
"</p>\n";
3440 myMetadata +=
"<p>";
3442 myMetadata +=
"</p>\n";
3447 myMetadata +=
"<p class=\"glossy\">" +
tr(
"Description of this provider" ) +
"</p>\n";
3448 myMetadata +=
"<p>";
3450 myMetadata +=
"</p>\n";
3454 myMetadata +=
"<p class=\"glossy\">" +
tr(
"Source for this layer" ) +
"</p>\n";
3455 myMetadata +=
"<p>";
3457 myMetadata +=
"</p>\n";
3471 myMetadata +=
"<p class=\"glossy\">" +
tr(
"Geometry type of the features in this layer" ) +
"</p>\n";
3472 myMetadata +=
"<p>";
3473 myMetadata += typeString;
3474 myMetadata +=
"</p>\n";
3478 if ( !pkAttrList.isEmpty() )
3480 myMetadata +=
"<p class=\"glossy\">" +
tr(
"Primary key attributes" ) +
"</p>\n";
3481 myMetadata +=
"<p>";
3482 foreach (
int idx, pkAttrList )
3486 myMetadata +=
"</p>\n";
3491 myMetadata +=
"<p class=\"glossy\">" +
tr(
"The number of features in this layer" ) +
"</p>\n";
3492 myMetadata +=
"<p>";
3494 myMetadata +=
"</p>\n";
3496 myMetadata +=
"<p class=\"glossy\">" +
tr(
"Editing capabilities of this layer" ) +
"</p>\n";
3497 myMetadata +=
"<p>";
3499 myMetadata +=
"</p>\n";
3504 myMetadata +=
"<p class=\"subheaderglossy\">";
3505 myMetadata +=
tr(
"Extents" );
3506 myMetadata +=
"</p>\n";
3509 myMetadata +=
"<p class=\"glossy\">" +
tr(
"In layer spatial reference system units" ) +
"</p>\n";
3510 myMetadata +=
"<p>";
3523 QString xMin, yMin, xMax, yMax;
3524 double changeoverValue = 99999;
3525 if ( qAbs( myExtent.
xMinimum() ) > changeoverValue )
3527 xMin = QString(
"%1" ).arg( myExtent.
xMinimum(), 0,
'f', 2 );
3531 xMin = QString(
"%1" ).arg( myExtent.
xMinimum() );
3533 if ( qAbs( myExtent.
yMinimum() ) > changeoverValue )
3535 yMin = QString(
"%1" ).arg( myExtent.
yMinimum(), 0,
'f', 2 );
3539 yMin = QString(
"%1" ).arg( myExtent.
yMinimum() );
3541 if ( qAbs( myExtent.
xMaximum() ) > changeoverValue )
3543 xMax = QString(
"%1" ).arg( myExtent.
xMaximum(), 0,
'f', 2 );
3547 xMax = QString(
"%1" ).arg( myExtent.
xMaximum() );
3549 if ( qAbs( myExtent.
yMaximum() ) > changeoverValue )
3551 yMax = QString(
"%1" ).arg( myExtent.
yMaximum(), 0,
'f', 2 );
3555 yMax = QString(
"%1" ).arg( myExtent.
yMaximum() );
3558 myMetadata +=
tr(
"xMin,yMin %1,%2 : xMax,yMax %3,%4" )
3559 .arg( xMin ).arg( yMin ).arg( xMax ).arg( yMax );
3563 myMetadata +=
tr(
"unknown extent" );
3566 myMetadata +=
"</p>\n";
3574 QgsRectangle myProjectedExtent = coordinateTransform->transformBoundingBox(
extent() );
3575 myMetadata +=
"<p class=\"glossy\">" +
tr(
"In project spatial reference system units" ) +
"</p>\n";
3576 myMetadata +=
"<p>";
3577 myMetadata +=
tr(
"xMin,yMin %1,%2 : xMax,yMax %3,%4" )
3578 .arg( myProjectedExtent.
xMinimum() )
3579 .arg( myProjectedExtent.
yMinimum() )
3580 .arg( myProjectedExtent.
xMaximum() )
3581 .arg( myProjectedExtent.
yMaximum() );
3582 myMetadata +=
"</p>\n";
3588 myMetadata +=
"<p class=\"glossy\">" +
tr(
"Layer Spatial Reference System" ) +
"</p>\n";
3589 myMetadata +=
"<p>";
3590 myMetadata +=
crs().
toProj4().replace( QRegExp(
"\"" ),
" \"" );
3591 myMetadata +=
"</p>\n";
3599 myMetadata +=
"<p class=\"glossy\">" +
tr(
"Project (Output) Spatial Reference System" ) +
"</p>\n";
3600 myMetadata +=
"<p>";
3601 myMetadata += coordinateTransform->destCRS().toProj4().replace( QRegExp(
"\"" ),
" \"" );
3602 myMetadata +=
"</p>\n";
3610 myMetadata +=
"<p class=\"glossy\">" +
tr(
"In project spatial reference system units" ) +
"</p>\n";
3611 myMetadata +=
"<p>";
3612 myMetadata +=
tr(
"(Invalid transformation of layer extents)" );
3613 myMetadata +=
"</p>\n";
3621 myMetadata +=
"<p class=\"glossy\">" +
tr(
"Attribute field info" ) +
"</p>\n";
3622 myMetadata +=
"<p>";
3625 myMetadata +=
"<table width=\"100%\">";
3626 myMetadata +=
"<tr><th>";
3627 myMetadata +=
tr(
"Field" );
3628 myMetadata +=
"</th>";
3629 myMetadata +=
"<th>";
3630 myMetadata +=
tr(
"Type" );
3631 myMetadata +=
"</th>";
3632 myMetadata +=
"<th>";
3633 myMetadata +=
tr(
"Length" );
3634 myMetadata +=
"</th>";
3635 myMetadata +=
"<th>";
3636 myMetadata +=
tr(
"Precision" );
3637 myMetadata +=
"</th>";
3638 myMetadata +=
"<th>";
3639 myMetadata +=
tr(
"Comment" );
3640 myMetadata +=
"</th>";
3644 for (
int i = 0, n = myFields.
size(); i < n; ++i )
3646 const QgsField& myField = fields[i];
3648 myMetadata +=
"<tr><td>";
3649 myMetadata += myField.
name();
3650 myMetadata +=
"</td>";
3651 myMetadata +=
"<td>";
3653 myMetadata +=
"</td>";
3654 myMetadata +=
"<td>";
3655 myMetadata += QString(
"%1" ).arg( myField.
length() );
3656 myMetadata +=
"</td>";
3657 myMetadata +=
"<td>";
3658 myMetadata += QString(
"%1" ).arg( myField.
precision() );
3659 myMetadata +=
"</td>";
3660 myMetadata +=
"<td>";
3661 myMetadata += QString(
"%1" ).arg( myField.
comment() );
3662 myMetadata +=
"</td></tr>";
3666 myMetadata +=
"</table>";
3669 myMetadata +=
"</body></html>";
3675 mSymbolFeatureCounted =
false;
3678 void QgsVectorLayer::onRelationsLoaded()
3701 void QgsVectorLayer::onJoinedFieldsChanged()
3714 cfg.value(
"Key" ).toString(),
3715 cfg.value(
"Value" ).toString(),
3716 cfg.value(
"AllowNull" ).toBool(),
3717 cfg.value(
"OrderByValue" ).toBool(),
3718 cfg.value(
"AllowMulti" ).toBool(),
3719 cfg.value(
"FilterExpression" ).toString()
3735 return mAttributeEditorElements;
3740 mAttributeEditorElements.clear();
3745 QDomElement elem = doc.createElement(
"attributeEditorContainer" );
3746 elem.setAttribute(
"name", mName );
3757 mChildren.append( widget );
3762 QList<QgsAttributeEditorElement*> results;
3768 results.append( elem );
3771 if ( elem->
type() == AeTypeContainer )
3784 QDomElement elem = doc.createElement(
"attributeEditorField" );
3785 elem.setAttribute(
"name", mName );
3786 elem.setAttribute(
"index", mIdx );
3796 msgError =
QObject::tr(
"Unable to load %1 provider" ).arg( mProviderKey );
3801 if ( !listStylesExternalMethod )
3804 msgError =
QObject::tr(
"Provider %1 has no %2 method" ).arg( mProviderKey ).arg(
"listStyles" );
3808 return listStylesExternalMethod(
mDataSource, ids, names, descriptions, msgError );
3817 msgError =
QObject::tr(
"Unable to load %1 provider" ).arg( mProviderKey );
3822 if ( !getStyleByIdMethod )
3825 msgError =
QObject::tr(
"Provider %1 has no %2 method" ).arg( mProviderKey ).arg(
"getStyleById" );
3829 return getStyleByIdMethod(
mDataSource, styleId, msgError );
3834 bool useAsDefault, QString uiFileContent, QString &msgError )
3837 QString sldStyle, qmlStyle;
3842 msgError =
QObject::tr(
"Unable to load %1 provider" ).arg( mProviderKey );
3847 if ( !saveStyleExternalMethod )
3850 msgError =
QObject::tr(
"Provider %1 has no %2 method" ).arg( mProviderKey ).arg(
"saveStyle" );
3854 QDomDocument qmlDocument, sldDocument;
3856 if ( !msgError.isNull() )
3860 qmlStyle = qmlDocument.toString();
3863 if ( !msgError.isNull() )
3867 sldStyle = sldDocument.toString();
3869 saveStyleExternalMethod(
mDataSource, qmlStyle, sldStyle, name,
3870 description, uiFileContent, useAsDefault, msgError );
3883 if ( !loadFromLocalDB && !dsUri.
database().isEmpty() )
3890 if ( loadStyleExternalMethod )
3892 QString qml, errorMsg;
3893 qml = loadStyleExternalMethod(
mDataSource, errorMsg );
3894 if ( !qml.isEmpty() )
3908 QDomDocument myDocument(
"qgis" );
3909 myDocument.setContent( namedStyle );
3917 QDomElement elem = doc.createElement(
"attributeEditorRelation" );
3918 elem.setAttribute(
"name", mName );
3919 elem.setAttribute(
"relation", mRelation.id() );
3925 mRelation = relationManager->
relation( mRelationId );
QgsFeatureId id() const
Get the feature id for this feature.
bool deleteVertex(QgsFeatureId atFeatureId, int atVertex)
Deletes a vertex from a feature.
void setExtent(const QgsRectangle &rect) override
Set the extent.
bool draw(QgsRenderContext &rendererContext) override
Draws the layer.
virtual QString subsetString()
Get the string (typically sql) used to define a subset of the layer.
const QgsEditorWidgetConfig editorWidgetV2Config(int fieldIdx) const
Get the configuration for the editor widget used to represent the field at the given index...
Class for parsing and evaluation of expressions (formerly called "search strings").
void updateFields()
Assembles mUpdatedFields considering provider fields, joined fields and added fields.
const QString & name() const
Gets the name of the field.
bool hasEvalError() const
Returns true if an error occurred when evaluating last input.
Wrapper for iterator of features from vector data provider or vector layer.
QMap< QgsFeatureId, QgsGeometry > QgsGeometryMap
bool isValid() const
Returns the validity of this relation.
void selectAll()
Select all the features.
bool intersects(const QgsRectangle &rect) const
returns true when rectangle intersects with other rectangle
QgsFeatureRendererV2 * rendererV2()
Return renderer V2.
#define RENDERER_TAG_NAME
virtual QString subsetString()
Returns the subset definition string (typically sql) currently in use by the layer and used by the pr...
bool fieldEditable(int idx)
is edit widget editable
bool addJoin(const QgsVectorJoinInfo &joinInfo)
Joins another vector layer to this layer.
virtual QString getStyleFromDatabase(QString styleId, QString &msgError)
Will return the named style corresponding to style id provided.
virtual bool willRenderFeature(QgsFeature &feat)
return whether the renderer will render a feature or not.
A rectangle specified with double values.
Base class for all map layer types.
bool init(QgsRelationManager *relManager)
Initializes the relation from the id.
const QList< QgsVectorJoinInfo > vectorJoins() const
void setDiagramLayerSettings(const QgsDiagramLayerSettings &s)
bool isEmpty() const
test if rectangle is empty.
int insertSegmentVerticesForSnap(const QList< QgsSnappingResult > &snapResults)
Inserts vertices to the snapped segments.
bool readSymbology(const QDomNode &node, QString &errorMessage) override
Read the symbology for the current layer from the Dom node supplied.
field comes from a joined layer (originIndex / 1000 = index of the join, originIndex % 1000 = index w...
float threshold() const
Gets the simplification threshold of the vector layer managed.
void clearAttributeEditorWidgets()
Clears all the tabs for the attribute editor form.
QgsFeatureList selectedFeatures()
Get a copy of the user-selected features.
QgsMapLayer::LayerType type() const
Get the type of the layer.
virtual bool addAttribute(const QgsField &field)
add an attribute field (but does not commit it) returns true if the field was added ...
virtual bool writeXml(QDomNode &layer_node, QDomDocument &doc) override
write vector layer specific state to project file Dom node.
void setMinimal()
Set a rectangle so that min corner is at max and max corner is at min.
int makeDifference(QgsGeometry *other)
Changes this geometry such that it does not intersect the other geometry.
EditorLayout editorLayout()
get the active layout for the attribute editor for this layer
virtual void saveStyleToDatabase(QString name, QString description, bool useAsDefault, QString uiFileContent, QString &msgError)
Save named and sld style of the layer to the style table in the db.
void createJoinCaches()
Calls cacheJoinLayer() for all vector joins.
virtual void updateExtents()
Update the extents of the layer.
void readCustomProperties(const QDomNode &layerNode, const QString &keyStartsWith="")
Read custom properties from project file.
void addExpression(const QString &exp, const QgsField &fld)
Add an expression to the buffer.
QList< QgsSymbolV2 * > QgsSymbolV2List
void removeJoin(const QString &joinLayerId)
Removes a vector layer join.
QString publicSource() const
void beforeRollBack()
Is emitted, before changes are rolled back.
int addRing(const QList< QgsPoint > &ring, QgsFeatureId *featureId=0)
Adds a ring to polygon/multipolygon features.
virtual bool addFeatures(QgsFeatureList &features)
Insert a copy of the given features into the layer (but does not commit it)
EditorLayout
The different types to layout the attribute editor.
Use exact geometry intersection (slower) instead of bounding boxes.
static QgsFeatureRendererV2 * loadSld(const QDomNode &node, QGis::GeometryType geomType, QString &errorMessage)
create a new renderer according to the information contained in the UserStyle element of a SLD style ...
void setEditFormInit(QString function)
set python function for edit form initialization
int translateFeature(QgsFeatureId featureId, double dx, double dy)
Translates feature by dx, dy.
QVariant maximumValue(int index)
Returns maximum value for an attribute column or invalid variant in case of error.
Renders the diagrams for all features with the same settings.
QString capabilitiesString() const
Returns the above in friendly format.
Q_DECL_DEPRECATED int removePolygonIntersections(QgsGeometry *geom, QgsFeatureIds ignoreFeatures=QgsFeatureIds())
Changes the specified geometry such that it has no intersections with other polygon (or multipolygon)...
virtual bool addFeature(QgsFeature &f)
Adds a feature.
static QgsProviderRegistry * instance(QString pluginPath=QString::null)
means of accessing canonical single instance
field has been temporarily added in editing mode (originIndex = index in the list of added attributes...
void layerTransparencyChanged(int layerTransparency)
Signal emitted when setLayerTransparency() is called.
double yMaximum() const
Get the y maximum value (top side of rectangle)
bool deleteFeature(QgsFeatureId fid)
delete a feature from the layer (but does not commit it)
virtual QgsCoordinateReferenceSystem crs()=0
QSet< QgsFeatureId > QgsFeatureIds
void uniqueValues(int index, QList< QVariant > &uniqueValues, int limit=-1)
Returns unique values for column.
QList< QgsFeature > QgsFeatureList
void beginEditCommand(QString text)
Create edit command for undo/redo operations.
const QgsVectorJoinList & vectorJoins() const
int fieldNameIndex(const QString &fieldName) const
Look up field's index from name also looks up case-insensitive if there is no match otherwise...
double rendererScale() const
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest())
Query the provider for features specified in request.
virtual QDomElement save(QDomDocument &doc)
store renderer info to XML element
friend class QgsVectorLayerFeatureSource
void setForceLocalOptimization(bool localOptimization)
Sets where the simplification executes, after fetch the geometries from provider, or when supported...
virtual bool applyNamedStyle(QString namedStyle, QString &errorMsg)
Will load a named style from a provided QML string.
void invertSelectionInRectangle(QgsRectangle &rect)
Invert selection of features found within the search rectangle (in layer's coordinates) ...
bool commitChanges()
Attempts to commit any changes to disk.
void setRendererV2(QgsFeatureRendererV2 *r)
Set renderer V2.
virtual QgsTransaction * transaction() const
Returns the transaction this data provider is included in, if any.
void deleteCachedGeometries()
Deletes the geometries in mCachedGeometries.
Storage and management of actions associated with Qgis layer attributes.
QgsGeometry * geometry() const
Get the geometry object associated with this feature.
virtual void setEncoding(const QString &e)
Set encoding used for accessing data from layer.
bool startEditing()
Make layer editable.
void setSimplifyHints(SimplifyHints simplifyHints)
Sets the simplification hints of the vector layer managed.
bool contains(const QgsRectangle &rect) const
return true when rectangle contains other rectangle
void setRendererScale(double scale)
void setCustomProperty(const QString &key, const QVariant &value)
Set a custom property for layer.
VertexMarkerType
Editing vertex markers.
void removeExpressionField(int index)
Remove an expression field.
static QgsMapLayerRegistry * instance()
const QgsChangedAttributesMap & changedAttributeValues()
Changed attributes values which are not commited.
double closestSegmentWithContext(const QgsPoint &point, QgsPoint &minDistPoint, int &afterVertex, double *leftOf=0, double epsilon=DEFAULT_SEGMENT_EPSILON)
Searches for the closest segment of geometry to the given point.
void select(QgsRectangle &rect, bool addToSelection)
Select features found within the search rectangle (in layer's coordinates)
QgsVectorLayer::FeatureFormSuppress featureFormSuppress() const
Type of feature form pop-up suppression after feature creation (overrides app setting) ...
#define Q_NOWARN_DEPRECATED_PUSH
int precision() const
Gets the precision of the field.
void renderLabel(QgsRenderContext &renderContext, QgsFeature &feature, bool selected, QgsLabelAttributes *classAttributes=0)
render label
QgsFeatureRequest & setSubsetOfAttributes(const QgsAttributeList &attrs)
Set a subset of attributes that will be fetched.
virtual QgsLegendSymbolList legendSymbolItems(double scaleDenominator=-1, QString rule="")
return a list of item text / symbol
QGis::GeometryType type() const
Returns type of the vector.
Q_DECL_DEPRECATED QString dateFormat(int idx)
Access date format.
SimplifyHint
Simplification flags for fast rendering of features.
bool deleteAttributes(QList< int > attrs)
Deletes a list of attribute fields (but does not commit it)
void readCustomSymbology(const QDomElement &element, QString &errorMessage)
Signal emitted whenever the symbology (QML-file) for this layer is being read.
void addAttributeAlias(int attIndex, QString aliasString)
Sets an alias (a display name) for attributes to display in dialogs.
static const char * vectorGeometryType(GeometryType type)
description strings for geometry types
int insertSegmentVerticesForSnap(const QList< QgsSnappingResult > &snapResults)
Inserts vertices to the snapped segments.
Q_DECL_DEPRECATED QMap< QString, QVariant > valueMap(int idx)
Access value map.
void readXml(const QDomNode &layer_node)
Reads joins from project file.
virtual void uniqueValues(int index, QList< QVariant > &uniqueValues, int limit=-1)
Return unique values of an attribute.
Container of fields for a vector layer.
virtual void rollBack()
Stop editing and discard the edits.
const QgsRectangle & cachedGeometriesRect()
void setDiagramRenderer(QgsDiagramRendererV2 *r)
Sets diagram rendering object (takes ownership)
void setLayerTransparency(int layerTransparency)
Write transparency for layer.
ValueRelationData valueRelation(int idx)
Access value relation widget data.
QgsChangedAttributesMap mChangedAttributeValues
Changed attributes values which are not commited.
WkbType
Used for symbology operations.
const QgsRectangle & extent() const
void remAttributeAlias(int attIndex)
Removes an alias (a display name) for attributes to display in dialogs.
The QGis class provides global constants for use throughout the application.
void setDisplayExpression(const QString &displayExpression)
Set the preview expression, used to create a human readable preview string.
bool addFeature(QgsFeature &f, bool alsoUpdateExtent=true)
Adds a feature.
virtual QList< QString > usedAttributes()=0
field comes from the underlying data provider of the vector layer (originIndex = index in provider's ...
int addPart(const QList< QgsPoint > &ring, QgsFeatureId featureId)
Adds a new part polygon to a multipart feature.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
QList< QgsRelation > referencingRelations(int idx)
Get relations, where the foreign key is on this layer.
static const int EditingCapabilities
bitmask of all provider's editing capabilities
virtual ~QgsVectorLayer()
Destructor.
virtual QgsAttributeList pkAttributeIndexes()
Return list of indexes of fields that make up the primary key.
const QString displayExpression()
Get the preview expression, used to create a human readable preview string.
bool deleteVertex(QgsFeatureId atFeatureId, int atVertex)
Deletes a vertex from a feature.
void beforeCommitChanges()
Is emitted, before changes are commited to the data provider.
QgsPoint closestVertex(const QgsPoint &point, int &atVertex, int &beforeVertex, int &afterVertex, double &sqrDist)
Returns the vertex closest to the given point, the corresponding vertex index, squared distance snap ...
QgsPoint vertexAt(int atVertex)
Returns coordinates of a vertex.
void committedFeaturesRemoved(const QString &layerId, const QgsFeatureIds &deletedFeatureIds)
void committedAttributesDeleted(const QString &layerId, const QgsAttributeList &deletedAttributes)
Signals emitted after committing changes.
virtual bool isEditable() const override
Returns true if the provider is in editing mode.
QVariant minimumValue(int index)
Returns minimum value for an attribute column or invalid variant in case of error.
bool insertVertex(double x, double y, QgsFeatureId atFeatureId, int beforeVertex)
Insert a new vertex before the given vertex number, in the given ring, item (first number is index 0)...
void featureDeleted(QgsFeatureId fid)
QString readPath(QString filename) const
turn filename read from the project file to an absolute path
void editCommandEnded()
Signal emitted, when an edit command successfully ended.
void setBlendMode(const QPainter::CompositionMode &blendMode)
Write blend mode for layer.
void writeCustomSymbology(QDomElement &element, QDomDocument &doc, QString &errorMessage) const
Signal emitted whenever the symbology (QML-file) for this layer is being written. ...
BlendMode
Blending modes enum defining the available composition modes that can be used when rendering a layer...
void invertSelection()
Select not selected features and deselect selected ones.
it has not been specified where the field comes from
int splitFeatures(const QList< QgsPoint > &splitLine, bool topologicalEditing=false)
Splits features cut by the given line.
virtual void startRender(QgsRenderContext &context, const QgsFields &fields)=0
static void logMessage(QString message, QString tag=QString::null, MessageLevel level=WARNING)
add a message to the instance (and create it if necessary)
virtual void updateExtents()
Update the extents for the layer.
Returns diagram settings for a feature.
QGis::WkbType wkbType() const
Returns the WKBType or WKBUnknown in case of error.
void removeSelection()
Clear selection.
Manages joined fields for a vector layer.
const QgsVectorJoinInfo * joinForFieldIndex(int index, const QgsFields &fields, int &sourceFieldIndex) const
Finds the vector join for a layer field index.
QString editForm()
get edit form
void set(const QgsPoint &p1, const QgsPoint &p2)
Set the rectangle from two QgsPoints.
virtual void stopRender(QgsRenderContext &context)=0
void setEditorLayout(EditorLayout editorLayout)
set the active layout for the attribute editor for this layer
bool writeXML(QDomNode &layer_node, QDomDocument &doc) const
Writes the actions out in XML format.
QgsGeometryMap & cachedGeometries()
virtual QDomElement toDomElement(QDomDocument &doc) const override
bool containsJoins() const
Quick way to test if there is any join at all.
const QString & name() const
Get the display name of the layer.
void checkJoinLayerRemove(QString theLayerId)
Check if there is a join with a layer that will be removed.
virtual QgsSymbolV2List originalSymbolsForFeature(QgsFeature &feat)
Equivalent of originalSymbolsForFeature() call extended to support renderers that may use more symbol...
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.
SnappingType
Snap to vertex, to segment or both.
QString encoding() const
Get encoding which is used for accessing data.
virtual void writeXML(QDomElement &layerElem, QDomDocument &doc, const QgsVectorLayer *layer) const =0
virtual QVariant maximumValue(int index)
Returns the maximum value of an attribute.
virtual QgsMapLayerRenderer * createMapRenderer(QgsRenderContext &rendererContext) override
Return new instance of QgsMapLayerRenderer that will be used for rendering of given context...
QgsFeatureRequest & setFilterFid(QgsFeatureId fid)
Set feature ID that should be fetched.
virtual QDomElement toDomElement(QDomDocument &doc) const override
void geometryChanged(QgsFeatureId fid, QgsGeometry &geom)
void combineExtentWith(QgsRectangle *rect)
expand the rectangle so that covers both the original rectangle and the given rectangle ...
bool addJoin(const QgsVectorJoinInfo &joinInfo)
Joins another vector layer to this layer.
QPainter::CompositionMode blendMode() const
Read blend mode for layer.
bool simplifyDrawingCanbeApplied(const QgsRenderContext &renderContext, QgsVectorSimplifyMethod::SimplifyHint simplifyHint) const
Returns whether the VectorLayer can apply the specified simplification hint.
void deselect(const QgsFeatureId featureId)
Deselect feature by its ID.
QPainter::CompositionMode featureBlendMode() const
Read blend mode for layer.
QgsFeatureRequest & setFilterFids(QgsFeatureIds fids)
Set feature ID that should be fetched.
bool writeSld(QDomNode &node, QDomDocument &doc, QString &errorMessage) const
QgsRectangle extent() override
Return the extent of the layer as a QRect.
void readStyleManager(const QDomNode &layerNode)
Read style manager's configuration (if any).
bool rollBack(bool deleteBuffer=true)
Stop editing and discard the edits.
double yMinimum() const
Get the y minimum value (bottom side of rectangle)
virtual bool setSubsetString(QString subset, bool updateFeatureCount=true)
Set the subset string used to create a subset of features in the layer.
QgsDataProvider * provider(const QString &providerKey, const QString &dataSource)
Create an instance of the provider.
double xMaximum() const
Get the x maximum value (right side of rectangle)
QString attributeDisplayName(int attributeIndex) const
Convenience function that returns the attribute alias if defined or the field name else...
const QgsFeatureIds & selectedFeaturesIds() const
Return reference to identifiers of selected features.
QString capabilitiesString() const
Capabilities for this layer in a friendly format.
QgsRelation relation(const QString &id) const
Get access to a relation by its id.
The attribute value should not be shown in the attribute form.
virtual QString dataComment() const
Return a short comment for the data that this provider is providing access to (e.g.
Represents the result of a snapping operation.
void readXML(const QDomElement &elem, const QgsVectorLayer *layer)
void setCrs(const QgsCoordinateReferenceSystem &srs, bool emitSignal=true)
Sets layer's spatial reference system.
Q_DECL_DEPRECATED EditType editType(int idx)
Get edit type.
virtual int capabilities() const
Returns a bitmask containing the supported capabilities Note, some capabilities may change depending ...
void writeStyleManager(QDomNode &layerNode, QDomDocument &doc) const
Write style manager's configuration (if exists).
int snapWithContext(const QgsPoint &startPoint, double snappingTolerance, QMultiMap< double, QgsSnappingResult > &snappingResults, QgsSnapper::SnappingType snap_to)
Snaps to segment or vertex within given tolerance.
const QString editorWidgetV2(int fieldIdx) const
Get the id for the editor widget used to represent the field at the given index.
virtual void setExtent(const QgsRectangle &rect)
Set the extent.
int addTopologicalPoints(QgsGeometry *geom)
Adds topological points for every vertex of the geometry.
void setScaleBasedVisibility(bool theVisibilityFlag)
Accessor and mutator for the scale based visilibility flag.
void committedFeaturesAdded(const QString &layerId, const QgsFeatureList &addedFeatures)
int addPart(const QList< QgsPoint > &ring)
Adds a new part polygon to a multipart feature.
int fieldOriginIndex(int fieldIdx) const
Get field's origin index (its meaning is specific to each type of origin)
bool deleteAttribute(int attr)
delete an attribute field (but does not commit it)
void editingStopped()
Is emitted, when edited changes successfully have been written to the data provider.
void writeXml(QDomNode &layer_node, QDomDocument &document) const
Saves expressions to xml under the layer node.
QgsGeometryMap mChangedGeometries
Changed geometries which are not commited.
int translateFeature(QgsFeatureId featureId, double dx, double dy)
Translates feature by dx, dy.
bool moveVertex(double x, double y, QgsFeatureId atFeatureId, int atVertex)
Moves the vertex at the given position number, ring and item (first number is index 0)...
virtual QString storageType() const
Returns the permanent storage type for this layer as a friendly name.
void triggerRepaint()
Will advice the map canvas (and any other interested party) that this layer requires to be repainted...
virtual long featureCount() const =0
Number of features in the layer.
QgsVectorLayer(QString path=QString::null, QString baseName=QString::null, QString providerLib=QString::null, bool loadDefaultStyleFlag=true)
Constructor - creates a vector layer.
This class wraps a request for features to a vector layer (or directly its vector data provider)...
int pendingFeatureCount()
returns feature count after commit
QList< int > QgsAttributeList
AttributeEditorType type() const
void destroyEditCommand()
Destroy active command and reverts all changes in it.
Q_DECL_DEPRECATED bool changeAttributeValue(QgsFeatureId fid, int field, QVariant value, bool emitSignal)
Changes an attribute value (but does not commit it)
const QgsAttributes & attributes() const
bool scaleBasedVisibility() const
void writeCustomProperties(QDomNode &layerNode, QDomDocument &doc) const
Write custom properties to project file.
const QString displayField() const
Returns the primary display field name used in the identify results dialog.
int count() const
Return number of items.
bool setReadOnly(bool readonly=true)
Make layer read-only (editing disabled) or not.
bool changeGeometry(QgsFeatureId fid, QgsGeometry *geom)
change feature's geometry
virtual bool isModified() const
Returns true if the provider has been modified since the last commit.
QGis::GeometryType geometryType() const
Returns point, line or polygon.
QString labelField(int attr) const
label field
QgsFeatureIds mDeletedFeatureIds
Deleted feature IDs which are not commited.
int afterVertexNr
The index of the vertex after snappedVertex or -1 if no such vertex.
Encapsulate a field in an attribute table or data source.
virtual bool importNamedStyle(QDomDocument &doc, QString &errorMsg)
Import the properties of this layer from a QDomDocument.
void featureAdded(QgsFeatureId fid)
static QgsFeatureRendererV2 * defaultRenderer(QGis::GeometryType geomType)
return a new renderer - used by default in vector layers
void setFeatureBlendMode(const QPainter::CompositionMode &blendMode)
Write blend mode for features.
void rendererChanged()
Signal emitted when renderer is changed.
void updateFields(QgsFields &flds)
Adds fields with the expressions buffered in this object to a QgsFields object.
virtual QGis::WkbType geometryType() const =0
Get feature type.
QString attributeAlias(int attributeIndex) const
Returns the alias of an attribute name or an empty string if there is no alias.
fast access to features using their ID
void readXML(const QDomNode &node)
Reads the renderer configuration from an XML file.
QgsFeatureId snappedAtGeometry
Index of the snapped geometry.
bool mValid
Indicates if the layer is valid and can be drawn.
bool useRenderingOptimization() const
Returns true if the rendering optimization (geometry simplification) can be executed.
void editingStarted()
Is emitted, when editing on this layer has started.
static void drawVertexMarker(double x, double y, QPainter &p, QgsVectorLayer::VertexMarkerType type, int vertexSize)
Draws a vertex symbol at (screen) coordinates x, y.
bool addFeatures(QgsFeatureList features, bool makeSelected=true)
Insert a copy of the given features into the layer (but does not commit it)
A class to represent a point.
QList< QgsRelation > referencingRelations(QgsVectorLayer *layer=0, int fieldIdx=-2) const
Get all relations where the specified layer (and field) is the referencing part (i.e.
void writeXML(QDomNode &label_node, QDomDocument &document) const
Writes the contents of the renderer to a configuration file.
void removeJoin(const QString &joinLayerId)
Removes a vector layer join.
void endEditCommand()
Finish edit command and add it to undo/redo stack.
virtual bool commitChanges(QStringList &commitErrors)
Attempts to commit any changes to disk.
void committedAttributeValuesChanges(const QString &layerId, const QgsChangedAttributesMap &changedAttributesValues)
virtual bool deleteAttribute(int attr)
delete an attribute field (but does not commit it)
const QStringList & commitErrors()
int indexFromName(const QString &name) const
Look up field's index from name. Returns -1 on error.
bool labelOnTop(int idx)
label widget on top
void invalidateSymbolCountedFlag()
bool deleteSelectedFeatures(int *deletedCount=0)
Deletes the selected features.
QgsPoint beforeVertex
The layer coordinates of the vertex before snappedVertex.
bool forceLocalOptimization() const
Gets where the simplification executes, after fetch the geometries from provider, or when supported...
Class for storing the component parts of a PostgreSQL/RDBMS datasource URI.
QgsPoint afterVertex
The layer coordinates of the vertex after snappedVertex.
int addTopologicalPoints(QgsGeometry *geom)
Adds topological points for every vertex of the geometry.
void editCommandDestroyed()
Signal emitted, whan an edit command is destroyed.
bool isGeosEqual(QgsGeometry &)
compare geometries using GEOS
void setMaximumScale(float maximumScale)
Sets the maximum scale at which the layer should be simplified.
virtual void reload() override
Synchronises with changes in the datasource.
void setEditorWidgetV2Config(int attrIdx, const QgsEditorWidgetConfig &config)
Set the editor widget config for a field.
bool countSymbolFeatures(bool showProgress=true)
Count features for symbols.
A class to render labels.
static QgsMapLayerLegend * defaultVectorLegend(QgsVectorLayer *vl)
Create new legend implementation for vector layer.
A registry / canonical manager of data providers.
void setProviderEncoding(const QString &encoding)
Sets the textencoding of the data provider.
virtual bool isReadOnly() const
Returns true if the provider is in read-only mode.
virtual QString loadNamedStyle(const QString &theURI, bool &theResultFlag, bool loadFromLocalDb)
Load a named style from file/local db/datasource db.
QgsAttributeEditorElement * attributeEditorElementFromDomElement(QDomElement &elem, QObject *parent)
convert a saved attribute editor element into a AttributeEditor structure as it's used internally...
Implementation of threaded rendering for vector layers.
int layerTransparency() const
Read transparency for layer.
static QPainter::CompositionMode getCompositionMode(const QgsMapRenderer::BlendMode &blendMode)
Returns a QPainter::CompositionMode corresponding to a BlendMode.
QgsFeatureIterator selectedFeaturesIterator(QgsFeatureRequest request=QgsFeatureRequest())
Get an iterator of the selected features.
QLibrary * providerLibrary(const QString &providerKey) const
int snappedVertexNr
The vertex index of snappedVertex or -1 if no such vertex number (e.g.
#define Q_NOWARN_DEPRECATED_POP
bool snapPoint(QgsPoint &point, double tolerance)
Snaps a point to the closest vertex if there is one within the snapping tolerance.
void setEditorWidgetV2(int attrIdx, const QString &widgetType)
Set the editor widget type for a field.
void addRequiredFields(QgsAttributeList &fields) const
add vector of required fields to existing list of fields
Q_DECL_DEPRECATED void setEditType(int idx, EditType edit)
Get edit type.
virtual void exportNamedStyle(QDomDocument &doc, QString &errorMsg)
Export the properties of this layer as named style in a QDomDocument.
bool updateFeature(QgsFeature &f)
Updates an existing feature.
void selectionChanged()
This signal is emitted when selection was changed.
bool insertVertex(double x, double y, QgsFeatureId atFeatureId, int beforeVertex)
Insert a new vertex before the given vertex number, in the given ring, item (first number is index 0)...
virtual bool render() override
Do the rendering (based on data stored in the class)
QString providerType() const
Return the provider type for this layer.
void featureBlendModeChanged(const QPainter::CompositionMode &blendMode)
Signal emitted when setFeatureBlendMode() is called.
QgsRectangle boundingBox()
Returns the bounding box of this feature.
int addRing(const QList< QgsPoint > &ring, QgsFeatureId *featureId=0)
Adds a ring to polygon/multipolygon features.
bool hasGeometryType() const
Returns true if this is a geometry layer and false in case of NoGeometry (table only) or UnknownGeome...
void attributeAdded(int idx)
Will be emitted, when a new attribute has been added to this vector layer.
virtual long featureCount() const
Number of features in the layer.
Q_DECL_DEPRECATED QSize widgetSize(int idx)
Access widget size for photo and webview widget.
Contains information about the context of a rendering operation.
void setMaxScale(float theMaxScale)
Accessor and mutator for the maximum scale member.
Buffers information about expression fields for a vector layer.
QString getStyleById_t(const QString &uri, QString styleID, QString &errCause)
virtual QDomElement toDomElement(QDomDocument &doc) const =0
virtual const QgsFields & fields() const =0
Return a map of indexes with field names for this layer.
void editCommandStarted(const QString &text)
Signal emitted when a new edit command has been started.
QString loadStyle_t(const QString &uri, QString &errCause)
QVariant attribute(const QString &name) const
Lookup attribute value from attribute name.
QgsAttributeList pendingAllAttributesList()
returns list of attributes
virtual QgsRectangle extent()=0
Get the extent of the layer.
QMap< QgsFeatureId, QgsAttributeMap > QgsChangedAttributesMap
void setAnnotationForm(const QString &ui)
set annotation form for layer
QString mDataSource
data source description string, varies by layer type
virtual QString loadDefaultStyle(bool &theResultFlag)
Retrieve the default style for this layer if one exists (either as a .qml file on disk or as a record...
static Q_DECL_DEPRECATED const QString convertEditType(QgsVectorLayer::EditType editType, QgsEditorWidgetConfig &cfg, QgsVectorLayer *vl, const QString &name, const QDomElement &editTypeElement=QDomElement())
void setSelectedFeatures(const QgsFeatureIds &ids)
Change selection to the new set of features.
void writeXml(QDomNode &layer_node, QDomDocument &document) const
Saves mVectorJoins to xml under the layer node.
This class manages a set of relations between layers.
static QgsFeatureRendererV2 * load(QDomElement &symbologyElem)
create a renderer from XML element
const QString & typeName() const
Gets the field type.
virtual bool setSubsetString(QString subset)
Set the string (typically sql) used to define a subset of the layer.
virtual void reloadData()
Reloads the data from the source.
void beforeModifiedCheck() const
Is emitted, when layer is checked for modifications.
virtual QVariant minimumValue(int index)
Returns the minimum value of an attribute.
void setEditForm(QString ui)
set edit form
Q_DECL_DEPRECATED RangeData range(int idx)
Access range widget config data.
virtual bool isValid()=0
Returns true if this is a valid layer.
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)...
void updateFields(QgsFields &fields)
Updates field map with joined attributes.
void repaintRequested()
By emitting this signal the layer tells that either appearance or content have been changed and any v...
void committedAttributesAdded(const QString &layerId, const QList< QgsField > &addedAttributes)
void readXml(const QDomNode &layer_node)
Reads expressions from project file.
void attributeValueChanged(QgsFeatureId fid, int idx, const QVariant &)
static QgsProject * instance()
access to canonical QgsProject instance
QgsPoint snappedVertex
The coordinates of the snapping result.
Q_DECL_DEPRECATED void setCheckedState(int idx, QString checked, QString notChecked)
Set string representing 'true' for a checkbox.
void removeExpression(int index)
Remove an expression from the buffer.
Class for storing a coordinate reference system (CRS)
void writeXML(QDomElement &layerElem, QDomDocument &doc, const QgsVectorLayer *layer) const
int length() const
Gets the length of the field.
friend class QgsVectorLayerEditBuffer
QgsLabel * label()
Get the label object associated with this layer.
int size() const
Return number of items.
virtual QString description() const =0
return description
bool hasLabelsEnabled() const
Label is on.
QList< QgsAttributeEditorElement * > & attributeEditorElements()
Returns a list of tabs holding groups and fields.
virtual Q_DECL_DEPRECATED QDomElement writeSld(QDomDocument &doc, const QgsVectorLayer &layer) const
create the SLD UserStyle element following the SLD v1.1 specs
SimplifyHints simplifyHints() const
Gets the simplification hints of the vector layer managed.
FieldOrigin fieldOrigin(int fieldIdx) const
Get field's origin (value from an enumeration)
virtual void readXML(const QDomElement &elem, const QgsVectorLayer *layer)=0
const QMap< QString, QgsMapLayer * > & mapLayers()
Retrieve the mapLayers collection (mainly intended for use by projection)
void recalculateExtents()
This is used to send a request that any mapcanvas using this layer update its extents.
virtual QDomElement toDomElement(QDomDocument &doc) const override
const QString & comment() const
Returns the field comment.
void setFieldEditable(int idx, bool editable)
set edit widget editable
virtual bool deleteFeature(QgsFeatureId fid)
delete a feature from the layer (but does not commit it)
bool readSld(const QDomNode &node, QString &errorMessage) override
static QColor colorFromOgcFill(const QDomElement &fillElement)
Parse XML with OGC fill into QColor.
virtual bool changeAttributeValue(QgsFeatureId fid, int field, const QVariant &newValue, const QVariant &oldValue=QVariant())
changed an attribute value (but does not commit it)
Base class for utility classes that encapsulate information necessary for rendering of map layers...
void addExpressionField(const QString &exp, const QgsField &fld)
Add a new field which is calculated by the expression specified.
void setLayerName(const QString &name)
Set the display name of the layer.
const QgsCoordinateReferenceSystem & crs() const
Returns layer's spatial reference system.
allows deletion of features
QgsMapLayer * mapLayer(QString theLayerId)
Retrieve a pointer to a loaded layer by id.
virtual QString loadNamedStyle(const QString &theURI, bool &theResultFlag)
Retrieve a named style for this layer if one exists (either as a .qml file on disk or as a record in ...
bool writeSymbology(QDomNode &node, QDomDocument &doc, QString &errorMessage) const override
Write the symbology for the layer into the docment provided.
void(*)() cast_to_fptr(void *p)
static QgsMapRenderer::BlendMode getBlendModeEnum(const QPainter::CompositionMode &blendMode)
Returns a BlendMode corresponding to a QPainter::CompositionMode.
QString dataComment() const
Returns a comment for the data in the layer.
void setMinScale(float theMinScale)
Accessor and mutator for the minimum scale member.
Custom exception class for Coordinate Reference System related exceptions.
QUndoStack * undoStack()
Return pointer to layer's undo stack.
const QgsFields & pendingFields() const
returns field list in the to-be-committed state
void setLabelOnTop(int idx, bool onTop)
label widget on top
QString metadata() override
Obtain Metadata for this layer.
QgsVectorDataProvider * dataProvider()
Returns the data provider.
virtual void addChildElement(QgsAttributeEditorElement *widget)
int splitParts(const QList< QgsPoint > &splitLine, bool topologicalEditing=false)
Splits parts cut by the given line.
void normalize()
Normalize the rectangle so it has non-negative width/height.
QString editFormInit()
get python function for edit form initialization
float maximumScale() const
Gets the maximum scale at which the layer should be simplified.
bool nextFeature(QgsFeature &f)
FeatureFormSuppress
Types of feature form suppression after feature creation.
void setCoordinateSystem()
Setup the coordinate system transformation for the layer.
This is the base class for vector data providers.
void attributeDeleted(int idx)
Will be emitted, when an attribute has been deleted from this vector layer.
Geometry is not required. It may still be returned if e.g. required for a filter condition.
virtual bool readXml(const QDomNode &layer_node) override
reads vector layer specific state from project file Dom node.
void setLegend(QgsMapLayerLegend *legend)
Assign a legend controller to the map layer.
QgsFeatureMap mAddedFeatures
New features which are not commited.
double width() const
Width of the rectangle.
void committedGeometriesChanges(const QString &layerId, const QgsGeometryMap &changedGeometries)
QgsFeatureIds allFeatureIds()
Get all feature Ids.
QgsAttributeList pendingPkAttributesList()
returns list of attribute making up the primary key
static QgsFeatureRendererV2 * readOldRenderer(const QDomNode &layerNode, QGis::GeometryType geomType)
Read old renderer definition from XML and create matching new renderer.
void updateFields(QgsFields &fields)
virtual QgsRectangle extent()
Return the extent of the layer.
Represents a vector layer which manages a vector based data sets.
int fieldNameIndex(const QString &fieldName) const
Returns the index of a field name or -1 if the field does not exist.
bool addAttribute(const QgsField &field)
add an attribute field (but does not commit it) returns true if the field was added ...
virtual bool isModified() const
Returns true if the provider has been modified since the last commit.
QString toString(bool automaticPrecision=false) const
returns string representation of form xmin,ymin xmax,ymax
QList< QPair< QString, QgsSymbolV2 * > > QgsLegendSymbolList
int splitParts(const QList< QgsPoint > &splitLine, bool topologicalEditing=false)
Splits parts cut by the given line.
void modifySelection(QgsFeatureIds selectIds, QgsFeatureIds deselectIds)
Modifies the current selection on this layer.
field is calculated from an expression
int selectedFeatureCount()
The number of features that are selected in this layer.
void updatedFields()
Is emitted, whenever the fields available from this layer have been changed.
QgsFeatureRequest & setFlags(Flags flags)
Set flags that affect how features will be fetched.
QgsRelationManager * relationManager() const
double xMinimum() const
Get the x minimum value (left side of rectangle)
const QgsVectorLayer * layer
Layer where the snap occurred.
QString joinLayerId
Source layer.
void layerModified()
This signal is emitted when modifications has been done on layer.
QgsAttributeList mDeletedAttributeIds
deleted attributes fields which are not commited.
QString evalErrorString() const
Returns evaluation error.
QgsAttributeList allAttributesList() const
Utility function to get list of attribute indexes.
void drawLabels(QgsRenderContext &rendererContext) override
Draws the layer labels using coordinate transformation.
bool readXML(const QDomNode &layer_node)
Reads the actions in in XML format.
virtual bool changeGeometry(QgsFeatureId fid, QgsGeometry *geom)
change feature's geometry
int beforeVertexNr
The index of the vertex before snappedVertex or -1 if no such vertex.
void createJoinCaches()
Caches joined attributes if required (and not already done)
virtual void exportSldStyle(QDomDocument &doc, QString &errorMsg)
Export the properties of this layer as SLD style in a QDomDocument.
virtual QString dataSourceUri() const
Get the data source specification.
int splitFeatures(const QList< QgsPoint > &splitLine, bool topologicalEditing=false)
Splits features cut by the given line.
void setDisplayField(QString fldName="")
Set the primary display field to be used in the identify results dialog.
const CORE_EXPORT QString GEO_EPSG_CRS_AUTHID
Geographic coord sys from EPSG authority.
virtual QList< QgsAttributeEditorElement * > findElements(AttributeEditorType type) const
double height() const
Height of the rectangle.
QString toProj4() const
Get the Proj Proj4 string representation of this srs.
void enableLabels(bool on)
Set labels on.
void setThreshold(float threshold)
Sets the simplification threshold of the vector layer managed.
void addAttributeEditorWidget(QgsAttributeEditorElement *data)
Adds a tab (for the attribute editor form) holding groups and fields.
QgsRectangle boundingBoxOfSelected()
Returns the bounding box of the selected features.
bool saveStyle_t(const QString &uri, const QString &qmlStyle, const QString &sldStyle, const QString &styleName, const QString &styleDescription, const QString &uiFileContent, bool useAsDefault, QString &errCause)
QString storageType() const
Returns the permanent storage type for this layer as a friendly name.
int listStyles_t(const QString &uri, QStringList &ids, QStringList &names, QStringList &descriptions, QString &errCause)