Skip to content

Commit

Permalink
Merge pull request #341 from matthias-kuhn/rubberband-point
Browse files Browse the repository at this point in the history
Allow the rubberband to display points
  • Loading branch information
mhugent committed Dec 6, 2012
2 parents ef6da72 + fc22a6f commit b777b51
Show file tree
Hide file tree
Showing 24 changed files with 178 additions and 99 deletions.
6 changes: 4 additions & 2 deletions python/gui/qgsrubberband.sip
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/app/nodetool/qgsmaptoolnodetool.cpp
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions src/app/qgsmaptoolpinlabels.cpp
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading

0 comments on commit b777b51

Please sign in to comment.