QGIS API Documentation  2.12.0-Lyon
qgsmaptooledit.cpp
Go to the documentation of this file.
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 
16 #include "qgsmaptooledit.h"
17 #include "qgsproject.h"
18 #include "qgsmapcanvas.h"
19 #include "qgsgeometryrubberband.h"
20 #include "qgsrubberband.h"
21 #include "qgsvectorlayer.h"
22 
23 #include <QKeyEvent>
24 #include <QSettings>
25 
26 
28  : QgsMapTool( canvas )
29 {
30 }
31 
33 {
34 }
35 
36 
38 {
39  QSettings settings;
40  QgsRubberBand* rb = new QgsRubberBand( mCanvas, geometryType );
41  rb->setWidth( settings.value( "/qgis/digitizing/line_width", 1 ).toInt() );
42  QColor color( settings.value( "/qgis/digitizing/line_color_red", 255 ).toInt(),
43  settings.value( "/qgis/digitizing/line_color_green", 0 ).toInt(),
44  settings.value( "/qgis/digitizing/line_color_blue", 0 ).toInt() );
45  double myAlpha = settings.value( "/qgis/digitizing/line_color_alpha", 200 ).toInt() / 255.0;
46  if ( alternativeBand )
47  {
48  myAlpha = myAlpha * settings.value( "/qgis/digitizing/line_color_alpha_scale", 0.75 ).toDouble();
49  rb->setLineStyle( Qt::DotLine );
50  }
51  if ( geometryType == QGis::Polygon )
52  {
53  color.setAlphaF( myAlpha );
54  }
55  color.setAlphaF( myAlpha );
56  rb->setColor( color );
57  rb->show();
58  return rb;
59 }
60 
62 {
63  return qobject_cast<QgsVectorLayer *>( mCanvas->currentLayer() );
64 }
65 
66 
68 {
69  if ( !mCanvas )
70  {
71  return 1;
72  }
73 
74  //find out current vector layer
76 
77  if ( !vlayer )
78  {
79  return 2;
80  }
81 
83  for ( ; list_it != geom.constEnd(); ++list_it )
84  {
85  vlayer->addTopologicalPoints( *list_it );
86  }
87  return 0;
88 }
89 
91 {
92  QSettings settings;
93  QgsGeometryRubberBand* rb = new QgsGeometryRubberBand( mCanvas, geometryType );
94  QColor color( settings.value( "/qgis/digitizing/line_color_red", 255 ).toInt(),
95  settings.value( "/qgis/digitizing/line_color_green", 0 ).toInt(),
96  settings.value( "/qgis/digitizing/line_color_blue", 0 ).toInt() );
97  double myAlpha = settings.value( "/qgis/digitizing/line_color_alpha", 200 ).toInt() / 255.0 ;
98  color.setAlphaF( myAlpha );
99  rb->setOutlineColor( color );
100  rb->setFillColor( color );
101  rb->show();
102  return rb;
103 }
104 
106 {
107  emit messageEmitted( tr( "No active vector layer" ) );
108 }
109 
111 {
112  emit messageEmitted( tr( "Layer not editable" ) );
113 }
void setWidth(int width)
Set the width of the line.
QgsGeometryRubberBand * createGeometryRubberBand(QGis::GeometryType geometryType=QGis::Line) const
int addTopologicalPoints(const QgsGeometry *geom)
Adds topological points for every vertex of the geometry.
void setLineStyle(Qt::PenStyle penStyle)
Set the style of the line.
void setOutlineColor(const QColor &c)
Sets outline color for vertex markes.
void setFillColor(const QColor &c)
Sets fill color for vertex markers.
GeometryType
Definition: qgis.h:104
virtual ~QgsMapToolEdit()
QString tr(const char *sourceText, const char *disambiguation, int n)
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:107
QgsMapCanvas * mCanvas
pointer to map canvas
Definition: qgsmaptool.h:193
void notifyNotEditableLayer()
Display a timed message bar noting the active vector layer is not editable.
QgsMapToolEdit(QgsMapCanvas *canvas)
int toInt(bool *ok) const
A class for drawing transient features (e.g.
Definition: qgsrubberband.h:32
QgsRubberBand * createRubberBand(QGis::GeometryType geometryType=QGis::Line, bool alternativeBand=false)
Creates a rubber band with the color/line width from the QGIS settings.
void messageEmitted(QString message, QgsMessageBar::MessageLevel=QgsMessageBar::INFO)
emit a message
QgsMapLayer * currentLayer()
returns current layer (set by legend widget)
Abstract base class for all map tools.
Definition: qgsmaptool.h:50
QgsVectorLayer * currentVectorLayer()
Returns the current vector layer of the map canvas or 0.
QVariant value(const QString &key, const QVariant &defaultValue) const
void notifyNotVectorLayer()
Display a timed message bar noting the active layer is not vector.
A rubberband class for QgsAbstractGeometryV2 (considering curved geometries)
int addTopologicalPoints(const QList< QgsPoint > &geom)
Adds vertices to other features to keep topology up to date, e.g.
double toDouble(bool *ok) const
void setColor(const QColor &color)
Set the color for the rubberband.
const_iterator constEnd() const
const_iterator constBegin() const
Represents a vector layer which manages a vector based data sets.