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
This commit is contained in:
mhugent 2011-04-28 08:31:01 +00:00
parent d8421bbb57
commit 353109206f
5 changed files with 54 additions and 9 deletions

View File

@ -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);

View File

@ -18,9 +18,9 @@
#include "qgsmapcanvas.h"
#include "qgsmaptopixel.h"
#include "qgscursors.h"
#include "qgsrubberband.h"
#include <QMouseEvent>
#include <QRubberBand>
#include <QRect>
#include <QCursor>
#include <QPixmap>
@ -28,13 +28,18 @@
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;
}

View File

@ -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

View File

@ -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.
*/

View File

@ -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