Skip to content

Commit 5fd04e6

Browse files
committedDec 10, 2014
advanced digitizing tools fixes part 2
* action in toolbar activate/disable the tools instead of showing/hiding the dock * do not filter event if tools are disabled * disable construction mode if tools are disabled * continue renaming cad to advanced digitiing tools
1 parent 21c4cbb commit 5fd04e6

File tree

4 files changed

+52
-35
lines changed

4 files changed

+52
-35
lines changed
 

‎src/app/qgisapp.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent,
587587

588588
// Advanced Digitizing dock
589589
mAdvancedDigitizingDockWidget = new QgsAdvancedDigitizingDockWidget( mMapCanvas, this );
590-
mAdvancedDigitizingDockWidget->setObjectName( "Cad" );
590+
mAdvancedDigitizingDockWidget->setObjectName( "AdvancedDigitizingTools" );
591591

592592
createActions();
593593
createActionGroups();
@@ -1641,10 +1641,7 @@ void QgisApp::createToolBars()
16411641
mHelpToolBar->addAction( actionWhatsThis );
16421642

16431643
// Cad toolbar
1644-
QAction* cadAction = mAdvancedDigitizingDockWidget->toggleViewAction();
1645-
cadAction->setText( tr( "Show CAD tools" ) );
1646-
cadAction->setIcon( QgsApplication::getThemeIcon( "/cadtools/cad.png" ) );
1647-
mAdvancedDigitizeToolBar->insertAction( mActionUndo, cadAction );
1644+
mAdvancedDigitizeToolBar->insertAction( mActionUndo, mAdvancedDigitizingDockWidget->enableAction() );
16481645
}
16491646

16501647
void QgisApp::createStatusBar()

‎src/app/qgsadvanceddigitizingdockwidget.cpp

Lines changed: 43 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "qgisapp.h"
2121
#include "qgsadvanceddigitizingdockwidget.h"
2222
#include "qgsadvanceddigitizingcanvasitem.h"
23+
#include "qgsapplication.h"
2324
#include "qgsexpression.h"
2425
#include "qgslogger.h"
2526
#include "qgsmapcanvas.h"
@@ -108,11 +109,19 @@ QgsAdvancedDigitizingDockWidget::QgsAdvancedDigitizingDockWidget( QgsMapCanvas*
108109
mXLineEdit->installEventFilter( this );
109110
mYLineEdit->installEventFilter( this );
110111

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+
111120
// enable/disable on map tool change
112121
connect( canvas, SIGNAL( mapToolSet( QgsMapTool* ) ), this, SLOT( mapToolChanged( QgsMapTool* ) ) );
113122

114123
// 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 ) ) );
116125
connect( mConstructionModeButton, SIGNAL( clicked( bool ) ), this, SLOT( setConstructionMode( bool ) ) );
117126
connect( mParallelButton, SIGNAL( clicked( bool ) ), this, SLOT( addtionalConstraintClicked( bool ) ) );
118127
connect( mPerpendicularButton, SIGNAL( clicked( bool ) ), this, SLOT( addtionalConstraintClicked( bool ) ) );
@@ -171,12 +180,6 @@ QgsAdvancedDigitizingDockWidget::~QgsAdvancedDigitizingDockWidget()
171180
delete mErrorMessage;
172181
}
173182

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-
180183
void QgsAdvancedDigitizingDockWidget::hideEvent( QHideEvent* )
181184
{
182185
// disable CAD but do not unset map event filter
@@ -213,25 +216,22 @@ void QgsAdvancedDigitizingDockWidget::mapToolChanged( QgsMapTool* tool )
213216

214217
if ( mCurrentMapTool )
215218
{
219+
mEnableAction->setEnabled( true );
216220
mErrorLabel->hide();
217221
mCadWidget->show();
218222
setMaximumSize( 5000, 220 );
219223

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() )
229227
{
230-
setCadEnabled( false );
228+
show();
231229
}
230+
setCadEnabled( enabled );
232231
}
233232
else
234233
{
234+
mEnableAction->setEnabled( false );
235235
mErrorLabel->setText( lblText );
236236
mErrorLabel->show();
237237
mCadWidget->hide();
@@ -244,22 +244,31 @@ void QgsAdvancedDigitizingDockWidget::mapToolChanged( QgsMapTool* tool )
244244
void QgsAdvancedDigitizingDockWidget::setCadEnabled( bool enabled )
245245
{
246246
mCadEnabled = enabled;
247-
mEnabledButton->setChecked( enabled );
247+
mEnableAction->setChecked( enabled );
248248
mCadButtons->setEnabled( enabled );
249249
mInputWidgets->setEnabled( enabled );
250250

251251
clearPoints();
252252
releaseLocks();
253+
setConstructionMode( false );
253254
}
254255

255256
void QgsAdvancedDigitizingDockWidget::activateCad( bool enabled )
256257
{
258+
enabled &= mCurrentMapTool != 0;
259+
257260
if ( mErrorMessageDisplayed )
258261
{
259262
QgisApp::instance()->messageBar()->popWidget( mErrorMessage );
260263
}
261264
QSettings().setValue( "/Cad/SessionActive", enabled );
262-
setCadEnabled( enabled && mCurrentMapTool );
265+
266+
if ( enabled && !isVisible() )
267+
{
268+
show();
269+
}
270+
271+
setCadEnabled( enabled );
263272
}
264273

265274
void QgsAdvancedDigitizingDockWidget::addtionalConstraintClicked( bool activated )
@@ -490,9 +499,6 @@ void QgsAdvancedDigitizingDockWidget::updateCapacity( bool updateUIwithoutChange
490499

491500
bool QgsAdvancedDigitizingDockWidget::applyConstraints( QgsMapMouseEvent* e )
492501
{
493-
if ( !mCadEnabled )
494-
return true;
495-
496502
bool res = true;
497503

498504
QgsDebugMsg( "Contraints (locked / relative / value" );
@@ -834,11 +840,14 @@ bool QgsAdvancedDigitizingDockWidget::canvasPressEventFilter( QgsMapMouseEvent*
834840
{
835841
Q_UNUSED( e );
836842

837-
return mConstructionMode;
843+
return mCadEnabled && mConstructionMode;
838844
}
839845

840846
bool QgsAdvancedDigitizingDockWidget::canvasReleaseEventFilter( QgsMapMouseEvent* e )
841847
{
848+
if ( !mCadEnabled )
849+
return false;
850+
842851
if ( mErrorMessageDisplayed )
843852
{
844853
QgisApp::instance()->messageBar()->popWidget( mErrorMessage );
@@ -883,6 +892,9 @@ bool QgsAdvancedDigitizingDockWidget::canvasReleaseEventFilter( QgsMapMouseEvent
883892

884893
bool QgsAdvancedDigitizingDockWidget::canvasMoveEventFilter( QgsMapMouseEvent* e )
885894
{
895+
if ( !mCadEnabled )
896+
return false;
897+
886898
if ( !applyConstraints( e ) )
887899
{
888900
if ( !mErrorMessageDisplayed )
@@ -908,6 +920,10 @@ bool QgsAdvancedDigitizingDockWidget::canvasMoveEventFilter( QgsMapMouseEvent* e
908920
bool QgsAdvancedDigitizingDockWidget::canvasKeyPressEventFilter( QKeyEvent* e )
909921
{
910922
// event on map tool
923+
924+
if ( !mCadEnabled )
925+
return false;
926+
911927
switch ( e->key() )
912928
{
913929
case Qt::Key_Backspace:
@@ -935,6 +951,10 @@ bool QgsAdvancedDigitizingDockWidget::canvasKeyPressEventFilter( QKeyEvent* e )
935951
void QgsAdvancedDigitizingDockWidget::keyPressEvent( QKeyEvent *e )
936952
{
937953
// event on dock (this)
954+
955+
if ( !mCadEnabled )
956+
return;
957+
938958
switch ( e->key() )
939959
{
940960
case Qt::Key_Backspace:

‎src/app/qgsadvanceddigitizingdockwidget.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ class APP_EXPORT QgsAdvancedDigitizingDockWidget : public QDockWidget, private U
120120

121121
~QgsAdvancedDigitizingDockWidget();
122122

123-
void showEvent( QShowEvent* );
124123
void hideEvent( QHideEvent* );
125124

126125
virtual bool canvasPressEventFilter( QgsMapMouseEvent* e );
@@ -157,6 +156,9 @@ class APP_EXPORT QgsAdvancedDigitizingDockWidget : public QDockWidget, private U
157156
bool pointSnapped() const {return mPointSnapped;}
158157
const QList<QgsPoint>& snappedSegment() const {return mSnappedSegment;}
159158

159+
//! return the action used to enable/disable the tools
160+
QAction* enableAction() { return mEnableAction; }
161+
160162
public slots:
161163
//! whenever a map tool changes, determines if the dock shall be activated or not
162164
void mapToolChanged( QgsMapTool* tool );
@@ -174,7 +176,8 @@ class APP_EXPORT QgsAdvancedDigitizingDockWidget : public QDockWidget, private U
174176
//! set the relative properties of constraints
175177
void setConstraintRelative( bool activate );
176178

177-
//! activates/deactivates CAD for the current map tool
179+
//! activate/deactuvate tools. It is called when tools are activated manually (from the GUI)
180+
//! it will call setCadEnabled to properly update the UI.
178181
void activateCad( bool enabled );
179182

180183
//! enable/disable construction mode (events are not forwarded to the map tool)
@@ -184,7 +187,7 @@ class APP_EXPORT QgsAdvancedDigitizingDockWidget : public QDockWidget, private U
184187
void settingsButtonTriggered( QAction* action );
185188

186189
private:
187-
//! used to update the UI when CAD is activated/deactivated
190+
//! updates the UI depending on activation of the tools and clear points / release locks.
188191
void setCadEnabled( bool enabled );
189192

190193
/**
@@ -255,6 +258,7 @@ class APP_EXPORT QgsAdvancedDigitizingDockWidget : public QDockWidget, private U
255258
bool mErrorMessageDisplayed;
256259

257260
// UI
261+
QAction* mEnableAction;
258262
QMap< QAction*, int > mCommonAngleActions; // map the common angle actions with their angle values
259263
QAction* mSnappingEnabledAction;
260264
};

‎src/ui/qgsadvanceddigitizingdockwidgetbase.ui

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,6 @@
6767
<property name="text">
6868
<string>...</string>
6969
</property>
70-
<property name="icon">
71-
<iconset resource="../../images/images.qrc">
72-
<normaloff>:/images/themes/default/cadtools/cad.png</normaloff>:/images/themes/default/cadtools/cad.png</iconset>
73-
</property>
7470
<property name="iconSize">
7571
<size>
7672
<width>24</width>

0 commit comments

Comments
 (0)
Please sign in to comment.