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