|
40 | 40 |
|
41 | 41 | QgsComposerMap::QgsComposerMap( QgsComposition *composition, int x, int y, int width, int height ) |
42 | 42 | : QgsComposerItem( x, y, width, height, composition ), mKeepLayerSet( false ), |
43 | | - mOverviewFrameMapId( -1 ), mGridEnabled( false ), mGridStyle( Solid ), |
| 43 | + mOverviewFrameMapId( -1 ), mOverviewBlendMode( QPainter::CompositionMode_SourceOver ), mOverviewInverted( false ), mGridEnabled( false ), mGridStyle( Solid ), |
44 | 44 | mGridIntervalX( 0.0 ), mGridIntervalY( 0.0 ), mGridOffsetX( 0.0 ), mGridOffsetY( 0.0 ), mGridAnnotationPrecision( 3 ), mShowGridAnnotation( false ), |
45 | 45 | mLeftGridAnnotationPosition( OutsideMapFrame ), mRightGridAnnotationPosition( OutsideMapFrame ), mTopGridAnnotationPosition( OutsideMapFrame ), |
46 | 46 | mBottomGridAnnotationPosition( OutsideMapFrame ), mAnnotationFrameDistance( 1.0 ), mLeftGridAnnotationDirection( Horizontal ), mRightGridAnnotationDirection( Horizontal ), |
@@ -82,7 +82,8 @@ QgsComposerMap::QgsComposerMap( QgsComposition *composition, int x, int y, int w |
82 | 82 | } |
83 | 83 |
|
84 | 84 | QgsComposerMap::QgsComposerMap( QgsComposition *composition ) |
85 | | - : QgsComposerItem( 0, 0, 10, 10, composition ), mKeepLayerSet( false ), mOverviewFrameMapId( -1 ), mGridEnabled( false ), mGridStyle( Solid ), |
| 85 | + : QgsComposerItem( 0, 0, 10, 10, composition ), mKeepLayerSet( false ), mOverviewFrameMapId( -1 ), |
| 86 | + mOverviewBlendMode( QPainter::CompositionMode_SourceOver ), mOverviewInverted( false ), mGridEnabled( false ), mGridStyle( Solid ), |
86 | 87 | mGridIntervalX( 0.0 ), mGridIntervalY( 0.0 ), mGridOffsetX( 0.0 ), mGridOffsetY( 0.0 ), mGridAnnotationPrecision( 3 ), mShowGridAnnotation( false ), |
87 | 88 | mLeftGridAnnotationPosition( OutsideMapFrame ), mRightGridAnnotationPosition( OutsideMapFrame ), mTopGridAnnotationPosition( OutsideMapFrame ), |
88 | 89 | mBottomGridAnnotationPosition( OutsideMapFrame ), mAnnotationFrameDistance( 1.0 ), mLeftGridAnnotationDirection( Horizontal ), mRightGridAnnotationDirection( Horizontal ), |
@@ -283,7 +284,7 @@ void QgsComposerMap::paint( QPainter* painter, const QStyleOptionGraphicsItem* i |
283 | 284 | //Qt 4.4.0 and 4.4.1 have problems with recursive paintings |
284 | 285 | //QgsComposerMap::cache() and QgsComposerMap::update() need to be called by |
285 | 286 | //client functions |
286 | | - |
| 287 | + |
287 | 288 | //Background color is already included in cached image, so no need to draw |
288 | 289 |
|
289 | 290 | QgsRectangle requestRectangle; |
@@ -682,10 +683,20 @@ bool QgsComposerMap::writeXML( QDomElement& elem, QDomDocument & doc ) const |
682 | 683 | //overview map frame |
683 | 684 | QDomElement overviewFrameElem = doc.createElement( "overviewFrame" ); |
684 | 685 | overviewFrameElem.setAttribute( "overviewFrameMap", mOverviewFrameMapId ); |
| 686 | + overviewFrameElem.setAttribute( "overviewBlendMode", QgsMapRenderer::getBlendModeEnum( mOverviewBlendMode ) ); |
| 687 | + if ( mOverviewInverted ) |
| 688 | + { |
| 689 | + overviewFrameElem.setAttribute( "overviewInverted", "true" ); |
| 690 | + } |
| 691 | + else |
| 692 | + { |
| 693 | + overviewFrameElem.setAttribute( "overviewInverted", "false" ); |
| 694 | + } |
685 | 695 | QDomElement overviewFrameStyleElem = QgsSymbolLayerV2Utils::saveSymbol( QString(), mOverviewFrameMapSymbol, doc ); |
686 | 696 | overviewFrameElem.appendChild( overviewFrameStyleElem ); |
687 | 697 | composerMapElem.appendChild( overviewFrameElem ); |
688 | 698 |
|
| 699 | + |
689 | 700 | //extent |
690 | 701 | QDomElement extentElem = doc.createElement( "Extent" ); |
691 | 702 | extentElem.setAttribute( "xmin", QString::number( mExtent.xMinimum() ) ); |
@@ -779,6 +790,18 @@ bool QgsComposerMap::readXML( const QDomElement& itemElem, const QDomDocument& d |
779 | 790 | if ( !overviewFrameElem.isNull() ) |
780 | 791 | { |
781 | 792 | setOverviewFrameMap( overviewFrameElem.attribute( "overviewFrameMap", "-1" ).toInt() ); |
| 793 | + setOverviewBlendMode( QgsMapRenderer::getCompositionMode(( QgsMapRenderer::BlendMode ) overviewFrameElem.attribute( "overviewBlendMode", "0" ).toUInt() ) ); |
| 794 | + |
| 795 | + QString overviewInvertedFlag = overviewFrameElem.attribute( "overviewInverted" ); |
| 796 | + if ( overviewInvertedFlag.compare( "true", Qt::CaseInsensitive ) == 0 ) |
| 797 | + { |
| 798 | + setOverviewInverted( true ); |
| 799 | + } |
| 800 | + else |
| 801 | + { |
| 802 | + setOverviewInverted( false ); |
| 803 | + } |
| 804 | + |
782 | 805 | QDomElement overviewFrameSymbolElem = overviewFrameElem.firstChildElement( "symbol" ); |
783 | 806 | if ( !overviewFrameSymbolElem.isNull() ) |
784 | 807 | { |
@@ -1699,6 +1722,18 @@ void QgsComposerMap::setOverviewFrameMapSymbol( QgsFillSymbolV2* symbol ) |
1699 | 1722 | mOverviewFrameMapSymbol = symbol; |
1700 | 1723 | } |
1701 | 1724 |
|
| 1725 | +void QgsComposerMap::setOverviewBlendMode( QPainter::CompositionMode blendMode ) |
| 1726 | +{ |
| 1727 | + mOverviewBlendMode = blendMode; |
| 1728 | + update(); |
| 1729 | +} |
| 1730 | + |
| 1731 | +void QgsComposerMap::setOverviewInverted( bool inverted ) |
| 1732 | +{ |
| 1733 | + mOverviewInverted = inverted; |
| 1734 | + update(); |
| 1735 | +} |
| 1736 | + |
1702 | 1737 | void QgsComposerMap::setGridLineSymbol( QgsLineSymbolV2* symbol ) |
1703 | 1738 | { |
1704 | 1739 | delete mGridLineSymbol; |
@@ -2043,17 +2078,38 @@ void QgsComposerMap::drawOverviewMapExtent( QPainter* p ) |
2043 | 2078 | context.setRasterScaleFactor( mComposition->printResolution() / 25.4 ); |
2044 | 2079 | } |
2045 | 2080 |
|
2046 | | - QPolygonF polygon; |
| 2081 | + p->save(); |
| 2082 | + p->setCompositionMode( mOverviewBlendMode ); |
| 2083 | + mOverviewFrameMapSymbol->startRender( context ); |
| 2084 | + |
| 2085 | + //construct a polygon corresponding to the intersecting map extent |
| 2086 | + QPolygonF intersectPolygon; |
2047 | 2087 | double x = ( intersectRect.xMinimum() - thisExtent.xMinimum() ) / thisExtent.width() * rect().width(); |
2048 | 2088 | double y = ( thisExtent.yMaximum() - intersectRect.yMaximum() ) / thisExtent.height() * rect().height(); |
2049 | 2089 | double width = intersectRect.width() / thisExtent.width() * rect().width(); |
2050 | 2090 | double height = intersectRect.height() / thisExtent.height() * rect().height(); |
2051 | | - polygon << QPointF( x, y ) << QPointF( x + width, y ) << QPointF( x + width, y + height ) << QPointF( x, y + height ) << QPointF( x, y ); |
| 2091 | + intersectPolygon << QPointF( x, y ) << QPointF( x + width, y ) << QPointF( x + width, y + height ) << QPointF( x, y + height ) << QPointF( x, y ); |
2052 | 2092 |
|
2053 | 2093 | QList<QPolygonF> rings; //empty list |
2054 | | - mOverviewFrameMapSymbol->startRender( context ); |
2055 | | - mOverviewFrameMapSymbol->renderPolygon( polygon, &rings, 0, context ); |
| 2094 | + if ( !mOverviewInverted ) |
| 2095 | + { |
| 2096 | + //Render the intersecting map extent |
| 2097 | + mOverviewFrameMapSymbol->renderPolygon( intersectPolygon, &rings, 0, context );; |
| 2098 | + } |
| 2099 | + else |
| 2100 | + { |
| 2101 | + //We are inverting the overview frame (ie, shading outside the intersecting extent) |
| 2102 | + //Construct a polygon corresponding to the overview map extent |
| 2103 | + QPolygonF outerPolygon; |
| 2104 | + outerPolygon << QPointF( 0, 0 ) << QPointF( rect().width(), 0 ) << QPointF( rect().width(), rect().height() ) << QPointF( 0, rect().height() ) << QPointF( 0, 0 ); |
| 2105 | + |
| 2106 | + //Intersecting extent is an inner ring for the shaded area |
| 2107 | + rings.append( intersectPolygon ); |
| 2108 | + mOverviewFrameMapSymbol->renderPolygon( outerPolygon, &rings, 0, context ); |
| 2109 | + } |
| 2110 | + |
2056 | 2111 | mOverviewFrameMapSymbol->stopRender( context ); |
| 2112 | + p->restore(); |
2057 | 2113 | } |
2058 | 2114 |
|
2059 | 2115 | void QgsComposerMap::createDefaultOverviewFrameSymbol() |
|
0 commit comments