Expand Up
@@ -44,22 +44,6 @@ QgsMapToolNodeTool::~QgsMapToolNodeTool()
removeRubberBands ();
}
void QgsMapToolNodeTool::deactivate ()
{
removeRubberBands ();
delete mSelectedFeature ;
mSelectedFeature = 0 ;
mRubberBand = 0 ;
mSelectAnother = false ;
mCtrl = false ;
mMoving = true ;
mClicked = false ;
QgsMapTool::deactivate ();
}
void QgsMapToolNodeTool::createMovingRubberBands ()
{
int topologicalEditing = QgsProject::instance ()->readNumEntry ( " Digitizing" , " /TopologicalEditing" , 0 );
Expand Down
Expand Up
@@ -129,52 +113,6 @@ void QgsMapToolNodeTool::createMovingRubberBands()
}
}
QgsRubberBand* QgsMapToolNodeTool::createRubberBandMarker ( QgsPoint center, QgsVectorLayer* vlayer )
{
// create rubberband marker for moving points
QgsRubberBand* marker = new QgsRubberBand ( mCanvas , true );
marker->setColor ( Qt::red );
marker->setWidth ( 2 );
double movement = 4 ;
double s = QgsTolerance::toleranceInMapUnits ( movement, vlayer, mCanvas ->mapRenderer (), QgsTolerance::Pixels );
QgsPoint pom = toMapCoordinates ( vlayer, center );
pom.setX ( pom.x () - s );
pom.setY ( pom.y () - s );
marker->addPoint ( pom );
pom.setX ( pom.x () + 2 *s );
marker->addPoint ( pom );
pom.setY ( pom.y () + 2 *s );
marker->addPoint ( pom );
pom.setX ( pom.x () - 2 *s );
marker->addPoint ( pom );
pom.setY ( pom.y () - 2 *s );
marker->addPoint ( pom );
return marker;
}
void QgsMapToolNodeTool::removeRubberBands ()
{
// cleanup rubberbands and list
foreach ( QgsRubberBand *rb, mRubberBands )
{
delete rb;
}
mRubberBands .clear ();
foreach ( QgsRubberBand *rb, mTopologyRubberBand )
{
delete rb;
}
mTopologyRubberBand .clear ();
mTopologyMovingVertexes .clear ();
mTopologyRubberBandVertexes .clear ();
// remove all data from selected feature (no change to rubberbands itself)
if ( mSelectedFeature )
mSelectedFeature ->cleanRubberBandsData ();
}
void QgsMapToolNodeTool::createTopologyRubberBands ( QgsVectorLayer* vlayer, const QList<QgsVertexEntry*> &vertexMap, int vertex )
{
QMultiMap<double , QgsSnappingResult> currentResultList;
Expand Down
Expand Up
@@ -281,10 +219,123 @@ void QgsMapToolNodeTool::createTopologyRubberBands( QgsVectorLayer* vlayer, cons
}
}
void QgsMapToolNodeTool::selectedFeatureDestroyed ( )
void QgsMapToolNodeTool::canvasMoveEvent ( QMouseEvent * e )
{
QgsDebugMsg ( " Entered." );
mSelectedFeature = 0 ;
QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer *>( mCanvas ->currentLayer () );
if ( !mSelectedFeature || !vlayer || !mClicked )
return ;
if ( !vlayer )
return ;
mSelectAnother = false ;
if ( mMoving )
{
// create rubberband if none exists
if ( mRubberBands .empty () )
{
if ( mIsPoint )
{
QList<QgsVertexEntry*> &vertexMap = mSelectedFeature ->vertexMap ();
for ( int i = 0 ; i < vertexMap.size (); i++ )
{
if ( vertexMap[i]->isSelected () )
{
QgsRubberBand* rb = createRubberBandMarker ( vertexMap[i]->point (), vlayer );
mRubberBands .append ( rb );
}
}
}
createMovingRubberBands ();
QList<QgsSnappingResult> snapResults;
QgsPoint posMapCoord = snapPointFromResults ( snapResults, e->pos () );
mPosMapCoordBackup = posMapCoord;
}
else
{
// move rubberband
QList<QgsSnappingResult> snapResults;
QgsPoint firstCoords = mCanvas ->getCoordinateTransform ()->toMapPoint ( mLastCoordinates ->x (), mLastCoordinates ->y () );
QList<QgsPoint> excludePoints;
excludePoints.append ( mClosestVertex );
mSnapper .snapToBackgroundLayers ( e->pos (), snapResults, excludePoints );
// get correct coordinates to move
QgsPoint posMapCoord = snapPointFromResults ( snapResults, e->pos () );
if ( snapResults.size () > 0 )
{
firstCoords = toMapCoordinates ( vlayer, mClosestVertex );
}
// special handling of points
if ( mIsPoint )
{
double offsetX = posMapCoord.x () - firstCoords.x ();
double offsetY = posMapCoord.y () - firstCoords.y ();
for ( int i = 0 ; i < mRubberBands .size (); i++ )
{
mRubberBands [i]->setTranslationOffset ( offsetX, offsetY );
}
return ;
}
// move points
QList<QgsVertexEntry*> &vertexMap = mSelectedFeature ->vertexMap ();
for ( int i = 0 ; i < vertexMap.size (); i++ )
{
if ( vertexMap[i]->isSelected () )
{
QgsPoint mapCoords = toMapCoordinates ( vlayer, vertexMap[i]->point () );
double x = mapCoords.x () + posMapCoord.x () - firstCoords.x ();
double y = mapCoords.y () + posMapCoord.y () - firstCoords.y ();
mRubberBands [vertexMap[i]->rubberBandNr ()]->movePoint ( vertexMap[i]->rubberBandIndex (), QgsPoint ( x, y ) );
if ( vertexMap[i]->rubberBandIndex () == 0 )
{
mRubberBands [vertexMap[i]->rubberBandNr ()]->movePoint ( 0 , QgsPoint ( x, y ) );
}
}
}
// topological editing
double offsetX = posMapCoord.x () - mPosMapCoordBackup .x ();
double offsetY = posMapCoord.y () - mPosMapCoordBackup .y ();
for ( int i = 0 ; i < mTopologyRubberBand .size (); i++ )
{
for ( int pointIndex = 0 ; pointIndex < mTopologyRubberBand [i]->numberOfVertices () - 1 ; pointIndex++ )
{
if ( mTopologyRubberBandVertexes [i]->contains ( pointIndex ) )
{
const QgsPoint* point = mTopologyRubberBand [i]->getPoint ( 0 , pointIndex );
if ( point == 0 )
{
break ;
}
mTopologyRubberBand [i]->movePoint ( pointIndex, QgsPoint ( point->x () + offsetX, point->y () + offsetY ) );
if ( pointIndex == 0 )
{
mTopologyRubberBand [i]->movePoint ( pointIndex , QgsPoint ( point->x () + offsetX, point->y () + offsetY ) );
}
}
}
}
mPosMapCoordBackup = posMapCoord;
}
}
else
{
if ( !mSelectionRectangle )
{
mSelectionRectangle = true ;
mRubberBand = new QRubberBand ( QRubberBand::Rectangle, mCanvas );
mRect = new QRect ();
mRect ->setTopLeft ( QPoint ( mLastCoordinates ->x (), mLastCoordinates ->y () ) );
}
mRect ->setBottomRight ( e->pos () );
QRect normalizedRect = mRect ->normalized ();
mRubberBand ->setGeometry ( normalizedRect );
mRubberBand ->show ();
}
}
void QgsMapToolNodeTool::canvasPressEvent ( QMouseEvent * e )
Expand All
@@ -293,8 +344,7 @@ void QgsMapToolNodeTool::canvasPressEvent( QMouseEvent * e )
QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer *>( mCanvas ->currentLayer () );
mClicked = true ;
mLastCoordinates = QgsPoint ( e->pos ().x (), e->pos ().y () );
mLastCoordinates = new QgsPoint ( e->pos ().x (), e->pos ().y () );
QList<QgsSnappingResult> snapResults;
if ( !mSelectedFeature )
{
Expand All
@@ -314,14 +364,13 @@ void QgsMapToolNodeTool::canvasPressEvent( QMouseEvent * e )
else
{
// some feature already selected
QgsPoint mapPoint = mCanvas ->getCoordinateTransform ()->toMapPoint ( e->pos ().x (), e->pos ().y () );
QgsPoint layerPoint = toLayerCoordinates ( vlayer, mapPoint );
QgsPoint mapCoordPoint = mCanvas ->getCoordinateTransform ()->toMapPoint ( e->pos ().x (), e->pos ().y () );
double tol = QgsTolerance::vertexSearchRadius ( vlayer, mCanvas ->mapRenderer () );
// get geometry and find if snapping is near it
int atVertex, beforeVertex, afterVertex;
double dist;
QgsPoint closestPoint = mSelectedFeature ->geometry ()->closestVertex ( layerPoint , atVertex, beforeVertex, afterVertex, dist );
mSelectedFeature ->geometry ()->closestVertex ( toLayerCoordinates ( vlayer, mapCoordPoint ) , atVertex, beforeVertex, afterVertex, dist );
dist = sqrt ( dist );
mSnapper .snapToCurrentLayer ( e->pos (), snapResults, QgsSnapper::SnapToVertex, tol );
Expand All
@@ -330,9 +379,7 @@ void QgsMapToolNodeTool::canvasPressEvent( QMouseEvent * e )
// for points only selecting another feature
// no vertexes found (selecting or inverting selection) if move
// or select another feature if clicked there
if ( !mIsPoint )
mSnapper .snapToCurrentLayer ( e->pos (), snapResults, QgsSnapper::SnapToSegment, tol );
mSnapper .snapToCurrentLayer ( e->pos (), snapResults, mIsPoint ? QgsSnapper::SnapToVertex : QgsSnapper::SnapToSegment, tol );
if ( snapResults.size () > 0 )
{
// need to check all if there is a point in my selected feature
Expand All
@@ -354,7 +401,8 @@ void QgsMapToolNodeTool::canvasPressEvent( QMouseEvent * e )
if ( !mSelectAnother )
{
mMoving = true ;
mClosestVertex = closestPoint;
QgsPoint point = mCanvas ->getCoordinateTransform ()->toMapPoint ( e->pos ().x (), e->pos ().y () );
mClosestVertex = closestVertex ( toLayerCoordinates ( vlayer, point ) );
if ( mIsPoint )
{
Expand All
@@ -368,7 +416,8 @@ void QgsMapToolNodeTool::canvasPressEvent( QMouseEvent * e )
mSelectedFeature ->invertVertexSelection ( snapResult.snappedVertexNr );
}
}
else
else if ( !mSelectedFeature ->isSelected ( snapResult.beforeVertexNr ) ||
!mSelectedFeature ->isSelected ( snapResult.afterVertexNr ) )
{
if ( !mCtrl )
{
Expand All
@@ -393,7 +442,8 @@ void QgsMapToolNodeTool::canvasPressEvent( QMouseEvent * e )
{
// some vertex selected
mMoving = true ;
mClosestVertex = closestPoint;
QgsPoint point = mCanvas ->getCoordinateTransform ()->toMapPoint ( e->pos ().x (), e->pos ().y () );
mClosestVertex = closestVertex ( toLayerCoordinates ( vlayer, point ) );
if ( mMoving )
{
if ( mCtrl )
Expand All
@@ -417,124 +467,10 @@ void QgsMapToolNodeTool::canvasPressEvent( QMouseEvent * e )
QgsDebugMsg ( " Leaving." );
}
void QgsMapToolNodeTool::canvasMoveEvent ( QMouseEvent * e )
void QgsMapToolNodeTool::selectedFeatureDestroyed ( )
{
QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer *>( mCanvas ->currentLayer () );
if ( !mSelectedFeature || !vlayer || !mClicked )
return ;
if ( !vlayer )
return ;
mSelectAnother = false ;
if ( mMoving )
{
// create rubberband if none exists
if ( mRubberBands .empty () )
{
if ( mIsPoint )
{
QList<QgsVertexEntry*> &vertexMap = mSelectedFeature ->vertexMap ();
for ( int i = 0 ; i < vertexMap.size (); i++ )
{
if ( vertexMap[i]->isSelected () )
{
QgsRubberBand* rb = createRubberBandMarker ( vertexMap[i]->point (), vlayer );
mRubberBands .append ( rb );
}
}
}
createMovingRubberBands ();
QList<QgsSnappingResult> snapResults;
QgsPoint posMapCoord = snapPointFromResults ( snapResults, e->pos () );
mPosMapCoordBackup = posMapCoord;
}
else
{
// move rubberband
QList<QgsSnappingResult> snapResults;
QgsPoint firstCoords = mCanvas ->getCoordinateTransform ()->toMapPoint ( mLastCoordinates .x (), mLastCoordinates .y () );
QList<QgsPoint> excludePoints;
excludePoints.append ( mClosestVertex );
mSnapper .snapToBackgroundLayers ( e->pos (), snapResults, excludePoints );
// get correct coordinates to move
QgsPoint posMapCoord = snapPointFromResults ( snapResults, e->pos () );
if ( snapResults.size () > 0 )
{
firstCoords = toMapCoordinates ( vlayer, mClosestVertex );
}
QgsVector offset = posMapCoord - firstCoords;
// special handling of points
if ( mIsPoint )
{
for ( int i = 0 ; i < mRubberBands .size (); i++ )
{
mRubberBands [i]->setTranslationOffset ( offset.x (), offset.y () );
}
return ;
}
// move points
QList<QgsVertexEntry*> &vertexMap = mSelectedFeature ->vertexMap ();
for ( int i = 0 ; i < vertexMap.size (); i++ )
{
if ( vertexMap[i]->isSelected () )
{
QgsPoint mapCoord = toMapCoordinates ( vlayer, vertexMap[i]->point () ) + offset;
mRubberBands [vertexMap[i]->rubberBandNr ()]->movePoint ( vertexMap[i]->rubberBandIndex (), mapCoord );
if ( vertexMap[i]->rubberBandIndex () == 0 )
{
mRubberBands [vertexMap[i]->rubberBandNr ()]->movePoint ( 0 , mapCoord );
}
}
}
// topological editing
offset = posMapCoord - mPosMapCoordBackup ;
for ( int i = 0 ; i < mTopologyRubberBand .size (); i++ )
{
for ( int pointIndex = 0 ; pointIndex < mTopologyRubberBand [i]->numberOfVertices () - 1 ; pointIndex++ )
{
if ( mTopologyRubberBandVertexes [i]->contains ( pointIndex ) )
{
const QgsPoint* point = mTopologyRubberBand [i]->getPoint ( 0 , pointIndex );
if ( point == 0 )
{
break ;
}
mTopologyRubberBand [i]->movePoint ( pointIndex, *point + offset );
if ( pointIndex == 0 )
{
mTopologyRubberBand [i]->movePoint ( pointIndex , *point + offset );
}
}
}
}
mPosMapCoordBackup = posMapCoord;
}
}
else
{
if ( !mSelectionRectangle )
{
mSelectionRectangle = true ;
mRubberBand = new QRubberBand ( QRubberBand::Rectangle, mCanvas );
mRect = new QRect ();
mRect ->setTopLeft ( QPoint ( mLastCoordinates .x (), mLastCoordinates .y () ) );
}
mRect ->setBottomRight ( e->pos () );
QRect normalizedRect = mRect ->normalized ();
mRubberBand ->setGeometry ( normalizedRect );
mRubberBand ->show ();
}
QgsDebugMsg ( " Entered." );
mSelectedFeature = 0 ;
}
void QgsMapToolNodeTool::canvasReleaseEvent ( QMouseEvent * e )
Expand All
@@ -553,15 +489,15 @@ void QgsMapToolNodeTool::canvasReleaseEvent( QMouseEvent * e )
mSelectionRectangle = false ;
QgsPoint coords = toMapCoordinates ( e->pos () );
QgsPoint firstCoords = mCanvas ->getCoordinateTransform ()->toMapPoint ( mLastCoordinates . x (), mLastCoordinates . y () );
QgsPoint firstCoords = mCanvas ->getCoordinateTransform ()->toMapPoint ( mLastCoordinates -> x (), mLastCoordinates -> y () );
if ( mRubberBand )
{
mRubberBand ->close ();
delete mRubberBand ;
mRubberBand = 0 ;
}
if ( mLastCoordinates . x () == e->pos ().x () && mLastCoordinates . y () == e->pos ().y () )
if ( mLastCoordinates -> x () == e->pos ().x () && mLastCoordinates -> y () == e->pos ().y () )
{
if ( mSelectAnother )
{
Expand Down
Expand Up
@@ -606,7 +542,7 @@ void QgsMapToolNodeTool::canvasReleaseEvent( QMouseEvent * e )
{
mMoving = false ;
QList<QgsSnappingResult> snapResults;
QgsPoint firstCoords = mCanvas ->getCoordinateTransform ()->toMapPoint ( mLastCoordinates . x (), mLastCoordinates . y () );
QgsPoint firstCoords = mCanvas ->getCoordinateTransform ()->toMapPoint ( mLastCoordinates -> x (), mLastCoordinates -> y () );
QList<QgsPoint> excludePoints;
excludePoints.append ( mClosestVertex );
mSnapper .snapToBackgroundLayers ( e->pos (), snapResults, excludePoints );
Expand Down
Expand Up
@@ -659,6 +595,46 @@ void QgsMapToolNodeTool::canvasReleaseEvent( QMouseEvent * e )
mExcludePoint .clear ();
}
void QgsMapToolNodeTool::deactivate ()
{
removeRubberBands ();
delete mSelectedFeature ;
mSelectedFeature = 0 ;
mRubberBand = 0 ;
mSelectAnother = false ;
mCtrl = false ;
mMoving = true ;
mClicked = false ;
QgsMapTool::deactivate ();
}
void QgsMapToolNodeTool::removeRubberBands ()
{
// cleanup rubberbands and list
foreach ( QgsRubberBand *rb, mRubberBands )
{
delete rb;
}
mRubberBands .clear ();
foreach ( QgsRubberBand *rb, mTopologyRubberBand )
{
delete rb;
}
mTopologyRubberBand .clear ();
mTopologyMovingVertexes .clear ();
mTopologyRubberBandVertexes .clear ();
// remove all data from selected feature (no change to rubberbands itself)
if ( mSelectedFeature )
mSelectedFeature ->cleanRubberBandsData ();
}
void QgsMapToolNodeTool::canvasDoubleClickEvent ( QMouseEvent * e )
{
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mCanvas ->currentLayer () );
Expand Down
Expand Up
@@ -710,6 +686,15 @@ void QgsMapToolNodeTool::canvasDoubleClickEvent( QMouseEvent * e )
mCanvas ->refresh ();
}
QgsPoint QgsMapToolNodeTool::closestVertex ( QgsPoint point )
{
int at;
int before;
int after;
double dist;
return mSelectedFeature ->geometry ()->closestVertex ( point, at, before, after, dist );
}
void QgsMapToolNodeTool::keyPressEvent ( QKeyEvent* e )
{
if ( e->key () == Qt::Key_Control )
Expand All
@@ -732,3 +717,26 @@ void QgsMapToolNodeTool::keyReleaseEvent( QKeyEvent* e )
mCanvas ->refresh ();
}
}
QgsRubberBand* QgsMapToolNodeTool::createRubberBandMarker ( QgsPoint center, QgsVectorLayer* vlayer )
{
// create rubberband marker for moving points
QgsRubberBand* marker = new QgsRubberBand ( mCanvas , true );
marker->setColor ( Qt::red );
marker->setWidth ( 2 );
double movement = 4 ;
double s = QgsTolerance::toleranceInMapUnits ( movement, vlayer, mCanvas ->mapRenderer (), QgsTolerance::Pixels );
QgsPoint pom = toMapCoordinates ( vlayer, center );
pom.setX ( pom.x () - s );
pom.setY ( pom.y () - s );
marker->addPoint ( pom );
pom.setX ( pom.x () + 2 *s );
marker->addPoint ( pom );
pom.setY ( pom.y () + 2 *s );
marker->addPoint ( pom );
pom.setX ( pom.x () - 2 *s );
marker->addPoint ( pom );
pom.setY ( pom.y () - 2 *s );
marker->addPoint ( pom );
return marker;
}