28 #include <QPainterPath>
30 #include <QProgressDialog>
77 #ifdef TESTPROVIDERLIB
83 const QString& qmlStyle,
84 const QString& sldStyle,
85 const QString& styleName,
86 const QString& styleDescription,
87 const QString& uiFileContent,
101 QStringList &descriptions,
115 bool loadDefaultStyleFlag )
116 :
QgsMapLayer( VectorLayer, baseName, vectorLayerPath )
117 , mUpdateThreshold( 0 )
118 , mDataProvider( NULL )
119 , mProviderKey( providerKey )
121 , mRendererV2( NULL )
124 , mLabelFontNotFoundNotified( false )
125 , mFeatureBlendMode( QPainter::CompositionMode_SourceOver )
126 , mLayerTransparency( 0 )
127 , mVertexMarkerOnlyForSelection( false )
131 , mDiagramRenderer( 0 )
132 , mDiagramLayerSettings( 0 )
133 , mValidExtent( false )
134 , mSymbolFeatureCounted( false )
135 , mCurrentRendererContext( 0 )
152 bool defaultLoadedFlag =
false;
153 if ( loadDefaultStyleFlag )
249 QString idxName =
"";
252 if ( !fldName.isEmpty() )
259 int fieldsSize = fields.
size();
261 for (
int idx = 0; idx < fields.
count(); ++idx )
263 QString fldName = fields[idx].name();
264 QgsDebugMsg(
"Checking field " + fldName +
" of " + QString::number( fieldsSize ) +
" total" );
270 if ( fldName.indexOf(
"name", 0, Qt::CaseInsensitive ) > -1 )
272 if ( idxName.isEmpty() )
277 if ( fldName.indexOf(
"descrip", 0, Qt::CaseInsensitive ) > -1 )
279 if ( idxName.isEmpty() )
284 if ( fldName.indexOf(
"id", 0, Qt::CaseInsensitive ) > -1 )
286 if ( idxId.isEmpty() )
294 if ( fieldsSize == 0 )
297 if ( idxName.length() > 0 )
303 if ( idxId.length() > 0 )
335 attributes.append( attrNum );
343 QgsDebugMsg(
"Selecting features based on view extent" );
352 .setFilterRect( rendererContext.
extent() )
353 .setSubsetOfAttributes( attributes ) );
377 QgsDebugMsg( QString(
"Total features processed %1" ).arg( featureCount ) );
396 bool vertexMarkerOnlyForSelection = settings.value(
"/qgis/digitizing/marker_only_for_selected",
false ).toBool();
410 #ifndef Q_WS_MAC //MH: disable this on Mac for now to avoid problems with resizing
419 qApp->processEvents();
421 else if ( featureCount % 1000 == 0 )
424 qApp->processEvents();
437 bool drawMarker = (
mEditBuffer && ( !vertexMarkerOnlyForSelection || sel ) );
464 QgsDebugMsg( QString(
"Failed to transform a point while drawing a feature with ID '%1'. Ignoring this feature. %2" )
465 .arg( fet.
id() ).arg( cse.
what() ) );
477 QgsDebugMsg( QString(
"Total features processed %1" ).arg( featureCount ) );
486 QHash< QgsSymbolV2*, QList<QgsFeature> > features;
489 bool vertexMarkerOnlyForSelection = settings.value(
"/qgis/digitizing/marker_only_for_selected",
false ).toBool();
516 if ( featureCount % 1000 == 0 )
518 qApp->processEvents();
527 if ( !features.contains( sym ) )
529 features.insert( sym, QList<QgsFeature>() );
531 features[sym].append( fet );
559 for (
int i = 0; i < symbols.count(); i++ )
565 if ( level < 0 || level >= 1000 )
568 while ( level >= levels.count() )
570 levels[level].append( item );
575 for (
int l = 0; l < levels.count(); l++ )
578 for (
int i = 0; i < level.count(); i++ )
581 if ( !features.contains( item.
symbol() ) )
586 int layer = item.
layer();
587 QList<QgsFeature>& lst = features[item.
symbol()];
588 QList<QgsFeature>::iterator fit;
592 for ( fit = lst.begin(); fit != lst.end(); ++fit )
600 if ( featureCount % 1000 == 0 )
602 qApp->processEvents();
607 bool drawMarker = (
mEditBuffer && ( !vertexMarkerOnlyForSelection || sel ) );
616 QgsDebugMsg( QString(
"Failed to transform a point while drawing a feature with ID '%1'. Ignoring this feature. %2" )
617 .arg( fet.
id() ).arg( cse.
what() ) );
675 attributes.append( attrNum );
676 QgsDebugMsg(
"attrs: " + attrName +
" - " + QString::number( attrNum ) );
679 bool labeling =
false;
687 .setFilterRect( rendererContext.
extent() )
688 .setSubsetOfAttributes( attributes ) );
703 p.setPen( QColor( 50, 100, 120, 200 ) );
704 p.setBrush( QColor( 200, 200, 210, 120 ) );
705 p.drawEllipse( x - m, y - m, m * 2 + 1, m * 2 + 1 );
709 p.setPen( QColor( 255, 0, 0 ) );
710 p.drawLine( x - m, y + m, x + m, y - m );
711 p.drawLine( x - m, y - m, x + m, y + m );
754 .setFilterRect( rect )
766 if ( !addToSelection )
779 if ( intersectingIds.count() > 0 )
781 QgsDebugMsg(
"Trying to select and deselect the same item at the same time. Unsure what to do. Selecting dubious items." );
837 .setFilterRect( rect )
849 deselectIds << fet.
id();
853 selectIds << fet.
id();
932 QgsDebugMsg( QString(
"Data Provider Geometry type is not recognised, is %1" ).arg( type ) );
944 QgsDebugMsg(
"WARNING: This code should never be reached. Problems may occur..." );
1004 if ( retval.
width() == 0.0 || retval.
height() == 0.0 )
1013 retval.
set( -1.0, -1.0, 1.0, 1.0 );
1054 QgsLegendSymbolList::const_iterator symbolIt = symbolList.constBegin();
1056 for ( ; symbolIt != symbolList.constEnd(); ++symbolIt )
1062 QProgressDialog progressDialog(
tr(
"Updating feature count for layer %1" ).arg(
name() ),
tr(
"Abort" ), 0, nFeatures );
1063 progressDialog.setWindowModality( Qt::WindowModal );
1064 int featuresCounted = 0;
1077 for ( QgsSymbolV2List::iterator symbolIt = featureSymbolList.begin(); symbolIt != featureSymbolList.end(); ++symbolIt )
1085 if ( featuresCounted % 50 == 0 )
1087 if ( featuresCounted > nFeatures )
1089 progressDialog.setMaximum( 0 );
1091 progressDialog.setValue( featuresCounted );
1092 if ( progressDialog.wasCanceled() )
1102 progressDialog.setValue( nFeatures );
1224 Q_UNUSED( alsoUpdateExtent );
1248 QgsDebugMsg( QString(
"feature %1 could not be retrieved" ).arg( f.
id() ) );
1256 QgsDebugMsg( QString(
"geometry of feature %1 could not be changed." ).arg( f.
id() ) );
1264 for (
int attr = 0; attr < fa.count(); ++attr )
1266 if ( fa[attr] != ca[attr] )
1270 QgsDebugMsg( QString(
"attribute %1 of feature %2 could not be changed." ).arg( attr ).arg( f.
id() ) );
1286 return utils.
insertVertex( x, y, atFeatureId, beforeVertex );
1296 return utils.
moveVertex( x, y, atFeatureId, atVertex );
1386 return utils.
splitFeatures( splitLine, topologicalEditing );
1394 int returnValue = 0;
1407 .setFilterRect( geomBBox )
1414 if ( ignoreFeatures.contains( f.
id() ) )
1521 QDomNode pkeyNode = layer_node.namedItem(
"provider" );
1523 if ( pkeyNode.isNull() )
1529 QDomElement pkeyElt = pkeyNode.toElement();
1553 QDomElement pkeyElem = pkeyNode.toElement();
1554 if ( !pkeyElem.isNull() )
1556 QString encodingString = pkeyElem.attribute(
"encoding" );
1557 if ( !encodingString.isEmpty() )
1573 QDomNode prevExpNode = layer_node.namedItem(
"previewExpression" );
1575 if ( prevExpNode.isNull() )
1581 QDomElement prevExpElem = prevExpNode.toElement();
1611 QgsDebugMsg(
"Instantiated the data provider plugin" );
1645 QRegExp reg(
"\"[^\"]+\"\\.\"([^\"]+)\"( \\([^)]+\\))?" );
1646 if ( reg.indexIn(
name() ) >= 0 )
1648 QStringList stuff = reg.capturedTexts();
1649 QString lName = stuff[1];
1653 QMap<QString, QgsMapLayer*>::const_iterator it;
1654 for ( it = layers.constBegin(); it != layers.constEnd() && ( *it )->name() != lName; it++ )
1657 if ( it != layers.constEnd() && stuff.size() > 2 )
1659 lName +=
"." + stuff[2].mid( 2, stuff[2].length() - 3 );
1662 if ( !lName.isEmpty() )
1676 else if ( provider ==
"ogr" )
1709 QDomDocument & document )
1713 QDomElement mapLayerNode = layer_node.toElement();
1715 if ( mapLayerNode.isNull() || (
"maplayer" != mapLayerNode.nodeName() ) )
1721 mapLayerNode.setAttribute(
"type",
"vector" );
1729 QDomElement provider = document.createElement(
"provider" );
1731 QDomText providerText = document.createTextNode(
providerType() );
1732 provider.appendChild( providerText );
1733 layer_node.appendChild( provider );
1737 QDomElement prevExpElem = document.createElement(
"previewExpression" );
1739 prevExpElem.appendChild( prevExpText );
1740 layer_node.appendChild( prevExpElem );
1752 Q_UNUSED( errorMessage );
1757 if ( !rendererElement.isNull() )
1775 QDomNode displayFieldNode = node.namedItem(
"displayfield" );
1776 if ( !displayFieldNode.isNull() )
1778 QDomElement e = displayFieldNode.toElement();
1783 QDomNode blendModeNode = node.namedItem(
"blendMode" );
1784 if ( !blendModeNode.isNull() )
1786 QDomElement e = blendModeNode.toElement();
1791 QDomNode featureBlendModeNode = node.namedItem(
"featureBlendMode" );
1792 if ( !featureBlendModeNode.isNull() )
1794 QDomElement e = featureBlendModeNode.toElement();
1799 QDomNode layerTransparencyNode = node.namedItem(
"layerTransparency" );
1800 if ( !layerTransparencyNode.isNull() )
1802 QDomElement e = layerTransparencyNode.toElement();
1807 QDomElement e = node.toElement();
1816 QDomNode labelnode = node.namedItem(
"label" );
1817 QDomElement element = labelnode.toElement();
1819 if ( hasLabelsEnabled < 1 )
1828 QDomNode labelattributesnode = node.namedItem(
"labelattributes" );
1830 if ( !labelattributesnode.isNull() )
1838 QDomElement singleCatDiagramElem = node.firstChildElement(
"SingleCategoryDiagramRenderer" );
1839 if ( !singleCatDiagramElem.isNull() )
1844 QDomElement linearDiagramElem = node.firstChildElement(
"LinearlyInterpolatedDiagramRenderer" );
1845 if ( !linearDiagramElem.isNull() )
1853 QDomElement diagramSettingsElem = node.firstChildElement(
"DiagramLayerSettings" );
1854 if ( !diagramSettingsElem.isNull() )
1866 QDomNode editTypesNode = node.namedItem(
"edittypes" );
1867 if ( !editTypesNode.isNull() )
1869 QDomNodeList editTypeNodes = editTypesNode.childNodes();
1871 for (
int i = 0; i < editTypeNodes.size(); i++ )
1873 QDomNode editTypeNode = editTypeNodes.at( i );
1874 QDomElement editTypeElement = editTypeNode.toElement();
1876 QString
name = editTypeElement.attribute(
"name" );
1883 int editable = editTypeElement.attribute(
"editable" ,
"1" ).toInt();
1886 int labelOnTop = editTypeElement.attribute(
"labelontop" ,
"0" ).toInt();
1892 if ( editTypeNode.hasChildNodes() )
1894 mValueMaps.insert( name, QMap<QString, QVariant>() );
1896 QDomNodeList valueMapNodes = editTypeNode.childNodes();
1897 for (
int j = 0; j < valueMapNodes.size(); j++ )
1899 QDomElement value = valueMapNodes.at( j ).toElement();
1900 mValueMaps[
name ].insert( value.attribute(
"key" ), value.attribute(
"value" ) );
1909 QVariant
min = editTypeElement.attribute(
"min" );
1910 QVariant
max = editTypeElement.attribute(
"max" );
1911 QVariant step = editTypeElement.attribute(
"step" );
1918 mCheckedStates[
name ] = QPair<QString, QString>( editTypeElement.attribute(
"checked" ), editTypeElement.attribute(
"unchecked" ) );
1923 QString
id = editTypeElement.attribute(
"layer" );
1924 QString key = editTypeElement.attribute(
"key" );
1925 QString value = editTypeElement.attribute(
"value" );
1926 bool allowNull = editTypeElement.attribute(
"allowNull" ) ==
"true";
1927 bool orderByValue = editTypeElement.attribute(
"orderByValue" ) ==
"true";
1928 bool allowMulti = editTypeElement.attribute(
"allowMulti",
"false" ) ==
"true";
1930 QString filterExpression;
1931 if ( editTypeElement.hasAttribute(
"filterAttributeColumn" ) &&
1932 editTypeElement.hasAttribute(
"filterAttributeValue" ) )
1934 filterExpression = QString(
"\"%1\"='%2'" )
1935 .arg( editTypeElement.attribute(
"filterAttributeColumn" ) )
1936 .arg( editTypeElement.attribute(
"filterAttributeValue" ) );
1940 filterExpression = editTypeElement.attribute(
"filterExpression", QString::null );
1953 mWidgetSize[
name ] = QSize( editTypeElement.attribute(
"widgetWidth" ).toInt(), editTypeElement.attribute(
"widgetHeight" ).toInt() );
1972 QDomNode editFormNode = node.namedItem(
"editform" );
1973 if ( !editFormNode.isNull() )
1975 QDomElement e = editFormNode.toElement();
1979 QDomNode editFormInitNode = node.namedItem(
"editforminit" );
1980 if ( !editFormInitNode.isNull() )
1985 QDomNode annotationFormNode = node.namedItem(
"annotationform" );
1986 if ( !annotationFormNode.isNull() )
1988 QDomElement e = annotationFormNode.toElement();
1993 QDomNode aliasesNode = node.namedItem(
"aliases" );
1994 if ( !aliasesNode.isNull() )
1996 QDomElement aliasElem;
1999 QDomNodeList aliasNodeList = aliasesNode.toElement().elementsByTagName(
"alias" );
2000 for (
int i = 0; i < aliasNodeList.size(); ++i )
2002 aliasElem = aliasNodeList.at( i ).toElement();
2005 if ( aliasElem.hasAttribute(
"field" ) )
2007 field = aliasElem.attribute(
"field" );
2011 int index = aliasElem.attribute(
"index" ).toInt();
2022 QDomNode editorLayoutNode = node.namedItem(
"editorlayout" );
2023 if ( editorLayoutNode.isNull() )
2029 if ( editorLayoutNode.toElement().text() ==
"uifilelayout" )
2033 else if ( editorLayoutNode.toElement().text() ==
"tablayout" )
2045 QDomNode excludeWMSNode = node.namedItem(
"excludeAttributesWMS" );
2046 if ( !excludeWMSNode.isNull() )
2048 QDomNodeList attributeNodeList = excludeWMSNode.toElement().elementsByTagName(
"attribute" );
2049 for (
int i = 0; i < attributeNodeList.size(); ++i )
2056 QDomNode excludeWFSNode = node.namedItem(
"excludeAttributesWFS" );
2057 if ( !excludeWFSNode.isNull() )
2059 QDomNodeList attributeNodeList = excludeWFSNode.toElement().elementsByTagName(
"attribute" );
2060 for (
int i = 0; i < attributeNodeList.size(); ++i )
2068 QDomNode attributeEditorFormNode = node.namedItem(
"attributeEditorForm" );
2069 QDomNodeList attributeEditorFormNodeList = attributeEditorFormNode.toElement().childNodes();
2071 for (
int i = 0; i < attributeEditorFormNodeList.size(); i++ )
2073 QDomElement elem = attributeEditorFormNodeList.at( i ).toElement();
2085 if ( elem.tagName() ==
"attributeEditorContainer" )
2089 QDomNodeList childNodeList = elem.childNodes();
2091 for (
int i = 0; i < childNodeList.size(); i++ )
2093 QDomElement childElem = childNodeList.at( i ).toElement();
2098 newElement = container;
2100 else if ( elem.tagName() ==
"attributeEditorField" )
2102 QString
name = elem.attribute(
"name" );
2112 Q_UNUSED( errorMessage );
2113 QDomElement mapLayerNode = node.toElement();
2118 node.appendChild( rendererElement );
2122 mapLayerNode.setAttribute(
"minLabelScale", QString::number(
mLabel->
minScale() ) );
2123 mapLayerNode.setAttribute(
"maxLabelScale", QString::number(
mLabel->
maxScale() ) );
2129 QDomElement blendModeElem = doc.createElement(
"blendMode" );
2131 blendModeElem.appendChild( blendModeText );
2132 node.appendChild( blendModeElem );
2135 QDomElement featureBlendModeElem = doc.createElement(
"featureBlendMode" );
2137 featureBlendModeElem.appendChild( featureBlendModeText );
2138 node.appendChild( featureBlendModeElem );
2141 QDomElement layerTransparencyElem = doc.createElement(
"layerTransparency" );
2142 QDomText layerTransparencyText = doc.createTextNode( QString::number(
layerTransparency() ) );
2143 layerTransparencyElem.appendChild( layerTransparencyText );
2144 node.appendChild( layerTransparencyElem );
2147 QDomElement dField = doc.createElement(
"displayfield" );
2148 QDomText dFieldText = doc.createTextNode(
displayField() );
2149 dField.appendChild( dFieldText );
2150 node.appendChild( dField );
2153 QDomElement labelElem = doc.createElement(
"label" );
2154 QDomText labelText = doc.createTextNode(
"" );
2158 labelText.setData(
"1" );
2162 labelText.setData(
"0" );
2164 labelElem.appendChild( labelText );
2166 node.appendChild( labelElem );
2171 if ( fieldname !=
"" )
2173 dField = doc.createElement(
"labelfield" );
2174 dFieldText = doc.createTextNode( fieldname );
2175 dField.appendChild( dFieldText );
2176 node.appendChild( dField );
2192 QDomElement editTypesElement = doc.createElement(
"edittypes" );
2194 for ( QMap<QString, EditType>::const_iterator it =
mEditTypes.begin(); it !=
mEditTypes.end(); ++it )
2196 QDomElement editTypeElement = doc.createElement(
"edittype" );
2197 editTypeElement.setAttribute(
"name", it.key() );
2198 editTypeElement.setAttribute(
"type", it.value() );
2199 editTypeElement.setAttribute(
"editable",
mFieldEditables[ it.key()] ? 1 : 0 );
2200 editTypeElement.setAttribute(
"labelontop",
mLabelOnTop[ it.key()] ? 1 : 0 );
2207 const QMap<QString, QVariant> &map =
mValueMaps[ it.key()];
2209 for ( QMap<QString, QVariant>::const_iterator vmit = map.begin(); vmit != map.end(); vmit++ )
2211 QDomElement value = doc.createElement(
"valuepair" );
2212 value.setAttribute(
"key", vmit.key() );
2213 value.setAttribute(
"value", vmit.value().toString() );
2214 editTypeElement.appendChild( value );
2222 if (
mRanges.contains( it.key() ) )
2224 editTypeElement.setAttribute(
"min",
mRanges[ it.key()].mMin.toString() );
2225 editTypeElement.setAttribute(
"max",
mRanges[ it.key()].mMax.toString() );
2226 editTypeElement.setAttribute(
"step",
mRanges[ it.key()].mStep.toString() );
2233 editTypeElement.setAttribute(
"checked",
mCheckedStates[ it.key()].first );
2234 editTypeElement.setAttribute(
"unchecked",
mCheckedStates[ it.key()].second );
2242 editTypeElement.setAttribute(
"layer", data.
mLayer );
2243 editTypeElement.setAttribute(
"key", data.
mKey );
2244 editTypeElement.setAttribute(
"value", data.
mValue );
2245 editTypeElement.setAttribute(
"allowNull", data.
mAllowNull ?
"true" :
"false" );
2246 editTypeElement.setAttribute(
"orderByValue", data.
mOrderByValue ?
"true" :
"false" );
2247 editTypeElement.setAttribute(
"allowMulti", data.
mAllowMulti ?
"true" :
"false" );
2254 editTypeElement.setAttribute(
"dateFormat",
mDateFormats[ it.key()] );
2259 editTypeElement.setAttribute(
"widgetWidth",
mWidgetSize[ it.key()].width() );
2260 editTypeElement.setAttribute(
"widgetHeight",
mWidgetSize[ it.key()].height() );
2277 editTypesElement.appendChild( editTypeElement );
2280 node.appendChild( editTypesElement );
2283 QDomElement efField = doc.createElement(
"editform" );
2285 efField.appendChild( efText );
2286 node.appendChild( efField );
2288 QDomElement efiField = doc.createElement(
"editforminit" );
2290 efiField.appendChild( efiText );
2291 node.appendChild( efiField );
2293 QDomElement afField = doc.createElement(
"annotationform" );
2295 afField.appendChild( afText );
2296 node.appendChild( afField );
2299 QDomElement editorLayoutElem = doc.createElement(
"editorlayout" );
2303 editorLayoutElem.appendChild( doc.createTextNode(
"uifilelayout" ) );
2307 editorLayoutElem.appendChild( doc.createTextNode(
"tablayout" ) );
2312 editorLayoutElem.appendChild( doc.createTextNode(
"generatedlayout" ) );
2316 node.appendChild( editorLayoutElem );
2321 QDomElement aliasElem = doc.createElement(
"aliases" );
2329 QDomElement aliasEntryElem = doc.createElement(
"alias" );
2330 aliasEntryElem.setAttribute(
"field", a_it.key() );
2331 aliasEntryElem.setAttribute(
"index", idx );
2332 aliasEntryElem.setAttribute(
"name", a_it.value() );
2333 aliasElem.appendChild( aliasEntryElem );
2335 node.appendChild( aliasElem );
2339 QDomElement excludeWMSElem = doc.createElement(
"excludeAttributesWMS" );
2343 QDomElement attrElem = doc.createElement(
"attribute" );
2344 QDomText attrText = doc.createTextNode( *attWMSIt );
2345 attrElem.appendChild( attrText );
2346 excludeWMSElem.appendChild( attrElem );
2348 node.appendChild( excludeWMSElem );
2351 QDomElement excludeWFSElem = doc.createElement(
"excludeAttributesWFS" );
2355 QDomElement attrElem = doc.createElement(
"attribute" );
2356 QDomText attrText = doc.createTextNode( *attWFSIt );
2357 attrElem.appendChild( attrText );
2358 excludeWFSElem.appendChild( attrElem );
2360 node.appendChild( excludeWFSElem );
2365 QDomElement tabsElem = doc.createElement(
"attributeEditorForm" );
2369 QDomElement attributeEditorWidgetElem = ( *it )->toDomElement( doc );
2370 tabsElem.appendChild( attributeEditorWidgetElem );
2373 node.appendChild( tabsElem );
2385 QDomElement nameElem = node.firstChildElement(
"Name" );
2386 if ( nameElem.isNull() )
2388 errorMessage =
"Warning: Name element not found within NamedLayer while it's required.";
2405 Q_UNUSED( errorMessage );
2408 QDomElement nameNode = doc.createElement(
"se:Name" );
2409 nameNode.appendChild( doc.createTextNode(
name() ) );
2410 node.appendChild( nameNode );
2435 Q_UNUSED( emitSignal );
2468 if ( attributeIndex < 0 || attributeIndex >=
pendingFields().count() )
2479 if ( displayName.isEmpty() )
2482 if ( attributeIndex >= 0 && attributeIndex < fields.
count() )
2484 displayName = fields[attributeIndex].name();
2500 bool deleted =
false;
2503 attrs = attrs.toSet().toList();
2505 qSort( attrs.begin(), attrs.end(), qGreater<int>() );
2507 foreach (
int attr, attrs )
2554 pkAttributesList << i;
2557 return pkAttributesList;
2707 for ( QgsFeatureList::iterator iter = features.begin(); iter != features.end(); ++iter )
2724 QMultiMap<double, QgsSnappingResult> snapResults;
2732 if ( snapResults.size() < 1 )
2737 QMultiMap<double, QgsSnappingResult>::const_iterator snap_it = snapResults.constBegin();
2738 point.
setX( snap_it.value().snappedVertex.x() );
2739 point.
setY( snap_it.value().snappedVertex.y() );
2745 QMultiMap<double, QgsSnappingResult>& snappingResults,
2756 QList<QgsFeature> featureList;
2757 QgsRectangle searchRect( startPoint.
x() - snappingTolerance, startPoint.
y() - snappingTolerance,
2758 startPoint.
x() + snappingTolerance, startPoint.
y() + snappingTolerance );
2759 double sqrSnappingTolerance = snappingTolerance * snappingTolerance;
2767 for ( QgsGeometryMap::iterator it = cachedGeometries.begin(); it != cachedGeometries.end() ; ++it )
2772 snapToGeometry( startPoint, it.key(), g, sqrSnappingTolerance, snappingResults, snap_to );
2782 .setFilterRect( searchRect )
2793 return n == 0 ? 2 : 0;
2799 double sqrSnappingTolerance,
2800 QMultiMap<double, QgsSnappingResult>& snappingResults,
2808 int atVertex, beforeVertex, afterVertex;
2809 double sqrDistVertexSnap, sqrDistSegmentSnap;
2816 snappedPoint = geom->
closestVertex( startPoint, atVertex, beforeVertex, afterVertex, sqrDistVertexSnap );
2817 if ( sqrDistVertexSnap < sqrSnappingTolerance )
2822 if ( beforeVertex != -1 )
2827 if ( afterVertex != -1 )
2832 snappingResultVertex.
layer =
this;
2833 snappingResults.insert( sqrt( sqrDistVertexSnap ), snappingResultVertex );
2841 sqrDistSegmentSnap = geom->
closestSegmentWithContext( startPoint, snappedPoint, afterVertex, NULL,
crs().geographicFlag() ? 1e-12 : 1e-8 );
2843 if ( sqrDistSegmentSnap < sqrSnappingTolerance )
2852 snappingResultSegment.
layer =
this;
2853 snappingResults.insert( sqrt( sqrDistSegmentSnap ), snappingResultSegment );
2869 QString markerTypeString = settings.value(
"/qgis/digitizing/marker_style",
"Cross" ).toString();
2870 if ( markerTypeString ==
"Cross" )
2874 else if ( markerTypeString ==
"SemiTransparentCircle" )
2887 return settings.value(
"/qgis/digitizing/marker_size", 3 ).toInt();
2894 QgsDebugMsg(
"----- Computing Coordinate System" );
2965 if ( idx >= 0 && idx < fields.
count() )
3009 static QMap< QString, QVariant > invalidMap;
3010 if ( idx < 0 || idx >= fields.
count() )
3012 QgsDebugMsg( QString(
"field %1 not found" ).arg( idx ) );
3015 QString fieldName = fields[idx].name();
3018 mValueMaps[fieldName] = QMap<QString, QVariant>();
3029 if ( idx < 0 || idx >= fields.
count() )
3031 QgsDebugMsg( QString(
"field %1 not found" ).arg( idx ) );
3032 return invalidRange;
3034 QString fieldName = fields[idx].name();
3036 if ( !
mRanges.contains( fieldName ) )
3046 QString fieldName = fields[idx].name();
3058 QString fieldName = fields[idx].name();
3069 if ( idx >= 0 && idx < fields.
count() )
3082 if ( idx >= 0 && idx < fields.
count() )
3083 return mLabelOnTop.value( fields[idx].name(), false );
3091 if ( idx >= 0 && idx < fields.
count() )
3098 if ( idx >= 0 && idx < fields.
count() )
3143 if ( idx >= 0 && idx < fields.
count() )
3153 return QPair<QString, QString>(
"1",
"0" );
3160 for (
int idx = 0; idx < theFields.
count(); ++idx )
3162 if ( QString::compare( theFields[idx].
name(), fieldName, Qt::CaseInsensitive ) == 0 )
3221 uniqueValues.clear();
3235 int sourceLayerIndex;
3258 .setSubsetOfAttributes( attList ) );
3261 QVariant currentValue;
3262 QHash<QString, QVariant> val;
3266 val.insert( currentValue.toString(), currentValue );
3267 if ( limit >= 0 && val.size() >= limit )
3273 uniqueValues = val.values();
3277 Q_ASSERT_X(
false,
"QgsVectorLayer::uniqueValues()",
"Unknown source of the field!" );
3295 int sourceLayerIndex;
3318 .setSubsetOfAttributes( attList ) );
3322 double currentValue = 0;
3325 currentValue = f.
attribute( index ).toDouble();
3326 if ( currentValue < minimumValue )
3328 minimumValue = currentValue;
3331 return QVariant( minimumValue );
3334 Q_ASSERT_X(
false,
"QgsVectorLayer::minimumValue()",
"Unknown source of the field!" );
3353 int sourceLayerIndex;
3379 .setSubsetOfAttributes( attList ) );
3383 double currentValue = 0;
3386 currentValue = f.
attribute( index ).toDouble();
3387 if ( currentValue > maximumValue )
3389 maximumValue = currentValue;
3392 return QVariant( maximumValue );
3395 Q_ASSERT_X(
false,
"QgsVectorLayer::maximumValue()",
"Unknown source of the field!" );
3438 QSet<int> attrIndex;
3441 QSet<int>::const_iterator attIt = attrIndex.constBegin();
3442 for ( ; attIt != attrIndex.constEnd(); ++attIt )
3444 if ( !attributes.contains( *attIt ) )
3446 attributes << *attIt;
3460 .setFilterRect( rendererContext.
extent() )
3465 int nFeatsToLabel = 0;
3488 QList<int>::const_iterator attIt = att.constBegin();
3489 for ( ; attIt != att.constEnd(); ++attIt )
3491 if ( !attributes.contains( *attIt ) )
3493 attributes << *attIt;
3517 QString myMetadata =
"<html><body>";
3521 myMetadata +=
"<p class=\"subheaderglossy\">";
3522 myMetadata +=
tr(
"General" );
3523 myMetadata +=
"</p>\n";
3528 myMetadata +=
"<p class=\"glossy\">" +
tr(
"Layer comment" ) +
"</p>\n";
3529 myMetadata +=
"<p>";
3531 myMetadata +=
"</p>\n";
3535 myMetadata +=
"<p class=\"glossy\">" +
tr(
"Storage type of this layer" ) +
"</p>\n";
3536 myMetadata +=
"<p>";
3538 myMetadata +=
"</p>\n";
3543 myMetadata +=
"<p class=\"glossy\">" +
tr(
"Description of this provider" ) +
"</p>\n";
3544 myMetadata +=
"<p>";
3546 myMetadata +=
"</p>\n";
3550 myMetadata +=
"<p class=\"glossy\">" +
tr(
"Source for this layer" ) +
"</p>\n";
3551 myMetadata +=
"<p>";
3553 myMetadata +=
"</p>\n";
3567 myMetadata +=
"<p class=\"glossy\">" +
tr(
"Geometry type of the features in this layer" ) +
"</p>\n";
3568 myMetadata +=
"<p>";
3569 myMetadata += typeString;
3570 myMetadata +=
"</p>\n";
3574 if ( !pkAttrList.isEmpty() )
3576 myMetadata +=
"<p class=\"glossy\">" +
tr(
"Primary key attributes" ) +
"</p>\n";
3577 myMetadata +=
"<p>";
3578 foreach (
int idx, pkAttrList )
3582 myMetadata +=
"</p>\n";
3587 myMetadata +=
"<p class=\"glossy\">" +
tr(
"The number of features in this layer" ) +
"</p>\n";
3588 myMetadata +=
"<p>";
3590 myMetadata +=
"</p>\n";
3592 myMetadata +=
"<p class=\"glossy\">" +
tr(
"Editing capabilities of this layer" ) +
"</p>\n";
3593 myMetadata +=
"<p>";
3595 myMetadata +=
"</p>\n";
3600 myMetadata +=
"<p class=\"subheaderglossy\">";
3601 myMetadata +=
tr(
"Extents" );
3602 myMetadata +=
"</p>\n";
3605 myMetadata +=
"<p class=\"glossy\">" +
tr(
"In layer spatial reference system units" ) +
"</p>\n";
3606 myMetadata +=
"<p>";
3619 QString xMin, yMin, xMax, yMax;
3620 double changeoverValue = 99999;
3621 if ( qAbs( myExtent.
xMinimum() ) > changeoverValue )
3623 xMin = QString(
"%1" ).arg( myExtent.
xMinimum(), 0,
'f', 2 );
3627 xMin = QString(
"%1" ).arg( myExtent.
xMinimum() );
3629 if ( qAbs( myExtent.
yMinimum() ) > changeoverValue )
3631 yMin = QString(
"%1" ).arg( myExtent.
yMinimum(), 0,
'f', 2 );
3635 yMin = QString(
"%1" ).arg( myExtent.
yMinimum() );
3637 if ( qAbs( myExtent.
xMaximum() ) > changeoverValue )
3639 xMax = QString(
"%1" ).arg( myExtent.
xMaximum(), 0,
'f', 2 );
3643 xMax = QString(
"%1" ).arg( myExtent.
xMaximum() );
3645 if ( qAbs( myExtent.
yMaximum() ) > changeoverValue )
3647 yMax = QString(
"%1" ).arg( myExtent.
yMaximum(), 0,
'f', 2 );
3651 yMax = QString(
"%1" ).arg( myExtent.
yMaximum() );
3654 myMetadata +=
tr(
"xMin,yMin %1,%2 : xMax,yMax %3,%4" )
3655 .arg( xMin ).arg( yMin ).arg( xMax ).arg( yMax );
3659 myMetadata +=
tr(
"unknown extent" );
3662 myMetadata +=
"</p>\n";
3670 QgsRectangle myProjectedExtent = coordinateTransform->transformBoundingBox(
extent() );
3671 myMetadata +=
"<p class=\"glossy\">" +
tr(
"In project spatial reference system units" ) +
"</p>\n";
3672 myMetadata +=
"<p>";
3673 myMetadata +=
tr(
"xMin,yMin %1,%2 : xMax,yMax %3,%4" )
3674 .arg( myProjectedExtent.
xMinimum() )
3675 .arg( myProjectedExtent.
yMinimum() )
3676 .arg( myProjectedExtent.
xMaximum() )
3677 .arg( myProjectedExtent.
yMaximum() );
3678 myMetadata +=
"</p>\n";
3684 myMetadata +=
"<p class=\"glossy\">" +
tr(
"Layer Spatial Reference System" ) +
"</p>\n";
3685 myMetadata +=
"<p>";
3686 myMetadata +=
crs().
toProj4().replace( QRegExp(
"\"" ),
" \"" );
3687 myMetadata +=
"</p>\n";
3695 myMetadata +=
"<p class=\"glossy\">" +
tr(
"Project (Output) Spatial Reference System" ) +
"</p>\n";
3696 myMetadata +=
"<p>";
3697 myMetadata += coordinateTransform->destCRS().toProj4().replace( QRegExp(
"\"" ),
" \"" );
3698 myMetadata +=
"</p>\n";
3706 myMetadata +=
"<p class=\"glossy\">" +
tr(
"In project spatial reference system units" ) +
"</p>\n";
3707 myMetadata +=
"<p>";
3708 myMetadata +=
tr(
"(Invalid transformation of layer extents)" );
3709 myMetadata +=
"</p>\n";
3717 myMetadata +=
"<p class=\"glossy\">" +
tr(
"Attribute field info" ) +
"</p>\n";
3718 myMetadata +=
"<p>";
3721 myMetadata +=
"<table width=\"100%\">";
3722 myMetadata +=
"<tr><th>";
3723 myMetadata +=
tr(
"Field" );
3724 myMetadata +=
"</th>";
3725 myMetadata +=
"<th>";
3726 myMetadata +=
tr(
"Type" );
3727 myMetadata +=
"</th>";
3728 myMetadata +=
"<th>";
3729 myMetadata +=
tr(
"Length" );
3730 myMetadata +=
"</th>";
3731 myMetadata +=
"<th>";
3732 myMetadata +=
tr(
"Precision" );
3733 myMetadata +=
"</th>";
3734 myMetadata +=
"<th>";
3735 myMetadata +=
tr(
"Comment" );
3736 myMetadata +=
"</th>";
3740 for ( QgsFieldMap::const_iterator it = myFields.begin(); it != myFields.end(); ++it )
3744 myMetadata +=
"<tr><td>";
3745 myMetadata += myField.
name();
3746 myMetadata +=
"</td>";
3747 myMetadata +=
"<td>";
3749 myMetadata +=
"</td>";
3750 myMetadata +=
"<td>";
3751 myMetadata += QString(
"%1" ).arg( myField.
length() );
3752 myMetadata +=
"</td>";
3753 myMetadata +=
"<td>";
3754 myMetadata += QString(
"%1" ).arg( myField.
precision() );
3755 myMetadata +=
"</td>";
3756 myMetadata +=
"<td>";
3757 myMetadata += QString(
"%1" ).arg( myField.
comment() );
3758 myMetadata +=
"</td></tr>";
3762 myMetadata +=
"</table>";
3765 myMetadata +=
"</body></html>";
3786 if ( idx < 0 || idx >= fields.
count() )
3788 QgsDebugMsg( QString(
"field %1 not found" ).arg( idx ) );
3791 QString fieldName = fields[idx].name();
3813 QDomElement elem = doc.createElement(
"attributeEditorContainer" );
3814 elem.setAttribute(
"name",
mName );
3815 for ( QList< QgsAttributeEditorElement* >::const_iterator it =
mChildren.begin(); it !=
mChildren.end(); ++it )
3817 elem.appendChild(( *it )->toDomElement( doc ) );
3830 QDomElement elem = doc.createElement(
"attributeEditorField" );
3831 elem.setAttribute(
"name",
mName );
3832 elem.setAttribute(
"index",
mIdx );
3847 if ( !listStylesExternalMethod )
3854 return listStylesExternalMethod(
mDataSource, ids, names, descriptions, msgError );
3868 if ( !getStyleByIdMethod )
3875 return getStyleByIdMethod(
mDataSource, styleId, msgError );
3880 bool useAsDefault, QString uiFileContent, QString &msgError )
3883 QString sldStyle, qmlStyle;
3893 if ( !saveStyleExternalMethod )
3900 QDomDocument qmlDocument, sldDocument;
3902 if ( !msgError.isNull() )
3906 qmlStyle = qmlDocument.toString();
3909 if ( !msgError.isNull() )
3913 sldStyle = sldDocument.toString();
3915 saveStyleExternalMethod(
mDataSource, qmlStyle, sldStyle, name,
3916 description, uiFileContent, useAsDefault, msgError );
3929 if ( !loadFromLocalDB && !dsUri.
database().isEmpty() )
3936 if ( loadStyleExternalMethod )
3938 QString qml, errorMsg;
3939 qml = loadStyleExternalMethod(
mDataSource, errorMsg );
3940 if ( !qml.isEmpty() )
3954 QDomDocument myDocument(
"qgis" );
3955 myDocument.setContent( namedStyle );
3957 QDomElement myRoot = myDocument.firstChildElement(
"qgis" );
3959 if ( myRoot.isNull() )
3961 errorMsg =
tr(
"Error: qgis element could not be found" );
3970 QDomNode transparencyNode = myRoot.namedItem(
"transparencyLevelInt" );
3971 if ( ! transparencyNode.isNull() )
3975 QDomElement myElement = transparencyNode.toElement();
3976 setTransparency( myElement.text().toInt() );