Skip to content
Permalink
Browse files

Move tracing action creation to qgis app

  • Loading branch information
wonder-sk committed Jan 19, 2016
1 parent f4bdaad commit 7a5df7ada69ab9fe033355c99e35aa4452f16ebc
@@ -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
@@ -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
@@ -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()
@@ -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 );
@@ -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 )
@@ -17,6 +17,7 @@ QgsMapCanvasTracer::QgsMapCanvasTracer( QgsMapCanvas* canvas, QgsMessageBar* mes
: mCanvas( canvas )
, mMessageBar( messageBar )
, mLastMessage( nullptr )
, mActionEnableTracing( nullptr )
{
sTracers.insert( canvas, this );

@@ -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() );
@@ -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
@@ -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
@@ -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();
}


@@ -381,6 +381,7 @@
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
<addaction name="mActionEnableTracing"/>
<addaction name="mActionUndo"/>
<addaction name="mActionRedo"/>
<addaction name="mActionRotateFeature"/>
@@ -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"/>

0 comments on commit 7a5df7a

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