Create QgsAbstractAnnotationItemEditOperation as base class for

edit operations on annotation layers, with initial implementation
as QgsAnnotationItemEditOperationMoveNode

This class encapsulates edit operations which apply to annotation
layers/items
This commit is contained in:
Nyall Dawson 2021-09-09 15:04:34 +10:00
parent 5ed05fadca
commit a87206dbdf
7 changed files with 276 additions and 0 deletions

View File

@ -0,0 +1,88 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/annotations/qgsannotationitemeditoperation.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
class QgsAbstractAnnotationItemEditOperation
{
%Docstring(signature="appended")
Abstract base class for annotation item edit operations
.. versionadded:: 3.22
%End
%TypeHeaderCode
#include "qgsannotationitemeditoperation.h"
%End
public:
QgsAbstractAnnotationItemEditOperation( const QString &itemId );
%Docstring
Constructor for QgsAbstractAnnotationItemEditOperation, for the specified item id.
%End
virtual ~QgsAbstractAnnotationItemEditOperation();
QString itemId() const;
%Docstring
Returns the associated item ID.
%End
protected:
};
class QgsAnnotationItemEditOperationMoveNode : QgsAbstractAnnotationItemEditOperation
{
%Docstring(signature="appended")
Annotation item edit operation consisting of moving a node
.. versionadded:: 3.22
%End
%TypeHeaderCode
#include "qgsannotationitemeditoperation.h"
%End
public:
QgsAnnotationItemEditOperationMoveNode( const QString &itemId, QgsVertexId nodeId, const QgsPointXY &before, const QgsPointXY &after );
%Docstring
Constructor for QgsAnnotationItemEditOperationMoveNode, where the node with the specified ``id`` moves
from ``before`` to ``after`` (in layer coordinates).
%End
QgsVertexId nodeId() const;
%Docstring
Returns the associated node ID.
%End
QgsPointXY before() const;
%Docstring
Returns the node position before the move occurred (in layer coordinates).
.. seealso:: :py:func:`after`
%End
QgsPointXY after() const;
%Docstring
Returns the node position after the move occurred (in layer coordinates).
.. seealso:: :py:func:`before`
%End
};
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/annotations/qgsannotationitemeditoperation.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/

View File

@ -205,6 +205,7 @@
%Include auto_generated/./3d/qgsabstract3drenderer.sip
%Include auto_generated/annotations/qgsannotation.sip
%Include auto_generated/annotations/qgsannotationitem.sip
%Include auto_generated/annotations/qgsannotationitemeditoperation.sip
%Include auto_generated/annotations/qgsannotationitemnode.sip
%Include auto_generated/annotations/qgsannotationitemregistry.sip
%Include auto_generated/annotations/qgsannotationlayer.sip

View File

@ -175,6 +175,7 @@ set(QGIS_CORE_SRCS
annotations/qgsannotation.cpp
annotations/qgsannotationitem.cpp
annotations/qgsannotationitemeditoperation.cpp
annotations/qgsannotationitemregistry.cpp
annotations/qgsannotationlayer.cpp
annotations/qgsannotationlayerrenderer.cpp
@ -1154,6 +1155,7 @@ set(QGIS_CORE_HDRS
annotations/qgsannotation.h
annotations/qgsannotationitem.h
annotations/qgsannotationitemeditoperation.h
annotations/qgsannotationitemnode.h
annotations/qgsannotationitemregistry.h
annotations/qgsannotationlayer.h

View File

@ -0,0 +1,43 @@
/***************************************************************************
qgsannotationitemeditoperation.cpp
----------------
copyright : (C) 2021 by Nyall Dawson
email : nyall dot dawson at gmail dot com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "qgsannotationitemeditoperation.h"
//
// QgsAbstractAnnotationItemEditOperation
//
QgsAbstractAnnotationItemEditOperation::QgsAbstractAnnotationItemEditOperation( const QString &itemId )
: mItemId( itemId )
{
}
QgsAbstractAnnotationItemEditOperation::~QgsAbstractAnnotationItemEditOperation() = default;
//
// QgsAnnotationItemEditOperationMoveNode
//
QgsAnnotationItemEditOperationMoveNode::QgsAnnotationItemEditOperationMoveNode( const QString &itemId, QgsVertexId nodeId, const QgsPointXY &before, const QgsPointXY &after )
: QgsAbstractAnnotationItemEditOperation( itemId )
, mNodeId( nodeId )
, mBefore( before )
, mAfter( after )
{
}

View File

@ -0,0 +1,96 @@
/***************************************************************************
qgsannotationitemeditoperation.h
----------------
copyright : (C) 2021 by Nyall Dawson
email : nyall dot dawson at gmail dot com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSANNOTATIONITEMEDITOPERATION_H
#define QGSANNOTATIONITEMEDITOPERATION_H
#include "qgis_core.h"
#include "qgis_sip.h"
#include "qgis.h"
#include "qgspointxy.h"
#include "qgsabstractgeometry.h"
#include "qgsgeometry.h"
/**
* \ingroup core
* \brief Abstract base class for annotation item edit operations
* \since QGIS 3.22
*/
class CORE_EXPORT QgsAbstractAnnotationItemEditOperation
{
public:
/**
* Constructor for QgsAbstractAnnotationItemEditOperation, for the specified item id.
*/
QgsAbstractAnnotationItemEditOperation( const QString &itemId );
virtual ~QgsAbstractAnnotationItemEditOperation();
/**
* Returns the associated item ID.
*/
QString itemId() const { return mItemId; }
protected:
QString mItemId;
};
/**
* \ingroup core
* \brief Annotation item edit operation consisting of moving a node
* \since QGIS 3.22
*/
class CORE_EXPORT QgsAnnotationItemEditOperationMoveNode : public QgsAbstractAnnotationItemEditOperation
{
public:
/**
* 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 );
/**
* Returns the associated node ID.
*/
QgsVertexId nodeId() const { return mNodeId; }
/**
* Returns the node position before the move occurred (in layer coordinates).
*
* \see after()
*/
QgsPointXY before() const { return mBefore; }
/**
* Returns the node position after the move occurred (in layer coordinates).
*
* \see before()
*/
QgsPointXY after() const { return mAfter; }
private:
QgsVertexId mNodeId;
QgsPointXY mBefore;
QgsPointXY mAfter;
};
#endif // QGSANNOTATIONITEMEDITOPERATION_H

View File

@ -20,6 +20,7 @@ ADD_PYTHON_TEST(PyQgsArcGisPortalUtils test_qgsarcgisportalutils.py)
ADD_PYTHON_TEST(PyQgsPythonProvider test_provider_python.py)
ADD_PYTHON_TEST(PyQgsAggregateCalculator test_qgsaggregatecalculator.py)
ADD_PYTHON_TEST(PyQgsAnnotation test_qgsannotation.py)
ADD_PYTHON_TEST(PyQgsAnnotationItemEditOperation test_qgsannotationitemeditoperation.py)
ADD_PYTHON_TEST(PyQgsAnnotationItemNode test_qgsannotationitemnode.py)
ADD_PYTHON_TEST(PyQgsAnnotationLayer test_qgsannotationlayer.py)
ADD_PYTHON_TEST(PyQgsAnnotationLineItem test_qgsannotationlineitem.py)

View File

@ -0,0 +1,45 @@
# -*- coding: utf-8 -*-
"""QGIS Unit tests for QgsAnnotationItemEditOperation
From build dir, run: ctest -R QgsAnnotationItemEditOperation -V
.. note:: This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
"""
__author__ = '(C) 2020 by Nyall Dawson'
__date__ = '09/09/2020'
__copyright__ = 'Copyright 2020, The QGIS Project'
import qgis # NOQA
from qgis.core import (
QgsAbstractAnnotationItemEditOperation,
QgsAnnotationItemEditOperationMoveNode,
QgsVertexId,
QgsPointXY
)
from qgis.testing import start_app, unittest
from utilities import unitTestDataPath
start_app()
TEST_DATA_DIR = unitTestDataPath()
class TestQgsAnnotationItemEditOperation(unittest.TestCase):
def test_basic(self):
base = QgsAbstractAnnotationItemEditOperation('my item')
self.assertEqual(base.itemId(), 'my item')
def test_move_operation(self):
operation = QgsAnnotationItemEditOperationMoveNode('item id', QgsVertexId(1, 2, 3), QgsPointXY(4, 5), QgsPointXY(6, 7))
self.assertEqual(operation.itemId(), 'item id')
self.assertEqual(operation.nodeId(), QgsVertexId(1, 2, 3))
self.assertEqual(operation.before(), QgsPointXY(4, 5))
self.assertEqual(operation.after(), QgsPointXY(6, 7))
if __name__ == '__main__':
unittest.main()