Skip to content

Commit b49bc46

Browse files
author
mhugent
committedNov 11, 2008
Allow a 0 pointer for the vector layer in QgsRubberBand::setToGeometry
git-svn-id: http://svn.osgeo.org/qgis/trunk@9623 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 5971fed commit b49bc46

File tree

5 files changed

+64
-16
lines changed

5 files changed

+64
-16
lines changed
 

‎python/gui/qgsrubberband.sip

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ class QgsRubberBand: QgsMapCanvasItem
2929
/**Sets this rubber band to the geometry of an existing feature.
3030
This is usefull for feature highlighting.
3131
@param geom the geometry object
32-
@param layer the layer containing the feature (used for coord transformation)
32+
@param layer the layer containing the feature, used for coord transformation to map
33+
crs. In case of 0 pointer, the coordinates are not going to be transformed.
3334
@param render the maprender object (used for coord transformation)*/
34-
void setToGeometry(QgsGeometry* geom, QgsVectorLayer& layer);
35+
void setToGeometry(QgsGeometry* geom, QgsVectorLayer* layer);
3536

3637
/**Adds translation to original coordinates (all in map coordinates)*/
3738
void setTranslationOffset(double dx, double dy);

‎src/app/qgsmaptoolidentify.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ void QgsMapToolIdentify::highlightFeature( int featureId )
465465

466466
if ( mRubberBand )
467467
{
468-
mRubberBand->setToGeometry( feat.geometry(), *layer );
468+
mRubberBand->setToGeometry( feat.geometry(), layer );
469469
mRubberBand->setWidth( 2 );
470470
mRubberBand->setColor( Qt::red );
471471
mRubberBand->show();

‎src/app/qgsmaptoolmovefeature.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ void QgsMapToolMoveFeature::canvasPressEvent( QMouseEvent * e )
109109
mStartPointMapCoords = toMapCoordinates( e->pos() );
110110
mMovedFeature = cf.id(); //todo: take the closest feature, not the first one...
111111
mRubberBand = createRubberBand();
112-
mRubberBand->setToGeometry( cf.geometry(), *vlayer );
112+
mRubberBand->setToGeometry( cf.geometry(), vlayer );
113113
mRubberBand->setColor( Qt::red );
114114
mRubberBand->setWidth( 2 );
115115
mRubberBand->show();

‎src/gui/qgsrubberband.cpp

Lines changed: 56 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ void QgsRubberBand::movePoint( int index, const QgsPoint& p, int geometryIndex )
153153
update();
154154
}
155155

156-
void QgsRubberBand::setToGeometry( QgsGeometry* geom, QgsVectorLayer& layer )
156+
void QgsRubberBand::setToGeometry( QgsGeometry* geom, QgsVectorLayer* layer )
157157
{
158158
if ( !geom )
159159
{
@@ -177,7 +177,15 @@ void QgsRubberBand::setToGeometry( QgsGeometry* geom, QgsVectorLayer& layer )
177177
{
178178
mIsPolygon = true;
179179
double d = mMapCanvas->extent().width() * 0.005;
180-
QgsPoint pt = mr->layerToMapCoordinates( &layer, geom->asPoint() );
180+
QgsPoint pt;
181+
if(layer)
182+
{
183+
pt = mr->layerToMapCoordinates( layer, geom->asPoint() );
184+
}
185+
else
186+
{
187+
pt = geom->asPoint();
188+
}
181189
addPoint( QgsPoint( pt.x() - d, pt.y() - d ) );
182190
addPoint( QgsPoint( pt.x() + d, pt.y() - d ) );
183191
addPoint( QgsPoint( pt.x() + d, pt.y() + d ) );
@@ -194,10 +202,20 @@ void QgsRubberBand::setToGeometry( QgsGeometry* geom, QgsVectorLayer& layer )
194202
for ( int i = 0; i < mpt.size(); ++i )
195203
{
196204
QgsPoint pt = mpt[i];
197-
addPoint( mr->layerToMapCoordinates( &layer, QgsPoint( pt.x() - d, pt.y() - d ) ) );
198-
addPoint( mr->layerToMapCoordinates( &layer, QgsPoint( pt.x() + d, pt.y() - d ) ) );
199-
addPoint( mr->layerToMapCoordinates( &layer, QgsPoint( pt.x() + d, pt.y() + d ) ) );
200-
addPoint( mr->layerToMapCoordinates( &layer, QgsPoint( pt.x() - d, pt.y() + d ) ) );
205+
if(layer)
206+
{
207+
addPoint( mr->layerToMapCoordinates( layer, QgsPoint( pt.x() - d, pt.y() - d ) ) );
208+
addPoint( mr->layerToMapCoordinates( layer, QgsPoint( pt.x() + d, pt.y() - d ) ) );
209+
addPoint( mr->layerToMapCoordinates( layer, QgsPoint( pt.x() + d, pt.y() + d ) ) );
210+
addPoint( mr->layerToMapCoordinates( layer, QgsPoint( pt.x() - d, pt.y() + d ) ) );
211+
}
212+
else
213+
{
214+
addPoint(QgsPoint( pt.x() - d, pt.y() - d ) );
215+
addPoint(QgsPoint( pt.x() + d, pt.y() - d ) );
216+
addPoint(QgsPoint( pt.x() + d, pt.y() + d ) );
217+
addPoint(QgsPoint( pt.x() - d, pt.y() + d ) );
218+
}
201219
}
202220
}
203221
break;
@@ -209,7 +227,14 @@ void QgsRubberBand::setToGeometry( QgsGeometry* geom, QgsVectorLayer& layer )
209227
QgsPolyline line = geom->asPolyline();
210228
for ( int i = 0; i < line.count(); i++ )
211229
{
212-
addPoint( mr->layerToMapCoordinates( &layer, line[i] ) );
230+
if(layer)
231+
{
232+
addPoint( mr->layerToMapCoordinates( layer, line[i] ) );
233+
}
234+
else
235+
{
236+
addPoint(line[i]);
237+
}
213238
}
214239
}
215240
break;
@@ -228,7 +253,14 @@ void QgsRubberBand::setToGeometry( QgsGeometry* geom, QgsVectorLayer& layer )
228253
QgsPolyline line = mline[i];
229254
for ( int j = 0; j < line.size(); ++j )
230255
{
231-
addPoint( mr->layerToMapCoordinates( &layer, line[j] ), false, i );
256+
if(layer)
257+
{
258+
addPoint( mr->layerToMapCoordinates( layer, line[j] ), false, i );
259+
}
260+
else
261+
{
262+
addPoint(line[j]);
263+
}
232264
}
233265
}
234266
}
@@ -242,7 +274,14 @@ void QgsRubberBand::setToGeometry( QgsGeometry* geom, QgsVectorLayer& layer )
242274
QgsPolyline line = poly[0];
243275
for ( int i = 0; i < line.count(); i++ )
244276
{
245-
addPoint( mr->layerToMapCoordinates( &layer, line[i] ) );
277+
if(layer)
278+
{
279+
addPoint( mr->layerToMapCoordinates( layer, line[i] ) );
280+
}
281+
else
282+
{
283+
addPoint(line[i]);
284+
}
246285
}
247286
}
248287
break;
@@ -262,7 +301,14 @@ void QgsRubberBand::setToGeometry( QgsGeometry* geom, QgsVectorLayer& layer )
262301
QgsPolyline line = poly[0];
263302
for ( int j = 0; j < line.count(); ++j )
264303
{
265-
addPoint( mr->layerToMapCoordinates( &layer, line[j] ), false, i );
304+
if(layer)
305+
{
306+
addPoint( mr->layerToMapCoordinates( layer, line[j] ), false, i );
307+
}
308+
else
309+
{
310+
addPoint(line[j]);
311+
}
266312
}
267313
}
268314
}

‎src/gui/qgsrubberband.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,10 @@ class GUI_EXPORT QgsRubberBand: public QgsMapCanvasItem
5656
/**Sets this rubber band to the geometry of an existing feature.
5757
This is usefull for feature highlighting.
5858
@param geom the geometry object
59-
@param layer the layer containing the feature (used for coord transformation)
59+
@param layer the layer containing the feature, used for coord transformation to map
60+
crs. In case of 0 pointer, the coordinates are not going to be transformed.
6061
@param render the maprender object (used for coord transformation)*/
61-
void setToGeometry( QgsGeometry* geom, QgsVectorLayer& layer );
62+
void setToGeometry( QgsGeometry* geom, QgsVectorLayer* layer );
6263

6364
/**Adds translation to original coordinates (all in map coordinates)*/
6465
void setTranslationOffset( double dx, double dy );

0 commit comments

Comments
 (0)
Please sign in to comment.