mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-19 00:04:52 -04:00
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:
parent
d8421bbb57
commit
353109206f
@ -44,6 +44,11 @@ class QgsRubberBand: QgsMapCanvasItem
|
|||||||
*/
|
*/
|
||||||
void addGeometry(QgsGeometry* geom, QgsVectorLayer* layer);
|
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)*/
|
/**Adds translation to original coordinates (all in map coordinates)*/
|
||||||
void setTranslationOffset(double dx, double dy);
|
void setTranslationOffset(double dx, double dy);
|
||||||
|
|
||||||
|
@ -18,9 +18,9 @@
|
|||||||
#include "qgsmapcanvas.h"
|
#include "qgsmapcanvas.h"
|
||||||
#include "qgsmaptopixel.h"
|
#include "qgsmaptopixel.h"
|
||||||
#include "qgscursors.h"
|
#include "qgscursors.h"
|
||||||
|
#include "qgsrubberband.h"
|
||||||
|
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
#include <QRubberBand>
|
|
||||||
#include <QRect>
|
#include <QRect>
|
||||||
#include <QCursor>
|
#include <QCursor>
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
@ -28,13 +28,18 @@
|
|||||||
|
|
||||||
|
|
||||||
QgsMapToolZoom::QgsMapToolZoom( QgsMapCanvas* canvas, bool zoomOut )
|
QgsMapToolZoom::QgsMapToolZoom( QgsMapCanvas* canvas, bool zoomOut )
|
||||||
: QgsMapTool( canvas ), mZoomOut( zoomOut ), mDragging( false )
|
: QgsMapTool( canvas ), mZoomOut( zoomOut ), mDragging( false ), mRubberBand( 0 )
|
||||||
{
|
{
|
||||||
// set the cursor
|
// set the cursor
|
||||||
QPixmap myZoomQPixmap = QPixmap(( const char ** )( zoomOut ? zoom_out : zoom_in ) );
|
QPixmap myZoomQPixmap = QPixmap(( const char ** )( zoomOut ? zoom_out : zoom_in ) );
|
||||||
mCursor = QCursor( myZoomQPixmap, 7, 7 );
|
mCursor = QCursor( myZoomQPixmap, 7, 7 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QgsMapToolZoom::~QgsMapToolZoom()
|
||||||
|
{
|
||||||
|
delete mRubberBand;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void QgsMapToolZoom::canvasMoveEvent( QMouseEvent * e )
|
void QgsMapToolZoom::canvasMoveEvent( QMouseEvent * e )
|
||||||
{
|
{
|
||||||
@ -44,12 +49,16 @@ void QgsMapToolZoom::canvasMoveEvent( QMouseEvent * e )
|
|||||||
if ( !mDragging )
|
if ( !mDragging )
|
||||||
{
|
{
|
||||||
mDragging = true;
|
mDragging = true;
|
||||||
mRubberBand = new QRubberBand( QRubberBand::Rectangle, mCanvas );
|
delete mRubberBand;
|
||||||
|
mRubberBand = new QgsRubberBand( mCanvas, true );
|
||||||
mZoomRect.setTopLeft( e->pos() );
|
mZoomRect.setTopLeft( e->pos() );
|
||||||
}
|
}
|
||||||
mZoomRect.setBottomRight( e->pos() );
|
mZoomRect.setBottomRight( e->pos() );
|
||||||
mRubberBand->setGeometry( mZoomRect.normalized() );
|
if ( mRubberBand )
|
||||||
mRubberBand->show();
|
{
|
||||||
|
mRubberBand->setToCanvasRectangle( mZoomRect );
|
||||||
|
mRubberBand->show();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -126,3 +135,9 @@ void QgsMapToolZoom::canvasReleaseEvent( QMouseEvent * e )
|
|||||||
mCanvas->zoomWithCenter( e->x(), e->y(), !mZoomOut );
|
mCanvas->zoomWithCenter( e->x(), e->y(), !mZoomOut );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QgsMapToolZoom::deactivate()
|
||||||
|
{
|
||||||
|
delete mRubberBand;
|
||||||
|
mRubberBand = 0;
|
||||||
|
}
|
||||||
|
@ -20,8 +20,7 @@
|
|||||||
#include "qgsmaptool.h"
|
#include "qgsmaptool.h"
|
||||||
#include <QRect>
|
#include <QRect>
|
||||||
|
|
||||||
|
class QgsRubberBand;
|
||||||
class QRubberBand;
|
|
||||||
|
|
||||||
/** \ingroup gui
|
/** \ingroup gui
|
||||||
* A map tool for zooming into the map.
|
* A map tool for zooming into the map.
|
||||||
@ -33,6 +32,8 @@ class GUI_EXPORT QgsMapToolZoom : public QgsMapTool
|
|||||||
//! constructor
|
//! constructor
|
||||||
QgsMapToolZoom( QgsMapCanvas* canvas, bool zoomOut );
|
QgsMapToolZoom( QgsMapCanvas* canvas, bool zoomOut );
|
||||||
|
|
||||||
|
~QgsMapToolZoom();
|
||||||
|
|
||||||
//! Overridden mouse move event
|
//! Overridden mouse move event
|
||||||
virtual void canvasMoveEvent( QMouseEvent * e );
|
virtual void canvasMoveEvent( QMouseEvent * e );
|
||||||
|
|
||||||
@ -44,6 +45,8 @@ class GUI_EXPORT QgsMapToolZoom : public QgsMapTool
|
|||||||
|
|
||||||
virtual bool isTransient() { return true; }
|
virtual bool isTransient() { return true; }
|
||||||
|
|
||||||
|
virtual void deactivate();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
//! stores actual zoom rect
|
//! stores actual zoom rect
|
||||||
QRect mZoomRect;
|
QRect mZoomRect;
|
||||||
@ -54,8 +57,7 @@ class GUI_EXPORT QgsMapToolZoom : public QgsMapTool
|
|||||||
//! Flag to indicate a map canvas drag operation is taking place
|
//! Flag to indicate a map canvas drag operation is taking place
|
||||||
bool mDragging;
|
bool mDragging;
|
||||||
|
|
||||||
//! TODO: to be changed to a canvas item
|
QgsRubberBand* mRubberBand;
|
||||||
QRubberBand* mRubberBand;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -341,6 +341,24 @@ void QgsRubberBand::addGeometry( QgsGeometry* geom, QgsVectorLayer* layer )
|
|||||||
update();
|
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.
|
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 );
|
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
|
/**Add the geometry of an existing feature to a rubberband
|
||||||
This is useful for multi feature highlighting.
|
This is useful for multi feature highlighting.
|
||||||
@param geom the geometry object
|
@param geom the geometry object
|
||||||
|
Loading…
x
Reference in New Issue
Block a user