[composer] Correctly update extent when restoring composermap state, except when composer map is not yet visible after loading

This commit is contained in:
Sandro Mani 2014-04-07 12:03:11 +02:00 committed by Nyall Dawson
parent 31c3b0dc55
commit b9bd4d247e
4 changed files with 33 additions and 4 deletions

View File

@ -401,6 +401,12 @@ class QgsComposerMap : QgsComposerItem
/** Sets the margin size (percentage) used when the map is in atlas mode */
void setAtlasMargin( double margin );
/** Sets whether updates to the composer map are enabled. */
void setUpdatesEnabled( bool enabled );
/** Returns whether updates to the composer map are enabled. */
bool updatesEnabled() const;
signals:
void extentChanged();

View File

@ -44,7 +44,7 @@
QgsComposerMap::QgsComposerMap( QgsComposition *composition, int x, int y, int width, int height )
: QgsComposerItem( x, y, width, height, composition ), mMapRotation( 0 ), mKeepLayerSet( false )
, mOverviewFrameMapId( -1 ), mOverviewBlendMode( QPainter::CompositionMode_SourceOver ), mOverviewInverted( false ), mOverviewCentered( false )
, mGridEnabled( false ), mGridStyle( Solid )
, mUpdatesEnabled( true ), mGridEnabled( false ), mGridStyle( Solid )
, mGridIntervalX( 0.0 ), mGridIntervalY( 0.0 ), mGridOffsetX( 0.0 ), mGridOffsetY( 0.0 ), mGridAnnotationFontColor( QColor( 0, 0, 0 ) )
, mGridAnnotationPrecision( 3 ), mShowGridAnnotation( false ), mGridBlendMode( QPainter::CompositionMode_SourceOver )
, mLeftGridAnnotationPosition( OutsideMapFrame ), mRightGridAnnotationPosition( OutsideMapFrame )
@ -102,7 +102,7 @@ QgsComposerMap::QgsComposerMap( QgsComposition *composition, int x, int y, int w
QgsComposerMap::QgsComposerMap( QgsComposition *composition )
: QgsComposerItem( 0, 0, 10, 10, composition ), mMapRotation( 0 ), mKeepLayerSet( false ), mOverviewFrameMapId( -1 )
, mOverviewBlendMode( QPainter::CompositionMode_SourceOver ), mOverviewInverted( false ), mOverviewCentered( false )
, mGridEnabled( false ), mGridStyle( Solid )
, mUpdatesEnabled( true ), mGridEnabled( false ), mGridStyle( Solid )
, mGridIntervalX( 0.0 ), mGridIntervalY( 0.0 ), mGridOffsetX( 0.0 ), mGridOffsetY( 0.0 ), mGridAnnotationFontColor( QColor( 0, 0, 0 ) )
, mGridAnnotationPrecision( 3 ), mShowGridAnnotation( false ), mGridBlendMode( QPainter::CompositionMode_SourceOver )
, mLeftGridAnnotationPosition( OutsideMapFrame ), mRightGridAnnotationPosition( OutsideMapFrame )
@ -734,6 +734,11 @@ void QgsComposerMap::setMapRotation( double r )
void QgsComposerMap::updateItem()
{
if ( !mUpdatesEnabled )
{
return;
}
if ( mPreviewMode != QgsComposerMap::Rectangle && !mCacheUpdated )
{
cache();
@ -1065,8 +1070,7 @@ bool QgsComposerMap::readXML( const QDomElement& itemElem, const QDomDocument& d
xmax = extentElem.attribute( "xmax" ).toDouble();
ymin = extentElem.attribute( "ymin" ).toDouble();
ymax = extentElem.attribute( "ymax" ).toDouble();
mExtent = QgsRectangle( xmin, ymin, xmax, ymax );
setNewExtent( QgsRectangle( xmin, ymin, xmax, ymax ) );
}
//map rotation
@ -2553,3 +2557,4 @@ void QgsComposerMap::sizeChangedByRotation( double& width, double& height )
//kept for api compatibility with QGIS 2.0 - use mMapRotation
return QgsComposerItem::sizeChangedByRotation( width, height, mMapRotation );
}

View File

@ -439,6 +439,12 @@ class CORE_EXPORT QgsComposerMap : public QgsComposerItem
/** Sets the margin size (percentage) used when the map is in atlas mode */
void setAtlasMargin( double margin ) { mAtlasMargin = margin; }
/** Sets whether updates to the composer map are enabled. */
void setUpdatesEnabled( bool enabled ) { mUpdatesEnabled = enabled; }
/** Returns whether updates to the composer map are enabled. */
bool updatesEnabled() const { return mUpdatesEnabled; }
signals:
void extentChanged();
@ -518,6 +524,9 @@ class CORE_EXPORT QgsComposerMap : public QgsComposerItem
/** Centering mode for overview */
bool mOverviewCentered;
/** Whether updates to the map are enabled */
bool mUpdatesEnabled;
/**Establishes signal/slot connection for update in case of layer change*/
void connectUpdateSlot();
@ -659,3 +668,4 @@ class CORE_EXPORT QgsComposerMap : public QgsComposerItem
};
#endif

View File

@ -868,6 +868,12 @@ void QgsComposition::addItemsFromXML( const QDomElement& elem, const QDomDocumen
{
QDomElement currentComposerMapElem = composerMapList.at( i ).toElement();
QgsComposerMap* newMap = new QgsComposerMap( this );
if ( mapsToRestore )
{
newMap->setUpdatesEnabled( false );
}
newMap->readXML( currentComposerMapElem, doc );
newMap->assignFreeId();
@ -875,6 +881,7 @@ void QgsComposition::addItemsFromXML( const QDomElement& elem, const QDomDocumen
{
mapsToRestore->insert( newMap, ( int )( newMap->previewMode() ) );
newMap->setPreviewMode( QgsComposerMap::Rectangle );
newMap->setUpdatesEnabled( true );
}
addComposerMap( newMap, false );
newMap->setZValue( newMap->zValue() + zOrderOffset );
@ -2579,3 +2586,4 @@ double QgsComposition::relativePosition( double position, double beforeMin, doub
//return linearly scaled position
return m * position + c;
}