Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Add measurement converter and dpi to layout context
- Loading branch information
|
@@ -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 |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
@@ -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 |
|
@@ -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 |
|
|
|
@@ -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(); |
|
|
} |
|
@@ -19,6 +19,7 @@ |
|
|
#include "qgis_core.h" |
|
|
#include "qgsfeature.h" |
|
|
#include "qgsvectorlayer.h" |
|
|
#include "qgslayoutmeasurementconverter.h" |
|
|
#include <QtGlobal> |
|
|
|
|
|
class QgsFeature; |
|
@@ -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 |
|
|
|
@@ -35,6 +35,7 @@ class TestQgsLayoutContext: public QObject |
|
|
void flags(); //test QgsLayout flags |
|
|
void feature(); |
|
|
void layer(); |
|
|
void dpi(); |
|
|
|
|
|
private: |
|
|
QString mReport; |
|
@@ -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" |