diff --git a/python/core/qgsdatumtransformstore.sip b/python/core/qgsdatumtransformstore.sip index 1f63e39da6b1..cf461148ec2b 100644 --- a/python/core/qgsdatumtransformstore.sip +++ b/python/core/qgsdatumtransformstore.sip @@ -26,7 +26,7 @@ class QgsDatumTransformStore * @returns transformation associated with layer, or an invalid QgsCoordinateTransform * if no transform is associated with the layer */ - QgsCoordinateTransform transformation( QgsMapLayer* layer ) const; + QgsCoordinateTransform transformation( const QgsMapLayer* layer ) const; void readXml( const QDomNode& parentNode ); diff --git a/python/core/qgsmapsettings.sip b/python/core/qgsmapsettings.sip index 35f611d08fda..7bec941aa260 100644 --- a/python/core/qgsmapsettings.sip +++ b/python/core/qgsmapsettings.sip @@ -177,54 +177,54 @@ class QgsMapSettings * @param referenceExtent A reference extent based on which to perform the computation. If not specified, the layer extent is used * @note added in QGIS 2.12 */ - double layerToMapUnits( QgsMapLayer* layer, const QgsRectangle& referenceExtent = QgsRectangle() ) const; + double layerToMapUnits( const QgsMapLayer* layer, const QgsRectangle& referenceExtent = QgsRectangle() ) const; /** * @brief transform bounding box from layer's CRS to output CRS * @see layerToMapCoordinates( QgsMapLayer* layer, QgsRectangle rect ) if you want to transform a rectangle * @return a bounding box (aligned rectangle) containing the transformed extent */ - QgsRectangle layerExtentToOutputExtent( QgsMapLayer* layer, QgsRectangle extent ) const; + QgsRectangle layerExtentToOutputExtent( const QgsMapLayer* layer, QgsRectangle extent ) const; /** * @brief transform bounding box from output CRS to layer's CRS * @see mapToLayerCoordinates( QgsMapLayer* layer,QgsRectangle rect ) if you want to transform a rectangle * @return a bounding box (aligned rectangle) containing the transformed extent */ - QgsRectangle outputExtentToLayerExtent( QgsMapLayer* layer, QgsRectangle extent ) const; + QgsRectangle outputExtentToLayerExtent( const QgsMapLayer* layer, QgsRectangle extent ) const; /** * @brief transform point coordinates from layer's CRS to output CRS * @return the transformed point */ - QgsPoint layerToMapCoordinates( QgsMapLayer* layer, QgsPoint point ) const; + QgsPoint layerToMapCoordinates( const QgsMapLayer* layer, QgsPoint point ) const; /** * @brief transform rectangle from layer's CRS to output CRS * @see layerExtentToOutputExtent() if you want to transform a bounding box * @return the transformed rectangle */ - QgsRectangle layerToMapCoordinates( QgsMapLayer* layer, QgsRectangle rect ) const; + QgsRectangle layerToMapCoordinates( const QgsMapLayer* layer, QgsRectangle rect ) const; /** * @brief transform point coordinates from output CRS to layer's CRS * @return the transformed point */ - QgsPoint mapToLayerCoordinates( QgsMapLayer* layer, QgsPoint point ) const; + QgsPoint mapToLayerCoordinates( const QgsMapLayer* layer, QgsPoint point ) const; /** * @brief transform rectangle from output CRS to layer's CRS * @see outputExtentToLayerExtent() if you want to transform a bounding box * @return the transformed rectangle */ - QgsRectangle mapToLayerCoordinates( QgsMapLayer* layer, QgsRectangle rect ) const; + QgsRectangle mapToLayerCoordinates( const QgsMapLayer* layer, QgsRectangle rect ) const; /** * @brief Return coordinate transform from layer's CRS to destination CRS * @param layer * @return transform - may be invalid if the transform is not needed */ - QgsCoordinateTransform layerTransform( QgsMapLayer *layer ) const; + QgsCoordinateTransform layerTransform( const QgsMapLayer *layer ) const; //! returns current extent of layer set QgsRectangle fullExtent() const; diff --git a/python/core/qgspointlocator.sip b/python/core/qgspointlocator.sip index 6e9a91263b72..3c9d48a24480 100644 --- a/python/core/qgspointlocator.sip +++ b/python/core/qgspointlocator.sip @@ -96,6 +96,8 @@ class QgsPointLocator : QObject //! Only for a valid edge match - obtain endpoints of the edge void edgePoints( QgsPoint& pt1 /Out/, QgsPoint& pt2 /Out/ ) const; + + bool operator==( const QgsPointLocator::Match& other ) const; }; typedef QList MatchList; diff --git a/python/gui/qgsmaptool.sip b/python/gui/qgsmaptool.sip index f03c5c67d235..4a65dfee886c 100644 --- a/python/gui/qgsmaptool.sip +++ b/python/gui/qgsmaptool.sip @@ -144,20 +144,20 @@ class QgsMapTool : QObject QgsPoint toMapCoordinates( QPoint point ); //! transformation from screen coordinates to layer's coordinates - QgsPoint toLayerCoordinates( QgsMapLayer* layer, QPoint point ); + QgsPoint toLayerCoordinates( const QgsMapLayer* layer, QPoint point ); //! transformation from map coordinates to layer's coordinates - QgsPoint toLayerCoordinates( QgsMapLayer* layer, const QgsPoint& point ); + QgsPoint toLayerCoordinates( const QgsMapLayer* layer, const QgsPoint& point ); //!transformation from layer's coordinates to map coordinates (which is different in case reprojection is used) - QgsPoint toMapCoordinates( QgsMapLayer* layer, const QgsPoint& point ); + QgsPoint toMapCoordinates( const QgsMapLayer* layer, const QgsPoint& point ); //!transformation from layer's coordinates to map coordinates (which is different in case reprojection is used) //! @note available in python bindings as toMapCoordinatesV2 - QgsPointV2 toMapCoordinates( QgsMapLayer* layer, const QgsPointV2 &point ) /PyName=toMapCoordinatesV2/; + QgsPointV2 toMapCoordinates( const QgsMapLayer* layer, const QgsPointV2 &point ) /PyName=toMapCoordinatesV2/; //! trnasformation of the rect from map coordinates to layer's coordinates - QgsRectangle toLayerCoordinates( QgsMapLayer* layer, const QgsRectangle& rect ); + QgsRectangle toLayerCoordinates( const QgsMapLayer* layer, const QgsRectangle& rect ); //! transformation from map coordinates to screen coordinates QPoint toCanvasCoordinates( const QgsPoint& point ); diff --git a/python/gui/qgsmaptooledit.sip b/python/gui/qgsmaptooledit.sip index 36100524afb6..5023fc531248 100644 --- a/python/gui/qgsmaptooledit.sip +++ b/python/gui/qgsmaptooledit.sip @@ -30,6 +30,10 @@ class QgsMapToolEdit: QgsMapTool double defaultZValue() const; protected: + static QColor digitizingStrokeColor(); + static int digitizingStrokeWidth(); + static QColor digitizingFillColor(); + /** Creates a rubber band with the color/line width from * the QGIS settings. The caller takes ownership of the * returned object diff --git a/src/core/qgsdatumtransformstore.cpp b/src/core/qgsdatumtransformstore.cpp index f5dbc2a55507..d165ae1ae125 100644 --- a/src/core/qgsdatumtransformstore.cpp +++ b/src/core/qgsdatumtransformstore.cpp @@ -50,7 +50,7 @@ bool QgsDatumTransformStore::hasEntryForLayer( QgsMapLayer* layer ) const return mEntries.contains( layer->id() ); } -QgsCoordinateTransform QgsDatumTransformStore::transformation( QgsMapLayer* layer ) const +QgsCoordinateTransform QgsDatumTransformStore::transformation( const QgsMapLayer* layer ) const { if ( !layer ) return QgsCoordinateTransform(); diff --git a/src/core/qgsdatumtransformstore.h b/src/core/qgsdatumtransformstore.h index 865c098ae006..f74a107c6caf 100644 --- a/src/core/qgsdatumtransformstore.h +++ b/src/core/qgsdatumtransformstore.h @@ -48,7 +48,7 @@ class CORE_EXPORT QgsDatumTransformStore * @returns transformation associated with layer, or an invalid QgsCoordinateTransform * if no transform is associated with the layer */ - QgsCoordinateTransform transformation( QgsMapLayer* layer ) const; + QgsCoordinateTransform transformation( const QgsMapLayer* layer ) const; void readXml( const QDomNode& parentNode ); diff --git a/src/core/qgsmapsettings.cpp b/src/core/qgsmapsettings.cpp index 2dde3096045c..9ee5441b081c 100644 --- a/src/core/qgsmapsettings.cpp +++ b/src/core/qgsmapsettings.cpp @@ -377,13 +377,13 @@ double QgsMapSettings::scale() const } -QgsCoordinateTransform QgsMapSettings::layerTransform( QgsMapLayer *layer ) const +QgsCoordinateTransform QgsMapSettings::layerTransform( const QgsMapLayer *layer ) const { return mDatumTransformStore.transformation( layer ); } -double QgsMapSettings::layerToMapUnits( QgsMapLayer *layer, const QgsRectangle& referenceExtent ) const +double QgsMapSettings::layerToMapUnits( const QgsMapLayer *layer, const QgsRectangle& referenceExtent ) const { QgsRectangle extent = referenceExtent.isEmpty() ? layer->extent() : referenceExtent; QgsPoint l1( extent.xMinimum(), extent.yMinimum() ); @@ -396,7 +396,7 @@ double QgsMapSettings::layerToMapUnits( QgsMapLayer *layer, const QgsRectangle& } -QgsRectangle QgsMapSettings::layerExtentToOutputExtent( QgsMapLayer* layer, QgsRectangle extent ) const +QgsRectangle QgsMapSettings::layerExtentToOutputExtent( const QgsMapLayer* layer, QgsRectangle extent ) const { if ( hasCrsTransformEnabled() ) { @@ -423,7 +423,7 @@ QgsRectangle QgsMapSettings::layerExtentToOutputExtent( QgsMapLayer* layer, QgsR } -QgsRectangle QgsMapSettings::outputExtentToLayerExtent( QgsMapLayer* layer, QgsRectangle extent ) const +QgsRectangle QgsMapSettings::outputExtentToLayerExtent( const QgsMapLayer* layer, QgsRectangle extent ) const { if ( hasCrsTransformEnabled() ) { @@ -450,7 +450,7 @@ QgsRectangle QgsMapSettings::outputExtentToLayerExtent( QgsMapLayer* layer, QgsR } -QgsPoint QgsMapSettings::layerToMapCoordinates( QgsMapLayer* layer, QgsPoint point ) const +QgsPoint QgsMapSettings::layerToMapCoordinates( const QgsMapLayer* layer, QgsPoint point ) const { if ( hasCrsTransformEnabled() ) { @@ -473,7 +473,7 @@ QgsPoint QgsMapSettings::layerToMapCoordinates( QgsMapLayer* layer, QgsPoint poi } -QgsRectangle QgsMapSettings::layerToMapCoordinates( QgsMapLayer* layer, QgsRectangle rect ) const +QgsRectangle QgsMapSettings::layerToMapCoordinates( const QgsMapLayer* layer, QgsRectangle rect ) const { if ( hasCrsTransformEnabled() ) { @@ -496,7 +496,7 @@ QgsRectangle QgsMapSettings::layerToMapCoordinates( QgsMapLayer* layer, QgsRecta } -QgsPoint QgsMapSettings::mapToLayerCoordinates( QgsMapLayer* layer, QgsPoint point ) const +QgsPoint QgsMapSettings::mapToLayerCoordinates( const QgsMapLayer* layer, QgsPoint point ) const { if ( hasCrsTransformEnabled() ) { @@ -519,7 +519,7 @@ QgsPoint QgsMapSettings::mapToLayerCoordinates( QgsMapLayer* layer, QgsPoint poi } -QgsRectangle QgsMapSettings::mapToLayerCoordinates( QgsMapLayer* layer, QgsRectangle rect ) const +QgsRectangle QgsMapSettings::mapToLayerCoordinates( const QgsMapLayer* layer, QgsRectangle rect ) const { if ( hasCrsTransformEnabled() ) { diff --git a/src/core/qgsmapsettings.h b/src/core/qgsmapsettings.h index 06bc51458af5..3aeb790fde7e 100644 --- a/src/core/qgsmapsettings.h +++ b/src/core/qgsmapsettings.h @@ -228,54 +228,54 @@ class CORE_EXPORT QgsMapSettings * @param referenceExtent A reference extent based on which to perform the computation. If not specified, the layer extent is used * @note added in QGIS 2.12 */ - double layerToMapUnits( QgsMapLayer* layer, const QgsRectangle& referenceExtent = QgsRectangle() ) const; + double layerToMapUnits( const QgsMapLayer* layer, const QgsRectangle& referenceExtent = QgsRectangle() ) const; /** * @brief transform bounding box from layer's CRS to output CRS * @see layerToMapCoordinates( QgsMapLayer* layer, QgsRectangle rect ) if you want to transform a rectangle * @return a bounding box (aligned rectangle) containing the transformed extent */ - QgsRectangle layerExtentToOutputExtent( QgsMapLayer* layer, QgsRectangle extent ) const; + QgsRectangle layerExtentToOutputExtent( const QgsMapLayer* layer, QgsRectangle extent ) const; /** * @brief transform bounding box from output CRS to layer's CRS * @see mapToLayerCoordinates( QgsMapLayer* layer,QgsRectangle rect ) if you want to transform a rectangle * @return a bounding box (aligned rectangle) containing the transformed extent */ - QgsRectangle outputExtentToLayerExtent( QgsMapLayer* layer, QgsRectangle extent ) const; + QgsRectangle outputExtentToLayerExtent( const QgsMapLayer* layer, QgsRectangle extent ) const; /** * @brief transform point coordinates from layer's CRS to output CRS * @return the transformed point */ - QgsPoint layerToMapCoordinates( QgsMapLayer* layer, QgsPoint point ) const; + QgsPoint layerToMapCoordinates( const QgsMapLayer* layer, QgsPoint point ) const; /** * @brief transform rectangle from layer's CRS to output CRS * @see layerExtentToOutputExtent() if you want to transform a bounding box * @return the transformed rectangle */ - QgsRectangle layerToMapCoordinates( QgsMapLayer* layer, QgsRectangle rect ) const; + QgsRectangle layerToMapCoordinates( const QgsMapLayer* layer, QgsRectangle rect ) const; /** * @brief transform point coordinates from output CRS to layer's CRS * @return the transformed point */ - QgsPoint mapToLayerCoordinates( QgsMapLayer* layer, QgsPoint point ) const; + QgsPoint mapToLayerCoordinates( const QgsMapLayer* layer, QgsPoint point ) const; /** * @brief transform rectangle from output CRS to layer's CRS * @see outputExtentToLayerExtent() if you want to transform a bounding box * @return the transformed rectangle */ - QgsRectangle mapToLayerCoordinates( QgsMapLayer* layer, QgsRectangle rect ) const; + QgsRectangle mapToLayerCoordinates( const QgsMapLayer* layer, QgsRectangle rect ) const; /** * @brief Return coordinate transform from layer's CRS to destination CRS * @param layer * @return transform - may be invalid if the transform is not needed */ - QgsCoordinateTransform layerTransform( QgsMapLayer *layer ) const; + QgsCoordinateTransform layerTransform( const QgsMapLayer *layer ) const; //! returns current extent of layer set QgsRectangle fullExtent() const; diff --git a/src/core/qgspointlocator.h b/src/core/qgspointlocator.h index 7d82f1319d20..986c30b5acca 100644 --- a/src/core/qgspointlocator.h +++ b/src/core/qgspointlocator.h @@ -160,6 +160,17 @@ class CORE_EXPORT QgsPointLocator : public QObject pt2 = mEdgePoints[1]; } + bool operator==( const Match& other ) const + { + return mType == other.mType && + mDist == other.mDist && + mPoint == other.mPoint && + mLayer == other.mLayer && + mFid == other.mFid && + mVertexIndex == other.mVertexIndex && + mEdgePoints == other.mEdgePoints; + } + protected: Type mType; double mDist; diff --git a/src/gui/qgsmaptool.cpp b/src/gui/qgsmaptool.cpp index 08696183b8a4..6dd0edbc03b5 100644 --- a/src/gui/qgsmaptool.cpp +++ b/src/gui/qgsmaptool.cpp @@ -43,30 +43,30 @@ QgsPoint QgsMapTool::toMapCoordinates( QPoint point ) return mCanvas->getCoordinateTransform()->toMapCoordinates( point ); } -QgsPointV2 QgsMapTool::toMapCoordinates( QgsMapLayer* layer, const QgsPointV2& point ) +QgsPointV2 QgsMapTool::toMapCoordinates( const QgsMapLayer* layer, const QgsPointV2& point ) { QgsPoint result = mCanvas->mapSettings().layerToMapCoordinates( layer, QgsPoint( point.x(), point.y() ) ); return QgsPointV2( result.x(), result.y() ); } -QgsPoint QgsMapTool::toLayerCoordinates( QgsMapLayer* layer, QPoint point ) +QgsPoint QgsMapTool::toLayerCoordinates( const QgsMapLayer* layer, QPoint point ) { QgsPoint pt = toMapCoordinates( point ); return toLayerCoordinates( layer, pt ); } -QgsPoint QgsMapTool::toLayerCoordinates( QgsMapLayer* layer, const QgsPoint& point ) +QgsPoint QgsMapTool::toLayerCoordinates( const QgsMapLayer* layer, const QgsPoint& point ) { return mCanvas->mapSettings().mapToLayerCoordinates( layer, point ); } -QgsPoint QgsMapTool::toMapCoordinates( QgsMapLayer* layer, const QgsPoint& point ) +QgsPoint QgsMapTool::toMapCoordinates( const QgsMapLayer* layer, const QgsPoint& point ) { return mCanvas->mapSettings().layerToMapCoordinates( layer, point ); } -QgsRectangle QgsMapTool::toLayerCoordinates( QgsMapLayer* layer, const QgsRectangle& rect ) +QgsRectangle QgsMapTool::toLayerCoordinates( const QgsMapLayer* layer, const QgsRectangle& rect ) { return mCanvas->mapSettings().mapToLayerCoordinates( layer, rect ); } diff --git a/src/gui/qgsmaptool.h b/src/gui/qgsmaptool.h index 1f7b566a4682..598940022696 100644 --- a/src/gui/qgsmaptool.h +++ b/src/gui/qgsmaptool.h @@ -170,20 +170,20 @@ class GUI_EXPORT QgsMapTool : public QObject QgsPoint toMapCoordinates( QPoint point ); //! transformation from screen coordinates to layer's coordinates - QgsPoint toLayerCoordinates( QgsMapLayer* layer, QPoint point ); + QgsPoint toLayerCoordinates( const QgsMapLayer* layer, QPoint point ); //! transformation from map coordinates to layer's coordinates - QgsPoint toLayerCoordinates( QgsMapLayer* layer, const QgsPoint& point ); + QgsPoint toLayerCoordinates( const QgsMapLayer* layer, const QgsPoint& point ); //!transformation from layer's coordinates to map coordinates (which is different in case reprojection is used) - QgsPoint toMapCoordinates( QgsMapLayer* layer, const QgsPoint& point ); + QgsPoint toMapCoordinates( const QgsMapLayer* layer, const QgsPoint& point ); //!transformation from layer's coordinates to map coordinates (which is different in case reprojection is used) //! @note available in python bindings as toMapCoordinatesV2 - QgsPointV2 toMapCoordinates( QgsMapLayer* layer, const QgsPointV2 &point ); + QgsPointV2 toMapCoordinates( const QgsMapLayer* layer, const QgsPointV2 &point ); //! trnasformation of the rect from map coordinates to layer's coordinates - QgsRectangle toLayerCoordinates( QgsMapLayer* layer, const QgsRectangle& rect ); + QgsRectangle toLayerCoordinates( const QgsMapLayer* layer, const QgsRectangle& rect ); //! transformation from map coordinates to screen coordinates QPoint toCanvasCoordinates( const QgsPoint& point ); diff --git a/src/gui/qgsmaptooledit.cpp b/src/gui/qgsmaptooledit.cpp index 68892d015200..ab10b7652700 100644 --- a/src/gui/qgsmaptooledit.cpp +++ b/src/gui/qgsmaptooledit.cpp @@ -34,34 +34,52 @@ double QgsMapToolEdit::defaultZValue() const return QSettings().value( QStringLiteral( "/qgis/digitizing/default_z_value" ), Qgis::DEFAULT_Z_COORDINATE ).toDouble(); } -QgsRubberBand* QgsMapToolEdit::createRubberBand( QgsWkbTypes::GeometryType geometryType, bool alternativeBand ) +QColor QgsMapToolEdit::digitizingStrokeColor() { QSettings settings; - QgsRubberBand* rb = new QgsRubberBand( mCanvas, geometryType ); - rb->setWidth( settings.value( QStringLiteral( "/qgis/digitizing/line_width" ), 1 ).toInt() ); QColor color( settings.value( QStringLiteral( "/qgis/digitizing/line_color_red" ), 255 ).toInt(), settings.value( QStringLiteral( "/qgis/digitizing/line_color_green" ), 0 ).toInt(), settings.value( QStringLiteral( "/qgis/digitizing/line_color_blue" ), 0 ).toInt() ); double myAlpha = settings.value( QStringLiteral( "/qgis/digitizing/line_color_alpha" ), 200 ).toInt() / 255.0; - if ( alternativeBand ) - { - myAlpha = myAlpha * settings.value( QStringLiteral( "/qgis/digitizing/line_color_alpha_scale" ), 0.75 ).toDouble(); - rb->setLineStyle( Qt::DotLine ); - } - if ( geometryType == QgsWkbTypes::PolygonGeometry ) - { - color.setAlphaF( myAlpha ); - } color.setAlphaF( myAlpha ); - rb->setColor( color ); + return color; +} +int QgsMapToolEdit::digitizingStrokeWidth() +{ + QSettings settings; + return settings.value( QStringLiteral( "/qgis/digitizing/line_width" ), 1 ).toInt(); +} + +QColor QgsMapToolEdit::digitizingFillColor() +{ + QSettings settings; QColor fillColor( settings.value( QStringLiteral( "/qgis/digitizing/fill_color_red" ), 255 ).toInt(), settings.value( QStringLiteral( "/qgis/digitizing/fill_color_green" ), 0 ).toInt(), settings.value( QStringLiteral( "/qgis/digitizing/fill_color_blue" ), 0 ).toInt() ); - myAlpha = settings.value( QStringLiteral( "/qgis/digitizing/fill_color_alpha" ), 30 ).toInt() / 255.0 ; + double myAlpha = settings.value( QStringLiteral( "/qgis/digitizing/fill_color_alpha" ), 30 ).toInt() / 255.0 ; fillColor.setAlphaF( myAlpha ); + return fillColor; +} + + +QgsRubberBand* QgsMapToolEdit::createRubberBand( QgsWkbTypes::GeometryType geometryType, bool alternativeBand ) +{ + QSettings settings; + QgsRubberBand* rb = new QgsRubberBand( mCanvas, geometryType ); + rb->setWidth( digitizingStrokeWidth() ); + QColor color = digitizingStrokeColor(); + if ( alternativeBand ) + { + double alphaScale = settings.value( QStringLiteral( "/qgis/digitizing/line_color_alpha_scale" ), 0.75 ).toDouble(); + color.setAlphaF( color.alphaF() * alphaScale ); + rb->setLineStyle( Qt::DotLine ); + } + rb->setStrokeColor( color ); + + QColor fillColor = digitizingFillColor(); rb->setFillColor( fillColor ); rb->show(); diff --git a/src/gui/qgsmaptooledit.h b/src/gui/qgsmaptooledit.h index 40069e4ac046..657165e23b8d 100644 --- a/src/gui/qgsmaptooledit.h +++ b/src/gui/qgsmaptooledit.h @@ -45,6 +45,13 @@ class GUI_EXPORT QgsMapToolEdit: public QgsMapTool protected: + //! Returns stroke color for rubber bands (from global settings) + static QColor digitizingStrokeColor(); + //! Returns stroke width for rubber bands (from global settings) + static int digitizingStrokeWidth(); + //! Returns fill color for rubber bands (from global settings) + static QColor digitizingFillColor(); + /** Creates a rubber band with the color/line width from * the QGIS settings. The caller takes ownership of the * returned object