QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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  , mProgress( nullptr )
27 {
28  connect( canvas, SIGNAL( extentsChanged() ), this, SLOT( canvasMapSettingsChanged() ) );
29  connect( canvas, SIGNAL( destinationCrsChanged() ), this, SLOT( canvasMapSettingsChanged() ) );
30  connect( canvas, SIGNAL( layersChanged() ), this, SLOT( canvasMapSettingsChanged() ) );
31  connect( canvas, SIGNAL( currentLayerChanged( QgsMapLayer* ) ), this, SLOT( canvasCurrentLayerChanged() ) );
32  canvasMapSettingsChanged();
33  canvasCurrentLayerChanged();
34 }
35 
36 void QgsMapCanvasSnappingUtils::canvasMapSettingsChanged()
37 {
38  setMapSettings( mCanvas->mapSettings() );
39 }
40 
41 void QgsMapCanvasSnappingUtils::canvasCurrentLayerChanged()
42 {
43  setCurrentLayer( qobject_cast<QgsVectorLayer*>( mCanvas->currentLayer() ) );
44 }
45 
47 {
48  QApplication::setOverrideCursor( Qt::WaitCursor );
49  mProgress = new QProgressDialog( tr( "Indexing data..." ), QString(), 0, count, mCanvas->topLevelWidget() );
50  mProgress->setWindowModality( Qt::WindowModal );
51 }
52 
54 {
55  if ( !mProgress )
56  return;
57 
58  mProgress->setValue( index );
59  if ( index == mProgress->maximum() )
60  {
61  delete mProgress;
62  mProgress = nullptr;
64  }
65 }
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)
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:109
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)
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...
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)