Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
1 parent
5ed05fa
commit a87206d
Showing
7 changed files
with
276 additions
and
0 deletions.
There are no files selected for viewing
88 changes: 88 additions & 0 deletions
88
python/core/auto_generated/annotations/qgsannotationitemeditoperation.sip.in
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 * | ||
************************************************************************/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ) | ||
{ | ||
|
||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |