Skip to content
Permalink
Browse files

Add a context class for layouts

Stores information relating to the current context (such as
associated feature and layer) and rendering settings for a layout.
  • Loading branch information
nyalldawson committed Jul 7, 2017
1 parent d70f53c commit b2b35dd08453908cbd1b011ab8ed24be3989f3a9
@@ -378,6 +378,7 @@
%Include gps/qgsgpsdetector.sip
%Include gps/qgsnmeaconnection.sip
%Include gps/qgsgpsdconnection.sip
%Include layout/qgslayoutcontext.sip
%Include layout/qgslayoutitem.sip
%Include layout/qgslayoutitemregistry.sip
%Include layout/qgslayoutobject.sip
@@ -0,0 +1,111 @@
/************************************************************************
* 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

};




/************************************************************************
* This file has been generated automatically from *
* *
* src/core/layout/qgslayoutcontext.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
@@ -350,6 +350,7 @@ SET(QGIS_CORE_SRCS
dxf/qgsdxfpallabeling.cpp

layout/qgslayout.cpp
layout/qgslayoutcontext.cpp
layout/qgslayoutitem.cpp
layout/qgslayoutitemregistry.cpp
layout/qgslayoutmeasurement.cpp
@@ -671,6 +672,7 @@ SET(QGIS_CORE_MOC_HDRS
gps/qgsgpsdconnection.h

layout/qgslayout.h
layout/qgslayoutcontext.h
layout/qgslayoutitem.h
layout/qgslayoutitemregistry.h
layout/qgslayoutobject.h
@@ -0,0 +1,56 @@
/***************************************************************************
qgslayoutcontext.cpp
--------------------
begin : July 2017
copyright : (C) 2017 by Nyall Dawson
email : nyall dot dawson at gmail dot com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgslayoutcontext.h"
#include "qgsfeature.h"


QgsLayoutContext::QgsLayoutContext()
: mFlags( FlagAntialiasing | FlagUseAdvancedEffects )
{}

void QgsLayoutContext::setFlags( const QgsLayoutContext::Flags flags )
{
mFlags = flags;
}

void QgsLayoutContext::setFlag( const QgsLayoutContext::Flag flag, const bool on )
{
if ( on )
mFlags |= flag;
else
mFlags &= ~flag;
}

QgsLayoutContext::Flags QgsLayoutContext::flags() const
{
return mFlags;
}

bool QgsLayoutContext::testFlag( const QgsLayoutContext::Flag flag ) const
{
return mFlags.testFlag( flag );
}

QgsVectorLayer *QgsLayoutContext::layer() const
{
return mLayer;
}

void QgsLayoutContext::setLayer( QgsVectorLayer *layer )
{
mLayer = layer;
}
@@ -0,0 +1,123 @@
/***************************************************************************
qgslayoutcontext.h
-------------------
begin : July 2017
copyright : (C) 2017 by Nyall Dawson
email : nyall dot dawson at gmail dot com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSLAYOUTCONTEXT_H
#define QGSLAYOUTCONTEXT_H

#include "qgis_core.h"
#include "qgsfeature.h"
#include "qgsvectorlayer.h"
#include <QtGlobal>

class QgsFeature;
class QgsVectorLayer;

/**
* \ingroup Layout
* \class QgsLayoutContext
* \brief Stores information relating to the current context and rendering settings for a layout.
* \since QGIS 3.0
*/
class CORE_EXPORT QgsLayoutContext
{

public:

//! Flags for controlling how a layout is rendered
enum Flag
{
FlagDebug = 1 << 1, //!< Debug/testing mode, items are drawn as solid rectangles.
FlagOutlineOnly = 1 << 2, //!< Render items as outlines only.
FlagAntialiasing = 1 << 3, //!< Use antialiasing when drawing items.
FlagUseAdvancedEffects = 1 << 4, //!< Enable advanced effects such as blend modes.
};
Q_DECLARE_FLAGS( Flags, Flag )

QgsLayoutContext();

/**
* Sets the combination of \a flags that will be used for rendering the layout.
* \see setFlag()
* \see flags()
* \see testFlag()
*/
void setFlags( const QgsLayoutContext::Flags flags );

/**
* Enables or disables a particular rendering \a flag for the layout. Other existing
* flags are not affected.
* \see setFlags()
* \see flags()
* \see testFlag()
*/
void setFlag( const QgsLayoutContext::Flag flag, const bool on = true );

/**
* Returns the current combination of flags used for rendering the layout.
* \see setFlags()
* \see setFlag()
* \see testFlag()
*/
QgsLayoutContext::Flags flags() const;

/**
* Check whether a particular rendering \a flag is enabled for the layout.
* \see setFlags()
* \see setFlag()
* \see flags()
*/
bool testFlag( const Flag flag ) const;

/**
* Sets the current \a feature for evaluating the layout. This feature may
* be used for altering an item's content and appearance for a report
* or atlas layout.
* \see feature()
*/
void setFeature( const QgsFeature &feature ) { mFeature = feature; }

/**
* 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.
* \see setFeature()
*/
QgsFeature feature() const { return mFeature; }

/**
* Returns the vector layer associated with the layout's context.
* \see setLayer()
*/
QgsVectorLayer *layer() const;

/**
* Sets the vector \a layer associated with the layout's context.
* \see layer()
*/
void setLayer( QgsVectorLayer *layer );

private:

Flags mFlags = 0;

QgsFeature mFeature;
QPointer< QgsVectorLayer > mLayer;

};

#endif //QGSLAYOUTCONTEXT_H



@@ -127,6 +127,7 @@ SET(TESTS
testqgslabelingengine.cpp
testqgslayertree.cpp
testqgslayout.cpp
testqgslayoutcontext.cpp
testqgslayoutitem.cpp
testqgslayoutobject.cpp
testqgslayoutunits.cpp

0 comments on commit b2b35dd

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