Skip to content
Permalink
Browse files

[composer] Correctly update extent when restoring composermap state, …

…except when composer map is not yet visible after loading
  • Loading branch information
manisandro authored and nyalldawson committed Apr 15, 2014
1 parent 31c3b0d commit b9bd4d247e021b8c98345d5f1372a510eee67041
@@ -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();

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

@@ -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

@@ -868,13 +868,20 @@ 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();

if ( mapsToRestore )
{
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;
}

0 comments on commit b9bd4d2

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