From 6aea5c8564800f022321270497a131226b216507 Mon Sep 17 00:00:00 2001 From: timlinux Date: Sat, 26 Jun 2004 23:14:35 +0000 Subject: [PATCH] Added functionality to lock a map canvas to prevent user interaction so that the overview canvas cant be misused, e.g.: mOverviewCanvas->userInteractionAllowed(false); This fixes bug: 977032 Fix "overview does not zoom to all when layer removed" bug [ 977034 ] Fixed overview paints multiple times bug 977015 git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@1686 c8812cc2-4d05-0410-92ff-de0c093fc19c --- src/qgisapp.cpp | 3 +++ src/qgsmapcanvas.cpp | 16 ++++++++++++++++ src/qgsmapcanvas.h | 8 ++++++++ 3 files changed, 27 insertions(+) diff --git a/src/qgisapp.cpp b/src/qgisapp.cpp index efbfafa6f47..3c86a6a60d2 100644 --- a/src/qgisapp.cpp +++ b/src/qgisapp.cpp @@ -300,6 +300,8 @@ QgisApp::QgisApp(QWidget * parent, const char *name, WFlags fl):QgisAppBase(pare mMapLegend->setSorting(-1); mOverviewCanvas = new QgsMapCanvas(legendOverviewSplit); + // lock the canvas to prevent user interaction + mOverviewCanvas->userInteractionAllowed(false); // mL = new QScrollView(canvasLegendSplit); //add a canvas mMapCanvas = new QgsMapCanvas(canvasLegendSplit); @@ -1742,6 +1744,7 @@ void QgisApp::removeLayer() mMapLayerRegistry->removeMapLayer(layer->getLayerID()); mOverviewCanvas->freeze(false); // draw the map + mOverviewCanvas->zoomFullExtent(); mOverviewCanvas->clear(); mOverviewCanvas->render(); mMapCanvas->freeze(false); diff --git a/src/qgsmapcanvas.cpp b/src/qgsmapcanvas.cpp index fdcad7e3364..8a30731bdb1 100644 --- a/src/qgsmapcanvas.cpp +++ b/src/qgsmapcanvas.cpp @@ -207,6 +207,8 @@ QgsMapCanvas::QgsMapCanvas(QWidget * parent, const char *name) : QWidget(parent, name), mCanvasProperties( new CanvasProperties(width(), height()) ) { setEraseColor(mCanvasProperties->bgColor); + //by default we allow a user to interact with the canvas + mUserInteractionAllowed=true; setMouseTracking(true); setFocusPolicy(QWidget::StrongFocus); QPaintDeviceMetrics *pdm = new QPaintDeviceMetrics(this); @@ -733,6 +735,7 @@ void QgsMapCanvas::zoomToSelected() void QgsMapCanvas::mousePressEvent(QMouseEvent * e) { + if (!mUserInteractionAllowed) return; mCanvasProperties->mouseButtonDown = true; mCanvasProperties->boxStartPoint = e->pos(); @@ -752,6 +755,7 @@ void QgsMapCanvas::mousePressEvent(QMouseEvent * e) void QgsMapCanvas::mouseReleaseEvent(QMouseEvent * e) { + if (!mUserInteractionAllowed) return; QPainter paint; QPen pen(Qt::gray); QgsPoint ll, ur; @@ -974,6 +978,7 @@ void QgsMapCanvas::resizeEvent(QResizeEvent * e) void QgsMapCanvas::mouseMoveEvent(QMouseEvent * e) { + if (!mUserInteractionAllowed) return; // XXX magic numbers BAD -- 513? if (e->state() == Qt::LeftButton || e->state() == 513) { @@ -1266,6 +1271,17 @@ std::list < QString > & QgsMapCanvas::zOrders() return mCanvasProperties->zOrder; } // zOrders +//! determines whether the user can interact with the overview canvas. +void QgsMapCanvas::userInteractionAllowed(bool theFlag) +{ + mUserInteractionAllowed = theFlag; +} +//! determines whether the user can interact with the overview canvas. +bool QgsMapCanvas::isUserInteractionAllowed() +{ + return mUserInteractionAllowed; +} + double QgsMapCanvas::mupp() const { diff --git a/src/qgsmapcanvas.h b/src/qgsmapcanvas.h index 90bcd4a6e25..5f4089bd508 100644 --- a/src/qgsmapcanvas.h +++ b/src/qgsmapcanvas.h @@ -185,6 +185,11 @@ public slots: //! sets z order based on order of layers in the legend void setZOrderFromLegend(QgsLegend *lv); + //! determines whether the user can interact with the overview canvas. + void userInteractionAllowed(bool); + //! accessor to flag indicating whether the user can interact with the canvase + bool isUserInteractionAllowed(); + signals: /** Let the owner know how far we are with render operations */ void setProgress(int,int); @@ -261,6 +266,9 @@ private: //! true if canvas currently drawing bool isDrawing(); + //! detrmines whether the user can interact with the canvas using a mouse + //(useful for locking the overview canvas) + bool mUserInteractionAllowed; }; // class QgsMapCanvas #endif