Skip to content
Permalink
Browse files
Added setButton() and button() functions to QgsMapTool so that also b…
…utton

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


git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@7035 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder committed Jun 17, 2007
1 parent 37d5a4b commit 4b801ceb9667c23034f6d8b70b68f53dc86f66da
Showing with 35 additions and 6 deletions.
  1. +19 −3 src/gui/qgsmaptool.cpp
  2. +16 −3 src/gui/qgsmaptool.h
@@ -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
@@ -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)
{
}

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

void QgsMapTool::activate()
{
// make action active
// make action and/or button active
if (mAction)
mAction->setChecked(true);
if (mButton)
mButton->setChecked(true);

// set cursor (map tools usually set it in constructor)
mCanvas->setCursor(mCursor);
@@ -84,6 +87,8 @@ void QgsMapTool::deactivate()
{
if (mAction)
mAction->setChecked(false);
if (mButton)
mButton->setChecked(false);
}

void QgsMapTool::setAction(QAction* action)
@@ -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 *)
{
}
@@ -28,7 +28,7 @@ class QgsPoint;
class QgsRect;
class QPoint;
class QAction;

class QAbstractButton;

class GUI_EXPORT QgsMapTool : public QObject
{
@@ -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.*/
@@ -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;

};

#endif

0 comments on commit 4b801ce

Please sign in to comment.