Skip to content

Commit

Permalink
Move BlendMode enum and functions to QgsMapRenderer
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Mar 27, 2013
1 parent 87265c7 commit 4b1b2fb
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 75 deletions.
2 changes: 1 addition & 1 deletion src/app/qgsrasterlayerproperties.cpp
Expand Up @@ -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() ) );
Expand Down
46 changes: 3 additions & 43 deletions src/core/qgsmaplayer.cpp
Expand Up @@ -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();

Expand Down Expand Up @@ -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 );
Expand Down
31 changes: 4 additions & 27 deletions src/core/qgsmaplayer.h
Expand Up @@ -29,6 +29,7 @@
#include "qgis.h"
#include "qgserror.h"
#include "qgsrectangle.h"
#include "qgsmaprenderer.h"

class QgsRenderContext;
class QgsCoordinateReferenceSystem;
Expand All @@ -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
Expand Down Expand Up @@ -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*/
Expand Down Expand Up @@ -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;
Expand Down
40 changes: 39 additions & 1 deletion src/core/qgsmaprenderer.cpp
Expand Up @@ -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 )
{
Expand Down Expand Up @@ -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;
24 changes: 24 additions & 0 deletions src/core/qgsmaprenderer.h
Expand Up @@ -20,6 +20,7 @@
#include <QSize>
#include <QStringList>
#include <QVector>
#include <QPainter>

#include "qgis.h"
#include "qgsrectangle.h"
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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 );
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsvectorlayer.cpp
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/core/raster/qgsrasterlayer.cpp
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/gui/symbology-ng/qgsrendererv2propertiesdialog.cpp
Expand Up @@ -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()
Expand Down

0 comments on commit 4b1b2fb

Please sign in to comment.