Skip to content

Commit

Permalink
[FEATURE]: display rectangle of another composer map (overview map)
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Jul 6, 2012
1 parent 813a73c commit 30f63f4
Show file tree
Hide file tree
Showing 5 changed files with 212 additions and 3 deletions.
102 changes: 102 additions & 0 deletions src/app/composer/qgscomposermapwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,25 @@ QgsComposerMapWidget::QgsComposerMapWidget( QgsComposerMap* composerMap ): QWidg
connect( composerMap, SIGNAL( itemChanged() ), this, SLOT( setGuiElementValues() ) );
}

if ( mComposerMap )
{
//insert available maps into mMapComboBox
const QgsComposition* composition = mComposerMap->composition();
if ( composition )
{
QList<const QgsComposerMap*> availableMaps = composition->composerMapItems();
QList<const QgsComposerMap*>::const_iterator mapItemIt = availableMaps.constBegin();
for ( ; mapItemIt != availableMaps.constEnd(); ++mapItemIt )
{
if (( *mapItemIt )->id() != mComposerMap->id() )
{
mOverviewFrameMapComboBox->addItem( tr( "Map %1" ).arg(( *mapItemIt )->id() ), ( *mapItemIt )->id() );
}
}
}
}


updateGuiElements();
blockAllSignals( false );
}
Expand Down Expand Up @@ -459,6 +478,7 @@ void QgsComposerMapWidget::blockAllSignals( bool b )
mDrawCanvasItemsCheckBox->blockSignals( b );
mFrameStyleComboBox->blockSignals( b );
mFrameWidthSpinBox->blockSignals( b );
mOverviewFrameMapComboBox->blockSignals( b );
}

void QgsComposerMapWidget::on_mUpdatePreviewButton_clicked()
Expand Down Expand Up @@ -519,6 +539,88 @@ void QgsComposerMapWidget::on_mDrawCanvasItemsCheckBox_stateChanged( int state )
mComposerMap->endCommand();
}

void QgsComposerMapWidget::on_mOverviewFrameMapComboBox_activated( const QString& text )
{
if ( !mComposerMap )
{
return;
}

//get composition
const QgsComposition* composition = mComposerMap->composition();
if ( !composition )
{
return;
}

//extract id
int id;
bool conversionOk;
QStringList textSplit = text.split( " " );
if ( textSplit.size() < 1 )
{
return;
}

QString idString = textSplit.at( textSplit.size() - 1 );
id = idString.toInt( &conversionOk );

if ( !conversionOk )
{
return;
}

const QgsComposerMap* composerMap = composition->getComposerMapById( id );
if ( !composerMap )
{
return;
}

mComposerMap->setOverviewFrameMap( id );
mComposerMap->update();

#if 0
f( !mPicture || text.isEmpty() || !mPicture->useRotationMap() )
{
return;
}

//get composition
const QgsComposition* composition = mPicture->composition();
if ( !composition )
{
return;
}

//extract id
int id;
bool conversionOk;
QStringList textSplit = text.split( " " );
if ( textSplit.size() < 1 )
{
return;
}

QString idString = textSplit.at( textSplit.size() - 1 );
id = idString.toInt( &conversionOk );

if ( !conversionOk )
{
return;
}

const QgsComposerMap* composerMap = composition->getComposerMapById( id );
if ( !composerMap )
{
return;
}
mPicture->beginCommand( tr( "Rotation map changed" ) );
mPicture->setRotationMap( id );
mPicture->update();
mPicture->endCommand();
#endif //0
}

void QgsComposerMapWidget::on_mGridCheckBox_toggled( bool state )
{
if ( !mComposerMap )
Expand Down
1 change: 1 addition & 0 deletions src/app/composer/qgscomposermapwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class QgsComposerMapWidget: public QWidget, private Ui::QgsComposerMapWidgetBase
void on_mUpdatePreviewButton_clicked();
void on_mKeepLayerListCheckBox_stateChanged( int state );
void on_mDrawCanvasItemsCheckBox_stateChanged( int state );
void on_mOverviewFrameMapComboBox_activated( const QString& text );

void on_mXMinLineEdit_editingFinished();
void on_mXMaxLineEdit_editingFinished();
Expand Down
91 changes: 89 additions & 2 deletions src/core/composer/qgscomposermap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#include <cmath>

QgsComposerMap::QgsComposerMap( QgsComposition *composition, int x, int y, int width, int height )
: QgsComposerItem( x, y, width, height, composition ), mKeepLayerSet( false ), mGridEnabled( false ), mGridStyle( Solid ),
: QgsComposerItem( x, y, width, height, composition ), mKeepLayerSet( false ), mOverviewFrameMap( 0 ), mGridEnabled( false ), mGridStyle( Solid ),
mGridIntervalX( 0.0 ), mGridIntervalY( 0.0 ), mGridOffsetX( 0.0 ), mGridOffsetY( 0.0 ), mGridAnnotationPrecision( 3 ), mShowGridAnnotation( false ),
mLeftGridAnnotationPosition( OutsideMapFrame ), mRightGridAnnotationPosition( OutsideMapFrame ), mTopGridAnnotationPosition( OutsideMapFrame ),
mBottomGridAnnotationPosition( OutsideMapFrame ), mAnnotationFrameDistance( 1.0 ), mLeftGridAnnotationDirection( Horizontal ), mRightGridAnnotationDirection( Horizontal ),
Expand Down Expand Up @@ -85,7 +85,7 @@ QgsComposerMap::QgsComposerMap( QgsComposition *composition, int x, int y, int w
}

QgsComposerMap::QgsComposerMap( QgsComposition *composition )
: QgsComposerItem( 0, 0, 10, 10, composition ), mKeepLayerSet( false ), mGridEnabled( false ), mGridStyle( Solid ),
: QgsComposerItem( 0, 0, 10, 10, composition ), mKeepLayerSet( false ), mOverviewFrameMap( 0 ), mGridEnabled( false ), mGridStyle( Solid ),
mGridIntervalX( 0.0 ), mGridIntervalY( 0.0 ), mGridOffsetX( 0.0 ), mGridOffsetY( 0.0 ), mGridAnnotationPrecision( 3 ), mShowGridAnnotation( false ),
mLeftGridAnnotationPosition( OutsideMapFrame ), mRightGridAnnotationPosition( OutsideMapFrame ), mTopGridAnnotationPosition( OutsideMapFrame ),
mBottomGridAnnotationPosition( OutsideMapFrame ), mAnnotationFrameDistance( 1.0 ), mLeftGridAnnotationDirection( Horizontal ), mRightGridAnnotationDirection( Horizontal ),
Expand Down Expand Up @@ -364,6 +364,10 @@ void QgsComposerMap::paint( QPainter* painter, const QStyleOptionGraphicsItem* i
drawSelectionBoxes( painter );
}

if ( mOverviewFrameMap )
{
drawOverviewMapExtent( painter );
}

painter->restore();
}
Expand Down Expand Up @@ -679,6 +683,13 @@ bool QgsComposerMap::writeXML( QDomElement& elem, QDomDocument & doc ) const
}
composerMapElem.appendChild( layerSetElem );

int overviewMapId = -1;
if ( mOverviewFrameMap )
{
overviewMapId = mOverviewFrameMap->id();
}
composerMapElem.setAttribute( "overviewFrameMap", overviewMapId );

//grid
QDomElement gridElem = doc.createElement( "Grid" );
gridElem.setAttribute( "show", mGridEnabled );
Expand Down Expand Up @@ -799,6 +810,26 @@ bool QgsComposerMap::readXML( const QDomElement& itemElem, const QDomDocument& d
mNumCachedLayers = 0;
mCacheUpdated = false;

//todo: overview frame map
#if 0
//rotation map
int rotationMapId = itemElem.attribute( "mapId", "-1" ).toInt();
if ( rotationMapId == -1 )
{
mRotationMap = 0;
}
else if ( mComposition )
{

if ( mRotationMap )
{
QObject::disconnect( mRotationMap, SIGNAL( rotationChanged( double ) ), this, SLOT( setRotation( double ) ) );
}
mRotationMap = mComposition->getComposerMapById( rotationMapId );
QObject::connect( mRotationMap, SIGNAL( rotationChanged( double ) ), this, SLOT( setRotation( double ) ) );
}
#endif //0

//grid
QDomNodeList gridNodeList = itemElem.elementsByTagName( "Grid" );
if ( gridNodeList.size() > 0 )
Expand Down Expand Up @@ -1536,6 +1567,44 @@ double QgsComposerMap::mapUnitsToMM() const
return rect().width() / extentWidth;
}

void QgsComposerMap::setOverviewFrameMap( int mapId )
{
if ( !mComposition )
{
return;
}

if ( mapId == -1 ) //disable overview map frame
{
QObject::disconnect( mOverviewFrameMap, SIGNAL( extentChanged() ), this, SLOT( repaint() ) );
mOverviewFrameMap = 0;
}

const QgsComposerMap* map = mComposition->getComposerMapById( mapId );
if ( !map )
{
return;
}
if ( mOverviewFrameMap )
{
QObject::disconnect( mOverviewFrameMap, SIGNAL( extentChanged() ), this, SLOT( repaint() ) );
}
QObject::connect( mOverviewFrameMap, SIGNAL( extentChanged() ), this, SLOT( repaint() ) );
mOverviewFrameMap = map;
}

int QgsComposerMap::overviewFrameMapId() const
{
if ( !mOverviewFrameMap )
{
return -1;
}
else
{
return mOverviewFrameMap->id();
}
}

void QgsComposerMap::transformShift( double& xShift, double& yShift ) const
{
double mmToMapUnits = 1.0 / mapUnitsToMM();
Expand Down Expand Up @@ -1845,4 +1914,22 @@ void QgsComposerMap::sortGridLinesOnBorders( const QList< QPair< double, QLineF
}
}

void QgsComposerMap::drawOverviewMapExtent( QPainter* p )
{
if ( !mOverviewFrameMap )
{
return;
}

QgsRectangle otherExtent = mOverviewFrameMap->extent();
QgsRectangle thisExtent = extent();
QgsRectangle intersectRect = thisExtent.intersect( &otherExtent );

p->setPen( QPen( Qt::red ) ); //todo: make appearance configurable
p->setBrush( QBrush( QColor( 255, 0, 0, 100 ) ) );
double x = ( intersectRect.xMinimum() - thisExtent.xMinimum() ) / thisExtent.width() * rect().width();
double y = ( thisExtent.yMaximum() - intersectRect.yMaximum() ) / thisExtent.height() * rect().height();
double width = intersectRect.width() / thisExtent.width() * rect().width();
double height = intersectRect.height() / thisExtent.height() * rect().height();
p->drawRect( QRectF( x, y, width, height ) );
}
9 changes: 9 additions & 0 deletions src/core/composer/qgscomposermap.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,11 @@ class CORE_EXPORT QgsComposerMap : public QgsComposerItem
/**Returns the conversion factor map units -> mm*/
double mapUnitsToMM() const;

/**Sets overview frame map. -1 disables the overview frame*/
void setOverviewFrameMap( int mapId );
/**Returns id of overview frame (or -1 if no overfiew frame)*/
int overviewFrameMapId() const;

signals:
void extentChanged();

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

/**Map that displays its rectangle into this composer map (or 0 if no frame of another map)*/
const QgsComposerMap* mOverviewFrameMap;

/**Establishes signal/slot connection for update in case of layer change*/
void connectUpdateSlot();

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

#endif
12 changes: 11 additions & 1 deletion src/ui/qgscomposermapwidgetbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,16 @@
</property>
</spacer>
</item>
<item row="5" column="1">
<widget class="QComboBox" name="mOverviewFrameMapComboBox"/>
</item>
<item row="5" column="0">
<widget class="QLabel" name="mOverviewFrameMapLabel">
<property name="text">
<string>Overview frame</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="page_2">
Expand Down Expand Up @@ -336,7 +346,7 @@
<x>0</x>
<y>0</y>
<width>218</width>
<height>712</height>
<height>716</height>
</rect>
</property>
<attribute name="label">
Expand Down

0 comments on commit 30f63f4

Please sign in to comment.