Skip to content
Permalink
Browse files

[FEATURE]: display rectangle of another composer map (overview map)

  • Loading branch information
mhugent committed Jul 6, 2012
1 parent 813a73c commit 30f63f4e88ff271a57706ecab358996b5f615b86
@@ -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 );
}
@@ -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()
@@ -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 )
@@ -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();
@@ -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 ),
@@ -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 ),
@@ -364,6 +364,10 @@ void QgsComposerMap::paint( QPainter* painter, const QStyleOptionGraphicsItem* i
drawSelectionBoxes( painter );
}

if ( mOverviewFrameMap )
{
drawOverviewMapExtent( painter );
}

painter->restore();
}
@@ -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 );
@@ -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 )
@@ -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();
@@ -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 ) );
}
@@ -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();

@@ -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();

@@ -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
@@ -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">
@@ -336,7 +346,7 @@
<x>0</x>
<y>0</y>
<width>218</width>
<height>712</height>
<height>716</height>
</rect>
</property>
<attribute name="label">

0 comments on commit 30f63f4

Please sign in to comment.
You can’t perform that action at this time.