Skip to content

Commit

Permalink
Add a context class for layouts
Browse files Browse the repository at this point in the history
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 18, 2017
1 parent d70f53c commit b2b35dd
Show file tree
Hide file tree
Showing 7 changed files with 424 additions and 0 deletions.
1 change: 1 addition & 0 deletions python/core/core_auto.sip
Expand Up @@ -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
Expand Down
111 changes: 111 additions & 0 deletions python/core/layout/qgslayoutcontext.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 *
************************************************************************/
2 changes: 2 additions & 0 deletions src/core/CMakeLists.txt
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
56 changes: 56 additions & 0 deletions src/core/layout/qgslayoutcontext.cpp
@@ -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;
}
123 changes: 123 additions & 0 deletions src/core/layout/qgslayoutcontext.h
@@ -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



1 change: 1 addition & 0 deletions tests/src/core/CMakeLists.txt
Expand Up @@ -127,6 +127,7 @@ SET(TESTS
testqgslabelingengine.cpp
testqgslayertree.cpp
testqgslayout.cpp
testqgslayoutcontext.cpp
testqgslayoutitem.cpp
testqgslayoutobject.cpp
testqgslayoutunits.cpp
Expand Down

0 comments on commit b2b35dd

Please sign in to comment.