QGIS API Documentation  2.14.0-Essen
qgsmapcanvassnappingutils.cpp
Go to the documentation of this file.
2 
3 #include "qgsmapcanvas.h"
4 #include "qgsvectorlayer.h"
5 
6 #include <QApplication>
7 #include <QProgressDialog>
8 
10  : QgsSnappingUtils( parent )
11  , mCanvas( canvas )
12  , mProgress( nullptr )
13 {
14  connect( canvas, SIGNAL( extentsChanged() ), this, SLOT( canvasMapSettingsChanged() ) );
15  connect( canvas, SIGNAL( destinationCrsChanged() ), this, SLOT( canvasMapSettingsChanged() ) );
16  connect( canvas, SIGNAL( layersChanged() ), this, SLOT( canvasMapSettingsChanged() ) );
17  connect( canvas, SIGNAL( currentLayerChanged( QgsMapLayer* ) ), this, SLOT( canvasCurrentLayerChanged() ) );
18  canvasMapSettingsChanged();
19  canvasCurrentLayerChanged();
20 }
21 
22 void QgsMapCanvasSnappingUtils::canvasMapSettingsChanged()
23 {
24  setMapSettings( mCanvas->mapSettings() );
25 }
26 
27 void QgsMapCanvasSnappingUtils::canvasCurrentLayerChanged()
28 {
29  setCurrentLayer( qobject_cast<QgsVectorLayer*>( mCanvas->currentLayer() ) );
30 }
31 
33 {
34  QApplication::setOverrideCursor( Qt::WaitCursor );
35  mProgress = new QProgressDialog( tr( "Indexing data..." ), QString(), 0, count, mCanvas->topLevelWidget() );
36  mProgress->setWindowModality( Qt::WindowModal );
37 }
38 
40 {
41  if ( !mProgress )
42  return;
43 
44  mProgress->setValue( index );
45  if ( index == mProgress->maximum() )
46  {
47  delete mProgress;
48  mProgress = nullptr;
50  }
51 }
static unsigned index
Base class for all map layer types.
Definition: qgsmaplayer.h:49
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. ...
virtual void prepareIndexStarting(int count) override
Called when starting to index - can be overridden and e.g. progress dialog can be provided...
void setWindowModality(Qt::WindowModality windowModality)
const QgsMapSettings & mapSettings() const
Get access to properties used for map rendering.
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:105
void setValue(int progress)
QWidget * topLevelWidget() const
virtual void prepareIndexProgress(int index) override
Called when finished indexing a layer. When index == count the indexing is complete.
void setOverrideCursor(const QCursor &cursor)
void restoreOverrideCursor()
void setMapSettings(const QgsMapSettings &settings)
Assign current map settings to the utils - used for conversion between screen coords to map coords...
QgsMapLayer * currentLayer()
returns current layer (set by legend widget)
This class has all the configuration of snapping and can return answers to snapping queries...
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)