21 changes: 21 additions & 0 deletions src/core/qgsmaplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "qgscoordinatereferencesystem.h"
#include "qgsapplication.h"
#include "qgsproject.h"
#include "qgsprojectfiletransform.h"
#include "qgsdatasourceuri.h"
#include "qgsvectorlayer.h"

Expand Down Expand Up @@ -778,6 +779,26 @@ QString QgsMapLayer::loadNamedStyle( const QString theURI, bool &theResultFlag )
return myErrorMessage;
}

// get style file version string, if any
QgsProjectVersion fileVersion( myDocument.firstChildElement( "qgis" ).attribute( "version" ) );
QgsProjectVersion thisVersion( QGis::QGIS_VERSION );

if ( thisVersion > fileVersion )
{
QgsLogger::warning( "Loading a style file that was saved with an older "
"version of qgis (saved in " + fileVersion.text() +
", loaded in " + QGis::QGIS_VERSION +
"). Problems may occur." );

QgsProjectFileTransform styleFile( myDocument, fileVersion );

styleFile.dump();

styleFile.updateRevision( thisVersion );

styleFile.dump();
}

// now get the layer node out and pass it over to the layer
// to deserialise...
QDomElement myRoot = myDocument.firstChildElement( "qgis" );
Expand Down
25 changes: 25 additions & 0 deletions src/core/qgsprojectfiletransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,31 @@ void QgsProjectFileTransform::transform1800to1900()
}
}

// SimpleFill symbol layer v2: avoid double transparency
// replacing alpha value of symbol layer's color with 255 (the
// transparency value is already stored as symbol transparency).
QDomNodeList rendererList = mDom.elementsByTagName( "renderer-v2" );
for ( int i = 0; i < rendererList.size(); ++i )
{
QDomNodeList layerList = rendererList.at( i ).toElement().elementsByTagName( "layer" );
for ( int j = 0; j < layerList.size(); ++j )
{
QDomElement layerElem = layerList.at( j ).toElement();
if ( layerElem.attribute( "class" ) == "SimpleFill" )
{
QDomNodeList propList = layerElem.elementsByTagName( "prop" );
for ( int k = 0; k < propList.size(); ++k )
{
QDomElement propElem = propList.at( k ).toElement();
if ( propElem.attribute( "k" ) == "color" || propElem.attribute( "k" ) == "color_border" )
{
propElem.setAttribute( "v", propElem.attribute( "v" ).section( ",", 0, 2 ) + ",255" );
}
}
}
}
}

QgsDebugMsg( mDom.toString() );
}

Expand Down
11 changes: 7 additions & 4 deletions src/core/symbology-ng/qgsfillsymbollayerv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ QString QgsSimpleFillSymbolLayerV2::layerType() const

void QgsSimpleFillSymbolLayerV2::startRender( QgsSymbolV2RenderContext& context )
{
mColor.setAlphaF( context.alpha() );
mBrush = QBrush( mColor, mBrushStyle );
QColor fillColor = mColor;
fillColor.setAlphaF( context.alpha() * mColor.alphaF() );
mBrush = QBrush( fillColor, mBrushStyle );

// scale brush content for printout
double rasterScaleFactor = context.renderContext().rasterScaleFactor();
Expand All @@ -87,8 +88,10 @@ void QgsSimpleFillSymbolLayerV2::startRender( QgsSymbolV2RenderContext& context
// this would mean symbols with "no fill" look the same whether or not they are selected
if ( selectFillStyle )
mSelBrush.setStyle( mBrushStyle );
mBorderColor.setAlphaF( context.alpha() );
mPen = QPen( mBorderColor );

QColor borderColor = mBorderColor;
borderColor.setAlphaF( context.alpha() * mBorderColor.alphaF());
mPen = QPen( borderColor );
mSelPen = QPen( selPenColor );
mPen.setStyle( mBorderStyle );
mPen.setWidthF( context.outputLineWidth( mBorderWidth ) );
Expand Down
2 changes: 1 addition & 1 deletion src/core/symbology-ng/qgslinesymbollayerv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ QString QgsSimpleLineSymbolLayerV2::layerType() const
void QgsSimpleLineSymbolLayerV2::startRender( QgsSymbolV2RenderContext& context )
{
QColor penColor = mColor;
penColor.setAlphaF( context.alpha() );
penColor.setAlphaF( mColor.alphaF() * context.alpha() );
mPen.setColor( penColor );
double scaledWidth = context.outputLineWidth( mWidth );
mPen.setWidthF( scaledWidth );
Expand Down
9 changes: 4 additions & 5 deletions src/core/symbology-ng/qgsmarkersymbollayerv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,10 @@ void QgsSimpleMarkerSymbolLayerV2::startRender( QgsSymbolV2RenderContext& contex
{
QColor brushColor = mColor;
QColor penColor = mBorderColor;
if ( context.alpha() < 1 )
{
penColor.setAlphaF( context.alpha() );
brushColor.setAlphaF( context.alpha() );
}

brushColor.setAlphaF( mColor.alphaF() * context.alpha() );
penColor.setAlphaF( mBorderColor.alphaF() * context.alpha() );

mBrush = QBrush( brushColor );
mPen = QPen( penColor );
mPen.setWidthF( context.outputLineWidth( mPen.widthF() ) );
Expand Down
20 changes: 10 additions & 10 deletions src/gui/symbology-ng/qgssymbollayerv2widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ void QgsSimpleLineSymbolLayerV2Widget::colorChanged()
// Native Mac dialog works only for Qt Carbon
// Qt bug: http://bugreports.qt.nokia.com/browse/QTBUG-14889
// FIXME need to also check max QT_VERSION when Qt bug fixed
QColor color = QColorDialog::getColor( mLayer->color(), this, "", QColorDialog::DontUseNativeDialog );
QColor color = QColorDialog::getColor( mLayer->color(), this, "", QColorDialog::DontUseNativeDialog | QColorDialog::ShowAlphaChannel);
#else
QColor color = QColorDialog::getColor( mLayer->color(), this );
QColor color = QColorDialog::getColor( mLayer->color(), this, "", QColorDialog::ShowAlphaChannel);
#endif
if ( !color.isValid() )
return;
Expand Down Expand Up @@ -259,9 +259,9 @@ void QgsSimpleMarkerSymbolLayerV2Widget::setColorBorder()
// Native Mac dialog works only for Qt Carbon
// Qt bug: http://bugreports.qt.nokia.com/browse/QTBUG-14889
// FIXME need to also check max QT_VERSION when Qt bug fixed
QColor borderColor = QColorDialog::getColor( mLayer->borderColor(), this, "", QColorDialog::DontUseNativeDialog );
QColor borderColor = QColorDialog::getColor( mLayer->borderColor(), this, "", QColorDialog::DontUseNativeDialog | QColorDialog::ShowAlphaChannel );
#else
QColor borderColor = QColorDialog::getColor( mLayer->borderColor(), this );
QColor borderColor = QColorDialog::getColor( mLayer->borderColor(), this, "", QColorDialog::ShowAlphaChannel );
#endif
if ( !borderColor.isValid() )
return;
Expand All @@ -276,9 +276,9 @@ void QgsSimpleMarkerSymbolLayerV2Widget::setColorFill()
// Native Mac dialog works only for Qt Carbon
// Qt bug: http://bugreports.qt.nokia.com/browse/QTBUG-14889
// FIXME need to also check max QT_VERSION when Qt bug fixed
QColor color = QColorDialog::getColor( mLayer->color(), this, "", QColorDialog::DontUseNativeDialog );
QColor color = QColorDialog::getColor( mLayer->color(), this, "", QColorDialog::DontUseNativeDialog | QColorDialog::ShowAlphaChannel );
#else
QColor color = QColorDialog::getColor( mLayer->color(), this );
QColor color = QColorDialog::getColor( mLayer->color(), this, "", QColorDialog::ShowAlphaChannel );
#endif
if ( !color.isValid() )
return;
Expand Down Expand Up @@ -357,9 +357,9 @@ void QgsSimpleFillSymbolLayerV2Widget::setColor()
// Native Mac dialog works only for Qt Carbon
// Qt bug: http://bugreports.qt.nokia.com/browse/QTBUG-14889
// FIXME need to also check max QT_VERSION when Qt bug fixed
QColor color = QColorDialog::getColor( mLayer->color(), this, "", QColorDialog::DontUseNativeDialog );
QColor color = QColorDialog::getColor( mLayer->color(), this, "", QColorDialog::DontUseNativeDialog | QColorDialog::ShowAlphaChannel);
#else
QColor color = QColorDialog::getColor( mLayer->color(), this );
QColor color = QColorDialog::getColor( mLayer->color(), this, "", QColorDialog::ShowAlphaChannel);
#endif
if ( !color.isValid() )
return;
Expand All @@ -374,9 +374,9 @@ void QgsSimpleFillSymbolLayerV2Widget::setBorderColor()
// Native Mac dialog works only for Qt Carbon
// Qt bug: http://bugreports.qt.nokia.com/browse/QTBUG-14889
// FIXME need to also check max QT_VERSION when Qt bug fixed
QColor color = QColorDialog::getColor( mLayer->borderColor(), this, "", QColorDialog::DontUseNativeDialog );
QColor color = QColorDialog::getColor( mLayer->borderColor(), this, "", QColorDialog::DontUseNativeDialog | QColorDialog::ShowAlphaChannel);
#else
QColor color = QColorDialog::getColor( mLayer->borderColor(), this );
QColor color = QColorDialog::getColor( mLayer->borderColor(), this, "", QColorDialog::ShowAlphaChannel);
#endif
if ( !color.isValid() )
return;
Expand Down