Skip to content

Commit

Permalink
Refactor layout context
Browse files Browse the repository at this point in the history
Split render context from reporting context
  • Loading branch information
nyalldawson committed Jan 5, 2018
1 parent 9af7c63 commit 5bc543a
Show file tree
Hide file tree
Showing 60 changed files with 813 additions and 654 deletions.
3 changes: 2 additions & 1 deletion python/core/core_auto.sip
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,6 @@
%Include gps/qgsgpsdconnection.sip
%Include layout/qgslayout.sip
%Include layout/qgslayoutatlas.sip
%Include layout/qgslayoutcontext.sip
%Include layout/qgslayouteffect.sip
%Include layout/qgslayoutguidecollection.sip
%Include layout/qgslayoutframe.sip
Expand All @@ -435,6 +434,8 @@
%Include layout/qgslayoutmultiframe.sip
%Include layout/qgslayoutpagecollection.sip
%Include layout/qgslayoutobject.sip
%Include layout/qgslayoutrendercontext.sip
%Include layout/qgslayoutreportcontext.sip
%Include layout/qgslayouttable.sip
%Include layout/qgslayouttablecolumn.sip
%Include layout/qgslayoutundostack.sip
Expand Down
13 changes: 10 additions & 3 deletions python/core/layout/qgslayout.sip
Original file line number Diff line number Diff line change
Expand Up @@ -309,10 +309,17 @@ Converts a ``point`` from the layout's native units to a specified target ``unit
.. seealso:: :py:func:`units()`
%End

QgsLayoutContext &context();
QgsLayoutRenderContext &renderContext();
%Docstring
Returns a reference to the layout's context, which stores information relating to the
current context and rendering settings for the layout.
Returns a reference to the layout's render context, which stores information relating to the
current rendering settings for the layout.
%End


QgsLayoutReportContext &reportContext();
%Docstring
Returns a reference to the layout's report context, which stores information relating to the
current reporting context for the layout.
%End


Expand Down
6 changes: 3 additions & 3 deletions python/core/layout/qgslayoutexporter.sip
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ Set to true to generate an external world file alongside
exported images.
%End

QgsLayoutContext::Flags flags;
QgsLayoutRenderContext::Flags flags;
%Docstring
Layout context flags, which control how the export will be created.
%End
Expand Down Expand Up @@ -244,7 +244,7 @@ correct appearance in the output.
This option is mutually exclusive with rasterizeWholeImage.
%End

QgsLayoutContext::Flags flags;
QgsLayoutRenderContext::Flags flags;
%Docstring
Layout context flags, which control how the export will be created.
%End
Expand Down Expand Up @@ -330,7 +330,7 @@ Note that this option is considered experimental, and the generated
SVG may differ from the expected appearance of the layout.
%End

QgsLayoutContext::Flags flags;
QgsLayoutRenderContext::Flags flags;
%Docstring
Layout context flags, which control how the export will be created.
%End
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/layout/qgslayoutcontext.h *
* src/core/layout/qgslayoutrendercontext.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/



class QgsLayoutContext : QObject
class QgsLayoutRenderContext : QObject
{
%Docstring
Stores information relating to the current context and rendering settings for a layout.
Stores information relating to the current rendering settings for a layout.

.. versionadded:: 3.0
%End

%TypeHeaderCode
#include "qgslayoutcontext.h"
#include "qgslayoutrendercontext.h"
%End
public:

Expand All @@ -30,15 +30,15 @@ class QgsLayoutContext : QObject
FlagForceVectorOutput,
FlagHideCoverageLayer,
};
typedef QFlags<QgsLayoutContext::Flag> Flags;
typedef QFlags<QgsLayoutRenderContext::Flag> Flags;


QgsLayoutContext( QgsLayout *layout /TransferThis/ );
QgsLayoutRenderContext( QgsLayout *layout /TransferThis/ );
%Docstring
Constructor for QgsLayoutContext.
Constructor for QgsLayoutRenderContext.
%End

void setFlags( const QgsLayoutContext::Flags flags );
void setFlags( const QgsLayoutRenderContext::Flags flags );
%Docstring
Sets the combination of ``flags`` that will be used for rendering the layout.

Expand All @@ -49,7 +49,7 @@ Sets the combination of ``flags`` that will be used for rendering the layout.
.. seealso:: :py:func:`testFlag()`
%End

void setFlag( const QgsLayoutContext::Flag flag, const bool on = true );
void setFlag( const QgsLayoutRenderContext::Flag flag, const bool on = true );
%Docstring
Enables or disables a particular rendering ``flag`` for the layout. Other existing
flags are not affected.
Expand All @@ -61,7 +61,7 @@ flags are not affected.
.. seealso:: :py:func:`testFlag()`
%End

QgsLayoutContext::Flags flags() const;
QgsLayoutRenderContext::Flags flags() const;
%Docstring
Returns the current combination of flags used for rendering the layout.

Expand All @@ -86,56 +86,6 @@ Check whether a particular rendering ``flag`` is enabled for the layout.
QgsRenderContext::Flags renderContextFlags() const;
%Docstring
Returns the combination of render context flags matched to the layout context's settings.
%End

void setFeature( const QgsFeature &feature );
%Docstring
Sets the current ``feature`` for evaluating the layout. This feature may
be used for altering an item's content and appearance for a report
or atlas layout.

Emits the changed() signal.

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

QgsFeature feature() const;
%Docstring
Returns the current feature for evaluating the layout. This feature may
be used for altering an item's content and appearance for a report
or atlas layout.

.. seealso:: :py:func:`currentGeometry()`

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

QgsGeometry currentGeometry( const QgsCoordinateReferenceSystem &crs = QgsCoordinateReferenceSystem() ) const;
%Docstring
Returns the current feature() geometry in the given ``crs``.
If no CRS is specified, the original feature geometry is returned.

Reprojection only works if a valid layer is set for layer().

.. seealso:: :py:func:`feature()`

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

QgsVectorLayer *layer() const;
%Docstring
Returns the vector layer associated with the layout's context.

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

void setLayer( QgsVectorLayer *layer );
%Docstring
Sets the vector ``layer`` associated with the layout's context.

Emits the changed() signal.

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

void setDpi( double dpi );
Expand Down Expand Up @@ -233,41 +183,15 @@ and customise their rendering based on the layer.
If ``layer`` is -1, all item layers should be rendered.

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

void setPredefinedScales( const QVector<qreal> &scales );
%Docstring
Sets the list of predefined ``scales`` to use with the layout. This is used
for maps which are set to the predefined atlas scaling mode.

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

QVector<qreal> predefinedScales() const;
%Docstring
Returns the current list of predefined scales for use with the layout.

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

signals:

void flagsChanged( QgsLayoutContext::Flags flags );
void flagsChanged( QgsLayoutRenderContext::Flags flags );
%Docstring
Emitted whenever the context's ``flags`` change.

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

void layerChanged( QgsVectorLayer *layer );
%Docstring
Emitted when the context's ``layer`` is changed.
%End

void changed();
%Docstring
Emitted certain settings in the context is changed, e.g. by setting a new feature or vector layer
for the context.
%End

void dpiChanged();
Expand All @@ -284,7 +208,7 @@ Emitted when the context's DPI is changed.
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/layout/qgslayoutcontext.h *
* src/core/layout/qgslayoutrendercontext.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
117 changes: 117 additions & 0 deletions python/core/layout/qgslayoutreportcontext.sip
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/layout/qgslayoutreportcontext.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/


class QgsLayoutReportContext : QObject
{
%Docstring
Stores information relating to the current reporting context for a layout.

.. versionadded:: 3.0
%End

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

QgsLayoutReportContext( QgsLayout *layout /TransferThis/ );
%Docstring
Constructor for QgsLayoutReportContext.
%End

void setFeature( const QgsFeature &feature );
%Docstring
Sets the current ``feature`` for evaluating the layout. This feature may
be used for altering an item's content and appearance for a report
or atlas layout.

Emits the changed() signal.

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

QgsFeature feature() const;
%Docstring
Returns the current feature for evaluating the layout. This feature may
be used for altering an item's content and appearance for a report
or atlas layout.

.. seealso:: :py:func:`currentGeometry()`

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

QgsGeometry currentGeometry( const QgsCoordinateReferenceSystem &crs = QgsCoordinateReferenceSystem() ) const;
%Docstring
Returns the current feature() geometry in the given ``crs``.
If no CRS is specified, the original feature geometry is returned.

Reprojection only works if a valid layer is set for layer().

.. seealso:: :py:func:`feature()`

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

QgsVectorLayer *layer() const;
%Docstring
Returns the vector layer associated with the layout's context.

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

void setLayer( QgsVectorLayer *layer );
%Docstring
Sets the vector ``layer`` associated with the layout's context.

Emits the changed() signal.

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

void setPredefinedScales( const QVector<qreal> &scales );
%Docstring
Sets the list of predefined ``scales`` to use with the layout. This is used
for maps which are set to the predefined atlas scaling mode.

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

QVector<qreal> predefinedScales() const;
%Docstring
Returns the current list of predefined scales for use with the layout.

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

signals:

void layerChanged( QgsVectorLayer *layer );
%Docstring
Emitted when the context's ``layer`` is changed.
%End

void changed();
%Docstring
Emitted certain settings in the context is changed, e.g. by setting a new feature or vector layer
for the context.
%End

};




/************************************************************************
* This file has been generated automatically from *
* *
* src/core/layout/qgslayoutreportcontext.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
2 changes: 1 addition & 1 deletion src/app/layout/qgslayoutaddpagesdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ QgsLayoutAddPagesDialog::QgsLayoutAddPagesDialog( QWidget *parent, Qt::WindowFla

void QgsLayoutAddPagesDialog::setLayout( QgsLayout *layout )
{
mConverter = layout->context().measurementConverter();
mConverter = layout->renderContext().measurementConverter();
mSizeUnitsComboBox->setConverter( &mConverter );
mExistingPageSpinBox->setMaximum( layout->pageCollection()->pageCount() );
mSizeUnitsComboBox->setUnit( layout->units() );
Expand Down
2 changes: 1 addition & 1 deletion src/app/layout/qgslayoutattributetablewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ QgsLayoutAttributeTableWidget::QgsLayoutAttributeTableWidget( QgsLayoutFrame *fr
connect( mTable, &QgsLayoutMultiFrame::changed, this, &QgsLayoutAttributeTableWidget::updateGuiElements );

// repopulate relations combo box if atlas layer changes
connect( &mTable->layout()->context(), &QgsLayoutContext::layerChanged,
connect( &mTable->layout()->reportContext(), &QgsLayoutReportContext::layerChanged,
this, &QgsLayoutAttributeTableWidget::updateRelationsCombo );

if ( QgsLayoutAtlas *atlas = layoutAtlas() )
Expand Down
Loading

0 comments on commit 5bc543a

Please sign in to comment.