Skip to content
Permalink
Browse files
Merge pull request #341 from matthias-kuhn/rubberband-point
Allow the rubberband to display points
  • Loading branch information
mhugent committed Dec 6, 2012
2 parents ef6da72 + fc22a6f commit b777b51147e7b9ea0d89d480273d4d8240c9b594
@@ -5,13 +5,15 @@ class QgsRubberBand: QgsMapCanvasItem
%End

public:
QgsRubberBand( QgsMapCanvas* mapCanvas /TransferThis/, bool isPolygon = false );
QgsRubberBand( QgsMapCanvas* mapCanvas /TransferThis/, QGis::GeometryType geometryType = QGis::Line );
QgsRubberBand( QgsMapCanvas* mapCanvas /TransferThis/, bool isPolygon );
~QgsRubberBand();

void setColor( const QColor & color );
void setWidth( int width );

void reset( bool isPolygon = false );
void reset( QGis::GeometryType geometryType = QGis::Line );
void reset( bool isPolygon );

//! Add point to rubberband and update canvas
//! If adding more points consider using update=false for better performance
@@ -78,7 +78,7 @@ void QgsMapToolNodeTool::createMovingRubberBands()
}
// we have first vertex of moving part
// create rubberband and set default paramaters
QgsRubberBand* rb = new QgsRubberBand( mCanvas, false );
QgsRubberBand* rb = new QgsRubberBand( mCanvas, QGis::Line );
rb->setWidth( 2 );
rb->setColor( Qt::blue );
int index = 0;
@@ -137,7 +137,7 @@ void QgsMapToolNodeTool::createTopologyRubberBands( QgsVectorLayer* vlayer, cons
continue;
}
}
QgsRubberBand* trb = new QgsRubberBand( mCanvas, false );
QgsRubberBand* trb = new QgsRubberBand( mCanvas, QGis::Line );
mTopologyRubberBand.append( trb );
int rbId = mTopologyRubberBand.size() - 1;
trb->setWidth( 1 );
@@ -701,7 +701,7 @@ void QgsMapToolNodeTool::keyReleaseEvent( QKeyEvent* e )
QgsRubberBand* QgsMapToolNodeTool::createRubberBandMarker( QgsPoint center, QgsVectorLayer* vlayer )
{
// create rubberband marker for moving points
QgsRubberBand* marker = new QgsRubberBand( mCanvas, true );
QgsRubberBand* marker = new QgsRubberBand( mCanvas, QGis::Polygon );
marker->setColor( Qt::red );
marker->setWidth( 2 );
double movement = 4;
@@ -204,7 +204,7 @@ int QgsMapToolCapture::addVertex( const QPoint &p )

if ( !mRubberBand )
{
mRubberBand = createRubberBand( mCaptureMode == CapturePolygon );
mRubberBand = createRubberBand( mCaptureMode == CapturePolygon ? QGis::Polygon : QGis::Line );
}

mRubberBand->addPoint( mapPoint );
@@ -66,10 +66,10 @@ QgsPoint QgsMapToolEdit::snapPointFromResults( const QList<QgsSnappingResult>& s
}
}

QgsRubberBand* QgsMapToolEdit::createRubberBand( bool isPolygon )
QgsRubberBand* QgsMapToolEdit::createRubberBand( QGis::GeometryType geometryType )
{
QSettings settings;
QgsRubberBand* rb = new QgsRubberBand( mCanvas, isPolygon );
QgsRubberBand* rb = new QgsRubberBand( mCanvas, geometryType );
QColor color( settings.value( "/qgis/digitizing/line_color_red", 255 ).toInt(),
settings.value( "/qgis/digitizing/line_color_green", 0 ).toInt(),
settings.value( "/qgis/digitizing/line_color_blue", 0 ).toInt() );
@@ -53,7 +53,7 @@ class QgsMapToolEdit: public QgsMapTool
/**Creates a rubber band with the color/line width from
the QGIS settings. The caller takes ownership of the
returned object*/
QgsRubberBand* createRubberBand( bool isPolygon = false );
QgsRubberBand* createRubberBand( QGis::GeometryType geometryType = QGis::Line );

/**Returns the current vector layer of the map canvas or 0*/
QgsVectorLayer* currentVectorLayer();
@@ -59,7 +59,7 @@ void QgsMapToolLabel::createRubberBands( )

//label rubber band
QgsRectangle rect = mCurrentLabelPos.labelRect;
mLabelRubberBand = new QgsRubberBand( mCanvas, false );
mLabelRubberBand = new QgsRubberBand( mCanvas, QGis::Line );
mLabelRubberBand->addPoint( QgsPoint( rect.xMinimum(), rect.yMinimum() ) );
mLabelRubberBand->addPoint( QgsPoint( rect.xMinimum(), rect.yMaximum() ) );
mLabelRubberBand->addPoint( QgsPoint( rect.xMaximum(), rect.yMaximum() ) );
@@ -79,7 +79,7 @@ void QgsMapToolLabel::createRubberBands( )
QgsGeometry* geom = f.geometry();
if ( geom )
{
mFeatureRubberBand = new QgsRubberBand( mCanvas, geom->type() == QGis::Polygon );
mFeatureRubberBand = new QgsRubberBand( mCanvas, geom->type() );
mFeatureRubberBand->setColor( Qt::red );
mFeatureRubberBand->setToGeometry( geom, vlayer );
mFeatureRubberBand->show();
@@ -100,7 +100,7 @@ void QgsMapToolLabel::createRubberBands( )
}

QgsGeometry* pointGeom = QgsGeometry::fromPoint( fixPoint );
mFixPointRubberBand = new QgsRubberBand( mCanvas, false );
mFixPointRubberBand = new QgsRubberBand( mCanvas, QGis::Line );
mFixPointRubberBand->setColor( Qt::blue );
mFixPointRubberBand->setToGeometry( pointGeom, vlayer );
mFixPointRubberBand->show();
@@ -127,7 +127,7 @@ void QgsMapToolMeasureAngle::deactivate()
void QgsMapToolMeasureAngle::createRubberBand()
{
delete mRubberBand;
mRubberBand = new QgsRubberBand( mCanvas, false );
mRubberBand = new QgsRubberBand( mCanvas, QGis::Line );

QSettings settings;
int myRed = settings.value( "/qgis/default_measure_color_red", 180 ).toInt();
@@ -52,7 +52,7 @@ void QgsMapToolPinLabels::canvasPressEvent( QMouseEvent * e )
mSelectRect.setRect( 0, 0, 0, 0 );
mSelectRect.setTopLeft( e->pos() );
mSelectRect.setBottomRight( e->pos() );
mRubberBand = new QgsRubberBand( mCanvas, true );
mRubberBand = new QgsRubberBand( mCanvas, QGis::Polygon );
}

void QgsMapToolPinLabels::canvasMoveEvent( QMouseEvent * e )
@@ -105,7 +105,7 @@ void QgsMapToolPinLabels::canvasReleaseEvent( QMouseEvent * e )

delete selectGeom;

mRubberBand->reset( true );
mRubberBand->reset( QGis::Polygon );
delete mRubberBand;
mRubberBand = 0;
}
@@ -197,7 +197,7 @@ QgsRubberBand* QgsMapToolRotateLabel::createRotationPreviewBox()
return 0;
}

mRotationPreviewBox = new QgsRubberBand( mCanvas, false );
mRotationPreviewBox = new QgsRubberBand( mCanvas, QGis::Line );
mRotationPreviewBox->setColor( Qt::blue );
mRotationPreviewBox->setWidth( 3 );
setRotationPreviewBox( mCurrentRotation - mStartRotation );
@@ -40,13 +40,13 @@ void QgsMapToolSelect::canvasReleaseEvent( QMouseEvent * e )
{
return;
}
QgsRubberBand rubberBand( mCanvas, true );
QgsRubberBand rubberBand( mCanvas, QGis::Polygon );
QRect selectRect( 0, 0, 0, 0 );
QgsMapToolSelectUtils::expandSelectRectangle( selectRect, vlayer, e->pos() );
QgsMapToolSelectUtils::setRubberBand( mCanvas, selectRect, &rubberBand );
QgsGeometry* selectGeom = rubberBand.asGeometry();
bool doDifference = e->modifiers() & Qt::ControlModifier ? true : false;
QgsMapToolSelectUtils::setSelectFeatures( mCanvas, selectGeom, false, doDifference, true );
delete selectGeom;
rubberBand.reset( true );
rubberBand.reset( QGis::Polygon );
}
@@ -43,7 +43,7 @@ void QgsMapToolSelectFreehand::canvasPressEvent( QMouseEvent * e )
}
if ( mRubberBand == NULL )
{
mRubberBand = new QgsRubberBand( mCanvas, true );
mRubberBand = new QgsRubberBand( mCanvas, QGis::Polygon );
}
mRubberBand->addPoint( toMapCoordinates( e->pos() ) );
mDragging = true;
@@ -72,7 +72,7 @@ void QgsMapToolSelectFreehand::canvasReleaseEvent( QMouseEvent * e )
QgsMapToolSelectUtils::setSelectFeatures( mCanvas, shapeGeom, e );
delete shapeGeom;
}
mRubberBand->reset( true );
mRubberBand->reset( QGis::Polygon );
delete mRubberBand;
mRubberBand = 0;
mDragging = false;
@@ -39,7 +39,7 @@ void QgsMapToolSelectPolygon::canvasPressEvent( QMouseEvent * e )
{
if ( mRubberBand == NULL )
{
mRubberBand = new QgsRubberBand( mCanvas, true );
mRubberBand = new QgsRubberBand( mCanvas, QGis::Polygon );
}
if ( e->button() == Qt::LeftButton )
{
@@ -53,7 +53,7 @@ void QgsMapToolSelectPolygon::canvasPressEvent( QMouseEvent * e )
QgsMapToolSelectUtils::setSelectFeatures( mCanvas, polygonGeom, e );
delete polygonGeom;
}
mRubberBand->reset( true );
mRubberBand->reset( QGis::Polygon );
delete mRubberBand;
mRubberBand = 0;
}
@@ -62,7 +62,7 @@ void QgsMapToolSelectRadius::canvasMoveEvent( QMouseEvent * e )
{
if ( mRubberBand == NULL )
{
mRubberBand = new QgsRubberBand( mCanvas, true );
mRubberBand = new QgsRubberBand( mCanvas, QGis::Polygon );
}
mDragging = true;
}
@@ -81,7 +81,7 @@ void QgsMapToolSelectRadius::canvasReleaseEvent( QMouseEvent * e )
{
if ( mRubberBand == NULL )
{
mRubberBand = new QgsRubberBand( mCanvas, true );
mRubberBand = new QgsRubberBand( mCanvas, QGis::Polygon );
}
mRadiusCenter = toMapCoordinates( e->pos() );
QgsPoint radiusEdge = toMapCoordinates( QPoint( e->pos().x() + 1, e->pos().y() + 1 ) );
@@ -90,7 +90,7 @@ void QgsMapToolSelectRadius::canvasReleaseEvent( QMouseEvent * e )
QgsGeometry* radiusGeometry = mRubberBand->asGeometry();
QgsMapToolSelectUtils::setSelectFeatures( mCanvas, radiusGeometry, e );
delete radiusGeometry;
mRubberBand->reset( true );
mRubberBand->reset( QGis::Polygon );
delete mRubberBand;
mRubberBand = 0;
mDragging = false;
@@ -100,7 +100,7 @@ void QgsMapToolSelectRadius::canvasReleaseEvent( QMouseEvent * e )
void QgsMapToolSelectRadius::setRadiusRubberBand( QgsPoint & radiusEdge )
{
double r = sqrt( mRadiusCenter.sqrDist( radiusEdge ) );
mRubberBand->reset( true );
mRubberBand->reset( QGis::Polygon );
for ( int i = 0; i <= RADIUS_SEGMENTS; ++i )
{
double theta = i * ( 2.0 * M_PI / RADIUS_SEGMENTS );
@@ -42,7 +42,7 @@ void QgsMapToolSelectRectangle::canvasPressEvent( QMouseEvent *e )
{
Q_UNUSED( e );
mSelectRect.setRect( 0, 0, 0, 0 );
mRubberBand = new QgsRubberBand( mCanvas, true );
mRubberBand = new QgsRubberBand( mCanvas, QGis::Polygon );
}


@@ -97,7 +97,7 @@ void QgsMapToolSelectRectangle::canvasReleaseEvent( QMouseEvent *e )
QgsMapToolSelectUtils::setSelectFeatures( mCanvas, selectGeom, e );
delete selectGeom;

mRubberBand->reset( true );
mRubberBand->reset( QGis::Polygon );
delete mRubberBand;
mRubberBand = 0;
}
@@ -51,7 +51,7 @@ void QgsMapToolSelectUtils::setRubberBand( QgsMapCanvas* canvas, QRect& selectRe

if ( rubberBand )
{
rubberBand->reset( true );
rubberBand->reset( QGis::Polygon );
rubberBand->addPoint( ll, false );
rubberBand->addPoint( QgsPoint( ur.x(), ll.y() ), false );
rubberBand->addPoint( ur, false );
@@ -45,7 +45,7 @@ void QgsMapToolShowHideLabels::canvasPressEvent( QMouseEvent * e )
mSelectRect.setRect( 0, 0, 0, 0 );
mSelectRect.setTopLeft( e->pos() );
mSelectRect.setBottomRight( e->pos() );
mRubberBand = new QgsRubberBand( mCanvas, true );
mRubberBand = new QgsRubberBand( mCanvas, QGis::Polygon );
}

void QgsMapToolShowHideLabels::canvasMoveEvent( QMouseEvent * e )
@@ -93,7 +93,7 @@ void QgsMapToolShowHideLabels::canvasReleaseEvent( QMouseEvent * e )

showHideLabels( e );

mRubberBand->reset( true );
mRubberBand->reset( QGis::Polygon );
delete mRubberBand;
mRubberBand = 0;
}
@@ -35,7 +35,7 @@ QgsMeasureTool::QgsMeasureTool( QgsMapCanvas* canvas, bool measureArea )
{
mMeasureArea = measureArea;

mRubberBand = new QgsRubberBand( canvas, mMeasureArea );
mRubberBand = new QgsRubberBand( canvas, mMeasureArea ? QGis::Polygon : QGis::Line );

QPixmap myCrossHairQPixmap = QPixmap(( const char ** ) cross_hair_cursor );
mCursor = QCursor( myCrossHairQPixmap, 8, 8 );
@@ -103,7 +103,7 @@ void QgsMeasureTool::restart()
{
mPoints.clear();

mRubberBand->reset( mMeasureArea );
mRubberBand->reset( mMeasureArea ? QGis::Polygon : QGis::Line );

// re-read settings
updateSettings();
@@ -49,7 +49,7 @@ void QgsMapToolZoom::canvasMoveEvent( QMouseEvent * e )
{
mDragging = true;
delete mRubberBand;
mRubberBand = new QgsRubberBand( mCanvas, true );
mRubberBand = new QgsRubberBand( mCanvas, QGis::Polygon );
mZoomRect.setTopLeft( e->pos() );
}
mZoomRect.setBottomRight( e->pos() );

0 comments on commit b777b51

Please sign in to comment.