Skip to content
Permalink
Browse files

Move BlendMode enum and functions to QgsMapRenderer

  • Loading branch information
nyalldawson committed Mar 27, 2013
1 parent 87265c7 commit 4b1b2fbab2639b55c916164e4d73e1e485c13dfa
@@ -825,7 +825,7 @@ void QgsRasterLayerProperties::apply()
}

//set the blend mode for the layer
mRasterLayer->setBlendMode(( QgsMapLayer::BlendMode ) mBlendModeComboBox->blendMode() );
mRasterLayer->setBlendMode(( QgsMapRenderer::BlendMode ) mBlendModeComboBox->blendMode() );

//get the thumbnail for the layer
pixmapThumbnail->setPixmap( mRasterLayer->previewAsPixmap( pixmapThumbnail->size() ) );
@@ -50,7 +50,7 @@ QgsMapLayer::QgsMapLayer( QgsMapLayer::LayerType type,
mLayerOrigName( lyrname ), // store the original name
mID( "" ),
mLayerType( type ),
mBlendMode( QgsMapLayer::BlendNormal ) // Default to normal blending
mBlendMode( QgsMapRenderer::BlendNormal ) // Default to normal blending
{
mCRS = new QgsCoordinateReferenceSystem();

@@ -135,57 +135,17 @@ QgsRectangle QgsMapLayer::extent()
}

/** Write blend mode for layer */
void QgsMapLayer::setBlendMode( const QgsMapLayer::BlendMode blendMode )
void QgsMapLayer::setBlendMode( const QgsMapRenderer::BlendMode blendMode )
{
mBlendMode = blendMode;
}

/** Read blend mode for layer */
QgsMapLayer::BlendMode QgsMapLayer::blendMode() const
QgsMapRenderer::BlendMode QgsMapLayer::blendMode() const
{
return mBlendMode;
}

/** Returns a QPainter::CompositionMode corresponding to the current
* blend mode for this layer
*/
QPainter::CompositionMode QgsMapLayer::getCompositionMode()
{
// Map QgsMapLayer::BlendNormal to QPainter::CompositionMode
switch ( mBlendMode )
{
case QgsMapLayer::BlendNormal:
return QPainter::CompositionMode_SourceOver;
case QgsMapLayer::BlendLighten:
return QPainter::CompositionMode_Lighten;
case QgsMapLayer::BlendScreen:
return QPainter::CompositionMode_Screen;
case QgsMapLayer::BlendDodge:
return QPainter::CompositionMode_ColorDodge;
case QgsMapLayer::BlendAddition:
return QPainter::CompositionMode_Plus;
case QgsMapLayer::BlendDarken:
return QPainter::CompositionMode_Darken;
case QgsMapLayer::BlendMultiply:
return QPainter::CompositionMode_Multiply;
case QgsMapLayer::BlendBurn:
return QPainter::CompositionMode_ColorBurn;
case QgsMapLayer::BlendOverlay:
return QPainter::CompositionMode_Overlay;
case QgsMapLayer::BlendSoftLight:
return QPainter::CompositionMode_SoftLight;
case QgsMapLayer::BlendHardLight:
return QPainter::CompositionMode_HardLight;
case QgsMapLayer::BlendDifference:
return QPainter::CompositionMode_Difference;
case QgsMapLayer::BlendSubtract:
return QPainter::CompositionMode_Exclusion;
default:
return QPainter::CompositionMode_SourceOver;
}
}


bool QgsMapLayer::draw( QgsRenderContext& rendererContext )
{
Q_UNUSED( rendererContext );
@@ -29,6 +29,7 @@
#include "qgis.h"
#include "qgserror.h"
#include "qgsrectangle.h"
#include "qgsmaprenderer.h"

class QgsRenderContext;
class QgsCoordinateReferenceSystem;
@@ -54,26 +55,6 @@ class CORE_EXPORT QgsMapLayer : public QObject
PluginLayer // added in 1.5
};

/** Blending modes enum defining the available composition modes that can
* be used when rendering a layer
*/
enum BlendMode
{
BlendNormal,
BlendLighten,
BlendScreen,
BlendDodge,
BlendAddition,
BlendDarken,
BlendMultiply,
BlendBurn,
BlendOverlay,
BlendSoftLight,
BlendHardLight,
BlendDifference,
BlendSubtract
};

/** Constructor
* @param type Type of layer as defined in QgsMapLayer::LayerType enum
* @param lyrname Display Name of the layer
@@ -116,13 +97,9 @@ class CORE_EXPORT QgsMapLayer : public QObject
const QString& abstract() const { return mAbstract; }

/* Set the blending mode used for rendering a layer */
void setBlendMode( const QgsMapLayer::BlendMode blendMode );
void setBlendMode( const QgsMapRenderer::BlendMode blendMode );
/* Returns the current blending mode for a layer */
QgsMapLayer::BlendMode blendMode() const;
/** Returns a QPainter::CompositionMode corresponding to the
* current blending mode for the layer
*/
QPainter::CompositionMode getCompositionMode();
QgsMapRenderer::BlendMode blendMode() const;

/**Synchronises with changes in the datasource
@note added in version 1.6*/
@@ -494,7 +471,7 @@ class CORE_EXPORT QgsMapLayer : public QObject
QgsMapLayer::LayerType mLayerType;

/** Blend mode for the layer */
QgsMapLayer::BlendMode mBlendMode;
QgsMapRenderer::BlendMode mBlendMode;

/** Tag for embedding additional information */
QString mTag;
@@ -388,7 +388,7 @@ void QgsMapRenderer::render( QPainter* painter, double* forceWidthScale )

// Set the QPainter composition mode so that this layer is rendered using
// the desired blending mode
mypContextPainter->setCompositionMode( ml->getCompositionMode() );
mypContextPainter->setCompositionMode( getCompositionMode( ml->blendMode() ) );

if ( !ml->hasScaleBasedVisibility() || ( ml->minimumScale() <= mScale && mScale < ml->maximumScale() ) || mOverview )
{
@@ -1152,4 +1152,42 @@ const QgsCoordinateTransform* QgsMapRenderer::tr( QgsMapLayer *layer )
return QgsCoordinateTransformCache::instance()->transform( layer->crs().authid(), mDestCRS->authid() );
}

/** Returns a QPainter::CompositionMode corresponding to a QgsMapRenderer::BlendMode
*/
QPainter::CompositionMode QgsMapRenderer::getCompositionMode( const QgsMapRenderer::BlendMode blendMode )
{
// Map QgsMapRenderer::BlendNormal to QPainter::CompositionMode
switch ( blendMode )
{
case QgsMapRenderer::BlendNormal:
return QPainter::CompositionMode_SourceOver;
case QgsMapRenderer::BlendLighten:
return QPainter::CompositionMode_Lighten;
case QgsMapRenderer::BlendScreen:
return QPainter::CompositionMode_Screen;
case QgsMapRenderer::BlendDodge:
return QPainter::CompositionMode_ColorDodge;
case QgsMapRenderer::BlendAddition:
return QPainter::CompositionMode_Plus;
case QgsMapRenderer::BlendDarken:
return QPainter::CompositionMode_Darken;
case QgsMapRenderer::BlendMultiply:
return QPainter::CompositionMode_Multiply;
case QgsMapRenderer::BlendBurn:
return QPainter::CompositionMode_ColorBurn;
case QgsMapRenderer::BlendOverlay:
return QPainter::CompositionMode_Overlay;
case QgsMapRenderer::BlendSoftLight:
return QPainter::CompositionMode_SoftLight;
case QgsMapRenderer::BlendHardLight:
return QPainter::CompositionMode_HardLight;
case QgsMapRenderer::BlendDifference:
return QPainter::CompositionMode_Difference;
case QgsMapRenderer::BlendSubtract:
return QPainter::CompositionMode_Exclusion;
default:
return QPainter::CompositionMode_SourceOver;
}
}

bool QgsMapRenderer::mDrawing = false;
@@ -20,6 +20,7 @@
#include <QSize>
#include <QStringList>
#include <QVector>
#include <QPainter>

#include "qgis.h"
#include "qgsrectangle.h"
@@ -123,6 +124,26 @@ class CORE_EXPORT QgsMapRenderer : public QObject
//MAP_UNITS probably supported in future versions
};

/** Blending modes enum defining the available composition modes that can
* be used when rendering a layer
*/
enum BlendMode
{
BlendNormal,
BlendLighten,
BlendScreen,
BlendDodge,
BlendAddition,
BlendDarken,
BlendMultiply,
BlendBurn,
BlendOverlay,
BlendSoftLight,
BlendHardLight,
BlendDifference,
BlendSubtract
};

//! constructor
QgsMapRenderer();

@@ -230,6 +251,9 @@ class CORE_EXPORT QgsMapRenderer : public QObject
//! Added in QGIS v1.4
void setLabelingEngine( QgsLabelingEngineInterface* iface );

//! Returns a QPainter::CompositionMode corresponding to a BlendMode
QPainter::CompositionMode getCompositionMode( const QgsMapRenderer::BlendMode blendMode );

signals:

void drawingProgress( int current, int total );
@@ -2265,7 +2265,7 @@ bool QgsVectorLayer::readSymbology( const QDomNode& node, QString& errorMessage
if ( !blendModeNode.isNull() )
{
QDomElement e = blendModeNode.toElement();
setBlendMode(( QgsMapLayer::BlendMode ) e.text().toInt() );
setBlendMode(( QgsMapRenderer::BlendMode ) e.text().toInt() );
}

// use scale dependent visibility flag
@@ -2317,7 +2317,7 @@ bool QgsRasterLayer::readSymbology( const QDomNode& layer_node, QString& errorMe
if ( !blendModeNode.isNull() )
{
QDomElement e = blendModeNode.toElement();
setBlendMode(( QgsMapLayer::BlendMode ) e.text().toInt() );
setBlendMode(( QgsMapRenderer::BlendMode ) e.text().toInt() );
}

return true;
@@ -182,7 +182,7 @@ void QgsRendererV2PropertiesDialog::apply()
}

// set the blend mode for the layer
mLayer->setBlendMode(( QgsMapLayer::BlendMode ) mBlendModeComboBox->blendMode() );
mLayer->setBlendMode(( QgsMapRenderer::BlendMode ) mBlendModeComboBox->blendMode() );
}

void QgsRendererV2PropertiesDialog::onOK()

0 comments on commit 4b1b2fb

Please sign in to comment.
You can’t perform that action at this time.