Skip to content

Commit

Permalink
Allow a 0 pointer for the vector layer in QgsRubberBand::setToGeometry
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@9623 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Nov 11, 2008
1 parent 676df9d commit 257d4b6
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 16 deletions.
5 changes: 3 additions & 2 deletions python/gui/qgsrubberband.sip
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsmaptoolidentify.cpp
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsmaptoolmovefeature.cpp
Expand Up @@ -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();
Expand Down
66 changes: 56 additions & 10 deletions src/gui/qgsrubberband.cpp
Expand Up @@ -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 )
{
Expand All @@ -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 ) );
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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]);
}
}
}
}
Expand All @@ -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;
Expand All @@ -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]);
}
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/gui/qgsrubberband.h
Expand Up @@ -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 );
Expand Down

0 comments on commit 257d4b6

Please sign in to comment.