38 #include <QPainterPath>
83 #ifdef TESTPROVIDERLIB
88 static const char *
const ident_ =
"$Id$";
98 bool loadDefaultStyleFlag )
99 :
QgsMapLayer( VectorLayer, baseName, vectorLayerPath )
100 , mUpdateThreshold( 0 )
101 , mDataProvider( NULL )
102 , mProviderKey( providerKey )
106 , mMaxUpdatedIndex( -1 )
107 , mActiveCommand( NULL )
109 , mRendererV2( NULL )
110 , mUsingRendererV2( false )
113 , mVertexMarkerOnlyForSelection( false )
116 , mDiagramRenderer( 0 )
117 , mDiagramLayerSettings( 0 )
133 if ( settings.value(
"/qgis/use_symbology_ng",
true ).toBool() &&
hasGeometryType() )
141 bool defaultLoadedFlag =
false;
142 if ( loadDefaultStyleFlag )
201 QList<QgsVectorOverlay*>::iterator overlayIt =
mOverlays.begin();
202 for ( ; overlayIt !=
mOverlays.end(); ++overlayIt )
255 QString idxName =
"";
258 if ( !fldName.isEmpty() )
265 int fieldsSize = fields.size();
267 for ( QgsFieldMap::const_iterator it = fields.begin(); it != fields.end(); ++it )
269 QString fldName = it.value().name();
270 QgsDebugMsg(
"Checking field " + fldName +
" of " + QString::number( fieldsSize ) +
" total" );
276 if ( fldName.indexOf(
"name",
false ) > -1 )
278 if ( idxName.isEmpty() )
283 if ( fldName.indexOf(
"descrip",
false ) > -1 )
285 if ( idxName.isEmpty() )
290 if ( fldName.indexOf(
"id",
false ) > -1 )
292 if ( idxId.isEmpty() )
300 if ( fieldsSize == 0 )
303 if ( idxName.length() > 0 )
309 if ( idxId.length() > 0 )
347 attributes.append( attrNum );
356 QgsDebugMsg(
"Selecting features based on view extent" );
389 QgsDebugMsg( QString(
"Total features processed %1" ).arg( featureCount ) );
401 QPainter *p = renderContext.
painter();
402 unsigned char *ptr = feature + 5;
403 unsigned int wkbType = *((
int* )( feature + 1 ) );
404 unsigned int nPoints = *((
int* )ptr );
409 std::vector<double> x( nPoints );
410 std::vector<double> y( nPoints );
411 std::vector<double> z( nPoints, 0.0 );
414 for (
register unsigned int i = 0; i < nPoints; ++i )
416 x[i] = *((
double * ) ptr );
417 ptr +=
sizeof( double );
418 y[i] = *((
double * ) ptr );
419 ptr +=
sizeof( double );
422 ptr +=
sizeof( double );
434 for (
register unsigned int i = 0; i < nPoints; ++i )
446 QPolygonF pa( nPoints );
447 for (
register unsigned int i = 0; i < nPoints; ++i )
462 QPen myTransparentPen = p->pen();
463 QColor myColor = myTransparentPen.color();
470 myTransparentPen.setColor( myColor );
471 p->setPen( myTransparentPen );
472 p->drawPolyline( pa );
478 std::vector<double>::const_iterator xIt;
479 std::vector<double>::const_iterator yIt;
480 for ( xIt = x.begin(), yIt = y.begin(); xIt != x.end(); ++xIt, ++yIt )
494 QPainter *p = renderContext.
painter();
495 typedef std::pair<std::vector<double>, std::vector<double> > ringType;
496 typedef ringType* ringTypePtr;
497 typedef std::vector<ringTypePtr> ringsType;
500 unsigned int numRings = *((
int* )( feature + 1 +
sizeof(
int ) ) );
505 unsigned int wkbType = *((
int* )( feature + 1 ) );
509 int total_points = 0;
517 unsigned char* ptr = feature + 1 + 2 *
sizeof( int );
519 for (
register unsigned int idx = 0; idx < numRings; idx++ )
521 unsigned int nPoints = *((
int* )ptr );
523 ringTypePtr ring =
new ringType( std::vector<double>( nPoints ), std::vector<double>( nPoints ) );
527 std::vector<double> zVector( nPoints, 0.0 );
530 for (
register unsigned int jdx = 0; jdx < nPoints; jdx++ )
532 ring->first[jdx] = *((
double * ) ptr );
533 ptr +=
sizeof( double );
534 ring->second[jdx] = *((
double * ) ptr );
535 ptr +=
sizeof( double );
538 ptr +=
sizeof( double );
544 QgsDebugMsg(
"Ring has only " + QString::number( nPoints ) +
" points! Skipping this ring." );
554 for (
register unsigned int i = 0; i < nPoints; ++i )
566 if ( ring->first.size() == 0 )
570 rings.push_back( ring );
571 total_points += ring->first.size();
584 if ( total_points > 0 )
587 QBrush brush = p->brush();
593 QBrush myTransparentBrush = p->brush();
594 QColor myColor = brush.color();
602 myTransparentBrush.setColor( myColor );
603 QPen myTransparentPen = p->pen();
604 myColor = myTransparentPen.color();
612 myTransparentPen.setColor( myColor );
614 p->setBrush( myTransparentBrush );
615 p->setPen( myTransparentPen );
619 ringTypePtr r = rings[0];
620 unsigned ringSize = r->first.size();
622 QPolygonF pa( ringSize );
623 for (
register unsigned int j = 0; j != ringSize; ++j )
625 pa[j].setX( r->first[j] );
626 pa[j].setY( r->second[j] );
628 p->drawPolygon( pa );
633 for (
register unsigned int j = 0; j != ringSize; ++j )
645 int numRings = rings.size();
646 for (
register int i = 0; i < numRings; ++i )
650 ringTypePtr r = rings[i];
652 unsigned ringSize = r->first.size();
655 QPolygonF pa( ringSize );
656 for (
register unsigned int j = 0; j != ringSize; ++j )
658 pa[j].setX( r->first[j] );
659 pa[j].setY( r->second[j] );
662 path.addPolygon( pa );
676 for (
int i = 0; i < pa.size(); ++i )
678 largestX = qMax( largestX, pa.point( i ).x() );
679 smallestX = qMin( smallestX, pa.point( i ).x() );
680 largestY = qMax( largestY, pa.point( i ).y() );
681 smallestY = qMin( smallestY, pa.point( i ).y() );
683 QgsDebugMsg( QString(
"Largest X coordinate was %1" ).arg( largestX ) );
684 QgsDebugMsg( QString(
"Smallest X coordinate was %1" ).arg( smallestX ) );
685 QgsDebugMsg( QString(
"Largest Y coordinate was %1" ).arg( largestY ) );
686 QgsDebugMsg( QString(
"Smallest Y coordinate was %1" ).arg( smallestY ) );
697 for (
int i = 0; i < path.elementCount(); ++i )
699 const QPainterPath::Element & e = path.elementAt( i );
708 p->setBrush( brush );
722 bool vertexMarkerOnlyForSelection = settings.value(
"/qgis/digitizing/marker_only_for_selected",
false ).toBool();
740 #ifndef Q_WS_MAC //MH: disable this on Mac for now to avoid problems with resizing
745 qApp->processEvents();
747 else if ( featureCount % 1000 == 0 )
750 qApp->processEvents();
755 bool drawMarker = (
mEditable && ( !vertexMarkerOnlyForSelection || sel ) );
781 QgsDebugMsg( QString(
"Failed to transform a point while drawing a feature of type '%1'. Ignoring this feature. %2" )
790 QgsDebugMsg( QString(
"Total features processed %1" ).arg( featureCount ) );
799 QHash< QgsSymbolV2*, QList<QgsFeature> > features;
802 bool vertexMarkerOnlyForSelection = settings.value(
"/qgis/digitizing/marker_only_for_selected",
false ).toBool();
829 if ( featureCount % 1000 == 0 )
831 qApp->processEvents();
840 if ( !features.contains( sym ) )
842 features.insert( sym, QList<QgsFeature>() );
844 features[sym].append( fet );
872 for (
int i = 0; i < symbols.count(); i++ )
878 if ( level < 0 || level >= 1000 )
881 while ( level >= levels.count() )
883 levels[level].append( item );
888 for (
int l = 0; l < levels.count(); l++ )
891 for (
int i = 0; i < level.count(); i++ )
894 if ( !features.contains( item.
symbol() ) )
899 int layer = item.
layer();
900 QList<QgsFeature>& lst = features[item.
symbol()];
901 QList<QgsFeature>::iterator fit;
905 for ( fit = lst.begin(); fit != lst.end(); ++fit )
913 if ( featureCount % 1000 == 0 )
915 qApp->processEvents();
920 bool drawMarker = (
mEditable && ( !vertexMarkerOnlyForSelection || sel ) );
928 QgsDebugMsg( QString(
"Failed to transform a point while drawing a feature of type '%1'. Ignoring this feature. %2" )
979 attributes.append( attrNum );
980 QgsDebugMsg(
"attrs: " + attrName +
" - " + QString::number( attrNum ) );
983 bool labeling =
false;
1014 int vertexMarkerSize = 7;
1031 bool labeling =
false;
1046 #ifndef Q_WS_MAC //MH: disable this on Mac for now to avoid problems with resizing
1051 qApp->processEvents();
1053 else if ( featureCount % 1000 == 0 )
1056 qApp->processEvents();
1085 double opacity = 1.0;
1114 QgsDebugMsg( QString(
"Failed to transform a point while drawing a feature of type '%1'. Rendering stopped. %2" )
1119 QgsDebugMsg( QString(
"Total features processed %1" ).arg( featureCount ) );
1145 p.setPen( QColor( 50, 100, 120, 200 ) );
1146 p.setBrush( QColor( 200, 200, 210, 120 ) );
1147 p.drawEllipse( x - m, y - m, m * 2 + 1, m * 2 + 1 );
1151 p.setPen( QColor( 255, 0, 0 ) );
1152 p.drawLine( x - m, y + m, x + m, y - m );
1153 p.drawLine( x - m, y - m, x + m, y + m );
1223 for ( QgsFeatureIds::iterator iter = tmp.begin(); iter != tmp.end(); ++iter )
1357 QgsDebugMsg( QString(
"Data Provider Geometry type is not recognised, is %1" ).arg( type ) );
1361 QgsDebugMsg(
"pointer to mDataProvider is null" );
1369 QgsDebugMsg(
"WARNING: This code should never be reached. Problems may occur..." );
1412 if ( retval.
width() == 0.0 || retval.
height() == 0.0 )
1421 retval.
set( -1.0, -1.0, 1.0, 1.0 );
1544 for ( QgsAttributeMap::const_iterator it = map.begin(); it != map.end(); it++ )
1550 for ( QgsAttributeMap::const_iterator it = map.begin(); it != map.end(); it++ )
1556 if ( !map.contains( it.key() ) && ( all ||
mFetchAttributes.contains( it.key() ) ) )
1561 const QVariant& joinValue,
const QgsAttributeList& attributes,
int attributeIndexOffset )
1563 const QHash< QString, QgsAttributeMap>& memoryCache = joinInfo.
cachedAttributes;
1564 if ( !memoryCache.isEmpty() )
1566 QgsAttributeMap featureAttributes = memoryCache.value( joinValue.toString() );
1567 bool found = !featureAttributes.isEmpty();
1568 QgsAttributeList::const_iterator attIt = attributes.constBegin();
1569 for ( ; attIt != attributes.constEnd(); ++attIt )
1573 f.
addAttribute( *attIt + attributeIndexOffset, featureAttributes.value( *attIt ) );
1577 f.
addAttribute( *attIt + attributeIndexOffset, QVariant() );
1592 if ( !subsetString.isEmpty() )
1594 subsetString.append(
" AND " );
1597 subsetString.append(
"\"" + joinFieldName +
"\"" +
" = " +
"\"" + joinValue.toString() +
"\"" );
1608 QgsAttributeMap::const_iterator attIt = attMap.constBegin();
1609 for ( ; attIt != attMap.constEnd(); ++attIt )
1611 f.
addAttribute( attIt.key() + attributeIndexOffset, attIt.value() );
1616 QgsAttributeList::const_iterator attIt = attributes.constBegin();
1617 for ( ; attIt != attributes.constEnd(); ++attIt )
1619 f.
addAttribute( *attIt + attributeIndexOffset, QVariant() );
1659 int maxProviderIndex = 0;
1666 QgsAttributeList::const_iterator joinFieldIt = joinFields.constBegin();
1667 for ( ; joinFieldIt != joinFields.constEnd(); ++joinFieldIt )
1737 if ( fid == it->id() )
1747 QgsDebugMsg( QString(
"No attributes for the added feature %1 found" ).arg( f.
id() ) );
1831 if ( fetchAttributes )
1833 if ( featureId < 0 )
1840 if ( featureId != it->id() )
1849 QgsDebugMsg( QString(
"No attributes for the added feature %1 found" ).arg( f.
id() ) );
1866 if ( iter->id() == featureId )
1870 if ( fetchGeometries )
1873 if ( fetchAttributes )
1881 if ( fetchAttributes )
1901 static int addedIdLowWaterMark = -1;
1919 addedIdLowWaterMark--;
1921 QgsDebugMsg(
"Assigned feature id " + QString::number( addedIdLowWaterMark ) );
1934 if ( alsoUpdateExtent )
2103 int addRingReturnCode = 5;
2104 double xMin, yMin, xMax, yMax;
2123 if ( addRingReturnCode == 0 )
2132 return addRingReturnCode;
2160 int returnValue = geom.
addIsland( ring );
2170 if ( addedIt->id() == selectedFeatureId )
2172 return addedIt->geometry()->
addIsland( ring );
2179 QgsGeometryMap::iterator cachedIt =
mCachedGeometries.find( selectedFeatureId );
2182 int errorCode = cachedIt->addIsland( ring );
2183 if ( errorCode == 0 )
2195 if (
featureAtId( selectedFeatureId, f,
true,
false ) )
2200 int errorCode = fGeom->
addIsland( ring );
2222 int errorCode = geom.
translate( dx, dy );
2231 if ( addedIt->id() == featureId )
2233 return addedIt->geometry()->translate( dx, dy );
2242 int errorCode = cachedIt->translate( dx, dy );
2243 if ( errorCode == 0 )
2258 int errorCode = translateGeom.
translate( dx, dy );
2259 if ( errorCode == 0 )
2276 double xMin, yMin, xMax, yMax;
2279 int splitFunctionReturn;
2280 int numberOfSplittedFeatures = 0;
2285 if ( selectedIds.size() > 0 )
2309 else if ( bBox.
height() == 0.0 && bBox.
width() > 0 )
2327 QgsFeatureList::iterator select_it = featureList.begin();
2328 for ( ; select_it != featureList.end(); ++select_it )
2330 QList<QgsGeometry*> newGeometries;
2331 QList<QgsPoint> topologyTestPoints;
2333 splitFunctionReturn = select_it->geometry()->
splitGeometry( splitLine, newGeometries, topologicalEditing, topologyTestPoints );
2334 if ( splitFunctionReturn == 0 )
2342 for (
int i = 0; i < newGeometries.size(); ++i )
2344 newGeometry = newGeometries.at( i );
2348 newFeatures.append( newFeature );
2352 if ( topologicalEditing )
2354 QList<QgsPoint>::const_iterator topol_it = topologyTestPoints.constBegin();
2355 for ( ; topol_it != topologyTestPoints.constEnd(); ++topol_it )
2360 ++numberOfSplittedFeatures;
2362 else if ( splitFunctionReturn > 1 )
2364 returnCode = splitFunctionReturn;
2368 if ( numberOfSplittedFeatures == 0 && selectedIds.size() > 0 )
2387 int returnValue = 0;
2438 QgsPolyline::const_iterator line_it = theLine.constBegin();
2439 for ( ; line_it != theLine.constEnd(); ++line_it )
2456 for (
int i = 0; i < theMultiLine.size(); ++i )
2458 QgsPolyline::const_iterator line_it = currentPolyline.constBegin();
2459 for ( ; line_it != currentPolyline.constEnd(); ++line_it )
2477 for (
int i = 0; i < thePolygon.size(); ++i )
2479 currentRing = thePolygon.at( i );
2480 QgsPolyline::const_iterator line_it = currentRing.constBegin();
2481 for ( ; line_it != currentRing.constEnd(); ++line_it )
2500 for (
int i = 0; i < theMultiPolygon.size(); ++i )
2502 currentPolygon = theMultiPolygon.at( i );
2503 for (
int j = 0; j < currentPolygon.size(); ++j )
2505 currentRing = currentPolygon.at( j );
2506 QgsPolyline::const_iterator line_it = currentRing.constBegin();
2507 for ( ; line_it != currentRing.constEnd(); ++line_it )
2529 QMultiMap<double, QgsSnappingResult> snapResults;
2531 QMultiMap<double, QgsSnappingResult> vertexSnapResults;
2533 QList<QgsSnappingResult> filteredSnapResults;
2536 double threshold = 0.0000001;
2552 QMultiMap<double, QgsSnappingResult>::const_iterator snap_it = snapResults.constBegin();
2553 QMultiMap<double, QgsSnappingResult>::const_iterator vertex_snap_it;
2554 for ( ; snap_it != snapResults.constEnd(); ++snap_it )
2557 bool vertexAlreadyExists =
false;
2563 vertex_snap_it = vertexSnapResults.constBegin();
2564 for ( ; vertex_snap_it != vertexSnapResults.constEnd(); ++vertex_snap_it )
2566 if ( snap_it.value().snappedAtGeometry == vertex_snap_it.value().snappedAtGeometry )
2568 vertexAlreadyExists =
true;
2572 if ( !vertexAlreadyExists )
2574 filteredSnapResults.push_back( *snap_it );
2645 QDomNode pkeyNode = layer_node.namedItem(
"provider" );
2647 if ( pkeyNode.isNull() )
2653 QDomElement pkeyElt = pkeyNode.toElement();
2677 QDomElement pkeyElem = pkeyNode.toElement();
2678 if ( !pkeyElem.isNull() )
2680 QString encodingString = pkeyElem.attribute(
"encoding" );
2681 if ( !encodingString.isEmpty() )
2723 QgsDebugMsg(
"Instantiated the data provider plugin" );
2756 QRegExp reg(
"\"[^\"]+\"\\.\"([^\"]+)\"( \\([^)]+\\))?" );
2757 if ( reg.indexIn(
name() ) >= 0 )
2759 QStringList stuff = reg.capturedTexts();
2760 QString lName = stuff[1];
2764 QMap<QString, QgsMapLayer*>::const_iterator it;
2765 for ( it = layers.constBegin(); it != layers.constEnd() && ( *it )->name() != lName; it++ )
2768 if ( it != layers.constEnd() && stuff.size() > 2 )
2770 lName +=
"." + stuff[2].mid( 2, stuff[2].length() - 3 );
2773 if ( !lName.isEmpty() )
2814 QDomDocument & document )
2818 QDomElement mapLayerNode = layer_node.toElement();
2820 if ( mapLayerNode.isNull() || (
"maplayer" != mapLayerNode.nodeName() ) )
2826 mapLayerNode.setAttribute(
"type",
"vector" );
2834 QDomElement provider = document.createElement(
"provider" );
2836 QDomText providerText = document.createTextNode(
providerType() );
2837 provider.appendChild( providerText );
2838 layer_node.appendChild( provider );
2855 if ( !rendererElement.isNull() )
2873 QDomNode singlenode = node.namedItem(
"singlesymbol" );
2874 QDomNode graduatednode = node.namedItem(
"graduatedsymbol" );
2875 QDomNode continuousnode = node.namedItem(
"continuoussymbol" );
2876 QDomNode uniquevaluenode = node.namedItem(
"uniquevalue" );
2881 if ( !singlenode.isNull() )
2884 returnCode = renderer->
readXML( singlenode, *
this );
2886 else if ( !graduatednode.isNull() )
2889 returnCode = renderer->
readXML( graduatednode, *
this );
2891 else if ( !continuousnode.isNull() )
2894 returnCode = renderer->
readXML( continuousnode, *
this );
2896 else if ( !uniquevaluenode.isNull() )
2899 returnCode = renderer->
readXML( uniquevaluenode, *
this );
2904 errorMessage = tr(
"Unknown renderer" );
2908 if ( returnCode == 1 )
2910 errorMessage = tr(
"No renderer object" );
delete renderer;
return false;
2912 else if ( returnCode == 2 )
2914 errorMessage = tr(
"Classification field not found" );
delete renderer;
return false;
2921 QDomNode displayFieldNode = node.namedItem(
"displayfield" );
2922 if ( !displayFieldNode.isNull() )
2924 QDomElement e = displayFieldNode.toElement();
2929 QDomElement e = node.toElement();
2938 QDomNode labelnode = node.namedItem(
"label" );
2939 QDomElement element = labelnode.toElement();
2941 if ( hasLabelsEnabled < 1 )
2950 QDomNode labelattributesnode = node.namedItem(
"labelattributes" );
2952 if ( !labelattributesnode.isNull() )
2960 QDomElement singleCatDiagramElem = node.firstChildElement(
"SingleCategoryDiagramRenderer" );
2961 if ( !singleCatDiagramElem.isNull() )
2966 QDomElement linearDiagramElem = node.firstChildElement(
"LinearlyInterpolatedDiagramRenderer" );
2967 if ( !linearDiagramElem.isNull() )
2975 QDomElement diagramSettingsElem = node.firstChildElement(
"DiagramLayerSettings" );
2976 if ( !diagramSettingsElem.isNull() )
2988 QDomNode editTypesNode = node.namedItem(
"edittypes" );
2989 if ( !editTypesNode.isNull() )
2991 QDomNodeList editTypeNodes = editTypesNode.childNodes();
2993 for (
int i = 0; i < editTypeNodes.size(); i++ )
2995 QDomNode editTypeNode = editTypeNodes.at( i );
2996 QDomElement editTypeElement = editTypeNode.toElement();
2998 QString
name = editTypeElement.attribute(
"name" );
3005 if ( editType ==
ValueMap && editTypeNode.hasChildNodes() )
3007 mValueMaps.insert( name, QMap<QString, QVariant>() );
3009 QDomNodeList valueMapNodes = editTypeNode.childNodes();
3010 for (
int j = 0; j < valueMapNodes.size(); j++ )
3012 QDomElement value = valueMapNodes.at( j ).toElement();
3013 mValueMaps[
name ].insert( value.attribute(
"key" ), value.attribute(
"value" ) );
3018 QVariant
min = editTypeElement.attribute(
"min" );
3019 QVariant
max = editTypeElement.attribute(
"max" );
3020 QVariant step = editTypeElement.attribute(
"step" );
3026 mCheckedStates[
name ] = QPair<QString, QString>( editTypeElement.attribute(
"checked" ), editTypeElement.attribute(
"unchecked" ) );
3031 QDomNode editFormNode = node.namedItem(
"editform" );
3032 if ( !editFormNode.isNull() )
3034 QDomElement e = editFormNode.toElement();
3038 QDomNode editFormInitNode = node.namedItem(
"editforminit" );
3039 if ( !editFormInitNode.isNull() )
3044 QDomNode annotationFormNode = node.namedItem(
"annotationform" );
3045 if ( !annotationFormNode.isNull() )
3047 QDomElement e = annotationFormNode.toElement();
3052 QDomNode aliasesNode = node.namedItem(
"aliases" );
3053 if ( !aliasesNode.isNull() )
3055 QDomElement aliasElem;
3058 QDomNodeList aliasNodeList = aliasesNode.toElement().elementsByTagName(
"alias" );
3059 for (
int i = 0; i < aliasNodeList.size(); ++i )
3061 aliasElem = aliasNodeList.at( i ).toElement();
3064 if ( aliasElem.hasAttribute(
"field" ) )
3066 field = aliasElem.attribute(
"field" );
3070 int index = aliasElem.attribute(
"index" ).toInt();
3085 QDomElement mapLayerNode = node.toElement();
3092 node.appendChild( rendererElement );
3098 mapLayerNode.setAttribute(
"minLabelScale",
mLabel->
minScale() );
3099 mapLayerNode.setAttribute(
"maxLabelScale",
mLabel->
maxScale() );
3104 for ( QgsAttributeList::const_iterator it = attributes.begin(); it != attributes.end(); ++it )
3106 QDomElement classificationElement = doc.createElement(
"classificationattribute" );
3107 QDomText classificationText = doc.createTextNode( providerFields[*it].
name() );
3108 classificationElement.appendChild( classificationText );
3109 node.appendChild( classificationElement );
3116 if ( !myRenderer->
writeXML( node, doc, *
this ) )
3118 errorMessage = tr(
"renderer failed to save" );
3125 errorMessage = tr(
"no renderer" );
3134 QDomElement dField = doc.createElement(
"displayfield" );
3135 QDomText dFieldText = doc.createTextNode(
displayField() );
3136 dField.appendChild( dFieldText );
3137 node.appendChild( dField );
3140 QDomElement labelElem = doc.createElement(
"label" );
3141 QDomText labelText = doc.createTextNode(
"" );
3145 labelText.setData(
"1" );
3149 labelText.setData(
"0" );
3151 labelElem.appendChild( labelText );
3153 node.appendChild( labelElem );
3158 if ( fieldname !=
"" )
3160 dField = doc.createElement(
"labelfield" );
3161 dFieldText = doc.createTextNode( fieldname );
3162 dField.appendChild( dFieldText );
3163 node.appendChild( dField );
3179 QDomElement editTypesElement = doc.createElement(
"edittypes" );
3181 for ( QMap<QString, EditType>::const_iterator it =
mEditTypes.begin(); it !=
mEditTypes.end(); ++it )
3183 QDomElement editTypeElement = doc.createElement(
"edittype" );
3184 editTypeElement.setAttribute(
"name", it.key() );
3185 editTypeElement.setAttribute(
"type", it.value() );
3192 const QMap<QString, QVariant> &map =
mValueMaps[ it.key()];
3194 for ( QMap<QString, QVariant>::const_iterator vmit = map.begin(); vmit != map.end(); vmit++ )
3196 QDomElement value = doc.createElement(
"valuepair" );
3197 value.setAttribute(
"key", vmit.key() );
3198 value.setAttribute(
"value", vmit.value().toString() );
3199 editTypeElement.appendChild( value );
3207 if (
mRanges.contains( it.key() ) )
3209 editTypeElement.setAttribute(
"min",
mRanges[ it.key()].mMin.toString() );
3210 editTypeElement.setAttribute(
"max",
mRanges[ it.key()].mMax.toString() );
3211 editTypeElement.setAttribute(
"step",
mRanges[ it.key()].mStep.toString() );
3218 editTypeElement.setAttribute(
"checked",
mCheckedStates[ it.key()].first );
3219 editTypeElement.setAttribute(
"unchecked",
mCheckedStates[ it.key()].second );
3236 editTypesElement.appendChild( editTypeElement );
3239 node.appendChild( editTypesElement );
3242 QDomElement efField = doc.createElement(
"editform" );
3244 efField.appendChild( efText );
3245 node.appendChild( efField );
3247 QDomElement efiField = doc.createElement(
"editforminit" );
3249 efiField.appendChild( efiText );
3250 node.appendChild( efiField );
3252 QDomElement afField = doc.createElement(
"annotationform" );
3254 afField.appendChild( afText );
3255 node.appendChild( afField );
3260 QDomElement aliasElem = doc.createElement(
"aliases" );
3268 QDomElement aliasEntryElem = doc.createElement(
"alias" );
3269 aliasEntryElem.setAttribute(
"field", a_it.key() );
3270 aliasEntryElem.setAttribute(
"index", idx );
3271 aliasEntryElem.setAttribute(
"name", a_it.value() );
3272 aliasElem.appendChild( aliasEntryElem );
3274 node.appendChild( aliasElem );
3281 QList<QgsVectorOverlay*>::const_iterator overlay_it =
mOverlays.constBegin();
3282 for ( ; overlay_it !=
mOverlays.constEnd(); ++overlay_it )
3286 ( *overlay_it )->writeXML( mapLayerNode, doc );
3327 if ( field.
name().isEmpty() )
3332 if ( it.value().name() == field.
name() )
3361 for ( i = 0; i < types.size() && types[i].mTypeName !=
type; i++ )
3391 if ( displayName.isEmpty() )
3394 QgsFieldMap::const_iterator fieldIt = fields.find( attributeIndex );
3395 if ( fieldIt != fields.constEnd() )
3397 displayName = fieldIt->name();
3468 bool success =
true;
3492 bool attributesChanged =
false;
3502 attributesChanged =
true;
3516 QList<QgsField> addedAttributes;
3530 attributesChanged =
true;
3542 bool attributeChangesOk =
true;
3543 if ( attributesChanged )
3546 QMap<int, QString> src;
3549 src[ it.key()] = it.value().name();
3552 int maxAttrIdx = -1;
3556 QMap<QString, int> dst;
3557 for ( QgsFieldMap::const_iterator it = pFields.begin(); it != pFields.end(); it++ )
3559 dst[ it.value().name()] = it.key();
3560 if ( it.key() > maxAttrIdx )
3561 maxAttrIdx = it.key();
3571 if ( dst.contains( name ) )
3575 mCommitErrors << tr(
"SUCCESS: attribute %1 was added." ).arg( name );
3580 dst[
name ] = ++maxAttrIdx;
3581 attributeChangesOk =
false;
3582 mCommitErrors << tr(
"ERROR: attribute %1 not added" ).arg( name );
3588 QMap<int, int> remap;
3589 for ( QMap<int, QString>::const_iterator it = src.begin(); it != src.end(); it++ )
3591 if ( dst.contains( it.value() ) )
3593 remap[ it.key()] = dst[ it.value()];
3603 for ( QgsAttributeMap::const_iterator it = src.begin(); it != src.end(); it++ )
3605 if ( remap.contains( it.key() ) )
3607 dst[ remap[it.key()] ] = it.value();
3619 for ( QgsAttributeMap::const_iterator it = src.begin(); it != src.end(); it++ )
3620 if ( remap.contains( it.key() ) )
3621 dst[ remap[it.key()] ] = it.value();
3623 fit->setAttributeMap( dst );
3629 for ( QMap<int, int>::iterator it = remap.begin(); it != remap.end(); it++ )
3635 if ( attributeChangesOk )
3839 bool selectionIsAddedFeature =
false;
3844 if ( *it == iter->id() )
3847 selectionIsAddedFeature =
true;
3853 if ( !selectionIsAddedFeature )
3889 for ( QgsFeatureList::iterator iter = features.begin(); iter != features.end(); ++iter )
3949 if ( otherVectorLayer )
3951 if ( otherVectorLayer->
type() !=
type() )
3959 if ( fieldsThis.size() != fieldsOther.size() )
3966 uint fieldsThisSize = fieldsThis.size();
3968 for ( uint i = 0; i < fieldsThisSize; ++i )
3970 if ( fieldsThis[i].
name() != fieldsOther[i].
name() )
3986 QMultiMap<double, QgsSnappingResult> snapResults;
3994 if ( snapResults.size() < 1 )
3999 QMultiMap<double, QgsSnappingResult>::const_iterator snap_it = snapResults.constBegin();
4000 point.
setX( snap_it.value().snappedVertex.x() );
4001 point.
setY( snap_it.value().snappedVertex.y() );
4007 QMultiMap<double, QgsSnappingResult>& snappingResults,
4018 QList<QgsFeature> featureList;
4019 QgsRectangle searchRect( startPoint.
x() - snappingTolerance, startPoint.
y() - snappingTolerance,
4020 startPoint.
x() + snappingTolerance, startPoint.
y() + snappingTolerance );
4021 double sqrSnappingTolerance = snappingTolerance * snappingTolerance;
4034 snapToGeometry( startPoint, it.key(), g, sqrSnappingTolerance, snappingResults, snap_to );
4052 return n == 0 ? 2 : 0;
4063 int atVertex, beforeVertex, afterVertex;
4064 double sqrDistVertexSnap, sqrDistSegmentSnap;
4071 snappedPoint = geom->
closestVertex( startPoint, atVertex, beforeVertex, afterVertex, sqrDistVertexSnap );
4072 if ( sqrDistVertexSnap < sqrSnappingTolerance )
4077 if ( beforeVertex != -1 )
4082 if ( afterVertex != -1 )
4087 snappingResultVertex.
layer =
this;
4088 snappingResults.insert( sqrt( sqrDistVertexSnap ), snappingResultVertex );
4098 if ( sqrDistSegmentSnap < sqrSnappingTolerance )
4107 snappingResultSegment.
layer =
this;
4108 snappingResults.insert( sqrt( sqrDistSegmentSnap ), snappingResultSegment );
4123 QList<QgsSnappingResult>::const_iterator it = snapResults.constBegin();
4124 for ( ; it != snapResults.constEnd(); ++it )
4126 if ( it->snappedVertexNr == -1 )
4128 layerPoint = it->snappedVertex;
4129 if ( !
insertVertex( layerPoint.
x(), layerPoint.
y(), it->snappedAtGeometry, it->afterVertexNr ) )
4140 if ( list.size() < 1 )
4150 for ( QList<QgsPoint>::const_iterator it = list.constBegin(); it != list.constEnd(); ++it )
4152 if ( it->x() < xmin )
4156 if ( it->x() > xmax )
4160 if ( it->y() < ymin )
4164 if ( it->y() > ymax )
4176 QString markerTypeString = settings.value(
"/qgis/digitizing/marker_style",
"Cross" ).toString();
4177 if ( markerTypeString ==
"Cross" )
4181 else if ( markerTypeString ==
"SemiTransparentCircle" )
4194 return settings.value(
"/qgis/digitizing/marker_size", 3 ).toInt();
4201 QPainter *p = renderContext.
painter();
4216 unsigned char* feature = geom->
asWkb();
4225 double x = *((
double * )( feature + 5 ) );
4226 double y = *((
double * )( feature + 5 +
sizeof(
double ) ) );
4242 p->drawImage( pt, *marker );
4250 unsigned char *ptr = feature + 5;
4251 unsigned int nPoints = *((
int* )ptr );
4258 for (
register unsigned int i = 0; i < nPoints; ++i )
4261 double x = *((
double * ) ptr );
4262 ptr +=
sizeof( double );
4263 double y = *((
double * ) ptr );
4264 ptr +=
sizeof( double );
4267 ptr +=
sizeof( double );
4279 p->drawImage( pt, *marker );
4294 unsigned char* ptr = feature + 5;
4295 unsigned int numLineStrings = *((
int* )ptr );
4298 for (
register unsigned int jdx = 0; jdx < numLineStrings; jdx++ )
4313 unsigned char *ptr = feature + 5;
4314 unsigned int numPolygons = *((
int* )ptr );
4316 for (
register unsigned int kdx = 0; kdx < numPolygons; kdx++ )
4330 QgsDebugMsg(
"----- Computing Coordinate System" );
4360 double& x,
double& y,
4377 std::vector<double>& x, std::vector<double>& y, std::vector<double>& z,
4429 if ( fields.contains( idx ) &&
mEditTypes.contains( fields[idx].
name() ) )
4438 if ( fields.contains( idx ) )
4472 if ( !fields.contains( idx ) )
4474 QgsDebugMsg( QString(
"field %1 not found" ).arg( idx ) );
4477 if ( !
mValueMaps.contains( fields[idx].name() ) )
4478 mValueMaps[ fields[idx].name()] = QMap<QString, QVariant>();
4488 if ( fields.contains( idx ) )
4490 QgsDebugMsg( QString(
"field %1 not found" ).arg( idx ) );
4493 if ( !
mRanges.contains( fields[idx].name() ) )
4496 return mRanges[ fields[idx].name()];
4506 for (
int i =
mOverlays.size() - 1; i >= 0; --i )
4508 if (
mOverlays.at( i )->typeName() == typeName )
4522 QList<QgsVectorOverlay*>::iterator it =
mOverlays.begin();
4525 if (( *it )->typeName() == typeName )
4592 bool isFirstChange =
true;
4593 if ( featureId < 0 )
4601 isFirstChange =
false;
4611 isFirstChange =
false;
4617 if ( featureId >= 0 )
4672 QMap<int, QgsUndoCommand::GeometryChangeEntry>& geometryChange = cmd->
mGeometryChange;
4675 QMap<int, QgsUndoCommand::AttributeChanges>& attributeChange = cmd->
mAttributeChange;
4681 QMap<int, QgsUndoCommand::GeometryChangeEntry>::iterator it = geometryChange.begin();
4682 for ( ; it != geometryChange.end(); ++it )
4684 if ( it.value().target == NULL )
4695 QgsFeatureIds::iterator delIt = deletedFeatureIdChange.begin();
4696 for ( ; delIt != deletedFeatureIdChange.end(); ++delIt )
4703 QgsFeatureList::iterator addIt = addedFeatures.begin();
4704 for ( ; addIt != addedFeatures.end(); ++addIt )
4711 QMap<int, QgsUndoCommand::AttributeChanges>::iterator attrFeatIt = attributeChange.begin();
4712 for ( ; attrFeatIt != attributeChange.end(); ++attrFeatIt )
4714 int fid = attrFeatIt.key();
4716 QMap<int, QgsUndoCommand::AttributeChangeEntry>::iterator attrChIt = attrFeatIt.value().begin();
4717 for ( ; attrChIt != attrFeatIt.value().end(); ++attrChIt )
4722 if ( attrChIt.value().target.isNull() )
4740 mAddedFeatures[i].changeAttribute( attrChIt.key(), attrChIt.value().target );
4750 QgsFieldMap::iterator attrIt = addedAttributes.begin();
4751 for ( ; attrIt != addedAttributes.end(); ++attrIt )
4753 int attrIndex = attrIt.key();
4760 QgsFieldMap::iterator dAttrIt = deletedAttributes.begin();
4761 for ( ; dAttrIt != deletedAttributes.end(); ++dAttrIt )
4763 int attrIndex = dAttrIt.key();
4776 QMap<int, QgsUndoCommand::GeometryChangeEntry>& geometryChange = cmd->
mGeometryChange;
4779 QMap<int, QgsUndoCommand::AttributeChanges>& attributeChange = cmd->
mAttributeChange;
4784 QgsFieldMap::iterator dAttrIt = deletedAttributes.begin();
4785 for ( ; dAttrIt != deletedAttributes.end(); ++dAttrIt )
4787 int attrIndex = dAttrIt.key();
4794 QgsFieldMap::iterator attrIt = addedAttributes.begin();
4795 for ( ; attrIt != addedAttributes.end(); ++attrIt )
4797 int attrIndex = attrIt.key();
4804 QMap<int, QgsUndoCommand::GeometryChangeEntry>::iterator it = geometryChange.begin();
4805 for ( ; it != geometryChange.end(); ++it )
4807 if ( it.value().original == NULL )
4818 QgsFeatureIds::iterator delIt = deletedFeatureIdChange.begin();
4819 for ( ; delIt != deletedFeatureIdChange.end(); ++delIt )
4826 QgsFeatureList::iterator addIt = addedFeatures.begin();
4827 for ( ; addIt != addedFeatures.end(); ++addIt )
4832 if ( addedIt->id() == addIt->id() )
4842 QMap<int, QgsUndoCommand::AttributeChanges>::iterator attrFeatIt = attributeChange.begin();
4843 for ( ; attrFeatIt != attributeChange.end(); ++attrFeatIt )
4845 int fid = attrFeatIt.key();
4846 QMap<int, QgsUndoCommand::AttributeChangeEntry>::iterator attrChIt = attrFeatIt.value().begin();
4847 for ( ; attrChIt != attrFeatIt.value().end(); ++attrChIt )
4851 if ( attrChIt.value().isFirstChange )
4869 mAddedFeatures[i].changeAttribute( attrChIt.key(), attrChIt.value().original );
4874 QVariant original = attrChIt.value().original;
4875 if ( attrChIt.value().isFirstChange )
4893 if ( fields.contains( idx ) )
4903 return QPair<QString, QString>(
"1",
"0" );
4910 for ( QgsFieldMap::const_iterator it = theFields.constBegin(); it != theFields.constEnd(); ++it )
4912 if ( QString::compare( it->name(), fieldName, Qt::CaseInsensitive ) == 0 )
4949 bkAddedAttributes.insert( *attIdIt,
mUpdatedFields.value( *attIdIt ) );
4958 int currentMaxIndex = 0;
4974 QgsFieldMap::const_iterator fieldIt = bkAddedAttributes.constBegin();
4975 for ( ; fieldIt != bkAddedAttributes.constEnd(); ++fieldIt )
4993 featureIt->setAttributeMap( attMap );
5015 uniqueValues.clear();
5021 int maxProviderIndex;
5024 if ( index <= maxProviderIndex && !
mEditable )
5059 QVariant currentValue;
5060 QHash<QString, QVariant> val;
5064 val.insert( currentValue.toString(), currentValue );
5065 if ( limit >= 0 && val.size() >= limit )
5071 uniqueValues = val.values();
5081 int maxProviderIndex;
5084 if ( index <= maxProviderIndex && !
mEditable )
5116 double currentValue = 0;
5120 if ( currentValue < minimumValue )
5122 minimumValue = currentValue;
5125 return QVariant( minimumValue );
5135 int maxProviderIndex;
5138 if ( index <= maxProviderIndex && !
mEditable )
5170 double currentValue = 0;
5174 if ( currentValue > maximumValue )
5176 maximumValue = currentValue;
5179 return QVariant( maximumValue );
5194 QgsAttributeMap::const_iterator it = map.find( oldIndex );
5195 if ( it == map.constEnd() )
5200 map.insert( newIndex, it.value() );
5201 map.remove( oldIndex );
5209 QSet<int> attrIndex;
5212 QSet<int>::const_iterator attIt = attrIndex.constBegin();
5213 for ( ; attIt != attrIndex.constEnd(); ++attIt )
5215 if ( !attributes.contains( *attIt ) )
5217 attributes << *attIt;
5230 QList<int>::const_iterator attIt = att.constBegin();
5231 for ( ; attIt != att.constEnd(); ++attIt )
5233 if ( !attributes.contains( *attIt ) )
5235 attributes << *attIt;