Skip to content


Browse files Browse the repository at this point in the history
Added setButton() and button() functions to QgsMapTool so that also b…

associated with a map tool can be set as checked when the tool is active.

git-svn-id: c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder committed Jun 17, 2007
1 parent 37d5a4b commit 4b801ce
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
22 changes: 19 additions & 3 deletions src/gui/qgsmaptool.cpp
@@ -1,5 +1,5 @@
qgsmaptool.h - base class for map canvas tools
qgsmaptool.cpp - base class for map canvas tools
begin : January 2006
copyright : (C) 2006 by Martin Dobias
Expand All @@ -20,9 +20,10 @@
#include "qgsmaprender.h"
#include "qgsmaptopixel.h"
#include <QAction>
#include <QAbstractButton>

QgsMapTool::QgsMapTool(QgsMapCanvas* canvas)
: QObject(canvas), mCanvas(canvas), mCursor(Qt::CrossCursor), mAction(NULL)
: QObject(canvas), mCanvas(canvas), mCursor(Qt::CrossCursor), mAction(NULL), mButton(NULL)

Expand Down Expand Up @@ -70,9 +71,11 @@ QPoint QgsMapTool::toCanvasCoords(const QgsPoint& point)

void QgsMapTool::activate()
// make action active
// make action and/or button active
if (mAction)
if (mButton)

// set cursor (map tools usually set it in constructor)
Expand All @@ -84,6 +87,8 @@ void QgsMapTool::deactivate()
if (mAction)
if (mButton)

void QgsMapTool::setAction(QAction* action)
Expand All @@ -96,6 +101,17 @@ QAction* QgsMapTool::action()
return mAction;

void QgsMapTool::setButton(QAbstractButton* button)
mButton = button;

QAbstractButton* QgsMapTool::button()
return mButton;

void QgsMapTool::canvasMoveEvent(QMouseEvent *)
Expand Down
19 changes: 16 additions & 3 deletions src/gui/qgsmaptool.h
Expand Up @@ -28,7 +28,7 @@ class QgsPoint;
class QgsRect;
class QPoint;
class QAction;

class QAbstractButton;

class GUI_EXPORT QgsMapTool : public QObject
Expand All @@ -49,15 +49,24 @@ class GUI_EXPORT QgsMapTool : public QObject
//! Called when rendering has finished. Default implementation does nothing.
virtual void renderComplete();

/** Use this to associate a button, toolbutton, menu entry etc
* that inherits qaction to this maptool. Then when the setMapTool

/** Use this to associate a QAction to this maptool. Then when the setMapTool
* method of mapcanvas is called the action state will be set to on.
* Usually this will cause e.g. a toolbutton to appear pressed in and
* the previously used toolbutton to pop out. */
void setAction(QAction* action);

/** Return associated action with map tool or NULL if no action is associated */
QAction* action();

/** Use this to associate a button to this maptool. It has the same meaning
* as setAction() function except it works with a button instead of an QAction. */
void setButton(QAbstractButton* button);

/** Return associated button with map tool or NULL if no button is associated */
QAbstractButton* button();

/** Check whether this MapTool performs a zoom or pan operation.
* If it does, we will be able to perform the zoom and then
* resume operations with the original / previously used tool.*/
Expand Down Expand Up @@ -105,6 +114,10 @@ class GUI_EXPORT QgsMapTool : public QObject
//! which will be used to set that action as active
QAction* mAction;

//! optionally map tool can have pointer to a button
//! which will be used to set that action as active
QAbstractButton* mButton;



0 comments on commit 4b801ce

Please sign in to comment.