@@ -46,6 +46,7 @@ QgsComposerMap::QgsComposerMap( QgsComposition *composition, int x, int y, int w
46
46
mCrossLength( 3 ), mMapCanvas( 0 ), mDrawCanvasItems( true )
47
47
{
48
48
mComposition = composition;
49
+ mOverviewFrameMapSymbol = new QgsFillSymbolV2 ();
49
50
50
51
// mId = mComposition->composerMapItems().size();
51
52
int maxId = -1 ;
@@ -92,6 +93,9 @@ QgsComposerMap::QgsComposerMap( QgsComposition *composition )
92
93
mTopGridAnnotationDirection( Horizontal ), mBottomGridAnnotationDirection( Horizontal ), mGridFrameStyle( NoGridFrame ), mGridFrameWidth( 2.0 ), mCrossLength( 3 ),
93
94
mMapCanvas( 0 ), mDrawCanvasItems( true )
94
95
{
96
+
97
+ mOverviewFrameMapSymbol = new QgsFillSymbolV2 ();
98
+
95
99
// Offset
96
100
mXOffset = 0.0 ;
97
101
mYOffset = 0.0 ;
@@ -110,6 +114,7 @@ QgsComposerMap::QgsComposerMap( QgsComposition *composition )
110
114
111
115
QgsComposerMap::~QgsComposerMap ()
112
116
{
117
+ delete mOverviewFrameMapSymbol ;
113
118
}
114
119
115
120
void QgsComposerMap::draw ( QPainter *painter, const QgsRectangle& extent, const QSize& size, int dpi )
@@ -756,7 +761,7 @@ bool QgsComposerMap::readXML( const QDomElement& itemElem, const QDomDocument& d
756
761
mPreviewMode = Rectangle;
757
762
}
758
763
759
- mOverviewFrameMapId = itemElem.attribute ( " overviewFrameMap" , " -1" ).toInt ();
764
+ setOverviewFrameMap ( itemElem.attribute ( " overviewFrameMap" , " -1" ).toInt () );
760
765
761
766
// extent
762
767
QDomNodeList extentNodeList = itemElem.elementsByTagName ( " Extent" );
@@ -1570,6 +1575,12 @@ void QgsComposerMap::setOverviewFrameMap( int mapId )
1570
1575
update ();
1571
1576
}
1572
1577
1578
+ void QgsComposerMap::setOverviewFrameMapSymbol ( QgsFillSymbolV2* symbol )
1579
+ {
1580
+ delete mOverviewFrameMapSymbol ;
1581
+ mOverviewFrameMapSymbol = symbol;
1582
+ }
1583
+
1573
1584
void QgsComposerMap::transformShift ( double & xShift, double & yShift ) const
1574
1585
{
1575
1586
double mmToMapUnits = 1.0 / mapUnitsToMM ();
@@ -1881,7 +1892,7 @@ void QgsComposerMap::sortGridLinesOnBorders( const QList< QPair< double, QLineF
1881
1892
1882
1893
void QgsComposerMap::drawOverviewMapExtent ( QPainter* p )
1883
1894
{
1884
- if ( mOverviewFrameMapId == -1 )
1895
+ if ( mOverviewFrameMapId == -1 || ! mComposition )
1885
1896
{
1886
1897
return ;
1887
1898
}
@@ -1896,11 +1907,41 @@ void QgsComposerMap::drawOverviewMapExtent( QPainter* p )
1896
1907
QgsRectangle thisExtent = extent ();
1897
1908
QgsRectangle intersectRect = thisExtent.intersect ( &otherExtent );
1898
1909
1899
- p->setPen ( QPen ( Qt::red ) ); // todo: make appearance configurable
1910
+ QgsRenderContext context;
1911
+ context.setPainter ( p );
1912
+ if ( mPreviewMode == Rectangle )
1913
+ {
1914
+ return ;
1915
+ }
1916
+ else if ( mComposition ->plotStyle () == QgsComposition::Preview )
1917
+ {
1918
+ context.setScaleFactor ( 1.0 );
1919
+ context.setRasterScaleFactor ( /* 96.0*/ mComposition ->printResolution () / 25.4 );
1920
+ }
1921
+ else // print
1922
+ {
1923
+ context.setScaleFactor ( 1.0 );
1924
+ double rasterScaleFactor = mComposition ->printResolution () / 25.4 ;
1925
+ context.setRasterScaleFactor ( rasterScaleFactor );
1926
+ }
1927
+
1928
+ QPolygonF polygon;
1929
+ double x = ( intersectRect.xMinimum () - thisExtent.xMinimum () ) / thisExtent.width () * rect ().width ();
1930
+ double y = ( thisExtent.yMaximum () - intersectRect.yMaximum () ) / thisExtent.height () * rect ().height ();
1931
+ double width = intersectRect.width () / thisExtent.width () * rect ().width ();
1932
+ double height = intersectRect.height () / thisExtent.height () * rect ().height ();
1933
+ polygon << QPointF ( x, y ) << QPointF ( x + width, y ) << QPointF ( x + width, y + height ) << QPointF ( x, y + height );
1934
+
1935
+ QList<QPolygonF> rings; // empty list
1936
+ mOverviewFrameMapSymbol ->startRender ( context );
1937
+ mOverviewFrameMapSymbol ->renderPolygon ( polygon, &rings, 0 , context );
1938
+ mOverviewFrameMapSymbol ->stopRender ( context );
1939
+
1940
+ /* p->setPen( QPen( Qt::red ) ); //todo: make appearance configurable
1900
1941
p->setBrush( QBrush( QColor( 255, 0, 0, 100 ) ) );
1901
1942
double x = ( intersectRect.xMinimum() - thisExtent.xMinimum() ) / thisExtent.width() * rect().width();
1902
1943
double y = ( thisExtent.yMaximum() - intersectRect.yMaximum() ) / thisExtent.height() * rect().height();
1903
1944
double width = intersectRect.width() / thisExtent.width() * rect().width();
1904
1945
double height = intersectRect.height() / thisExtent.height() * rect().height();
1905
- p->drawRect ( QRectF ( x, y, width, height ) );
1946
+ p->drawRect( QRectF( x, y, width, height ) );*/
1906
1947
}
0 commit comments