mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-13 00:03:09 -04:00
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
This commit is contained in:
parent
5971fedc70
commit
b49bc46bf8
@ -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);
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
|
@ -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]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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 );
|
||||
|
Loading…
x
Reference in New Issue
Block a user