Skip to content

Commit 30f63f4

Browse files
committed
[FEATURE]: display rectangle of another composer map (overview map)
1 parent 813a73c commit 30f63f4

File tree

5 files changed

+212
-3
lines changed

5 files changed

+212
-3
lines changed

src/app/composer/qgscomposermapwidget.cpp

+102
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,25 @@ QgsComposerMapWidget::QgsComposerMapWidget( QgsComposerMap* composerMap ): QWidg
6464
connect( composerMap, SIGNAL( itemChanged() ), this, SLOT( setGuiElementValues() ) );
6565
}
6666

67+
if ( mComposerMap )
68+
{
69+
//insert available maps into mMapComboBox
70+
const QgsComposition* composition = mComposerMap->composition();
71+
if ( composition )
72+
{
73+
QList<const QgsComposerMap*> availableMaps = composition->composerMapItems();
74+
QList<const QgsComposerMap*>::const_iterator mapItemIt = availableMaps.constBegin();
75+
for ( ; mapItemIt != availableMaps.constEnd(); ++mapItemIt )
76+
{
77+
if (( *mapItemIt )->id() != mComposerMap->id() )
78+
{
79+
mOverviewFrameMapComboBox->addItem( tr( "Map %1" ).arg(( *mapItemIt )->id() ), ( *mapItemIt )->id() );
80+
}
81+
}
82+
}
83+
}
84+
85+
6786
updateGuiElements();
6887
blockAllSignals( false );
6988
}
@@ -459,6 +478,7 @@ void QgsComposerMapWidget::blockAllSignals( bool b )
459478
mDrawCanvasItemsCheckBox->blockSignals( b );
460479
mFrameStyleComboBox->blockSignals( b );
461480
mFrameWidthSpinBox->blockSignals( b );
481+
mOverviewFrameMapComboBox->blockSignals( b );
462482
}
463483

464484
void QgsComposerMapWidget::on_mUpdatePreviewButton_clicked()
@@ -519,6 +539,88 @@ void QgsComposerMapWidget::on_mDrawCanvasItemsCheckBox_stateChanged( int state )
519539
mComposerMap->endCommand();
520540
}
521541

542+
void QgsComposerMapWidget::on_mOverviewFrameMapComboBox_activated( const QString& text )
543+
{
544+
if ( !mComposerMap )
545+
{
546+
return;
547+
}
548+
549+
//get composition
550+
const QgsComposition* composition = mComposerMap->composition();
551+
if ( !composition )
552+
{
553+
return;
554+
}
555+
556+
//extract id
557+
int id;
558+
bool conversionOk;
559+
QStringList textSplit = text.split( " " );
560+
if ( textSplit.size() < 1 )
561+
{
562+
return;
563+
}
564+
565+
QString idString = textSplit.at( textSplit.size() - 1 );
566+
id = idString.toInt( &conversionOk );
567+
568+
if ( !conversionOk )
569+
{
570+
return;
571+
}
572+
573+
const QgsComposerMap* composerMap = composition->getComposerMapById( id );
574+
if ( !composerMap )
575+
{
576+
return;
577+
}
578+
579+
mComposerMap->setOverviewFrameMap( id );
580+
mComposerMap->update();
581+
582+
#if 0
583+
f( !mPicture || text.isEmpty() || !mPicture->useRotationMap() )
584+
{
585+
return;
586+
}
587+
588+
//get composition
589+
const QgsComposition* composition = mPicture->composition();
590+
if ( !composition )
591+
{
592+
return;
593+
}
594+
595+
//extract id
596+
int id;
597+
bool conversionOk;
598+
QStringList textSplit = text.split( " " );
599+
if ( textSplit.size() < 1 )
600+
{
601+
return;
602+
}
603+
604+
QString idString = textSplit.at( textSplit.size() - 1 );
605+
id = idString.toInt( &conversionOk );
606+
607+
if ( !conversionOk )
608+
{
609+
return;
610+
}
611+
612+
const QgsComposerMap* composerMap = composition->getComposerMapById( id );
613+
if ( !composerMap )
614+
{
615+
return;
616+
}
617+
mPicture->beginCommand( tr( "Rotation map changed" ) );
618+
mPicture->setRotationMap( id );
619+
mPicture->update();
620+
mPicture->endCommand();
621+
#endif //0
622+
}
623+
522624
void QgsComposerMapWidget::on_mGridCheckBox_toggled( bool state )
523625
{
524626
if ( !mComposerMap )

src/app/composer/qgscomposermapwidget.h

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class QgsComposerMapWidget: public QWidget, private Ui::QgsComposerMapWidgetBase
4343
void on_mUpdatePreviewButton_clicked();
4444
void on_mKeepLayerListCheckBox_stateChanged( int state );
4545
void on_mDrawCanvasItemsCheckBox_stateChanged( int state );
46+
void on_mOverviewFrameMapComboBox_activated( const QString& text );
4647

4748
void on_mXMinLineEdit_editingFinished();
4849
void on_mXMaxLineEdit_editingFinished();

src/core/composer/qgscomposermap.cpp

+89-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
#include <cmath>
3939

4040
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 ),
4242
mGridIntervalX( 0.0 ), mGridIntervalY( 0.0 ), mGridOffsetX( 0.0 ), mGridOffsetY( 0.0 ), mGridAnnotationPrecision( 3 ), mShowGridAnnotation( false ),
4343
mLeftGridAnnotationPosition( OutsideMapFrame ), mRightGridAnnotationPosition( OutsideMapFrame ), mTopGridAnnotationPosition( OutsideMapFrame ),
4444
mBottomGridAnnotationPosition( OutsideMapFrame ), mAnnotationFrameDistance( 1.0 ), mLeftGridAnnotationDirection( Horizontal ), mRightGridAnnotationDirection( Horizontal ),
@@ -85,7 +85,7 @@ QgsComposerMap::QgsComposerMap( QgsComposition *composition, int x, int y, int w
8585
}
8686

8787
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 ),
8989
mGridIntervalX( 0.0 ), mGridIntervalY( 0.0 ), mGridOffsetX( 0.0 ), mGridOffsetY( 0.0 ), mGridAnnotationPrecision( 3 ), mShowGridAnnotation( false ),
9090
mLeftGridAnnotationPosition( OutsideMapFrame ), mRightGridAnnotationPosition( OutsideMapFrame ), mTopGridAnnotationPosition( OutsideMapFrame ),
9191
mBottomGridAnnotationPosition( OutsideMapFrame ), mAnnotationFrameDistance( 1.0 ), mLeftGridAnnotationDirection( Horizontal ), mRightGridAnnotationDirection( Horizontal ),
@@ -364,6 +364,10 @@ void QgsComposerMap::paint( QPainter* painter, const QStyleOptionGraphicsItem* i
364364
drawSelectionBoxes( painter );
365365
}
366366

367+
if ( mOverviewFrameMap )
368+
{
369+
drawOverviewMapExtent( painter );
370+
}
367371

368372
painter->restore();
369373
}
@@ -679,6 +683,13 @@ bool QgsComposerMap::writeXML( QDomElement& elem, QDomDocument & doc ) const
679683
}
680684
composerMapElem.appendChild( layerSetElem );
681685

686+
int overviewMapId = -1;
687+
if ( mOverviewFrameMap )
688+
{
689+
overviewMapId = mOverviewFrameMap->id();
690+
}
691+
composerMapElem.setAttribute( "overviewFrameMap", overviewMapId );
692+
682693
//grid
683694
QDomElement gridElem = doc.createElement( "Grid" );
684695
gridElem.setAttribute( "show", mGridEnabled );
@@ -799,6 +810,26 @@ bool QgsComposerMap::readXML( const QDomElement& itemElem, const QDomDocument& d
799810
mNumCachedLayers = 0;
800811
mCacheUpdated = false;
801812

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+
802833
//grid
803834
QDomNodeList gridNodeList = itemElem.elementsByTagName( "Grid" );
804835
if ( gridNodeList.size() > 0 )
@@ -1536,6 +1567,44 @@ double QgsComposerMap::mapUnitsToMM() const
15361567
return rect().width() / extentWidth;
15371568
}
15381569

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+
15391608
void QgsComposerMap::transformShift( double& xShift, double& yShift ) const
15401609
{
15411610
double mmToMapUnits = 1.0 / mapUnitsToMM();
@@ -1845,4 +1914,22 @@ void QgsComposerMap::sortGridLinesOnBorders( const QList< QPair< double, QLineF
18451914
}
18461915
}
18471916

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 );
18481927

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+
}

src/core/composer/qgscomposermap.h

+9
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,11 @@ class CORE_EXPORT QgsComposerMap : public QgsComposerItem
289289
/**Returns the conversion factor map units -> mm*/
290290
double mapUnitsToMM() const;
291291

292+
/**Sets overview frame map. -1 disables the overview frame*/
293+
void setOverviewFrameMap( int mapId );
294+
/**Returns id of overview frame (or -1 if no overfiew frame)*/
295+
int overviewFrameMapId() const;
296+
292297
signals:
293298
void extentChanged();
294299

@@ -339,6 +344,9 @@ class CORE_EXPORT QgsComposerMap : public QgsComposerItem
339344
/**Stored layer list (used if layer live-link mKeepLayerSet is disabled)*/
340345
QStringList mLayerSet;
341346

347+
/**Map that displays its rectangle into this composer map (or 0 if no frame of another map)*/
348+
const QgsComposerMap* mOverviewFrameMap;
349+
342350
/**Establishes signal/slot connection for update in case of layer change*/
343351
void connectUpdateSlot();
344352

@@ -445,6 +453,7 @@ class CORE_EXPORT QgsComposerMap : public QgsComposerItem
445453
void sortGridLinesOnBorders( const QList< QPair< double, QLineF > >& hLines, const QList< QPair< double, QLineF > >& vLines, QMap< double, double >& leftFrameEntries,
446454
QMap< double, double >& rightFrameEntries, QMap< double, double >& topFrameEntries, QMap< double, double >& bottomFrameEntries ) const;
447455
void drawGridFrameBorder( QPainter* p, const QMap< double, double >& borderPos, Border border );
456+
void drawOverviewMapExtent( QPainter* p );
448457
};
449458

450459
#endif

src/ui/qgscomposermapwidgetbase.ui

+11-1
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,16 @@
220220
</property>
221221
</spacer>
222222
</item>
223+
<item row="5" column="1">
224+
<widget class="QComboBox" name="mOverviewFrameMapComboBox"/>
225+
</item>
226+
<item row="5" column="0">
227+
<widget class="QLabel" name="mOverviewFrameMapLabel">
228+
<property name="text">
229+
<string>Overview frame</string>
230+
</property>
231+
</widget>
232+
</item>
223233
</layout>
224234
</widget>
225235
<widget class="QWidget" name="page_2">
@@ -336,7 +346,7 @@
336346
<x>0</x>
337347
<y>0</y>
338348
<width>218</width>
339-
<height>712</height>
349+
<height>716</height>
340350
</rect>
341351
</property>
342352
<attribute name="label">

0 commit comments

Comments
 (0)