Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Move tracing action creation to qgis app
  • Loading branch information
wonder-sk committed Jan 19, 2016
1 parent f4bdaad commit 7a5df7a
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 13 deletions.
9 changes: 7 additions & 2 deletions python/gui/qgsmapcanvastracer.sip
Expand Up @@ -2,6 +2,7 @@
* Extension of QgsTracer that provides extra functionality:
* - automatic updates of own configuration based on canvas settings
* - reporting of issues to the user via message bar
* - determines whether tracing is currently enabled by the user
*
* A simple registry of tracer instances associated to map canvas instances
* is kept for convenience. (Map tools do not need to create their local
Expand All @@ -21,8 +22,12 @@ class QgsMapCanvasTracer : QgsTracer
explicit QgsMapCanvasTracer( QgsMapCanvas* canvas, QgsMessageBar* messageBar = 0 );
~QgsMapCanvasTracer();

//! Access to action that user may use to toggle tracing on/off
QAction* actionEnableTracing();
//! Access to action that user may use to toggle tracing on/off. May be null if no action was associated
QAction* actionEnableTracing() const;

//! Assign "enable tracing" checkable action to the tracer.
//! The action is used to determine whether tracing is currently enabled by the user
void setActionEnableTracing( QAction* action );

//! Retrieve instance of this class associated with given canvas (if any).
//! The class keeps a simple registry of tracers associated with map canvas
Expand Down
8 changes: 4 additions & 4 deletions src/app/qgisapp.cpp
Expand Up @@ -1981,10 +1981,10 @@ void QgisApp::createToolBars()
mDigitizeToolBar->insertWidget( mActionMoveFeature, tbAddCircularString );

// Cad toolbar
mAdvancedDigitizeToolBar->insertAction( mActionUndo, mAdvancedDigitizingDockWidget->enableAction() );
mAdvancedDigitizeToolBar->insertAction( mActionEnableTracing, mAdvancedDigitizingDockWidget->enableAction() );

mTracer = new QgsMapCanvasTracer( mMapCanvas, messageBar() );
mAdvancedDigitizeToolBar->insertAction( mActionUndo, mTracer->actionEnableTracing() );
mTracer->setActionEnableTracing( mActionEnableTracing );
}

void QgisApp::createStatusBar()
Expand Down Expand Up @@ -9739,7 +9739,7 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
mActionMergeFeatures->setEnabled( false );
mActionMergeFeatureAttributes->setEnabled( false );
mActionRotatePointSymbols->setEnabled( false );
mTracer->actionEnableTracing()->setEnabled( false );
mActionEnableTracing->setEnabled( false );

mActionPinLabels->setEnabled( false );
mActionShowHideLabels->setEnabled( false );
Expand Down Expand Up @@ -9860,7 +9860,7 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
mActionRotateFeature->setEnabled( isEditable && canChangeGeometry );
mActionNodeTool->setEnabled( isEditable && canChangeGeometry );

mTracer->actionEnableTracing()->setEnabled( isEditable && canAddFeatures &&
mActionEnableTracing->setEnabled( isEditable && canAddFeatures &&
( vlayer->geometryType() == QGis::Line || vlayer->geometryType() == QGis::Polygon ) );

if ( vlayer->geometryType() == QGis::Point )
Expand Down
5 changes: 1 addition & 4 deletions src/gui/qgsmapcanvastracer.cpp
Expand Up @@ -17,6 +17,7 @@ QgsMapCanvasTracer::QgsMapCanvasTracer( QgsMapCanvas* canvas, QgsMessageBar* mes
: mCanvas( canvas )
, mMessageBar( messageBar )
, mLastMessage( nullptr )
, mActionEnableTracing( nullptr )
{
sTracers.insert( canvas, this );

Expand All @@ -27,10 +28,6 @@ QgsMapCanvasTracer::QgsMapCanvasTracer( QgsMapCanvas* canvas, QgsMessageBar* mes
connect( canvas, SIGNAL( currentLayerChanged( QgsMapLayer* ) ), this, SLOT( onCurrentLayerChanged() ) );
connect( canvas->snappingUtils(), SIGNAL( configChanged() ), this, SLOT( invalidateGraph() ) );

mActionEnableTracing = new QAction( QIcon( QgsApplication::getThemeIcon( "/mActionTracing.png" ) ), tr( "Enable Tracing" ), this );
mActionEnableTracing->setShortcut( Qt::Key_T );
mActionEnableTracing->setCheckable( true );

// arbitrarily chosen limit that should allow for fairly fast initialization
// of the underlying graph structure
setMaxFeatureCount( QSettings().value( "/qgis/digitizing/tracing_max_feature_count", 10000 ).toInt() );
Expand Down
9 changes: 7 additions & 2 deletions src/gui/qgsmapcanvastracer.h
Expand Up @@ -12,6 +12,7 @@ class QgsMessageBarItem;
* Extension of QgsTracer that provides extra functionality:
* - automatic updates of own configuration based on canvas settings
* - reporting of issues to the user via message bar
* - determines whether tracing is currently enabled by the user
*
* A simple registry of tracer instances associated to map canvas instances
* is kept for convenience. (Map tools do not need to create their local
Expand All @@ -29,8 +30,12 @@ class GUI_EXPORT QgsMapCanvasTracer : public QgsTracer
explicit QgsMapCanvasTracer( QgsMapCanvas* canvas, QgsMessageBar* messageBar = 0 );
~QgsMapCanvasTracer();

//! Access to action that user may use to toggle tracing on/off
QAction* actionEnableTracing() { return mActionEnableTracing; }
//! Access to action that user may use to toggle tracing on/off. May be null if no action was associated
QAction* actionEnableTracing() const { return mActionEnableTracing; }

//! Assign "enable tracing" checkable action to the tracer.
//! The action is used to determine whether tracing is currently enabled by the user
void setActionEnableTracing( QAction* action ) { mActionEnableTracing = action; }

//! Retrieve instance of this class associated with given canvas (if any).
//! The class keeps a simple registry of tracers associated with map canvas
Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgsmaptoolcapture.cpp
Expand Up @@ -139,7 +139,7 @@ void QgsMapToolCapture::currentLayerChanged( QgsMapLayer *layer )
bool QgsMapToolCapture::tracingEnabled()
{
QgsMapCanvasTracer* tracer = QgsMapCanvasTracer::tracerForCanvas( mCanvas );
return tracer && tracer->actionEnableTracing()->isChecked();
return tracer && tracer->actionEnableTracing() && tracer->actionEnableTracing()->isChecked();
}


Expand Down
16 changes: 16 additions & 0 deletions src/ui/qgisapp.ui
Expand Up @@ -381,6 +381,7 @@
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
<addaction name="mActionEnableTracing"/>
<addaction name="mActionUndo"/>
<addaction name="mActionRedo"/>
<addaction name="mActionRotateFeature"/>
Expand Down Expand Up @@ -2398,6 +2399,21 @@ Acts on currently active editable layer</string>
<string>Report an issue</string>
</property>
</action>
<action name="mActionEnableTracing">
<property name="checkable">
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/mActionTracing.png</normaloff>:/images/themes/default/mActionTracing.png</iconset>
</property>
<property name="text">
<string>Enable Tracing</string>
</property>
<property name="shortcut">
<string>T</string>
</property>
</action>
</widget>
<resources>
<include location="../../images/images.qrc"/>
Expand Down

0 comments on commit 7a5df7a

Please sign in to comment.