mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-17 00:04:02 -04:00
Add ability to define QImage format for render jobs via map settings
- Defaults to QImage::Format_ARGB32_Premultiplied, as before - Update labeling unit tests to use defined format
This commit is contained in:
parent
34aeed7450
commit
72c33799d3
@ -72,6 +72,11 @@ class QgsMapSettings
|
|||||||
Flags flags() const;
|
Flags flags() const;
|
||||||
bool testFlag( Flag flag ) const;
|
bool testFlag( Flag flag ) const;
|
||||||
|
|
||||||
|
//! sets format of internal QImage
|
||||||
|
void setOutputImageFormat( QImage::Format format );
|
||||||
|
//! format of internal QImage, default QImage::Format_ARGB32_Premultiplied
|
||||||
|
QImage::Format outputImageFormat() const;
|
||||||
|
|
||||||
bool hasValidSettings() const;
|
bool hasValidSettings() const;
|
||||||
QgsRectangle visibleExtent() const;
|
QgsRectangle visibleExtent() const;
|
||||||
double mapUnitsPerPixel() const;
|
double mapUnitsPerPixel() const;
|
||||||
|
@ -186,6 +186,7 @@ void QgsComposerMap::draw( QPainter *painter, const QgsRectangle& extent, const
|
|||||||
jobMapSettings.setMapUnits( ms.mapUnits() );
|
jobMapSettings.setMapUnits( ms.mapUnits() );
|
||||||
jobMapSettings.setBackgroundColor( Qt::transparent );
|
jobMapSettings.setBackgroundColor( Qt::transparent );
|
||||||
jobMapSettings.setShowSelection( false );
|
jobMapSettings.setShowSelection( false );
|
||||||
|
jobMapSettings.setOutputImageFormat( ms.outputImageFormat() );
|
||||||
|
|
||||||
//set layers to render
|
//set layers to render
|
||||||
QStringList theLayerSet = layersToRender();
|
QStringList theLayerSet = layersToRender();
|
||||||
|
@ -50,7 +50,7 @@ QgsMapRendererSequentialJob::QgsMapRendererSequentialJob( const QgsMapSettings&
|
|||||||
{
|
{
|
||||||
QgsDebugMsg( "SEQUENTIAL construct" );
|
QgsDebugMsg( "SEQUENTIAL construct" );
|
||||||
|
|
||||||
mImage = QImage( mSettings.outputSize(), QImage::Format_ARGB32_Premultiplied );
|
mImage = QImage( mSettings.outputSize(), mSettings.outputImageFormat() );
|
||||||
}
|
}
|
||||||
|
|
||||||
QgsMapRendererSequentialJob::~QgsMapRendererSequentialJob()
|
QgsMapRendererSequentialJob::~QgsMapRendererSequentialJob()
|
||||||
@ -639,7 +639,8 @@ LayerRenderJobs QgsMapRendererJob::prepareJobs( QPainter* painter, QgsPalLabelin
|
|||||||
// Flattened image for drawing when a blending mode is set
|
// Flattened image for drawing when a blending mode is set
|
||||||
QImage * mypFlattenedImage = 0;
|
QImage * mypFlattenedImage = 0;
|
||||||
mypFlattenedImage = new QImage( mSettings.outputSize().width(),
|
mypFlattenedImage = new QImage( mSettings.outputSize().width(),
|
||||||
mSettings.outputSize().height(), QImage::Format_ARGB32_Premultiplied );
|
mSettings.outputSize().height(),
|
||||||
|
mSettings.outputImageFormat() );
|
||||||
if ( mypFlattenedImage->isNull() )
|
if ( mypFlattenedImage->isNull() )
|
||||||
{
|
{
|
||||||
mErrors.append( Error( layerId, "Insufficient memory for image " + QString::number( mSettings.outputSize().width() ) + "x" + QString::number( mSettings.outputSize().height() ) ) );
|
mErrors.append( Error( layerId, "Insufficient memory for image " + QString::number( mSettings.outputSize().width() ) + "x" + QString::number( mSettings.outputSize().height() ) ) );
|
||||||
@ -915,7 +916,7 @@ void QgsMapRendererParallelJob::renderLabelsStatic( QgsMapRendererParallelJob* s
|
|||||||
|
|
||||||
QImage QgsMapRendererJob::composeImage( const QgsMapSettings& settings, const LayerRenderJobs& jobs )
|
QImage QgsMapRendererJob::composeImage( const QgsMapSettings& settings, const LayerRenderJobs& jobs )
|
||||||
{
|
{
|
||||||
QImage image( settings.outputSize(), QImage::Format_ARGB32_Premultiplied );
|
QImage image( settings.outputSize(), settings.outputImageFormat() );
|
||||||
image.fill( settings.backgroundColor().rgb() );
|
image.fill( settings.backgroundColor().rgb() );
|
||||||
|
|
||||||
QPainter painter( &image );
|
QPainter painter( &image );
|
||||||
|
@ -27,6 +27,7 @@ QgsMapSettings::QgsMapSettings()
|
|||||||
, mSelectionColor( Qt::yellow )
|
, mSelectionColor( Qt::yellow )
|
||||||
, mShowSelection( true )
|
, mShowSelection( true )
|
||||||
, mFlags( Antialiasing | UseAdvancedEffects | DrawLabeling )
|
, mFlags( Antialiasing | UseAdvancedEffects | DrawLabeling )
|
||||||
|
, mImageFormat( QImage::Format_ARGB32_Premultiplied )
|
||||||
{
|
{
|
||||||
updateDerived();
|
updateDerived();
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#define QGSMAPSETTINGS_H
|
#define QGSMAPSETTINGS_H
|
||||||
|
|
||||||
#include <QColor>
|
#include <QColor>
|
||||||
|
#include <QImage>
|
||||||
#include <QSize>
|
#include <QSize>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
|
|
||||||
@ -88,6 +89,11 @@ class CORE_EXPORT QgsMapSettings
|
|||||||
Flags flags() const;
|
Flags flags() const;
|
||||||
bool testFlag( Flag flag ) const;
|
bool testFlag( Flag flag ) const;
|
||||||
|
|
||||||
|
//! sets format of internal QImage
|
||||||
|
void setOutputImageFormat( QImage::Format format ) { mImageFormat = format; }
|
||||||
|
//! format of internal QImage, default QImage::Format_ARGB32_Premultiplied
|
||||||
|
QImage::Format outputImageFormat() const { return mImageFormat; }
|
||||||
|
|
||||||
bool hasValidSettings() const;
|
bool hasValidSettings() const;
|
||||||
QgsRectangle visibleExtent() const;
|
QgsRectangle visibleExtent() const;
|
||||||
double mapUnitsPerPixel() const;
|
double mapUnitsPerPixel() const;
|
||||||
@ -178,6 +184,8 @@ class CORE_EXPORT QgsMapSettings
|
|||||||
|
|
||||||
Flags mFlags;
|
Flags mFlags;
|
||||||
|
|
||||||
|
QImage::Format mImageFormat;
|
||||||
|
|
||||||
// derived properties
|
// derived properties
|
||||||
bool mValid; //!< whether the actual settings are valid (set in updateDerived())
|
bool mValid; //!< whether the actual settings are valid (set in updateDerived())
|
||||||
QgsRectangle mVisibleExtent; //!< extent with some additional white space that matches the output aspect ratio
|
QgsRectangle mVisibleExtent; //!< extent with some additional white space that matches the output aspect ratio
|
||||||
|
@ -233,6 +233,7 @@ class TestQgsPalLabeling(TestCase):
|
|||||||
ms.setCrsTransformEnabled(oms.hasCrsTransformEnabled())
|
ms.setCrsTransformEnabled(oms.hasCrsTransformEnabled())
|
||||||
ms.setMapUnits(oms.mapUnits())
|
ms.setMapUnits(oms.mapUnits())
|
||||||
ms.setExtent(oms.extent())
|
ms.setExtent(oms.extent())
|
||||||
|
ms.setOutputImageFormat(oms.outputImageFormat())
|
||||||
|
|
||||||
ms.setLayers(oms.layers())
|
ms.setLayers(oms.layers())
|
||||||
return ms
|
return ms
|
||||||
|
@ -123,19 +123,22 @@ class TestComposerBase(TestQgsPalLabeling):
|
|||||||
|
|
||||||
# noinspection PyUnusedLocal
|
# noinspection PyUnusedLocal
|
||||||
def _get_composer_image(self, width, height, dpi):
|
def _get_composer_image(self, width, height, dpi):
|
||||||
# image = QImage(QSize(width, height), QImage.Format_ARGB32)
|
image = QImage(QSize(width, height),
|
||||||
# image.fill(QColor(152, 219, 249).rgb())
|
self._TestMapSettings.outputImageFormat())
|
||||||
# image.setDotsPerMeterX(dpi / 25.4 * 1000)
|
image.fill(QColor(152, 219, 249).rgb())
|
||||||
# image.setDotsPerMeterY(dpi / 25.4 * 1000)
|
image.setDotsPerMeterX(dpi / 25.4 * 1000)
|
||||||
#
|
image.setDotsPerMeterY(dpi / 25.4 * 1000)
|
||||||
# p = QPainter(image)
|
|
||||||
# p.setRenderHint(QPainter.Antialiasing, False)
|
|
||||||
# p.setRenderHint(QPainter.HighQualityAntialiasing, False)
|
|
||||||
# self._c.renderPage(p, 0)
|
|
||||||
# p.end()
|
|
||||||
|
|
||||||
image = self._c.printPageAsRaster(0)
|
p = QPainter(image)
|
||||||
""":type: QImage"""
|
p.setRenderHint(
|
||||||
|
QPainter.Antialiasing,
|
||||||
|
self._TestMapSettings.testFlag(QgsMapSettings.Antialiasing)
|
||||||
|
)
|
||||||
|
self._c.renderPage(p, 0)
|
||||||
|
p.end()
|
||||||
|
|
||||||
|
# image = self._c.printPageAsRaster(0)
|
||||||
|
# """:type: QImage"""
|
||||||
|
|
||||||
if image.isNull():
|
if image.isNull():
|
||||||
return False, ''
|
return False, ''
|
||||||
@ -169,13 +172,18 @@ class TestComposerBase(TestQgsPalLabeling):
|
|||||||
if temp_size == os.path.getsize(svgpath):
|
if temp_size == os.path.getsize(svgpath):
|
||||||
return False, ''
|
return False, ''
|
||||||
|
|
||||||
image = QImage(width, height, QImage.Format_ARGB32)
|
image = QImage(width, height, self._TestMapSettings.outputImageFormat())
|
||||||
image.fill(QColor(152, 219, 249).rgb())
|
image.fill(QColor(152, 219, 249).rgb())
|
||||||
image.setDotsPerMeterX(dpi / 25.4 * 1000)
|
image.setDotsPerMeterX(dpi / 25.4 * 1000)
|
||||||
image.setDotsPerMeterY(dpi / 25.4 * 1000)
|
image.setDotsPerMeterY(dpi / 25.4 * 1000)
|
||||||
|
|
||||||
svgr = QSvgRenderer(svgpath)
|
svgr = QSvgRenderer(svgpath)
|
||||||
p = QPainter(image)
|
p = QPainter(image)
|
||||||
|
p.setRenderHint(
|
||||||
|
QPainter.Antialiasing,
|
||||||
|
self._TestMapSettings.testFlag(QgsMapSettings.Antialiasing)
|
||||||
|
)
|
||||||
|
p.setRenderHint(QPainter.TextAntialiasing)
|
||||||
svgr.render(p)
|
svgr.render(p)
|
||||||
p.end()
|
p.end()
|
||||||
|
|
||||||
|
@ -302,6 +302,7 @@ def mapSettingsString(ms):
|
|||||||
ms.testFlag(QgsMapSettings.DrawLabeling))
|
ms.testFlag(QgsMapSettings.DrawLabeling))
|
||||||
s += ' flag.DrawEditingInfo: {0}\n'.format(
|
s += ' flag.DrawEditingInfo: {0}\n'.format(
|
||||||
ms.testFlag(QgsMapSettings.DrawEditingInfo))
|
ms.testFlag(QgsMapSettings.DrawEditingInfo))
|
||||||
|
s += ' outputImageFormat(): {0}\n'.format(ms.outputImageFormat())
|
||||||
return s
|
return s
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user