Skip to content

Commit

Permalink
Add measurement converter and dpi to layout context
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jul 18, 2017
1 parent b2b35dd commit cd380f6
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 2 deletions.
22 changes: 22 additions & 0 deletions python/core/layout/qgslayoutcontext.sip
Expand Up @@ -97,6 +97,28 @@ class QgsLayoutContext
.. seealso:: layer()
%End

void setDpi( double dpi );
%Docstring
Sets the ``dpi`` for outputting the layout. This also sets the
corresponding DPI for the context's measurementConverter().
.. seealso:: dpi()
%End

double dpi() const;
%Docstring
Returns the ``dpi`` for outputting the layout.
.. seealso:: setDpi()
:rtype: float
%End


QgsLayoutMeasurementConverter &measurementConverter();
%Docstring
Returns the layout measurement converter to be used in the layout. This converter is used
for translating between other measurement units and the layout's native unit.
:rtype: QgsLayoutMeasurementConverter
%End

};


Expand Down
3 changes: 1 addition & 2 deletions src/core/CMakeLists.txt
Expand Up @@ -672,7 +672,6 @@ 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 Expand Up @@ -918,7 +917,7 @@ SET(QGIS_CORE_HDRS
composer/qgscomposertexttable.h
composer/qgspaperitem.h

layout/qgslayout.h
layout/qgslayoutcontext.h
layout/qgslayoutmeasurement.h
layout/qgslayoutmeasurementconverter.h
layout/qgspagesizeregistry.h
Expand Down
10 changes: 10 additions & 0 deletions src/core/layout/qgslayoutcontext.cpp
Expand Up @@ -54,3 +54,13 @@ void QgsLayoutContext::setLayer( QgsVectorLayer *layer )
{
mLayer = layer;
}

void QgsLayoutContext::setDpi( double dpi )
{
mMeasurementConverter.setDpi( dpi );
}

double QgsLayoutContext::dpi() const
{
return mMeasurementConverter.dpi();
}
28 changes: 28 additions & 0 deletions src/core/layout/qgslayoutcontext.h
Expand Up @@ -19,6 +19,7 @@
#include "qgis_core.h"
#include "qgsfeature.h"
#include "qgsvectorlayer.h"
#include "qgslayoutmeasurementconverter.h"
#include <QtGlobal>

class QgsFeature;
Expand Down Expand Up @@ -108,13 +109,40 @@ class CORE_EXPORT QgsLayoutContext
*/
void setLayer( QgsVectorLayer *layer );

/**
* Sets the \a dpi for outputting the layout. This also sets the
* corresponding DPI for the context's measurementConverter().
* \see dpi()
*/
void setDpi( double dpi );

/**
* Returns the \a dpi for outputting the layout.
* \see setDpi()
*/
double dpi() const;

/**
* Returns the layout measurement converter to be used in the layout. This converter is used
* for translating between other measurement units and the layout's native unit.
*/
SIP_SKIP const QgsLayoutMeasurementConverter &measurementConverter() const { return mMeasurementConverter; }

/**
* Returns the layout measurement converter to be used in the layout. This converter is used
* for translating between other measurement units and the layout's native unit.
*/
QgsLayoutMeasurementConverter &measurementConverter() { return mMeasurementConverter; }

private:

Flags mFlags = 0;

QgsFeature mFeature;
QPointer< QgsVectorLayer > mLayer;

QgsLayoutMeasurementConverter mMeasurementConverter;

};

#endif //QGSLAYOUTCONTEXT_H
Expand Down
9 changes: 9 additions & 0 deletions tests/src/core/testqgslayoutcontext.cpp
Expand Up @@ -35,6 +35,7 @@ class TestQgsLayoutContext: public QObject
void flags(); //test QgsLayout flags
void feature();
void layer();
void dpi();

private:
QString mReport;
Expand Down Expand Up @@ -126,5 +127,13 @@ void TestQgsLayoutContext::layer()
delete layer;
}

void TestQgsLayoutContext::dpi()
{
QgsLayoutContext context;
context.setDpi( 600 );
QCOMPARE( context.dpi(), 600.0 );
QCOMPARE( context.measurementConverter().dpi(), 600.0 );
}

QGSTEST_MAIN( TestQgsLayoutContext )
#include "testqgslayoutcontext.moc"

0 comments on commit cd380f6

Please sign in to comment.