Skip to content

Commit

Permalink
[FEATURE][composer] Add checkbox and data defined button for controlling
Browse files Browse the repository at this point in the history
whether an item is excluded from composer exports/printouts.
  • Loading branch information
nyalldawson committed Sep 26, 2014
1 parent 89a7573 commit ce21425
Show file tree
Hide file tree
Showing 18 changed files with 182 additions and 0 deletions.
22 changes: 22 additions & 0 deletions python/core/composer/qgscomposeritem.sip
Expand Up @@ -543,6 +543,22 @@ class QgsComposerItem : QgsComposerObject, QGraphicsRectItem
* @note added in version 2.5
*/
virtual void setVisibility( const bool visible );

/**Returns whether the item should be excluded from composer exports and prints
* @param valueType controls whether the returned value is the user specified vaule,
* or the current evaluated value (which may be affected by data driven settings).
* @returns true if item should be excluded
* @note added in version 2.5
* @see setExcludeFromExports
*/
bool excludeFromExports( const QgsComposerObject::PropertyValueType valueType = QgsComposerObject::EvaluatedValue );

/**Sets whether the item should be excluded from composer exports and prints
* @param exclude set to true to exclude the item from exports
* @note added in version 2.5
* @see excludeFromExports
*/
virtual void setExcludeFromExports( const bool exclude );

/**Returns whether this item is part of a group
* @returns true if item is in a group
Expand Down Expand Up @@ -700,6 +716,12 @@ class QgsComposerItem : QgsComposerObject, QGraphicsRectItem

/**Update an item rect to consider data defined position and size of item*/
QRectF evalItemRect( const QRectF &newRect );

/**Returns whether the item should be drawn in the current context
* @returns true if item should be drawn
* @note added in QGIS 2.5
*/
bool shouldDrawItem() const;

signals:
/**Is emitted on item rotation change*/
Expand Down
1 change: 1 addition & 0 deletions python/core/composer/qgscomposerobject.sip
Expand Up @@ -30,6 +30,7 @@ class QgsComposerObject : QObject
ItemRotation, /*< rotation of item */
Transparency, /*< item transparency */
BlendMode, /*< item blend mode */
ExcludeFromExports, /*< exclude item from exports */
//composer map
MapRotation, /*< map rotation */
MapScale, /*< map scale */
Expand Down
24 changes: 24 additions & 0 deletions src/app/composer/qgscomposeritemwidget.cpp 100755 → 100644
Expand Up @@ -179,6 +179,9 @@ QgsComposerItemWidget::QgsComposerItemWidget( QWidget* parent, QgsComposerItem*
connect( mBlendModeDDBtn, SIGNAL( dataDefinedChanged( const QString& ) ), this, SLOT( updateDataDefinedProperty( ) ) );
connect( mBlendModeDDBtn, SIGNAL( dataDefinedActivated( bool ) ), this, SLOT( updateDataDefinedProperty( ) ) );
connect( mBlendModeDDBtn, SIGNAL( dataDefinedActivated( bool ) ), mBlendModeCombo, SLOT( setDisabled( bool ) ) );

connect( mExcludePrintsDDBtn, SIGNAL( dataDefinedChanged( const QString& ) ), this, SLOT( updateDataDefinedProperty( ) ) );
connect( mExcludePrintsDDBtn, SIGNAL( dataDefinedActivated( bool ) ), this, SLOT( updateDataDefinedProperty( ) ) );
}

QgsComposerItemWidget::QgsComposerItemWidget(): QgsComposerItemBaseWidget( 0, 0 )
Expand Down Expand Up @@ -504,6 +507,7 @@ void QgsComposerItemWidget::setValuesForGuiNonPositionElements()
mFrameJoinStyleCombo->blockSignals( true );
mBackgroundColorButton->blockSignals( true );
mItemRotationSpinBox->blockSignals( true );
mExcludeFromPrintsCheckBox->blockSignals( true );

mBackgroundColorButton->setColor( mItem->brush().color() );
mFrameColorButton->setColor( mItem->pen().color() );
Expand All @@ -516,6 +520,7 @@ void QgsComposerItemWidget::setValuesForGuiNonPositionElements()
mTransparencySlider->setValue( mItem->transparency() );
mTransparencySpnBx->setValue( mItem->transparency() );
mItemRotationSpinBox->setValue( mItem->itemRotation( QgsComposerObject::OriginalValue ) );
mExcludeFromPrintsCheckBox->setChecked( mItem->excludeFromExports( QgsComposerObject::OriginalValue ) );

mBackgroundColorButton->blockSignals( false );
mFrameColorButton->blockSignals( false );
Expand All @@ -528,6 +533,7 @@ void QgsComposerItemWidget::setValuesForGuiNonPositionElements()
mTransparencySlider->blockSignals( false );
mTransparencySpnBx->blockSignals( false );
mItemRotationSpinBox->blockSignals( false );
mExcludeFromPrintsCheckBox->blockSignals( false );
}

void QgsComposerItemWidget::populateDataDefinedButtons()
Expand All @@ -542,6 +548,7 @@ void QgsComposerItemWidget::populateDataDefinedButtons()
mItemRotationDDBtn->blockSignals( true );
mTransparencyDDBtn->blockSignals( true );
mBlendModeDDBtn->blockSignals( true );
mExcludePrintsDDBtn->blockSignals( true );

//initialise buttons to use atlas coverage layer
mXPositionDDBtn->init( vl, mItem->dataDefinedProperty( QgsComposerObject::PositionX ),
Expand All @@ -558,6 +565,8 @@ void QgsComposerItemWidget::populateDataDefinedButtons()
QgsDataDefinedButton::AnyType, QgsDataDefinedButton::intTranspDesc() );
mBlendModeDDBtn->init( vl, mItem->dataDefinedProperty( QgsComposerObject::BlendMode ),
QgsDataDefinedButton::String, QgsDataDefinedButton::blendModesDesc() );
mExcludePrintsDDBtn->init( vl, mItem->dataDefinedProperty( QgsComposerObject::ExcludeFromExports ),
QgsDataDefinedButton::String, QgsDataDefinedButton::boolDesc() );

//initial state of controls - disable related controls when dd buttons are active
mXLineEdit->setEnabled( !mXPositionDDBtn->isActive() );
Expand All @@ -578,6 +587,7 @@ void QgsComposerItemWidget::populateDataDefinedButtons()
mItemRotationDDBtn->blockSignals( false );
mTransparencyDDBtn->blockSignals( false );
mBlendModeDDBtn->blockSignals( false );
mExcludePrintsDDBtn->blockSignals( false );
}

QgsComposerObject::DataDefinedProperty QgsComposerItemWidget::ddPropertyForWidget( QgsDataDefinedButton* widget )
Expand Down Expand Up @@ -610,6 +620,10 @@ QgsComposerObject::DataDefinedProperty QgsComposerItemWidget::ddPropertyForWidge
{
return QgsComposerObject::BlendMode;
}
else if ( widget == mExcludePrintsDDBtn )
{
return QgsComposerObject::ExcludeFromExports;
}

return QgsComposerObject::NoProperty;
}
Expand Down Expand Up @@ -782,3 +796,13 @@ void QgsComposerItemWidget::on_mItemRotationSpinBox_valueChanged( double val )
mItem->endCommand();
}
}

void QgsComposerItemWidget::on_mExcludeFromPrintsCheckBox_toggled( bool checked )
{
if ( mItem )
{
mItem->beginCommand( tr( "Exclude from exports changed" ) );
mItem->setExcludeFromExports( checked );
mItem->endCommand();
}
}
1 change: 1 addition & 0 deletions src/app/composer/qgscomposeritemwidget.h
Expand Up @@ -112,6 +112,7 @@ class QgsComposerItemWidget: public QgsComposerItemBaseWidget, private Ui::QgsCo
void on_mTransparencySlider_valueChanged( int value );

void on_mItemRotationSpinBox_valueChanged( double val );
void on_mExcludeFromPrintsCheckBox_toggled( bool checked );

void setValuesForGuiElements();
//sets the values for all position related (x, y, width, height) elements
Expand Down
4 changes: 4 additions & 0 deletions src/core/composer/qgscomposerarrow.cpp
Expand Up @@ -94,6 +94,10 @@ void QgsComposerArrow::paint( QPainter* painter, const QStyleOptionGraphicsItem
{
return;
}
if ( !shouldDrawItem() )
{
return;
}

drawBackground( painter );

Expand Down
4 changes: 4 additions & 0 deletions src/core/composer/qgscomposerattributetable.cpp
Expand Up @@ -138,6 +138,10 @@ void QgsComposerAttributeTable::paint( QPainter* painter, const QStyleOptionGrap
{
return;
}
if ( !shouldDrawItem() )
{
return;
}
QgsComposerTable::paint( painter, itemStyle, pWidget );
}

Expand Down
4 changes: 4 additions & 0 deletions src/core/composer/qgscomposerframe.cpp
Expand Up @@ -147,6 +147,10 @@ void QgsComposerFrame::paint( QPainter* painter, const QStyleOptionGraphicsItem*
{
return;
}
if ( !shouldDrawItem() )
{
return;
}

drawBackground( painter );
if ( mMultiFrame )
Expand Down
44 changes: 44 additions & 0 deletions src/core/composer/qgscomposeritem.cpp
Expand Up @@ -67,6 +67,8 @@ QgsComposerItem::QgsComposerItem( QgsComposition* composition, bool manageZValue
, mBlendMode( QPainter::CompositionMode_SourceOver )
, mEffectsEnabled( true )
, mTransparency( 0 )
, mExcludeFromExports( false )
, mEvaluatedExcludeFromExports( false )
, mLastUsedPositionMode( UpperLeft )
, mIsGroupMember( false )
, mCurrentExportLayer( -1 )
Expand Down Expand Up @@ -94,6 +96,8 @@ QgsComposerItem::QgsComposerItem( qreal x, qreal y, qreal width, qreal height, Q
, mBlendMode( QPainter::CompositionMode_SourceOver )
, mEffectsEnabled( true )
, mTransparency( 0 )
, mExcludeFromExports( false )
, mEvaluatedExcludeFromExports( false )
, mLastUsedPositionMode( UpperLeft )
, mIsGroupMember( false )
, mCurrentExportLayer( -1 )
Expand Down Expand Up @@ -137,6 +141,7 @@ void QgsComposerItem::init( const bool manageZValue )
mDataDefinedNames.insert( QgsComposerObject::ItemRotation, QString( "dataDefinedRotation" ) );
mDataDefinedNames.insert( QgsComposerObject::Transparency, QString( "dataDefinedTransparency" ) );
mDataDefinedNames.insert( QgsComposerObject::BlendMode, QString( "dataDefinedBlendMode" ) );
mDataDefinedNames.insert( QgsComposerObject::ExcludeFromExports, QString( "dataDefinedExcludeExports" ) );

if ( mComposition )
{
Expand Down Expand Up @@ -261,6 +266,8 @@ bool QgsComposerItem::_writeXML( QDomElement& itemElem, QDomDocument& doc ) cons
//transparency
composerItemElem.setAttribute( "transparency", QString::number( mTransparency ) );

composerItemElem.setAttribute( "excludeFromExports", mExcludeFromExports );

QgsComposerObject::writeXML( composerItemElem, doc );
itemElem.appendChild( composerItemElem );

Expand Down Expand Up @@ -409,6 +416,9 @@ bool QgsComposerItem::_readXML( const QDomElement& itemElem, const QDomDocument&
//transparency
setTransparency( itemElem.attribute( "transparency" , "0" ).toInt() );

mExcludeFromExports = itemElem.attribute( "excludeFromExports", "0" ).toInt();
mEvaluatedExcludeFromExports = mExcludeFromExports;

QRectF evaluatedRect = evalItemRect( QRectF( x, y, width, height ) );
setSceneRect( evaluatedRect );

Expand Down Expand Up @@ -797,6 +807,18 @@ QRectF QgsComposerItem::evalItemRect( const QRectF &newRect )
return result;
}

bool QgsComposerItem::shouldDrawItem() const
{
if (( mComposition && mComposition->plotStyle() == QgsComposition::Preview ) || !mComposition )
{
//preview mode or no composition, so ok to draw item
return true;
}

//exporting composition, so check if item is excluded from exports
return !mEvaluatedExcludeFromExports;
}

void QgsComposerItem::drawBackground( QPainter* p )
{
if ( mBackground && p )
Expand Down Expand Up @@ -1305,6 +1327,17 @@ void QgsComposerItem::refreshDataDefinedProperty( const QgsComposerObject::DataD
{
refreshBlendMode();
}
if ( property == QgsComposerObject::ExcludeFromExports || property == QgsComposerObject::AllProperties )
{
bool exclude = mExcludeFromExports;
//data defined exclude from exports set?
QVariant exprVal;
if ( dataDefinedEvaluate( QgsComposerObject::ExcludeFromExports, exprVal ) )
{
exclude = exprVal.toBool();
}
mEvaluatedExcludeFromExports = exclude;
}

update();
}
Expand Down Expand Up @@ -1391,3 +1424,14 @@ void QgsComposerItem::setVisibility( const bool visible )
mComposition->itemsModel()->updateItemVisibility( this );
}
}

bool QgsComposerItem::excludeFromExports( const QgsComposerObject::PropertyValueType valueType )
{
return valueType == QgsComposerObject::EvaluatedValue ? mEvaluatedExcludeFromExports : mExcludeFromExports;
}

void QgsComposerItem::setExcludeFromExports( const bool exclude )
{
mExcludeFromExports = exclude;
refreshDataDefinedProperty( QgsComposerObject::ExcludeFromExports );
}
29 changes: 29 additions & 0 deletions src/core/composer/qgscomposeritem.h
Expand Up @@ -500,6 +500,22 @@ class CORE_EXPORT QgsComposerItem: public QgsComposerObject, public QGraphicsRec
*/
virtual void setVisibility( const bool visible );

/**Returns whether the item should be excluded from composer exports and prints
* @param valueType controls whether the returned value is the user specified vaule,
* or the current evaluated value (which may be affected by data driven settings).
* @returns true if item should be excluded
* @note added in version 2.5
* @see setExcludeFromExports
*/
bool excludeFromExports( const QgsComposerObject::PropertyValueType valueType = QgsComposerObject::EvaluatedValue );

/**Sets whether the item should be excluded from composer exports and prints
* @param exclude set to true to exclude the item from exports
* @note added in version 2.5
* @see excludeFromExports
*/
virtual void setExcludeFromExports( const bool exclude );

/**Returns whether this item is part of a group
* @returns true if item is in a group
* @note added in version 2.5
Expand Down Expand Up @@ -601,6 +617,13 @@ class CORE_EXPORT QgsComposerItem: public QgsComposerObject, public QGraphicsRec
/**Item transparency*/
int mTransparency;

/**Whether item should be excluded in exports*/
bool mExcludeFromExports;

/**Temporary evaluated item exclusion. Data defined properties may mean
* this value differs from mExcludeFromExports.*/
bool mEvaluatedExcludeFromExports;

/**The item's position mode
@note: this member was added in version 2.0*/
ItemPositionMode mLastUsedPositionMode;
Expand Down Expand Up @@ -709,6 +732,12 @@ class CORE_EXPORT QgsComposerItem: public QgsComposerObject, public QGraphicsRec
/**Update an item rect to consider data defined position and size of item*/
QRectF evalItemRect( const QRectF &newRect );

/**Returns whether the item should be drawn in the current context
* @returns true if item should be drawn
* @note added in QGIS 2.5
*/
bool shouldDrawItem() const;

signals:
/**Is emitted on item rotation change*/
void itemRotationChanged( double newRotation );
Expand Down
4 changes: 4 additions & 0 deletions src/core/composer/qgscomposerlabel.cpp
Expand Up @@ -79,6 +79,10 @@ void QgsComposerLabel::paint( QPainter* painter, const QStyleOptionGraphicsItem*
{
return;
}
if ( !shouldDrawItem() )
{
return;
}

drawBackground( painter );
painter->save();
Expand Down
5 changes: 5 additions & 0 deletions src/core/composer/qgscomposerlegend.cpp
Expand Up @@ -67,6 +67,11 @@ void QgsComposerLegend::paint( QPainter* painter, const QStyleOptionGraphicsItem
if ( !painter )
return;

if ( !shouldDrawItem() )
{
return;
}

int dpi = painter->device()->logicalDpiX();
double dotsPerMM = dpi / 25.4;

Expand Down
4 changes: 4 additions & 0 deletions src/core/composer/qgscomposermap.cpp
Expand Up @@ -309,6 +309,10 @@ void QgsComposerMap::paint( QPainter* painter, const QStyleOptionGraphicsItem* i
{
return;
}
if ( !shouldDrawItem() )
{
return;
}

QRectF thisPaintRect = QRectF( 0, 0, QGraphicsRectItem::rect().width(), QGraphicsRectItem::rect().height() );
painter->save();
Expand Down
1 change: 1 addition & 0 deletions src/core/composer/qgscomposerobject.h
Expand Up @@ -57,6 +57,7 @@ class CORE_EXPORT QgsComposerObject: public QObject
ItemRotation, /*< rotation of item */
Transparency, /*< item transparency */
BlendMode, /*< item blend mode */
ExcludeFromExports, /*< exclude item from exports */
//composer map
MapRotation, /*< map rotation */
MapScale, /*< map scale */
Expand Down
4 changes: 4 additions & 0 deletions src/core/composer/qgscomposerpicture.cpp
Expand Up @@ -97,6 +97,10 @@ void QgsComposerPicture::paint( QPainter* painter, const QStyleOptionGraphicsIte
{
return;
}
if ( !shouldDrawItem() )
{
return;
}

drawBackground( painter );

Expand Down
4 changes: 4 additions & 0 deletions src/core/composer/qgscomposerscalebar.cpp
Expand Up @@ -64,6 +64,10 @@ void QgsComposerScaleBar::paint( QPainter* painter, const QStyleOptionGraphicsIt
{
return;
}
if ( !shouldDrawItem() )
{
return;
}

drawBackground( painter );

Expand Down
5 changes: 5 additions & 0 deletions src/core/composer/qgscomposershape.cpp
Expand Up @@ -113,6 +113,11 @@ void QgsComposerShape::paint( QPainter* painter, const QStyleOptionGraphicsItem*
{
return;
}
if ( !shouldDrawItem() )
{
return;
}

drawBackground( painter );
drawFrame( painter );

Expand Down

0 comments on commit ce21425

Please sign in to comment.