Skip to content

Commit

Permalink
Port polygon and polyline items to layouts
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Nov 7, 2017
1 parent b41fea9 commit 783636d
Show file tree
Hide file tree
Showing 33 changed files with 1,991 additions and 0 deletions.
3 changes: 3 additions & 0 deletions python/core/core_auto.sip
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions python/core/layout/qgslayoutitem.sip
Expand Up @@ -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
Expand Down
181 changes: 181 additions & 0 deletions python/core/layout/qgslayoutitemnodeitem.sip
@@ -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 *
************************************************************************/
85 changes: 85 additions & 0 deletions python/core/layout/qgslayoutitempolygon.sip
@@ -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 *
************************************************************************/
86 changes: 86 additions & 0 deletions python/core/layout/qgslayoutitempolyline.sip
@@ -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 *
************************************************************************/
2 changes: 2 additions & 0 deletions python/core/layout/qgslayoutitemregistry.sip
Expand Up @@ -104,6 +104,8 @@ class QgsLayoutItemRegistry : QObject
LayoutPage,
LayoutMap,
LayoutShape,
LayoutPolygon,
LayoutPolyline,

// item
PluginItem,
Expand Down

0 comments on commit 783636d

Please sign in to comment.