Skip to content

Commit

Permalink
Merge pull request #4877 from nyalldawson/layout_next
Browse files Browse the repository at this point in the history
Layouts, chapter II
  • Loading branch information
nyalldawson committed Jul 23, 2017
2 parents d570b43 + 54bf013 commit faa4a09
Show file tree
Hide file tree
Showing 70 changed files with 6,034 additions and 58 deletions.
6 changes: 5 additions & 1 deletion python/core/core_auto.sip
Expand Up @@ -153,12 +153,13 @@
%Include composer/qgscomposermultiframecommand.sip
%Include composer/qgscomposertexttable.sip
%Include composer/qgspaperitem.sip
%Include layout/qgslayout.sip
%Include layout/qgslayoutcontext.sip
%Include layout/qgslayoutmeasurement.sip
%Include layout/qgslayoutmeasurementconverter.sip
%Include layout/qgspagesizeregistry.sip
%Include layout/qgslayoutpoint.sip
%Include layout/qgslayoutsize.sip
%Include layout/qgslayoututils.sip
%Include metadata/qgslayermetadata.sip
%Include metadata/qgslayermetadatavalidator.sip
%Include processing/qgsprocessing.sip
Expand Down Expand Up @@ -378,8 +379,11 @@
%Include gps/qgsgpsdetector.sip
%Include gps/qgsnmeaconnection.sip
%Include gps/qgsgpsdconnection.sip
%Include layout/qgslayout.sip
%Include layout/qgslayoutitem.sip
%Include layout/qgslayoutitemmap.sip
%Include layout/qgslayoutitemregistry.sip
%Include layout/qgslayoutitemshape.sip
%Include layout/qgslayoutobject.sip
%Include symbology-ng/qgscptcityarchive.sip
%Include symbology-ng/qgssvgcache.sip
Expand Down
168 changes: 166 additions & 2 deletions python/core/layout/qgslayout.sip
Expand Up @@ -7,7 +7,8 @@
************************************************************************/


class QgsLayout : QGraphicsScene

class QgsLayout : QGraphicsScene, QgsExpressionContextGenerator
{
%Docstring
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Expand All @@ -24,7 +25,170 @@ class QgsLayout : QGraphicsScene
ZMapTool,
};

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

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

QString name() const;
%Docstring
Returns the layout's name.
.. seealso:: setName()
:rtype: str
%End

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

void setUnits( QgsUnitTypes::LayoutUnit units );
%Docstring
Sets the native measurement ``units`` for the layout. These also form the default unit
for measurements for the layout.
.. seealso:: units()
.. seealso:: convertToLayoutUnits()
%End

QgsUnitTypes::LayoutUnit units() const;
%Docstring
Returns the native units for the layout.
.. seealso:: setUnits()
.. seealso:: convertToLayoutUnits()
:rtype: QgsUnitTypes.LayoutUnit
%End

double convertToLayoutUnits( const QgsLayoutMeasurement &measurement ) const;
%Docstring
Converts a measurement into the layout's native units.
:return: length of measurement in layout units
.. seealso:: convertFromLayoutUnits()
.. seealso:: units()
:rtype: float
%End

QSizeF convertToLayoutUnits( const QgsLayoutSize &size ) const;
%Docstring
Converts a size into the layout's native units.
:return: size of measurement in layout units
.. seealso:: convertFromLayoutUnits()
.. seealso:: units()
:rtype: QSizeF
%End

QPointF convertToLayoutUnits( const QgsLayoutPoint &point ) const;
%Docstring
Converts a ``point`` into the layout's native units.
:return: point in layout units
.. seealso:: convertFromLayoutUnits()
.. seealso:: units()
:rtype: QPointF
%End

QgsLayoutMeasurement convertFromLayoutUnits( const double length, const QgsUnitTypes::LayoutUnit unit ) const;
%Docstring
Converts a ``length`` measurement from the layout's native units to a specified target ``unit``.
:return: length of measurement in specified units
.. seealso:: convertToLayoutUnits()
.. seealso:: units()
:rtype: QgsLayoutMeasurement
%End

QgsLayoutSize convertFromLayoutUnits( const QSizeF &size, const QgsUnitTypes::LayoutUnit unit ) const;
%Docstring
Converts a ``size`` from the layout's native units to a specified target ``unit``.
:return: size of measurement in specified units
.. seealso:: convertToLayoutUnits()
.. seealso:: units()
:rtype: QgsLayoutSize
%End

QgsLayoutPoint convertFromLayoutUnits( const QPointF &point, const QgsUnitTypes::LayoutUnit unit ) const;
%Docstring
Converts a ``point`` from the layout's native units to a specified target ``unit``.
:return: point in specified units
.. seealso:: convertToLayoutUnits()
.. seealso:: units()
:rtype: QgsLayoutPoint
%End

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


virtual QgsExpressionContext createExpressionContext() const;

%Docstring
Creates an expression context relating to the layout's current state. The context includes
scopes for global, project, layout and layout context properties.
:rtype: QgsExpressionContext
%End

void setCustomProperty( const QString &key, const QVariant &value );
%Docstring
Set a custom property for the layout.
\param key property key. If a property with the same key already exists it will be overwritten.
\param value property value
.. seealso:: customProperty()
.. seealso:: removeCustomProperty()
.. seealso:: customProperties()
%End

QVariant customProperty( const QString &key, const QVariant &defaultValue = QVariant() ) const;
%Docstring
Read a custom property from the layout.
\param key property key
\param defaultValue default value to return if property with matching key does not exist
:return: value of matching property
.. seealso:: setCustomProperty()
.. seealso:: removeCustomProperty()
.. seealso:: customProperties()
:rtype: QVariant
%End

void removeCustomProperty( const QString &key );
%Docstring
Remove a custom property from the layout.
\param key property key
.. seealso:: setCustomProperty()
.. seealso:: customProperty()
.. seealso:: customProperties()
%End

QStringList customProperties() const;
%Docstring
Return list of keys stored in custom properties for the layout.
.. seealso:: setCustomProperty()
.. seealso:: customProperty()
.. seealso:: removeCustomProperty()
:rtype: list of str
%End

QgsLayoutItemMap *referenceMap() const;
%Docstring
:rtype: QgsLayoutItemMap
%End

void setReferenceMap( QgsLayoutItemMap *map );

signals:

void variablesChanged();
%Docstring
Emitted whenever the expression variables stored in the layout have been changed.
%End

};

Expand Down
133 changes: 133 additions & 0 deletions python/core/layout/qgslayoutcontext.sip
@@ -0,0 +1,133 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/layout/qgslayoutcontext.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/



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

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

enum Flag
{
FlagDebug,
FlagOutlineOnly,
FlagAntialiasing,
FlagUseAdvancedEffects,
};
typedef QFlags<QgsLayoutContext::Flag> Flags;


QgsLayoutContext();

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

void setFlag( const QgsLayoutContext::Flag flag, const bool on = true );
%Docstring
Enables or disables a particular rendering ``flag`` for the layout. Other existing
flags are not affected.
.. seealso:: setFlags()
.. seealso:: flags()
.. seealso:: testFlag()
%End

QgsLayoutContext::Flags flags() const;
%Docstring
Returns the current combination of flags used for rendering the layout.
.. seealso:: setFlags()
.. seealso:: setFlag()
.. seealso:: testFlag()
:rtype: QgsLayoutContext.Flags
%End

bool testFlag( const Flag flag ) const;
%Docstring
Check whether a particular rendering ``flag`` is enabled for the layout.
.. seealso:: setFlags()
.. seealso:: setFlag()
.. seealso:: flags()
:rtype: bool
%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.
.. seealso:: 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:: setFeature()
:rtype: QgsFeature
%End

QgsVectorLayer *layer() const;
%Docstring
Returns the vector layer associated with the layout's context.
.. seealso:: setLayer()
:rtype: QgsVectorLayer
%End

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

void setDpi( double dpi );
%Docstring
Sets the ``dpi`` for outputting the layout. This also sets the
corresponding DPI for the context's measurementConverter().
.. seealso:: dpi()
%End

double dpi() const;
%Docstring
Returns the ``dpi`` for outputting the layout.
.. seealso:: setDpi()
:rtype: float
%End


QgsLayoutMeasurementConverter &measurementConverter();
%Docstring
Returns the layout measurement converter to be used in the layout. This converter is used
for translating between other measurement units and the layout's native unit.
:rtype: QgsLayoutMeasurementConverter
%End

};




/************************************************************************
* This file has been generated automatically from *
* *
* src/core/layout/qgslayoutcontext.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/

0 comments on commit faa4a09

Please sign in to comment.