10 changes: 9 additions & 1 deletion src/core/composer/qgscomposeritem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ QgsComposerItem::QgsComposerItem( QgsComposition* composition, bool manageZValue
, mVAlignSnapItem( 0 )
, mFrame( false )
, mBackground( true )
, mBackgroundColor( QColor( 255, 255, 255, 255 ) )
, mItemPositionLocked( false )
, mLastValidViewScaleFactor( -1 )
, mRotation( 0 )
Expand All @@ -72,6 +73,7 @@ QgsComposerItem::QgsComposerItem( qreal x, qreal y, qreal width, qreal height, Q
, mVAlignSnapItem( 0 )
, mFrame( false )
, mBackground( true )
, mBackgroundColor( QColor( 255, 255, 255, 255 ) )
, mItemPositionLocked( false )
, mLastValidViewScaleFactor( -1 )
, mRotation( 0 )
Expand Down Expand Up @@ -326,7 +328,7 @@ bool QgsComposerItem::_readXML( const QDomElement& itemElem, const QDomDocument&
if ( redOk && greenOk && blueOk && alphaOk )
{
QColor brushColor( bgRed, bgGreen, bgBlue, bgAlpha );
setBrush( QBrush( brushColor ) );
setBackgroundColor( brushColor );
}
}

Expand Down Expand Up @@ -884,6 +886,12 @@ void QgsComposerItem::drawBackground( QPainter* p )
}
}

void QgsComposerItem::setBackgroundColor( const QColor& backgroundColor )
{
mBackgroundColor = backgroundColor;
setBrush( QBrush( mBackgroundColor, Qt::SolidPattern ) );
}

void QgsComposerItem::setBlendMode( QPainter::CompositionMode blendMode )
{
mBlendMode = blendMode;
Expand Down
15 changes: 15 additions & 0 deletions src/core/composer/qgscomposeritem.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,19 @@ class CORE_EXPORT QgsComposerItem: public QObject, public QGraphicsRectItem
*/
void setBackgroundEnabled( bool drawBackground ) {mBackground = drawBackground;}

/** Gets the background color for this item
* @returns background color
* @note introduced in 2.0
*/
QColor backgroundColor() const { return mBackgroundColor; }

/** Sets the background color for this item
* @param backgroundColor new background color
* @returns nothing
* @note introduced in 2.0
*/
void setBackgroundColor( const QColor& backgroundColor );

/** Returns the item's composition blending mode */
QPainter::CompositionMode blendMode() const {return mBlendMode;}

Expand Down Expand Up @@ -309,6 +322,8 @@ class CORE_EXPORT QgsComposerItem: public QObject, public QGraphicsRectItem
bool mFrame;
/**True if item background needs to be painted*/
bool mBackground;
/**Background color*/
QColor mBackgroundColor;

/**True if item position and size cannot be changed with mouse move
@note: this member was added in version 1.2*/
Expand Down
22 changes: 19 additions & 3 deletions src/core/composer/qgscomposermap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,18 @@ void QgsComposerMap::cache( void )
double forcedWidthScaleFactor = w / requestExtent.width() / mapUnitsToMM();

mCacheImage = QImage( w, h, QImage::Format_ARGB32 );
mCacheImage.fill( QColor( 255, 255, 255, 0 ).rgba() ); // the background is drawn by composerItem, but we still need to start with that empty fill to avoid artifacts

if ( hasBackground() )
{
//Initially fill image with specified background color. This ensures that layers with blend modes will
//preview correctly
mCacheImage.fill( backgroundColor().rgba() );
}
else
{
//no background, but start with empty fill to avoid artifacts
mCacheImage.fill( QColor( 255, 255, 255, 0 ).rgba() );
}

double mapUnitsPerPixel = mExtent.width() / w;

Expand Down Expand Up @@ -257,10 +268,10 @@ void QgsComposerMap::paint( QPainter* painter, const QStyleOptionGraphicsItem* i
painter->save();
painter->setClipRect( thisPaintRect );

drawBackground( painter );

if ( mComposition->plotStyle() == QgsComposition::Preview && mPreviewMode == Rectangle )
{
// Fill with background color
drawBackground( painter );
QFont messageFont( "", 12 );
painter->setFont( messageFont );
painter->setPen( QColor( 0, 0, 0 ) );
Expand All @@ -272,6 +283,8 @@ void QgsComposerMap::paint( QPainter* painter, const QStyleOptionGraphicsItem* i
//Qt 4.4.0 and 4.4.1 have problems with recursive paintings
//QgsComposerMap::cache() and QgsComposerMap::update() need to be called by
//client functions

//Background color is already included in cached image, so no need to draw

QgsRectangle requestRectangle;
requestedExtent( requestRectangle );
Expand Down Expand Up @@ -323,6 +336,9 @@ void QgsComposerMap::paint( QPainter* painter, const QStyleOptionGraphicsItem* i
return;
}

// Fill with background color
drawBackground( painter );

QgsRectangle requestRectangle;
requestedExtent( requestRectangle );

Expand Down
12 changes: 10 additions & 2 deletions src/core/raster/qgsrasterdataprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,13 +341,21 @@ QString QgsRasterDataProvider::lastErrorFormat()
return "text/plain";
}

typedef QList<QPair<QString, QString> > pyramidResamplingMethods_t();
typedef QList<QPair<QString, QString> > *pyramidResamplingMethods_t();
QList<QPair<QString, QString> > QgsRasterDataProvider::pyramidResamplingMethods( QString providerKey )
{
pyramidResamplingMethods_t *pPyramidResamplingMethods = ( pyramidResamplingMethods_t * ) cast_to_fptr( QgsProviderRegistry::instance()->function( providerKey, "pyramidResamplingMethods" ) );
if ( pPyramidResamplingMethods )
{
return pPyramidResamplingMethods();
QList<QPair<QString, QString> > *methods = pPyramidResamplingMethods();
if ( !methods )
{
QgsDebugMsg( "provider pyramidResamplingMethods returned no methods" );
}
else
{
return *methods;
}
}
else
{
Expand Down
7 changes: 1 addition & 6 deletions src/core/symbology-ng/qgscategorizedsymbolrendererv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,7 @@ QgsSymbolV2* QgsCategorizedSymbolRendererV2::symbolForFeature( QgsFeature& featu
if ( symbol == NULL )
{
// if no symbol found use default one
//return symbolForValue( QVariant( "" ) );
// What is default? Empty string may be a legal value, and features not found
// should not be rendered using empty string value category symbology.
// We also need to get NULL in that case so that willRenderFeature()
// may be used to count features.
return 0;
return symbolForValue( QVariant( "" ) );
}

if ( mRotationFieldIdx == -1 && mSizeScaleFieldIdx == -1 )
Expand Down
23 changes: 13 additions & 10 deletions src/providers/gdal/qgsgdalprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2753,16 +2753,19 @@ QString QgsGdalProvider::validatePyramidsCreationOptions( RasterPyramidsFormat p
// by running one of the other resampling strategies below.
// see ticket #284

QGISEXTERN QList<QPair<QString, QString> > pyramidResamplingMethods()
QGISEXTERN QList<QPair<QString, QString> > *pyramidResamplingMethods()
{
QList<QPair<QString, QString> > methods;
methods.append( QPair<QString, QString>( "NEAREST", QObject::tr( "Nearest Neighbour" ) ) );
methods.append( QPair<QString, QString>( "AVERAGE", QObject::tr( "Average" ) ) );
methods.append( QPair<QString, QString>( "GAUSS", QObject::tr( "Gauss" ) ) );
methods.append( QPair<QString, QString>( "CUBIC", QObject::tr( "Cubic" ) ) );
methods.append( QPair<QString, QString>( "MODE", QObject::tr( "Mode" ) ) );
methods.append( QPair<QString, QString>( "NONE", QObject::tr( "None" ) ) );
static QList<QPair<QString, QString> > methods;

return methods;
}
if ( methods.isEmpty() )
{
methods.append( QPair<QString, QString>( "NEAREST", QObject::tr( "Nearest Neighbour" ) ) );
methods.append( QPair<QString, QString>( "AVERAGE", QObject::tr( "Average" ) ) );
methods.append( QPair<QString, QString>( "GAUSS", QObject::tr( "Gauss" ) ) );
methods.append( QPair<QString, QString>( "CUBIC", QObject::tr( "Cubic" ) ) );
methods.append( QPair<QString, QString>( "MODE", QObject::tr( "Mode" ) ) );
methods.append( QPair<QString, QString>( "NONE", QObject::tr( "None" ) ) );
}

return &methods;
}