Skip to content

Commit

Permalink
Add a common base class for print layouts and reports, and adapt
Browse files Browse the repository at this point in the history
QgsLayoutManager to suit
  • Loading branch information
nyalldawson committed Jan 5, 2018
1 parent d8af098 commit 6f2c63f
Show file tree
Hide file tree
Showing 39 changed files with 543 additions and 210 deletions.
12 changes: 6 additions & 6 deletions python/core/composer/qgslayoutmanager.sip
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ as a result of a duplicate composition name).
.. seealso:: :py:func:`compositionAdded()`
%End

bool addLayout( QgsLayout *layout /Transfer/ );
bool addLayout( QgsMasterLayoutInterface *layout /Transfer/ );
%Docstring
Adds a ``layout`` to the manager. Ownership of the layout is transferred to the manager.
Returns true if the addition was successful, or false if the layout could not be added (eg
Expand All @@ -76,7 +76,7 @@ of removing a composition which is not contained in the manager).
.. seealso:: :py:func:`clear()`
%End

bool removeLayout( QgsLayout *layout );
bool removeLayout( QgsMasterLayoutInterface *layout );
%Docstring
Removes a ``layout`` from the manager. The layout is deleted.
Returns true if the removal was successful, or false if the removal failed (eg as a result
Expand All @@ -103,7 +103,7 @@ Removes and deletes all layouts from the manager.
Returns a list of all compositions contained in the manager.
%End

QList< QgsLayout * > layouts() const;
QList< QgsMasterLayoutInterface * > layouts() const;
%Docstring
Returns a list of all layouts contained in the manager.
%End
Expand All @@ -114,7 +114,7 @@ Returns the composition with a matching name, or None if no matching composition
were found.
%End

QgsLayout *layoutByName( const QString &name ) const;
QgsMasterLayoutInterface *layoutByName( const QString &name ) const;
%Docstring
Returns the layout with a matching name, or None if no matching layouts
were found.
Expand Down Expand Up @@ -148,7 +148,7 @@ composition will automatically be stored in the manager.
Returns new composition if duplication was successful.
%End

QgsLayout *duplicateLayout( const QgsLayout *layout, const QString &newName );
QgsMasterLayoutInterface *duplicateLayout( const QgsMasterLayoutInterface *layout, const QString &newName );
%Docstring
Duplicates an existing ``layout`` from the manager. The new
layout will automatically be stored in the manager.
Expand Down Expand Up @@ -214,7 +214,7 @@ Emitted when a layout is about to be removed from the manager
Emitted when a composition is renamed
%End

void layoutRenamed( QgsLayout *layout, const QString &newName );
void layoutRenamed( QgsMasterLayoutInterface *layout, const QString &newName );
%Docstring
Emitted when a layout is renamed
%End
Expand Down
3 changes: 2 additions & 1 deletion python/core/core_auto.sip
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@
%Include composer/qgspaperitem.sip
%Include layout/qgsabstractlayoutiterator.sip
%Include layout/qgsabstractreportsection.sip
%Include layout/qgsmasterlayoutinterface.sip
%Include layout/qgslayoutaligner.sip
%Include layout/qgslayoutexporter.sip
%Include layout/qgslayoutgridsettings.sip
Expand All @@ -175,7 +176,6 @@
%Include layout/qgslayoutsnapper.sip
%Include layout/qgslayoutundocommand.sip
%Include layout/qgslayoututils.sip
%Include layout/qgsreport.sip
%Include layout/qgsreportsectionfieldgroup.sip
%Include layout/qgsreportsectionlayout.sip
%Include metadata/qgslayermetadata.sip
Expand Down Expand Up @@ -444,6 +444,7 @@
%Include layout/qgslayouttablecolumn.sip
%Include layout/qgslayoutundostack.sip
%Include layout/qgsprintlayout.sip
%Include layout/qgsreport.sip
%Include symbology/qgscptcityarchive.sip
%Include symbology/qgssvgcache.sip
%Include symbology/qgsstyle.sip
Expand Down
4 changes: 2 additions & 2 deletions python/core/layout/qgsabstractreportsection.sip
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ sections form the body of the report section.
.. seealso:: :py:func:`children()`
%End

QList< QgsAbstractReportSection * > children() const;
QList< QgsAbstractReportSection * > childSections() const;
%Docstring
Return all child sections for this report section. The child
sections form the body of the report section.
Expand All @@ -221,7 +221,7 @@ sections form the body of the report section.
.. seealso:: :py:func:`removeChild()`
%End

QgsAbstractReportSection *child( int index );
QgsAbstractReportSection *childSection( int index );
%Docstring
Returns the child section at the specified ``index``.

Expand Down
23 changes: 1 addition & 22 deletions python/core/layout/qgslayout.sip
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ called on the new layout.

~QgsLayout();

virtual QgsLayout *clone() const /Factory/;
QgsLayout *clone() const /Factory/;
%Docstring
Creates a clone of the layout. Ownership of the return layout
is transferred to the caller.
Expand Down Expand Up @@ -86,20 +86,6 @@ relations and various other bits. It is never null.
Returns the items model attached to the layout.
%End

QString name() const;
%Docstring
Returns the layout's name.

.. seealso:: :py:func:`setName()`
%End

void setName( const QString &name );
%Docstring
Sets the layout's name.

.. seealso:: :py:func:`name()`
%End


QList<QgsLayoutItem *> selectedLayoutItems( const bool includeLockedItems = true );
%Docstring
Expand Down Expand Up @@ -624,13 +610,6 @@ If None, no item is selected.
%Docstring
Is emitted when the layout has been refreshed and items should also be refreshed
and updated.
%End

void nameChanged( const QString &name );
%Docstring
Emitted when the layout's name is changed.

.. seealso:: :py:func:`setName()`
%End

};
Expand Down
76 changes: 76 additions & 0 deletions python/core/layout/qgsmasterlayoutinterface.sip
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/layout/qgsmasterlayoutinterface.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/


class QgsMasterLayoutInterface
{
%Docstring
Interface for master layout type objects, such as print layouts and reports.

.. versionadded:: 3.0
%End

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

virtual ~QgsMasterLayoutInterface();

virtual QgsMasterLayoutInterface *clone() const = 0 /Factory/;
%Docstring
Creates a clone of the layout. Ownership of the returned layout
is transferred to the caller.
%End

virtual QString name() const = 0;
%Docstring
Returns the layout's name.

.. seealso:: :py:func:`setName()`
%End

virtual void setName( const QString &name ) = 0;
%Docstring
Sets the layout's name.

.. seealso:: :py:func:`name()`
%End

virtual QgsProject *layoutProject() const = 0;
%Docstring
The project associated with the layout. Used to get access to layers, map themes,
relations and various other bits. It is never null.
%End

virtual QDomElement writeLayoutXml( QDomDocument &document, const QgsReadWriteContext &context ) const = 0;
%Docstring
Returns the layout's state encapsulated in a DOM element.

.. seealso:: :py:func:`readLayoutXml()`
%End

virtual bool readLayoutXml( const QDomElement &layoutElement, const QDomDocument &document, const QgsReadWriteContext &context ) = 0;
%Docstring
Sets the layout's state from a DOM element. ``layoutElement`` is the DOM node corresponding to the layout.

.. seealso:: :py:func:`writeLayoutXml()`
%End

};




/************************************************************************
* This file has been generated automatically from *
* *
* src/core/layout/qgsmasterlayoutinterface.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
22 changes: 21 additions & 1 deletion python/core/layout/qgsprintlayout.sip
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@



class QgsPrintLayout : QgsLayout
class QgsPrintLayout : QgsLayout, QgsMasterLayoutInterface
{
%Docstring
Print layout, a QgsLayout subclass for static or atlas-based layouts.
Expand All @@ -28,19 +28,39 @@ Constructor for QgsPrintLayout.

virtual QgsPrintLayout *clone() const /Factory/;

virtual QgsProject *layoutProject() const;


QgsLayoutAtlas *atlas();
%Docstring
Returns the print layout's atlas.
%End

virtual QString name() const;
virtual void setName( const QString &name );


virtual QDomElement writeXml( QDomDocument &document, const QgsReadWriteContext &context ) const;

virtual bool readXml( const QDomElement &layoutElement, const QDomDocument &document, const QgsReadWriteContext &context );


virtual QDomElement writeLayoutXml( QDomDocument &document, const QgsReadWriteContext &context ) const;

virtual bool readLayoutXml( const QDomElement &layoutElement, const QDomDocument &document, const QgsReadWriteContext &context );

virtual QgsExpressionContext createExpressionContext() const;


signals:

void nameChanged( const QString &name );
%Docstring
Emitted when the layout's name is changed.

.. seealso:: :py:func:`setName()`
%End

};

/************************************************************************
Expand Down
25 changes: 18 additions & 7 deletions python/core/layout/qgsreport.sip
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@




class QgsReport : QgsAbstractReportSection
class QgsReport : QObject, QgsAbstractReportSection, QgsMasterLayoutInterface
{
%Docstring
Represents a report for use with the QgsLayout engine.
Expand Down Expand Up @@ -39,13 +38,25 @@ Constructor for QgsReport, associated with the specified
Note that ownership is not transferred to ``project``.
%End

QgsProject *project();
%Docstring
Returns the associated project.
%End

virtual QgsProject *layoutProject() const;
virtual QgsReport *clone() const /Factory/;

virtual QString name() const;
virtual void setName( const QString &name );

virtual QDomElement writeLayoutXml( QDomDocument &document, const QgsReadWriteContext &context ) const;

virtual bool readLayoutXml( const QDomElement &layoutElement, const QDomDocument &document, const QgsReadWriteContext &context );


signals:

void nameChanged( const QString &name );
%Docstring
Emitted when the report's name is changed.

.. seealso:: :py:func:`setName()`
%End

};

Expand Down
8 changes: 7 additions & 1 deletion python/gui/layout/qgslayoutdesignerinterface.sip
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,17 @@ Constructor for QgsLayoutDesignerInterface.

virtual QgsLayout *layout() = 0;
%Docstring
Returns the layout displayed in the designer.
Returns the current layout displayed in the designer.

.. seealso:: :py:func:`view()`
%End

virtual QgsMasterLayoutInterface *masterLayout() = 0;
%Docstring
Returns the master layout displayed in the designer.

.. seealso:: :py:func:`layout()`
%End

virtual QgsLayoutView *view() = 0;
%Docstring
Expand Down
2 changes: 1 addition & 1 deletion python/gui/qgisinterface.sip
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ Opens the layout manager dialog.
.. versionadded:: 3.0
%End

virtual QgsLayoutDesignerInterface *openLayoutDesigner( QgsLayout *layout ) = 0;
virtual QgsLayoutDesignerInterface *openLayoutDesigner( QgsMasterLayoutInterface *layout ) = 0;
%Docstring
Opens a new layout designer dialog for the specified ``layout``, or
brings an already open designer window to the foreground if one
Expand Down
Loading

0 comments on commit 6f2c63f

Please sign in to comment.