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
Expand Up @@ -587,7 +587,7 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent,


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


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


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


void QgisApp::createStatusBar() void QgisApp::createStatusBar()
Expand Down
66 changes: 43 additions & 23 deletions src/app/qgsadvanceddigitizingdockwidget.cpp
Expand Up @@ -20,6 +20,7 @@
#include "qgisapp.h" #include "qgisapp.h"
#include "qgsadvanceddigitizingdockwidget.h" #include "qgsadvanceddigitizingdockwidget.h"
#include "qgsadvanceddigitizingcanvasitem.h" #include "qgsadvanceddigitizingcanvasitem.h"
#include "qgsapplication.h"
#include "qgsexpression.h" #include "qgsexpression.h"
#include "qgslogger.h" #include "qgslogger.h"
#include "qgsmapcanvas.h" #include "qgsmapcanvas.h"
Expand Down Expand Up @@ -108,11 +109,19 @@ QgsAdvancedDigitizingDockWidget::QgsAdvancedDigitizingDockWidget( QgsMapCanvas*
mXLineEdit->installEventFilter( this ); mXLineEdit->installEventFilter( this );
mYLineEdit->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 // enable/disable on map tool change
connect( canvas, SIGNAL( mapToolSet( QgsMapTool* ) ), this, SLOT( mapToolChanged( QgsMapTool* ) ) ); connect( canvas, SIGNAL( mapToolSet( QgsMapTool* ) ), this, SLOT( mapToolChanged( QgsMapTool* ) ) );


// Connect the UI to the event filter to update constraints // 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( mConstructionModeButton, SIGNAL( clicked( bool ) ), this, SLOT( setConstructionMode( bool ) ) );
connect( mParallelButton, SIGNAL( clicked( bool ) ), this, SLOT( addtionalConstraintClicked( bool ) ) ); connect( mParallelButton, SIGNAL( clicked( bool ) ), this, SLOT( addtionalConstraintClicked( bool ) ) );
connect( mPerpendicularButton, 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; 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* ) void QgsAdvancedDigitizingDockWidget::hideEvent( QHideEvent* )
{ {
// disable CAD but do not unset map event filter // disable CAD but do not unset map event filter
Expand Down Expand Up @@ -213,25 +216,22 @@ void QgsAdvancedDigitizingDockWidget::mapToolChanged( QgsMapTool* tool )


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


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


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


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

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

setCadEnabled( enabled );
} }


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


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

bool res = true; bool res = true;


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


return mConstructionMode; return mCadEnabled && mConstructionMode;
} }


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

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


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

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

if ( !mCadEnabled )
return false;

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

if ( !mCadEnabled )
return;

switch ( e->key() ) switch ( e->key() )
{ {
case Qt::Key_Backspace: case Qt::Key_Backspace:
Expand Down
10 changes: 7 additions & 3 deletions src/app/qgsadvanceddigitizingdockwidget.h
Expand Up @@ -120,7 +120,6 @@ class APP_EXPORT QgsAdvancedDigitizingDockWidget : public QDockWidget, private U


~QgsAdvancedDigitizingDockWidget(); ~QgsAdvancedDigitizingDockWidget();


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


virtual bool canvasPressEventFilter( QgsMapMouseEvent* e ); 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;} bool pointSnapped() const {return mPointSnapped;}
const QList<QgsPoint>& snappedSegment() const {return mSnappedSegment;} const QList<QgsPoint>& snappedSegment() const {return mSnappedSegment;}


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

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


//! enable/disable construction mode (events are not forwarded to the map tool) //! 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 ); void settingsButtonTriggered( QAction* action );


private: 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 ); void setCadEnabled( bool enabled );


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


// UI // UI
QAction* mEnableAction;
QMap< QAction*, int > mCommonAngleActions; // map the common angle actions with their angle values QMap< QAction*, int > mCommonAngleActions; // map the common angle actions with their angle values
QAction* mSnappingEnabledAction; QAction* mSnappingEnabledAction;
}; };
Expand Down
4 changes: 0 additions & 4 deletions src/ui/qgsadvanceddigitizingdockwidgetbase.ui
Expand Up @@ -67,10 +67,6 @@
<property name="text"> <property name="text">
<string>...</string> <string>...</string>
</property> </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"> <property name="iconSize">
<size> <size>
<width>24</width> <width>24</width>
Expand Down

0 comments on commit 5fd04e6

Please sign in to comment.