Skip to content
Permalink
Browse files

Add a signal to QgsLayoutContext when flags change

  • Loading branch information
nyalldawson committed Oct 10, 2017
1 parent 91c3b5d commit 0143d0be68b5bcf68290a02b103526f1ead31ff6
@@ -8,7 +8,7 @@



class QgsLayoutContext
class QgsLayoutContext : QObject
{
%Docstring
Stores information relating to the current context and rendering settings for a layout.
@@ -168,11 +168,20 @@ class QgsLayoutContext
:rtype: bool
%End

signals:

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

};





/************************************************************************
* This file has been generated automatically from *
* *
@@ -972,7 +972,6 @@ SET(QGIS_CORE_HDRS
composer/qgspaperitem.h

layout/qgslayoutaligner.h
layout/qgslayoutcontext.h
layout/qgslayoutgridsettings.h
layout/qgslayoutitemundocommand.h
layout/qgslayoutmeasurement.h
@@ -24,15 +24,26 @@ QgsLayoutContext::QgsLayoutContext()

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

mFlags = flags;
emit flagsChanged( mFlags );
}

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

if ( newFlags == mFlags )
return;

mFlags = newFlags;
emit flagsChanged( mFlags );
}

QgsLayoutContext::Flags QgsLayoutContext::flags() const
@@ -31,9 +31,11 @@ class QgsVectorLayer;
* \brief Stores information relating to the current context and rendering settings for a layout.
* \since QGIS 3.0
*/
class CORE_EXPORT QgsLayoutContext
class CORE_EXPORT QgsLayoutContext : public QObject
{

Q_OBJECT

public:

//! Flags for controlling how a layout is rendered
@@ -179,6 +181,14 @@ class CORE_EXPORT QgsLayoutContext
*/
bool pagesVisible() const { return mPagesVisible; }

signals:

/**
* Emitted whenever the context's \a flags change.
* \see setFlags()
*/
void flagsChanged( QgsLayoutContext::Flags flags );

private:

Flags mFlags = 0;
@@ -195,6 +205,8 @@ class CORE_EXPORT QgsLayoutContext

};

Q_DECLARE_METATYPE( QgsLayoutContext::Flags )

#endif //QGSLAYOUTCONTEXT_H


@@ -43,6 +43,7 @@
#include "qgsuserprofilemanager.h"
#include "qgsreferencedgeometry.h"
#include "qgs3drendererregistry.h"
#include "qgslayoutcontext.h"

#include "gps/qgsgpsconnectionregistry.h"
#include "processing/qgsprocessingregistry.h"
@@ -152,6 +153,7 @@ void QgsApplication::init( QString profileFolder )
qRegisterMetaType<QgsMessageLog::MessageLevel>( "QgsMessageLog::MessageLevel" );
qRegisterMetaType<QgsReferencedRectangle>( "QgsReferencedRectangle" );
qRegisterMetaType<QgsReferencedPointXY>( "QgsReferencedPointXY" );
qRegisterMetaType<QgsLayoutContext::Flags>( "QgsLayoutContext::Flags" );

QString prefixPath( getenv( "QGIS_PREFIX_PATH" ) ? getenv( "QGIS_PREFIX_PATH" ) : applicationDirPath() );
// QgsDebugMsg( QString( "prefixPath(): %1" ).arg( prefixPath ) );
@@ -21,6 +21,7 @@
#include "qgsvectorlayer.h"
#include <QObject>
#include "qgstest.h"
#include <QtTest/QSignalSpy>

class TestQgsLayoutContext: public QObject
{
@@ -81,16 +82,27 @@ void TestQgsLayoutContext::creation()
void TestQgsLayoutContext::flags()
{
QgsLayoutContext context;
QSignalSpy spyFlagsChanged( &context, &QgsLayoutContext::flagsChanged );

//test getting and setting flags
context.setFlags( QgsLayoutContext::Flags( QgsLayoutContext::FlagAntialiasing | QgsLayoutContext::FlagUseAdvancedEffects ) );
// default flags, so should be no signal
QCOMPARE( spyFlagsChanged.count(), 0 );

QVERIFY( context.flags() == ( QgsLayoutContext::FlagAntialiasing | QgsLayoutContext::FlagUseAdvancedEffects ) );
QVERIFY( context.testFlag( QgsLayoutContext::FlagAntialiasing ) );
QVERIFY( context.testFlag( QgsLayoutContext::FlagUseAdvancedEffects ) );
QVERIFY( ! context.testFlag( QgsLayoutContext::FlagDebug ) );
context.setFlag( QgsLayoutContext::FlagDebug );
QCOMPARE( spyFlagsChanged.count(), 1 );
QVERIFY( context.testFlag( QgsLayoutContext::FlagDebug ) );
context.setFlag( QgsLayoutContext::FlagDebug, false );
QCOMPARE( spyFlagsChanged.count(), 2 );
QVERIFY( ! context.testFlag( QgsLayoutContext::FlagDebug ) );
context.setFlag( QgsLayoutContext::FlagDebug, false ); //no change
QCOMPARE( spyFlagsChanged.count(), 2 );
context.setFlags( QgsLayoutContext::FlagDebug );
QCOMPARE( spyFlagsChanged.count(), 3 );
}

void TestQgsLayoutContext::feature()

0 comments on commit 0143d0b

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