~ubuntu-branches/ubuntu/wily/qgis/wily

« back to all changes in this revision

Viewing changes to src/app/qgsmaptoolsplitfeatures.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
    qgsmaptoolsplitfeatures.cpp
 
3
    ---------------------------
 
4
    begin                : August 2007
 
5
    copyright            : (C) 2007 by Marco Hugentobler
 
6
    email                : marco.hugentobler@karto.baug.ethz.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 "qgsmaptoolsplitfeatures.h"
 
18
#include "qgsmapcanvas.h"
 
19
#include "qgsproject.h"
 
20
#include "qgsrubberband.h"
 
21
#include "qgsvectorlayer.h"
 
22
#include <QMessageBox>
 
23
#include <QMouseEvent>
 
24
 
 
25
QgsMapToolSplitFeatures::QgsMapToolSplitFeatures( QgsMapCanvas* canvas ): QgsMapToolCapture( canvas, QgsMapToolCapture::CaptureLine )
 
26
{
 
27
 
 
28
}
 
29
 
 
30
QgsMapToolSplitFeatures::~QgsMapToolSplitFeatures()
 
31
{
 
32
 
 
33
}
 
34
 
 
35
void QgsMapToolSplitFeatures::canvasReleaseEvent( QMouseEvent * e )
 
36
{
 
37
  //check if we operate on a vector layer
 
38
  QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mCanvas->currentLayer() );
 
39
 
 
40
  if ( !vlayer )
 
41
  {
 
42
    QMessageBox::information( 0, tr( "Not a vector layer" ),
 
43
                              tr( "The current layer is not a vector layer" ) );
 
44
    return;
 
45
  }
 
46
 
 
47
  if ( !vlayer->isEditable() )
 
48
  {
 
49
    QMessageBox::information( 0, tr( "Layer not editable" ),
 
50
                              tr( "Cannot edit the vector layer. To make it editable, go to the file item "
 
51
                                  "of the layer, right click and check 'Allow Editing'." ) );
 
52
    return;
 
53
  }
 
54
 
 
55
  //add point to list and to rubber band
 
56
  int error = addVertex( e->pos() );
 
57
  if ( error == 1 )
 
58
  {
 
59
    //current layer is not a vector layer
 
60
    return;
 
61
  }
 
62
  else if ( error == 2 )
 
63
  {
 
64
    //problem with coordinate transformation
 
65
    QMessageBox::information( 0, tr( "Coordinate transform error" ),
 
66
                              tr( "Cannot transform the point to the layers coordinate system" ) );
 
67
    return;
 
68
  }
 
69
 
 
70
  if ( e->button() == Qt::LeftButton )
 
71
  {
 
72
    mCapturing = TRUE;
 
73
  }
 
74
  else if ( e->button() == Qt::RightButton )
 
75
  {
 
76
    mCapturing = FALSE;
 
77
    delete mRubberBand;
 
78
    mRubberBand = 0;
 
79
 
 
80
    //bring up dialog if a split was not possible (polygon) or only done once (line)
 
81
    int topologicalEditing = QgsProject::instance()->readNumEntry( "Digitizing", "/TopologicalEditing", 0 );
 
82
    vlayer->beginEditCommand( tr( "Features split" ) );
 
83
    int returnCode = vlayer->splitFeatures( mCaptureList, topologicalEditing );
 
84
    vlayer->endEditCommand();
 
85
    if ( returnCode == 4 )
 
86
    {
 
87
      QMessageBox::warning( 0, tr( "No feature split done" ), tr( "If there are selected features, the split tool only applies to the selected ones. If you like to split all features under the split line, clear the selection" ) );
 
88
    }
 
89
    else if ( returnCode != 0 )
 
90
    {
 
91
      //several intersections but only one split (most likely line)
 
92
      QMessageBox::warning( 0, tr( "Split error" ), tr( "An error occured during feature splitting" ) );
 
93
    }
 
94
 
 
95
    mCaptureList.clear();
 
96
    mCanvas->refresh();
 
97
  }
 
98
}