Skip to content

Commit

Permalink
adapt QgsMapToolCapture to correctly support shape map tools
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids committed Jan 28, 2022
1 parent 55e8819 commit 0aed1cc
Show file tree
Hide file tree
Showing 7 changed files with 370 additions and 149 deletions.
128 changes: 96 additions & 32 deletions src/gui/qgisinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -610,38 +610,102 @@ class GUI_EXPORT QgisInterface : public QObject
virtual QAction *actionAbout() = 0;

// Shape digitize actions
//! Returns the native add circle from 2 points action. Call trigger() on it to set the map tool.
virtual QAction *actionCircle2Points() = 0;
//! Returns the native add circle from 3 points action. Call trigger() on it to set the map tool.
virtual QAction *actionCircle3Points() = 0;
//! Returns the native add circle from 3 tangents action. Call trigger() on it to set the map tool.
virtual QAction *actionCircle3Tangents() = 0;
//! Returns the native add circle from 2 tangents and a point action. Call trigger() on it to set the map tool.
virtual QAction *actionCircle2TangentsPoint() = 0;
//! Returns the native add circle from center action. Call trigger() on it to set the map tool.
virtual QAction *actionCircleCenterPoint() = 0;
//! Returns the native add ellipse from center and 2 points action. Call trigger() on it to set the map tool.
virtual QAction *actionEllipseCenter2Points() = 0;
//! Returns the native add ellipse from center and a point action. Call trigger() on it to set the map tool.
virtual QAction *actionEllipseCenterPoint() = 0;
//! Returns the native add ellipse from an extent action. Call trigger() on it to set the map tool.
virtual QAction *actionEllipseExtent() = 0;
//! Returns the native add ellipse from foci action. Call trigger() on it to set the map tool.
virtual QAction *actionEllipseFoci() = 0;
//! Returns the native add rectangle from center and a point action. Call trigger() on it to set the map tool.
virtual QAction *actionRectangleCenterPoint() = 0;
//! Returns the native add rectangle from extent action. Call trigger() on it to set the map tool.
virtual QAction *actionRectangleExtent() = 0;
//! Returns the native add rectangle from 3 points (distance from 2nd and 3rd points) action. Call trigger() on it to set the map tool.
virtual QAction *actionRectangle3PointsDistance() = 0;
//! Returns the native add rectangle from 3 points (distance from projected 3rd point on segment p1 and p2) action. Call trigger() on it to set the map tool.
virtual QAction *actionRectangle3PointsProjected() = 0;
//! Returns the native add regular polygon from 2 points action. Call trigger() on it to set the map tool.
virtual QAction *actionRegularPolygon2Points() = 0;
//! Returns the native add regular polygon from center and a point action. Call trigger() on it to set the map tool.
virtual QAction *actionRegularPolygonCenterPoint() = 0;
//! Returns the native add regular polygon from center and a corner action. Call trigger() on it to set the map tool.
virtual QAction *actionRegularPolygonCenterCorner() = 0;

/**
* Returns the native add circle from 2 points action. Call trigger() on it to set the map tool.
* \deprecated since QGIS 3.24 shape digitizing is now part of the add feature tool
*/
Q_DECL_DEPRECATED virtual QAction *actionCircle2Points() SIP_DEPRECATED {return actionAddFeature();}

/**
* Returns the native add circle from 3 points action. Call trigger() on it to set the map tool.
* \deprecated since QGIS 3.24 shape digitizing is now part of the add feature tool
*/
Q_DECL_DEPRECATED virtual QAction *actionCircle3Points() SIP_DEPRECATED {return actionAddFeature();}

/**
* Returns the native add circle from 3 tangents action. Call trigger() on it to set the map tool.
* \deprecated since QGIS 3.24 shape digitizing is now part of the add feature tool
*/
Q_DECL_DEPRECATED virtual QAction *actionCircle3Tangents() SIP_DEPRECATED {return actionAddFeature();}

/**
* Returns the native add circle from 2 tangents and a point action. Call trigger() on it to set the map tool.
* \deprecated since QGIS 3.24 shape digitizing is now part of the add feature tool
*/
Q_DECL_DEPRECATED virtual QAction *actionCircle2TangentsPoint() SIP_DEPRECATED {return actionAddFeature();}

/**
* Returns the native add circle from center action. Call trigger() on it to set the map tool.
* \deprecated since QGIS 3.24 shape digitizing is now part of the add feature tool
*/
Q_DECL_DEPRECATED virtual QAction *actionCircleCenterPoint() SIP_DEPRECATED {return actionAddFeature();}

/**
* Returns the native add ellipse from center and 2 points action. Call trigger() on it to set the map tool.
* \deprecated since QGIS 3.24 shape digitizing is now part of the add feature tool
*/
Q_DECL_DEPRECATED virtual QAction *actionEllipseCenter2Points() SIP_DEPRECATED {return actionAddFeature();}

/**
* Returns the native add ellipse from center and a point action. Call trigger() on it to set the map tool.
* \deprecated since QGIS 3.24 shape digitizing is now part of the add feature tool
*/
Q_DECL_DEPRECATED virtual QAction *actionEllipseCenterPoint() SIP_DEPRECATED {return actionAddFeature();}

/**
* Returns the native add ellipse from an extent action. Call trigger() on it to set the map tool.
* \deprecated since QGIS 3.24 shape digitizing is now part of the add feature tool
*/
Q_DECL_DEPRECATED virtual QAction *actionEllipseExtent() SIP_DEPRECATED {return actionAddFeature();}

/**
* Returns the native add ellipse from foci action. Call trigger() on it to set the map tool.
* \deprecated since QGIS 3.24 shape digitizing is now part of the add feature tool
*/
Q_DECL_DEPRECATED virtual QAction *actionEllipseFoci() SIP_DEPRECATED {return actionAddFeature();}

/**
* Returns the native add rectangle from center and a point action. Call trigger() on it to set the map tool.
* \deprecated since QGIS 3.24 shape digitizing is now part of the add feature tool
*/
Q_DECL_DEPRECATED virtual QAction *actionRectangleCenterPoint() SIP_DEPRECATED {return actionAddFeature();}

/**
* Returns the native add rectangle from extent action. Call trigger() on it to set the map tool.
* \deprecated since QGIS 3.24 shape digitizing is now part of the add feature tool
*/
Q_DECL_DEPRECATED virtual QAction *actionRectangleExtent() SIP_DEPRECATED {return actionAddFeature();}

/**
* Returns the native add rectangle from 3 points (distance from 2nd and 3rd points) action. Call trigger() on it to set the map tool.
* \deprecated since QGIS 3.24 shape digitizing is now part of the add feature tool
*/
Q_DECL_DEPRECATED virtual QAction *actionRectangle3PointsDistance() SIP_DEPRECATED {return actionAddFeature();}

/**
* Returns the native add rectangle from 3 points (distance from projected 3rd point on segment p1 and p2) action. Call trigger() on it to set the map tool.
* \deprecated since QGIS 3.24 shape digitizing is now part of the add feature tool
*/
Q_DECL_DEPRECATED virtual QAction *actionRectangle3PointsProjected() SIP_DEPRECATED {return actionAddFeature();}

/**
* Returns the native add regular polygon from 2 points action. Call trigger() on it to set the map tool.
* \deprecated since QGIS 3.24 shape digitizing is now part of the add feature tool
*/
Q_DECL_DEPRECATED virtual QAction *actionRegularPolygon2Points() SIP_DEPRECATED {return actionAddFeature();}

/**
* Returns the native add regular polygon from center and a point action. Call trigger() on it to set the map tool.
* \deprecated since QGIS 3.24 shape digitizing is now part of the add feature tool
*/
Q_DECL_DEPRECATED virtual QAction *actionRegularPolygonCenterPoint() SIP_DEPRECATED {return actionAddFeature();}

/**
* Returns the native add regular polygon from center and a corner action. Call trigger() on it to set the map tool.
* \deprecated since QGIS 3.24 shape digitizing is now part of the add feature tool
*/
Q_DECL_DEPRECATED virtual QAction *actionRegularPolygonCenterCorner() SIP_DEPRECATED {return actionAddFeature();}

/**
* Access the vector layer tools instance.
Expand Down
8 changes: 8 additions & 0 deletions src/gui/qgsgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
#include "qgssubsetstringeditorproviderregistry.h"
#include "qgsprovidersourcewidgetproviderregistry.h"
#include "qgsrelationwidgetregistry.h"
#include "qgsmaptoolshaperegistry.h"
#include "qgssettingsregistrygui.h"
#include "qgshistoryproviderregistry.h"

Expand Down Expand Up @@ -91,6 +92,11 @@ QgsRelationWidgetRegistry *QgsGui::relationWidgetRegistry()
return instance()->mRelationEditorRegistry;
}

QgsMapToolShapeRegistry *QgsGui::mapToolShapeRegistry()
{
return instance()->mShapeMapToolRegistry;
}

QgsSourceSelectProviderRegistry *QgsGui::sourceSelectProviderRegistry()
{
return instance()->mSourceSelectProviderRegistry;
Expand Down Expand Up @@ -223,6 +229,7 @@ QgsGui::~QgsGui()
delete mCodeEditorColorSchemeRegistry;
delete mSubsetStringEditorProviderRegistry;
delete mProviderSourceWidgetProviderRegistry;
delete mShapeMapToolRegistry;
delete mRelationEditorRegistry;
delete mSettingsRegistryGui;
}
Expand Down Expand Up @@ -294,6 +301,7 @@ QgsGui::QgsGui()

mEditorWidgetRegistry = new QgsEditorWidgetRegistry();
mRelationEditorRegistry = new QgsRelationWidgetRegistry();
mShapeMapToolRegistry = new QgsMapToolShapeRegistry();
mShortcutsManager = new QgsShortcutsManager();
mLayerTreeEmbeddedWidgetRegistry = new QgsLayerTreeEmbeddedWidgetRegistry();
mMapLayerActionRegistry = new QgsMapLayerActionRegistry();
Expand Down
7 changes: 7 additions & 0 deletions src/gui/qgsgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class QgsMessageBar;
class QgsSubsetStringEditorProviderRegistry;
class QgsProviderSourceWidgetProviderRegistry;
class QgsRelationWidgetRegistry;
class QgsMapToolShapeRegistry;
class QgsHistoryProviderRegistry;

/**
Expand Down Expand Up @@ -191,6 +192,11 @@ class GUI_EXPORT QgsGui : public QObject
*/
static QgsRelationWidgetRegistry *relationWidgetRegistry() SIP_KEEPREFERENCE;

/**
* Returns the registry of shape map tools
* \since QGIS 3.24
*/
static QgsMapToolShapeRegistry *mapToolShapeRegistry() SIP_SKIP;

/**
* Returns the global history provider registry, used for tracking history providers.
Expand Down Expand Up @@ -304,6 +310,7 @@ class GUI_EXPORT QgsGui : public QObject
QgsSubsetStringEditorProviderRegistry *mSubsetStringEditorProviderRegistry = nullptr;
QgsProviderSourceWidgetProviderRegistry *mProviderSourceWidgetProviderRegistry = nullptr;
QgsRelationWidgetRegistry *mRelationEditorRegistry = nullptr;
QgsMapToolShapeRegistry *mShapeMapToolRegistry = nullptr;
QgsHistoryProviderRegistry *mHistoryProviderRegistry = nullptr;
std::unique_ptr< QgsWindowManagerInterface > mWindowManager;

Expand Down
6 changes: 3 additions & 3 deletions src/gui/qgsmaptool.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,9 @@ class GUI_EXPORT QgsMapTool : public QObject
*/
virtual bool populateContextMenuWithEvent( QMenu *menu, QgsMapMouseEvent *event );

//! Transforms a \a point from screen coordinates to map coordinates.
QgsPointXY toMapCoordinates( QPoint point );

signals:
//! emit a message
void messageEmitted( const QString &message, Qgis::MessageLevel = Qgis::MessageLevel::Info );
Expand All @@ -283,9 +286,6 @@ class GUI_EXPORT QgsMapTool : public QObject
//! Constructor takes a map canvas as a parameter.
QgsMapTool( QgsMapCanvas *canvas SIP_TRANSFERTHIS );

//! Transforms a \a point from screen coordinates to map coordinates.
QgsPointXY toMapCoordinates( QPoint point );

/**
* Transforms a \a point from map coordinates to \a layer coordinates.
* \note This method is available in the Python bindings as toLayerCoordinatesV2.
Expand Down

0 comments on commit 0aed1cc

Please sign in to comment.