Skip to content
Permalink
Browse files
More editing merges...
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@7884 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Jan 9, 2008
1 parent 7e41e58 commit 765b15d4b4aafb78fed6dd80578c5fe2b5fa479a
@@ -19,6 +19,7 @@
#include "qgsattributedialog.h"
#include "qgscsexception.h"
#include "qgsfield.h"
#include "qgsgeometry.h"
#include "qgsmapcanvas.h"
#include "qgsproject.h"
#include "qgsrubberband.h"
@@ -226,15 +227,15 @@ void QgsMapToolAddFeature::canvasReleaseEvent(QMouseEvent * e)
delete mRubberBand;
mRubberBand = NULL;

//bail out if there are not at least two vertices
if(mCaptureList.size() < 2)
//lines: bail out if there are not at least two vertices
if(mTool == CaptureLine && mCaptureList.size() < 2)
{
mCaptureList.clear();
return;
}

//bail out if there are not at least two vertices
if(mCaptureList.size() < 2)
//polygons: bail out if there are not at least two vertices
if(mTool == CapturePolygon && mCaptureList.size() < 3)
{
mCaptureList.clear();
return;
@@ -312,6 +313,7 @@ void QgsMapToolAddFeature::canvasReleaseEvent(QMouseEvent * e)
QMessageBox::critical(0, QObject::tr("Error"), QObject::tr("Cannot add feature. Unknown WKB type"));
return; //unknown wkbtype
}
f->setGeometryAndOwnership(&wkb[0],size);
}
else // polygon
{
@@ -404,8 +406,18 @@ void QgsMapToolAddFeature::canvasReleaseEvent(QMouseEvent * e)
QMessageBox::critical(0, QObject::tr("Error"), QObject::tr("Cannot add feature. Unknown WKB type"));
return; //unknown wkbtype
}
f->setGeometryAndOwnership(&wkb[0],size);
//is automatic polygon intersection removal activated?
int avoidPolygonIntersections = QgsProject::instance()->readNumEntry("Digitizing", "/AvoidPolygonIntersections", 0);

if(avoidPolygonIntersections != 0)
{
if(vlayer->removePolygonIntersections(f->geometry()) != 0)
{
QMessageBox::critical(0, QObject::tr("Error"), QObject::tr("Could not remove polygon intersection"));
}
}
}
f->setGeometryAndOwnership(&wkb[0],size);

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

if (QgsAttributeDialog::queryAttributes(fields, *f))
{
//add points to other features to keep topology up-to-date
int topologicalEditing = QgsProject::instance()->readNumEntry("Digitizing", "/TopologicalEditing", 0);
if(topologicalEditing)
{
addTopologicalPoints(mCaptureList);
}
vlayer->addFeature(*f);
}
delete f;
@@ -15,7 +15,9 @@
/* $Id$ */

#include "qgsmaptooladdisland.h"
#include "qgsgeometry.h"
#include "qgsmapcanvas.h"
#include "qgsproject.h"
#include "qgsrubberband.h"
#include "qgsvectorlayer.h"
#include <QMessageBox>
@@ -77,6 +79,13 @@ void QgsMapToolAddIsland::canvasReleaseEvent(QMouseEvent * e)

//close polygon
mCaptureList.push_back(*mCaptureList.begin());

//add points to other features to keep topology up-to-date
int topologicalEditing = QgsProject::instance()->readNumEntry("Digitizing", "/TopologicalEditing", 0);
if(topologicalEditing)
{
addTopologicalPoints(mCaptureList);
}

int errorCode = vlayer->addIsland(mCaptureList);
QString errorMessage;
@@ -38,7 +38,7 @@ void QgsMapToolAddVertex::canvasMoveEvent(QMouseEvent * e)
if(mSnapper.snapToBackgroundLayers(e->pos(), snapResults) == 0)
{
QgsPoint posMapCoord = snapPointFromResults(snapResults, e->pos());
mRubberBand->movePoint(1, posMapCoord);
mRubberBand->movePoint(2, posMapCoord); //consider that the first rubber band point is added twice
}
}
}
@@ -19,6 +19,7 @@
#include "qgscoordinatetransform.h"
#include "qgsfield.h"
#include "qgslogger.h"
#include "qgsgeometry.h"
#include "qgsmaptoolcapture.h"
#include "qgsmapcanvas.h"
#include "qgsmaprender.h"
@@ -124,8 +125,6 @@ int QgsMapToolCapture::addVertex(const QPoint& p)
}
mRubberBand->addPoint(mapPoint);
mCaptureList.push_back(layerPoint);
//insert also vertices for adjacent features if topological editing is enabled
insertSegmentVerticesForSnap(snapResults, vlayer);
}

return 0;
@@ -21,7 +21,7 @@
#include "qgsmaptooledit.h"
#include "qgspoint.h"


class QgsGeometry;
class QgsRubberBand;

#include <QPoint>
@@ -57,7 +57,6 @@ int QgsMapToolEdit::insertSegmentVerticesForSnap(const QList<QgsSnappingResult>&
//snap to edited layer?
if(it->layer == editedLayer)
{
//segment snap?
if(it->snappedVertexNr == -1) //segment snap
{
layerPoint = toLayerCoords(editedLayer, it->snappedVertex);
@@ -112,3 +111,62 @@ QgsVectorLayer* QgsMapToolEdit::currentVectorLayer()
}
return vlayer;
}


int QgsMapToolEdit::addTopologicalPoints(const QList<QgsPoint>& geom)
{
if(!mCanvas)
{
return 1;
}

//find out current vector layer
QgsVectorLayer *vlayer = currentVectorLayer();

if (!vlayer)
{
return 2;
}

QList<QgsPoint>::const_iterator list_it = geom.constBegin();
for(; list_it != geom.constEnd(); ++list_it)
{
addTopologicalPoints(*list_it, vlayer);
}

return 0;
}

int QgsMapToolEdit::addTopologicalPoints(const QgsPoint& p, QgsVectorLayer* vl)
{
if(!vl)
{
return 1;
}

QMultiMap<double, QgsSnappingResult> snapResults; //results from the snapper object
QList<QgsSnappingResult> filteredSnapResults; //we filter out the results that are on existing vertices

const double threshold = 0.00000001;

if(vl->snapWithContext(p, threshold, snapResults, QgsSnapper::SNAP_TO_SEGMENT) != 0)
{
return 2;
}

QMultiMap<double, QgsSnappingResult>::const_iterator snap_it = snapResults.constBegin();

for(; snap_it != snapResults.constEnd(); ++snap_it)
{
//check if there is already an existing vertex at the position of p
QgsPoint vertexPoint(p);
if(vl->snapPoint(vertexPoint, threshold))
{
continue;
}

filteredSnapResults.push_back(*snap_it);
}
insertSegmentVerticesForSnap(filteredSnapResults, vl);
return 0;
}
@@ -56,6 +56,16 @@ class QgsMapToolEdit: public QgsMapTool

/**Returns the current vector layer of the map canvas or 0*/
QgsVectorLayer* currentVectorLayer();

/**Adds vertices to other features to keep topology up to date, e.g. to neighbouring polygons.
Note that geom must be a geometry that is not yet inserted into the layer.
@param geom a geometry that is to be inserted into the current vector layer
@return 0 in case of success*/
int addTopologicalPoints(const QList<QgsPoint>& geom);
/**Adds topological points for one vertex
@param p vertex in layer coordinates
@return 0 in case of success*/
int addTopologicalPoints(const QgsPoint& p, QgsVectorLayer* vl);
};

#endif
Loading

0 comments on commit 765b15d

Please sign in to comment.