Skip to content

Commit 7a5df7a

Browse files
committedJan 19, 2016
Move tracing action creation to qgis app
1 parent f4bdaad commit 7a5df7a

File tree

6 files changed

+36
-13
lines changed

6 files changed

+36
-13
lines changed
 

‎python/gui/qgsmapcanvastracer.sip

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* Extension of QgsTracer that provides extra functionality:
33
* - automatic updates of own configuration based on canvas settings
44
* - reporting of issues to the user via message bar
5+
* - determines whether tracing is currently enabled by the user
56
*
67
* A simple registry of tracer instances associated to map canvas instances
78
* is kept for convenience. (Map tools do not need to create their local
@@ -21,8 +22,12 @@ class QgsMapCanvasTracer : QgsTracer
2122
explicit QgsMapCanvasTracer( QgsMapCanvas* canvas, QgsMessageBar* messageBar = 0 );
2223
~QgsMapCanvasTracer();
2324

24-
//! Access to action that user may use to toggle tracing on/off
25-
QAction* actionEnableTracing();
25+
//! Access to action that user may use to toggle tracing on/off. May be null if no action was associated
26+
QAction* actionEnableTracing() const;
27+
28+
//! Assign "enable tracing" checkable action to the tracer.
29+
//! The action is used to determine whether tracing is currently enabled by the user
30+
void setActionEnableTracing( QAction* action );
2631

2732
//! Retrieve instance of this class associated with given canvas (if any).
2833
//! The class keeps a simple registry of tracers associated with map canvas

‎src/app/qgisapp.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1981,10 +1981,10 @@ void QgisApp::createToolBars()
19811981
mDigitizeToolBar->insertWidget( mActionMoveFeature, tbAddCircularString );
19821982

19831983
// Cad toolbar
1984-
mAdvancedDigitizeToolBar->insertAction( mActionUndo, mAdvancedDigitizingDockWidget->enableAction() );
1984+
mAdvancedDigitizeToolBar->insertAction( mActionEnableTracing, mAdvancedDigitizingDockWidget->enableAction() );
19851985

19861986
mTracer = new QgsMapCanvasTracer( mMapCanvas, messageBar() );
1987-
mAdvancedDigitizeToolBar->insertAction( mActionUndo, mTracer->actionEnableTracing() );
1987+
mTracer->setActionEnableTracing( mActionEnableTracing );
19881988
}
19891989

19901990
void QgisApp::createStatusBar()
@@ -9739,7 +9739,7 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
97399739
mActionMergeFeatures->setEnabled( false );
97409740
mActionMergeFeatureAttributes->setEnabled( false );
97419741
mActionRotatePointSymbols->setEnabled( false );
9742-
mTracer->actionEnableTracing()->setEnabled( false );
9742+
mActionEnableTracing->setEnabled( false );
97439743

97449744
mActionPinLabels->setEnabled( false );
97459745
mActionShowHideLabels->setEnabled( false );
@@ -9860,7 +9860,7 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
98609860
mActionRotateFeature->setEnabled( isEditable && canChangeGeometry );
98619861
mActionNodeTool->setEnabled( isEditable && canChangeGeometry );
98629862

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

98669866
if ( vlayer->geometryType() == QGis::Point )

‎src/gui/qgsmapcanvastracer.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ QgsMapCanvasTracer::QgsMapCanvasTracer( QgsMapCanvas* canvas, QgsMessageBar* mes
1717
: mCanvas( canvas )
1818
, mMessageBar( messageBar )
1919
, mLastMessage( nullptr )
20+
, mActionEnableTracing( nullptr )
2021
{
2122
sTracers.insert( canvas, this );
2223

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

30-
mActionEnableTracing = new QAction( QIcon( QgsApplication::getThemeIcon( "/mActionTracing.png" ) ), tr( "Enable Tracing" ), this );
31-
mActionEnableTracing->setShortcut( Qt::Key_T );
32-
mActionEnableTracing->setCheckable( true );
33-
3431
// arbitrarily chosen limit that should allow for fairly fast initialization
3532
// of the underlying graph structure
3633
setMaxFeatureCount( QSettings().value( "/qgis/digitizing/tracing_max_feature_count", 10000 ).toInt() );

‎src/gui/qgsmapcanvastracer.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class QgsMessageBarItem;
1212
* Extension of QgsTracer that provides extra functionality:
1313
* - automatic updates of own configuration based on canvas settings
1414
* - reporting of issues to the user via message bar
15+
* - determines whether tracing is currently enabled by the user
1516
*
1617
* A simple registry of tracer instances associated to map canvas instances
1718
* is kept for convenience. (Map tools do not need to create their local
@@ -29,8 +30,12 @@ class GUI_EXPORT QgsMapCanvasTracer : public QgsTracer
2930
explicit QgsMapCanvasTracer( QgsMapCanvas* canvas, QgsMessageBar* messageBar = 0 );
3031
~QgsMapCanvasTracer();
3132

32-
//! Access to action that user may use to toggle tracing on/off
33-
QAction* actionEnableTracing() { return mActionEnableTracing; }
33+
//! Access to action that user may use to toggle tracing on/off. May be null if no action was associated
34+
QAction* actionEnableTracing() const { return mActionEnableTracing; }
35+
36+
//! Assign "enable tracing" checkable action to the tracer.
37+
//! The action is used to determine whether tracing is currently enabled by the user
38+
void setActionEnableTracing( QAction* action ) { mActionEnableTracing = action; }
3439

3540
//! Retrieve instance of this class associated with given canvas (if any).
3641
//! The class keeps a simple registry of tracers associated with map canvas

‎src/gui/qgsmaptoolcapture.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ void QgsMapToolCapture::currentLayerChanged( QgsMapLayer *layer )
139139
bool QgsMapToolCapture::tracingEnabled()
140140
{
141141
QgsMapCanvasTracer* tracer = QgsMapCanvasTracer::tracerForCanvas( mCanvas );
142-
return tracer && tracer->actionEnableTracing()->isChecked();
142+
return tracer && tracer->actionEnableTracing() && tracer->actionEnableTracing()->isChecked();
143143
}
144144

145145

‎src/ui/qgisapp.ui

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@
381381
<attribute name="toolBarBreak">
382382
<bool>false</bool>
383383
</attribute>
384+
<addaction name="mActionEnableTracing"/>
384385
<addaction name="mActionUndo"/>
385386
<addaction name="mActionRedo"/>
386387
<addaction name="mActionRotateFeature"/>
@@ -2398,6 +2399,21 @@ Acts on currently active editable layer</string>
23982399
<string>Report an issue</string>
23992400
</property>
24002401
</action>
2402+
<action name="mActionEnableTracing">
2403+
<property name="checkable">
2404+
<bool>true</bool>
2405+
</property>
2406+
<property name="icon">
2407+
<iconset resource="../../images/images.qrc">
2408+
<normaloff>:/images/themes/default/mActionTracing.png</normaloff>:/images/themes/default/mActionTracing.png</iconset>
2409+
</property>
2410+
<property name="text">
2411+
<string>Enable Tracing</string>
2412+
</property>
2413+
<property name="shortcut">
2414+
<string>T</string>
2415+
</property>
2416+
</action>
24012417
</widget>
24022418
<resources>
24032419
<include location="../../images/images.qrc"/>

0 commit comments

Comments
 (0)