Skip to content

Commit

Permalink
- add find by UUID
Browse files Browse the repository at this point in the history
  • Loading branch information
olivierdalang authored and mhugent committed Mar 15, 2013
1 parent 00c832b commit 1e30eb0
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 0 deletions.
12 changes: 12 additions & 0 deletions python/core/composer/qgscomposition.sip
Expand Up @@ -106,13 +106,25 @@ class QgsComposition : QGraphicsScene
const QgsComposerHtml* getComposerHtmlByItem( QgsComposerItem *item ) const;

/**Returns a composer item given its text identifier.
Ids are not necessarely unique, but this function returns only one element.
@note added in 2.0
@param theId - A QString representing the identifier of the item to
retrieve.
@return QgsComposerItem pointer or 0 pointer if no such item exists.
**/
const QgsComposerItem* getComposerItemById( QString theId ) const;


/**Returns a composer item given its unique identifier.
Warning : ids are not necessarely unique, but this function returns only one element.
@note added in 2.0
@param theId - A QString representing the UUID of the item to retrieve.
@param inAllComposers - Whether the search should be done in all composers of the project
@return QgsComposerItem pointer or 0 pointer if no such item exists.
**/
//const QgsComposerItem* getComposerItemByUuid( QString theUuid, bool inAllComposers = false ) const;
const QgsComposerItem* getComposerItemByUuid( QString theUuid ) const;

int printResolution() const;
void setPrintResolution( int dpi );

Expand Down
55 changes: 55 additions & 0 deletions src/core/composer/qgscomposition.cpp
Expand Up @@ -261,6 +261,61 @@ const QgsComposerItem* QgsComposition::getComposerItemById( QString theId ) cons
}
return 0;
}
/*
const QgsComposerItem* QgsComposition::getComposerItemByUuid( QString theUuid, bool inAllComposers ) const
{
//This does not work since it seems impossible to get the QgisApp::instance() from here... Is there a workaround ?
QSet<QgsComposer*> composers = QSet<QgsComposer*>();
if( inAllComposers )
{
composers = QgisApp::instance()->printComposers();
}
else
{
composers.insert( this )
}
QSet<QgsComposer*>::const_iterator it = composers.constBegin();
for ( ; it != composers.constEnd(); ++it )
{
QList<QGraphicsItem *> itemList = ( *it )->items();
QList<QGraphicsItem *>::iterator itemIt = itemList.begin();
for ( ; itemIt != itemList.end(); ++itemIt )
{
const QgsComposerItem* mypItem = dynamic_cast<const QgsComposerItem *>( *itemIt );
if ( mypItem )
{
if ( mypItem->uuid() == theUuid )
{
return mypItem;
}
}
}
}
return 0;
}
*/

const QgsComposerItem* QgsComposition::getComposerItemByUuid( QString theUuid ) const
{
QList<QGraphicsItem *> itemList = items();
QList<QGraphicsItem *>::iterator itemIt = itemList.begin();
for ( ; itemIt != itemList.end(); ++itemIt )
{
const QgsComposerItem* mypItem = dynamic_cast<const QgsComposerItem *>( *itemIt );
if ( mypItem )
{
if ( mypItem->uuid() == theUuid )
{
return mypItem;
}
}
}

return 0;
}

int QgsComposition::pixelFontSize( double pointSize ) const
{
Expand Down
13 changes: 13 additions & 0 deletions src/core/composer/qgscomposition.h
Expand Up @@ -30,6 +30,7 @@
#include "qgscomposeritemcommand.h"
#include "qgsatlascomposition.h"

class QgisApp;
class QgsComposerFrame;
class QgsComposerItem;
class QgsComposerMap;
Expand All @@ -50,6 +51,7 @@ class QgsComposerAttributeTable;
class QgsComposerMultiFrame;
class QgsComposerMultiFrameCommand;
class QgsVectorLayer;
class QgsComposer;

/** \ingroup MapComposer
* Graphics scene for map printing. The class manages the paper item which always
Expand Down Expand Up @@ -158,13 +160,24 @@ class CORE_EXPORT QgsComposition: public QGraphicsScene
const QgsComposerHtml* getComposerHtmlByItem( QgsComposerItem *item ) const;

/**Returns a composer item given its text identifier.
Ids are not necessarely unique, but this function returns only one element.
@note added in 2.0
@param theId - A QString representing the identifier of the item to
retrieve.
@return QgsComposerItem pointer or 0 pointer if no such item exists.
**/
const QgsComposerItem* getComposerItemById( QString theId ) const;

/**Returns a composer item given its unique identifier.
@note added in 2.0
@param theId - A QString representing the UUID of the item to
@param inAllComposers - Whether the search should be done in all composers of the project
retrieve.
@return QgsComposerItem pointer or 0 pointer if no such item exists.
**/
//const QgsComposerItem* getComposerItemByUuid( QString theUuid, bool inAllComposers = false ) const;//does not work since it's impossible to get QGisApp::instance()
const QgsComposerItem* getComposerItemByUuid( QString theUuid ) const;

int printResolution() const {return mPrintResolution;}
void setPrintResolution( int dpi ) {mPrintResolution = dpi;}

Expand Down

0 comments on commit 1e30eb0

Please sign in to comment.