|
38 | 38 | #include <cmath>
|
39 | 39 |
|
40 | 40 | QgsComposerMap::QgsComposerMap( QgsComposition *composition, int x, int y, int width, int height )
|
41 |
| - : QgsComposerItem( x, y, width, height, composition ), mKeepLayerSet( false ), mGridEnabled( false ), mGridStyle( Solid ), |
| 41 | + : QgsComposerItem( x, y, width, height, composition ), mKeepLayerSet( false ), mOverviewFrameMap( 0 ), mGridEnabled( false ), mGridStyle( Solid ), |
42 | 42 | mGridIntervalX( 0.0 ), mGridIntervalY( 0.0 ), mGridOffsetX( 0.0 ), mGridOffsetY( 0.0 ), mGridAnnotationPrecision( 3 ), mShowGridAnnotation( false ),
|
43 | 43 | mLeftGridAnnotationPosition( OutsideMapFrame ), mRightGridAnnotationPosition( OutsideMapFrame ), mTopGridAnnotationPosition( OutsideMapFrame ),
|
44 | 44 | mBottomGridAnnotationPosition( OutsideMapFrame ), mAnnotationFrameDistance( 1.0 ), mLeftGridAnnotationDirection( Horizontal ), mRightGridAnnotationDirection( Horizontal ),
|
@@ -85,7 +85,7 @@ QgsComposerMap::QgsComposerMap( QgsComposition *composition, int x, int y, int w
|
85 | 85 | }
|
86 | 86 |
|
87 | 87 | QgsComposerMap::QgsComposerMap( QgsComposition *composition )
|
88 |
| - : QgsComposerItem( 0, 0, 10, 10, composition ), mKeepLayerSet( false ), mGridEnabled( false ), mGridStyle( Solid ), |
| 88 | + : QgsComposerItem( 0, 0, 10, 10, composition ), mKeepLayerSet( false ), mOverviewFrameMap( 0 ), mGridEnabled( false ), mGridStyle( Solid ), |
89 | 89 | mGridIntervalX( 0.0 ), mGridIntervalY( 0.0 ), mGridOffsetX( 0.0 ), mGridOffsetY( 0.0 ), mGridAnnotationPrecision( 3 ), mShowGridAnnotation( false ),
|
90 | 90 | mLeftGridAnnotationPosition( OutsideMapFrame ), mRightGridAnnotationPosition( OutsideMapFrame ), mTopGridAnnotationPosition( OutsideMapFrame ),
|
91 | 91 | mBottomGridAnnotationPosition( OutsideMapFrame ), mAnnotationFrameDistance( 1.0 ), mLeftGridAnnotationDirection( Horizontal ), mRightGridAnnotationDirection( Horizontal ),
|
@@ -364,6 +364,10 @@ void QgsComposerMap::paint( QPainter* painter, const QStyleOptionGraphicsItem* i
|
364 | 364 | drawSelectionBoxes( painter );
|
365 | 365 | }
|
366 | 366 |
|
| 367 | + if ( mOverviewFrameMap ) |
| 368 | + { |
| 369 | + drawOverviewMapExtent( painter ); |
| 370 | + } |
367 | 371 |
|
368 | 372 | painter->restore();
|
369 | 373 | }
|
@@ -679,6 +683,13 @@ bool QgsComposerMap::writeXML( QDomElement& elem, QDomDocument & doc ) const
|
679 | 683 | }
|
680 | 684 | composerMapElem.appendChild( layerSetElem );
|
681 | 685 |
|
| 686 | + int overviewMapId = -1; |
| 687 | + if ( mOverviewFrameMap ) |
| 688 | + { |
| 689 | + overviewMapId = mOverviewFrameMap->id(); |
| 690 | + } |
| 691 | + composerMapElem.setAttribute( "overviewFrameMap", overviewMapId ); |
| 692 | + |
682 | 693 | //grid
|
683 | 694 | QDomElement gridElem = doc.createElement( "Grid" );
|
684 | 695 | gridElem.setAttribute( "show", mGridEnabled );
|
@@ -799,6 +810,26 @@ bool QgsComposerMap::readXML( const QDomElement& itemElem, const QDomDocument& d
|
799 | 810 | mNumCachedLayers = 0;
|
800 | 811 | mCacheUpdated = false;
|
801 | 812 |
|
| 813 | + //todo: overview frame map |
| 814 | +#if 0 |
| 815 | + //rotation map |
| 816 | + int rotationMapId = itemElem.attribute( "mapId", "-1" ).toInt(); |
| 817 | + if ( rotationMapId == -1 ) |
| 818 | + { |
| 819 | + mRotationMap = 0; |
| 820 | + } |
| 821 | + else if ( mComposition ) |
| 822 | + { |
| 823 | + |
| 824 | + if ( mRotationMap ) |
| 825 | + { |
| 826 | + QObject::disconnect( mRotationMap, SIGNAL( rotationChanged( double ) ), this, SLOT( setRotation( double ) ) ); |
| 827 | + } |
| 828 | + mRotationMap = mComposition->getComposerMapById( rotationMapId ); |
| 829 | + QObject::connect( mRotationMap, SIGNAL( rotationChanged( double ) ), this, SLOT( setRotation( double ) ) ); |
| 830 | + } |
| 831 | +#endif //0 |
| 832 | + |
802 | 833 | //grid
|
803 | 834 | QDomNodeList gridNodeList = itemElem.elementsByTagName( "Grid" );
|
804 | 835 | if ( gridNodeList.size() > 0 )
|
@@ -1536,6 +1567,44 @@ double QgsComposerMap::mapUnitsToMM() const
|
1536 | 1567 | return rect().width() / extentWidth;
|
1537 | 1568 | }
|
1538 | 1569 |
|
| 1570 | +void QgsComposerMap::setOverviewFrameMap( int mapId ) |
| 1571 | +{ |
| 1572 | + if ( !mComposition ) |
| 1573 | + { |
| 1574 | + return; |
| 1575 | + } |
| 1576 | + |
| 1577 | + if ( mapId == -1 ) //disable overview map frame |
| 1578 | + { |
| 1579 | + QObject::disconnect( mOverviewFrameMap, SIGNAL( extentChanged() ), this, SLOT( repaint() ) ); |
| 1580 | + mOverviewFrameMap = 0; |
| 1581 | + } |
| 1582 | + |
| 1583 | + const QgsComposerMap* map = mComposition->getComposerMapById( mapId ); |
| 1584 | + if ( !map ) |
| 1585 | + { |
| 1586 | + return; |
| 1587 | + } |
| 1588 | + if ( mOverviewFrameMap ) |
| 1589 | + { |
| 1590 | + QObject::disconnect( mOverviewFrameMap, SIGNAL( extentChanged() ), this, SLOT( repaint() ) ); |
| 1591 | + } |
| 1592 | + QObject::connect( mOverviewFrameMap, SIGNAL( extentChanged() ), this, SLOT( repaint() ) ); |
| 1593 | + mOverviewFrameMap = map; |
| 1594 | +} |
| 1595 | + |
| 1596 | +int QgsComposerMap::overviewFrameMapId() const |
| 1597 | +{ |
| 1598 | + if ( !mOverviewFrameMap ) |
| 1599 | + { |
| 1600 | + return -1; |
| 1601 | + } |
| 1602 | + else |
| 1603 | + { |
| 1604 | + return mOverviewFrameMap->id(); |
| 1605 | + } |
| 1606 | +} |
| 1607 | + |
1539 | 1608 | void QgsComposerMap::transformShift( double& xShift, double& yShift ) const
|
1540 | 1609 | {
|
1541 | 1610 | double mmToMapUnits = 1.0 / mapUnitsToMM();
|
@@ -1845,4 +1914,22 @@ void QgsComposerMap::sortGridLinesOnBorders( const QList< QPair< double, QLineF
|
1845 | 1914 | }
|
1846 | 1915 | }
|
1847 | 1916 |
|
| 1917 | +void QgsComposerMap::drawOverviewMapExtent( QPainter* p ) |
| 1918 | +{ |
| 1919 | + if ( !mOverviewFrameMap ) |
| 1920 | + { |
| 1921 | + return; |
| 1922 | + } |
| 1923 | + |
| 1924 | + QgsRectangle otherExtent = mOverviewFrameMap->extent(); |
| 1925 | + QgsRectangle thisExtent = extent(); |
| 1926 | + QgsRectangle intersectRect = thisExtent.intersect( &otherExtent ); |
1848 | 1927 |
|
| 1928 | + p->setPen( QPen( Qt::red ) ); //todo: make appearance configurable |
| 1929 | + p->setBrush( QBrush( QColor( 255, 0, 0, 100 ) ) ); |
| 1930 | + double x = ( intersectRect.xMinimum() - thisExtent.xMinimum() ) / thisExtent.width() * rect().width(); |
| 1931 | + double y = ( thisExtent.yMaximum() - intersectRect.yMaximum() ) / thisExtent.height() * rect().height(); |
| 1932 | + double width = intersectRect.width() / thisExtent.width() * rect().width(); |
| 1933 | + double height = intersectRect.height() / thisExtent.height() * rect().height(); |
| 1934 | + p->drawRect( QRectF( x, y, width, height ) ); |
| 1935 | +} |
0 commit comments