~ubuntu-branches/ubuntu/trusty/qgis/trusty

« back to all changes in this revision

Viewing changes to src/app/qgsmaptooledit.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Johan Van de Wauw
  • Date: 2010-07-11 20:23:24 UTC
  • mfrom: (3.1.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100711202324-5ktghxa7hracohmr
Tags: 1.4.0+12730-3ubuntu1
* Merge from Debian unstable (LP: #540941).
* Fix compilation issues with QT 4.7
* Add build-depends on libqt4-webkit-dev 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
    qgsmaptooledit.cpp  -  base class for editing map tools
 
3
    ---------------------
 
4
    begin                : Juli 2007
 
5
    copyright            : (C) 2007 by Marco Hugentobler
 
6
    email                : marco dot hugentobler at karto dot baug dot ethz dot ch
 
7
 ***************************************************************************
 
8
 *                                                                         *
 
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.                                   *
 
13
 *                                                                         *
 
14
 ***************************************************************************/
 
15
/* $Id$ */
 
16
 
 
17
#include "qgsmaptooledit.h"
 
18
#include "qgsproject.h"
 
19
#include "qgsmapcanvas.h"
 
20
#include "qgsrubberband.h"
 
21
#include "qgsvectorlayer.h"
 
22
#include <QKeyEvent>
 
23
#include <QSettings>
 
24
 
 
25
QgsMapToolEdit::QgsMapToolEdit( QgsMapCanvas* canvas ): QgsMapTool( canvas )
 
26
{
 
27
  mSnapper.setMapCanvas( canvas );
 
28
}
 
29
 
 
30
 
 
31
QgsMapToolEdit::~QgsMapToolEdit()
 
32
{
 
33
 
 
34
}
 
35
 
 
36
int QgsMapToolEdit::insertSegmentVerticesForSnap( const QList<QgsSnappingResult>& snapResults, QgsVectorLayer* editedLayer )
 
37
{
 
38
  QgsPoint layerPoint;
 
39
 
 
40
  if ( !editedLayer || !editedLayer->isEditable() )
 
41
  {
 
42
    return 1;
 
43
  }
 
44
 
 
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 )
 
49
  {
 
50
    QgsPoint layerPoint = toLayerCoordinates( editedLayer, it->snappedVertex );
 
51
    it->snappedVertex = layerPoint;
 
52
  }
 
53
 
 
54
  return editedLayer->insertSegmentVerticesForSnap( transformedSnapResults );
 
55
}
 
56
 
 
57
QgsPoint QgsMapToolEdit::snapPointFromResults( const QList<QgsSnappingResult>& snapResults, const QPoint& screenCoords )
 
58
{
 
59
  if ( snapResults.size() < 1 )
 
60
  {
 
61
    return toMapCoordinates( screenCoords );
 
62
  }
 
63
  else
 
64
  {
 
65
    return snapResults.constBegin()->snappedVertex;
 
66
  }
 
67
}
 
68
 
 
69
QgsRubberBand* QgsMapToolEdit::createRubberBand( bool isPolygon )
 
70
{
 
71
  QSettings settings;
 
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() );
 
78
  rb->show();
 
79
  return rb;
 
80
}
 
81
 
 
82
QgsVectorLayer* QgsMapToolEdit::currentVectorLayer()
 
83
{
 
84
  QgsMapLayer* currentLayer = mCanvas->currentLayer();
 
85
  if ( !currentLayer )
 
86
  {
 
87
    return 0;
 
88
  }
 
89
 
 
90
  QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer *>( currentLayer );
 
91
  if ( !vlayer )
 
92
  {
 
93
    return 0;
 
94
  }
 
95
  return vlayer;
 
96
}
 
97
 
 
98
 
 
99
int QgsMapToolEdit::addTopologicalPoints( const QList<QgsPoint>& geom )
 
100
{
 
101
  if ( !mCanvas )
 
102
  {
 
103
    return 1;
 
104
  }
 
105
 
 
106
  //find out current vector layer
 
107
  QgsVectorLayer *vlayer = currentVectorLayer();
 
108
 
 
109
  if ( !vlayer )
 
110
  {
 
111
    return 2;
 
112
  }
 
113
 
 
114
  QList<QgsPoint>::const_iterator list_it = geom.constBegin();
 
115
  for ( ; list_it != geom.constEnd(); ++list_it )
 
116
  {
 
117
    vlayer->addTopologicalPoints( *list_it );
 
118
  }
 
119
  return 0;
 
120
}
 
121
 
 
122