Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
More merging of editing branch
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@7882 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Jan 9, 2008
1 parent 44e4170 commit 7e41e58
Show file tree
Hide file tree
Showing 23 changed files with 1,512 additions and 62 deletions.
Binary file added images/themes/default/mActionSplitFeatures.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/app/CMakeLists.txt
Expand Up @@ -37,6 +37,7 @@ SET(QGIS_APP_SRCS
qgsmaptoolmovefeature.cpp
qgsmaptoolmovevertex.cpp
qgsmaptoolselect.cpp
qgsmaptoolsplitfeatures.cpp
qgsmaptoolvertexedit.cpp
qgsmarkerdialog.cpp
qgsmeasuredialog.cpp
Expand Down
17 changes: 17 additions & 0 deletions src/app/qgisapp.cpp
Expand Up @@ -153,6 +153,7 @@
#include "qgsmaptoolmovevertex.h"
#include "qgsmaptoolpan.h"
#include "qgsmaptoolselect.h"
#include "qgsmaptoolsplitfeatures.h"
#include "qgsmaptoolvertexedit.h"
#include "qgsmaptoolzoom.h"
#include "qgsmeasuretool.h"
Expand Down Expand Up @@ -414,6 +415,7 @@ QgisApp::~QgisApp()
delete mMapTools.mCaptureLine;
delete mMapTools.mCapturePolygon;
delete mMapTools.mMoveFeature;
delete mMapTools.mSplitFeatures;
delete mMapTools.mSelect;
delete mMapTools.mVertexAdd;
delete mMapTools.mVertexMove;
Expand Down Expand Up @@ -743,6 +745,11 @@ void QgisApp::createActions()
connect(mActionMoveFeature, SIGNAL(triggered()), this, SLOT(moveFeature()));
mActionMoveFeature->setEnabled(true);
//
mActionSplitFeatures = new QAction(QIcon(myIconPath+"/mActionSplitFeatures.png"), tr("Split Features"), this);
mActionSplitFeatures->setStatusTip(tr("Split Features"));
connect(mActionSplitFeatures, SIGNAL(triggered()), this, SLOT(splitFeatures()));
mActionSplitFeatures->setEnabled(true);
//
mActionAddVertex = new QAction(QIcon(myIconPath+"/mActionAddVertex.png"), tr("Add Vertex"), this);
mActionAddVertex->setStatusTip(tr("Add Vertex"));
connect(mActionAddVertex, SIGNAL(triggered()), this, SLOT(addVertex()));
Expand Down Expand Up @@ -826,6 +833,8 @@ void QgisApp::createActionGroups()
mMapToolGroup->addAction(mActionCapturePolygon);
mActionMoveFeature->setCheckable(true);
mMapToolGroup->addAction(mActionMoveFeature);
mActionSplitFeatures->setCheckable(true);
mMapToolGroup->addAction(mActionSplitFeatures);
mMapToolGroup->addAction(mActionDeleteSelected);
mActionAddVertex->setCheckable(true);
mMapToolGroup->addAction(mActionAddVertex);
Expand Down Expand Up @@ -986,6 +995,7 @@ void QgisApp::createToolBars()
mDigitizeToolBar->addAction(mActionCaptureLine);
mDigitizeToolBar->addAction(mActionCapturePolygon);
mDigitizeToolBar->addAction(mActionMoveFeature);
mDigitizeToolBar->addAction(mActionSplitFeatures);
mDigitizeToolBar->addAction(mActionDeleteSelected);
mDigitizeToolBar->addAction(mActionAddVertex);
mDigitizeToolBar->addAction(mActionDeleteVertex);
Expand Down Expand Up @@ -1252,6 +1262,8 @@ void QgisApp::createCanvas()
mMapTools.mCapturePolygon->setAction(mActionCapturePolygon);
mMapTools.mMoveFeature = new QgsMapToolMoveFeature(mMapCanvas);
mMapTools.mMoveFeature->setAction(mActionMoveFeature);
mMapTools.mSplitFeatures = new QgsMapToolSplitFeatures(mMapCanvas);
mMapTools.mSplitFeatures->setAction(mActionSplitFeatures);
mMapTools.mSelect = new QgsMapToolSelect(mMapCanvas);
mMapTools.mSelect->setAction(mActionSelect);
mMapTools.mVertexAdd = new QgsMapToolAddVertex(mMapCanvas);
Expand Down Expand Up @@ -3418,6 +3430,11 @@ void QgisApp::moveFeature()
mMapCanvas->setMapTool(mMapTools.mMoveFeature);
}

void QgisApp::splitFeatures()
{
mMapCanvas->setMapTool(mMapTools.mSplitFeatures);
}

void QgisApp::capturePoint()
{
if(mMapCanvas && mMapCanvas->isDrawing())
Expand Down
4 changes: 4 additions & 0 deletions src/app/qgisapp.h
Expand Up @@ -289,6 +289,8 @@ public slots:
void deleteSelected();
//! activates the move feature tool
void moveFeature();
//! activates the split features tool
void splitFeatures();
//! activates the add vertex tool
void addVertex();
//! activates the move vertex tool
Expand Down Expand Up @@ -484,6 +486,7 @@ public slots:
QAction *mActionCapturePolygon;
QAction *mActionDeleteSelected;
QAction *mActionMoveFeature;
QAction *mActionSplitFeatures;
QAction *mActionAddVertex;
QAction *mActionDeleteVertex;
QAction *mActionMoveVertex;
Expand Down Expand Up @@ -541,6 +544,7 @@ public slots:
QgsMapTool* mCaptureLine;
QgsMapTool* mCapturePolygon;
QgsMapTool* mMoveFeature;
QgsMapTool* mSplitFeatures;
QgsMapTool* mSelect;
QgsMapTool* mVertexAdd;
QgsMapTool* mVertexMove;
Expand Down
7 changes: 7 additions & 0 deletions src/app/qgsmaptooladdfeature.cpp
Expand Up @@ -225,6 +225,13 @@ void QgsMapToolAddFeature::canvasReleaseEvent(QMouseEvent * e)

delete mRubberBand;
mRubberBand = NULL;

//bail out if there are not at least two vertices
if(mCaptureList.size() < 2)
{
mCaptureList.clear();
return;
}

//bail out if there are not at least two vertices
if(mCaptureList.size() < 2)
Expand Down
21 changes: 18 additions & 3 deletions src/app/qgsmaptoolcapture.cpp
Expand Up @@ -18,6 +18,7 @@
#include "qgsattributedialog.h"
#include "qgscoordinatetransform.h"
#include "qgsfield.h"
#include "qgslogger.h"
#include "qgsmaptoolcapture.h"
#include "qgsmapcanvas.h"
#include "qgsmaprender.h"
Expand Down Expand Up @@ -132,11 +133,25 @@ int QgsMapToolCapture::addVertex(const QPoint& p)

void QgsMapToolCapture::undo()
{
//todo: a more sophisticated undo-behaviour is needed...
if(mRubberBand)
{
//mRubberBand->pop_back();
int rubberBandSize = mRubberBand->numberOfVertices();
int captureListSize = mCaptureList.size();

if(rubberBandSize < 1 || captureListSize < 1)
{
return;
}

mRubberBand->removeLastPoint();
mCaptureList.pop_back();
mCanvas->refresh();
}
}

void QgsMapToolCapture::keyPressEvent(QKeyEvent* e)
{
if(e->key() == Qt::Key_Backspace)
{
undo();
}
}
4 changes: 3 additions & 1 deletion src/app/qgsmaptoolcapture.h
Expand Up @@ -51,7 +51,9 @@ class QgsMapToolCapture : public QgsMapToolEdit
virtual void canvasPressEvent(QMouseEvent * e);

//! Overridden mouse release event
virtual void canvasReleaseEvent(QMouseEvent * e)=0;
virtual void canvasReleaseEvent(QMouseEvent * e)=0;

virtual void keyPressEvent(QKeyEvent* e);

//! Resize rubber band
virtual void renderComplete();
Expand Down
12 changes: 0 additions & 12 deletions src/app/qgsmaptooledit.cpp
Expand Up @@ -25,10 +25,6 @@
QgsMapToolEdit::QgsMapToolEdit(QgsMapCanvas* canvas): QgsMapTool(canvas)
{
mSnapper.setMapCanvas(canvas);
if(canvas)
{
connect(mCanvas, SIGNAL(keyPressed(QKeyEvent*)), this, SLOT(keyPress(QKeyEvent*)));
}
}


Expand Down Expand Up @@ -116,11 +112,3 @@ QgsVectorLayer* QgsMapToolEdit::currentVectorLayer()
}
return vlayer;
}

void QgsMapToolEdit::keyPress(QKeyEvent* e)
{
if(e->key() == Qt::Key_Backspace)
{
undo();
}
}
8 changes: 0 additions & 8 deletions src/app/qgsmaptooledit.h
Expand Up @@ -26,7 +26,6 @@ class QKeyEvent;
/**Base class for map tools that edit vector geometry*/
class QgsMapToolEdit: public QgsMapTool
{
Q_OBJECT
public:
QgsMapToolEdit(QgsMapCanvas* canvas);
virtual ~QgsMapToolEdit();
Expand Down Expand Up @@ -57,13 +56,6 @@ class QgsMapToolEdit: public QgsMapTool

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

/**Default implementation does nothing*/
virtual void undo(){}

public slots:
/**Connected with keyPressed signal from QgsMapCanvas*/
void keyPress(QKeyEvent* e);
};

#endif
94 changes: 94 additions & 0 deletions src/app/qgsmaptoolsplitfeatures.cpp
@@ -0,0 +1,94 @@
/***************************************************************************
qgsmaptoolsplitfeatures.cpp
---------------------------
begin : August 2007
copyright : (C) 2007 by Marco Hugentobler
email : marco.hugentobler@karto.baug.ethz.ch
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
/* $Id$ */

#include "qgsmaptoolsplitfeatures.h"
#include "qgsmapcanvas.h"
#include "qgsrubberband.h"
#include "qgsvectorlayer.h"
#include <QMessageBox>

QgsMapToolSplitFeatures::QgsMapToolSplitFeatures(QgsMapCanvas* canvas): QgsMapToolCapture(canvas, QgsMapToolCapture::CaptureLine)
{

}

QgsMapToolSplitFeatures::~QgsMapToolSplitFeatures()
{

}

void QgsMapToolSplitFeatures::canvasReleaseEvent(QMouseEvent * e)
{
//check if we operate on a vector layer
QgsVectorLayer *vlayer = dynamic_cast <QgsVectorLayer*>(mCanvas->currentLayer());

if (!vlayer)
{
QMessageBox::information(0, QObject::tr("Not a vector layer"), \
QObject::tr("The current layer is not a vector layer"));
return;
}

if (!vlayer->isEditable())
{
QMessageBox::information(0, QObject::tr("Layer not editable"),
QObject::tr("Cannot edit the vector layer. To make it editable, go to the file item "
"of the layer, right click and check 'Allow Editing'."));
return;
}

//add point to list and to rubber band
int error = addVertex(e->pos());
if(error == 1)
{
//current layer is not a vector layer
return;
}
else if (error == 2)
{
//problem with coordinate transformation
QMessageBox::information(0, QObject::tr("Coordinate transform error"), \
QObject::tr("Cannot transform the point to the layers coordinate system"));
return;
}

if (e->button() == Qt::LeftButton)
{
mCapturing = TRUE;
}
else if (e->button() == Qt::RightButton)
{
mCapturing = FALSE;
delete mRubberBand;
mRubberBand = 0;

//bring up dialog if a split was not possible (polygon) or only done once (line)
int returnCode = vlayer->splitFeatures(mCaptureList);
if(returnCode == 1)
{
//several intersections but only one split (most likely line)
QMessageBox::warning(0, tr("Intersection problem"), tr("One or more geometries are intersected several times by the split lines. Those geometries are only split once."));
}
else if(returnCode == 2)
{
//too complex intersection (most likely several polygon intersections)
QMessageBox::warning(0, tr("Intersection problem"), tr("One or more geometries cannot be split because the intersection is too complex. Note that polygon splits can only be done if the split line intersects the polygon once. Also inner polygon rings cannot be split"));
}

mCaptureList.clear();
mCanvas->refresh();
}
}
31 changes: 31 additions & 0 deletions src/app/qgsmaptoolsplitfeatures.h
@@ -0,0 +1,31 @@
/***************************************************************************
qgsmaptoolsplitfeatures.h
---------------------
begin : August 2007
copyright : (C) 2007 by Marco Hugentobler
email : marco.hugentobler@karto.baug.ethz.ch
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
/* $Id$ */

#ifndef QGSMAPTOOLSPLITFEATURES_H
#define QGSMAPTOOLSPLITFEATURES_H

#include "qgsmaptoolcapture.h"

/**A map tool that draws a line and splits the features cut by the line*/
class QgsMapToolSplitFeatures: public QgsMapToolCapture
{
public:
QgsMapToolSplitFeatures(QgsMapCanvas* canvas);
virtual ~QgsMapToolSplitFeatures();
void canvasReleaseEvent(QMouseEvent * e);
};

#endif
5 changes: 3 additions & 2 deletions src/core/qgsfeature.cpp
Expand Up @@ -171,9 +171,10 @@ const QgsAttributeMap& QgsFeature::attributeMap() const
return mAttributes;
}

void QgsFeature::setAttributeMap(const QgsAttributeMap& attributeMap)
/**Sets the attributes for this feature*/
void QgsFeature::setAttributeMap(const QgsAttributeMap& attributes)
{
mAttributes = attributeMap;
mAttributes = attributes;
}

/**
Expand Down

0 comments on commit 7e41e58

Please sign in to comment.