Skip to content

Commit 2002f68

Browse files
author
mhugent
committedJan 9, 2008
More editing merges...
git-svn-id: http://svn.osgeo.org/qgis/trunk@7884 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 5d1af70 commit 2002f68

24 files changed

+1142
-797
lines changed
 

‎src/app/qgsmaptooladdfeature.cpp

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "qgsattributedialog.h"
2020
#include "qgscsexception.h"
2121
#include "qgsfield.h"
22+
#include "qgsgeometry.h"
2223
#include "qgsmapcanvas.h"
2324
#include "qgsproject.h"
2425
#include "qgsrubberband.h"
@@ -226,15 +227,15 @@ void QgsMapToolAddFeature::canvasReleaseEvent(QMouseEvent * e)
226227
delete mRubberBand;
227228
mRubberBand = NULL;
228229

229-
//bail out if there are not at least two vertices
230-
if(mCaptureList.size() < 2)
230+
//lines: bail out if there are not at least two vertices
231+
if(mTool == CaptureLine && mCaptureList.size() < 2)
231232
{
232233
mCaptureList.clear();
233234
return;
234235
}
235236

236-
//bail out if there are not at least two vertices
237-
if(mCaptureList.size() < 2)
237+
//polygons: bail out if there are not at least two vertices
238+
if(mTool == CapturePolygon && mCaptureList.size() < 3)
238239
{
239240
mCaptureList.clear();
240241
return;
@@ -312,6 +313,7 @@ void QgsMapToolAddFeature::canvasReleaseEvent(QMouseEvent * e)
312313
QMessageBox::critical(0, QObject::tr("Error"), QObject::tr("Cannot add feature. Unknown WKB type"));
313314
return; //unknown wkbtype
314315
}
316+
f->setGeometryAndOwnership(&wkb[0],size);
315317
}
316318
else // polygon
317319
{
@@ -404,8 +406,18 @@ void QgsMapToolAddFeature::canvasReleaseEvent(QMouseEvent * e)
404406
QMessageBox::critical(0, QObject::tr("Error"), QObject::tr("Cannot add feature. Unknown WKB type"));
405407
return; //unknown wkbtype
406408
}
409+
f->setGeometryAndOwnership(&wkb[0],size);
410+
//is automatic polygon intersection removal activated?
411+
int avoidPolygonIntersections = QgsProject::instance()->readNumEntry("Digitizing", "/AvoidPolygonIntersections", 0);
412+
413+
if(avoidPolygonIntersections != 0)
414+
{
415+
if(vlayer->removePolygonIntersections(f->geometry()) != 0)
416+
{
417+
QMessageBox::critical(0, QObject::tr("Error"), QObject::tr("Could not remove polygon intersection"));
418+
}
419+
}
407420
}
408-
f->setGeometryAndOwnership(&wkb[0],size);
409421

410422
// add the fields to the QgsFeature
411423
const QgsFieldMap fields = provider->fields();
@@ -416,6 +428,12 @@ void QgsMapToolAddFeature::canvasReleaseEvent(QMouseEvent * e)
416428

417429
if (QgsAttributeDialog::queryAttributes(fields, *f))
418430
{
431+
//add points to other features to keep topology up-to-date
432+
int topologicalEditing = QgsProject::instance()->readNumEntry("Digitizing", "/TopologicalEditing", 0);
433+
if(topologicalEditing)
434+
{
435+
addTopologicalPoints(mCaptureList);
436+
}
419437
vlayer->addFeature(*f);
420438
}
421439
delete f;

‎src/app/qgsmaptooladdisland.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
/* $Id$ */
1616

1717
#include "qgsmaptooladdisland.h"
18+
#include "qgsgeometry.h"
1819
#include "qgsmapcanvas.h"
20+
#include "qgsproject.h"
1921
#include "qgsrubberband.h"
2022
#include "qgsvectorlayer.h"
2123
#include <QMessageBox>
@@ -77,6 +79,13 @@ void QgsMapToolAddIsland::canvasReleaseEvent(QMouseEvent * e)
7779

7880
//close polygon
7981
mCaptureList.push_back(*mCaptureList.begin());
82+
83+
//add points to other features to keep topology up-to-date
84+
int topologicalEditing = QgsProject::instance()->readNumEntry("Digitizing", "/TopologicalEditing", 0);
85+
if(topologicalEditing)
86+
{
87+
addTopologicalPoints(mCaptureList);
88+
}
8089

8190
int errorCode = vlayer->addIsland(mCaptureList);
8291
QString errorMessage;

‎src/app/qgsmaptooladdvertex.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ void QgsMapToolAddVertex::canvasMoveEvent(QMouseEvent * e)
3838
if(mSnapper.snapToBackgroundLayers(e->pos(), snapResults) == 0)
3939
{
4040
QgsPoint posMapCoord = snapPointFromResults(snapResults, e->pos());
41-
mRubberBand->movePoint(1, posMapCoord);
41+
mRubberBand->movePoint(2, posMapCoord); //consider that the first rubber band point is added twice
4242
}
4343
}
4444
}

‎src/app/qgsmaptoolcapture.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "qgscoordinatetransform.h"
2020
#include "qgsfield.h"
2121
#include "qgslogger.h"
22+
#include "qgsgeometry.h"
2223
#include "qgsmaptoolcapture.h"
2324
#include "qgsmapcanvas.h"
2425
#include "qgsmaprender.h"
@@ -124,8 +125,6 @@ int QgsMapToolCapture::addVertex(const QPoint& p)
124125
}
125126
mRubberBand->addPoint(mapPoint);
126127
mCaptureList.push_back(layerPoint);
127-
//insert also vertices for adjacent features if topological editing is enabled
128-
insertSegmentVerticesForSnap(snapResults, vlayer);
129128
}
130129

131130
return 0;

‎src/app/qgsmaptoolcapture.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include "qgsmaptooledit.h"
2222
#include "qgspoint.h"
2323

24-
24+
class QgsGeometry;
2525
class QgsRubberBand;
2626

2727
#include <QPoint>

‎src/app/qgsmaptooledit.cpp

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ int QgsMapToolEdit::insertSegmentVerticesForSnap(const QList<QgsSnappingResult>&
5757
//snap to edited layer?
5858
if(it->layer == editedLayer)
5959
{
60-
//segment snap?
6160
if(it->snappedVertexNr == -1) //segment snap
6261
{
6362
layerPoint = toLayerCoords(editedLayer, it->snappedVertex);
@@ -112,3 +111,62 @@ QgsVectorLayer* QgsMapToolEdit::currentVectorLayer()
112111
}
113112
return vlayer;
114113
}
114+
115+
116+
int QgsMapToolEdit::addTopologicalPoints(const QList<QgsPoint>& geom)
117+
{
118+
if(!mCanvas)
119+
{
120+
return 1;
121+
}
122+
123+
//find out current vector layer
124+
QgsVectorLayer *vlayer = currentVectorLayer();
125+
126+
if (!vlayer)
127+
{
128+
return 2;
129+
}
130+
131+
QList<QgsPoint>::const_iterator list_it = geom.constBegin();
132+
for(; list_it != geom.constEnd(); ++list_it)
133+
{
134+
addTopologicalPoints(*list_it, vlayer);
135+
}
136+
137+
return 0;
138+
}
139+
140+
int QgsMapToolEdit::addTopologicalPoints(const QgsPoint& p, QgsVectorLayer* vl)
141+
{
142+
if(!vl)
143+
{
144+
return 1;
145+
}
146+
147+
QMultiMap<double, QgsSnappingResult> snapResults; //results from the snapper object
148+
QList<QgsSnappingResult> filteredSnapResults; //we filter out the results that are on existing vertices
149+
150+
const double threshold = 0.00000001;
151+
152+
if(vl->snapWithContext(p, threshold, snapResults, QgsSnapper::SNAP_TO_SEGMENT) != 0)
153+
{
154+
return 2;
155+
}
156+
157+
QMultiMap<double, QgsSnappingResult>::const_iterator snap_it = snapResults.constBegin();
158+
159+
for(; snap_it != snapResults.constEnd(); ++snap_it)
160+
{
161+
//check if there is already an existing vertex at the position of p
162+
QgsPoint vertexPoint(p);
163+
if(vl->snapPoint(vertexPoint, threshold))
164+
{
165+
continue;
166+
}
167+
168+
filteredSnapResults.push_back(*snap_it);
169+
}
170+
insertSegmentVerticesForSnap(filteredSnapResults, vl);
171+
return 0;
172+
}

‎src/app/qgsmaptooledit.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,16 @@ class QgsMapToolEdit: public QgsMapTool
5656

5757
/**Returns the current vector layer of the map canvas or 0*/
5858
QgsVectorLayer* currentVectorLayer();
59+
60+
/**Adds vertices to other features to keep topology up to date, e.g. to neighbouring polygons.
61+
Note that geom must be a geometry that is not yet inserted into the layer.
62+
@param geom a geometry that is to be inserted into the current vector layer
63+
@return 0 in case of success*/
64+
int addTopologicalPoints(const QList<QgsPoint>& geom);
65+
/**Adds topological points for one vertex
66+
@param p vertex in layer coordinates
67+
@return 0 in case of success*/
68+
int addTopologicalPoints(const QgsPoint& p, QgsVectorLayer* vl);
5969
};
6070

6171
#endif

0 commit comments

Comments
 (0)
Please sign in to comment.