Skip to content
Permalink
Browse files
Port zoom rectangle from QRubberBand to QgsRubberBand. Fixes zoom rec…
…tangle fill on x11 platform after resize bug workaround

git-svn-id: http://svn.osgeo.org/qgis/trunk@15838 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Apr 28, 2011
1 parent d8421bb commit 353109206f6c283c8fe80b84a58cdd674a7a1ba5
Showing with 54 additions and 9 deletions.
  1. +5 −0 python/gui/qgsrubberband.sip
  2. +20 −5 src/gui/qgsmaptoolzoom.cpp
  3. +6 −4 src/gui/qgsmaptoolzoom.h
  4. +18 −0 src/gui/qgsrubberband.cpp
  5. +5 −0 src/gui/qgsrubberband.h
@@ -44,6 +44,11 @@ class QgsRubberBand: QgsMapCanvasItem
*/
void addGeometry(QgsGeometry* geom, QgsVectorLayer* layer);

/**Sets this rubber band to a map canvas rectangle
@param rect rectangle in canvas coordinates
@note added in version 1.7*/
void setToCanvasRectangle( const QRect& rect );

/**Adds translation to original coordinates (all in map coordinates)*/
void setTranslationOffset(double dx, double dy);

@@ -18,23 +18,28 @@
#include "qgsmapcanvas.h"
#include "qgsmaptopixel.h"
#include "qgscursors.h"
#include "qgsrubberband.h"

#include <QMouseEvent>
#include <QRubberBand>
#include <QRect>
#include <QCursor>
#include <QPixmap>
#include "qgslogger.h"


QgsMapToolZoom::QgsMapToolZoom( QgsMapCanvas* canvas, bool zoomOut )
: QgsMapTool( canvas ), mZoomOut( zoomOut ), mDragging( false )
: QgsMapTool( canvas ), mZoomOut( zoomOut ), mDragging( false ), mRubberBand( 0 )
{
// set the cursor
QPixmap myZoomQPixmap = QPixmap(( const char ** )( zoomOut ? zoom_out : zoom_in ) );
mCursor = QCursor( myZoomQPixmap, 7, 7 );
}

QgsMapToolZoom::~QgsMapToolZoom()
{
delete mRubberBand;
}


void QgsMapToolZoom::canvasMoveEvent( QMouseEvent * e )
{
@@ -44,12 +49,16 @@ void QgsMapToolZoom::canvasMoveEvent( QMouseEvent * e )
if ( !mDragging )
{
mDragging = true;
mRubberBand = new QRubberBand( QRubberBand::Rectangle, mCanvas );
delete mRubberBand;
mRubberBand = new QgsRubberBand( mCanvas, true );
mZoomRect.setTopLeft( e->pos() );
}
mZoomRect.setBottomRight( e->pos() );
mRubberBand->setGeometry( mZoomRect.normalized() );
mRubberBand->show();
if ( mRubberBand )
{
mRubberBand->setToCanvasRectangle( mZoomRect );
mRubberBand->show();
}
}


@@ -126,3 +135,9 @@ void QgsMapToolZoom::canvasReleaseEvent( QMouseEvent * e )
mCanvas->zoomWithCenter( e->x(), e->y(), !mZoomOut );
}
}

void QgsMapToolZoom::deactivate()
{
delete mRubberBand;
mRubberBand = 0;
}
@@ -20,8 +20,7 @@
#include "qgsmaptool.h"
#include <QRect>


class QRubberBand;
class QgsRubberBand;

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

~QgsMapToolZoom();

//! Overridden mouse move event
virtual void canvasMoveEvent( QMouseEvent * e );

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

virtual bool isTransient() { return true; }

virtual void deactivate();

protected:
//! stores actual zoom rect
QRect mZoomRect;
@@ -54,8 +57,7 @@ class GUI_EXPORT QgsMapToolZoom : public QgsMapTool
//! Flag to indicate a map canvas drag operation is taking place
bool mDragging;

//! TODO: to be changed to a canvas item
QRubberBand* mRubberBand;
QgsRubberBand* mRubberBand;
};

#endif
@@ -341,6 +341,24 @@ void QgsRubberBand::addGeometry( QgsGeometry* geom, QgsVectorLayer* layer )
update();
}

void QgsRubberBand::setToCanvasRectangle( const QRect& rect )
{
if ( !mMapCanvas )
{
return;
}

const QgsMapToPixel* transform = mMapCanvas->getCoordinateTransform();
QgsPoint ll = transform->toMapCoordinates( rect.left(), rect.bottom() );
QgsPoint ur = transform->toMapCoordinates( rect.right(), rect.top() );

reset( true );
addPoint( ll, false );
addPoint( QgsPoint( ur.x(), ll.y() ), false );
addPoint( ur, false );
addPoint( QgsPoint( ll.x(), ur.y() ), true );
}

/*!
Draw the shape in response to an update event.
*/
@@ -61,6 +61,11 @@ class GUI_EXPORT QgsRubberBand: public QgsMapCanvasItem
*/
void setToGeometry( QgsGeometry* geom, QgsVectorLayer* layer );

/**Sets this rubber band to a map canvas rectangle
@param rect rectangle in canvas coordinates
@note added in version 1.7*/
void setToCanvasRectangle( const QRect& rect );

/**Add the geometry of an existing feature to a rubberband
This is useful for multi feature highlighting.
@param geom the geometry object

0 comments on commit 3531092

Please sign in to comment.