Skip to content

Commit

Permalink
Merge pull request #4910 from nyalldawson/layout_next
Browse files Browse the repository at this point in the history
Layouts, chapter III
  • Loading branch information
nyalldawson committed Jul 26, 2017
2 parents 11dd417 + c89a15a commit f0a6376
Show file tree
Hide file tree
Showing 84 changed files with 5,162 additions and 401 deletions.
129 changes: 74 additions & 55 deletions python/core/composer/qgscomposeritem.sip
Expand Up @@ -31,68 +31,87 @@ class QgsComposerItem: QgsComposerObject, QGraphicsRectItem
#include <qgscomposerpolygon.h>
#include <qgscomposerpolyline.h>
#include <qgscomposertexttable.h>
#include <qgslayoutitemshape.h>
#include <qgslayoutitempage.h>
%End

%ConvertToSubClassCode
// the conversions have to be static, because they're using multiple inheritance
// (seen in PyQt4 .sip files for some QGraphicsItem classes)
switch ( sipCpp->type() )
if ( dynamic_cast< QgsComposerItem * >( sipCpp ) )
{
case QgsComposerItem::ComposerItem:
sipType = sipType_QgsComposerItem;
*sipCppRet = static_cast<QgsComposerItem *>( sipCpp );
break;
case QgsComposerItem::ComposerArrow:
sipType = sipType_QgsComposerArrow;
*sipCppRet = static_cast<QgsComposerArrow *>( sipCpp );
break;
case QgsComposerItem::ComposerItemGroup:
sipType = sipType_QgsComposerItemGroup;
*sipCppRet = static_cast<QgsComposerItemGroup *>( sipCpp );
break;
case QgsComposerItem::ComposerLabel:
sipType = sipType_QgsComposerLabel;
*sipCppRet = static_cast<QgsComposerLabel *>( sipCpp );
break;
case QgsComposerItem::ComposerLegend:
sipType = sipType_QgsComposerLegend;
*sipCppRet = static_cast<QgsComposerLegend *>( sipCpp );
break;
case QgsComposerItem::ComposerMap:
sipType = sipType_QgsComposerMap;
*sipCppRet = static_cast<QgsComposerMap *>( sipCpp );
break;
case QgsComposerItem::ComposerPaper:
sipType = sipType_QgsPaperItem;
*sipCppRet = static_cast<QgsPaperItem *>( sipCpp );
break;
case QgsComposerItem::ComposerPicture:
sipType = sipType_QgsComposerPicture;
*sipCppRet = static_cast<QgsComposerPicture *>( sipCpp );
break;
case QgsComposerItem::ComposerScaleBar:
sipType = sipType_QgsComposerScaleBar;
*sipCppRet = static_cast<QgsComposerScaleBar *>( sipCpp );
break;
case QgsComposerItem::ComposerShape:
sipType = sipType_QgsComposerShape;
*sipCppRet = static_cast<QgsComposerShape *>( sipCpp );
break;
case QgsComposerItem::ComposerPolygon:
sipType = sipType_QgsComposerPolygon;
*sipCppRet = static_cast<QgsComposerPolygon *>( sipCpp );
break;
case QgsComposerItem::ComposerPolyline:
sipType = sipType_QgsComposerPolyline;
*sipCppRet = static_cast<QgsComposerPolyline *>( sipCpp );
break;
case QgsComposerItem::ComposerFrame:
sipType = sipType_QgsComposerFrame;
*sipCppRet = static_cast<QgsComposerFrame *>( sipCpp );
break;
default:
sipType = 0;
switch ( sipCpp->type() )
{
case QgsComposerItem::ComposerItem:
sipType = sipType_QgsComposerItem;
*sipCppRet = static_cast<QgsComposerItem *>( sipCpp );
break;
case QgsComposerItem::ComposerArrow:
sipType = sipType_QgsComposerArrow;
*sipCppRet = static_cast<QgsComposerArrow *>( sipCpp );
break;
case QgsComposerItem::ComposerItemGroup:
sipType = sipType_QgsComposerItemGroup;
*sipCppRet = static_cast<QgsComposerItemGroup *>( sipCpp );
break;
case QgsComposerItem::ComposerLabel:
sipType = sipType_QgsComposerLabel;
*sipCppRet = static_cast<QgsComposerLabel *>( sipCpp );
break;
case QgsComposerItem::ComposerLegend:
sipType = sipType_QgsComposerLegend;
*sipCppRet = static_cast<QgsComposerLegend *>( sipCpp );
break;
case QgsComposerItem::ComposerMap:
sipType = sipType_QgsComposerMap;
*sipCppRet = static_cast<QgsComposerMap *>( sipCpp );
break;
case QgsComposerItem::ComposerPaper:
sipType = sipType_QgsPaperItem;
*sipCppRet = static_cast<QgsPaperItem *>( sipCpp );
break;
case QgsComposerItem::ComposerPicture:
sipType = sipType_QgsComposerPicture;
*sipCppRet = static_cast<QgsComposerPicture *>( sipCpp );
break;
case QgsComposerItem::ComposerScaleBar:
sipType = sipType_QgsComposerScaleBar;
*sipCppRet = static_cast<QgsComposerScaleBar *>( sipCpp );
break;
case QgsComposerItem::ComposerShape:
sipType = sipType_QgsComposerShape;
*sipCppRet = static_cast<QgsComposerShape *>( sipCpp );
break;
case QgsComposerItem::ComposerPolygon:
sipType = sipType_QgsComposerPolygon;
*sipCppRet = static_cast<QgsComposerPolygon *>( sipCpp );
break;
case QgsComposerItem::ComposerPolyline:
sipType = sipType_QgsComposerPolyline;
*sipCppRet = static_cast<QgsComposerPolyline *>( sipCpp );
break;
case QgsComposerItem::ComposerFrame:
sipType = sipType_QgsComposerFrame;
*sipCppRet = static_cast<QgsComposerFrame *>( sipCpp );
break;
default:
sipType = 0;
}
}
else
{
switch ( sipCpp->type() )
{
// really, these *should* use the constants from QgsLayoutItemRegistry, but sip doesn't like that!
case QGraphicsItem::UserType + 101:
sipType = sipType_QgsLayoutItemPage;
*sipCppRet = static_cast<QgsLayoutItemPage *>( sipCpp );
break;
default:
sipType = 0;
}
}

%End
public:

Expand Down
2 changes: 2 additions & 0 deletions python/core/core_auto.sip
Expand Up @@ -382,8 +382,10 @@
%Include layout/qgslayout.sip
%Include layout/qgslayoutitem.sip
%Include layout/qgslayoutitemmap.sip
%Include layout/qgslayoutitempage.sip
%Include layout/qgslayoutitemregistry.sip
%Include layout/qgslayoutitemshape.sip
%Include layout/qgslayoutpagecollection.sip
%Include layout/qgslayoutobject.sip
%Include symbology-ng/qgscptcityarchive.sip
%Include symbology-ng/qgssvgcache.sip
Expand Down
41 changes: 41 additions & 0 deletions python/core/layout/qgslayout.sip
Expand Up @@ -22,12 +22,23 @@ class QgsLayout : QGraphicsScene, QgsExpressionContextGenerator

enum ZValues
{
ZPage,
ZMapTool,
};

QgsLayout( QgsProject *project );
%Docstring
Construct a new layout linked to the specified ``project``.

If the layout is a "new" layout (as opposed to a layout which will
restore a previous state from XML) then initializeDefaults() should be
called on the new layout.
%End

void initializeDefaults();
%Docstring
Initializes an empty layout, e.g. by adding a default page to the layout. This should be called after creating
a new layout.
%End

QgsProject *project() const;
Expand Down Expand Up @@ -183,6 +194,36 @@ class QgsLayout : QGraphicsScene, QgsExpressionContextGenerator

void setReferenceMap( QgsLayoutItemMap *map );

QgsLayoutPageCollection *pageCollection();
%Docstring
Returns a pointer to the layout's page collection, which stores and manages
page items in the layout.
:rtype: QgsLayoutPageCollection
%End

QRectF layoutBounds( bool ignorePages = false, double margin = 0.0 ) const;
%Docstring
Calculates the bounds of all non-gui items in the layout. Ignores snap lines, mouse handles
and other cosmetic items.
\param ignorePages set to true to ignore page items
\param margin optional marginal (in percent, e.g., 0.05 = 5% ) to add around items
:return: layout bounds, in layout units.
:rtype: QRectF
%End

void addLayoutItem( QgsLayoutItem *item /Transfer/ );
%Docstring
Adds an ``item`` to the layout. This should be called instead of the base class addItem()
method. Ownership of the item is transferred to the layout.
%End

public slots:

void updateBounds();
%Docstring
Updates the scene bounds of the layout.
%End

signals:

void variablesChanged();
Expand Down
6 changes: 6 additions & 0 deletions python/core/layout/qgslayoutcontext.sip
Expand Up @@ -67,6 +67,12 @@ class QgsLayoutContext
:rtype: bool
%End

QgsRenderContext::Flags renderContextFlags() const;
%Docstring
Returns the combination of render context flags matched to the layout context's settings.
:rtype: QgsRenderContext.Flags
%End

void setFeature( const QgsFeature &feature );
%Docstring
Sets the current ``feature`` for evaluating the layout. This feature may
Expand Down
117 changes: 117 additions & 0 deletions python/core/layout/qgslayoutitem.sip
Expand Up @@ -18,6 +18,24 @@ class QgsLayoutItem : QgsLayoutObject, QGraphicsRectItem

%TypeHeaderCode
#include "qgslayoutitem.h"

#include <qgslayoutitemshape.h>
#include <qgslayoutitempage.h>
%End

%ConvertToSubClassCode
// the conversions have to be static, because they're using multiple inheritance
// (seen in PyQt4 .sip files for some QGraphicsItem classes)
switch ( sipCpp->type() )
{
// really, these *should* use the constants from QgsLayoutItemRegistry, but sip doesn't like that!
case QGraphicsItem::UserType + 101:
sipType = sipType_QgsLayoutItemPage;
*sipCppRet = static_cast<QgsLayoutItemPage *>( sipCpp );
break;
default:
sipType = 0;
}
%End
public:

Expand All @@ -39,6 +57,51 @@ class QgsLayoutItem : QgsLayoutObject, QGraphicsRectItem
Constructor for QgsLayoutItem, with the specified parent ``layout``.
%End

virtual int type() const = 0;
%Docstring
Return correct graphics item type
.. seealso:: stringType()
:rtype: int
%End

virtual QString stringType() const = 0;
%Docstring
Return the item type as a string.

This string must be a unique, single word, character only representation of the item type, eg "LayoutScaleBar"
.. seealso:: type()
:rtype: str
%End

QString uuid() const;
%Docstring
Returns the item identification string. This is a unique random string set for the item
upon creation.
.. note::

There is no corresponding setter for the uuid - it's created automatically.
.. seealso:: id()
.. seealso:: setId()
:rtype: str
%End

QString id() const;
%Docstring
Returns the item's ID name. This is not necessarily unique, and duplicate ID names may exist
for a layout.
.. seealso:: setId()
.. seealso:: uuid()
:rtype: str
%End

virtual void setId( const QString &id );
%Docstring
Set the item's ``id`` name. This is not necessarily unique, and duplicate ID names may exist
for a layout.
.. seealso:: id()
.. seealso:: uuid()
%End

virtual void paint( QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget );

%Docstring
Expand Down Expand Up @@ -130,6 +193,32 @@ class QgsLayoutItem : QgsLayoutObject, QGraphicsRectItem
:rtype: float
%End

virtual bool writeXml( QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context ) const;
%Docstring
Stores the item state in a DOM element.
\param parentElement parent DOM element (e.g. 'Layout' element)
\param document DOM document
\param context read write context
.. seealso:: readXml()
.. note::

Subclasses should ensure that they call writePropertiesToElement() in their implementation.
:rtype: bool
%End

virtual bool readXml( const QDomElement &itemElement, const QDomDocument &document, const QgsReadWriteContext &context );
%Docstring
Sets the item state from a DOM element.
\param itemElement is the DOM node corresponding to item (e.g. 'LayoutItem' element)
\param document DOM document
\param context read write context
.. seealso:: writeXml()
.. note::

Subclasses should ensure that they call readPropertiesFromElement() in their implementation.
:rtype: bool
%End

public slots:

virtual void refresh();
Expand Down Expand Up @@ -230,6 +319,34 @@ class QgsLayoutItem : QgsLayoutObject, QGraphicsRectItem
:rtype: QPointF
%End

virtual bool writePropertiesToElement( QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context ) const;
%Docstring
Stores item state within an XML DOM element.
\param element is the DOM element to store the item's properties in
\param document DOM document
\param context read write context
.. seealso:: writeXml()
.. seealso:: readPropertiesFromElement()
.. note::

derived classes must call this base implementation when overriding this method
:rtype: bool
%End

virtual bool readPropertiesFromElement( const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context );
%Docstring
Sets item state from a DOM element.
\param element is the DOM element for the item
\param document DOM document
\param context read write context
.. seealso:: writePropertiesToElement()
.. seealso:: readXml()
.. note::

derived classes must call this base implementation when overriding this method
:rtype: bool
%End

};


Expand Down
2 changes: 2 additions & 0 deletions python/core/layout/qgslayoutitemmap.sip
Expand Up @@ -24,6 +24,8 @@ class QgsLayoutItemMap : QgsLayoutItem
%Docstring
Constructor for QgsLayoutItemMap, with the specified parent ``layout``.
%End
virtual int type() const;
virtual QString stringType() const;

protected:

Expand Down

0 comments on commit f0a6376

Please sign in to comment.