Skip to content
Permalink
Browse files

Merge pull request #4910 from nyalldawson/layout_next

Layouts, chapter III
  • Loading branch information
nyalldawson committed Jul 26, 2017
2 parents 11dd417 + c89a15a commit f0a6376adb91df9d09bd0b19039c936f6058cee9
Showing with 5,162 additions and 401 deletions.
  1. +74 −55 python/core/composer/qgscomposeritem.sip
  2. +2 −0 python/core/core_auto.sip
  3. +41 −0 python/core/layout/qgslayout.sip
  4. +6 −0 python/core/layout/qgslayoutcontext.sip
  5. +117 −0 python/core/layout/qgslayoutitem.sip
  6. +2 −0 python/core/layout/qgslayoutitemmap.sip
  7. +91 −0 python/core/layout/qgslayoutitempage.sip
  8. +1 −0 python/core/layout/qgslayoutitemregistry.sip
  9. +3 −0 python/core/layout/qgslayoutitemshape.sip
  10. +22 −0 python/core/layout/qgslayoutobject.sip
  11. +206 −0 python/core/layout/qgslayoutpagecollection.sip
  12. +4 −2 python/core/layout/qgslayoututils.sip
  13. +16 −1 python/core/layout/qgspagesizeregistry.sip
  14. +20 −0 python/core/qgsunittypes.sip
  15. +1 −0 python/gui/gui_auto.sip
  16. +20 −7 python/gui/layout/qgslayoutitemguiregistry.sip
  17. +106 −0 python/gui/layout/qgslayoutitemwidget.sip
  18. +7 −0 python/gui/layout/qgslayoutnewitempropertiesdialog.sip
  19. +28 −0 python/gui/layout/qgslayoutunitscombobox.sip
  20. +42 −0 python/gui/layout/qgslayoutview.sip
  21. +6 −0 src/app/CMakeLists.txt
  22. +156 −0 src/app/layout/qgslayoutaddpagesdialog.cpp
  23. +91 −0 src/app/layout/qgslayoutaddpagesdialog.h
  24. +58 −0 src/app/layout/qgslayoutappmenuprovider.cpp
  25. +44 −0 src/app/layout/qgslayoutappmenuprovider.h
  26. +122 −25 src/app/layout/qgslayoutdesignerdialog.cpp
  27. +19 −0 src/app/layout/qgslayoutdesignerdialog.h
  28. +163 −0 src/app/layout/qgslayoutpagepropertieswidget.cpp
  29. +63 −0 src/app/layout/qgslayoutpagepropertieswidget.h
  30. +4 −0 src/core/CMakeLists.txt
  31. +74 −55 src/core/composer/qgscomposeritem.h
  32. +74 −1 src/core/layout/qgslayout.cpp
  33. +43 −1 src/core/layout/qgslayout.h
  34. +13 −0 src/core/layout/qgslayoutcontext.cpp
  35. +5 −0 src/core/layout/qgslayoutcontext.h
  36. +127 −4 src/core/layout/qgslayoutitem.cpp
  37. +109 −0 src/core/layout/qgslayoutitem.h
  38. +3 −0 src/core/layout/qgslayoutitemmap.h
  39. +168 −0 src/core/layout/qgslayoutitempage.cpp
  40. +98 −0 src/core/layout/qgslayoutitempage.h
  41. +2 −0 src/core/layout/qgslayoutitemregistry.cpp
  42. +4 −2 src/core/layout/qgslayoutitemregistry.h
  43. +4 −1 src/core/layout/qgslayoutitemshape.h
  44. +48 −0 src/core/layout/qgslayoutobject.cpp
  45. +21 −0 src/core/layout/qgslayoutobject.h
  46. +211 −0 src/core/layout/qgslayoutpagecollection.cpp
  47. +213 −0 src/core/layout/qgslayoutpagecollection.h
  48. +7 −2 src/core/layout/qgslayoututils.cpp
  49. +4 −2 src/core/layout/qgslayoututils.h
  50. +54 −30 src/core/layout/qgspagesizeregistry.cpp
  51. +13 −1 src/core/layout/qgspagesizeregistry.h
  52. +48 −0 src/core/qgsunittypes.cpp
  53. +18 −0 src/core/qgsunittypes.h
  54. +2 −0 src/gui/CMakeLists.txt
  55. +6 −3 src/gui/layout/qgslayoutitemguiregistry.cpp
  56. +24 −9 src/gui/layout/qgslayoutitemguiregistry.h
  57. +156 −0 src/gui/layout/qgslayoutitemwidget.cpp
  58. +150 −0 src/gui/layout/qgslayoutitemwidget.h
  59. +17 −1 src/gui/layout/qgslayoutnewitempropertiesdialog.cpp
  60. +7 −0 src/gui/layout/qgslayoutnewitempropertiesdialog.h
  61. +22 −26 src/gui/layout/qgslayoutruler.cpp
  62. +46 −19 src/gui/layout/qgslayoutunitscombobox.cpp
  63. +41 −0 src/gui/layout/qgslayoutunitscombobox.h
  64. +52 −8 src/gui/layout/qgslayoutview.cpp
  65. +38 −0 src/gui/layout/qgslayoutview.h
  66. +2 −1 src/gui/layout/qgslayoutviewtooladditem.cpp
  67. +17 −1 src/ui/layout/qgslayoutdesignerbase.ui
  68. +170 −131 src/ui/layout/qgslayoutnewitemproperties.ui
  69. +293 −0 src/ui/layout/qgslayoutnewpagedialog.ui
  70. +180 −0 src/ui/layout/qgslayoutpagepropertieswidget.ui
  71. +1 −0 tests/src/core/CMakeLists.txt
  72. +115 −0 tests/src/core/testqgslayout.cpp
  73. +23 −0 tests/src/core/testqgslayoutcontext.cpp
  74. +137 −0 tests/src/core/testqgslayoutitem.cpp
  75. +126 −0 tests/src/core/testqgslayoutobject.cpp
  76. +129 −0 tests/src/core/testqgslayoutpage.cpp
  77. +41 −3 tests/src/core/testqgslayoututils.cpp
  78. +13 −0 tests/src/core/testqgspagesizeregistry.cpp
  79. +14 −9 tests/src/gui/testqgslayoutview.cpp
  80. +1 −0 tests/src/python/CMakeLists.txt
  81. +378 −0 tests/src/python/test_qgslayoutpagecollection.py
  82. +34 −1 tests/src/python/test_qgslayoutunitscombobox.py
  83. +13 −0 tests/src/python/test_qgslayoutview.py
  84. +18 −0 tests/src/python/test_qgsunittypes.py
@@ -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:

@@ -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
@@ -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;
@@ -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();
@@ -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
@@ -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:

@@ -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
@@ -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();
@@ -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

};


@@ -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:

0 comments on commit f0a6376

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