Skip to content
Permalink
Browse files

Made point symbols respect the layer transparency setting. Fixes #1220

git-svn-id: http://svn.osgeo.org/qgis/trunk@11275 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
homann
homann committed Aug 5, 2009
1 parent 3ddd179 commit ca0b14db750fe6ad0fabafd5e9a75db6ebfeec22
@@ -739,7 +739,13 @@ bool QgsVectorLayer::draw( QgsRenderContext& rendererContext )

//QgsDebugMsg(QString("markerScale before renderFeature(): %1").arg(markerScaleFactor));
// markerScalerFactore reflects the wanted scaling of the marker
mRenderer->renderFeature( rendererContext, fet, &marker, sel );

double opacity = 1.0;
if ( !mRenderer->usesTransparency() )
{
opacity = ( mTransparencyLevel * 1.0) / 255.0;
}
mRenderer->renderFeature( rendererContext, fet, &marker, sel, opacity );

// markerScalerFactore now reflects the actual scaling of the marker that the render performed.
//QgsDebugMsg(QString("markerScale after renderFeature(): %1").arg(markerScaleFactor));
@@ -74,7 +74,7 @@ void QgsContinuousColorRenderer::setMaximumSymbol( QgsSymbol* sy )
mMaximumSymbol = sy;
}

void QgsContinuousColorRenderer::renderFeature( QgsRenderContext &renderContext, QgsFeature & f, QImage* img, bool selected )
void QgsContinuousColorRenderer::renderFeature( QgsRenderContext &renderContext, QgsFeature & f, QImage* img, bool selected, double opacity )
{
QPainter *p = renderContext.painter();

@@ -148,7 +148,9 @@ void QgsContinuousColorRenderer::renderFeature( QgsRenderContext &renderContext,
brush.setStyle( Qt::SolidPattern );

*img = QgsMarkerCatalogue::instance()->imageMarker( mMinimumSymbol->pointSymbolName(),
mMinimumSymbol->pointSize() * renderContext.scaleFactor() * renderContext.rasterScaleFactor(), pen, brush );
mMinimumSymbol->pointSize() * renderContext.scaleFactor() * renderContext.rasterScaleFactor(),
pen, brush, opacity );

}
else if ( mGeometryType == QGis::Line )
{
@@ -38,7 +38,7 @@ class CORE_EXPORT QgsContinuousColorRenderer: public QgsRenderer

/**Renders the feature using the minimum and maximum value of the classification field
* added in 1.2 */
void renderFeature( QgsRenderContext &renderContext, QgsFeature& f, QImage* img, bool selected );
void renderFeature( QgsRenderContext &renderContext, QgsFeature& f, QImage* img, bool selected, double opacity = 1.0 );

/**Returns the number of the classification field*/
int classificationField() const;
@@ -116,7 +116,7 @@ bool QgsGraduatedSymbolRenderer::willRenderFeature( QgsFeature *f )
return ( symbolForFeature( f ) != 0 );
}

void QgsGraduatedSymbolRenderer::renderFeature( QgsRenderContext &renderContext, QgsFeature & f, QImage* img, bool selected )
void QgsGraduatedSymbolRenderer::renderFeature( QgsRenderContext &renderContext, QgsFeature & f, QImage* img, bool selected, double opacity )
{
QPainter *p = renderContext.painter();
QgsSymbol* theSymbol = symbolForFeature( &f );
@@ -165,7 +165,8 @@ void QgsGraduatedSymbolRenderer::renderFeature( QgsRenderContext &renderContext,
oldName = theSymbol->pointSymbolName();
theSymbol->setNamedPointSymbol( name );
}
*img = theSymbol->getPointSymbolAsImage( renderContext.scaleFactor(), selected, mSelectionColor, fieldScale, rotation, renderContext.rasterScaleFactor() );
*img = theSymbol->getPointSymbolAsImage( renderContext.scaleFactor(), selected, mSelectionColor, fieldScale,
rotation, renderContext.rasterScaleFactor(), opacity );

if ( !oldName.isNull() )
{
@@ -71,7 +71,7 @@ class CORE_EXPORT QgsGraduatedSymbolRenderer: public QgsRenderer
\param f a pointer to a feature to render
\param t the transform object containing the information how to transform the map coordinates to screen coordinates
\note added in 1.2 */
void renderFeature( QgsRenderContext &renderContext, QgsFeature& f, QImage* img, bool selected );
void renderFeature( QgsRenderContext &renderContext, QgsFeature& f, QImage* img, bool selected, double opacity = 1.0 );

/**Sets the classicifation field by index
\param field the number of the field to classify*/
@@ -72,7 +72,11 @@ class CORE_EXPORT QgsRenderer

/**A vector layer passes features to a renderer object to change the brush and pen of the qpainter
@note added in 1.2 */
virtual void renderFeature( QgsRenderContext &renderContext, QgsFeature& f, QImage* pic, bool selected ) = 0;
//void renderFeature( QgsRenderContext &renderContext, QgsFeature& f, QImage* pic, bool selected )
//{
// void renderFeature( renderContext, f, pic, selected, 255);
//}
virtual void renderFeature( QgsRenderContext &renderContext, QgsFeature& f, QImage* pic, bool selected, double opacity = 1.0 ) = 0;

/**Reads the renderer configuration from an XML file
@param rnode the Dom node to read
@@ -94,7 +94,7 @@ void QgsSingleSymbolRenderer::addSymbol( QgsSymbol *sy )
updateSymbolAttributes();
}

void QgsSingleSymbolRenderer::renderFeature( QgsRenderContext &renderContext, QgsFeature & f, QImage* img, bool selected )
void QgsSingleSymbolRenderer::renderFeature( QgsRenderContext &renderContext, QgsFeature & f, QImage* img, bool selected, double opacity )
{
QPainter *p = renderContext.painter();

@@ -156,7 +156,7 @@ void QgsSingleSymbolRenderer::renderFeature( QgsRenderContext &renderContext, Qg
scale *= ( x2 - x1 ) * 0.001;
}

*img = sy->getPointSymbolAsImage( scale, selected, mSelectionColor, fieldScale, rotation, renderContext.rasterScaleFactor() );
*img = sy->getPointSymbolAsImage( scale, selected, mSelectionColor, fieldScale, rotation, renderContext.rasterScaleFactor(), opacity );
}

// Line, polygon
@@ -40,7 +40,7 @@ class CORE_EXPORT QgsSingleSymbolRenderer: public QgsRenderer

/**Renders a feature
* added in 1.2 */
void renderFeature( QgsRenderContext &renderContext, QgsFeature& f, QImage* img, bool selected );
void renderFeature( QgsRenderContext &renderContext, QgsFeature& f, QImage* img, bool selected, double opacity = 1.0 );

/**Reads the renderer configuration from an XML file
@param rnode the Dom node to read
@@ -105,7 +105,7 @@ bool QgsUniqueValueRenderer::willRenderFeature( QgsFeature *f )
return ( symbolForFeature( f ) != 0 );
}

void QgsUniqueValueRenderer::renderFeature( QgsRenderContext &renderContext, QgsFeature& f, QImage* img, bool selected )
void QgsUniqueValueRenderer::renderFeature( QgsRenderContext &renderContext, QgsFeature& f, QImage* img, bool selected, double opacity )
{
QPainter *p = renderContext.painter();
QgsSymbol* symbol = symbolForFeature( &f );
@@ -152,7 +152,8 @@ void QgsUniqueValueRenderer::renderFeature( QgsRenderContext &renderContext, Qgs
}

*img = symbol->getPointSymbolAsImage( renderContext.scaleFactor(), selected, mSelectionColor,
fieldScale, rotation, renderContext.rasterScaleFactor() );
fieldScale, rotation, renderContext.rasterScaleFactor(),
opacity );
if ( !oldName.isNull() )
{
symbol->setNamedPointSymbol( oldName );
@@ -34,7 +34,7 @@ class CORE_EXPORT QgsUniqueValueRenderer: public QgsRenderer

/** Render feature
* added in 1.2 */
void renderFeature( QgsRenderContext &renderContext, QgsFeature& f, QImage* img, bool selected );
void renderFeature( QgsRenderContext &renderContext, QgsFeature& f, QImage* img, bool selected, double opacity = 1.0 );

/**Reads the renderer configuration from an XML file
@param rnode the Dom node to read
@@ -113,7 +113,7 @@ QgsMarkerCatalogue *QgsMarkerCatalogue::instance()
return QgsMarkerCatalogue::mMarkerCatalogue;
}

QImage QgsMarkerCatalogue::imageMarker( QString fullName, double size, QPen pen, QBrush brush, bool qtBug )
QImage QgsMarkerCatalogue::imageMarker( QString fullName, double size, QPen pen, QBrush brush, double opacity )
{

//
@@ -149,6 +149,7 @@ QImage QgsMarkerCatalogue::imageMarker( QString fullName, double size, QPen pen,
QPainter myPainter;
myPainter.begin( &myImage );
myPainter.setRenderHint( QPainter::Antialiasing );
myPainter.setOpacity( opacity );

//
// Now pass the paintdevice along to have the marker rendered on it
@@ -182,7 +183,7 @@ QImage QgsMarkerCatalogue::imageMarker( QString fullName, double size, QPen pen,

if ( fullName.startsWith( "hard:" ) )
{
hardMarker( &myPainter, imageSize, fullName.mid( 5 ), size, pen, brush, qtBug );
hardMarker( &myPainter, imageSize, fullName.mid( 5 ), size, pen, brush);
#ifdef IMAGEDEBUG
QgsDebugMsg( "*** Saving hard marker to hardMarker.png ***" );
#ifdef QGISDEBUG
@@ -195,7 +196,7 @@ QImage QgsMarkerCatalogue::imageMarker( QString fullName, double size, QPen pen,
return QImage(); // empty
}

QPicture QgsMarkerCatalogue::pictureMarker( QString fullName, double size, QPen pen, QBrush brush, bool qtBug )
QPicture QgsMarkerCatalogue::pictureMarker( QString fullName, double size, QPen pen, QBrush brush, double opacity)
{

//
@@ -218,6 +219,7 @@ QPicture QgsMarkerCatalogue::pictureMarker( QString fullName, double size, QPen

QPainter myPainter( &myPicture );
myPainter.setRenderHint( QPainter::Antialiasing );
myPainter.setOpacity( opacity );

//
// Now pass the paintdevice along to have the marker rndered on it
@@ -233,7 +235,7 @@ QPicture QgsMarkerCatalogue::pictureMarker( QString fullName, double size, QPen

if ( fullName.left( 5 ) == "hard:" )
{
hardMarker( &myPainter, ( int ) size, fullName.mid( 5 ), size, pen, brush, qtBug );
hardMarker( &myPainter, ( int ) size, fullName.mid( 5 ), size, pen, brush );
return myPicture;
}

@@ -285,7 +287,7 @@ bool QgsMarkerCatalogue::svgMarker( QPainter * thepPainter, QString fileName, do
return true;
}

void QgsMarkerCatalogue::hardMarker( QPainter * thepPainter, int imageSize, QString name, double s, QPen pen, QBrush brush, bool qtBug )
void QgsMarkerCatalogue::hardMarker( QPainter * thepPainter, int imageSize, QString name, double s, QPen pen, QBrush brush )
{
// Size of polygon symbols is calculated so that the boundingbox is circumscribed
// around a circle with diameter mPointSize
@@ -43,12 +43,12 @@ class CORE_EXPORT QgsMarkerCatalogue : public QObject
/** Returns pixmap of the marker
* \param fullName full name, e.g. hard:circle, svg:/home/usr1/marker1.svg
*/
QImage imageMarker( QString fullName, double size, QPen pen, QBrush brush, bool qtBug = true );
QImage imageMarker( QString fullName, double size, QPen pen, QBrush brush, double opacity = 1.0);

/** Returns qpicture of the marker
* \param fullName full name, e.g. hard:circle, svg:/home/usr1/marker1.svg
*/
QPicture pictureMarker( QString fullName, double size, QPen pen, QBrush brush, bool qtBug = true );
QPicture pictureMarker( QString fullName, double size, QPen pen, QBrush brush, double opacity = 1.0 );

/** Returns a pixmap given a file name of a svg marker
* NOTE: this method needs to be public static for QgsMarkerDialog::visualizeMarkers */
@@ -71,7 +71,7 @@ class CORE_EXPORT QgsMarkerCatalogue : public QObject
QStringList mList;

/** Hard coded */
void hardMarker( QPainter * thepPainter, int imageSize, QString name, double size, QPen pen, QBrush brush, bool qtBug = true );
void hardMarker( QPainter * thepPainter, int imageSize, QString name, double size, QPen pen, QBrush brush );

bool fontMarker( QPainter * thepPainter, QString name, double size );

@@ -352,19 +352,19 @@ QImage QgsSymbol::getPolygonSymbolAsImage()
return img; //this is ok because of qts sharing mechanism
}

QImage QgsSymbol::getCachedPointSymbolAsImage( double widthScale,
bool selected, QColor selectionColor )
QImage QgsSymbol::getCachedPointSymbolAsImage( double widthScale, bool selected, QColor selectionColor, double opacity )
{
if ( !mCacheUpToDate2
|| ( selected && mSelectionColor != selectionColor ) )
|| ( selected && mSelectionColor != selectionColor ) || ( opacity != mOpacity ) )
{
if ( selected )
{
cache2( widthScale, selectionColor );
cache2( widthScale, selectionColor, opacity);
}
else
{
cache2( widthScale, mSelectionColor );

cache2( widthScale, mSelectionColor, opacity );
}
}

@@ -379,14 +379,15 @@ QImage QgsSymbol::getCachedPointSymbolAsImage( double widthScale,
}

QImage QgsSymbol::getPointSymbolAsImage( double widthScale, bool selected, QColor selectionColor, double scale,
double rotation, double rasterScaleFactor )
double rotation, double rasterScaleFactor, double opacity )
{

if ( 1.0 == ( scale * rasterScaleFactor ) && 0 == rotation )
{
if ( mWidthScale < 0 || widthScale == mWidthScale )
{
// If scale is 1.0 and rotation 0.0, use cached image.
return getCachedPointSymbolAsImage( widthScale, selected, selectionColor );
// If scale is 1.0, rotation 0.0 use cached image.
return getCachedPointSymbolAsImage( widthScale, selected, selectionColor, opacity );
}
}

@@ -402,18 +403,19 @@ QImage QgsSymbol::getPointSymbolAsImage( double widthScale, bool selected, QColo
preRotateImage = QgsMarkerCatalogue::instance()->imageMarker(
mPointSymbolName,
( float )( mSize * scale * widthScale * rasterScaleFactor ),
pen, mBrush );
pen, mBrush, opacity );
}
else
{
QgsDebugMsg( QString( "marker:%1 mPointSize:%2 mPointSizeUnits:%3 scale:%4 widthScale:%5 rasterScaleFactor:%6" )
.arg( mPointSymbolName )
.arg( mSize ).arg( mSizeInMapUnits ? "true" : "false" )
.arg( scale ).arg( widthScale ).arg( rasterScaleFactor ) );
QgsDebugMsg( QString( "marker:%1 mPointSize:%2 mPointSizeUnits:%3 scale:%4 widthScale:%5 rasterScaleFactor:%6 opacity:%7" )
.arg( mPointSymbolName ).arg( mSize ).arg( mSizeInMapUnits ? "true" : "false" )
.arg( scale ).arg( widthScale ).arg( rasterScaleFactor ).arg( opacity ) );


preRotateImage = QgsMarkerCatalogue::instance()->imageMarker(
mPointSymbolName,
( float )( mSize * scale * widthScale * rasterScaleFactor ),
pen, mBrush );
pen, mBrush, opacity );
}

QMatrix rotationMatrix;
@@ -443,26 +445,29 @@ void QgsSymbol::cache( QColor selectionColor )
mCacheUpToDate = true;
}

void QgsSymbol::cache2( double widthScale, QColor selectionColor )
void QgsSymbol::cache2( double widthScale, QColor selectionColor, double opacity )
{
// QgsDebugMsg(QString("widthScale = %1").arg(widthScale));

QPen pen = mPen;
pen.setWidthF( widthScale * pen.widthF() );

mPointSymbolImage2 = QgsMarkerCatalogue::instance()->imageMarker( mPointSymbolName, mSize * widthScale,
pen, mBrush, false );
pen, mBrush, opacity);

QBrush brush = mBrush;
brush.setColor( selectionColor );
pen.setColor( selectionColor );

mPointSymbolImageSelected2 = QgsMarkerCatalogue::instance()->imageMarker(
mPointSymbolName, mSize * widthScale, pen, brush, false );
mPointSymbolName, mSize * widthScale, pen, brush, opacity );

mSelectionColor2 = selectionColor;

mWidthScale = widthScale;

mOpacity = opacity;

mCacheUpToDate2 = true;
}

@@ -108,7 +108,9 @@ class CORE_EXPORT QgsSymbol
/** Get QImage representation of point symbol with current settings
*/
virtual QImage getCachedPointSymbolAsImage( double widthScale = 1.0,
bool selected = false, QColor selectionColor = Qt::yellow );
bool selected = false,
QColor selectionColor = Qt::yellow,
double opacity = 1.0);

/** Get QImage representation of point symbol with current settings
* and scaled (can be slow when scale != 1.0)
@@ -118,7 +120,8 @@ class CORE_EXPORT QgsSymbol
QColor selectionColor = Qt::yellow,
double scale = 1.0,
double rotation = 0.0,
double rasterScaleFactor = 1.0 );
double rasterScaleFactor = 1.0,
double opacity = 1.0);

/**Writes the contents of the symbol to a configuration file
@ return true in case of success*/
@@ -193,11 +196,14 @@ class CORE_EXPORT QgsSymbol
QImage mPointSymbolImage2;
QImage mPointSymbolImageSelected2;

/* The alpha channel of the symbol */
double mOpacity;

/* Create point symbol mPointSymbolImage/mPointSymbolImage cache */
void cache( QColor selectionColor );

/* Create point symbol mPointSymbolImage2 cache */
void cache2( double widthScale, QColor selectionColor );
void cache2( double widthScale, QColor selectionColor, double opacity);

/* mPointSymbolImage/mPointSymbolImage cache updated */
bool mCacheUpToDate;
@@ -92,7 +92,7 @@ bool OsmRenderer::willRenderFeature( QgsFeature *f )
}


void OsmRenderer::renderFeature( QgsRenderContext &renderContext, QgsFeature& f, QImage* pic, bool selected )
void OsmRenderer::renderFeature( QgsRenderContext &renderContext, QgsFeature& f, QImage* pic, bool selected, double opacity )
{
// QgsDebugMsg("RENDERING FEAT:" + f.id());
QPainter* p = renderContext.painter();
@@ -104,20 +104,20 @@ void OsmRenderer::renderFeature( QgsRenderContext &renderContext, QgsFeature& f,
QPen pen = osmstyle.get_pen( tags );
QColor penColor = pen.color();
p->setPen( osmstyle.get_pen( tags ) );
p->setOpacity( 1.0 );
p->setOpacity( opacity );
}
else if ( mGeomType == QGis::Polygon )
{
QBrush br;
p->setPen( osmstyle.get_pen_brush( tags, br ) );
p->setBrush( br );
p->setBackgroundMode( Qt::TransparentMode );
p->setOpacity( 0.5 );
p->setOpacity( opacity );
}
else if ( mGeomType == QGis::Point )
{
*pic = osmstyle.get_image( tags );
p->setOpacity( 1.0 );
p->setOpacity( opacity );
}
}

0 comments on commit ca0b14d

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