Skip to content

Commit

Permalink
Enable streaming/curve digitizing modes also for polygon/line annotation
Browse files Browse the repository at this point in the history
item creation
  • Loading branch information
nyalldawson committed Sep 8, 2021
1 parent 0464eec commit 6a7f882
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 10 deletions.
40 changes: 31 additions & 9 deletions src/app/qgisapp.cpp
Expand Up @@ -802,10 +802,19 @@ void QgisApp::annotationItemTypeAdded( int id )
mAnnotationsToolBar->addAction( action );
}

connect( action, &QAction::triggered, this, [this, id]()
connect( action, &QAction::toggled, this, [this, action, id]( bool checked )
{
if ( !checked )
return;

QgsCreateAnnotationItemMapToolInterface *tool = QgsGui::annotationItemGuiRegistry()->itemMetadata( id )->createMapTool( mMapCanvas, mAdvancedDigitizingDockWidget );
tool->mapTool()->setAction( action );
mMapCanvas->setMapTool( tool->mapTool() );
if ( qobject_cast< QgsMapToolCapture * >( tool->mapTool() ) )
{
enableDigitizeTechniqueActions( checked, action );
}

connect( tool->mapTool(), &QgsMapTool::deactivated, tool->mapTool(), &QObject::deleteLater );
connect( tool->handler(), &QgsCreateAnnotationItemMapToolHandler::itemCreated, this, [ = ]
{
Expand Down Expand Up @@ -3122,6 +3131,7 @@ void QgisApp::createActionGroups()
mMapToolGroup->addAction( mActionChangeLabelProperties );
mMapToolGroup->addAction( mActionReverseLine );
mMapToolGroup->addAction( mActionTrimExtendFeature );
mMapToolGroup->addAction( mActionModifyAnnotation );

//
// Preview Modes Group
Expand Down Expand Up @@ -10290,8 +10300,8 @@ void QgisApp::enableDigitizeWithCurve( bool enable )
QgsSettings().setValue( QStringLiteral( "UI/digitizeTechnique" ), 0 );
}

const QList< QgsMapToolCapture * > captureTools = mMapTools->captureTools();
for ( QgsMapToolCapture *tool : captureTools )
const QList< QgsMapToolCapture * > tools = captureTools();
for ( QgsMapToolCapture *tool : tools )
{
if ( tool->supportsTechnique( QgsMapToolCapture::CircularString ) )
tool->setCircularDigitizingEnabled( enable );
Expand All @@ -10314,8 +10324,8 @@ void QgisApp::enableStreamDigitizing( bool enable )
QgsSettings().setValue( QStringLiteral( "UI/digitizeTechnique" ), 1 );
}

const QList< QgsMapToolCapture * > captureTools = mMapTools->captureTools();
for ( QgsMapToolCapture *tool : captureTools )
const QList< QgsMapToolCapture * > tools = captureTools();
for ( QgsMapToolCapture *tool : tools )
{
if ( tool->supportsTechnique( QgsMapToolCapture::Streaming ) )
tool->setStreamDigitizingEnabled( enable );
Expand All @@ -10331,10 +10341,10 @@ void QgisApp::enableDigitizeTechniqueActions( bool enable, QAction *triggeredFro

QgsSettings settings;

const QList< QgsMapToolCapture * > captureTools = mMapTools->captureTools();
const QList< QgsMapToolCapture * > tools = captureTools();

QSet< QgsMapToolCapture::CaptureTechnique > supportedTechniques;
for ( QgsMapToolCapture *tool : captureTools )
for ( QgsMapToolCapture *tool : tools )
{
if ( triggeredFromToolAction == tool->action() || ( !triggeredFromToolAction && mMapCanvas->mapTool() == tool ) )
{
Expand All @@ -10355,7 +10365,7 @@ void QgisApp::enableDigitizeTechniqueActions( bool enable, QAction *triggeredFro
const bool streamIsChecked = settings.value( QStringLiteral( "UI/digitizeWithStream" ) ).toInt();
mActionStreamDigitize->setChecked( streamIsChecked && mActionStreamDigitize->isEnabled() );

for ( QgsMapToolCapture *tool : captureTools )
for ( QgsMapToolCapture *tool : tools )
{
if ( tool->supportsTechnique( QgsMapToolCapture::CircularString ) )
tool->setCircularDigitizingEnabled( mActionDigitizeWithCurve->isChecked() );
Expand Down Expand Up @@ -11559,6 +11569,18 @@ void QgisApp::enableMeshEditingTools( bool enable )
}
}

QList<QgsMapToolCapture *> QgisApp::captureTools()
{
QList< QgsMapToolCapture * > res = mMapTools->captureTools();
// also check current tool, in case it's a custom tool
if ( QgsMapToolCapture *currentTool = qobject_cast< QgsMapToolCapture * >( mMapCanvas->mapTool() ) )
{
if ( !res.contains( currentTool ) )
res.append( currentTool );
}
return res;
}

void QgisApp::saveEdits()
{
const auto constSelectedLayers = mLayerTreeView->selectedLayers();
Expand Down Expand Up @@ -15825,7 +15847,7 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer *layer )
mActionLabeling->setEnabled( false );
mActionDiagramProperties->setEnabled( false );
mActionIdentify->setEnabled( true );
enableDigitizeTechniqueActions( false );
enableDigitizeTechniqueActions( true );
mActionToggleEditing->setEnabled( false );
mActionToggleEditing->setChecked( true ); // always editable
mActionUndo->setEnabled( false );
Expand Down
6 changes: 6 additions & 0 deletions src/app/qgisapp.h
Expand Up @@ -149,6 +149,8 @@ class QgsDevToolsPanelWidget;
class QgsDevToolWidgetFactory;
class QgsNetworkLogger;
class QgsNetworkLoggerWidgetFactory;
class QgsMapToolCapture;

#include <QMainWindow>
#include <QToolBar>
#include <QAbstractSocket>
Expand Down Expand Up @@ -2379,6 +2381,10 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
*/
void enableMeshEditingTools( bool enable );

/**
* Returns a list of all capture map tools.
*/
QList< QgsMapToolCapture * > captureTools();

QgisAppStyleSheet *mStyleSheetBuilder = nullptr;

Expand Down
5 changes: 5 additions & 0 deletions src/gui/annotations/qgscreateannotationitemmaptool_impl.cpp
Expand Up @@ -123,6 +123,11 @@ QgsMapToolCapture::Capabilities QgsMapToolCaptureAnnotationItem::capabilities()
return SupportsCurves;
}

bool QgsMapToolCaptureAnnotationItem::supportsTechnique( CaptureTechnique ) const
{
return true;
}


//
// QgsCreateLineMapTool
Expand Down
2 changes: 1 addition & 1 deletion src/gui/annotations/qgscreateannotationitemmaptool_impl.h
Expand Up @@ -69,7 +69,7 @@ class QgsMapToolCaptureAnnotationItem : public QgsMapToolCapture
QgsMapToolCaptureAnnotationItem( QgsMapCanvas *canvas, QgsAdvancedDigitizingDockWidget *cadDockWidget, CaptureMode mode );

QgsMapToolCapture::Capabilities capabilities() const override;

bool supportsTechnique( CaptureTechnique technique ) const override;

};

Expand Down

0 comments on commit 6a7f882

Please sign in to comment.