Add a signal to QgsLayoutContext when flags change

This commit is contained in:
Nyall Dawson 2017-10-11 07:24:25 +10:00
parent 91c3b5d255
commit 0143d0be68
6 changed files with 50 additions and 5 deletions

View File

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

View File

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

View File

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

View File

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

View File

@ -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 ) );

View File

@ -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()