Skip to content
Permalink
Browse files
Add new annotation edit operation for deleting a vertex
  • Loading branch information
nyalldawson committed Sep 10, 2021
1 parent 8cf4903 commit 4b245f59e0bb7a4a3d832381cdbd97dd865f2228
@@ -0,0 +1,6 @@
# The following has been generated automatically from src/core/annotations/qgsannotationitemeditoperation.h
# monkey patching scoped based enum
QgsAbstractAnnotationItemEditOperation.Type.MoveNode.__doc__ = "Move a node"
QgsAbstractAnnotationItemEditOperation.Type.DeleteNode.__doc__ = "Delete a node"
QgsAbstractAnnotationItemEditOperation.Type.__doc__ = 'Operation type\n\n' + '* ``MoveNode``: ' + QgsAbstractAnnotationItemEditOperation.Type.MoveNode.__doc__ + '\n' + '* ``DeleteNode``: ' + QgsAbstractAnnotationItemEditOperation.Type.DeleteNode.__doc__
# --
@@ -22,13 +22,24 @@ Abstract base class for annotation item edit operations
%End
public:

enum class Type
{
MoveNode,
DeleteNode,
};

QgsAbstractAnnotationItemEditOperation( const QString &itemId );
%Docstring
Constructor for QgsAbstractAnnotationItemEditOperation, for the specified item id.
%End

virtual ~QgsAbstractAnnotationItemEditOperation();

virtual Type type() const = 0;
%Docstring
Returns the operation type.
%End

QString itemId() const;
%Docstring
Returns the associated item ID.
@@ -52,25 +63,28 @@ Annotation item edit operation consisting of moving a node
%End
public:

QgsAnnotationItemEditOperationMoveNode( const QString &itemId, QgsVertexId nodeId, const QgsPointXY &before, const QgsPointXY &after );
QgsAnnotationItemEditOperationMoveNode( const QString &itemId, QgsVertexId nodeId, const QgsPoint &before, const QgsPoint &after );
%Docstring
Constructor for QgsAnnotationItemEditOperationMoveNode, where the node with the specified ``id`` moves
from ``before`` to ``after`` (in layer coordinates).
%End

virtual Type type() const;


QgsVertexId nodeId() const;
%Docstring
Returns the associated node ID.
%End

QgsPointXY before() const;
QgsPoint before() const;
%Docstring
Returns the node position before the move occurred (in layer coordinates).

.. seealso:: :py:func:`after`
%End

QgsPointXY after() const;
QgsPoint after() const;
%Docstring
Returns the node position after the move occurred (in layer coordinates).

@@ -79,6 +93,41 @@ Returns the node position after the move occurred (in layer coordinates).

};


class QgsAnnotationItemEditOperationDeleteNode : QgsAbstractAnnotationItemEditOperation
{
%Docstring(signature="appended")
Annotation item edit operation consisting of deleting a node

.. versionadded:: 3.22
%End

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

QgsAnnotationItemEditOperationDeleteNode( const QString &itemId, QgsVertexId nodeId, const QgsPoint &before );
%Docstring
Constructor for QgsAnnotationItemEditOperationDeleteNode, where the node with the specified ``id`` and previous
position ``before`` is deleted.
%End

virtual Type type() const;


QgsVertexId nodeId() const;
%Docstring
Returns the deleted node ID.
%End

QgsPoint before() const;
%Docstring
Returns the node position before the delete occurred (in layer coordinates).
%End

};

class QgsAnnotationItemEditOperationTransientResults
{
%Docstring(signature="appended")
@@ -31,7 +31,7 @@ QgsAbstractAnnotationItemEditOperation::~QgsAbstractAnnotationItemEditOperation(
//
// QgsAnnotationItemEditOperationMoveNode
//
QgsAnnotationItemEditOperationMoveNode::QgsAnnotationItemEditOperationMoveNode( const QString &itemId, QgsVertexId nodeId, const QgsPointXY &before, const QgsPointXY &after )
QgsAnnotationItemEditOperationMoveNode::QgsAnnotationItemEditOperationMoveNode( const QString &itemId, QgsVertexId nodeId, const QgsPoint &before, const QgsPoint &after )
: QgsAbstractAnnotationItemEditOperation( itemId )
, mNodeId( nodeId )
, mBefore( before )
@@ -40,4 +40,25 @@ QgsAnnotationItemEditOperationMoveNode::QgsAnnotationItemEditOperationMoveNode(

}

QgsAbstractAnnotationItemEditOperation::Type QgsAnnotationItemEditOperationMoveNode::type() const
{
return Type::MoveNode;
}


//
// QgsAnnotationItemEditOperationDeleteNode
//

QgsAnnotationItemEditOperationDeleteNode::QgsAnnotationItemEditOperationDeleteNode( const QString &itemId, QgsVertexId nodeId, const QgsPoint &before )
: QgsAbstractAnnotationItemEditOperation( itemId )
, mNodeId( nodeId )
, mBefore( before )
{

}

QgsAbstractAnnotationItemEditOperation::Type QgsAnnotationItemEditOperationDeleteNode::type() const
{
return Type::DeleteNode;
}
@@ -33,13 +33,27 @@ class CORE_EXPORT QgsAbstractAnnotationItemEditOperation
{
public:

/**
* Operation type
*/
enum class Type : int
{
MoveNode, //!< Move a node
DeleteNode, //!< Delete a node
};

/**
* Constructor for QgsAbstractAnnotationItemEditOperation, for the specified item id.
*/
QgsAbstractAnnotationItemEditOperation( const QString &itemId );

virtual ~QgsAbstractAnnotationItemEditOperation();

/**
* Returns the operation type.
*/
virtual Type type() const = 0;

/**
* Returns the associated item ID.
*/
@@ -64,7 +78,9 @@ class CORE_EXPORT QgsAnnotationItemEditOperationMoveNode : public QgsAbstractAnn
* Constructor for QgsAnnotationItemEditOperationMoveNode, where the node with the specified \a id moves
* from \a before to \a after (in layer coordinates).
*/
QgsAnnotationItemEditOperationMoveNode( const QString &itemId, QgsVertexId nodeId, const QgsPointXY &before, const QgsPointXY &after );
QgsAnnotationItemEditOperationMoveNode( const QString &itemId, QgsVertexId nodeId, const QgsPoint &before, const QgsPoint &after );

Type type() const override;

/**
* Returns the associated node ID.
@@ -76,20 +92,55 @@ class CORE_EXPORT QgsAnnotationItemEditOperationMoveNode : public QgsAbstractAnn
*
* \see after()
*/
QgsPointXY before() const { return mBefore; }
QgsPoint before() const { return mBefore; }

/**
* Returns the node position after the move occurred (in layer coordinates).
*
* \see before()
*/
QgsPointXY after() const { return mAfter; }
QgsPoint after() const { return mAfter; }

private:

QgsVertexId mNodeId;
QgsPoint mBefore;
QgsPoint mAfter;

};


/**
* \ingroup core
* \brief Annotation item edit operation consisting of deleting a node
* \since QGIS 3.22
*/
class CORE_EXPORT QgsAnnotationItemEditOperationDeleteNode : public QgsAbstractAnnotationItemEditOperation
{
public:

/**
* Constructor for QgsAnnotationItemEditOperationDeleteNode, where the node with the specified \a id and previous
* position \a before is deleted.
*/
QgsAnnotationItemEditOperationDeleteNode( const QString &itemId, QgsVertexId nodeId, const QgsPoint &before );

Type type() const override;

/**
* Returns the deleted node ID.
*/
QgsVertexId nodeId() const { return mNodeId; }

/**
* Returns the node position before the delete occurred (in layer coordinates).
*/
QgsPoint before() const { return mBefore; }

private:

QgsVertexId mNodeId;
QgsPointXY mBefore;
QgsPointXY mAfter;
QgsPoint mBefore;

};

@@ -105,25 +105,41 @@ bool QgsAnnotationLineItem::transform( const QTransform &transform )

bool QgsAnnotationLineItem::applyEdit( QgsAbstractAnnotationItemEditOperation *operation )
{
if ( QgsAnnotationItemEditOperationMoveNode *moveOperation = dynamic_cast< QgsAnnotationItemEditOperationMoveNode * >( operation ) )
switch ( operation->type() )
{
return mCurve->moveVertex( moveOperation->nodeId(), QgsPoint( moveOperation->after() ) );
}
else
{
return false;
case QgsAbstractAnnotationItemEditOperation::Type::MoveNode:
{
QgsAnnotationItemEditOperationMoveNode *moveOperation = qgis::down_cast< QgsAnnotationItemEditOperationMoveNode * >( operation );
return mCurve->moveVertex( moveOperation->nodeId(), QgsPoint( moveOperation->after() ) );
}

case QgsAbstractAnnotationItemEditOperation::Type::DeleteNode:
{
QgsAnnotationItemEditOperationDeleteNode *deleteOperation = qgis::down_cast< QgsAnnotationItemEditOperationDeleteNode * >( operation );
return mCurve->deleteVertex( deleteOperation->nodeId() );
}
}

return false;
}

QgsAnnotationItemEditOperationTransientResults *QgsAnnotationLineItem::transientEditResults( QgsAbstractAnnotationItemEditOperation *operation )
{
if ( QgsAnnotationItemEditOperationMoveNode *moveOperation = dynamic_cast< QgsAnnotationItemEditOperationMoveNode * >( operation ) )
switch ( operation->type() )
{
std::unique_ptr< QgsCurve > modifiedCurve( mCurve->clone() );
if ( modifiedCurve->moveVertex( moveOperation->nodeId(), QgsPoint( moveOperation->after() ) ) )
case QgsAbstractAnnotationItemEditOperation::Type::MoveNode:
{
return new QgsAnnotationItemEditOperationTransientResults( QgsGeometry( std::move( modifiedCurve ) ) );
QgsAnnotationItemEditOperationMoveNode *moveOperation = dynamic_cast< QgsAnnotationItemEditOperationMoveNode * >( operation );
std::unique_ptr< QgsCurve > modifiedCurve( mCurve->clone() );
if ( modifiedCurve->moveVertex( moveOperation->nodeId(), QgsPoint( moveOperation->after() ) ) )
{
return new QgsAnnotationItemEditOperationTransientResults( QgsGeometry( std::move( modifiedCurve ) ) );
}
break;
}

case QgsAbstractAnnotationItemEditOperation::Type::DeleteNode:
break;
}
return nullptr;
}
@@ -82,22 +82,36 @@ QList<QgsAnnotationItemNode> QgsAnnotationMarkerItem::nodes() const

bool QgsAnnotationMarkerItem::applyEdit( QgsAbstractAnnotationItemEditOperation *operation )
{
if ( QgsAnnotationItemEditOperationMoveNode *moveOperation = dynamic_cast< QgsAnnotationItemEditOperationMoveNode * >( operation ) )
switch ( operation->type() )
{
mPoint = QgsPoint( moveOperation->after() );
return true;
}
else
{
return false;
case QgsAbstractAnnotationItemEditOperation::Type::MoveNode:
{
QgsAnnotationItemEditOperationMoveNode *moveOperation = qgis::down_cast< QgsAnnotationItemEditOperationMoveNode * >( operation );
mPoint = QgsPoint( moveOperation->after() );
return true;
}

case QgsAbstractAnnotationItemEditOperation::Type::DeleteNode:
{
return false;
}
}

return false;
}

QgsAnnotationItemEditOperationTransientResults *QgsAnnotationMarkerItem::transientEditResults( QgsAbstractAnnotationItemEditOperation *operation )
{
if ( QgsAnnotationItemEditOperationMoveNode *moveOperation = dynamic_cast< QgsAnnotationItemEditOperationMoveNode * >( operation ) )
switch ( operation->type() )
{
return new QgsAnnotationItemEditOperationTransientResults( QgsGeometry::fromPointXY( moveOperation->after() ) );
case QgsAbstractAnnotationItemEditOperation::Type::MoveNode:
{
QgsAnnotationItemEditOperationMoveNode *moveOperation = dynamic_cast< QgsAnnotationItemEditOperationMoveNode * >( operation );
return new QgsAnnotationItemEditOperationTransientResults( QgsGeometry( moveOperation->after().clone() ) );
}

case QgsAbstractAnnotationItemEditOperation::Type::DeleteNode:
break;
}
return nullptr;
}
@@ -149,22 +149,36 @@ bool QgsAnnotationPointTextItem::transform( const QTransform &transform )

bool QgsAnnotationPointTextItem::applyEdit( QgsAbstractAnnotationItemEditOperation *operation )
{
if ( QgsAnnotationItemEditOperationMoveNode *moveOperation = dynamic_cast< QgsAnnotationItemEditOperationMoveNode * >( operation ) )
switch ( operation->type() )
{
mPoint = moveOperation->after();
return true;
}
else
{
return false;
case QgsAbstractAnnotationItemEditOperation::Type::MoveNode:
{
QgsAnnotationItemEditOperationMoveNode *moveOperation = dynamic_cast< QgsAnnotationItemEditOperationMoveNode * >( operation );
mPoint = moveOperation->after();
return true;
}

case QgsAbstractAnnotationItemEditOperation::Type::DeleteNode:
{
return false;
}
}

return false;
}

QgsAnnotationItemEditOperationTransientResults *QgsAnnotationPointTextItem::transientEditResults( QgsAbstractAnnotationItemEditOperation *operation )
{
if ( QgsAnnotationItemEditOperationMoveNode *moveOperation = dynamic_cast< QgsAnnotationItemEditOperationMoveNode * >( operation ) )
switch ( operation->type() )
{
return new QgsAnnotationItemEditOperationTransientResults( QgsGeometry::fromPointXY( moveOperation->after() ) );
case QgsAbstractAnnotationItemEditOperation::Type::MoveNode:
{
QgsAnnotationItemEditOperationMoveNode *moveOperation = dynamic_cast< QgsAnnotationItemEditOperationMoveNode * >( operation );
return new QgsAnnotationItemEditOperationTransientResults( QgsGeometry( moveOperation->after().clone() ) );
}

case QgsAbstractAnnotationItemEditOperation::Type::DeleteNode:
break;
}
return nullptr;
}

0 comments on commit 4b245f5

Please sign in to comment.