Skip to content
Permalink
Browse files

[FEATURE][composer] Add checkbox and data defined button for controlling

whether an item is excluded from composer exports/printouts.
  • Loading branch information
nyalldawson committed Sep 26, 2014
1 parent 89a7573 commit ce2142585abec0b5cd8029480db444268a76d834
@@ -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
@@ -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*/
@@ -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 */
@@ -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 )
@@ -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() );
@@ -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 );
@@ -528,6 +533,7 @@ void QgsComposerItemWidget::setValuesForGuiNonPositionElements()
mTransparencySlider->blockSignals( false );
mTransparencySpnBx->blockSignals( false );
mItemRotationSpinBox->blockSignals( false );
mExcludeFromPrintsCheckBox->blockSignals( false );
}

void QgsComposerItemWidget::populateDataDefinedButtons()
@@ -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 ),
@@ -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() );
@@ -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 )
@@ -610,6 +620,10 @@ QgsComposerObject::DataDefinedProperty QgsComposerItemWidget::ddPropertyForWidge
{
return QgsComposerObject::BlendMode;
}
else if ( widget == mExcludePrintsDDBtn )
{
return QgsComposerObject::ExcludeFromExports;
}

return QgsComposerObject::NoProperty;
}
@@ -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();
}
}
@@ -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
@@ -94,6 +94,10 @@ void QgsComposerArrow::paint( QPainter* painter, const QStyleOptionGraphicsItem
{
return;
}
if ( !shouldDrawItem() )
{
return;
}

drawBackground( painter );

@@ -138,6 +138,10 @@ void QgsComposerAttributeTable::paint( QPainter* painter, const QStyleOptionGrap
{
return;
}
if ( !shouldDrawItem() )
{
return;
}
QgsComposerTable::paint( painter, itemStyle, pWidget );
}

@@ -147,6 +147,10 @@ void QgsComposerFrame::paint( QPainter* painter, const QStyleOptionGraphicsItem*
{
return;
}
if ( !shouldDrawItem() )
{
return;
}

drawBackground( painter );
if ( mMultiFrame )
@@ -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 )
@@ -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 )
@@ -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 )
{
@@ -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 );

@@ -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 );

@@ -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 )
@@ -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();
}
@@ -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 );
}
@@ -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
@@ -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;
@@ -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 );
@@ -79,6 +79,10 @@ void QgsComposerLabel::paint( QPainter* painter, const QStyleOptionGraphicsItem*
{
return;
}
if ( !shouldDrawItem() )
{
return;
}

drawBackground( painter );
painter->save();
@@ -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;

@@ -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();
@@ -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 */
@@ -97,6 +97,10 @@ void QgsComposerPicture::paint( QPainter* painter, const QStyleOptionGraphicsIte
{
return;
}
if ( !shouldDrawItem() )
{
return;
}

drawBackground( painter );

@@ -64,6 +64,10 @@ void QgsComposerScaleBar::paint( QPainter* painter, const QStyleOptionGraphicsIt
{
return;
}
if ( !shouldDrawItem() )
{
return;
}

drawBackground( painter );

@@ -113,6 +113,11 @@ void QgsComposerShape::paint( QPainter* painter, const QStyleOptionGraphicsItem*
{
return;
}
if ( !shouldDrawItem() )
{
return;
}

drawBackground( painter );
drawFrame( painter );

0 comments on commit ce21425

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