Skip to content

Commit

Permalink
More editing merges...
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@7884 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Jan 9, 2008
1 parent 5d1af70 commit 2002f68
Show file tree
Hide file tree
Showing 24 changed files with 1,142 additions and 797 deletions.
28 changes: 23 additions & 5 deletions src/app/qgsmaptooladdfeature.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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();
Expand All @@ -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;
Expand Down
9 changes: 9 additions & 0 deletions src/app/qgsmaptooladdisland.cpp
Expand Up @@ -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>
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsmaptooladdvertex.cpp
Expand Up @@ -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
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/app/qgsmaptoolcapture.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsmaptoolcapture.h
Expand Up @@ -21,7 +21,7 @@
#include "qgsmaptooledit.h"
#include "qgspoint.h"


class QgsGeometry;
class QgsRubberBand;

#include <QPoint>
Expand Down
60 changes: 59 additions & 1 deletion src/app/qgsmaptooledit.cpp
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
10 changes: 10 additions & 0 deletions src/app/qgsmaptooledit.h
Expand Up @@ -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

0 comments on commit 2002f68

Please sign in to comment.