Skip to content

Commit 4b801ce

Browse files
author
wonder
committedJun 17, 2007
Added setButton() and button() functions to QgsMapTool so that also button
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

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-6
lines changed
 

‎src/gui/qgsmaptool.cpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/***************************************************************************
2-
qgsmaptool.h - base class for map canvas tools
2+
qgsmaptool.cpp - base class for map canvas tools
33
----------------------
44
begin : January 2006
55
copyright : (C) 2006 by Martin Dobias
@@ -20,9 +20,10 @@
2020
#include "qgsmaprender.h"
2121
#include "qgsmaptopixel.h"
2222
#include <QAction>
23+
#include <QAbstractButton>
2324

2425
QgsMapTool::QgsMapTool(QgsMapCanvas* canvas)
25-
: QObject(canvas), mCanvas(canvas), mCursor(Qt::CrossCursor), mAction(NULL)
26+
: QObject(canvas), mCanvas(canvas), mCursor(Qt::CrossCursor), mAction(NULL), mButton(NULL)
2627
{
2728
}
2829

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

7172
void QgsMapTool::activate()
7273
{
73-
// make action active
74+
// make action and/or button active
7475
if (mAction)
7576
mAction->setChecked(true);
77+
if (mButton)
78+
mButton->setChecked(true);
7679

7780
// set cursor (map tools usually set it in constructor)
7881
mCanvas->setCursor(mCursor);
@@ -84,6 +87,8 @@ void QgsMapTool::deactivate()
8487
{
8588
if (mAction)
8689
mAction->setChecked(false);
90+
if (mButton)
91+
mButton->setChecked(false);
8792
}
8893

8994
void QgsMapTool::setAction(QAction* action)
@@ -96,6 +101,17 @@ QAction* QgsMapTool::action()
96101
return mAction;
97102
}
98103

104+
void QgsMapTool::setButton(QAbstractButton* button)
105+
{
106+
mButton = button;
107+
}
108+
109+
QAbstractButton* QgsMapTool::button()
110+
{
111+
return mButton;
112+
}
113+
114+
99115
void QgsMapTool::canvasMoveEvent(QMouseEvent *)
100116
{
101117
}

‎src/gui/qgsmaptool.h

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class QgsPoint;
2828
class QgsRect;
2929
class QPoint;
3030
class QAction;
31-
31+
class QAbstractButton;
3232

3333
class GUI_EXPORT QgsMapTool : public QObject
3434
{
@@ -49,15 +49,24 @@ class GUI_EXPORT QgsMapTool : public QObject
4949
//! Called when rendering has finished. Default implementation does nothing.
5050
virtual void renderComplete();
5151

52-
/** Use this to associate a button, toolbutton, menu entry etc
53-
* that inherits qaction to this maptool. Then when the setMapTool
52+
53+
/** Use this to associate a QAction to this maptool. Then when the setMapTool
5454
* method of mapcanvas is called the action state will be set to on.
5555
* Usually this will cause e.g. a toolbutton to appear pressed in and
5656
* the previously used toolbutton to pop out. */
5757
void setAction(QAction* action);
5858

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

62+
/** Use this to associate a button to this maptool. It has the same meaning
63+
* as setAction() function except it works with a button instead of an QAction. */
64+
void setButton(QAbstractButton* button);
65+
66+
/** Return associated button with map tool or NULL if no button is associated */
67+
QAbstractButton* button();
68+
69+
6170
/** Check whether this MapTool performs a zoom or pan operation.
6271
* If it does, we will be able to perform the zoom and then
6372
* resume operations with the original / previously used tool.*/
@@ -105,6 +114,10 @@ class GUI_EXPORT QgsMapTool : public QObject
105114
//! which will be used to set that action as active
106115
QAction* mAction;
107116

117+
//! optionally map tool can have pointer to a button
118+
//! which will be used to set that action as active
119+
QAbstractButton* mButton;
120+
108121
};
109122

110123
#endif

0 commit comments

Comments
 (0)
Please sign in to comment.