Skip to content

Commit

Permalink
Address review and add test
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn committed Jul 29, 2024
1 parent 36ad5f9 commit 8384b41
Show file tree
Hide file tree
Showing 15 changed files with 184 additions and 115 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -236,25 +236,19 @@ align to segment for between line constraint.
If between line constraints are used, this will determine the angle to be locked depending on the snapped segment.
%End

bool processCanvasPressEvent( QgsMapMouseEvent *event );
void processCanvasPressEvent( QgsMapMouseEvent *event );
%Docstring
Processes the canvas press ``event``.

:return: Returns ``True`` if the event has been 'eaten' and should not propagate further.
%End

bool processCanvasMoveEvent( QgsMapMouseEvent *event );
void processCanvasMoveEvent( QgsMapMouseEvent *event );
%Docstring
Processes the canvas move ``event``.

:return: Returns ``True`` if the event has been 'eaten' and should not propagate further.
%End

bool processCanvasReleaseEvent( QgsMapMouseEvent *event );
void processCanvasReleaseEvent( QgsMapMouseEvent *event );
%Docstring
Processes the canvas release ``event``.

:return: Returns ``True`` if the event has been 'eaten' and should not propagate further.
%End

void setTool( QgsAdvancedDigitizingTool *tool );
Expand Down
38 changes: 28 additions & 10 deletions python/PyQt6/gui/auto_generated/qgsadvanceddigitizingtools.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@



class QgsAdvancedDigitizingTool : QWidget
class QgsAdvancedDigitizingTool : QObject
{
%Docstring(signature="appended")
An abstract class for advanced digitizing tools.
Expand Down Expand Up @@ -42,27 +42,45 @@ Returns the map canvas associated with the tool.
Returns the advanced digitizing widget associated with the tool.
%End

virtual QWidget *createWidget();
%Docstring
Returns a widget to control the tool.

.. note::

The caller gets the ownership.
%End

virtual void paint( QPainter *painter );
%Docstring
Paints tool content onto the advanced digitizing canvas item.
%End

virtual bool canvasPressEvent( QgsMapMouseEvent *event );
virtual void canvasPressEvent( QgsMapMouseEvent *event );
%Docstring
Handles canvas press event. If ``True`` is returned, the tool will have
blocked the event for propagating.
Handles canvas press event.

.. note::

To stop propagation, set the event's accepted property to ``False``.
%End

virtual bool canvasMoveEvent( QgsMapMouseEvent *event );
virtual void canvasMoveEvent( QgsMapMouseEvent *event );
%Docstring
Handles canvas press move. If ``True`` is returned, the tool will have
blocked the event for propagating.
Handles canvas press move.

.. note::

To stop propagation, set the event's accepted property to ``False``.
%End

virtual bool canvasReleaseEvent( QgsMapMouseEvent *event );
virtual void canvasReleaseEvent( QgsMapMouseEvent *event );
%Docstring
Handles canvas release event. If ``True`` is returned, the tool will have
blocked the event for propagating.
Handles canvas release event.

.. note::

To stop propagation, set the event's accepted property to ``False``.
%End

signals:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ class QgsAdvancedDigitizingToolsRegistry
%Docstring(signature="appended")
Registry of available advanced digitizing tools.

:py:class:`QgsAdvancedDigitizingToolsRegistry` is not usually directly created, but rather accessed through
:py:func:`QgsGui.advancedDigitizingToolsRegistry()`.

.. versionadded:: 3.40
%End

Expand Down
12 changes: 3 additions & 9 deletions python/gui/auto_generated/qgsadvanceddigitizingdockwidget.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -236,25 +236,19 @@ align to segment for between line constraint.
If between line constraints are used, this will determine the angle to be locked depending on the snapped segment.
%End

bool processCanvasPressEvent( QgsMapMouseEvent *event );
void processCanvasPressEvent( QgsMapMouseEvent *event );
%Docstring
Processes the canvas press ``event``.

:return: Returns ``True`` if the event has been 'eaten' and should not propagate further.
%End

bool processCanvasMoveEvent( QgsMapMouseEvent *event );
void processCanvasMoveEvent( QgsMapMouseEvent *event );
%Docstring
Processes the canvas move ``event``.

:return: Returns ``True`` if the event has been 'eaten' and should not propagate further.
%End

bool processCanvasReleaseEvent( QgsMapMouseEvent *event );
void processCanvasReleaseEvent( QgsMapMouseEvent *event );
%Docstring
Processes the canvas release ``event``.

:return: Returns ``True`` if the event has been 'eaten' and should not propagate further.
%End

void setTool( QgsAdvancedDigitizingTool *tool );
Expand Down
38 changes: 28 additions & 10 deletions python/gui/auto_generated/qgsadvanceddigitizingtools.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@



class QgsAdvancedDigitizingTool : QWidget
class QgsAdvancedDigitizingTool : QObject
{
%Docstring(signature="appended")
An abstract class for advanced digitizing tools.
Expand Down Expand Up @@ -42,27 +42,45 @@ Returns the map canvas associated with the tool.
Returns the advanced digitizing widget associated with the tool.
%End

virtual QWidget *createWidget();
%Docstring
Returns a widget to control the tool.

.. note::

The caller gets the ownership.
%End

virtual void paint( QPainter *painter );
%Docstring
Paints tool content onto the advanced digitizing canvas item.
%End

virtual bool canvasPressEvent( QgsMapMouseEvent *event );
virtual void canvasPressEvent( QgsMapMouseEvent *event );
%Docstring
Handles canvas press event. If ``True`` is returned, the tool will have
blocked the event for propagating.
Handles canvas press event.

.. note::

To stop propagation, set the event's accepted property to ``False``.
%End

virtual bool canvasMoveEvent( QgsMapMouseEvent *event );
virtual void canvasMoveEvent( QgsMapMouseEvent *event );
%Docstring
Handles canvas press move. If ``True`` is returned, the tool will have
blocked the event for propagating.
Handles canvas press move.

.. note::

To stop propagation, set the event's accepted property to ``False``.
%End

virtual bool canvasReleaseEvent( QgsMapMouseEvent *event );
virtual void canvasReleaseEvent( QgsMapMouseEvent *event );
%Docstring
Handles canvas release event. If ``True`` is returned, the tool will have
blocked the event for propagating.
Handles canvas release event.

.. note::

To stop propagation, set the event's accepted property to ``False``.
%End

signals:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ class QgsAdvancedDigitizingToolsRegistry
%Docstring(signature="appended")
Registry of available advanced digitizing tools.

:py:class:`QgsAdvancedDigitizingToolsRegistry` is not usually directly created, but rather accessed through
:py:func:`QgsGui.advancedDigitizingToolsRegistry()`.

.. versionadded:: 3.40
%End

Expand Down
7 changes: 4 additions & 3 deletions src/gui/qgsadvanceddigitizingcanvasitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,11 @@ void QgsAdvancedDigitizingCanvasItem::paint( QPainter *painter )
}
}

// Draw current intersection tool
if ( mAdvancedDigitizingDockWidget->tool() )
// Draw current tool
if ( QgsAdvancedDigitizingTool *tool = mAdvancedDigitizingDockWidget->tool() )
{
mAdvancedDigitizingDockWidget->tool()->paint( painter );
// if a tool is active in the dock, then delegate to that tool to handle decorating the canvas instead of using the default decorations
tool->paint( painter );
return;
}

Expand Down
54 changes: 33 additions & 21 deletions src/gui/qgsadvanceddigitizingdockwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,17 +242,20 @@ QgsAdvancedDigitizingDockWidget::QgsAdvancedDigitizingDockWidget( QgsMapCanvas *

// Tools
QMenu *toolsMenu = new QMenu( this );
const QStringList toolMetadataNames = QgsGui::instance()->advancedDigitizingToolsRegistry()->toolMetadataNames();
for ( const QString &name : toolMetadataNames )
connect( toolsMenu, &QMenu::aboutToShow, this, [ = ]()
{
QgsAdvancedDigitizingToolAbstractMetadata *toolMetadata = QgsGui::instance()->advancedDigitizingToolsRegistry()->toolMetadata( name );
QAction *toolAction = new QAction( toolMetadata->icon(), toolMetadata->visibleName(), this );
connect( toolAction, &QAction::triggered, this, [ = ]()
const QStringList toolMetadataNames = QgsGui::instance()->advancedDigitizingToolsRegistry()->toolMetadataNames();
for ( const QString &name : toolMetadataNames )
{
setTool( toolMetadata->createTool( mMapCanvas, this ) );
} );
toolsMenu->addAction( toolAction );
}
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 );

Expand Down Expand Up @@ -684,12 +687,15 @@ void QgsAdvancedDigitizingDockWidget::setTool( QgsAdvancedDigitizingTool *tool )
mCurrentTool = nullptr;
}

qDebug() << mCurrentTool;
mCurrentTool = tool;

if ( mCurrentTool )
{
mUserInputWidget->addUserInputWidget( mCurrentTool.data() );
if ( QWidget *toolWidget = mCurrentTool->createWidget() )
{
toolWidget->setParent( mUserInputWidget );
mUserInputWidget->addUserInputWidget( toolWidget );
}
connect( mCurrentTool.data(), &QgsAdvancedDigitizingTool::paintRequested, this, &QgsAdvancedDigitizingDockWidget::updateCadPaintItem );
}
}
Expand Down Expand Up @@ -1547,17 +1553,20 @@ QList<QgsPointXY> QgsAdvancedDigitizingDockWidget::snapSegmentToAllLayers( const
return segment;
}

bool QgsAdvancedDigitizingDockWidget::processCanvasPressEvent( QgsMapMouseEvent *event )
void QgsAdvancedDigitizingDockWidget::processCanvasPressEvent( QgsMapMouseEvent *event )
{
if ( mCurrentTool )
{
mCurrentTool->canvasPressEvent( event );
}

return constructionMode();
if ( constructionMode() )
{
event->setAccepted( false );
}
}

bool QgsAdvancedDigitizingDockWidget::processCanvasMoveEvent( QgsMapMouseEvent *event )
void QgsAdvancedDigitizingDockWidget::processCanvasMoveEvent( QgsMapMouseEvent *event )
{
// perpendicular/parallel constraint
// do a soft lock when snapping to a segment
Expand All @@ -1569,22 +1578,22 @@ bool QgsAdvancedDigitizingDockWidget::processCanvasMoveEvent( QgsMapMouseEvent *
}

updateCadPaintItem();

return false;
}

bool QgsAdvancedDigitizingDockWidget::processCanvasReleaseEvent( QgsMapMouseEvent *event )
void QgsAdvancedDigitizingDockWidget::processCanvasReleaseEvent( QgsMapMouseEvent *event )
{
if ( alignToSegment( event ) )
{
return true;
event->setAccepted( false );
return;
}

if ( mCurrentTool )
{
if ( mCurrentTool->canvasReleaseEvent( event ) )
mCurrentTool->canvasReleaseEvent( event );
if ( !event->isAccepted() )
{
return true;
return;
}
else
{
Expand All @@ -1608,7 +1617,10 @@ bool QgsAdvancedDigitizingDockWidget::processCanvasReleaseEvent( QgsMapMouseEven
addPoint( event->mapPoint() );
releaseLocks( false );

return constructionMode();
if ( constructionMode() )
{
event->setAccepted( false );
}
}

bool QgsAdvancedDigitizingDockWidget::alignToSegment( QgsMapMouseEvent *e, CadConstraint::LockMode lockMode )
Expand Down
9 changes: 3 additions & 6 deletions src/gui/qgsadvanceddigitizingdockwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -278,21 +278,18 @@ class GUI_EXPORT QgsAdvancedDigitizingDockWidget : public QgsDockWidget, private

/**
* Processes the canvas press \a event.
* \returns Returns TRUE if the event has been 'eaten' and should not propagate further.
*/
bool processCanvasPressEvent( QgsMapMouseEvent *event );
void processCanvasPressEvent( QgsMapMouseEvent *event );

/**
* Processes the canvas move \a event.
* \returns Returns TRUE if the event has been 'eaten' and should not propagate further.
*/
bool processCanvasMoveEvent( QgsMapMouseEvent *event );
void processCanvasMoveEvent( QgsMapMouseEvent *event );

/**
* Processes the canvas release \a event.
* \returns Returns TRUE if the event has been 'eaten' and should not propagate further.
*/
bool processCanvasReleaseEvent( QgsMapMouseEvent *event );
void processCanvasReleaseEvent( QgsMapMouseEvent *event );

/**
* Sets an advanced digitizing tool which will take over digitizing until the tool is close.
Expand Down
Loading

0 comments on commit 8384b41

Please sign in to comment.