@@ -33,7 +33,8 @@ QgsComposerMapGrid::QgsComposerMapGrid( const QString& name, QgsComposerMap* map
3333 mLeftGridAnnotationPosition( QgsComposerMap::OutsideMapFrame ), mRightGridAnnotationPosition( QgsComposerMap::OutsideMapFrame ), mTopGridAnnotationPosition( QgsComposerMap::OutsideMapFrame ),
3434 mBottomGridAnnotationPosition( QgsComposerMap::OutsideMapFrame ), mAnnotationFrameDistance( 1.0 ), mLeftGridAnnotationDirection( QgsComposerMap::Horizontal ),
3535 mRightGridAnnotationDirection( QgsComposerMap::Horizontal ), mTopGridAnnotationDirection( QgsComposerMap::Horizontal ), mBottomGridAnnotationDirection( QgsComposerMap::Horizontal ), mGridAnnotationFormat( QgsComposerMap::Decimal ),
36- mGridFrameStyle( QgsComposerMap::NoGridFrame ), mGridFrameWidth( 2.0 ), mCrossLength( 3 ), mGridLineSymbol( 0 ), mGridUnit( MapUnit )
36+ mGridFrameStyle( QgsComposerMap::NoGridFrame ), mGridFrameWidth( 2.0 ), mGridFramePenThickness( 0.5 ), mGridFramePenColor( QColor( 0 , 0 , 0 ) )
37+ , mGridFrameFillColor1( Qt::white ), mGridFrameFillColor2( Qt::black ), mCrossLength( 3 ), mGridLineSymbol( 0 ), mGridUnit( MapUnit ), mBlendMode( QPainter::CompositionMode_SourceOver )
3738{
3839 // debug
3940 mGridLineSymbol = QgsLineSymbolV2::createSimple ( QgsStringMap () );
@@ -112,9 +113,13 @@ bool QgsComposerMapGrid::writeXML( QDomElement& elem, QDomDocument& doc ) const
112113 mapGridElem.setAttribute ( " offsetX" , qgsDoubleToString ( mGridOffsetX ) );
113114 mapGridElem.setAttribute ( " offsetY" , qgsDoubleToString ( mGridOffsetY ) );
114115 mapGridElem.setAttribute ( " crossLength" , qgsDoubleToString ( mCrossLength ) );
116+ QDomElement gridLineStyleElem = QgsSymbolLayerV2Utils::saveSymbol ( QString (), mGridLineSymbol , doc );
115117 mapGridElem.setAttribute ( " gridFrameStyle" , mGridFrameStyle );
116118 mapGridElem.setAttribute ( " gridFrameWidth" , qgsDoubleToString ( mGridFrameWidth ) );
117- QDomElement gridLineStyleElem = QgsSymbolLayerV2Utils::saveSymbol ( QString (), mGridLineSymbol , doc );
119+ mapGridElem.setAttribute ( " gridFramePenThickness" , qgsDoubleToString ( mGridFramePenThickness ) );
120+ mapGridElem.setAttribute ( " gridFramePenColor" , QgsSymbolLayerV2Utils::encodeColor ( mGridFramePenColor ) );
121+ mapGridElem.setAttribute ( " frameFillColor1" , QgsSymbolLayerV2Utils::encodeColor ( mGridFrameFillColor1 ) );
122+ mapGridElem.setAttribute ( " frameFillColor2" , QgsSymbolLayerV2Utils::encodeColor ( mGridFrameFillColor2 ) );
118123 if ( mCRS .isValid () )
119124 {
120125 mCRS .writeXML ( mapGridElem, doc );
@@ -136,6 +141,7 @@ bool QgsComposerMapGrid::writeXML( QDomElement& elem, QDomDocument& doc ) const
136141 mapGridElem.setAttribute ( " annotationFontColor" , QgsSymbolLayerV2Utils::encodeColor ( mGridAnnotationFontColor ) );
137142 mapGridElem.setAttribute ( " annotationPrecision" , mGridAnnotationPrecision );
138143 mapGridElem.setAttribute ( " unit" , mGridUnit );
144+ mapGridElem.setAttribute ( " blendMode" , mBlendMode );
139145
140146 elem.appendChild ( mapGridElem );
141147 return true ;
@@ -162,6 +168,10 @@ bool QgsComposerMapGrid::readXML( const QDomElement& itemElem, const QDomDocumen
162168 mCrossLength = itemElem.attribute ( " crossLength" , " 3" ).toDouble ();
163169 mGridFrameStyle = ( QgsComposerMap::GridFrameStyle )itemElem.attribute ( " gridFrameStyle" , " 0" ).toInt ();
164170 mGridFrameWidth = itemElem.attribute ( " gridFrameWidth" , " 2.0" ).toDouble ();
171+ mGridFramePenThickness = itemElem.attribute ( " gridFramePenThickness" , " 0.5" ).toDouble ();
172+ mGridFramePenColor = QgsSymbolLayerV2Utils::decodeColor ( itemElem.attribute ( " gridFramePenColor" , " 0,0,0" ) );
173+ mGridFrameFillColor1 = QgsSymbolLayerV2Utils::decodeColor ( itemElem.attribute ( " frameFillColor1" , " 255,255,255,255" ) );
174+ mGridFrameFillColor2 = QgsSymbolLayerV2Utils::decodeColor ( itemElem.attribute ( " frameFillColor2" , " 0,0,0,255" ) );
165175 QDomElement gridSymbolElem = itemElem.firstChildElement ( " symbol" );
166176 delete mGridLineSymbol ;
167177 if ( gridSymbolElem.isNull ( ) )
@@ -187,6 +197,7 @@ bool QgsComposerMapGrid::readXML( const QDomElement& itemElem, const QDomDocumen
187197 {
188198 mCRS = QgsCoordinateReferenceSystem ();
189199 }
200+ mBlendMode = ( QPainter::CompositionMode )( itemElem.attribute ( " blendMode" , " 0" ).toUInt () );
190201
191202 // annotation
192203 mShowGridAnnotation = ( itemElem.attribute ( " showAnnotation" , " 0" ) != " 0" );
@@ -222,9 +233,6 @@ void QgsComposerMapGrid::drawGridCRSTransform( QPainter* painter ) const
222233 return ;
223234 }
224235
225- painter->save ();
226- painter->setRenderHint ( QPainter::Antialiasing );
227-
228236 // x grid lines
229237 QList< QPair< double , QPolygonF > > xGridLines;
230238 xGridLinesCRSTransform ( crsBoundingRect, inverseTr, xGridLines );
@@ -267,7 +275,6 @@ void QgsComposerMapGrid::drawGridCRSTransform( QPainter* painter ) const
267275 {
268276 drawCoordinateAnnotations ( painter, horizontalLines, verticalLines );
269277 }
270- painter->restore ();
271278}
272279
273280void QgsComposerMapGrid::drawGrid ( QPainter* p ) const
@@ -277,6 +284,10 @@ void QgsComposerMapGrid::drawGrid( QPainter* p ) const
277284 return ;
278285 }
279286
287+ p->save ();
288+ p->setCompositionMode ( mBlendMode );
289+ p->setRenderHint ( QPainter::Antialiasing );
290+
280291 // is grid in a different crs than map
281292 const QgsMapSettings& ms = mComposerMap ->composition ()->mapSettings ();
282293 if ( mGridUnit == MapUnit && mCRS .isValid () && mCRS != ms.destinationCrs () )
@@ -359,6 +370,8 @@ void QgsComposerMapGrid::drawGrid( QPainter* p ) const
359370 {
360371 drawCoordinateAnnotations ( p, horizontalLines, verticalLines );
361372 }
373+
374+ p->restore ();
362375}
363376
364377void QgsComposerMapGrid::drawGridFrame ( QPainter* p, const QList< QPair< double , QLineF > >& hLines, const QList< QPair< double , QLineF > >& vLines ) const
@@ -417,7 +430,7 @@ void QgsComposerMapGrid::drawGridFrameBorder( QPainter* p, const QMap< double, d
417430 }
418431
419432 double currentCoord = - mGridFrameWidth ;
420- bool white = true ;
433+ bool color1 = true ;
421434 double x = 0 ;
422435 double y = 0 ;
423436 double width = 0 ;
@@ -436,10 +449,16 @@ void QgsComposerMapGrid::drawGridFrameBorder( QPainter* p, const QMap< double, d
436449 pos.insert ( mComposerMap ->rect ().width () + mGridFrameWidth , mComposerMap ->rect ().width () + mGridFrameWidth );
437450 }
438451
452+ // set pen to current frame pen
453+ QPen framePen = QPen ( mGridFramePenColor );
454+ framePen.setWidthF ( mGridFramePenThickness );
455+ framePen.setJoinStyle ( Qt::MiterJoin );
456+ p->setPen ( framePen );
457+
439458 QMap< double , double >::const_iterator posIt = pos.constBegin ();
440459 for ( ; posIt != pos.constEnd (); ++posIt )
441460 {
442- p->setBrush ( QBrush ( white ? Qt::white : Qt::black ) );
461+ p->setBrush ( QBrush ( color1 ? mGridFrameFillColor1 : mGridFrameFillColor2 ) );
443462 if ( border == QgsComposerMap::Left || border == QgsComposerMap::Right )
444463 {
445464 height = posIt.key () - currentCoord;
@@ -456,7 +475,7 @@ void QgsComposerMapGrid::drawGridFrameBorder( QPainter* p, const QMap< double, d
456475 }
457476 p->drawRect ( QRectF ( x, y, width, height ) );
458477 currentCoord = posIt.key ();
459- white = !white ;
478+ color1 = !color1 ;
460479 }
461480}
462481
0 commit comments