[QGIS Commit] r15838 - in trunk/qgis: python/gui src/gui
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Thu Apr 28 04:31:01 EDT 2011
Author: mhugent
Date: 2011-04-28 01:31:01 -0700 (Thu, 28 Apr 2011)
New Revision: 15838
Modified:
trunk/qgis/python/gui/qgsrubberband.sip
trunk/qgis/src/gui/qgsmaptoolzoom.cpp
trunk/qgis/src/gui/qgsmaptoolzoom.h
trunk/qgis/src/gui/qgsrubberband.cpp
trunk/qgis/src/gui/qgsrubberband.h
Log:
Port zoom rectangle from QRubberBand to QgsRubberBand. Fixes zoom rectangle fill on x11 platform after resize bug workaround
Modified: trunk/qgis/python/gui/qgsrubberband.sip
===================================================================
--- trunk/qgis/python/gui/qgsrubberband.sip 2011-04-28 07:19:09 UTC (rev 15837)
+++ trunk/qgis/python/gui/qgsrubberband.sip 2011-04-28 08:31:01 UTC (rev 15838)
@@ -44,6 +44,11 @@
*/
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);
Modified: trunk/qgis/src/gui/qgsmaptoolzoom.cpp
===================================================================
--- trunk/qgis/src/gui/qgsmaptoolzoom.cpp 2011-04-28 07:19:09 UTC (rev 15837)
+++ trunk/qgis/src/gui/qgsmaptoolzoom.cpp 2011-04-28 08:31:01 UTC (rev 15838)
@@ -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,14 +28,19 @@
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 )
{
if ( !( e->buttons() & Qt::LeftButton ) )
@@ -44,12 +49,16 @@
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 @@
mCanvas->zoomWithCenter( e->x(), e->y(), !mZoomOut );
}
}
+
+void QgsMapToolZoom::deactivate()
+{
+ delete mRubberBand;
+ mRubberBand = 0;
+}
Modified: trunk/qgis/src/gui/qgsmaptoolzoom.h
===================================================================
--- trunk/qgis/src/gui/qgsmaptoolzoom.h 2011-04-28 07:19:09 UTC (rev 15837)
+++ trunk/qgis/src/gui/qgsmaptoolzoom.h 2011-04-28 08:31:01 UTC (rev 15838)
@@ -20,9 +20,8 @@
#include "qgsmaptool.h"
#include <QRect>
+class QgsRubberBand;
-class QRubberBand;
-
/** \ingroup gui
* A map tool for zooming into the map.
* @see QgsMapTool
@@ -33,6 +32,8 @@
//! constructor
QgsMapToolZoom( QgsMapCanvas* canvas, bool zoomOut );
+ ~QgsMapToolZoom();
+
//! Overridden mouse move event
virtual void canvasMoveEvent( QMouseEvent * e );
@@ -44,6 +45,8 @@
virtual bool isTransient() { return true; }
+ virtual void deactivate();
+
protected:
//! stores actual zoom rect
QRect mZoomRect;
@@ -54,8 +57,7 @@
//! 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
Modified: trunk/qgis/src/gui/qgsrubberband.cpp
===================================================================
--- trunk/qgis/src/gui/qgsrubberband.cpp 2011-04-28 07:19:09 UTC (rev 15837)
+++ trunk/qgis/src/gui/qgsrubberband.cpp 2011-04-28 08:31:01 UTC (rev 15838)
@@ -341,6 +341,24 @@
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.
*/
Modified: trunk/qgis/src/gui/qgsrubberband.h
===================================================================
--- trunk/qgis/src/gui/qgsrubberband.h 2011-04-28 07:19:09 UTC (rev 15837)
+++ trunk/qgis/src/gui/qgsrubberband.h 2011-04-28 08:31:01 UTC (rev 15838)
@@ -61,6 +61,11 @@
*/
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
More information about the QGIS-commit
mailing list