Skip to content

Commit 4b1b2fb

Browse files
committed
Move BlendMode enum and functions to QgsMapRenderer
1 parent 87265c7 commit 4b1b2fb

File tree

8 files changed

+74
-75
lines changed

8 files changed

+74
-75
lines changed

src/app/qgsrasterlayerproperties.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,7 @@ void QgsRasterLayerProperties::apply()
825825
}
826826

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

830830
//get the thumbnail for the layer
831831
pixmapThumbnail->setPixmap( mRasterLayer->previewAsPixmap( pixmapThumbnail->size() ) );

src/core/qgsmaplayer.cpp

Lines changed: 3 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ QgsMapLayer::QgsMapLayer( QgsMapLayer::LayerType type,
5050
mLayerOrigName( lyrname ), // store the original name
5151
mID( "" ),
5252
mLayerType( type ),
53-
mBlendMode( QgsMapLayer::BlendNormal ) // Default to normal blending
53+
mBlendMode( QgsMapRenderer::BlendNormal ) // Default to normal blending
5454
{
5555
mCRS = new QgsCoordinateReferenceSystem();
5656

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

137137
/** Write blend mode for layer */
138-
void QgsMapLayer::setBlendMode( const QgsMapLayer::BlendMode blendMode )
138+
void QgsMapLayer::setBlendMode( const QgsMapRenderer::BlendMode blendMode )
139139
{
140140
mBlendMode = blendMode;
141141
}
142142

143143
/** Read blend mode for layer */
144-
QgsMapLayer::BlendMode QgsMapLayer::blendMode() const
144+
QgsMapRenderer::BlendMode QgsMapLayer::blendMode() const
145145
{
146146
return mBlendMode;
147147
}
148148

149-
/** Returns a QPainter::CompositionMode corresponding to the current
150-
* blend mode for this layer
151-
*/
152-
QPainter::CompositionMode QgsMapLayer::getCompositionMode()
153-
{
154-
// Map QgsMapLayer::BlendNormal to QPainter::CompositionMode
155-
switch ( mBlendMode )
156-
{
157-
case QgsMapLayer::BlendNormal:
158-
return QPainter::CompositionMode_SourceOver;
159-
case QgsMapLayer::BlendLighten:
160-
return QPainter::CompositionMode_Lighten;
161-
case QgsMapLayer::BlendScreen:
162-
return QPainter::CompositionMode_Screen;
163-
case QgsMapLayer::BlendDodge:
164-
return QPainter::CompositionMode_ColorDodge;
165-
case QgsMapLayer::BlendAddition:
166-
return QPainter::CompositionMode_Plus;
167-
case QgsMapLayer::BlendDarken:
168-
return QPainter::CompositionMode_Darken;
169-
case QgsMapLayer::BlendMultiply:
170-
return QPainter::CompositionMode_Multiply;
171-
case QgsMapLayer::BlendBurn:
172-
return QPainter::CompositionMode_ColorBurn;
173-
case QgsMapLayer::BlendOverlay:
174-
return QPainter::CompositionMode_Overlay;
175-
case QgsMapLayer::BlendSoftLight:
176-
return QPainter::CompositionMode_SoftLight;
177-
case QgsMapLayer::BlendHardLight:
178-
return QPainter::CompositionMode_HardLight;
179-
case QgsMapLayer::BlendDifference:
180-
return QPainter::CompositionMode_Difference;
181-
case QgsMapLayer::BlendSubtract:
182-
return QPainter::CompositionMode_Exclusion;
183-
default:
184-
return QPainter::CompositionMode_SourceOver;
185-
}
186-
}
187-
188-
189149
bool QgsMapLayer::draw( QgsRenderContext& rendererContext )
190150
{
191151
Q_UNUSED( rendererContext );

src/core/qgsmaplayer.h

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "qgis.h"
3030
#include "qgserror.h"
3131
#include "qgsrectangle.h"
32+
#include "qgsmaprenderer.h"
3233

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

57-
/** Blending modes enum defining the available composition modes that can
58-
* be used when rendering a layer
59-
*/
60-
enum BlendMode
61-
{
62-
BlendNormal,
63-
BlendLighten,
64-
BlendScreen,
65-
BlendDodge,
66-
BlendAddition,
67-
BlendDarken,
68-
BlendMultiply,
69-
BlendBurn,
70-
BlendOverlay,
71-
BlendSoftLight,
72-
BlendHardLight,
73-
BlendDifference,
74-
BlendSubtract
75-
};
76-
7758
/** Constructor
7859
* @param type Type of layer as defined in QgsMapLayer::LayerType enum
7960
* @param lyrname Display Name of the layer
@@ -116,13 +97,9 @@ class CORE_EXPORT QgsMapLayer : public QObject
11697
const QString& abstract() const { return mAbstract; }
11798

11899
/* Set the blending mode used for rendering a layer */
119-
void setBlendMode( const QgsMapLayer::BlendMode blendMode );
100+
void setBlendMode( const QgsMapRenderer::BlendMode blendMode );
120101
/* Returns the current blending mode for a layer */
121-
QgsMapLayer::BlendMode blendMode() const;
122-
/** Returns a QPainter::CompositionMode corresponding to the
123-
* current blending mode for the layer
124-
*/
125-
QPainter::CompositionMode getCompositionMode();
102+
QgsMapRenderer::BlendMode blendMode() const;
126103

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

496473
/** Blend mode for the layer */
497-
QgsMapLayer::BlendMode mBlendMode;
474+
QgsMapRenderer::BlendMode mBlendMode;
498475

499476
/** Tag for embedding additional information */
500477
QString mTag;

src/core/qgsmaprenderer.cpp

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ void QgsMapRenderer::render( QPainter* painter, double* forceWidthScale )
388388

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

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

1155+
/** Returns a QPainter::CompositionMode corresponding to a QgsMapRenderer::BlendMode
1156+
*/
1157+
QPainter::CompositionMode QgsMapRenderer::getCompositionMode( const QgsMapRenderer::BlendMode blendMode )
1158+
{
1159+
// Map QgsMapRenderer::BlendNormal to QPainter::CompositionMode
1160+
switch ( blendMode )
1161+
{
1162+
case QgsMapRenderer::BlendNormal:
1163+
return QPainter::CompositionMode_SourceOver;
1164+
case QgsMapRenderer::BlendLighten:
1165+
return QPainter::CompositionMode_Lighten;
1166+
case QgsMapRenderer::BlendScreen:
1167+
return QPainter::CompositionMode_Screen;
1168+
case QgsMapRenderer::BlendDodge:
1169+
return QPainter::CompositionMode_ColorDodge;
1170+
case QgsMapRenderer::BlendAddition:
1171+
return QPainter::CompositionMode_Plus;
1172+
case QgsMapRenderer::BlendDarken:
1173+
return QPainter::CompositionMode_Darken;
1174+
case QgsMapRenderer::BlendMultiply:
1175+
return QPainter::CompositionMode_Multiply;
1176+
case QgsMapRenderer::BlendBurn:
1177+
return QPainter::CompositionMode_ColorBurn;
1178+
case QgsMapRenderer::BlendOverlay:
1179+
return QPainter::CompositionMode_Overlay;
1180+
case QgsMapRenderer::BlendSoftLight:
1181+
return QPainter::CompositionMode_SoftLight;
1182+
case QgsMapRenderer::BlendHardLight:
1183+
return QPainter::CompositionMode_HardLight;
1184+
case QgsMapRenderer::BlendDifference:
1185+
return QPainter::CompositionMode_Difference;
1186+
case QgsMapRenderer::BlendSubtract:
1187+
return QPainter::CompositionMode_Exclusion;
1188+
default:
1189+
return QPainter::CompositionMode_SourceOver;
1190+
}
1191+
}
1192+
11551193
bool QgsMapRenderer::mDrawing = false;

src/core/qgsmaprenderer.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <QSize>
2121
#include <QStringList>
2222
#include <QVector>
23+
#include <QPainter>
2324

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

127+
/** Blending modes enum defining the available composition modes that can
128+
* be used when rendering a layer
129+
*/
130+
enum BlendMode
131+
{
132+
BlendNormal,
133+
BlendLighten,
134+
BlendScreen,
135+
BlendDodge,
136+
BlendAddition,
137+
BlendDarken,
138+
BlendMultiply,
139+
BlendBurn,
140+
BlendOverlay,
141+
BlendSoftLight,
142+
BlendHardLight,
143+
BlendDifference,
144+
BlendSubtract
145+
};
146+
126147
//! constructor
127148
QgsMapRenderer();
128149

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

254+
//! Returns a QPainter::CompositionMode corresponding to a BlendMode
255+
QPainter::CompositionMode getCompositionMode( const QgsMapRenderer::BlendMode blendMode );
256+
233257
signals:
234258

235259
void drawingProgress( int current, int total );

src/core/qgsvectorlayer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2265,7 +2265,7 @@ bool QgsVectorLayer::readSymbology( const QDomNode& node, QString& errorMessage
22652265
if ( !blendModeNode.isNull() )
22662266
{
22672267
QDomElement e = blendModeNode.toElement();
2268-
setBlendMode(( QgsMapLayer::BlendMode ) e.text().toInt() );
2268+
setBlendMode(( QgsMapRenderer::BlendMode ) e.text().toInt() );
22692269
}
22702270

22712271
// use scale dependent visibility flag

src/core/raster/qgsrasterlayer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2317,7 +2317,7 @@ bool QgsRasterLayer::readSymbology( const QDomNode& layer_node, QString& errorMe
23172317
if ( !blendModeNode.isNull() )
23182318
{
23192319
QDomElement e = blendModeNode.toElement();
2320-
setBlendMode(( QgsMapLayer::BlendMode ) e.text().toInt() );
2320+
setBlendMode(( QgsMapRenderer::BlendMode ) e.text().toInt() );
23212321
}
23222322

23232323
return true;

src/gui/symbology-ng/qgsrendererv2propertiesdialog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ void QgsRendererV2PropertiesDialog::apply()
182182
}
183183

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

188188
void QgsRendererV2PropertiesDialog::onOK()

0 commit comments

Comments
 (0)