Skip to content

Commit 1e30eb0

Browse files
olivierdalangmhugent
authored andcommittedMar 15, 2013
- add find by UUID
1 parent 00c832b commit 1e30eb0

File tree

3 files changed

+80
-0
lines changed

3 files changed

+80
-0
lines changed
 

‎python/core/composer/qgscomposition.sip

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,25 @@ class QgsComposition : QGraphicsScene
106106
const QgsComposerHtml* getComposerHtmlByItem( QgsComposerItem *item ) const;
107107

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

117+
118+
/**Returns a composer item given its unique identifier.
119+
Warning : ids are not necessarely unique, but this function returns only one element.
120+
@note added in 2.0
121+
@param theId - A QString representing the UUID of the item to retrieve.
122+
@param inAllComposers - Whether the search should be done in all composers of the project
123+
@return QgsComposerItem pointer or 0 pointer if no such item exists.
124+
**/
125+
//const QgsComposerItem* getComposerItemByUuid( QString theUuid, bool inAllComposers = false ) const;
126+
const QgsComposerItem* getComposerItemByUuid( QString theUuid ) const;
127+
116128
int printResolution() const;
117129
void setPrintResolution( int dpi );
118130

‎src/core/composer/qgscomposition.cpp

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,61 @@ const QgsComposerItem* QgsComposition::getComposerItemById( QString theId ) cons
261261
}
262262
return 0;
263263
}
264+
/*
265+
const QgsComposerItem* QgsComposition::getComposerItemByUuid( QString theUuid, bool inAllComposers ) const
266+
{
267+
//This does not work since it seems impossible to get the QgisApp::instance() from here... Is there a workaround ?
268+
QSet<QgsComposer*> composers = QSet<QgsComposer*>();
269+
270+
if( inAllComposers )
271+
{
272+
composers = QgisApp::instance()->printComposers();
273+
}
274+
else
275+
{
276+
composers.insert( this )
277+
}
278+
279+
QSet<QgsComposer*>::const_iterator it = composers.constBegin();
280+
for ( ; it != composers.constEnd(); ++it )
281+
{
282+
QList<QGraphicsItem *> itemList = ( *it )->items();
283+
QList<QGraphicsItem *>::iterator itemIt = itemList.begin();
284+
for ( ; itemIt != itemList.end(); ++itemIt )
285+
{
286+
const QgsComposerItem* mypItem = dynamic_cast<const QgsComposerItem *>( *itemIt );
287+
if ( mypItem )
288+
{
289+
if ( mypItem->uuid() == theUuid )
290+
{
291+
return mypItem;
292+
}
293+
}
294+
}
295+
}
296+
297+
return 0;
298+
}
299+
*/
300+
301+
const QgsComposerItem* QgsComposition::getComposerItemByUuid( QString theUuid ) const
302+
{
303+
QList<QGraphicsItem *> itemList = items();
304+
QList<QGraphicsItem *>::iterator itemIt = itemList.begin();
305+
for ( ; itemIt != itemList.end(); ++itemIt )
306+
{
307+
const QgsComposerItem* mypItem = dynamic_cast<const QgsComposerItem *>( *itemIt );
308+
if ( mypItem )
309+
{
310+
if ( mypItem->uuid() == theUuid )
311+
{
312+
return mypItem;
313+
}
314+
}
315+
}
316+
317+
return 0;
318+
}
264319

265320
int QgsComposition::pixelFontSize( double pointSize ) const
266321
{

‎src/core/composer/qgscomposition.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "qgscomposeritemcommand.h"
3131
#include "qgsatlascomposition.h"
3232

33+
class QgisApp;
3334
class QgsComposerFrame;
3435
class QgsComposerItem;
3536
class QgsComposerMap;
@@ -50,6 +51,7 @@ class QgsComposerAttributeTable;
5051
class QgsComposerMultiFrame;
5152
class QgsComposerMultiFrameCommand;
5253
class QgsVectorLayer;
54+
class QgsComposer;
5355

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

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

171+
/**Returns a composer item given its unique identifier.
172+
@note added in 2.0
173+
@param theId - A QString representing the UUID of the item to
174+
@param inAllComposers - Whether the search should be done in all composers of the project
175+
retrieve.
176+
@return QgsComposerItem pointer or 0 pointer if no such item exists.
177+
**/
178+
//const QgsComposerItem* getComposerItemByUuid( QString theUuid, bool inAllComposers = false ) const;//does not work since it's impossible to get QGisApp::instance()
179+
const QgsComposerItem* getComposerItemByUuid( QString theUuid ) const;
180+
168181
int printResolution() const {return mPrintResolution;}
169182
void setPrintResolution( int dpi ) {mPrintResolution = dpi;}
170183

0 commit comments

Comments
 (0)
Please sign in to comment.