Skip to content

Commit 444c1c0

Browse files
author
rblazek
committed
fixed ticket 90 (post grass edit right click crash)
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@5676 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 6a26b12 commit 444c1c0

File tree

4 files changed

+36
-4
lines changed

4 files changed

+36
-4
lines changed

src/gui/qgsmapcanvas.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,20 @@ void QgsMapCanvas::setMapTool(QgsMapTool* tool)
823823

824824
} // setMapTool
825825

826+
void QgsMapCanvas::unsetMapTool(QgsMapTool* tool)
827+
{
828+
if (mMapTool && mMapTool == tool)
829+
{
830+
mMapTool->deactivate();
831+
mMapTool = NULL;
832+
}
833+
834+
if ( mLastNonZoomMapTool && mLastNonZoomMapTool == tool)
835+
{
836+
mLastNonZoomMapTool->deactivate(); // ? necessary
837+
mLastNonZoomMapTool = NULL;
838+
}
839+
}
826840

827841
/** Write property of QColor bgColor. */
828842
void QgsMapCanvas::setCanvasColor(const QColor & theColor)

src/gui/qgsmapcanvas.h

+7
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,13 @@ class QgsMapCanvas : public Q3CanvasView
114114

115115
/** \brief Sets the map tool currently being used on the canvas */
116116
void setMapTool(QgsMapTool* mapTool);
117+
118+
/** \brief Unset the current mapset tool or last non zoom tool if
119+
* it the same as passed map tool pointer. The tool is not
120+
* referenced/used any more, but the instance is not deleted
121+
* by this method.
122+
*/
123+
void unsetMapTool(QgsMapTool* mapTool);
117124

118125
/**Returns the currently active tool*/
119126
QgsMapTool* mapTool();

src/plugins/grass/qgsgrassedit.cpp

+11-4
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ bool QgsGrassEdit::mRunning = false;
106106

107107
QgsGrassEdit::QgsGrassEdit ( QgisApp *qgisApp, QgisIface *iface,
108108
QWidget * parent, Qt::WFlags f )
109-
:QMainWindow(parent,f), QgsGrassEditBase ()
109+
:QMainWindow(parent,f), QgsGrassEditBase (), mMapTool(0)
110110
{
111111
#ifdef QGISDEBUG
112112
std::cerr << "QgsGrassEdit()" << std::endl;
@@ -193,7 +193,7 @@ void QgsGrassEdit::keyPress(QKeyEvent *e)
193193
QgsGrassEdit::QgsGrassEdit ( QgisApp *qgisApp, QgisIface *iface,
194194
QgsGrassProvider *provider,
195195
QWidget * parent, Qt::WFlags f )
196-
:QMainWindow(parent, 0, f), QgsGrassEditBase ()
196+
:QMainWindow(parent, 0, f), QgsGrassEditBase (), mMapTool(0)
197197
{
198198
#ifdef QGISDEBUG
199199
std::cerr << "QgsGrassEdit()" << std::endl;
@@ -927,6 +927,10 @@ QgsGrassEdit::~QgsGrassEdit()
927927
delete mRubberBandLine;
928928
delete mRubberBandIcon;
929929
delete mCanvasEdit;
930+
931+
if ( mMapTool ) mCanvas->unsetMapTool ( mMapTool );
932+
// TODO: delete tool? Probably
933+
930934
mCanvas->refresh();
931935
}
932936

@@ -1235,7 +1239,10 @@ void QgsGrassEdit::startTool(int tool)
12351239
displayElement ( mSelectedLine, mSymb[mLineSymb[mSelectedLine]], mSize );
12361240

12371241
// close old tool by setting NULL tool
1238-
mCanvas->setMapTool(NULL);
1242+
// TODO: delete old tool? (check in set/unsetMapTool canvas methods)
1243+
if ( mMapTool ) mCanvas->unsetMapTool ( mMapTool );
1244+
mCanvas->setMapTool(NULL); // ? necessary
1245+
mMapTool = NULL;
12391246

12401247
// All necessary data were written -> reset mEditPoints etc.
12411248
Vect_reset_line ( mEditPoints );
@@ -1321,7 +1328,7 @@ void QgsGrassEdit::startTool(int tool)
13211328
// assign newly created tool to map canvas
13221329
// canvas will take care of destroying it
13231330
mCanvas->setMapTool(t);
1324-
1331+
mMapTool = t;
13251332
}
13261333

13271334

src/plugins/grass/qgsgrassedit.h

+4
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class QCloseEvent;
3838
class QgsRubberBand;
3939
class QgsVertexMarker;
4040
class QgsVectorLayer;
41+
class QgsMapTool;
4142
class QgsGrassEditLayer;
4243
class QgsGrassAttributes;
4344

@@ -437,6 +438,9 @@ public slots:
437438
QAction *mEditAttributesAction;
438439
QAction *mCloseEditAction;
439440

441+
// Current map tool
442+
QgsMapTool *mMapTool;
443+
440444
// Is projection enabled?
441445
bool mProjectionEnabled;
442446

0 commit comments

Comments
 (0)