Skip to content
Permalink
Browse files

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
  • Loading branch information
3nids committed Dec 10, 2014
1 parent 21c4cbb commit 5fd04e63b9ed9f185aa591f5a9af9838a5669054
@@ -587,7 +587,7 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent,

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

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

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

void QgisApp::createStatusBar()
@@ -20,6 +20,7 @@
#include "qgisapp.h"
#include "qgsadvanceddigitizingdockwidget.h"
#include "qgsadvanceddigitizingcanvasitem.h"
#include "qgsapplication.h"
#include "qgsexpression.h"
#include "qgslogger.h"
#include "qgsmapcanvas.h"
@@ -108,11 +109,19 @@ QgsAdvancedDigitizingDockWidget::QgsAdvancedDigitizingDockWidget( QgsMapCanvas*
mXLineEdit->installEventFilter( this );
mYLineEdit->installEventFilter( this );

// this action is also used in the advanced digitizing tool bar
mEnableAction = new QAction( this );
mEnableAction->setText( tr( "Enable advanced digitizing tools" ) );
mEnableAction->setIcon( QgsApplication::getThemeIcon( "/cadtools/cad.png" ) );
mEnableAction->setCheckable( true );
mEnabledButton->addAction( mEnableAction );
mEnabledButton->setDefaultAction( mEnableAction );

// enable/disable on map tool change
connect( canvas, SIGNAL( mapToolSet( QgsMapTool* ) ), this, SLOT( mapToolChanged( QgsMapTool* ) ) );

// Connect the UI to the event filter to update constraints
connect( mEnabledButton, SIGNAL( clicked( bool ) ), this, SLOT( activateCad( bool ) ) );
connect( mEnableAction, SIGNAL( triggered( bool ) ), this, SLOT( activateCad( bool ) ) );
connect( mConstructionModeButton, SIGNAL( clicked( bool ) ), this, SLOT( setConstructionMode( bool ) ) );
connect( mParallelButton, SIGNAL( clicked( bool ) ), this, SLOT( addtionalConstraintClicked( bool ) ) );
connect( mPerpendicularButton, SIGNAL( clicked( bool ) ), this, SLOT( addtionalConstraintClicked( bool ) ) );
@@ -171,12 +180,6 @@ QgsAdvancedDigitizingDockWidget::~QgsAdvancedDigitizingDockWidget()
delete mErrorMessage;
}

void QgsAdvancedDigitizingDockWidget::showEvent( QShowEvent* )
{
// when showing dock enable CAD if it used to be enabled
activateCad( QSettings().value( "/Cad/SessionActive", false ).toBool() );
}

void QgsAdvancedDigitizingDockWidget::hideEvent( QHideEvent* )
{
// disable CAD but do not unset map event filter
@@ -213,25 +216,22 @@ void QgsAdvancedDigitizingDockWidget::mapToolChanged( QgsMapTool* tool )

if ( mCurrentMapTool )
{
mEnableAction->setEnabled( true );
mErrorLabel->hide();
mCadWidget->show();
setMaximumSize( 5000, 220 );

if ( toolMap->cadAllowed() )
{
if ( isVisible() )
{
const bool enabled = QSettings().value( "/Cad/SessionActive", false ).toBool();
setCadEnabled( enabled );
}
}
else
// restore previous status
const bool enabled = QSettings().value( "/Cad/SessionActive", false ).toBool();
if ( enabled && !isVisible() )
{
setCadEnabled( false );
show();
}
setCadEnabled( enabled );
}
else
{
mEnableAction->setEnabled( false );
mErrorLabel->setText( lblText );
mErrorLabel->show();
mCadWidget->hide();
@@ -244,22 +244,31 @@ void QgsAdvancedDigitizingDockWidget::mapToolChanged( QgsMapTool* tool )
void QgsAdvancedDigitizingDockWidget::setCadEnabled( bool enabled )
{
mCadEnabled = enabled;
mEnabledButton->setChecked( enabled );
mEnableAction->setChecked( enabled );
mCadButtons->setEnabled( enabled );
mInputWidgets->setEnabled( enabled );

clearPoints();
releaseLocks();
setConstructionMode( false );
}

void QgsAdvancedDigitizingDockWidget::activateCad( bool enabled )
{
enabled &= mCurrentMapTool != 0;

if ( mErrorMessageDisplayed )
{
QgisApp::instance()->messageBar()->popWidget( mErrorMessage );
}
QSettings().setValue( "/Cad/SessionActive", enabled );
setCadEnabled( enabled && mCurrentMapTool );

if ( enabled && !isVisible() )
{
show();
}

setCadEnabled( enabled );
}

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

bool QgsAdvancedDigitizingDockWidget::applyConstraints( QgsMapMouseEvent* e )
{
if ( !mCadEnabled )
return true;

bool res = true;

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

return mConstructionMode;
return mCadEnabled && mConstructionMode;
}

bool QgsAdvancedDigitizingDockWidget::canvasReleaseEventFilter( QgsMapMouseEvent* e )
{
if ( !mCadEnabled )
return false;

if ( mErrorMessageDisplayed )
{
QgisApp::instance()->messageBar()->popWidget( mErrorMessage );
@@ -883,6 +892,9 @@ bool QgsAdvancedDigitizingDockWidget::canvasReleaseEventFilter( QgsMapMouseEvent

bool QgsAdvancedDigitizingDockWidget::canvasMoveEventFilter( QgsMapMouseEvent* e )
{
if ( !mCadEnabled )
return false;

if ( !applyConstraints( e ) )
{
if ( !mErrorMessageDisplayed )
@@ -908,6 +920,10 @@ bool QgsAdvancedDigitizingDockWidget::canvasMoveEventFilter( QgsMapMouseEvent* e
bool QgsAdvancedDigitizingDockWidget::canvasKeyPressEventFilter( QKeyEvent* e )
{
// event on map tool

if ( !mCadEnabled )
return false;

switch ( e->key() )
{
case Qt::Key_Backspace:
@@ -935,6 +951,10 @@ bool QgsAdvancedDigitizingDockWidget::canvasKeyPressEventFilter( QKeyEvent* e )
void QgsAdvancedDigitizingDockWidget::keyPressEvent( QKeyEvent *e )
{
// event on dock (this)

if ( !mCadEnabled )
return;

switch ( e->key() )
{
case Qt::Key_Backspace:
@@ -120,7 +120,6 @@ class APP_EXPORT QgsAdvancedDigitizingDockWidget : public QDockWidget, private U

~QgsAdvancedDigitizingDockWidget();

void showEvent( QShowEvent* );
void hideEvent( QHideEvent* );

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

//! return the action used to enable/disable the tools
QAction* enableAction() { return mEnableAction; }

public slots:
//! whenever a map tool changes, determines if the dock shall be activated or not
void mapToolChanged( QgsMapTool* tool );
@@ -174,7 +176,8 @@ class APP_EXPORT QgsAdvancedDigitizingDockWidget : public QDockWidget, private U
//! set the relative properties of constraints
void setConstraintRelative( bool activate );

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

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

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

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

// UI
QAction* mEnableAction;
QMap< QAction*, int > mCommonAngleActions; // map the common angle actions with their angle values
QAction* mSnappingEnabledAction;
};
@@ -67,10 +67,6 @@
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/cadtools/cad.png</normaloff>:/images/themes/default/cadtools/cad.png</iconset>
</property>
<property name="iconSize">
<size>
<width>24</width>

0 comments on commit 5fd04e6

Please sign in to comment.
You can’t perform that action at this time.