QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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 #include "qgssettings.h"
20 
21 #include <QApplication>
22 #include <QProgressDialog>
23 
25  : QgsSnappingUtils( parent, QgsSettings().value( QStringLiteral( "/qgis/digitizing/snap_invisible_feature" ), false ).toBool() )
26  , mCanvas( canvas )
27 
28 {
29  connect( canvas, &QgsMapCanvas::extentsChanged, this, &QgsMapCanvasSnappingUtils::canvasMapSettingsChanged );
30  connect( canvas, &QgsMapCanvas::destinationCrsChanged, this, &QgsMapCanvasSnappingUtils::canvasMapSettingsChanged );
31  connect( canvas, &QgsMapCanvas::layersChanged, this, &QgsMapCanvasSnappingUtils::canvasMapSettingsChanged );
32  connect( canvas, &QgsMapCanvas::currentLayerChanged, this, &QgsMapCanvasSnappingUtils::canvasCurrentLayerChanged );
33  connect( canvas, &QgsMapCanvas::transformContextChanged, this, &QgsMapCanvasSnappingUtils::canvasTransformContextChanged );
34  connect( canvas, &QgsMapCanvas::mapToolSet, this, &QgsMapCanvasSnappingUtils::canvasMapToolChanged );
35  canvasMapSettingsChanged();
36  canvasCurrentLayerChanged();
37 }
38 
39 void QgsMapCanvasSnappingUtils::canvasMapSettingsChanged()
40 {
41  setMapSettings( mCanvas->mapSettings() );
42  setEnableSnappingForInvisibleFeature( QgsSettings().value( QStringLiteral( "/qgis/digitizing/snap_invisible_feature" ), false ).toBool() );
43 }
44 
45 void QgsMapCanvasSnappingUtils::canvasTransformContextChanged()
46 {
47  // can't trust any of our previous locators, as we don't know exactly how datum transform changes would affect these
49  setMapSettings( mCanvas->mapSettings() );
50 }
51 
52 void QgsMapCanvasSnappingUtils::canvasCurrentLayerChanged()
53 {
54  setCurrentLayer( qobject_cast<QgsVectorLayer *>( mCanvas->currentLayer() ) );
55 }
56 
57 void QgsMapCanvasSnappingUtils::canvasMapToolChanged()
58 {
59  setEnableSnappingForInvisibleFeature( QgsSettings().value( QStringLiteral( "/qgis/digitizing/snap_invisible_feature" ), false ).toBool() );
60 }
61 
63 {
64  QApplication::setOverrideCursor( Qt::WaitCursor );
65  mProgress = new QProgressDialog( tr( "Indexing data…" ), QString(), 0, count, mCanvas->topLevelWidget() );
66  mProgress->setWindowModality( Qt::WindowModal );
67 }
68 
70 {
71  if ( !mProgress )
72  return;
73 
74  mProgress->setValue( index );
75  if ( index == mProgress->maximum() )
76  {
77  delete mProgress;
78  mProgress = nullptr;
79  QApplication::restoreOverrideCursor();
80  }
81 }
QgsMapCanvas::currentLayerChanged
void currentLayerChanged(QgsMapLayer *layer)
Emitted when the current layer is changed.
QgsMapCanvas::transformContextChanged
void transformContextChanged()
Emitted when the canvas transform context is changed.
QgsMapCanvas::mapToolSet
void mapToolSet(QgsMapTool *newTool, QgsMapTool *oldTool)
Emit map tool changed with the old tool.
QgsMapCanvas::destinationCrsChanged
void destinationCrsChanged()
Emitted when map CRS has changed.
qgsmapcanvas.h
QgsMapCanvas::mapSettings
const QgsMapSettings & mapSettings() const
Gets access to properties used for map rendering.
Definition: qgsmapcanvas.cpp:390
QgsMapCanvas
Definition: qgsmapcanvas.h:83
QgsSnappingUtils::setCurrentLayer
void setCurrentLayer(QgsVectorLayer *layer)
Sets current layer so that if mode is SnapCurrentLayer we know which layer to use.
Definition: qgssnappingutils.cpp:592
QgsSettings
Definition: qgssettings.h:61
QgsSnappingUtils::clearAllLocators
void clearAllLocators()
Deletes all existing locators (e.g. when destination CRS has changed and we need to reindex)
Definition: qgssnappingutils.cpp:51
QgsMapCanvasSnappingUtils::QgsMapCanvasSnappingUtils
QgsMapCanvasSnappingUtils(QgsMapCanvas *canvas, QObject *parent=nullptr)
Construct map canvas snapping utils object.
Definition: qgsmapcanvassnappingutils.cpp:24
QgsMapCanvas::layersChanged
void layersChanged()
Emitted when a new set of layers has been received.
QgsMapCanvas::extentsChanged
void extentsChanged()
Emitted when the extents of the map change.
QgsSnappingUtils
Definition: qgssnappingutils.h:49
QgsMapCanvasSnappingUtils::prepareIndexStarting
void prepareIndexStarting(int count) override
Called when starting to index with snapToMap - can be overridden and e.g. progress dialog can be prov...
Definition: qgsmapcanvassnappingutils.cpp:62
qgsvectorlayer.h
qgsmapcanvassnappingutils.h
QgsSnappingUtils::setEnableSnappingForInvisibleFeature
void setEnableSnappingForInvisibleFeature(bool enable)
Set if invisible features must be snapped or not.
Definition: qgssnappingutils.cpp:541
qgssettings.h
QgsMapCanvasSnappingUtils::prepareIndexProgress
void prepareIndexProgress(int index) override
Called when finished indexing a layer with snapToMap. When index == count the indexing is complete.
Definition: qgsmapcanvassnappingutils.cpp:69
QgsSnappingUtils::setMapSettings
void setMapSettings(const QgsMapSettings &settings)
Assign current map settings to the utils - used for conversion between screen coords to map coords.
Definition: qgssnappingutils.cpp:582
QgsMapCanvas::currentLayer
QgsMapLayer * currentLayer()
returns current layer (set by legend widget)
Definition: qgsmapcanvas.cpp:511