Skip to content
Permalink
Browse files

[composer] Add api method for toggling visibility of composer items

  • Loading branch information
nyalldawson committed Jul 28, 2014
1 parent 53e1aba commit 200a3431e95acf9f0edaf87ec5ba4e58c8494977
@@ -517,6 +517,15 @@ class QgsComposerItem : QgsComposerObject, QGraphicsRectItem
*/
virtual QString displayName() const;

/**Sets visibility for item.
* @param visible set to true to show item, false to hide item
* @note QGraphicsItem::setVisible should not be called directly
* on a QgsComposerItem, as some item types (eg groups) need to override
* the visibility toggle.
* @note added in version 2.5
*/
virtual void setVisibility( const bool visible );

/**Returns whether this item is part of a group
* @returns true if item is in a group
* @note added in version 2.5
@@ -20,6 +20,9 @@ class QgsComposerItemGroup: QgsComposerItem
/**Sets this items bound in scene coordinates such that 1 item size units
corresponds to 1 scene size unit*/
void setSceneRect( const QRectF& rectangle );

//overridden to also hide grouped items
virtual void setVisibility( const bool visible );

/** stores state in Dom node
* @param elem is Dom element corresponding to 'Composer' tag
@@ -185,7 +185,7 @@ bool QgsComposerItem::_writeXML( QDomElement& itemElem, QDomDocument& doc ) cons
composerItemElem.setAttribute( "frame", "false" );
}

//frame
//background
if ( mBackground )
{
composerItemElem.setAttribute( "background", "true" );
@@ -211,6 +211,7 @@ bool QgsComposerItem::_writeXML( QDomElement& itemElem, QDomDocument& doc ) cons
composerItemElem.setAttribute( "itemRotation", QString::number( mItemRotation ) );
composerItemElem.setAttribute( "uuid", mUuid );
composerItemElem.setAttribute( "id", mId );
composerItemElem.setAttribute( "visibility", isVisible() );
//position lock for mouse moves/resizes
if ( mItemPositionLocked )
{
@@ -223,7 +224,6 @@ bool QgsComposerItem::_writeXML( QDomElement& itemElem, QDomDocument& doc ) cons

composerItemElem.setAttribute( "lastValidViewScaleFactor", QString::number( mLastValidViewScaleFactor ) );


//frame color
QDomElement frameColorElem = doc.createElement( "FrameColor" );
QColor frameColor = pen().color();
@@ -310,6 +310,9 @@ bool QgsComposerItem::_readXML( const QDomElement& itemElem, const QDomDocument&
setPositionLock( false );
}

//visibility
setVisibility( itemElem.attribute( "visibility", "1" ) != "0" );

//position
int page;
double x, y, pagex, pagey, width, height;
@@ -1329,3 +1332,8 @@ QString QgsComposerItem::displayName() const

return tr( "<item>" );
}

void QgsComposerItem::setVisibility( const bool visible )
{
QGraphicsItem::setVisible( visible );
}
@@ -473,6 +473,15 @@ class CORE_EXPORT QgsComposerItem: public QgsComposerObject, public QGraphicsRec
*/
virtual QString displayName() const;

/**Sets visibility for item.
* @param visible set to true to show item, false to hide item
* @note QGraphicsItem::setVisible should not be called directly
* on a QgsComposerItem, as some item types (eg groups) need to override
* the visibility toggle.
* @note added in version 2.5
*/
virtual void setVisibility( const bool visible );

/**Returns whether this item is part of a group
* @returns true if item is in a group
* @note added in version 2.5
@@ -144,6 +144,18 @@ void QgsComposerItemGroup::setSceneRect( const QRectF& rectangle )
QgsComposerItem::setSceneRect( rectangle );
}

void QgsComposerItemGroup::setVisibility( const bool visible )
{
//also set visibility for all items within the group
QSet<QgsComposerItem*>::iterator item_it = mItems.begin();
for ( ; item_it != mItems.end(); ++item_it )
{
( *item_it )->setVisibility( visible );
}
//lastly set visibility for group item itself
QgsComposerItem::setVisibility( visible );
}

void QgsComposerItemGroup::drawFrame( QPainter* p )
{
if ( !mComposition )
@@ -42,6 +42,9 @@ class CORE_EXPORT QgsComposerItemGroup: public QgsComposerItem
corresponds to 1 scene size unit*/
void setSceneRect( const QRectF& rectangle );

//overridden to also hide grouped items
virtual void setVisibility( const bool visible );

/** stores state in Dom node
* @param elem is Dom element corresponding to 'Composer' tag
* @param doc is the Dom document

0 comments on commit 200a343

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