mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -04:00
Merge pull request #341 from matthias-kuhn/rubberband-point
Allow the rubberband to display points
This commit is contained in:
commit
b777b51147
@ -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,7 +40,7 @@ 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 );
|
||||
@ -48,5 +48,5 @@ void QgsMapToolSelect::canvasReleaseEvent( QMouseEvent * e )
|
||||
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() );
|
||||
|
@ -27,16 +27,22 @@
|
||||
\brief The QgsRubberBand class provides a transparent overlay widget
|
||||
for tracking the mouse while drawing polylines or polygons.
|
||||
*/
|
||||
QgsRubberBand::QgsRubberBand( QgsMapCanvas* mapCanvas, bool isPolygon )
|
||||
QgsRubberBand::QgsRubberBand( QgsMapCanvas* mapCanvas, QGis::GeometryType geometryType )
|
||||
: QgsMapCanvasItem( mapCanvas )
|
||||
, mIsPolygon( isPolygon )
|
||||
, mGeometryType( geometryType )
|
||||
, mTranslationOffsetX( 0.0 )
|
||||
, mTranslationOffsetY( 0.0 )
|
||||
{
|
||||
reset( isPolygon );
|
||||
reset( geometryType );
|
||||
setColor( QColor( Qt::lightGray ) );
|
||||
}
|
||||
|
||||
QgsRubberBand::QgsRubberBand( QgsMapCanvas* mapCanvas, bool isPolygon )
|
||||
: QgsMapCanvasItem( mapCanvas )
|
||||
{
|
||||
QgsRubberBand( mapCanvas, isPolygon ? QGis::Polygon : QGis::Line );
|
||||
}
|
||||
|
||||
QgsRubberBand::QgsRubberBand(): QgsMapCanvasItem( 0 )
|
||||
{
|
||||
}
|
||||
@ -61,16 +67,24 @@ void QgsRubberBand::setColor( const QColor & color )
|
||||
*/
|
||||
void QgsRubberBand::setWidth( int width )
|
||||
{
|
||||
mPen.setWidth( width );
|
||||
mWidth = width;
|
||||
}
|
||||
|
||||
/*!
|
||||
Remove all points from the shape being created.
|
||||
*/
|
||||
void QgsRubberBand::reset( QGis::GeometryType geometryType )
|
||||
{
|
||||
mPoints.clear();
|
||||
mGeometryType = geometryType;
|
||||
updateRect();
|
||||
update();
|
||||
}
|
||||
|
||||
void QgsRubberBand::reset( bool isPolygon )
|
||||
{
|
||||
mPoints.clear();
|
||||
mIsPolygon = isPolygon;
|
||||
mGeometryType = isPolygon ? QGis::Polygon : QGis::Line;
|
||||
updateRect();
|
||||
update();
|
||||
}
|
||||
@ -170,7 +184,7 @@ void QgsRubberBand::movePoint( int index, const QgsPoint& p, int geometryIndex )
|
||||
|
||||
void QgsRubberBand::setToGeometry( QgsGeometry* geom, QgsVectorLayer* layer )
|
||||
{
|
||||
reset( mIsPolygon );
|
||||
reset( mGeometryType );
|
||||
addGeometry( geom, layer );
|
||||
}
|
||||
|
||||
@ -196,7 +210,6 @@ void QgsRubberBand::addGeometry( QgsGeometry* geom, QgsVectorLayer* layer )
|
||||
case QGis::WKBPoint:
|
||||
case QGis::WKBPoint25D:
|
||||
{
|
||||
mIsPolygon = true;
|
||||
double d = mMapCanvas->extent().width() * 0.005;
|
||||
QgsPoint pt;
|
||||
if ( layer )
|
||||
@ -217,7 +230,6 @@ void QgsRubberBand::addGeometry( QgsGeometry* geom, QgsVectorLayer* layer )
|
||||
case QGis::WKBMultiPoint:
|
||||
case QGis::WKBMultiPoint25D:
|
||||
{
|
||||
mIsPolygon = true;
|
||||
double d = mMapCanvas->extent().width() * 0.005;
|
||||
QgsMultiPoint mpt = geom->asMultiPoint();
|
||||
for ( int i = 0; i < mpt.size(); ++i, ++idx )
|
||||
@ -244,7 +256,6 @@ void QgsRubberBand::addGeometry( QgsGeometry* geom, QgsVectorLayer* layer )
|
||||
case QGis::WKBLineString:
|
||||
case QGis::WKBLineString25D:
|
||||
{
|
||||
mIsPolygon = false;
|
||||
QgsPolyline line = geom->asPolyline();
|
||||
for ( int i = 0; i < line.count(); i++ )
|
||||
{
|
||||
@ -263,7 +274,6 @@ void QgsRubberBand::addGeometry( QgsGeometry* geom, QgsVectorLayer* layer )
|
||||
case QGis::WKBMultiLineString:
|
||||
case QGis::WKBMultiLineString25D:
|
||||
{
|
||||
mIsPolygon = false;
|
||||
mPoints.clear();
|
||||
|
||||
QgsMultiPolyline mline = geom->asMultiPolyline();
|
||||
@ -294,7 +304,6 @@ void QgsRubberBand::addGeometry( QgsGeometry* geom, QgsVectorLayer* layer )
|
||||
case QGis::WKBPolygon:
|
||||
case QGis::WKBPolygon25D:
|
||||
{
|
||||
mIsPolygon = true;
|
||||
QgsPolygon poly = geom->asPolygon();
|
||||
QgsPolyline line = poly[0];
|
||||
for ( int i = 0; i < line.count(); i++ )
|
||||
@ -314,7 +323,6 @@ void QgsRubberBand::addGeometry( QgsGeometry* geom, QgsVectorLayer* layer )
|
||||
case QGis::WKBMultiPolygon:
|
||||
case QGis::WKBMultiPolygon25D:
|
||||
{
|
||||
mIsPolygon = true;
|
||||
mPoints.clear();
|
||||
|
||||
QgsMultiPolygon multipoly = geom->asMultiPolygon();
|
||||
@ -357,7 +365,7 @@ void QgsRubberBand::setToCanvasRectangle( const QRect& rect )
|
||||
QgsPoint ll = transform->toMapCoordinates( rect.left(), rect.bottom() );
|
||||
QgsPoint ur = transform->toMapCoordinates( rect.right(), rect.top() );
|
||||
|
||||
reset( true );
|
||||
reset( QGis::Polygon );
|
||||
addPoint( ll, false );
|
||||
addPoint( QgsPoint( ur.x(), ll.y() ), false );
|
||||
addPoint( ur, false );
|
||||
@ -372,25 +380,47 @@ void QgsRubberBand::paint( QPainter* p )
|
||||
QList<QgsPoint> currentList;
|
||||
if ( mPoints.size() > 0 )
|
||||
{
|
||||
p->setPen( mPen );
|
||||
p->setBrush( mBrush );
|
||||
|
||||
for ( int i = 0; i < mPoints.size(); ++i )
|
||||
{
|
||||
QPolygonF pts;
|
||||
QVector<QPointF> pts;
|
||||
QList<QgsPoint>::const_iterator it = mPoints.at( i ).constBegin();
|
||||
for ( ; it != mPoints.at( i ).constEnd(); ++it )
|
||||
{
|
||||
pts.append( toCanvasCoordinates( QgsPoint( it->x() + mTranslationOffsetX, it->y() + mTranslationOffsetY ) ) - pos() );
|
||||
}
|
||||
|
||||
if ( mIsPolygon )
|
||||
switch ( mGeometryType )
|
||||
{
|
||||
p->drawPolygon( pts );
|
||||
}
|
||||
else
|
||||
{
|
||||
p->drawPolyline( pts );
|
||||
case QGis::Polygon:
|
||||
{
|
||||
mPen.setWidth( mWidth );
|
||||
p->setPen( mPen );
|
||||
p->drawPolygon( pts );
|
||||
}
|
||||
break;
|
||||
|
||||
case QGis::Point:
|
||||
{
|
||||
mPen.setWidth( 1 );
|
||||
p->setPen( mPen );
|
||||
QVector<QPointF>::const_iterator ptIt = pts.constBegin();
|
||||
for( ; ptIt != pts.constEnd(); ++ptIt )
|
||||
{
|
||||
p->drawEllipse( (*ptIt).x() - mWidth/2, (*ptIt).y() - mWidth/2, mWidth, mWidth );
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case QGis::Line:
|
||||
default:
|
||||
{
|
||||
mPen.setWidth( mWidth );
|
||||
p->setPen( mPen );
|
||||
p->drawPolyline( pts );
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -464,34 +494,55 @@ const QgsPoint *QgsRubberBand::getPoint( int i, int j ) const
|
||||
QgsGeometry *QgsRubberBand::asGeometry()
|
||||
{
|
||||
QgsGeometry *geom = NULL;
|
||||
if ( mIsPolygon )
|
||||
|
||||
switch( mGeometryType )
|
||||
{
|
||||
QgsPolygon polygon;
|
||||
QList< QList<QgsPoint> >::const_iterator it = mPoints.constBegin();
|
||||
for ( ; it != mPoints.constEnd(); ++it )
|
||||
case QGis::Polygon:
|
||||
{
|
||||
polygon.append( getPolyline( *it ) );
|
||||
QgsPolygon polygon;
|
||||
QList< QList<QgsPoint> >::const_iterator it = mPoints.constBegin();
|
||||
for ( ; it != mPoints.constEnd(); ++it )
|
||||
{
|
||||
polygon.append( getPolyline( *it ) );
|
||||
}
|
||||
geom = QgsGeometry::fromPolygon( polygon );
|
||||
break;
|
||||
}
|
||||
geom = QgsGeometry::fromPolygon( polygon );
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( mPoints.size() > 0 )
|
||||
|
||||
case QGis::Point:
|
||||
{
|
||||
if ( mPoints.size() > 1 )
|
||||
QgsMultiPoint multiPoint;
|
||||
|
||||
QList< QList<QgsPoint> >::const_iterator it = mPoints.constBegin();
|
||||
for ( ; it != mPoints.constEnd(); ++it )
|
||||
{
|
||||
QgsMultiPolyline multiPolyline;
|
||||
QList< QList<QgsPoint> >::const_iterator it = mPoints.constBegin();
|
||||
for ( ; it != mPoints.constEnd(); ++it )
|
||||
multiPoint += getPolyline( *it );
|
||||
}
|
||||
geom = QgsGeometry::fromMultiPoint( multiPoint );
|
||||
break;
|
||||
}
|
||||
|
||||
case QGis::Line:
|
||||
default:
|
||||
{
|
||||
if ( mPoints.size() > 0 )
|
||||
{
|
||||
if ( mPoints.size() > 1 )
|
||||
{
|
||||
multiPolyline.append( getPolyline( *it ) );
|
||||
QgsMultiPolyline multiPolyline;
|
||||
QList< QList<QgsPoint> >::const_iterator it = mPoints.constBegin();
|
||||
for ( ; it != mPoints.constEnd(); ++it )
|
||||
{
|
||||
multiPolyline.append( getPolyline( *it ) );
|
||||
}
|
||||
geom = QgsGeometry::fromMultiPolyline( multiPolyline );
|
||||
}
|
||||
else
|
||||
{
|
||||
geom = QgsGeometry::fromPolyline( getPolyline( mPoints[0] ) );
|
||||
}
|
||||
geom = QgsGeometry::fromMultiPolyline( multiPolyline );
|
||||
}
|
||||
else
|
||||
{
|
||||
geom = QgsGeometry::fromPolyline( getPolyline( mPoints[0] ) );
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return geom;
|
||||
|
@ -31,13 +31,39 @@ class QPaintEvent;
|
||||
class GUI_EXPORT QgsRubberBand: public QgsMapCanvasItem
|
||||
{
|
||||
public:
|
||||
QgsRubberBand( QgsMapCanvas* mapCanvas, bool isPolygon = false );
|
||||
/**
|
||||
* Creates a new RubberBand.
|
||||
* @param mapCanvas The map canvas to draw onto. It's CRS will be used map points onto screen coordinates.
|
||||
* @param geometryType Defines how the data should be drawn onto the screen. (Use QGis::Line, QGis::Polygon or QGis::Point)
|
||||
* Added in 1.9.
|
||||
*/
|
||||
QgsRubberBand( QgsMapCanvas* mapCanvas, QGis::GeometryType geometryType = QGis::Line );
|
||||
/**
|
||||
* Creates a new RubberBand.
|
||||
* @deprecated
|
||||
* @param mapCanvas The map canvas to draw onto. It's CRS will be used map points onto screen coordinates.
|
||||
* @param isPolygon true: draw as (multi-)polygon, false draw as (multi-)linestring
|
||||
*/
|
||||
QgsRubberBand( QgsMapCanvas* mapCanvas, bool isPolygon );
|
||||
~QgsRubberBand();
|
||||
|
||||
void setColor( const QColor & color );
|
||||
void setWidth( int width );
|
||||
|
||||
void reset( bool isPolygon = false );
|
||||
/**
|
||||
* Clears all the geometries in this rubberband.
|
||||
* Sets the representation type according to geometryType.
|
||||
* @param geometryType Defines how the data should be drawn onto the screen. (Use QGis::Line, QGis::Polygon or QGis::Point)
|
||||
* Added in 1.9.
|
||||
*/
|
||||
void reset( QGis::GeometryType geometryType = QGis::Line );
|
||||
/**
|
||||
* @deprecated
|
||||
* Clears all the geometries in this rubberband.
|
||||
* Sets the representation type according to isPolygon.
|
||||
* @param isPolygon true: draw as (multi-)polygon, false draw as (multi-)linestring
|
||||
*/
|
||||
void reset( bool isPolygon );
|
||||
|
||||
//! Add point to rubberband and update canvas
|
||||
//! If adding more points consider using update=false for better performance
|
||||
@ -101,9 +127,11 @@ class GUI_EXPORT QgsRubberBand: public QgsMapCanvasItem
|
||||
QBrush mBrush;
|
||||
QPen mPen;
|
||||
|
||||
int mWidth;
|
||||
|
||||
/**Nested lists used for multitypes*/
|
||||
QList< QList <QgsPoint> > mPoints;
|
||||
bool mIsPolygon;
|
||||
QGis::GeometryType mGeometryType;
|
||||
double mTranslationOffsetX;
|
||||
double mTranslationOffsetY;
|
||||
|
||||
|
@ -33,7 +33,7 @@ CoordinateCaptureMapTool::CoordinateCaptureMapTool( QgsMapCanvas* thepCanvas )
|
||||
QPixmap myCursor = QPixmap(( const char ** ) capture_point_cursor );
|
||||
mCursor = QCursor( myCursor, 8, 8 ); //8,8 is the point in the cursor where clicks register
|
||||
mpMapCanvas = thepCanvas;
|
||||
mpRubberBand = new QgsRubberBand( mpMapCanvas, true ); //true - its a polygon
|
||||
mpRubberBand = new QgsRubberBand( mpMapCanvas, QGis::Polygon );
|
||||
mpRubberBand->setColor( Qt::red );
|
||||
mpRubberBand->setWidth( 1 );
|
||||
}
|
||||
@ -78,7 +78,7 @@ void CoordinateCaptureMapTool::canvasReleaseEvent( QMouseEvent * thepEvent )
|
||||
QgsPoint myPoint4 =
|
||||
mCanvas->getCoordinateTransform()->toMapCoordinates( thepEvent->x() - 1, thepEvent->y() + 1 );
|
||||
|
||||
mpRubberBand->reset( true );
|
||||
mpRubberBand->reset( QGis::Polygon );
|
||||
// convert screen coordinates to map coordinates
|
||||
mpRubberBand->addPoint( myPoint1, false ); //true - update canvas
|
||||
mpRubberBand->addPoint( myPoint2, false ); //true - update canvas
|
||||
@ -90,6 +90,6 @@ void CoordinateCaptureMapTool::canvasReleaseEvent( QMouseEvent * thepEvent )
|
||||
|
||||
void CoordinateCaptureMapTool::deactivate()
|
||||
{
|
||||
mpRubberBand->reset( false );
|
||||
mpRubberBand->reset( QGis::Line );
|
||||
QgsMapTool::deactivate();
|
||||
}
|
||||
|
@ -152,15 +152,15 @@ RgShortestPathWidget::RgShortestPathWidget( QWidget* theParent, RoadGraphPlugin
|
||||
connect( mCalculate, SIGNAL( clicked( bool ) ), this, SLOT( findingPath() ) );
|
||||
connect( mClear, SIGNAL( clicked( bool ) ), this, SLOT( clear() ) );
|
||||
|
||||
mrbFrontPoint = new QgsRubberBand( mPlugin->iface()->mapCanvas(), true );
|
||||
mrbFrontPoint = new QgsRubberBand( mPlugin->iface()->mapCanvas(), QGis::Polygon );
|
||||
mrbFrontPoint->setColor( Qt::green );
|
||||
mrbFrontPoint->setWidth( 2 );
|
||||
|
||||
mrbBackPoint = new QgsRubberBand( mPlugin->iface()->mapCanvas(), true );
|
||||
mrbBackPoint = new QgsRubberBand( mPlugin->iface()->mapCanvas(), QGis::Polygon );
|
||||
mrbBackPoint->setColor( Qt::red );
|
||||
mrbBackPoint->setWidth( 2 );
|
||||
|
||||
mrbPath = new QgsRubberBand( mPlugin->iface()->mapCanvas(), false );
|
||||
mrbPath = new QgsRubberBand( mPlugin->iface()->mapCanvas(), QGis::Line );
|
||||
mrbPath->setWidth( 2 );
|
||||
|
||||
connect( mPlugin->iface()->mapCanvas(), SIGNAL( extentsChanged() ), this, SLOT( mapCanvasExtentsChanged() ) );
|
||||
@ -199,7 +199,7 @@ void RgShortestPathWidget::setFrontPoint( const QgsPoint& pt )
|
||||
|
||||
double mupp = mPlugin->iface()->mapCanvas()->getCoordinateTransform()->mapUnitsPerPixel() * 2;
|
||||
|
||||
mrbFrontPoint->reset( true );
|
||||
mrbFrontPoint->reset( QGis::Polygon );
|
||||
mrbFrontPoint->addPoint( QgsPoint( pt.x() - mupp, pt.y() - mupp ), false );
|
||||
mrbFrontPoint->addPoint( QgsPoint( pt.x() + mupp, pt.y() - mupp ), false );
|
||||
mrbFrontPoint->addPoint( QgsPoint( pt.x() + mupp, pt.y() + mupp ), false );
|
||||
@ -222,7 +222,7 @@ void RgShortestPathWidget::setBackPoint( const QgsPoint& pt )
|
||||
|
||||
double mupp = mPlugin->iface()->mapCanvas()->getCoordinateTransform()->mapUnitsPerPixel() * 2;
|
||||
|
||||
mrbBackPoint->reset( true );
|
||||
mrbBackPoint->reset( QGis::Polygon );
|
||||
mrbBackPoint->addPoint( QgsPoint( pt.x() - mupp, pt.y() - mupp ), false );
|
||||
mrbBackPoint->addPoint( QgsPoint( pt.x() + mupp, pt.y() - mupp ), false );
|
||||
mrbBackPoint->addPoint( QgsPoint( pt.x() + mupp, pt.y() + mupp ), false );
|
||||
@ -306,7 +306,7 @@ void RgShortestPathWidget::findingPath()
|
||||
if ( path == NULL )
|
||||
return;
|
||||
|
||||
mrbPath->reset( false );
|
||||
mrbPath->reset( QGis::Line );
|
||||
double time = 0.0;
|
||||
double cost = 0.0;
|
||||
|
||||
@ -348,10 +348,10 @@ void RgShortestPathWidget::findingPath()
|
||||
void RgShortestPathWidget::clear()
|
||||
{
|
||||
mFrontPointLineEdit->setText( QString() );
|
||||
mrbFrontPoint->reset( true );
|
||||
mrbFrontPoint->reset( QGis::Polygon );
|
||||
mBackPointLineEdit->setText( QString() );
|
||||
mrbBackPoint->reset( true );
|
||||
mrbPath->reset();
|
||||
mrbBackPoint->reset( QGis::Polygon );
|
||||
mrbPath->reset( QGis::Line );
|
||||
mPathCostLineEdit->setText( QString() );
|
||||
mPathTimeLineEdit->setText( QString() );
|
||||
}
|
||||
|
@ -23,9 +23,9 @@
|
||||
|
||||
QgsRubberSelectId::QgsRubberSelectId( QgsMapCanvas* mapCanvas )
|
||||
{
|
||||
mIsPolygon = false;
|
||||
mGeometryType = QGis::Line;
|
||||
mMapCanvas = mapCanvas;
|
||||
mRubberBand = new QgsRubberBand( mMapCanvas, mIsPolygon );
|
||||
mRubberBand = new QgsRubberBand( mMapCanvas, mGeometryType );
|
||||
mColorRGB[0] = 255;
|
||||
mColorRGB[1] = 0;
|
||||
mColorRGB[2] = 0;
|
||||
@ -42,7 +42,7 @@ QgsRubberSelectId::~QgsRubberSelectId()
|
||||
|
||||
void QgsRubberSelectId::reset()
|
||||
{
|
||||
mRubberBand->reset( mIsPolygon );
|
||||
mRubberBand->reset( mGeometryType );
|
||||
} // void QgsRubberSelectId::reset()
|
||||
|
||||
void QgsRubberSelectId::setStyle( int colorRed, int colorGreen, int colorBlue, int width )
|
||||
@ -56,13 +56,11 @@ void QgsRubberSelectId::setStyle( int colorRed, int colorGreen, int colorBlue, i
|
||||
|
||||
void QgsRubberSelectId::addFeature( QgsVectorLayer* lyr, QgsFeatureId fid )
|
||||
{
|
||||
bool isPolygon = ( lyr->geometryType() == QGis::Polygon );
|
||||
if ( mIsPolygon != isPolygon )
|
||||
if ( mGeometryType != lyr->geometryType() )
|
||||
{
|
||||
reset();
|
||||
delete mRubberBand;
|
||||
mIsPolygon = isPolygon;
|
||||
mRubberBand = new QgsRubberBand( mMapCanvas, mIsPolygon );
|
||||
mGeometryType = lyr->geometryType();
|
||||
mRubberBand->reset( lyr->geometryType() );
|
||||
setStyle();
|
||||
}
|
||||
QgsFeature feat;
|
||||
|
@ -72,7 +72,7 @@ class QgsRubberSelectId
|
||||
QgsRubberBand* mRubberBand;
|
||||
int mColorRGB[3];
|
||||
int mWidth;
|
||||
bool mIsPolygon;
|
||||
QGis::GeometryType mGeometryType;
|
||||
QgsMapCanvas* mMapCanvas;
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user