Skip to content

Commit

Permalink
Extend QgsRubberBand to support points.
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Nov 26, 2012
1 parent 6e24c16 commit 91d8aaf
Show file tree
Hide file tree
Showing 23 changed files with 150 additions and 97 deletions.
6 changes: 3 additions & 3 deletions src/app/nodetool/qgsmaptoolnodetool.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsmaptoolcapture.cpp
Expand Up @@ -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 );
Expand Down
4 changes: 2 additions & 2 deletions src/app/qgsmaptooledit.cpp
Expand Up @@ -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() );
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsmaptooledit.h
Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions src/app/qgsmaptoollabel.cpp
Expand Up @@ -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() ) );
Expand All @@ -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();
Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsmaptoolmeasureangle.cpp
Expand Up @@ -126,7 +126,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();
Expand Down
4 changes: 2 additions & 2 deletions src/app/qgsmaptoolpinlabels.cpp
Expand Up @@ -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 )
Expand Down Expand Up @@ -105,7 +105,7 @@ void QgsMapToolPinLabels::canvasReleaseEvent( QMouseEvent * e )

delete selectGeom;

mRubberBand->reset( true );
mRubberBand->reset( QGis::Polygon );
delete mRubberBand;
mRubberBand = 0;
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsmaptoolrotatelabel.cpp
Expand Up @@ -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 );
Expand Down
4 changes: 2 additions & 2 deletions src/app/qgsmaptoolselect.cpp
Expand Up @@ -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 );
}
4 changes: 2 additions & 2 deletions src/app/qgsmaptoolselectfreehand.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/app/qgsmaptoolselectpolygon.cpp
Expand Up @@ -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 )
{
Expand All @@ -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;
}
Expand Down
8 changes: 4 additions & 4 deletions src/app/qgsmaptoolselectradius.cpp
Expand Up @@ -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;
}
Expand All @@ -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 ) );
Expand All @@ -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;
Expand All @@ -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 );
Expand Down
4 changes: 2 additions & 2 deletions src/app/qgsmaptoolselectrectangle.cpp
Expand Up @@ -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 );
}


Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsmaptoolselectutils.cpp
Expand Up @@ -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 );
Expand Down
4 changes: 2 additions & 2 deletions src/app/qgsmaptoolshowhidelabels.cpp
Expand Up @@ -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 )
Expand Down Expand Up @@ -93,7 +93,7 @@ void QgsMapToolShowHideLabels::canvasReleaseEvent( QMouseEvent * e )

showHideLabels( e );

mRubberBand->reset( true );
mRubberBand->reset( QGis::Polygon );
delete mRubberBand;
mRubberBand = 0;
}
Expand Down
4 changes: 2 additions & 2 deletions src/app/qgsmeasuretool.cpp
Expand Up @@ -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 );
Expand Down Expand Up @@ -103,7 +103,7 @@ void QgsMeasureTool::restart()
{
mPoints.clear();

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

// re-read settings
updateSettings();
Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgsmaptoolzoom.cpp
Expand Up @@ -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() );
Expand Down

0 comments on commit 91d8aaf

Please sign in to comment.