QGIS API Documentation  3.0.2-Girona (307d082)
qgsmapcanvassnappingutils.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsmapcanvassnappingutils.cpp
3  ---------------------
4  begin : December 2014
5  copyright : (C) 2014 by Martin Dobias
6  email : wonder dot sk at gmail dot com
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  ***************************************************************************/
16 
17 #include "qgsmapcanvas.h"
18 #include "qgsvectorlayer.h"
19 
20 #include <QApplication>
21 #include <QProgressDialog>
22 
24  : QgsSnappingUtils( parent )
25  , mCanvas( canvas )
26 
27 {
28  connect( canvas, &QgsMapCanvas::extentsChanged, this, &QgsMapCanvasSnappingUtils::canvasMapSettingsChanged );
29  connect( canvas, &QgsMapCanvas::destinationCrsChanged, this, &QgsMapCanvasSnappingUtils::canvasMapSettingsChanged );
30  connect( canvas, &QgsMapCanvas::layersChanged, this, &QgsMapCanvasSnappingUtils::canvasMapSettingsChanged );
31  connect( canvas, &QgsMapCanvas::currentLayerChanged, this, &QgsMapCanvasSnappingUtils::canvasCurrentLayerChanged );
32  connect( canvas, &QgsMapCanvas::transformContextChanged, this, &QgsMapCanvasSnappingUtils::canvasTransformContextChanged );
33  canvasMapSettingsChanged();
34  canvasCurrentLayerChanged();
35 }
36 
37 void QgsMapCanvasSnappingUtils::canvasMapSettingsChanged()
38 {
39  setMapSettings( mCanvas->mapSettings() );
40 }
41 
42 void QgsMapCanvasSnappingUtils::canvasTransformContextChanged()
43 {
44  // can't trust any of our previous locators, as we don't know exactly how datum transform changes would affect these
46  setMapSettings( mCanvas->mapSettings() );
47 }
48 
49 void QgsMapCanvasSnappingUtils::canvasCurrentLayerChanged()
50 {
51  setCurrentLayer( qobject_cast<QgsVectorLayer *>( mCanvas->currentLayer() ) );
52 }
53 
55 {
56  QApplication::setOverrideCursor( Qt::WaitCursor );
57  mProgress = new QProgressDialog( tr( "Indexing data…" ), QString(), 0, count, mCanvas->topLevelWidget() );
58  mProgress->setWindowModality( Qt::WindowModal );
59 }
60 
62 {
63  if ( !mProgress )
64  return;
65 
66  mProgress->setValue( index );
67  if ( index == mProgress->maximum() )
68  {
69  delete mProgress;
70  mProgress = nullptr;
71  QApplication::restoreOverrideCursor();
72  }
73 }
QgsMapCanvasSnappingUtils(QgsMapCanvas *canvas, QObject *parent=nullptr)
void setCurrentLayer(QgsVectorLayer *layer)
Set current layer so that if mode is SnapCurrentLayer we know which layer to use. ...
void prepareIndexStarting(int count) override
Called when starting to index - can be overridden and e.g. progress dialog can be provided...
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:74
void clearAllLocators()
Deletes all existing locators (e.g. when destination CRS has changed and we need to reindex) ...
void prepareIndexProgress(int index) override
Called when finished indexing a layer. When index == count the indexing is complete.
void destinationCrsChanged()
Emitted when map CRS has changed.
void transformContextChanged()
Emitted when the canvas transform context is changed.
void setMapSettings(const QgsMapSettings &settings)
Assign current map settings to the utils - used for conversion between screen coords to map coords...
void currentLayerChanged(QgsMapLayer *layer)
Emitted when the current layer is changed.
QgsMapLayer * currentLayer()
returns current layer (set by legend widget)
const QgsMapSettings & mapSettings() const
Get access to properties used for map rendering.
This class has all the configuration of snapping and can return answers to snapping queries...
void extentsChanged()
Emitted when the extents of the map change.
void layersChanged()
Emitted when a new set of layers has been received.