Skip to content

Commit

Permalink
advanced digitizing tools fixes part 2
Browse files Browse the repository at this point in the history
* 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 5fd04e6
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 35 deletions.
7 changes: 2 additions & 5 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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()
Expand Down
66 changes: 43 additions & 23 deletions src/app/qgsadvanceddigitizingdockwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 ) ) );
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand All @@ -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 )
Expand Down Expand Up @@ -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" );
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -883,6 +892,9 @@ bool QgsAdvancedDigitizingDockWidget::canvasReleaseEventFilter( QgsMapMouseEvent

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

if ( !applyConstraints( e ) )
{
if ( !mErrorMessageDisplayed )
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
10 changes: 7 additions & 3 deletions src/app/qgsadvanceddigitizingdockwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ class APP_EXPORT QgsAdvancedDigitizingDockWidget : public QDockWidget, private U

~QgsAdvancedDigitizingDockWidget();

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

virtual bool canvasPressEventFilter( QgsMapMouseEvent* e );
Expand Down Expand Up @@ -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 );
Expand All @@ -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)
Expand All @@ -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 );

/**
Expand Down Expand Up @@ -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;
};
Expand Down
4 changes: 0 additions & 4 deletions src/ui/qgsadvanceddigitizingdockwidgetbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit 5fd04e6

Please sign in to comment.