mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-15 00:04:00 -04:00
Add different point symbols for QgsRubberband.
This commit is contained in:
parent
a4a8b4cc76
commit
f2328962df
@ -5,13 +5,35 @@ class QgsRubberBand: QgsMapCanvasItem
|
|||||||
%End
|
%End
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
/** Icons
|
||||||
|
* Added in 1.9 */
|
||||||
|
enum IconType
|
||||||
|
{
|
||||||
|
ICON_NONE,
|
||||||
|
ICON_CROSS,
|
||||||
|
ICON_X,
|
||||||
|
ICON_BOX,
|
||||||
|
ICON_CIRCLE
|
||||||
|
};
|
||||||
|
|
||||||
QgsRubberBand( QgsMapCanvas* mapCanvas /TransferThis/, QGis::GeometryType geometryType = QGis::Line );
|
QgsRubberBand( QgsMapCanvas* mapCanvas /TransferThis/, QGis::GeometryType geometryType = QGis::Line );
|
||||||
QgsRubberBand( QgsMapCanvas* mapCanvas /TransferThis/, bool isPolygon );
|
QgsRubberBand( QgsMapCanvas* mapCanvas /TransferThis/, bool isPolygon );
|
||||||
~QgsRubberBand();
|
~QgsRubberBand();
|
||||||
|
|
||||||
|
/** Set the color for the rubberband */
|
||||||
void setColor( const QColor & color );
|
void setColor( const QColor & color );
|
||||||
|
|
||||||
|
/** Set the width of the line. Outline width for polygon. */
|
||||||
void setWidth( int width );
|
void setWidth( int width );
|
||||||
|
|
||||||
|
/** Set the icon type to highlight point geometries.
|
||||||
|
* Added in 1.9 */
|
||||||
|
void setIcon( IconType icon );
|
||||||
|
|
||||||
|
/** Set the size of the point icons
|
||||||
|
* Added in 1.9 */
|
||||||
|
void setIconSize ( int iconSize );
|
||||||
|
|
||||||
void reset( QGis::GeometryType geometryType = QGis::Line );
|
void reset( QGis::GeometryType geometryType = QGis::Line );
|
||||||
void reset( bool isPolygon );
|
void reset( bool isPolygon );
|
||||||
|
|
||||||
@ -30,6 +52,7 @@ class QgsRubberBand: QgsMapCanvasItem
|
|||||||
|
|
||||||
/**Sets this rubber band to the geometry of an existing feature.
|
/**Sets this rubber band to the geometry of an existing feature.
|
||||||
This is useful for feature highlighting.
|
This is useful for feature highlighting.
|
||||||
|
In contrast to addGeometry, this method does also change the geometry type of the rubberband.
|
||||||
@param geom the geometry object
|
@param geom the geometry object
|
||||||
@param layer the layer containing the feature, used for coord transformation to map
|
@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.
|
crs. In case of 0 pointer, the coordinates are not going to be transformed.
|
||||||
|
@ -30,6 +30,8 @@
|
|||||||
QgsRubberBand::QgsRubberBand( QgsMapCanvas* mapCanvas, QGis::GeometryType geometryType )
|
QgsRubberBand::QgsRubberBand( QgsMapCanvas* mapCanvas, QGis::GeometryType geometryType )
|
||||||
: QgsMapCanvasItem( mapCanvas )
|
: QgsMapCanvasItem( mapCanvas )
|
||||||
, mWidth( 1 )
|
, mWidth( 1 )
|
||||||
|
, mIconSize( 5 )
|
||||||
|
, mIconType( ICON_CIRCLE )
|
||||||
, mGeometryType( geometryType )
|
, mGeometryType( geometryType )
|
||||||
, mTranslationOffsetX( 0.0 )
|
, mTranslationOffsetX( 0.0 )
|
||||||
, mTranslationOffsetY( 0.0 )
|
, mTranslationOffsetY( 0.0 )
|
||||||
@ -41,6 +43,8 @@ QgsRubberBand::QgsRubberBand( QgsMapCanvas* mapCanvas, QGis::GeometryType geomet
|
|||||||
QgsRubberBand::QgsRubberBand( QgsMapCanvas* mapCanvas, bool isPolygon )
|
QgsRubberBand::QgsRubberBand( QgsMapCanvas* mapCanvas, bool isPolygon )
|
||||||
: QgsMapCanvasItem( mapCanvas )
|
: QgsMapCanvasItem( mapCanvas )
|
||||||
, mWidth( 1 )
|
, mWidth( 1 )
|
||||||
|
, mIconSize( 5 )
|
||||||
|
, mIconType( ICON_CIRCLE )
|
||||||
, mTranslationOffsetX( 0.0 )
|
, mTranslationOffsetX( 0.0 )
|
||||||
, mTranslationOffsetY( 0.0 )
|
, mTranslationOffsetY( 0.0 )
|
||||||
{
|
{
|
||||||
@ -75,6 +79,16 @@ void QgsRubberBand::setWidth( int width )
|
|||||||
mWidth = width;
|
mWidth = width;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QgsRubberBand::setIcon( IconType icon )
|
||||||
|
{
|
||||||
|
mIconType = icon;
|
||||||
|
}
|
||||||
|
|
||||||
|
void QgsRubberBand::setIconSize( int iconSize )
|
||||||
|
{
|
||||||
|
mIconSize = iconSize;
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
Remove all points from the shape being created.
|
Remove all points from the shape being created.
|
||||||
*/
|
*/
|
||||||
@ -189,7 +203,7 @@ void QgsRubberBand::movePoint( int index, const QgsPoint& p, int geometryIndex )
|
|||||||
|
|
||||||
void QgsRubberBand::setToGeometry( QgsGeometry* geom, QgsVectorLayer* layer )
|
void QgsRubberBand::setToGeometry( QgsGeometry* geom, QgsVectorLayer* layer )
|
||||||
{
|
{
|
||||||
reset( mGeometryType );
|
reset( geom->type() );
|
||||||
addGeometry( geom, layer );
|
addGeometry( geom, layer );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -215,7 +229,6 @@ void QgsRubberBand::addGeometry( QgsGeometry* geom, QgsVectorLayer* layer )
|
|||||||
case QGis::WKBPoint:
|
case QGis::WKBPoint:
|
||||||
case QGis::WKBPoint25D:
|
case QGis::WKBPoint25D:
|
||||||
{
|
{
|
||||||
double d = mMapCanvas->extent().width() * 0.005;
|
|
||||||
QgsPoint pt;
|
QgsPoint pt;
|
||||||
if ( layer )
|
if ( layer )
|
||||||
{
|
{
|
||||||
@ -225,34 +238,24 @@ void QgsRubberBand::addGeometry( QgsGeometry* geom, QgsVectorLayer* layer )
|
|||||||
{
|
{
|
||||||
pt = geom->asPoint();
|
pt = geom->asPoint();
|
||||||
}
|
}
|
||||||
addPoint( QgsPoint( pt.x() - d, pt.y() - d ), false, idx );
|
addPoint( pt, false, idx );
|
||||||
addPoint( QgsPoint( pt.x() + d, pt.y() - d ), false, idx );
|
|
||||||
addPoint( QgsPoint( pt.x() + d, pt.y() + d ), false, idx );
|
|
||||||
addPoint( QgsPoint( pt.x() - d, pt.y() + d ), false, idx );
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case QGis::WKBMultiPoint:
|
case QGis::WKBMultiPoint:
|
||||||
case QGis::WKBMultiPoint25D:
|
case QGis::WKBMultiPoint25D:
|
||||||
{
|
{
|
||||||
double d = mMapCanvas->extent().width() * 0.005;
|
|
||||||
QgsMultiPoint mpt = geom->asMultiPoint();
|
QgsMultiPoint mpt = geom->asMultiPoint();
|
||||||
for ( int i = 0; i < mpt.size(); ++i, ++idx )
|
for ( int i = 0; i < mpt.size(); ++i, ++idx )
|
||||||
{
|
{
|
||||||
QgsPoint pt = mpt[i];
|
QgsPoint pt = mpt[i];
|
||||||
if ( layer )
|
if ( layer )
|
||||||
{
|
{
|
||||||
addPoint( mr->layerToMapCoordinates( layer, QgsPoint( pt.x() - d, pt.y() - d ) ), false, idx );
|
addPoint( mr->layerToMapCoordinates( layer, pt ), false, idx );
|
||||||
addPoint( mr->layerToMapCoordinates( layer, QgsPoint( pt.x() + d, pt.y() - d ) ), false, idx );
|
|
||||||
addPoint( mr->layerToMapCoordinates( layer, QgsPoint( pt.x() + d, pt.y() + d ) ), false, idx );
|
|
||||||
addPoint( mr->layerToMapCoordinates( layer, QgsPoint( pt.x() - d, pt.y() + d ) ), false, idx );
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
addPoint( QgsPoint( pt.x() - d, pt.y() - d ), false, idx );
|
addPoint( pt, false, idx );
|
||||||
addPoint( QgsPoint( pt.x() + d, pt.y() - d ), false, idx );
|
|
||||||
addPoint( QgsPoint( pt.x() + d, pt.y() + d ), false, idx );
|
|
||||||
addPoint( QgsPoint( pt.x() - d, pt.y() + d ), false, idx );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -386,6 +389,8 @@ void QgsRubberBand::paint( QPainter* p )
|
|||||||
if ( mPoints.size() > 0 )
|
if ( mPoints.size() > 0 )
|
||||||
{
|
{
|
||||||
p->setBrush( mBrush );
|
p->setBrush( mBrush );
|
||||||
|
mPen.setWidth( mWidth );
|
||||||
|
p->setPen( mPen );
|
||||||
|
|
||||||
for ( int i = 0; i < mPoints.size(); ++i )
|
for ( int i = 0; i < mPoints.size(); ++i )
|
||||||
{
|
{
|
||||||
@ -400,20 +405,46 @@ void QgsRubberBand::paint( QPainter* p )
|
|||||||
{
|
{
|
||||||
case QGis::Polygon:
|
case QGis::Polygon:
|
||||||
{
|
{
|
||||||
mPen.setWidth( mWidth );
|
|
||||||
p->setPen( mPen );
|
|
||||||
p->drawPolygon( pts );
|
p->drawPolygon( pts );
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case QGis::Point:
|
case QGis::Point:
|
||||||
{
|
{
|
||||||
mPen.setWidth( 1 );
|
|
||||||
p->setPen( mPen );
|
|
||||||
QVector<QPointF>::const_iterator ptIt = pts.constBegin();
|
QVector<QPointF>::const_iterator ptIt = pts.constBegin();
|
||||||
for ( ; ptIt != pts.constEnd(); ++ptIt )
|
for ( ; ptIt != pts.constEnd(); ++ptIt )
|
||||||
{
|
{
|
||||||
p->drawEllipse(( *ptIt ).x() - mWidth / 2, ( *ptIt ).y() - mWidth / 2, mWidth, mWidth );
|
double x = (*ptIt).x();
|
||||||
|
double y = (*ptIt).y();
|
||||||
|
|
||||||
|
qreal s = ( mIconSize - 1 ) / 2;
|
||||||
|
|
||||||
|
switch ( mIconType )
|
||||||
|
{
|
||||||
|
case ICON_NONE:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ICON_CROSS:
|
||||||
|
p->drawLine( QLineF( x - s, y, x + s, y ) );
|
||||||
|
p->drawLine( QLineF( x, y - s, x, y + s ) );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ICON_X:
|
||||||
|
p->drawLine( QLineF( x - s, y - s, x + s, y + s ) );
|
||||||
|
p->drawLine( QLineF( x - s, y + s, x + s, y - s ) );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ICON_BOX:
|
||||||
|
p->drawLine( QLineF( x - s, y - s, x + s, y - s ) );
|
||||||
|
p->drawLine( QLineF( x + s, y - s, x + s, y + s ) );
|
||||||
|
p->drawLine( QLineF( x + s, y + s, x - s, y + s ) );
|
||||||
|
p->drawLine( QLineF( x - s, y + s, x - s, y - s ) );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ICON_CIRCLE:
|
||||||
|
p->drawEllipse( x - s, y - s, mIconSize, mIconSize );
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -421,8 +452,6 @@ void QgsRubberBand::paint( QPainter* p )
|
|||||||
case QGis::Line:
|
case QGis::Line:
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
mPen.setWidth( mWidth );
|
|
||||||
p->setPen( mPen );
|
|
||||||
p->drawPolyline( pts );
|
p->drawPolyline( pts );
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -449,7 +478,10 @@ void QgsRubberBand::updateRect()
|
|||||||
QList<QgsPoint>::const_iterator it = mPoints.at( i ).constBegin();
|
QList<QgsPoint>::const_iterator it = mPoints.at( i ).constBegin();
|
||||||
for ( ; it != mPoints.at( i ).constEnd(); ++it )
|
for ( ; it != mPoints.at( i ).constEnd(); ++it )
|
||||||
{
|
{
|
||||||
r.combineExtentWith( it->x() + mTranslationOffsetX, it->y() + mTranslationOffsetY );
|
qreal s = ( mIconSize - 1 ) / 2;
|
||||||
|
QgsRectangle rect = QgsRectangle( it->x() + mTranslationOffsetX - s, it->y() + mTranslationOffsetY - s,
|
||||||
|
it->x() + mTranslationOffsetX + s, it->y() + mTranslationOffsetY + s );
|
||||||
|
r.combineExtentWith( &rect );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setRect( r );
|
setRect( r );
|
||||||
|
@ -31,6 +31,18 @@ class QPaintEvent;
|
|||||||
class GUI_EXPORT QgsRubberBand: public QgsMapCanvasItem
|
class GUI_EXPORT QgsRubberBand: public QgsMapCanvasItem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
/** Icons
|
||||||
|
* Added in 1.9 */
|
||||||
|
enum IconType
|
||||||
|
{
|
||||||
|
ICON_NONE,
|
||||||
|
ICON_CROSS,
|
||||||
|
ICON_X,
|
||||||
|
ICON_BOX,
|
||||||
|
ICON_CIRCLE
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new RubberBand.
|
* Creates a new RubberBand.
|
||||||
* @param mapCanvas The map canvas to draw onto. It's CRS will be used map points onto screen coordinates.
|
* @param mapCanvas The map canvas to draw onto. It's CRS will be used map points onto screen coordinates.
|
||||||
@ -47,9 +59,20 @@ class GUI_EXPORT QgsRubberBand: public QgsMapCanvasItem
|
|||||||
QgsRubberBand( QgsMapCanvas* mapCanvas, bool isPolygon );
|
QgsRubberBand( QgsMapCanvas* mapCanvas, bool isPolygon );
|
||||||
~QgsRubberBand();
|
~QgsRubberBand();
|
||||||
|
|
||||||
|
/** Set the color for the rubberband */
|
||||||
void setColor( const QColor & color );
|
void setColor( const QColor & color );
|
||||||
|
|
||||||
|
/** Set the width of the line. Outline width for polygon. */
|
||||||
void setWidth( int width );
|
void setWidth( int width );
|
||||||
|
|
||||||
|
/** Set the icon type to highlight point geometries.
|
||||||
|
* Added in 1.9 */
|
||||||
|
void setIcon( IconType icon );
|
||||||
|
|
||||||
|
/** Set the size of the point icons
|
||||||
|
* Added in 1.9 */
|
||||||
|
void setIconSize ( int iconSize );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clears all the geometries in this rubberband.
|
* Clears all the geometries in this rubberband.
|
||||||
* Sets the representation type according to geometryType.
|
* Sets the representation type according to geometryType.
|
||||||
@ -80,6 +103,7 @@ class GUI_EXPORT QgsRubberBand: public QgsMapCanvasItem
|
|||||||
|
|
||||||
/**Sets this rubber band to the geometry of an existing feature.
|
/**Sets this rubber band to the geometry of an existing feature.
|
||||||
This is useful for feature highlighting.
|
This is useful for feature highlighting.
|
||||||
|
In contrast to addGeometry, this method does also change the geometry type of the rubberband.
|
||||||
@param geom the geometry object
|
@param geom the geometry object
|
||||||
@param layer the layer containing the feature, used for coord transformation to map
|
@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.
|
crs. In case of 0 pointer, the coordinates are not going to be transformed.
|
||||||
@ -127,8 +151,17 @@ class GUI_EXPORT QgsRubberBand: public QgsMapCanvasItem
|
|||||||
QBrush mBrush;
|
QBrush mBrush;
|
||||||
QPen mPen;
|
QPen mPen;
|
||||||
|
|
||||||
|
/** The width of any line within the rubberband. */
|
||||||
int mWidth;
|
int mWidth;
|
||||||
|
|
||||||
|
/** The size of the icon for points.
|
||||||
|
* Added in 1.9 */
|
||||||
|
int mIconSize;
|
||||||
|
|
||||||
|
/** Icon to be shown.
|
||||||
|
* Added in 1.9 */
|
||||||
|
IconType mIconType ;
|
||||||
|
|
||||||
/**Nested lists used for multitypes*/
|
/**Nested lists used for multitypes*/
|
||||||
QList< QList <QgsPoint> > mPoints;
|
QList< QList <QgsPoint> > mPoints;
|
||||||
QGis::GeometryType mGeometryType;
|
QGis::GeometryType mGeometryType;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user