Large diffs are not rendered by default.

153 changes: 153 additions & 0 deletions src/app/nodetool/qgsmaptoolnodetool.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
/***************************************************************************
qgsmaptoolnodetool.h - add/move/delete vertex integrated in one tool
---------------------
begin : April 2009
copyright : (C) 2009 by Richard Kostecky
email : csf dot kostej at mail dot com
***************************************************************************
* *
* 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. *
* *
***************************************************************************/

#ifndef QGSMAPTOOLNODETOOL_H
#define QGSMAPTOOLNODETOOL_H

#include "qgsmaptoolvertexedit.h"

class QRubberBand;

class QgsRubberBand;
class QgsVertexEntry;
class QgsSelectedFeature;

/**
* Set representing set of vertex numbers
*/
typedef QSet<int> Vertexes;

/**A maptool to move/deletes/adds vertices of line or polygon features*/
class QgsMapToolNodeTool: public QgsMapToolVertexEdit
{
Q_OBJECT
public:
QgsMapToolNodeTool( QgsMapCanvas* canvas );
virtual ~QgsMapToolNodeTool();

void canvasMoveEvent( QMouseEvent * e );

void canvasDoubleClickEvent( QMouseEvent * e );

void canvasPressEvent( QMouseEvent * e );

void canvasReleaseEvent( QMouseEvent * e );

void keyPressEvent( QKeyEvent* e );

void keyReleaseEvent( QKeyEvent* e );

//! called when map tool is being deactivated
void deactivate();

/**
* Returns closest vertex to given point from selected feature
*/
QgsPoint closestVertex( QgsPoint point );

public slots:
void selectedFeatureDestroyed();

private:
/**
* Deletes the rubber band pointers and clears mRubberBands
*/
void removeRubberBands();

/**
* Creating rubber band marker for movin of point
* @param center coordinates of point to be moved
* @param vlayer vector layer on which we are working
* @return rubber band marker
*/
QgsRubberBand* createRubberBandMarker( QgsPoint center, QgsVectorLayer* vlayer );

/**
* Function to check if selected feature exists and is same with original one
* stored in internal structures
* @param vlayer vector layer for checking
* @return if feature is same as one in internal structures
*/
bool checkCorrectnessOfFeature( QgsVectorLayer* vlayer );

/**
* Creates rubberbands for moving points
*/
void createMovingRubberBands();

/**
* Creates rubber bands for ther features when topology editing is enabled
* @param vlayer vector layer for ehich rubber bands are created
* @param vertexMap map of vertexes
* @param vertex currently processed vertex
*/
void createTopologyRubberBands( QgsVectorLayer* vlayer, const QList<QgsVertexEntry*> &vertexMap, int vertex );

/** The position of the vertex to move (in map coordinates) to exclude later from snapping*/
QList<QgsPoint> mExcludePoint;

/** rubber bands */
QList<QgsRubberBand*> mRubberBands;

/** list of topology rubber bands */
QList<QgsRubberBand*> mTopologyRubberBand;

/** vertexes of rubberbands which are to be moved */
QMap<QgsFeatureId, Vertexes*> mTopologyMovingVertexes;

/** vertexes of features with int id which were already added tu rubber bands */
QMap<QgsFeatureId, Vertexes*> mTopologyRubberBandVertexes;

/** object containing selected feature and it's vertexes */
QgsSelectedFeature *mSelectedFeature;

/** flag if selection rectangle is active */
bool mSelectionRectangle;

/** flag if moving of vertexes is occuring */
bool mMoving;

/** flag if click action is still in queue to be processed */
bool mClicked;

/** flag if crtl is pressed */
bool mCtrl;

/** flag if selection of another feature can occur */
bool mSelectAnother;

/** feature id of another feature where user clicked */
QgsFeatureId mAnother;

/** stored position of last press down action to count how much vertexes should be moved */
QgsPoint* mLastCoordinates;

/** closest vertex to click */
QgsPoint mClosestVertex;

/** backup of map coordinates to be able to count change between moves */
QgsPoint mPosMapCoordBackup;

/** active rubberband for selecting vertexes */
QRubberBand *mRubberBand;

/** rectangle defining area for selecting vertexes */
QRect* mRect;

/** flag to tell if edition points */
bool mIsPoint;
};

#endif
576 changes: 576 additions & 0 deletions src/app/nodetool/qgsselectedfeature.cpp

Large diffs are not rendered by default.

194 changes: 18 additions & 176 deletions src/app/qgsmaptoolnodetool.h → src/app/nodetool/qgsselectedfeature.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/***************************************************************************
qgsmaptoolnodetool.h - add/move/delete vertex integrated in one tool
qgsselectedfeature.h - selected feature of nodetool
---------------------
begin : April 2009
copyright : (C) 2009 by Richard Kostecky
Expand All @@ -13,61 +13,24 @@
* *
***************************************************************************/

#ifndef QGSMAPTOOLNODETOOL_H
#define QGSMAPTOOLNODETOOL_H
#ifndef QGSSELECTEDFEATURE_H
#define QGSSELECTEDFEATURE_H

#include "nodetool/qgsselectedfeature.h"

#include "qgsmaptoolvertexedit.h"
#include "qgsfeature.h"
#include "qgsvertexmarker.h"
#include "qgsgeometryvalidator.h"
#include "qgsmapcanvas.h"
#include "qgslogger.h"
#include "qgsgeometry.h"

#include <QRect>
#include <QRubberBand>
#include <QObject>

class QgsMapCanvas;
class QgsVectorLayer;
class QgsMapLayer;
class QgsRubberBand;
class QgsGeometryValidator;
class QgsVertexMarker;

class VertexEntry
{
bool mSelected;
QgsPoint mPoint;
int mEquals;
bool mInRubberBand;
int mRubberBandNr;
int mIndex;
int mOriginalIndex;
int mPenWidth;
QString mToolTip;
QgsVertexMarker::IconType mType;
QgsVertexMarker *mMarker;
QgsMapCanvas *mCanvas;
QgsMapLayer *mLayer;
public:
VertexEntry( QgsMapCanvas *canvas, QgsMapLayer *layer, QgsPoint p, int originalIndex, QString tooltip = QString::null, QgsVertexMarker::IconType type = QgsVertexMarker::ICON_BOX, int penWidth = 2 );
~VertexEntry();

QgsPoint point() const { return mPoint; }
int equals() const { return mEquals; }
bool isSelected() const { return mSelected; }
bool isInRubberBand() const { return mInRubberBand; }

void setCenter( QgsPoint p );
void moveCenter( double x, double y );
void setEqual( int index ) { mEquals = index; }
void setSelected( bool selected = true );
void setInRubberBand( bool inRubberBand = true ) { mInRubberBand = inRubberBand; }
int rubberBandNr() const { return mRubberBandNr; }
int index() { return mIndex; }

void setRubberBandValues( bool inRubberBand, int rubberBandNr, int indexInRubberBand );
void update();
};

/**
* Set representing set of vertex numbers
*/
typedef QSet<int> Vertexes;
class QgsVertexEntry;

/**
* Constant representing zero value for distance. It's 0 because of error in double counting.
Expand All @@ -77,13 +40,13 @@ const static double ZERO_TOLERANCE = 0.000000001;
/**
* Class that keeps the selected feature
*/
class SelectedFeature: public QObject
class QgsSelectedFeature: public QObject
{
Q_OBJECT

public:
SelectedFeature( QgsFeatureId id, QgsVectorLayer *layer, QgsMapCanvas *canvas );
~SelectedFeature();
QgsSelectedFeature( QgsFeatureId id, QgsVectorLayer *layer, QgsMapCanvas *canvas );
~QgsSelectedFeature();

/**
* Setting selected feature
Expand Down Expand Up @@ -148,7 +111,7 @@ class SelectedFeature: public QObject
* Getting vertex map of vertexes
* @return currently used vertex map
*/
QList<VertexEntry*> &vertexMap();
QList<QgsVertexEntry*> &vertexMap();

/**
* Updates whole selection object from the selected object
Expand Down Expand Up @@ -253,7 +216,7 @@ class SelectedFeature: public QObject
bool mChangingGeometry;
QgsVectorLayer* mVlayer;
QgsRubberBand* mRubberBand;
QList<VertexEntry*> mVertexMap;
QList<QgsVertexEntry*> mVertexMap;
QgsMapCanvas* mCanvas;

QgsGeometryValidator *mValidator;
Expand All @@ -262,125 +225,4 @@ class SelectedFeature: public QObject
QList< QgsVertexMarker * > mGeomErrorMarkers;
};

/**A maptool to move/deletes/adds vertices of line or polygon features*/
class QgsMapToolNodeTool: public QgsMapToolVertexEdit
{
Q_OBJECT
public:
QgsMapToolNodeTool( QgsMapCanvas* canvas );
virtual ~QgsMapToolNodeTool();

void canvasMoveEvent( QMouseEvent * e );

void canvasDoubleClickEvent( QMouseEvent * e );

void canvasPressEvent( QMouseEvent * e );

void canvasReleaseEvent( QMouseEvent * e );

void keyPressEvent( QKeyEvent* e );

void keyReleaseEvent( QKeyEvent* e );

//! called when map tool is being deactivated
void deactivate();

/**
* Returns closest vertex to given point from selected feature
*/
QgsPoint closestVertex( QgsPoint point );

public slots:
void selectedFeatureDestroyed();

private:
/**
* Deletes the rubber band pointers and clears mRubberBands
*/
void removeRubberBands();

/**
* Creating rubber band marker for movin of point
* @param center coordinates of point to be moved
* @param vlayer vector layer on which we are working
* @return rubber band marker
*/
QgsRubberBand* createRubberBandMarker( QgsPoint center, QgsVectorLayer* vlayer );

/**
* Function to check if selected feature exists and is same with original one
* stored in internal structures
* @param vlayer vector layer for checking
* @return if feature is same as one in internal structures
*/
bool checkCorrectnessOfFeature( QgsVectorLayer* vlayer );

/**
* Creates rubberbands for moving points
*/
void createMovingRubberBands();

/**
* Creates rubber bands for ther features when topology editing is enabled
* @param vlayer vector layer for ehich rubber bands are created
* @param vertexMap map of vertexes
* @param vertex currently processed vertex
*/
void createTopologyRubberBands( QgsVectorLayer* vlayer, const QList<VertexEntry*> &vertexMap, int vertex );

/** The position of the vertex to move (in map coordinates) to exclude later from snapping*/
QList<QgsPoint> mExcludePoint;

/** rubber bands */
QList<QgsRubberBand*> mRubberBands;

/** list of topology rubber bands */
QList<QgsRubberBand*> mTopologyRubberBand;

/** vertexes of rubberbands which are to be moved */
QMap<QgsFeatureId, Vertexes*> mTopologyMovingVertexes;

/** vertexes of features with int id which were already added tu rubber bands */
QMap<QgsFeatureId, Vertexes*> mTopologyRubberBandVertexes;

/** object containing selected feature and it's vertexes */
SelectedFeature *mSelectedFeature;

/** flag if selection rectangle is active */
bool mSelectionRectangle;

/** flag if moving of vertexes is occuring */
bool mMoving;

/** flag if click action is still in queue to be processed */
bool mClicked;

/** flag if crtl is pressed */
bool mCtrl;

/** flag if selection of another feature can occur */
bool mSelectAnother;

/** feature id of another feature where user clicked */
QgsFeatureId mAnother;

/** stored position of last press down action to count how much vertexes should be moved */
QgsPoint* mLastCoordinates;

/** closest vertex to click */
QgsPoint mClosestVertex;

/** backup of map coordinates to be able to count change between moves */
QgsPoint mPosMapCoordBackup;

/** active rubberband for selecting vertexes */
QRubberBand *mRubberBand;

/** rectangle defining area for selecting vertexes */
QRect* mRect;

/** flag to tell if edition points */
bool mIsPoint;
};

#endif
98 changes: 98 additions & 0 deletions src/app/nodetool/qgsvertexentry.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/***************************************************************************
qgsvertexentry.cpp - entry for vertex of nodetool
---------------------
begin : April 2009
copyright : (C) 2009 by Richard Kostecky
email : csf dot kostej at mail dot com
***************************************************************************
* *
* 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. *
* *
***************************************************************************/

#include "nodetool/qgsvertexentry.h"

#include <qgsmaprenderer.h>

QgsVertexEntry::QgsVertexEntry( QgsMapCanvas *canvas, QgsMapLayer *layer, QgsPoint p, int originalIndex, QString tooltip, QgsVertexMarker::IconType type, int penWidth )
: mSelected( false )
, mEquals( -1 )
, mInRubberBand( false )
, mRubberBandNr( 0 )
, mOriginalIndex( originalIndex )
, mPenWidth( penWidth )
, mToolTip( tooltip )
, mType( type )
, mMarker( 0 )
, mCanvas( canvas )
, mLayer( layer )
{
setCenter( p );
}

QgsVertexEntry::~QgsVertexEntry()
{
if ( mMarker )
{
delete mMarker;
mMarker = 0;
}
}

void QgsVertexEntry::setCenter( QgsPoint p )
{
mPoint = p;
p = mCanvas->mapRenderer()->layerToMapCoordinates( mLayer, p );

if ( mCanvas->extent().contains( p ) )
{
if ( !mMarker )
{
mMarker = new QgsVertexMarker( mCanvas );
mMarker->setIconType( mType );
mMarker->setColor( mSelected ? Qt::blue : Qt::red );
mMarker->setPenWidth( mPenWidth );

if ( !mToolTip.isEmpty() )
mMarker->setToolTip( mToolTip );
}

mMarker->setCenter( p );
}
else if ( mMarker )
{
delete mMarker;
mMarker = 0;
}
}

void QgsVertexEntry::moveCenter( double x, double y )
{
mPoint += QgsVector( x, y );
setCenter( mPoint );
}

void QgsVertexEntry::setSelected( bool selected )
{
mSelected = selected;
if ( mMarker )
{
mMarker->setColor( mSelected ? Qt::blue : Qt::red );
}
}

void QgsVertexEntry::setRubberBandValues( bool inRubberBand, int rubberBandNr, int indexInRubberBand )
{
mIndex = indexInRubberBand;
mInRubberBand = inRubberBand;
mRubberBandNr = rubberBandNr;
}

void QgsVertexEntry::update()
{
if ( mMarker )
mMarker->update();
}
67 changes: 67 additions & 0 deletions src/app/nodetool/qgsvertexentry.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/***************************************************************************
qgsvertexentry.h - entry for vertex of nodetool
---------------------
begin : April 2009
copyright : (C) 2009 by Richard Kostecky
email : csf dot kostej at mail dot com
***************************************************************************
* *
* 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. *
* *
***************************************************************************/

#ifndef QGSVERTEXENTRY_H
#define QGSVERTEXENTRY_H

#include <qgspoint.h>
#include <qgsvertexmarker.h>
#include <qgsmapcanvas.h>
#include <qgsmaplayer.h>

class QgsVertexEntry
{
bool mSelected;
QgsPoint mPoint;
int mEquals;
bool mInRubberBand;
int mRubberBandNr;
int mIndex;
int mOriginalIndex;
int mPenWidth;
QString mToolTip;
QgsVertexMarker::IconType mType;
QgsVertexMarker *mMarker;
QgsMapCanvas *mCanvas;
QgsMapLayer *mLayer;

public:
QgsVertexEntry( QgsMapCanvas *canvas,
QgsMapLayer *layer,
QgsPoint p,
int originalIndex,
QString tooltip = QString::null,
QgsVertexMarker::IconType type = QgsVertexMarker::ICON_BOX,
int penWidth = 2 );
~QgsVertexEntry();

QgsPoint point() const { return mPoint; }
int equals() const { return mEquals; }
bool isSelected() const { return mSelected; }
bool isInRubberBand() const { return mInRubberBand; }

void setCenter( QgsPoint p );
void moveCenter( double x, double y );
void setEqual( int index ) { mEquals = index; }
void setSelected( bool selected = true );
void setInRubberBand( bool inRubberBand = true ) { mInRubberBand = inRubberBand; }
int rubberBandNr() const { return mRubberBandNr; }
int index() { return mIndex; }

void setRubberBandValues( bool inRubberBand, int rubberBandNr, int indexInRubberBand );
void update();
};

#endif
3 changes: 2 additions & 1 deletion src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@
#include "qgsmaptoolmeasureangle.h"
#include "qgsmaptoolmovefeature.h"
#include "qgsmaptoolmovevertex.h"
#include "qgsmaptoolnodetool.h"
#include "qgsmaptoolpan.h"
#include "qgsmaptoolselect.h"
#include "qgsmaptoolselectrectangle.h"
Expand All @@ -230,6 +229,8 @@
#include "qgsmaptoolrotatelabel.h"
#include "qgsmaptoolchangelabelproperties.h"

#include "nodetool/qgsmaptoolnodetool.h"

//
// Conditional Includes
//
Expand Down