Skip to content
Permalink
Browse files

Refactor layout context

Split render context from reporting context
  • Loading branch information
nyalldawson committed Jan 5, 2018
1 parent 9af7c63 commit 5bc543af6afaed1debe3471651ac1297694b7d70
Showing with 813 additions and 654 deletions.
  1. +2 −1 python/core/core_auto.sip
  2. +10 −3 python/core/layout/qgslayout.sip
  3. +3 −3 python/core/layout/qgslayoutexporter.sip
  4. +12 −88 python/core/layout/{qgslayoutcontext.sip → qgslayoutrendercontext.sip}
  5. +117 −0 python/core/layout/qgslayoutreportcontext.sip
  6. +1 −1 src/app/layout/qgslayoutaddpagesdialog.cpp
  7. +1 −1 src/app/layout/qgslayoutattributetablewidget.cpp
  8. +12 −12 src/app/layout/qgslayoutdesignerdialog.cpp
  9. +2 −2 src/app/layout/qgslayoutlegendwidget.cpp
  10. +2 −2 src/app/layout/qgslayoutmapgridwidget.cpp
  11. +4 −4 src/app/layout/qgslayoutmapwidget.cpp
  12. +2 −2 src/app/layout/qgslayoutpagepropertieswidget.cpp
  13. +1 −1 src/app/layout/qgslayoutpolygonwidget.cpp
  14. +1 −1 src/app/layout/qgslayoutpolylinewidget.cpp
  15. +3 −3 src/app/layout/qgslayoutpropertieswidget.cpp
  16. +2 −2 src/app/layout/qgslayoutshapewidget.cpp
  17. +4 −2 src/core/CMakeLists.txt
  18. +24 −13 src/core/layout/qgslayout.cpp
  19. +22 −8 src/core/layout/qgslayout.h
  20. +6 −6 src/core/layout/qgslayoutatlas.cpp
  21. +0 −169 src/core/layout/qgslayoutcontext.cpp
  22. +33 −33 src/core/layout/qgslayoutexporter.cpp
  23. +8 −7 src/core/layout/qgslayoutexporter.h
  24. +10 −10 src/core/layout/qgslayoutitem.cpp
  25. +6 −6 src/core/layout/qgslayoutitemattributetable.cpp
  26. +5 −5 src/core/layout/qgslayoutitemhtml.cpp
  27. +2 −2 src/core/layout/qgslayoutitemlabel.cpp
  28. +4 −4 src/core/layout/qgslayoutitemlegend.cpp
  29. +16 −15 src/core/layout/qgslayoutitemmap.cpp
  30. +1 −1 src/core/layout/qgslayoutitemnodeitem.cpp
  31. +5 −5 src/core/layout/qgslayoutitempage.cpp
  32. +12 −11 src/core/layout/qgslayoutitempicture.cpp
  33. +2 −2 src/core/layout/qgslayoutitempolygon.cpp
  34. +2 −2 src/core/layout/qgslayoutitempolyline.cpp
  35. +1 −1 src/core/layout/qgslayoutitemscalebar.cpp
  36. +2 −2 src/core/layout/qgslayoutitemshape.cpp
  37. +3 −2 src/core/layout/qgslayoutobject.cpp
  38. +111 −0 src/core/layout/qgslayoutrendercontext.cpp
  39. +16 −98 src/core/layout/{qgslayoutcontext.h → qgslayoutrendercontext.h}
  40. +82 −0 src/core/layout/qgslayoutreportcontext.cpp
  41. +135 −0 src/core/layout/qgslayoutreportcontext.h
  42. +1 −1 src/core/layout/qgslayouttable.cpp
  43. +2 −2 src/core/layout/qgslayoututils.cpp
  44. +2 −2 src/core/qgsapplication.cpp
  45. +9 −8 src/core/qgsexpressioncontext.cpp
  46. +5 −5 src/gui/layout/qgslayoutitemwidget.cpp
  47. +3 −3 src/gui/layout/qgslayoutmousehandles.cpp
  48. +2 −2 src/gui/layout/qgslayoutnewitempropertiesdialog.cpp
  49. +3 −3 tests/src/core/testqgslayout.cpp
  50. +2 −2 tests/src/core/testqgslayoutatlas.cpp
  51. +27 −26 tests/src/core/testqgslayoutcontext.cpp
  52. +2 −2 tests/src/core/testqgslayouthtml.cpp
  53. +19 −19 tests/src/core/testqgslayoutitem.cpp
  54. +5 −5 tests/src/core/testqgslayoutlabel.cpp
  55. +7 −7 tests/src/core/testqgslayoutmap.cpp
  56. +1 −1 tests/src/core/testqgslayoutpage.cpp
  57. +7 −7 tests/src/core/testqgslayouttable.cpp
  58. +6 −6 tests/src/core/testqgslayoututils.cpp
  59. +16 −16 tests/src/python/test_qgslayoutatlas.py
  60. +7 −7 tests/src/python/test_qgslayoutexporter.py
@@ -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
@@ -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
@@ -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


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

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

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

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

0 comments on commit 5bc543a

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