1
/***************************************************************************
2
qgsmaptooledit.cpp - base class for editing map tools
5
copyright : (C) 2007 by Marco Hugentobler
6
email : marco dot hugentobler at karto dot baug dot ethz dot ch
7
***************************************************************************
9
* This program is free software; you can redistribute it and/or modify *
10
* it under the terms of the GNU General Public License as published by *
11
* the Free Software Foundation; either version 2 of the License, or *
12
* (at your option) any later version. *
14
***************************************************************************/
17
#include "qgsmaptooledit.h"
18
#include "qgsproject.h"
19
#include "qgsmapcanvas.h"
20
#include "qgsrubberband.h"
21
#include "qgsvectorlayer.h"
25
QgsMapToolEdit::QgsMapToolEdit( QgsMapCanvas* canvas ): QgsMapTool( canvas )
27
mSnapper.setMapCanvas( canvas );
31
QgsMapToolEdit::~QgsMapToolEdit()
36
int QgsMapToolEdit::insertSegmentVerticesForSnap( const QList<QgsSnappingResult>& snapResults, QgsVectorLayer* editedLayer )
40
if ( !editedLayer || !editedLayer->isEditable() )
45
//transform snaping coordinates to layer crs first
46
QList<QgsSnappingResult> transformedSnapResults = snapResults;
47
QList<QgsSnappingResult>::iterator it = transformedSnapResults.begin();
48
for ( ; it != transformedSnapResults.constEnd(); ++it )
50
QgsPoint layerPoint = toLayerCoordinates( editedLayer, it->snappedVertex );
51
it->snappedVertex = layerPoint;
54
return editedLayer->insertSegmentVerticesForSnap( transformedSnapResults );
57
QgsPoint QgsMapToolEdit::snapPointFromResults( const QList<QgsSnappingResult>& snapResults, const QPoint& screenCoords )
59
if ( snapResults.size() < 1 )
61
return toMapCoordinates( screenCoords );
65
return snapResults.constBegin()->snappedVertex;
69
QgsRubberBand* QgsMapToolEdit::createRubberBand( bool isPolygon )
72
QgsRubberBand* rb = new QgsRubberBand( mCanvas, isPolygon );
73
QColor color( settings.value( "/qgis/digitizing/line_color_red", 255 ).toInt(),
74
settings.value( "/qgis/digitizing/line_color_green", 0 ).toInt(),
75
settings.value( "/qgis/digitizing/line_color_blue", 0 ).toInt() );
76
rb->setColor( color );
77
rb->setWidth( settings.value( "/qgis/digitizing/line_width", 1 ).toInt() );
82
QgsVectorLayer* QgsMapToolEdit::currentVectorLayer()
84
QgsMapLayer* currentLayer = mCanvas->currentLayer();
90
QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer *>( currentLayer );
99
int QgsMapToolEdit::addTopologicalPoints( const QList<QgsPoint>& geom )
106
//find out current vector layer
107
QgsVectorLayer *vlayer = currentVectorLayer();
114
QList<QgsPoint>::const_iterator list_it = geom.constBegin();
115
for ( ; list_it != geom.constEnd(); ++list_it )
117
vlayer->addTopologicalPoints( *list_it );