20
20
#include " qgisapp.h"
21
21
#include " qgsadvanceddigitizingdockwidget.h"
22
22
#include " qgsadvanceddigitizingcanvasitem.h"
23
+ #include " qgsapplication.h"
23
24
#include " qgsexpression.h"
24
25
#include " qgslogger.h"
25
26
#include " qgsmapcanvas.h"
@@ -108,11 +109,19 @@ QgsAdvancedDigitizingDockWidget::QgsAdvancedDigitizingDockWidget( QgsMapCanvas*
108
109
mXLineEdit ->installEventFilter ( this );
109
110
mYLineEdit ->installEventFilter ( this );
110
111
112
+ // this action is also used in the advanced digitizing tool bar
113
+ mEnableAction = new QAction ( this );
114
+ mEnableAction ->setText ( tr ( " Enable advanced digitizing tools" ) );
115
+ mEnableAction ->setIcon ( QgsApplication::getThemeIcon ( " /cadtools/cad.png" ) );
116
+ mEnableAction ->setCheckable ( true );
117
+ mEnabledButton ->addAction ( mEnableAction );
118
+ mEnabledButton ->setDefaultAction ( mEnableAction );
119
+
111
120
// enable/disable on map tool change
112
121
connect ( canvas, SIGNAL ( mapToolSet ( QgsMapTool* ) ), this , SLOT ( mapToolChanged ( QgsMapTool* ) ) );
113
122
114
123
// Connect the UI to the event filter to update constraints
115
- connect ( mEnabledButton , SIGNAL ( clicked ( bool ) ), this , SLOT ( activateCad ( bool ) ) );
124
+ connect ( mEnableAction , SIGNAL ( triggered ( bool ) ), this , SLOT ( activateCad ( bool ) ) );
116
125
connect ( mConstructionModeButton , SIGNAL ( clicked ( bool ) ), this , SLOT ( setConstructionMode ( bool ) ) );
117
126
connect ( mParallelButton , SIGNAL ( clicked ( bool ) ), this , SLOT ( addtionalConstraintClicked ( bool ) ) );
118
127
connect ( mPerpendicularButton , SIGNAL ( clicked ( bool ) ), this , SLOT ( addtionalConstraintClicked ( bool ) ) );
@@ -171,12 +180,6 @@ QgsAdvancedDigitizingDockWidget::~QgsAdvancedDigitizingDockWidget()
171
180
delete mErrorMessage ;
172
181
}
173
182
174
- void QgsAdvancedDigitizingDockWidget::showEvent ( QShowEvent* )
175
- {
176
- // when showing dock enable CAD if it used to be enabled
177
- activateCad ( QSettings ().value ( " /Cad/SessionActive" , false ).toBool () );
178
- }
179
-
180
183
void QgsAdvancedDigitizingDockWidget::hideEvent ( QHideEvent* )
181
184
{
182
185
// disable CAD but do not unset map event filter
@@ -213,25 +216,22 @@ void QgsAdvancedDigitizingDockWidget::mapToolChanged( QgsMapTool* tool )
213
216
214
217
if ( mCurrentMapTool )
215
218
{
219
+ mEnableAction ->setEnabled ( true );
216
220
mErrorLabel ->hide ();
217
221
mCadWidget ->show ();
218
222
setMaximumSize ( 5000 , 220 );
219
223
220
- if ( toolMap->cadAllowed () )
221
- {
222
- if ( isVisible () )
223
- {
224
- const bool enabled = QSettings ().value ( " /Cad/SessionActive" , false ).toBool ();
225
- setCadEnabled ( enabled );
226
- }
227
- }
228
- else
224
+ // restore previous status
225
+ const bool enabled = QSettings ().value ( " /Cad/SessionActive" , false ).toBool ();
226
+ if ( enabled && !isVisible () )
229
227
{
230
- setCadEnabled ( false );
228
+ show ( );
231
229
}
230
+ setCadEnabled ( enabled );
232
231
}
233
232
else
234
233
{
234
+ mEnableAction ->setEnabled ( false );
235
235
mErrorLabel ->setText ( lblText );
236
236
mErrorLabel ->show ();
237
237
mCadWidget ->hide ();
@@ -244,22 +244,31 @@ void QgsAdvancedDigitizingDockWidget::mapToolChanged( QgsMapTool* tool )
244
244
void QgsAdvancedDigitizingDockWidget::setCadEnabled ( bool enabled )
245
245
{
246
246
mCadEnabled = enabled;
247
- mEnabledButton ->setChecked ( enabled );
247
+ mEnableAction ->setChecked ( enabled );
248
248
mCadButtons ->setEnabled ( enabled );
249
249
mInputWidgets ->setEnabled ( enabled );
250
250
251
251
clearPoints ();
252
252
releaseLocks ();
253
+ setConstructionMode ( false );
253
254
}
254
255
255
256
void QgsAdvancedDigitizingDockWidget::activateCad ( bool enabled )
256
257
{
258
+ enabled &= mCurrentMapTool != 0 ;
259
+
257
260
if ( mErrorMessageDisplayed )
258
261
{
259
262
QgisApp::instance ()->messageBar ()->popWidget ( mErrorMessage );
260
263
}
261
264
QSettings ().setValue ( " /Cad/SessionActive" , enabled );
262
- setCadEnabled ( enabled && mCurrentMapTool );
265
+
266
+ if ( enabled && !isVisible () )
267
+ {
268
+ show ();
269
+ }
270
+
271
+ setCadEnabled ( enabled );
263
272
}
264
273
265
274
void QgsAdvancedDigitizingDockWidget::addtionalConstraintClicked ( bool activated )
@@ -490,9 +499,6 @@ void QgsAdvancedDigitizingDockWidget::updateCapacity( bool updateUIwithoutChange
490
499
491
500
bool QgsAdvancedDigitizingDockWidget::applyConstraints ( QgsMapMouseEvent* e )
492
501
{
493
- if ( !mCadEnabled )
494
- return true ;
495
-
496
502
bool res = true ;
497
503
498
504
QgsDebugMsg ( " Contraints (locked / relative / value" );
@@ -834,11 +840,14 @@ bool QgsAdvancedDigitizingDockWidget::canvasPressEventFilter( QgsMapMouseEvent*
834
840
{
835
841
Q_UNUSED ( e );
836
842
837
- return mConstructionMode ;
843
+ return mCadEnabled && mConstructionMode ;
838
844
}
839
845
840
846
bool QgsAdvancedDigitizingDockWidget::canvasReleaseEventFilter ( QgsMapMouseEvent* e )
841
847
{
848
+ if ( !mCadEnabled )
849
+ return false ;
850
+
842
851
if ( mErrorMessageDisplayed )
843
852
{
844
853
QgisApp::instance ()->messageBar ()->popWidget ( mErrorMessage );
@@ -883,6 +892,9 @@ bool QgsAdvancedDigitizingDockWidget::canvasReleaseEventFilter( QgsMapMouseEvent
883
892
884
893
bool QgsAdvancedDigitizingDockWidget::canvasMoveEventFilter ( QgsMapMouseEvent* e )
885
894
{
895
+ if ( !mCadEnabled )
896
+ return false ;
897
+
886
898
if ( !applyConstraints ( e ) )
887
899
{
888
900
if ( !mErrorMessageDisplayed )
@@ -908,6 +920,10 @@ bool QgsAdvancedDigitizingDockWidget::canvasMoveEventFilter( QgsMapMouseEvent* e
908
920
bool QgsAdvancedDigitizingDockWidget::canvasKeyPressEventFilter ( QKeyEvent* e )
909
921
{
910
922
// event on map tool
923
+
924
+ if ( !mCadEnabled )
925
+ return false ;
926
+
911
927
switch ( e->key () )
912
928
{
913
929
case Qt::Key_Backspace:
@@ -935,6 +951,10 @@ bool QgsAdvancedDigitizingDockWidget::canvasKeyPressEventFilter( QKeyEvent* e )
935
951
void QgsAdvancedDigitizingDockWidget::keyPressEvent ( QKeyEvent *e )
936
952
{
937
953
// event on dock (this)
954
+
955
+ if ( !mCadEnabled )
956
+ return ;
957
+
938
958
switch ( e->key () )
939
959
{
940
960
case Qt::Key_Backspace:
0 commit comments