Skip to content
Permalink
Browse files

Improve overview map frame in composer map

  • Loading branch information
mhugent committed Jul 10, 2012
1 parent 30f63f4 commit 4fb64bef2711947c0f6a51e3c34542ced61b7f90
@@ -67,6 +67,7 @@ QgsComposerMapWidget::QgsComposerMapWidget( QgsComposerMap* composerMap ): QWidg
if ( mComposerMap )
{
//insert available maps into mMapComboBox
mOverviewFrameMapComboBox->addItem( tr( "None" ), -1 );
const QgsComposition* composition = mComposerMap->composition();
if ( composition )
{
@@ -341,6 +342,10 @@ void QgsComposerMapWidget::updateGuiElements()
mDrawCanvasItemsCheckBox->setCheckState( Qt::Unchecked );
}

//overview frame
int overviewMapFrameId = mComposerMap->overviewFrameMapId();
mOverviewFrameMapComboBox->setCurrentIndex( mOverviewFrameMapComboBox->findData( overviewMapFrameId ) );

//grid
if ( mComposerMap->gridEnabled() )
{
@@ -539,13 +544,18 @@ void QgsComposerMapWidget::on_mDrawCanvasItemsCheckBox_stateChanged( int state )
mComposerMap->endCommand();
}

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

if ( text == tr( "None" ) )
{
mComposerMap->setOverviewFrameMap( -1 );
}

//get composition
const QgsComposition* composition = mComposerMap->composition();
if ( !composition )
@@ -578,47 +588,6 @@ void QgsComposerMapWidget::on_mOverviewFrameMapComboBox_activated( const QString

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 )
@@ -43,7 +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_mOverviewFrameMapComboBox_currentIndexChanged( 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 ), mOverviewFrameMap( 0 ), mGridEnabled( false ), mGridStyle( Solid ),
: QgsComposerItem( x, y, width, height, composition ), mKeepLayerSet( false ), mOverviewFrameMapId( -1 ), 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 ), mOverviewFrameMap( 0 ), mGridEnabled( false ), mGridStyle( Solid ),
: QgsComposerItem( 0, 0, 10, 10, composition ), mKeepLayerSet( false ), mOverviewFrameMapId( -1 ), 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,7 +364,7 @@ void QgsComposerMap::paint( QPainter* painter, const QStyleOptionGraphicsItem* i
drawSelectionBoxes( painter );
}

if ( mOverviewFrameMap )
if ( mOverviewFrameMapId != -1 )
{
drawOverviewMapExtent( painter );
}
@@ -663,6 +663,9 @@ bool QgsComposerMap::writeXML( QDomElement& elem, QDomDocument & doc ) const
composerMapElem.setAttribute( "drawCanvasItems", "false" );
}

//overview map frame
composerMapElem.setAttribute( "overviewMapFrame", mOverviewFrameMapId );

//extent
QDomElement extentElem = doc.createElement( "Extent" );
extentElem.setAttribute( "xmin", QString::number( mExtent.xMinimum() ) );
@@ -683,12 +686,8 @@ bool QgsComposerMap::writeXML( QDomElement& elem, QDomDocument & doc ) const
}
composerMapElem.appendChild( layerSetElem );

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

//grid
QDomElement gridElem = doc.createElement( "Grid" );
@@ -757,6 +756,8 @@ bool QgsComposerMap::readXML( const QDomElement& itemElem, const QDomDocument& d
mPreviewMode = Rectangle;
}

mOverviewFrameMapId = itemElem.attribute( "overviewFrameMap", "-1" ).toInt();

//extent
QDomNodeList extentNodeList = itemElem.elementsByTagName( "Extent" );
if ( extentNodeList.size() > 0 )
@@ -810,26 +811,6 @@ 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 )
@@ -1569,40 +1550,24 @@ double QgsComposerMap::mapUnitsToMM() const

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 )
if ( mOverviewFrameMapId != -1 )
{
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;
const QgsComposerMap* map = mComposition->getComposerMapById( mapId );
if ( map )
{
QObject::disconnect( map, SIGNAL( extentChanged() ), this, SLOT( repaint() ) );
}
}
else
mOverviewFrameMapId = mapId;
if ( mOverviewFrameMapId != -1 )
{
return mOverviewFrameMap->id();
const QgsComposerMap* map = mComposition->getComposerMapById( mapId );
if ( map )
{
QObject::connect( map, SIGNAL( extentChanged() ), this, SLOT( repaint() ) );
}
}
update();
}

void QgsComposerMap::transformShift( double& xShift, double& yShift ) const
@@ -1916,12 +1881,18 @@ void QgsComposerMap::sortGridLinesOnBorders( const QList< QPair< double, QLineF

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

const QgsComposerMap* overviewFrameMap = mComposition->getComposerMapById( mOverviewFrameMapId );
if ( !overviewFrameMap )
{
return;
}

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

@@ -292,7 +292,7 @@ class CORE_EXPORT QgsComposerMap : public QgsComposerItem
/**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;
int overviewFrameMapId() const { return mOverviewFrameMapId; }

signals:
void extentChanged();
@@ -344,8 +344,8 @@ 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;
/**Id of map which displays its extent rectangle into this composer map (overview map functionality). -1 if not present*/
int mOverviewFrameMapId;

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

0 comments on commit 4fb64be

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