Skip to content

Commit

Permalink
Add advanced digitizing tools registry
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn committed Jul 28, 2024
1 parent 244d784 commit 36ad5f9
Show file tree
Hide file tree
Showing 14 changed files with 514 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/qgsadvanceddigitizingtoolsregistry.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/





class QgsAdvancedDigitizingToolAbstractMetadata
{
%Docstring(signature="appended")
Stores metadata about one advanced digitizing tool class.

.. versionadded:: 3.40
%End

%TypeHeaderCode
#include "qgsadvanceddigitizingtoolsregistry.h"
%End
public:

QgsAdvancedDigitizingToolAbstractMetadata( const QString &name, const QString &visibleName, const QIcon &icon = QIcon() );
%Docstring
Constructor for QgsAdvancedDigitizingToolAbstractMetadata with the specified tool ``name``.

``visibleName`` should be set to a translated, user visible name identifying the corresponding annotation item.

An optional ``icon`` can be set, which will be used by the advanced digitizing dock widget.
%End

virtual ~QgsAdvancedDigitizingToolAbstractMetadata();

QString name() const;
%Docstring
Returns the tool's unique name
%End

QString visibleName() const;
%Docstring
Returns the tool's translatable user-friendly name
%End

QIcon icon() const;
%Docstring
Returns the tool's icon
%End

virtual QgsAdvancedDigitizingTool *createTool( QgsMapCanvas *canvas, QgsAdvancedDigitizingDockWidget *cadDockWidget ) /Factory/;
%Docstring
Returns new tool of this type. Return ``None`` on error
%End

protected:
};


class QgsAdvancedDigitizingToolsRegistry
{
%Docstring(signature="appended")
Registry of available advanced digitizing tools.

.. versionadded:: 3.40
%End

%TypeHeaderCode
#include "qgsadvanceddigitizingtoolsregistry.h"
%End
public:

QgsAdvancedDigitizingToolsRegistry();
~QgsAdvancedDigitizingToolsRegistry();


void addDefaultTools();
%Docstring
Adds the default tools shipped in QGIS
%End

bool addTool( QgsAdvancedDigitizingToolAbstractMetadata *toolMetaData /Transfer/ );
%Docstring
Adds an advanced digitizing tool (take ownership) and return ``True`` on success
%End

bool removeTool( const QString &name );
%Docstring
Removes the advanced digitizing tool matching the provided ``name`` and return ``True`` on success
%End

QgsAdvancedDigitizingToolAbstractMetadata *toolMetadata( const QString &name );
%Docstring
Returns the advanced digitizing tool matching the provided ``name`` or ``None`` when no match available
%End

const QStringList toolMetadataNames() const;
%Docstring
Returns the list of registered tool names
%End

private:
QgsAdvancedDigitizingToolsRegistry( const QgsAdvancedDigitizingToolsRegistry &rh );
};

/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/qgsadvanceddigitizingtoolsregistry.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
7 changes: 7 additions & 0 deletions python/PyQt6/gui/auto_generated/qgsgui.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ Returns the global layout item GUI registry, used for registering the GUI behavi
Returns the global annotation item GUI registry, used for registering the GUI behavior of annotation items.

.. versionadded:: 3.22
%End

static QgsAdvancedDigitizingToolsRegistry *advancedDigitizingToolsRegistry() /KeepReference/;
%Docstring
Returns the global advanced digitizing tools registry, used for registering advanced digitizing tools.

.. versionadded:: 3.40
%End

static QgsProcessingGuiRegistry *processingGuiRegistry() /KeepReference/;
Expand Down
1 change: 1 addition & 0 deletions python/PyQt6/gui/gui_auto.sip
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
%Include auto_generated/qgsadvanceddigitizingdockwidget.sip
%Include auto_generated/qgsadvanceddigitizingfloater.sip
%Include auto_generated/qgsadvanceddigitizingtools.sip
%Include auto_generated/qgsadvanceddigitizingtoolsregistry.sip
%Include auto_generated/qgsaggregatetoolbutton.sip
%Include auto_generated/qgsalignmentcombobox.sip
%Include auto_generated/qgsapplicationexitblockerinterface.sip
Expand Down
113 changes: 113 additions & 0 deletions python/gui/auto_generated/qgsadvanceddigitizingtoolsregistry.sip.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/qgsadvanceddigitizingtoolsregistry.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/





class QgsAdvancedDigitizingToolAbstractMetadata
{
%Docstring(signature="appended")
Stores metadata about one advanced digitizing tool class.

.. versionadded:: 3.40
%End

%TypeHeaderCode
#include "qgsadvanceddigitizingtoolsregistry.h"
%End
public:

QgsAdvancedDigitizingToolAbstractMetadata( const QString &name, const QString &visibleName, const QIcon &icon = QIcon() );
%Docstring
Constructor for QgsAdvancedDigitizingToolAbstractMetadata with the specified tool ``name``.

``visibleName`` should be set to a translated, user visible name identifying the corresponding annotation item.

An optional ``icon`` can be set, which will be used by the advanced digitizing dock widget.
%End

virtual ~QgsAdvancedDigitizingToolAbstractMetadata();

QString name() const;
%Docstring
Returns the tool's unique name
%End

QString visibleName() const;
%Docstring
Returns the tool's translatable user-friendly name
%End

QIcon icon() const;
%Docstring
Returns the tool's icon
%End

virtual QgsAdvancedDigitizingTool *createTool( QgsMapCanvas *canvas, QgsAdvancedDigitizingDockWidget *cadDockWidget ) /Factory/;
%Docstring
Returns new tool of this type. Return ``None`` on error
%End

protected:
};


class QgsAdvancedDigitizingToolsRegistry
{
%Docstring(signature="appended")
Registry of available advanced digitizing tools.

.. versionadded:: 3.40
%End

%TypeHeaderCode
#include "qgsadvanceddigitizingtoolsregistry.h"
%End
public:

QgsAdvancedDigitizingToolsRegistry();
~QgsAdvancedDigitizingToolsRegistry();


void addDefaultTools();
%Docstring
Adds the default tools shipped in QGIS
%End

bool addTool( QgsAdvancedDigitizingToolAbstractMetadata *toolMetaData /Transfer/ );
%Docstring
Adds an advanced digitizing tool (take ownership) and return ``True`` on success
%End

bool removeTool( const QString &name );
%Docstring
Removes the advanced digitizing tool matching the provided ``name`` and return ``True`` on success
%End

QgsAdvancedDigitizingToolAbstractMetadata *toolMetadata( const QString &name );
%Docstring
Returns the advanced digitizing tool matching the provided ``name`` or ``None`` when no match available
%End

const QStringList toolMetadataNames() const;
%Docstring
Returns the list of registered tool names
%End

private:
QgsAdvancedDigitizingToolsRegistry( const QgsAdvancedDigitizingToolsRegistry &rh );
};

/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/qgsadvanceddigitizingtoolsregistry.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
7 changes: 7 additions & 0 deletions python/gui/auto_generated/qgsgui.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ Returns the global layout item GUI registry, used for registering the GUI behavi
Returns the global annotation item GUI registry, used for registering the GUI behavior of annotation items.

.. versionadded:: 3.22
%End

static QgsAdvancedDigitizingToolsRegistry *advancedDigitizingToolsRegistry() /KeepReference/;
%Docstring
Returns the global advanced digitizing tools registry, used for registering advanced digitizing tools.

.. versionadded:: 3.40
%End

static QgsProcessingGuiRegistry *processingGuiRegistry() /KeepReference/;
Expand Down
1 change: 1 addition & 0 deletions python/gui/gui_auto.sip
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
%Include auto_generated/qgsadvanceddigitizingdockwidget.sip
%Include auto_generated/qgsadvanceddigitizingfloater.sip
%Include auto_generated/qgsadvanceddigitizingtools.sip
%Include auto_generated/qgsadvanceddigitizingtoolsregistry.sip
%Include auto_generated/qgsaggregatetoolbutton.sip
%Include auto_generated/qgsalignmentcombobox.sip
%Include auto_generated/qgsapplicationexitblockerinterface.sip
Expand Down
2 changes: 2 additions & 0 deletions src/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,7 @@ set(QGIS_GUI_SRCS
qgsadvanceddigitizingdockwidget.cpp
qgsadvanceddigitizingfloater.cpp
qgsadvanceddigitizingtools.cpp
qgsadvanceddigitizingtoolsregistry.cpp
qgsaggregatetoolbutton.cpp
qgsalignmentcombobox.cpp
qgsapplicationexitblockerinterface.cpp
Expand Down Expand Up @@ -792,6 +793,7 @@ set(QGIS_GUI_HDRS
qgsadvanceddigitizingdockwidget.h
qgsadvanceddigitizingfloater.h
qgsadvanceddigitizingtools.h
qgsadvanceddigitizingtoolsregistry.h
qgsaggregatetoolbutton.h
qgsalignmentcombobox.h
qgsapplicationexitblockerinterface.h
Expand Down
38 changes: 20 additions & 18 deletions src/gui/qgsadvanceddigitizingdockwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@
#include "qgsadvanceddigitizingdockwidget.h"
#include "qgsadvanceddigitizingfloater.h"
#include "qgsadvanceddigitizingcanvasitem.h"
#include "qgsadvanceddigitizingtoolsregistry.h"
#include "qgsbearingnumericformat.h"
#include "qgscadutils.h"
#include "qgsexpression.h"
#include "qgsgui.h"
#include "qgsmapcanvas.h"
#include "qgsmaptooledit.h"
#include "qgsmaptooladvanceddigitizing.h"
Expand Down Expand Up @@ -98,7 +100,6 @@ QgsAdvancedDigitizingDockWidget::QgsAdvancedDigitizingDockWidget( QgsMapCanvas *
connect( mConstructionModeAction, &QAction::triggered, this, &QgsAdvancedDigitizingDockWidget::setConstructionMode );
connect( mParallelAction, &QAction::triggered, this, &QgsAdvancedDigitizingDockWidget::betweenLineConstraintClicked );
connect( mPerpendicularAction, &QAction::triggered, this, &QgsAdvancedDigitizingDockWidget::betweenLineConstraintClicked );
connect( mCirclesIntersectionAction, &QAction::triggered, this, &QgsAdvancedDigitizingDockWidget::circlesIntersectionClicked );
connect( mLockAngleButton, &QAbstractButton::clicked, this, &QgsAdvancedDigitizingDockWidget::lockConstraint );
connect( mLockDistanceButton, &QAbstractButton::clicked, this, &QgsAdvancedDigitizingDockWidget::lockConstraint );
connect( mLockXButton, &QAbstractButton::clicked, this, &QgsAdvancedDigitizingDockWidget::lockConstraint );
Expand Down Expand Up @@ -239,6 +240,22 @@ QgsAdvancedDigitizingDockWidget::QgsAdvancedDigitizingDockWidget( QgsMapCanvas *
constructionModeToolButton->setMenu( constructionSettingsMenu );
constructionModeToolButton->setObjectName( QStringLiteral( "ConstructionModeButton" ) );

// Tools
QMenu *toolsMenu = new QMenu( this );
const QStringList toolMetadataNames = QgsGui::instance()->advancedDigitizingToolsRegistry()->toolMetadataNames();
for ( const QString &name : toolMetadataNames )
{
QgsAdvancedDigitizingToolAbstractMetadata *toolMetadata = QgsGui::instance()->advancedDigitizingToolsRegistry()->toolMetadata( name );
QAction *toolAction = new QAction( toolMetadata->icon(), toolMetadata->visibleName(), this );
connect( toolAction, &QAction::triggered, this, [ = ]()
{
setTool( toolMetadata->createTool( mMapCanvas, this ) );
} );
toolsMenu->addAction( toolAction );
}
qobject_cast< QToolButton *>( mToolbar->widgetForAction( mToolsAction ) )->setPopupMode( QToolButton::InstantPopup );
mToolsAction->setMenu( toolsMenu );

qobject_cast< QToolButton *>( mToolbar->widgetForAction( mSettingsAction ) )->setPopupMode( QToolButton::InstantPopup );
mSettingsAction->setMenu( mCommonAngleActionsMenu );
mSettingsAction->setCheckable( true );
Expand Down Expand Up @@ -546,7 +563,7 @@ void QgsAdvancedDigitizingDockWidget::setCadEnabled( bool enabled )
mInputWidgets->setEnabled( enabled );
mFloaterAction->setEnabled( enabled );
mConstructionAction->setEnabled( enabled );
mCirclesIntersectionAction->setEnabled( enabled );
mToolsAction->setEnabled( enabled );

if ( !enabled )
{
Expand Down Expand Up @@ -667,6 +684,7 @@ void QgsAdvancedDigitizingDockWidget::setTool( QgsAdvancedDigitizingTool *tool )
mCurrentTool = nullptr;
}

qDebug() << mCurrentTool;
mCurrentTool = tool;

if ( mCurrentTool )
Expand All @@ -681,22 +699,6 @@ QgsAdvancedDigitizingTool *QgsAdvancedDigitizingDockWidget::tool() const
return mCurrentTool.data();
}

void QgsAdvancedDigitizingDockWidget::circlesIntersectionClicked()
{
if ( mCurrentTool && dynamic_cast<QgsAdvancedDigitizingCirclesIntersectionTool *>( mCurrentTool.data() ) )
{
setTool( nullptr );
mCirclesIntersectionAction->setChecked( false );
}
else
{
QgsAdvancedDigitizingCirclesIntersectionTool *circlesIntersectionTool = new QgsAdvancedDigitizingCirclesIntersectionTool( mMapCanvas, this );
connect( circlesIntersectionTool, &QObject::destroyed, this, [ = ] { mCirclesIntersectionAction->setChecked( false ); } );
setTool( circlesIntersectionTool );
mCirclesIntersectionAction->setChecked( true );
}
}

void QgsAdvancedDigitizingDockWidget::betweenLineConstraintClicked( bool activated )
{
if ( !activated )
Expand Down
3 changes: 0 additions & 3 deletions src/gui/qgsadvanceddigitizingdockwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -981,9 +981,6 @@ class GUI_EXPORT QgsAdvancedDigitizingDockWidget : public QgsDockWidget, private
//! Sets the between line constraint by clicking on the perpendicular/parallel buttons
void betweenLineConstraintClicked( bool activated );

//! Activate the circles intersection tool
void circlesIntersectionClicked();

//! lock/unlock a constraint and set its value
void lockConstraint( bool activate = true );

Expand Down
Loading

0 comments on commit 36ad5f9

Please sign in to comment.