Skip to content
Permalink
Browse files

Fix for ticket #6062, unique composer map id in copy / paste

  • Loading branch information
mhugent committed Jul 19, 2012
1 parent 408d266 commit b299e0893c84eccc66116c898f2508eb9adc8b6e
Showing with 33 additions and 12 deletions.
  1. +28 −12 src/core/composer/qgscomposermap.cpp
  2. +4 −0 src/core/composer/qgscomposermap.h
  3. +1 −0 src/core/composer/qgscomposition.cpp
@@ -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;
@@ -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;
}
@@ -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();

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

0 comments on commit b299e08

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