Skip to content
Permalink
Browse files

Merge branch 'master' of github.com:qgis/Quantum-GIS

  • Loading branch information
timlinux committed Jul 19, 2012
2 parents 78bbb65 + 3af7ef3 commit 814ea09272258b961a6d1c0c7ef02250db9c3b5d
@@ -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 )
{
@@ -34,7 +34,7 @@ QgsCompositionChecker::~QgsCompositionChecker()
{
}

bool QgsCompositionChecker::testComposition()
bool QgsCompositionChecker::testComposition( int page )
{
if ( !mComposition )
{
@@ -70,9 +70,7 @@ bool QgsCompositionChecker::testComposition()
outputImage.setDotsPerMeterY( expectedImage.dotsPerMeterX() );
outputImage.fill( 0 );
QPainter p( &outputImage );
QRectF sourceArea( 0, 0, mComposition->paperWidth(), mComposition->paperHeight() );
QRectF targetArea( 0, 0, width, height );
mComposition->render( &p, targetArea, sourceArea );
mComposition->renderPage( &p, page );
p.end();

QString renderedFilePath = QDir::tempPath() + QDir::separator() + QFileInfo( mExpectedImageFile ).baseName() + "_rendered.png";
@@ -27,7 +27,7 @@ class QgsCompositionChecker
QgsCompositionChecker( const QString& testName, QgsComposition* composition, const QString& expectedImageFile );
~QgsCompositionChecker();

bool testComposition();
bool testComposition( int page = 0 );

private:
QgsCompositionChecker(); //forbidden
@@ -37,6 +37,7 @@ class TestQgsComposerMap: public QObject
void render(); //test if rendering of the composition with composr map is correct
void grid(); //test if grid and grid annotation works
void overviewMap(); //test if overview map frame works
void uniqueId(); //test if map id is adapted when doing copy paste

private:
QgsComposition* mComposition;
@@ -131,5 +132,32 @@ void TestQgsComposerMap::overviewMap()
QVERIFY( testResult );
}

void TestQgsComposerMap::uniqueId()
{
QDomDocument doc;
QDomElement documentElement = doc.createElement( "ComposerItemClipboard" );
mComposerMap->writeXML( documentElement, doc );
mComposition->addItemsFromXML( documentElement, doc, 0, false );

//test if both composer maps have different ids
const QgsComposerMap* newMap = 0;
QList<const QgsComposerMap*> mapList = mComposition->composerMapItems();
QList<const QgsComposerMap*>::const_iterator mapIt = mapList.constBegin();
for ( ; mapIt != mapList.constEnd(); ++mapIt )
{
if ( *mapIt != mComposerMap )
{
newMap = *mapIt;
break;
}
}
int oldId = mComposerMap->id();
int newId = newMap->id();

mComposition->removeComposerItem( const_cast<QgsComposerMap*>( newMap ) );

QVERIFY( oldId != newId );
}

QTEST_MAIN( TestQgsComposerMap )
#include "moc_testqgscomposermap.cxx"

0 comments on commit 814ea09

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