@@ -92,13 +92,22 @@ void CoordinateCapture::initGui()
92
92
mTransform .setDestCRS ( mCrs ); // set the CRS in the transform
93
93
mUserCrsDisplayPrecision = ( mCrs .mapUnits () == QGis::Degrees ) ? 5 : 3 ; // precision depends on CRS units
94
94
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
+
95
101
// Create the action for tool
96
102
mQActionPointer = new QAction ( QIcon (), tr ( " Coordinate Capture" ), this );
103
+ mQActionPointer ->setCheckable ( true );
104
+ mQActionPointer ->setChecked ( mpDockWidget->isVisible () );
97
105
// Set the what's this text
98
106
mQActionPointer ->setWhatsThis ( tr ( " Click on the map to view coordinates and capture to clipboard." ) );
99
107
// Connect the action to the run
100
- connect ( mQActionPointer , SIGNAL ( triggered () ), this , SLOT ( run () ) );
108
+ connect ( mQActionPointer , SIGNAL ( triggered () ), this , SLOT ( showOrHide () ) );
101
109
mQGisIface ->addPluginToVectorMenu ( tr ( " &Coordinate Capture" ), mQActionPointer );
110
+ mQGisIface ->addVectorToolBarIcon ( mQActionPointer );
102
111
103
112
// create our map tool
104
113
mpMapTool = new CoordinateCaptureMapTool ( mQGisIface ->mapCanvas () );
@@ -155,16 +164,9 @@ void CoordinateCapture::initGui()
155
164
mypLayout->addWidget ( mypCopyButton, 2 , 1 );
156
165
mypLayout->addWidget ( mpCaptureButton, 3 , 1 );
157
166
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
-
165
167
// now add our custom widget to the dock - ownership of the widget is passed to the dock
166
168
mpDockWidget->setWidget ( mypWidget );
167
-
169
+ connect ( mpDockWidget, SIGNAL ( visibilityChanged ( bool ) ), mQActionPointer , SLOT ( setChecked ( bool ) ) );
168
170
}
169
171
170
172
// method defined in interface
@@ -243,12 +245,23 @@ void CoordinateCapture::run()
243
245
// myPluginGui->show();
244
246
}
245
247
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
+
246
259
// Unload the plugin by cleaning up the GUI
247
260
void CoordinateCapture::unload ()
248
261
{
249
262
// remove the GUI
250
- mQGisIface ->removePluginMenu ( " &Coordinate Capture" , mQActionPointer );
251
- // mQGisIface->removeToolBarIcon ( mQActionPointer );
263
+ mQGisIface ->removePluginVectorMenu ( " &Coordinate Capture" , mQActionPointer );
264
+ mQGisIface ->removeVectorToolBarIcon ( mQActionPointer );
252
265
mpMapTool->deactivate ();
253
266
delete mpMapTool;
254
267
delete mpDockWidget;
0 commit comments