Skip to content
Permalink
Browse files

Port polygon and polyline items to layouts

  • Loading branch information
nyalldawson committed Oct 17, 2017
1 parent b41fea9 commit 783636dfa74735059f915ffefde6fba9f392ad9e
Showing with 1,991 additions and 0 deletions.
  1. +3 −0 python/core/core_auto.sip
  2. +18 −0 python/core/layout/qgslayoutitem.sip
  3. +181 −0 python/core/layout/qgslayoutitemnodeitem.sip
  4. +85 −0 python/core/layout/qgslayoutitempolygon.sip
  5. +86 −0 python/core/layout/qgslayoutitempolyline.sip
  6. +2 −0 python/core/layout/qgslayoutitemregistry.sip
  7. +16 −0 src/app/layout/qgslayoutapputils.cpp
  8. +6 −0 src/core/CMakeLists.txt
  9. +17 −0 src/core/layout/qgslayoutitem.cpp
  10. +18 −0 src/core/layout/qgslayoutitem.h
  11. +329 −0 src/core/layout/qgslayoutitemnodeitem.cpp
  12. +170 −0 src/core/layout/qgslayoutitemnodeitem.h
  13. +142 −0 src/core/layout/qgslayoutitempolygon.cpp
  14. +86 −0 src/core/layout/qgslayoutitempolygon.h
  15. +141 −0 src/core/layout/qgslayoutitempolyline.cpp
  16. +88 −0 src/core/layout/qgslayoutitempolyline.h
  17. +4 −0 src/core/layout/qgslayoutitemregistry.cpp
  18. +2 −0 src/core/layout/qgslayoutitemregistry.h
  19. +2 −0 tests/src/python/CMakeLists.txt
  20. +60 −0 tests/src/python/qgslayoutchecker.py
  21. +275 −0 tests/src/python/test_qgslayoutpolygon.py
  22. +260 −0 tests/src/python/test_qgslayoutpolyline.py
  23. BIN ...mages/composer_polygon/expected_composerpolygon_addnode/expected_composerpolygon_addnode_mask.png
  24. BIN ...oser_polygon/expected_composerpolygon_defaultstyle/expected_composerpolygon_defaultstyle_mask.png
  25. BIN ...oser_polygon/expected_composerpolygon_displaynodes/expected_composerpolygon_displaynodes_mask.png
  26. BIN ...ges/composer_polygon/expected_composerpolygon_movenode/expected_composerpolygon_movenode_mask.png
  27. BIN ...oser_polygon/expected_composerpolygon_selectednode/expected_composerpolygon_selectednode_mask.png
  28. BIN ...es/composer_polyline/expected_composerpolyline_addnode/expected_composerpolyline_addnode_mask.png
  29. BIN ...r_polyline/expected_composerpolyline_defaultstyle/expected_composerpolyline_defaultstyle_mask.png
  30. BIN ...r_polyline/expected_composerpolyline_displaynodes/expected_composerpolyline_displaynodes_mask.png
  31. BIN .../composer_polyline/expected_composerpolyline_movenode/expected_composerpolyline_movenode_mask.png
  32. BIN ...ser_polyline/expected_composerpolyline_removednode/expected_composerpolyline_removednode_mask.png
  33. BIN ...r_polyline/expected_composerpolyline_selectednode/expected_composerpolyline_selectednode_mask.png
@@ -409,7 +409,10 @@
%Include layout/qgslayoutitem.sip
%Include layout/qgslayoutitemgroup.sip
%Include layout/qgslayoutitemmap.sip
%Include layout/qgslayoutitemnodeitem.sip
%Include layout/qgslayoutitempage.sip
%Include layout/qgslayoutitempolygon.sip
%Include layout/qgslayoutitempolyline.sip
%Include layout/qgslayoutitemregistry.sip
%Include layout/qgslayoutitemshape.sip
%Include layout/qgslayoutmodel.sip
@@ -263,6 +263,24 @@ class QgsLayoutItem : QgsLayoutObject, QGraphicsRectItem, QgsLayoutUndoObjectInt
.. seealso:: positionWithUnits()
%End


void attemptSetSceneRect( const QRectF &rect, bool includesFrame = false );
%Docstring
Attempts to update the item's position and size to match the passed ``rect`` in layout
coordinates.

If ``includesFrame`` is true, then the position and size specified by ``rect`` represents the
position and size at for the outside of the item's frame.

Note that the final position and size of the item may not match the specified target rect,
as data defined item position and size may override the specified value.

.. seealso:: attemptResize()
.. seealso:: attemptMove()
.. seealso:: referencePoint()
.. seealso:: positionWithUnits()
%End

QgsLayoutPoint positionWithUnits() const;
%Docstring
Returns the item's current position, including units. The position returned
@@ -0,0 +1,181 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/layout/qgslayoutitemnodeitem.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/




class QgsLayoutNodesItem: QgsLayoutItem
{
%Docstring
An abstract layout item that provides generic methods for node based
shapes such as polygon or polylines.
.. versionadded:: 3.0
%End

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

bool addNode( QPointF point, bool checkArea = true, double radius = 10 );
%Docstring
Add a node in current shape.
\param point is the location of the new node (in scene coordinates)
\param checkArea is a flag to indicate if there's a space constraint.
\param radius is the space contraint and is used only if checkArea is
true. Typically, if this flag is true, the new node has to be nearer
than radius to the shape to be added.
:rtype: bool
%End

void setDisplayNodes( bool display = true );
%Docstring
Set whether the item's nodes should be displayed.
%End

bool moveNode( int index, QPointF node );
%Docstring
Moves a node to a new position.
\param index the index of the node to move
\param node is the new position in scene coordinate
:rtype: bool
%End

int nodeAtPosition( QPointF point, bool searchInRadius = true, double radius = 10 ) const;
%Docstring
Search for the nearest node in the shape within a maximal area. Returns the
index of the nearest node or -1 if no node was found.
\param point is the location to search for nodes from (in scene coordinates)
\param searchInRadius is a flag to indicate if the area of research is
limited in space.
\param radius is only used if searchInRadius is true
:rtype: int
%End

bool nodePosition( int index, QPointF &position ) const;
%Docstring
Gets the position of a node in scene coordinates.
\param index of the node
\param position the position of the node
:return: true if the index is valid and the position is set, false otherwise
:rtype: bool
%End

bool removeNode( int index );
%Docstring
Remove a node with specified ``index`` from the shape.
:rtype: bool
%End

int nodesSize() const;
%Docstring
Returns the number of nodes in the shape.
:rtype: int
%End

bool setSelectedNode( int index );
%Docstring
Selects a node by ``index``.
:rtype: bool
%End

int selectedNode() const;
%Docstring
Returns the currently selected node, or -1 if no node is selected.
:rtype: int
%End

void deselectNode();
%Docstring
Deselects any selected nodes.
%End

QPolygonF nodes() const;
%Docstring
Returns the nodes the shape consists of.
:rtype: QPolygonF
%End

protected:

QgsLayoutNodesItem( QgsLayout *layout );
%Docstring
Constructor
\param tagName tag used in XML file
\param layout parent layout
%End

QgsLayoutNodesItem( const QPolygonF &polygon, QgsLayout *layout );
%Docstring
Constructor
\param tagName tag used in XML file
\param polygon nodes of the shape
\param layout parent layout
%End

virtual void draw( QgsRenderContext &context, const QStyleOptionGraphicsItem *itemStyle = 0 );

virtual bool writePropertiesToElement( QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context ) const;

virtual bool readPropertiesFromElement( const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context );



virtual bool _addNode( const int nodeIndex, QPointF newNode, const double radius ) = 0;
%Docstring
Method called in addNode.
:rtype: bool
%End

virtual bool _removeNode( const int nodeIndex ) = 0;
%Docstring
Method called in removeNode.
:rtype: bool
%End

virtual void _draw( QgsRenderContext &context, const QStyleOptionGraphicsItem *itemStyle = 0 ) = 0;
%Docstring
Method called in paint.
%End

virtual void _readXmlStyle( const QDomElement &elmt, const QgsReadWriteContext &context ) = 0;
%Docstring
Method called in readXml.
%End

virtual void _writeXmlStyle( QDomDocument &doc, QDomElement &elmt, const QgsReadWriteContext &context ) const = 0;
%Docstring
Method called in writeXml.
%End

void rescaleToFitBoundingBox();
%Docstring
Rescale the current shape according to the item's bounding box. Useful when
the shape is resized thanks to the rubber band.
%End

double computeDistance( QPointF pt1, QPointF pt2 ) const;
%Docstring
Compute an euclidian distance between 2 nodes.
:rtype: float
%End

void updateSceneRect();
%Docstring
Update the current scene rectangle for this item.
%End

};

/************************************************************************
* This file has been generated automatically from *
* *
* src/core/layout/qgslayoutitemnodeitem.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
@@ -0,0 +1,85 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/layout/qgslayoutitempolygon.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/





class QgsLayoutItemPolygon: QgsLayoutNodesItem
{
%Docstring
Layout item for node based polygon shapes.
.. versionadded:: 3.0
%End

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

QgsLayoutItemPolygon( QgsLayout *layout );
%Docstring
Constructor for QgsLayoutItemPolygon for the specified ``layout``.
%End

QgsLayoutItemPolygon( const QPolygonF &polygon, QgsLayout *layout );
%Docstring
Constructor for QgsLayoutItemPolygon for the specified ``polygon``
and ``layout``.
%End

static QgsLayoutItemPolygon *create( QgsLayout *layout ) /Factory/;
%Docstring
Returns a new polygon item for the specified ``layout``.

The caller takes responsibility for deleting the returned object.
:rtype: QgsLayoutItemPolygon
%End

virtual int type() const;

virtual QString stringType() const;

virtual QString displayName() const;


QgsFillSymbol *symbol();
%Docstring
Returns the fill symbol used to draw the shape.
.. seealso:: setSymbol()
:rtype: QgsFillSymbol
%End

void setSymbol( QgsFillSymbol *symbol );
%Docstring
Sets the ``symbol`` used to draw the shape.
Ownership of ``symbol`` is not transferred.
.. seealso:: symbol()
%End

protected:
virtual bool _addNode( const int indexPoint, QPointF newPoint, const double radius );

virtual bool _removeNode( const int nodeIndex );

virtual void _draw( QgsRenderContext &context, const QStyleOptionGraphicsItem *itemStyle = 0 );

virtual void _readXmlStyle( const QDomElement &elmt, const QgsReadWriteContext &context );

virtual void _writeXmlStyle( QDomDocument &doc, QDomElement &elmt, const QgsReadWriteContext &context ) const;


};

/************************************************************************
* This file has been generated automatically from *
* *
* src/core/layout/qgslayoutitempolygon.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
@@ -0,0 +1,86 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/layout/qgslayoutitempolyline.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/




class QgsLayoutItemPolyline: QgsLayoutNodesItem
{
%Docstring
Layout item for node based polyline shapes.
.. versionadded:: 3.0
%End

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

QgsLayoutItemPolyline( QgsLayout *layout );
%Docstring
Constructor for QgsLayoutItemPolyline for the specified ``layout``.
%End

QgsLayoutItemPolyline( const QPolygonF &polyline, QgsLayout *layout );
%Docstring
Constructor for QgsLayoutItemPolyline for the specified ``polyline``
and ``layout``.
%End

static QgsLayoutItemPolyline *create( QgsLayout *layout ) /Factory/;
%Docstring
Returns a new polyline item for the specified ``layout``.

The caller takes responsibility for deleting the returned object.
:rtype: QgsLayoutItemPolyline
%End

virtual int type() const;

virtual QString stringType() const;

virtual QString displayName() const;


QgsLineSymbol *symbol();
%Docstring
Returns the line symbol used to draw the shape.
.. seealso:: setSymbol()
:rtype: QgsLineSymbol
%End

void setSymbol( QgsLineSymbol *symbol );
%Docstring
Sets the ``symbol`` used to draw the shape.
Ownership of ``symbol`` is not transferred.
.. seealso:: symbol()
%End

protected:

virtual bool _addNode( const int indexPoint, QPointF newPoint, const double radius );

virtual bool _removeNode( const int nodeIndex );

virtual void _draw( QgsRenderContext &context, const QStyleOptionGraphicsItem *itemStyle = 0 );

virtual void _readXmlStyle( const QDomElement &elmt, const QgsReadWriteContext &context );

virtual void _writeXmlStyle( QDomDocument &doc, QDomElement &elmt, const QgsReadWriteContext &context ) const;


};


/************************************************************************
* This file has been generated automatically from *
* *
* src/core/layout/qgslayoutitempolyline.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
@@ -104,6 +104,8 @@ class QgsLayoutItemRegistry : QObject
LayoutPage,
LayoutMap,
LayoutShape,
LayoutPolygon,
LayoutPolyline,

// item
PluginItem,

0 comments on commit 783636d

Please sign in to comment.
You can’t perform that action at this time.