mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-26 00:02:08 -05:00
Code shuffle, to make QgsLayoutContext aware of parent QgsLayout
This commit is contained in:
parent
4a7813b953
commit
92003c8797
@ -32,7 +32,10 @@ class QgsLayoutContext : QObject
|
||||
typedef QFlags<QgsLayoutContext::Flag> Flags;
|
||||
|
||||
|
||||
QgsLayoutContext();
|
||||
QgsLayoutContext( QgsLayout *layout /TransferThis/ );
|
||||
%Docstring
|
||||
Constructor for QgsLayoutContext.
|
||||
%End
|
||||
|
||||
void setFlags( const QgsLayoutContext::Flags flags );
|
||||
%Docstring
|
||||
|
@ -30,6 +30,7 @@
|
||||
|
||||
QgsLayout::QgsLayout( QgsProject *project )
|
||||
: mProject( project )
|
||||
, mContext( new QgsLayoutContext( this ) )
|
||||
, mSnapper( QgsLayoutSnapper( this ) )
|
||||
, mGridSettings( this )
|
||||
, mPageCollection( new QgsLayoutPageCollection( this ) )
|
||||
@ -281,32 +282,42 @@ QgsLayoutItem *QgsLayout::layoutItemAt( QPointF position, const QgsLayoutItem *b
|
||||
|
||||
double QgsLayout::convertToLayoutUnits( const QgsLayoutMeasurement &measurement ) const
|
||||
{
|
||||
return mContext.measurementConverter().convert( measurement, mUnits ).length();
|
||||
return mContext->measurementConverter().convert( measurement, mUnits ).length();
|
||||
}
|
||||
|
||||
QSizeF QgsLayout::convertToLayoutUnits( const QgsLayoutSize &size ) const
|
||||
{
|
||||
return mContext.measurementConverter().convert( size, mUnits ).toQSizeF();
|
||||
return mContext->measurementConverter().convert( size, mUnits ).toQSizeF();
|
||||
}
|
||||
|
||||
QPointF QgsLayout::convertToLayoutUnits( const QgsLayoutPoint &point ) const
|
||||
{
|
||||
return mContext.measurementConverter().convert( point, mUnits ).toQPointF();
|
||||
return mContext->measurementConverter().convert( point, mUnits ).toQPointF();
|
||||
}
|
||||
|
||||
QgsLayoutMeasurement QgsLayout::convertFromLayoutUnits( const double length, const QgsUnitTypes::LayoutUnit unit ) const
|
||||
{
|
||||
return mContext.measurementConverter().convert( QgsLayoutMeasurement( length, mUnits ), unit );
|
||||
return mContext->measurementConverter().convert( QgsLayoutMeasurement( length, mUnits ), unit );
|
||||
}
|
||||
|
||||
QgsLayoutSize QgsLayout::convertFromLayoutUnits( const QSizeF &size, const QgsUnitTypes::LayoutUnit unit ) const
|
||||
{
|
||||
return mContext.measurementConverter().convert( QgsLayoutSize( size.width(), size.height(), mUnits ), unit );
|
||||
return mContext->measurementConverter().convert( QgsLayoutSize( size.width(), size.height(), mUnits ), unit );
|
||||
}
|
||||
|
||||
QgsLayoutPoint QgsLayout::convertFromLayoutUnits( const QPointF &point, const QgsUnitTypes::LayoutUnit unit ) const
|
||||
{
|
||||
return mContext.measurementConverter().convert( QgsLayoutPoint( point.x(), point.y(), mUnits ), unit );
|
||||
return mContext->measurementConverter().convert( QgsLayoutPoint( point.x(), point.y(), mUnits ), unit );
|
||||
}
|
||||
|
||||
QgsLayoutContext &QgsLayout::context()
|
||||
{
|
||||
return *mContext;
|
||||
}
|
||||
|
||||
const QgsLayoutContext &QgsLayout::context() const
|
||||
{
|
||||
return *mContext;
|
||||
}
|
||||
|
||||
QgsLayoutGuideCollection &QgsLayout::guides()
|
||||
@ -709,7 +720,7 @@ void QgsLayout::writeXmlLayoutSettings( QDomElement &element, QDomDocument &docu
|
||||
element.setAttribute( QStringLiteral( "name" ), mName );
|
||||
element.setAttribute( QStringLiteral( "units" ), QgsUnitTypes::encodeUnit( mUnits ) );
|
||||
element.setAttribute( QStringLiteral( "worldFileMap" ), mWorldFileMapId );
|
||||
element.setAttribute( QStringLiteral( "printResolution" ), mContext.dpi() );
|
||||
element.setAttribute( QStringLiteral( "printResolution" ), mContext->dpi() );
|
||||
}
|
||||
|
||||
QDomElement QgsLayout::writeXml( QDomDocument &document, const QgsReadWriteContext &context ) const
|
||||
@ -753,7 +764,7 @@ bool QgsLayout::readXmlLayoutSettings( const QDomElement &layoutElement, const Q
|
||||
setName( layoutElement.attribute( QStringLiteral( "name" ) ) );
|
||||
setUnits( QgsUnitTypes::decodeLayoutUnit( layoutElement.attribute( QStringLiteral( "units" ) ) ) );
|
||||
mWorldFileMapId = layoutElement.attribute( QStringLiteral( "worldFileMap" ) );
|
||||
mContext.setDpi( layoutElement.attribute( QStringLiteral( "printResolution" ), "300" ).toDouble() );
|
||||
mContext->setDpi( layoutElement.attribute( QStringLiteral( "printResolution" ), "300" ).toDouble() );
|
||||
emit changed();
|
||||
|
||||
return true;
|
||||
|
@ -18,7 +18,6 @@
|
||||
|
||||
#include "qgis_core.h"
|
||||
#include <QGraphicsScene>
|
||||
#include "qgslayoutcontext.h"
|
||||
#include "qgslayoutsnapper.h"
|
||||
#include "qgsexpressioncontextgenerator.h"
|
||||
#include "qgslayoutgridsettings.h"
|
||||
@ -30,6 +29,7 @@ class QgsLayoutModel;
|
||||
class QgsLayoutMultiFrame;
|
||||
class QgsLayoutPageCollection;
|
||||
class QgsLayoutUndoStack;
|
||||
class QgsLayoutContext;
|
||||
|
||||
/**
|
||||
* \ingroup core
|
||||
@ -318,13 +318,13 @@ class CORE_EXPORT QgsLayout : public QGraphicsScene, public QgsExpressionContext
|
||||
* Returns a reference to the layout's context, which stores information relating to the
|
||||
* current context and rendering settings for the layout.
|
||||
*/
|
||||
QgsLayoutContext &context() { return mContext; }
|
||||
QgsLayoutContext &context();
|
||||
|
||||
/**
|
||||
* Returns a reference to the layout's context, which stores information relating to the
|
||||
* current context and rendering settings for the layout.
|
||||
*/
|
||||
SIP_SKIP const QgsLayoutContext &context() const { return mContext; }
|
||||
SIP_SKIP const QgsLayoutContext &context() const;
|
||||
|
||||
/**
|
||||
* Returns a reference to the layout's snapper, which stores handles layout snap grids and lines
|
||||
@ -629,7 +629,7 @@ class CORE_EXPORT QgsLayout : public QGraphicsScene, public QgsExpressionContext
|
||||
QgsObjectCustomProperties mCustomProperties;
|
||||
|
||||
QgsUnitTypes::LayoutUnit mUnits = QgsUnitTypes::LayoutMillimeters;
|
||||
QgsLayoutContext mContext;
|
||||
QgsLayoutContext *mContext = nullptr;
|
||||
QgsLayoutSnapper mSnapper;
|
||||
QgsLayoutGridSettings mGridSettings;
|
||||
|
||||
|
@ -16,10 +16,12 @@
|
||||
|
||||
#include "qgslayoutcontext.h"
|
||||
#include "qgsfeature.h"
|
||||
#include "qgslayout.h"
|
||||
|
||||
|
||||
QgsLayoutContext::QgsLayoutContext()
|
||||
: mFlags( FlagAntialiasing | FlagUseAdvancedEffects )
|
||||
QgsLayoutContext::QgsLayoutContext( QgsLayout *layout )
|
||||
: QObject( layout )
|
||||
, mFlags( FlagAntialiasing | FlagUseAdvancedEffects )
|
||||
, mLayout( layout )
|
||||
{}
|
||||
|
||||
void QgsLayoutContext::setFlags( const QgsLayoutContext::Flags flags )
|
||||
|
@ -49,7 +49,10 @@ class CORE_EXPORT QgsLayoutContext : public QObject
|
||||
};
|
||||
Q_DECLARE_FLAGS( Flags, Flag )
|
||||
|
||||
QgsLayoutContext();
|
||||
/**
|
||||
* Constructor for QgsLayoutContext.
|
||||
*/
|
||||
QgsLayoutContext( QgsLayout *layout SIP_TRANSFERTHIS );
|
||||
|
||||
/**
|
||||
* Sets the combination of \a flags that will be used for rendering the layout.
|
||||
@ -245,6 +248,8 @@ class CORE_EXPORT QgsLayoutContext : public QObject
|
||||
|
||||
Flags mFlags = nullptr;
|
||||
|
||||
QgsLayout *mLayout = nullptr;
|
||||
|
||||
int mCurrentExportLayer = -1;
|
||||
|
||||
QgsFeature mFeature;
|
||||
|
@ -75,14 +75,14 @@ void TestQgsLayoutContext::cleanup()
|
||||
|
||||
void TestQgsLayoutContext::creation()
|
||||
{
|
||||
QgsLayoutContext *context = new QgsLayoutContext();
|
||||
QgsLayoutContext *context = new QgsLayoutContext( nullptr );
|
||||
QVERIFY( context );
|
||||
delete context;
|
||||
}
|
||||
|
||||
void TestQgsLayoutContext::flags()
|
||||
{
|
||||
QgsLayoutContext context;
|
||||
QgsLayoutContext context( nullptr );
|
||||
QSignalSpy spyFlagsChanged( &context, &QgsLayoutContext::flagsChanged );
|
||||
|
||||
//test getting and setting flags
|
||||
@ -108,7 +108,7 @@ void TestQgsLayoutContext::flags()
|
||||
|
||||
void TestQgsLayoutContext::feature()
|
||||
{
|
||||
QgsLayoutContext context;
|
||||
QgsLayoutContext context( nullptr );
|
||||
|
||||
//test removing feature
|
||||
context.setFeature( QgsFeature() );
|
||||
@ -124,7 +124,7 @@ void TestQgsLayoutContext::feature()
|
||||
|
||||
void TestQgsLayoutContext::layer()
|
||||
{
|
||||
QgsLayoutContext context;
|
||||
QgsLayoutContext context( nullptr );
|
||||
|
||||
//test clearing layer
|
||||
context.setLayer( nullptr );
|
||||
@ -144,7 +144,7 @@ void TestQgsLayoutContext::layer()
|
||||
|
||||
void TestQgsLayoutContext::dpi()
|
||||
{
|
||||
QgsLayoutContext context;
|
||||
QgsLayoutContext context( nullptr );
|
||||
|
||||
QSignalSpy spyDpiChanged( &context, &QgsLayoutContext::dpiChanged );
|
||||
context.setDpi( 600 );
|
||||
@ -160,7 +160,7 @@ void TestQgsLayoutContext::dpi()
|
||||
|
||||
void TestQgsLayoutContext::renderContextFlags()
|
||||
{
|
||||
QgsLayoutContext context;
|
||||
QgsLayoutContext context( nullptr );
|
||||
context.setFlags( 0 );
|
||||
QgsRenderContext::Flags flags = context.renderContextFlags();
|
||||
QVERIFY( !( flags & QgsRenderContext::Antialiasing ) );
|
||||
@ -182,7 +182,7 @@ void TestQgsLayoutContext::renderContextFlags()
|
||||
|
||||
void TestQgsLayoutContext::boundingBoxes()
|
||||
{
|
||||
QgsLayoutContext context;
|
||||
QgsLayoutContext context( nullptr );
|
||||
context.setBoundingBoxesVisible( false );
|
||||
QVERIFY( !context.boundingBoxesVisible() );
|
||||
context.setBoundingBoxesVisible( true );
|
||||
@ -191,7 +191,7 @@ void TestQgsLayoutContext::boundingBoxes()
|
||||
|
||||
void TestQgsLayoutContext::exportLayer()
|
||||
{
|
||||
QgsLayoutContext context;
|
||||
QgsLayoutContext context( nullptr );
|
||||
// must default to -1
|
||||
QCOMPARE( context.currentExportLayer(), -1 );
|
||||
context.setCurrentExportLayer( 1 );
|
||||
|
Loading…
x
Reference in New Issue
Block a user