Skip to content

Commit d51ea41

Browse files
committedAug 27, 2013
fix capture coordinate plugin: refs pull request #803
1 parent c2310fd commit d51ea41

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed
 

‎src/plugins/coordinate_capture/coordinatecapture.cpp

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,22 @@ void CoordinateCapture::initGui()
9292
mTransform.setDestCRS( mCrs ); // set the CRS in the transform
9393
mUserCrsDisplayPrecision = ( mCrs.mapUnits() == QGis::Degrees ) ? 5 : 3; // precision depends on CRS units
9494

95+
//create the dock widget
96+
mpDockWidget = new QDockWidget( tr( "Coordinate Capture" ), mQGisIface->mainWindow() );
97+
mpDockWidget->setObjectName( "CoordinateCapture" );
98+
mpDockWidget->setAllowedAreas( Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea );
99+
mQGisIface->addDockWidget( Qt::LeftDockWidgetArea, mpDockWidget );
100+
95101
// Create the action for tool
96102
mQActionPointer = new QAction( QIcon(), tr( "Coordinate Capture" ), this );
103+
mQActionPointer->setCheckable( true );
104+
mQActionPointer->setChecked( mpDockWidget->isVisible() );
97105
// Set the what's this text
98106
mQActionPointer->setWhatsThis( tr( "Click on the map to view coordinates and capture to clipboard." ) );
99107
// Connect the action to the run
100-
connect( mQActionPointer, SIGNAL( triggered() ), this, SLOT( run() ) );
108+
connect( mQActionPointer, SIGNAL( triggered() ), this, SLOT( showOrHide() ) );
101109
mQGisIface->addPluginToVectorMenu( tr( "&Coordinate Capture" ), mQActionPointer );
110+
mQGisIface->addVectorToolBarIcon( mQActionPointer );
102111

103112
// create our map tool
104113
mpMapTool = new CoordinateCaptureMapTool( mQGisIface->mapCanvas() );
@@ -155,16 +164,9 @@ void CoordinateCapture::initGui()
155164
mypLayout->addWidget( mypCopyButton, 2, 1 );
156165
mypLayout->addWidget( mpCaptureButton, 3, 1 );
157166

158-
159-
//create the dock widget
160-
mpDockWidget = new QDockWidget( tr( "Coordinate Capture" ), mQGisIface->mainWindow() );
161-
mpDockWidget->setObjectName( "CoordinateCapture" );
162-
mpDockWidget->setAllowedAreas( Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea );
163-
mQGisIface->addDockWidget( Qt::LeftDockWidgetArea, mpDockWidget );
164-
165167
// now add our custom widget to the dock - ownership of the widget is passed to the dock
166168
mpDockWidget->setWidget( mypWidget );
167-
169+
connect( mpDockWidget, SIGNAL( visibilityChanged( bool ) ), mQActionPointer, SLOT( setChecked( bool ) ) );
168170
}
169171

170172
//method defined in interface
@@ -243,12 +245,23 @@ void CoordinateCapture::run()
243245
//myPluginGui->show();
244246
}
245247

248+
void CoordinateCapture::showOrHide()
249+
{
250+
if ( !mpDockWidget )
251+
run();
252+
else
253+
if ( mQActionPointer->isChecked() )
254+
mpDockWidget->show();
255+
else
256+
mpDockWidget->hide();
257+
}
258+
246259
// Unload the plugin by cleaning up the GUI
247260
void CoordinateCapture::unload()
248261
{
249262
// remove the GUI
250-
mQGisIface->removePluginMenu( "&Coordinate Capture", mQActionPointer );
251-
//mQGisIface->removeToolBarIcon( mQActionPointer );
263+
mQGisIface->removePluginVectorMenu( "&Coordinate Capture", mQActionPointer );
264+
mQGisIface->removeVectorToolBarIcon( mQActionPointer );
252265
mpMapTool->deactivate();
253266
delete mpMapTool;
254267
delete mpDockWidget;

‎src/plugins/coordinate_capture/coordinatecapture.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ class CoordinateCapture: public QObject, public QgisPlugin
9090
void run();
9191
//! unload the plugin
9292
void unload();
93+
//! Show/hide the dockwidget
94+
void showOrHide();
9395
//! show the help document
9496
void help();
9597
//! Set the Coordinate Reference System used for displaying non canvas CRS coord

0 commit comments

Comments
 (0)
Please sign in to comment.