diff --git a/python/gui/qgsrubberband.sip b/python/gui/qgsrubberband.sip index affcafddce6..8fbc4a3bd9d 100644 --- a/python/gui/qgsrubberband.sip +++ b/python/gui/qgsrubberband.sip @@ -29,9 +29,10 @@ class QgsRubberBand: QgsMapCanvasItem /**Sets this rubber band to the geometry of an existing feature. This is usefull for feature highlighting. @param geom the geometry object - @param layer the layer containing the feature (used for coord transformation) + @param layer the layer containing the feature, used for coord transformation to map + crs. In case of 0 pointer, the coordinates are not going to be transformed. @param render the maprender object (used for coord transformation)*/ - void setToGeometry(QgsGeometry* geom, QgsVectorLayer& layer); + void setToGeometry(QgsGeometry* geom, QgsVectorLayer* layer); /**Adds translation to original coordinates (all in map coordinates)*/ void setTranslationOffset(double dx, double dy); diff --git a/src/app/qgsmaptoolidentify.cpp b/src/app/qgsmaptoolidentify.cpp index 9842baedb63..3b6731d6edb 100644 --- a/src/app/qgsmaptoolidentify.cpp +++ b/src/app/qgsmaptoolidentify.cpp @@ -465,7 +465,7 @@ void QgsMapToolIdentify::highlightFeature( int featureId ) if ( mRubberBand ) { - mRubberBand->setToGeometry( feat.geometry(), *layer ); + mRubberBand->setToGeometry( feat.geometry(), layer ); mRubberBand->setWidth( 2 ); mRubberBand->setColor( Qt::red ); mRubberBand->show(); diff --git a/src/app/qgsmaptoolmovefeature.cpp b/src/app/qgsmaptoolmovefeature.cpp index 3025d308814..e5239b81728 100644 --- a/src/app/qgsmaptoolmovefeature.cpp +++ b/src/app/qgsmaptoolmovefeature.cpp @@ -109,7 +109,7 @@ void QgsMapToolMoveFeature::canvasPressEvent( QMouseEvent * e ) mStartPointMapCoords = toMapCoordinates( e->pos() ); mMovedFeature = cf.id(); //todo: take the closest feature, not the first one... mRubberBand = createRubberBand(); - mRubberBand->setToGeometry( cf.geometry(), *vlayer ); + mRubberBand->setToGeometry( cf.geometry(), vlayer ); mRubberBand->setColor( Qt::red ); mRubberBand->setWidth( 2 ); mRubberBand->show(); diff --git a/src/gui/qgsrubberband.cpp b/src/gui/qgsrubberband.cpp index 1160cf2bf7d..e3dfc063b14 100644 --- a/src/gui/qgsrubberband.cpp +++ b/src/gui/qgsrubberband.cpp @@ -153,7 +153,7 @@ void QgsRubberBand::movePoint( int index, const QgsPoint& p, int geometryIndex ) update(); } -void QgsRubberBand::setToGeometry( QgsGeometry* geom, QgsVectorLayer& layer ) +void QgsRubberBand::setToGeometry( QgsGeometry* geom, QgsVectorLayer* layer ) { if ( !geom ) { @@ -177,7 +177,15 @@ void QgsRubberBand::setToGeometry( QgsGeometry* geom, QgsVectorLayer& layer ) { mIsPolygon = true; double d = mMapCanvas->extent().width() * 0.005; - QgsPoint pt = mr->layerToMapCoordinates( &layer, geom->asPoint() ); + QgsPoint pt; + if(layer) + { + pt = mr->layerToMapCoordinates( layer, geom->asPoint() ); + } + else + { + pt = geom->asPoint(); + } addPoint( QgsPoint( pt.x() - d, pt.y() - d ) ); addPoint( QgsPoint( pt.x() + d, pt.y() - d ) ); addPoint( QgsPoint( pt.x() + d, pt.y() + d ) ); @@ -194,10 +202,20 @@ void QgsRubberBand::setToGeometry( QgsGeometry* geom, QgsVectorLayer& layer ) for ( int i = 0; i < mpt.size(); ++i ) { QgsPoint pt = mpt[i]; - addPoint( mr->layerToMapCoordinates( &layer, QgsPoint( pt.x() - d, pt.y() - d ) ) ); - addPoint( mr->layerToMapCoordinates( &layer, QgsPoint( pt.x() + d, pt.y() - d ) ) ); - addPoint( mr->layerToMapCoordinates( &layer, QgsPoint( pt.x() + d, pt.y() + d ) ) ); - addPoint( mr->layerToMapCoordinates( &layer, QgsPoint( pt.x() - d, pt.y() + d ) ) ); + if(layer) + { + addPoint( mr->layerToMapCoordinates( layer, QgsPoint( pt.x() - d, pt.y() - d ) ) ); + addPoint( mr->layerToMapCoordinates( layer, QgsPoint( pt.x() + d, pt.y() - d ) ) ); + addPoint( mr->layerToMapCoordinates( layer, QgsPoint( pt.x() + d, pt.y() + d ) ) ); + addPoint( mr->layerToMapCoordinates( layer, QgsPoint( pt.x() - d, pt.y() + d ) ) ); + } + else + { + addPoint(QgsPoint( pt.x() - d, pt.y() - d ) ); + addPoint(QgsPoint( pt.x() + d, pt.y() - d ) ); + addPoint(QgsPoint( pt.x() + d, pt.y() + d ) ); + addPoint(QgsPoint( pt.x() - d, pt.y() + d ) ); + } } } break; @@ -209,7 +227,14 @@ void QgsRubberBand::setToGeometry( QgsGeometry* geom, QgsVectorLayer& layer ) QgsPolyline line = geom->asPolyline(); for ( int i = 0; i < line.count(); i++ ) { - addPoint( mr->layerToMapCoordinates( &layer, line[i] ) ); + if(layer) + { + addPoint( mr->layerToMapCoordinates( layer, line[i] ) ); + } + else + { + addPoint(line[i]); + } } } break; @@ -228,7 +253,14 @@ void QgsRubberBand::setToGeometry( QgsGeometry* geom, QgsVectorLayer& layer ) QgsPolyline line = mline[i]; for ( int j = 0; j < line.size(); ++j ) { - addPoint( mr->layerToMapCoordinates( &layer, line[j] ), false, i ); + if(layer) + { + addPoint( mr->layerToMapCoordinates( layer, line[j] ), false, i ); + } + else + { + addPoint(line[j]); + } } } } @@ -242,7 +274,14 @@ void QgsRubberBand::setToGeometry( QgsGeometry* geom, QgsVectorLayer& layer ) QgsPolyline line = poly[0]; for ( int i = 0; i < line.count(); i++ ) { - addPoint( mr->layerToMapCoordinates( &layer, line[i] ) ); + if(layer) + { + addPoint( mr->layerToMapCoordinates( layer, line[i] ) ); + } + else + { + addPoint(line[i]); + } } } break; @@ -262,7 +301,14 @@ void QgsRubberBand::setToGeometry( QgsGeometry* geom, QgsVectorLayer& layer ) QgsPolyline line = poly[0]; for ( int j = 0; j < line.count(); ++j ) { - addPoint( mr->layerToMapCoordinates( &layer, line[j] ), false, i ); + if(layer) + { + addPoint( mr->layerToMapCoordinates( layer, line[j] ), false, i ); + } + else + { + addPoint(line[j]); + } } } } diff --git a/src/gui/qgsrubberband.h b/src/gui/qgsrubberband.h index 2f6eb2c6fec..7fc74a0d950 100644 --- a/src/gui/qgsrubberband.h +++ b/src/gui/qgsrubberband.h @@ -56,9 +56,10 @@ class GUI_EXPORT QgsRubberBand: public QgsMapCanvasItem /**Sets this rubber band to the geometry of an existing feature. This is usefull for feature highlighting. @param geom the geometry object - @param layer the layer containing the feature (used for coord transformation) + @param layer the layer containing the feature, used for coord transformation to map + crs. In case of 0 pointer, the coordinates are not going to be transformed. @param render the maprender object (used for coord transformation)*/ - void setToGeometry( QgsGeometry* geom, QgsVectorLayer& layer ); + void setToGeometry( QgsGeometry* geom, QgsVectorLayer* layer ); /**Adds translation to original coordinates (all in map coordinates)*/ void setTranslationOffset( double dx, double dy );