Skip to content

Commit 3531092

Browse files
author
mhugent
committed
Port zoom rectangle from QRubberBand to QgsRubberBand. Fixes zoom rectangle fill on x11 platform after resize bug workaround
git-svn-id: http://svn.osgeo.org/qgis/trunk@15838 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent d8421bb commit 3531092

File tree

5 files changed

+54
-9
lines changed

5 files changed

+54
-9
lines changed

python/gui/qgsrubberband.sip

+5
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ class QgsRubberBand: QgsMapCanvasItem
4444
*/
4545
void addGeometry(QgsGeometry* geom, QgsVectorLayer* layer);
4646

47+
/**Sets this rubber band to a map canvas rectangle
48+
@param rect rectangle in canvas coordinates
49+
@note added in version 1.7*/
50+
void setToCanvasRectangle( const QRect& rect );
51+
4752
/**Adds translation to original coordinates (all in map coordinates)*/
4853
void setTranslationOffset(double dx, double dy);
4954

src/gui/qgsmaptoolzoom.cpp

+20-5
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,28 @@
1818
#include "qgsmapcanvas.h"
1919
#include "qgsmaptopixel.h"
2020
#include "qgscursors.h"
21+
#include "qgsrubberband.h"
2122

2223
#include <QMouseEvent>
23-
#include <QRubberBand>
2424
#include <QRect>
2525
#include <QCursor>
2626
#include <QPixmap>
2727
#include "qgslogger.h"
2828

2929

3030
QgsMapToolZoom::QgsMapToolZoom( QgsMapCanvas* canvas, bool zoomOut )
31-
: QgsMapTool( canvas ), mZoomOut( zoomOut ), mDragging( false )
31+
: QgsMapTool( canvas ), mZoomOut( zoomOut ), mDragging( false ), mRubberBand( 0 )
3232
{
3333
// set the cursor
3434
QPixmap myZoomQPixmap = QPixmap(( const char ** )( zoomOut ? zoom_out : zoom_in ) );
3535
mCursor = QCursor( myZoomQPixmap, 7, 7 );
3636
}
3737

38+
QgsMapToolZoom::~QgsMapToolZoom()
39+
{
40+
delete mRubberBand;
41+
}
42+
3843

3944
void QgsMapToolZoom::canvasMoveEvent( QMouseEvent * e )
4045
{
@@ -44,12 +49,16 @@ void QgsMapToolZoom::canvasMoveEvent( QMouseEvent * e )
4449
if ( !mDragging )
4550
{
4651
mDragging = true;
47-
mRubberBand = new QRubberBand( QRubberBand::Rectangle, mCanvas );
52+
delete mRubberBand;
53+
mRubberBand = new QgsRubberBand( mCanvas, true );
4854
mZoomRect.setTopLeft( e->pos() );
4955
}
5056
mZoomRect.setBottomRight( e->pos() );
51-
mRubberBand->setGeometry( mZoomRect.normalized() );
52-
mRubberBand->show();
57+
if ( mRubberBand )
58+
{
59+
mRubberBand->setToCanvasRectangle( mZoomRect );
60+
mRubberBand->show();
61+
}
5362
}
5463

5564

@@ -126,3 +135,9 @@ void QgsMapToolZoom::canvasReleaseEvent( QMouseEvent * e )
126135
mCanvas->zoomWithCenter( e->x(), e->y(), !mZoomOut );
127136
}
128137
}
138+
139+
void QgsMapToolZoom::deactivate()
140+
{
141+
delete mRubberBand;
142+
mRubberBand = 0;
143+
}

src/gui/qgsmaptoolzoom.h

+6-4
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020
#include "qgsmaptool.h"
2121
#include <QRect>
2222

23-
24-
class QRubberBand;
23+
class QgsRubberBand;
2524

2625
/** \ingroup gui
2726
* A map tool for zooming into the map.
@@ -33,6 +32,8 @@ class GUI_EXPORT QgsMapToolZoom : public QgsMapTool
3332
//! constructor
3433
QgsMapToolZoom( QgsMapCanvas* canvas, bool zoomOut );
3534

35+
~QgsMapToolZoom();
36+
3637
//! Overridden mouse move event
3738
virtual void canvasMoveEvent( QMouseEvent * e );
3839

@@ -44,6 +45,8 @@ class GUI_EXPORT QgsMapToolZoom : public QgsMapTool
4445

4546
virtual bool isTransient() { return true; }
4647

48+
virtual void deactivate();
49+
4750
protected:
4851
//! stores actual zoom rect
4952
QRect mZoomRect;
@@ -54,8 +57,7 @@ class GUI_EXPORT QgsMapToolZoom : public QgsMapTool
5457
//! Flag to indicate a map canvas drag operation is taking place
5558
bool mDragging;
5659

57-
//! TODO: to be changed to a canvas item
58-
QRubberBand* mRubberBand;
60+
QgsRubberBand* mRubberBand;
5961
};
6062

6163
#endif

src/gui/qgsrubberband.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,24 @@ void QgsRubberBand::addGeometry( QgsGeometry* geom, QgsVectorLayer* layer )
341341
update();
342342
}
343343

344+
void QgsRubberBand::setToCanvasRectangle( const QRect& rect )
345+
{
346+
if ( !mMapCanvas )
347+
{
348+
return;
349+
}
350+
351+
const QgsMapToPixel* transform = mMapCanvas->getCoordinateTransform();
352+
QgsPoint ll = transform->toMapCoordinates( rect.left(), rect.bottom() );
353+
QgsPoint ur = transform->toMapCoordinates( rect.right(), rect.top() );
354+
355+
reset( true );
356+
addPoint( ll, false );
357+
addPoint( QgsPoint( ur.x(), ll.y() ), false );
358+
addPoint( ur, false );
359+
addPoint( QgsPoint( ll.x(), ur.y() ), true );
360+
}
361+
344362
/*!
345363
Draw the shape in response to an update event.
346364
*/

src/gui/qgsrubberband.h

+5
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ class GUI_EXPORT QgsRubberBand: public QgsMapCanvasItem
6161
*/
6262
void setToGeometry( QgsGeometry* geom, QgsVectorLayer* layer );
6363

64+
/**Sets this rubber band to a map canvas rectangle
65+
@param rect rectangle in canvas coordinates
66+
@note added in version 1.7*/
67+
void setToCanvasRectangle( const QRect& rect );
68+
6469
/**Add the geometry of an existing feature to a rubberband
6570
This is useful for multi feature highlighting.
6671
@param geom the geometry object

0 commit comments

Comments
 (0)