Skip to content

Commit

Permalink
Fix for ticket #6062, unique composer map id in copy / paste
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Jul 19, 2012
1 parent 408d266 commit b299e08
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 12 deletions.
40 changes: 28 additions & 12 deletions src/core/composer/qgscomposermap.cpp
Expand Up @@ -49,18 +49,8 @@ QgsComposerMap::QgsComposerMap( QgsComposition *composition, int x, int y, int w
mOverviewFrameMapSymbol = 0;
createDefaultOverviewFrameSymbol();

//mId = mComposition->composerMapItems().size();
int maxId = -1;
QList<const QgsComposerMap*> mapList = mComposition->composerMapItems();
QList<const QgsComposerMap*>::const_iterator mapIt = mapList.constBegin();
for ( ; mapIt != mapList.constEnd(); ++mapIt )
{
if (( *mapIt )->id() > maxId )
{
maxId = ( *mapIt )->id();
}
}
mId = maxId + 1;
mId = 0;
assignFreeId();

mMapRenderer = mComposition->mapRenderer();
mPreviewMode = QgsComposerMap::Rectangle;
Expand Down Expand Up @@ -1957,3 +1947,29 @@ void QgsComposerMap::createDefaultOverviewFrameSymbol()
mOverviewFrameMapSymbol = QgsFillSymbolV2::createSimple( properties );
mOverviewFrameMapSymbol->setAlpha( 0.3 );
}

void QgsComposerMap::assignFreeId()
{
if ( !mComposition )
{
return;
}

const QgsComposerMap* existingMap = mComposition->getComposerMapById( mId );
if ( !existingMap )
{
return; //keep mId as it is still available
}

int maxId = -1;
QList<const QgsComposerMap*> mapList = mComposition->composerMapItems();
QList<const QgsComposerMap*>::const_iterator mapIt = mapList.constBegin();
for ( ; mapIt != mapList.constEnd(); ++mapIt )
{
if (( *mapIt )->id() > maxId )
{
maxId = ( *mapIt )->id();
}
}
mId = maxId + 1;
}
4 changes: 4 additions & 0 deletions src/core/composer/qgscomposermap.h
Expand Up @@ -300,6 +300,10 @@ class CORE_EXPORT QgsComposerMap : public QgsComposerItem
void setOverviewFrameMapSymbol( QgsFillSymbolV2* symbol );
QgsFillSymbolV2* overviewFrameMapSymbol() { return mOverviewFrameMapSymbol; }

/**Sets mId to a number not yet used in the composition. mId is kept if it is not in use.
Usually, this function is called before adding the composer map to the composition*/
void assignFreeId();

signals:
void extentChanged();

Expand Down
1 change: 1 addition & 0 deletions src/core/composer/qgscomposition.cpp
Expand Up @@ -309,6 +309,7 @@ void QgsComposition::addItemsFromXML( const QDomElement& elem, const QDomDocumen
QDomElement currentComposerMapElem = composerMapList.at( i ).toElement();
QgsComposerMap* newMap = new QgsComposerMap( this );
newMap->readXML( currentComposerMapElem, doc );
newMap->assignFreeId();

if ( mapsToRestore )
{
Expand Down

0 comments on commit b299e08

Please sign in to comment.