Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix #958
git-svn-id: http://svn.osgeo.org/qgis/trunk@8656 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Jun 18, 2008
1 parent 409dcee commit aff0f86
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/app/qgisapp.cpp
Expand Up @@ -4750,8 +4750,6 @@ void QgisApp::showMapTip()
// only process vector layers
if ( mypLayer->type() == QgsMapLayer::VECTOR )
{


// Show the maptip if the maptips button is depressed
if(mMapTipsVisible)
{
Expand Down Expand Up @@ -4849,6 +4847,8 @@ void QgisApp::activateDeactivateLayerRelatedActions(QgsMapLayer* layer)
return;
}

mMapCanvas->restoreMapTool();

mActionToggleEditing->setEnabled(true);
mActionRemoveLayer->setEnabled(true);
mActionInOverview->setEnabled(true);
Expand Down
2 changes: 2 additions & 0 deletions src/app/qgsmaptooledit.h
Expand Up @@ -29,6 +29,8 @@ class QgsMapToolEdit: public QgsMapTool
public:
QgsMapToolEdit(QgsMapCanvas* canvas);
virtual ~QgsMapToolEdit();

virtual bool isEditTool() { return true; }

protected:
/**Snapper object that reads the settings from project and option
Expand Down
21 changes: 20 additions & 1 deletion src/gui/qgsmapcanvas.cpp
Expand Up @@ -87,6 +87,7 @@ class QgsMapCanvas::CanvasProperties
mMapOverview = NULL;
mMapTool = NULL;
mLastNonZoomMapTool = NULL;
mNonEditMapTool = NULL;

mDrawing = false;
mFrozen = false;
Expand Down Expand Up @@ -959,14 +960,32 @@ void QgsMapCanvas::setMapTool(QgsMapTool* tool)
{
mLastNonZoomMapTool = NULL;
}

// set new map tool and activate it
mMapTool = tool;
if (mMapTool)
mMapTool->activate();

} // setMapTool

void QgsMapCanvas::restoreMapTool()
{
if( !mMapTool )
return;

if( !mMapTool->isEditTool() )
{
mNonEditMapTool = mMapTool;
return;
}

if ( mCurrentLayer && !mCurrentLayer->isEditable() )
{
setMapTool(mNonEditMapTool);
}
}


void QgsMapCanvas::unsetMapTool(QgsMapTool* tool)
{
if (mMapTool && mMapTool == tool)
Expand Down
7 changes: 6 additions & 1 deletion src/gui/qgsmapcanvas.h
Expand Up @@ -234,6 +234,8 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
//! zooms with the factor supplied. Factor > 1 zooms in
void zoom(double scaleFactor);

//! restore tool on toggle editing
void restoreMapTool();

public slots:

Expand Down Expand Up @@ -299,7 +301,7 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView

//! Emit key release event
void keyReleased(QKeyEvent * e);

protected:
//! Overridden key press event
void keyPressEvent(QKeyEvent * e);
Expand Down Expand Up @@ -398,6 +400,9 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
//! previous tool if current is for zooming/panning
QgsMapTool* mLastNonZoomMapTool;

//! tool to restore when editing is toggled.
QgsMapTool* mNonEditMapTool;

//! recently used extent
QgsRect mLastExtent;

Expand Down
5 changes: 5 additions & 0 deletions src/gui/qgsmaptool.cpp
Expand Up @@ -141,6 +141,11 @@ bool QgsMapTool::isZoomTool()
return false;
}

bool QgsMapTool::isEditTool()
{
return false;
}

QgsMapCanvas* QgsMapTool::canvas()
{
return mCanvas;
Expand Down
8 changes: 7 additions & 1 deletion src/gui/qgsmaptool.h
Expand Up @@ -78,7 +78,13 @@ class GUI_EXPORT QgsMapTool : public QObject
* If it does, we will be able to perform the zoom and then
* resume operations with the original / previously used tool.*/
virtual bool isZoomTool();


/** Check whether this MapTool performs an edit operation.
* If it does, we will deactivate it when editing is turned off and
* reactivate it when editing is turned back on.
*/
virtual bool isEditTool();

//! called when set as currently active map tool
virtual void activate();

Expand Down

0 comments on commit aff0f86

Please sign in to comment.