32#include "moc_qgsmaptooladvanceddigitizing.cpp"
34using namespace Qt::StringLiterals;
52 if ( !e->isAccepted() )
63 if ( mSnapToLayerGridEnabled &&
layer )
76 if ( !e->isAccepted() )
87 if ( mSnapToGridCanvasItem && mSnapToLayerGridEnabled &&
layer )
101 if ( !e->isAccepted() )
112 if ( mSnapToGridCanvasItem && mSnapToLayerGridEnabled &&
layer )
115 mSnapToGridCanvasItem->setPoint( e->
mapPoint() );
118 if ( mSnapIndicator )
137 mSnapToGridCanvasItem->setPrecision(
currentVectorLayer()->geometryOptions()->geometryPrecision() );
139 mSnapToGridCanvasItem->setEnabled( mSnapToLayerGridEnabled );
148 delete mSnapToGridCanvasItem;
149 mSnapToGridCanvasItem =
nullptr;
151 if ( mSnapIndicator )
162 return static_cast<bool>( mSnapIndicator.get() );
167 areaString = QString();
168 totalLengthString = QString();
183 std::unique_ptr< QgsDistanceArea > distanceArea;
184 auto createDistanceArea = [destinationCrs, &distanceArea] {
189 distanceArea = std::make_unique< QgsDistanceArea >();
209 createDistanceArea();
210 const double area = distanceArea->measureArea( g );
217 switch ( totalLengthType )
229 createDistanceArea();
239 if ( enabled && !mSnapIndicator )
241 mSnapIndicator = std::make_unique<QgsSnapIndicator>(
mCanvas );
243 else if ( !enabled && mSnapIndicator )
245 mSnapIndicator.reset();
249void QgsMapToolAdvancedDigitizing::cadPointChanged(
const QgsPointXY &point )
252 QMouseEvent *ev =
new QMouseEvent( QEvent::MouseMove,
mCanvas->mouseLastXY(), Qt::NoButton, Qt::NoButton, Qt::NoModifier );
253 qApp->postEvent(
mCanvas->viewport(), ev );
256void QgsMapToolAdvancedDigitizing::onCurrentLayerChanged()
258 if ( mSnapToGridCanvasItem )
261 if (
layer && mSnapToLayerGridEnabled )
263 mSnapToGridCanvasItem->setPrecision(
layer->geometryOptions()->geometryPrecision() );
264 mSnapToGridCanvasItem->setCrs(
layer->crs() );
270 mSnapToGridCanvasItem->setEnabled(
false );
275 mSnapToGridCanvasItem->setEnabled( mSnapToLayerGridEnabled );
280void QgsMapToolAdvancedDigitizing::onTransientGeometryChanged(
const QgsReferencedGeometry &geometry )
285 QgsStatusBar *statusBar =
mCanvas ?
mCanvas->statusBar() :
nullptr;
301 QString totalLengthString;
304 QStringList messageParts;
305 if ( !areaString.isEmpty() )
306 messageParts.append( tr(
"Total area: %1" ).arg( areaString ) );
307 if ( !totalLengthString.isEmpty() )
310 messageParts.append( tr(
"Perimeter: %1" ).arg( totalLengthString ) );
312 messageParts.append( tr(
"Total length: %1" ).arg( totalLengthString ) );
315 statusBar->
showMessage( messageParts.join(
' ' ) );
321 return mSnapToLayerGridEnabled;
326 mSnapToLayerGridEnabled = snapToGridEnabled;
328 if ( mSnapToGridCanvasItem )
330 mSnapToGridCanvasItem->setEnabled( snapToGridEnabled );
CadMeasurementDisplayType
Advanced digitizing measurement display types.
@ Hidden
Hide measurement.
@ Cartesian
Use Cartesian measurements.
@ Ellipsoidal
Use Ellipsoidal measurements.
Represents a coordinate reference system (CRS).
Qgis::DistanceUnit mapUnits
Custom exception class for Coordinate Reference System related exceptions.
A geometry is the spatial representation of a feature.
double length() const
Returns the planar, 2-dimensional length of geometry.
Qgis::GeometryOperationResult transform(const QgsCoordinateTransform &ct, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward, bool transformZ=false)
Transforms this geometry as described by the coordinate transform ct.
double area() const
Returns the planar, 2-dimensional area of the geometry.
bool isEmpty() const
Returns true if the geometry is empty (eg a linestring with no vertices, or a collection with no geom...
void currentLayerChanged(QgsMapLayer *layer)
Emitted when the current layer is changed.
QgsMapLayer * currentLayer()
returns current layer (set by legend widget)
Base class for all map layer types.
A mouse event which is the result of a user interaction with a QgsMapCanvas.
QgsPointXY mapPoint() const
mapPoint returns the point in coordinates
QgsPointLocator::Match mapPointMatch() const
Returns the matching data from the most recently snapped point.
void snapToGrid(double precision, const QgsCoordinateReferenceSystem &crs)
Snaps the mapPoint to a grid with the given precision.
QgsPointXY snapPoint()
snapPoint will snap the points using the map canvas snapping utils configuration
static Q_INVOKABLE QString formatAreaForProject(QgsProject *project, double area, Qgis::AreaUnit unit)
Formats an area measurement (with the specified unit) for use with a project, respecting the project'...
static Q_INVOKABLE QString formatDistanceForProject(QgsProject *project, double distance, Qgis::DistanceUnit unit)
Formats a distance measurement (with the specified unit) for use with a project, respecting the proje...
static QgsProject * instance()
Returns the QgsProject singleton instance.
QgsCoordinateReferenceSystem crs() const
Returns the associated coordinate reference system, or an invalid CRS if no reference system is set.
A QgsGeometry with associated coordinate reference system.
T value(const QString &dynamicKeyPart=QString()) const
Returns settings value.
static const QgsSettingsEntryEnumFlag< Qgis::CadMeasurementDisplayType > * settingsDigitizingStatusBarTotalLengthDisplay
Settings entry digitizing status bar perimeter/total length display.
static const QgsSettingsEntryEnumFlag< Qgis::CadMeasurementDisplayType > * settingsDigitizingStatusBarAreaDisplay
Settings entry digitizing status bar area display.
Shows a grid on the map canvas given a spatial resolution.
void clearMessage()
Removes any temporary message being shown.
void showMessage(const QString &message, int timeout=0)
Displays the given message for the specified number of milli-seconds (timeout).
static Q_INVOKABLE Qgis::AreaUnit distanceToAreaUnit(Qgis::DistanceUnit distanceUnit)
Converts a distance unit to its corresponding area unit, e.g., meters to square meters.
Represents a vector layer which manages a vector based dataset.
#define QgsDebugError(str)