Skip to content
Permalink
Browse files

Port 'exclude from exports' functionality from composer

  • Loading branch information
nyalldawson committed Oct 10, 2017
1 parent 4e8878d commit 75898d8e09adbf1e89494567d860161fbbc19063
@@ -0,0 +1,61 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/layout/qgslayouteffect.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/





class QgsLayoutEffect : QGraphicsEffect
{
%Docstring

A QGraphicsEffect subclass used for rendering layout items
onto a scene with custom composition modes.

.. versionadded:: 3.0
%End

%TypeHeaderCode
#include "qgslayouteffect.h"
%End
public:

QgsLayoutEffect();
%Docstring
Constructor for QgsLayoutEffect.
%End

void setCompositionMode( QPainter::CompositionMode mode );
%Docstring
Sets the composition (blending) ``mode`` used for rendering
the item.
.. seealso:: compositionMode()
%End

QPainter::CompositionMode compositionMode() const;
%Docstring
Returns the composition (blending) mode used for rendering
the item.
.. seealso:: setCompositionMode()
:rtype: QPainter.CompositionMode
%End

protected:

virtual void draw( QPainter *painter );

};


/************************************************************************
* This file has been generated automatically from *
* *
* src/core/layout/qgslayouteffect.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
@@ -425,6 +425,19 @@ class QgsLayoutItem : QgsLayoutObject, QGraphicsRectItem, QgsLayoutUndoObjectInt
%Docstring
Sets the item's composition blending ``mode``.
.. seealso:: blendMode()
%End

bool excludeFromExports() const;
%Docstring
Returns whether the item should be excluded from layout exports and prints.
.. seealso:: setExcludeFromExports()
:rtype: bool
%End

void setExcludeFromExports( bool exclude );
%Docstring
Sets whether the item should be excluded from composer exports and prints.
.. seealso:: excludeFromExports()
%End

virtual double estimatedFrameBleed() const;
@@ -224,7 +224,7 @@ void QgsLayoutItem::setParentGroup( QgsLayoutItemGroup *group )

void QgsLayoutItem::paint( QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget * )
{
if ( !painter || !painter->device() )
if ( !painter || !painter->device() || !shouldDrawItem() )
{
return;
}
@@ -411,6 +411,20 @@ bool QgsLayoutItem::shouldBlockUndoCommands() const
return !mLayout || mLayout != scene() || mBlockUndoCommands;
}

bool QgsLayoutItem::shouldDrawItem() const
{
#if 0 //TODO
if ( ( mLayout && mLayout->plotStyle() == QgsComposition::Preview ) || !mLayout )
{
//preview mode or no composition, so OK to draw item
return true;
}
#endif

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

double QgsLayoutItem::itemRotation() const
{
return rotation();
@@ -518,6 +532,17 @@ void QgsLayoutItem::setBlendMode( const QPainter::CompositionMode mode )
refreshBlendMode();
}

bool QgsLayoutItem::excludeFromExports() const
{
return mExcludeFromExports;
}

void QgsLayoutItem::setExcludeFromExports( bool exclude )
{
mExcludeFromExports = exclude;
refreshDataDefinedProperty( QgsLayoutObject::ExcludeFromExports );
}

double QgsLayoutItem::estimatedFrameBleed() const
{
if ( !hasFrame() )
@@ -617,6 +642,14 @@ void QgsLayoutItem::refreshDataDefinedProperty( const QgsLayoutObject::DataDefin
{
refreshBlendMode();
}
if ( property == QgsLayoutObject::ExcludeFromExports || property == QgsLayoutObject::AllProperties )
{
bool exclude = mExcludeFromExports;
//data defined exclude from exports set?
mEvaluatedExcludeFromExports = mDataDefinedProperties.valueAsBool( QgsLayoutObject::ExcludeFromExports, createExpressionContext(), exclude );
}

update();
}

void QgsLayoutItem::setItemRotation( const double angle )
@@ -842,10 +875,10 @@ bool QgsLayoutItem::writePropertiesToElement( QDomElement &element, QDomDocument
#if 0
//transparency
// composerItemElem.setAttribute( "transparency", QString::number( mTransparency ) );

// composerItemElem.setAttribute( "excludeFromExports", mExcludeFromExports );
#endif

element.setAttribute( "excludeFromExports", mExcludeFromExports );

writeObjectPropertiesToElement( element, document, context );
return true;
}
@@ -968,9 +1001,9 @@ bool QgsLayoutItem::readPropertiesFromElement( const QDomElement &element, const
#if 0 //TODO
//transparency
setTransparency( itemElem.attribute( "transparency", "0" ).toInt() );
mExcludeFromExports = itemElem.attribute( "excludeFromExports", "0" ).toInt();
mEvaluatedExcludeFromExports = mExcludeFromExports;
#endif
mExcludeFromExports = element.attribute( QStringLiteral( "excludeFromExports" ), QStringLiteral( "0" ) ).toInt();
mEvaluatedExcludeFromExports = mExcludeFromExports;

mBlockUndoCommands = false;
return true;
@@ -429,6 +429,18 @@ class CORE_EXPORT QgsLayoutItem : public QgsLayoutObject, public QGraphicsRectIt
*/
void setBlendMode( const QPainter::CompositionMode mode );

/**
* Returns whether the item should be excluded from layout exports and prints.
* \see setExcludeFromExports()
*/
bool excludeFromExports() const;

/**
* Sets whether the item should be excluded from composer exports and prints.
* \see excludeFromExports()
*/
void setExcludeFromExports( bool exclude );

/**
* Returns the estimated amount the item's frame bleeds outside the item's
* actual rectangle. For instance, if the item has a 2mm frame stroke, then
@@ -657,6 +669,15 @@ class CORE_EXPORT QgsLayoutItem : public QgsLayoutObject, public QGraphicsRectIt
QgsLayoutPoint mItemPosition;
double mItemRotation = 0.0;

//! Whether item should be excluded in exports
bool mExcludeFromExports = false;

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

//! Composition blend mode for item
QPainter::CompositionMode mBlendMode = QPainter::CompositionMode_SourceOver;
std::unique_ptr< QgsLayoutEffect > mEffect;
@@ -699,6 +720,11 @@ class CORE_EXPORT QgsLayoutItem : public QgsLayoutObject, public QGraphicsRectIt
void setScenePos( const QPointF &destinationPos );
bool shouldBlockUndoCommands() const;

/**
* Returns whether the item should be drawn in the current context
*/
bool shouldDrawItem() const;

friend class TestQgsLayoutItem;
friend class QgsLayoutItemGroup;
};
@@ -129,6 +129,7 @@ void QgsLayoutItemGroup::setVisibility( const bool visible )

void QgsLayoutItemGroup::attemptMove( const QgsLayoutPoint &point, bool useReferencePoint )
{
Q_UNUSED( useReferencePoint ); //groups should always have reference point in top left
if ( !mLayout )
return;

@@ -644,8 +644,8 @@ void QgsLayoutItemPropertiesWidget::setValuesForGuiNonPositionElements()
#if 0//TODO
mOpacityWidget->setOpacity( mItem->itemOpacity() );
mItemRotationSpinBox->setValue( mItem->itemRotation( QgsComposerObject::OriginalValue ) );
mExcludeFromPrintsCheckBox->setChecked( mItem->excludeFromExports( QgsComposerObject::OriginalValue ) );
#endif
mExcludeFromPrintsCheckBox->setChecked( mItem->excludeFromExports() );

block( false );
}
@@ -889,9 +889,7 @@ void QgsLayoutItemPropertiesWidget::mExcludeFromPrintsCheckBox_toggled( bool che
if ( mItem )
{
mItem->layout()->undoStack()->beginCommand( mItem, checked ? tr( "Exclude from Exports" ) : tr( "Include in Exports" ) );
#if 0 //TODO
mItem->setExcludeFromExports( checked );
#endif
mItem->layout()->undoStack()->endCommand();
}
}
@@ -152,6 +152,7 @@ class TestQgsLayoutItem: public QObject
void multiItemUndo();
void overlappingUndo();
void blendMode();
void excludeFromExports();

private:

@@ -1355,6 +1356,7 @@ void TestQgsLayoutItem::writeReadXmlProperties()
original->setBackgroundEnabled( false );
original->setBackgroundColor( QColor( 200, 150, 100 ) );
original->setBlendMode( QPainter::CompositionMode_Darken );
original->setExcludeFromExports( true );

QgsLayoutItem *copy = createCopyViaXml( &l, original );

@@ -1378,6 +1380,7 @@ void TestQgsLayoutItem::writeReadXmlProperties()
QVERIFY( !copy->hasBackground() );
QCOMPARE( copy->backgroundColor(), QColor( 200, 150, 100 ) );
QCOMPARE( copy->blendMode(), QPainter::CompositionMode_Darken );
QVERIFY( copy->excludeFromExports( ) );

delete copy;
delete original;
@@ -1556,6 +1559,37 @@ void TestQgsLayoutItem::blendMode()
QCOMPARE( item->mEffect->compositionMode(), QPainter::CompositionMode_Lighten );
}

void TestQgsLayoutItem::excludeFromExports()
{
QgsProject proj;
QgsLayout l( &proj );

QgsLayoutItemRectangularShape *item = new QgsLayoutItemRectangularShape( &l );
l.addLayoutItem( item );

item->setExcludeFromExports( true );
QVERIFY( item->excludeFromExports() );
item->setExcludeFromExports( false );
QVERIFY( !item->excludeFromExports() );

item->dataDefinedProperties().setProperty( QgsLayoutObject::ExcludeFromExports, QgsProperty::fromExpression( "1" ) );
item->refreshDataDefinedProperty();
QVERIFY( !item->excludeFromExports() ); // should not change
QVERIFY( item->mEvaluatedExcludeFromExports );

item->setPos( 100, 100 );
item->setRect( 0, 0, 200, 200 );
l.setSceneRect( 0, 0, 400, 400 );
l.context().setFlag( QgsLayoutContext::FlagDebug, true );
QImage image( l.sceneRect().size().toSize(), QImage::Format_ARGB32 );
image.fill( 0 );
QPainter painter( &image );
l.render( &painter );
painter.end();

QVERIFY( renderCheck( QStringLiteral( "layoutitem_excluded" ), image, 0 ) );
}

QgsLayoutItem *TestQgsLayoutItem::createCopyViaXml( QgsLayout *layout, QgsLayoutItem *original )
{
//save original item to xml
Binary file not shown.

0 comments on commit 75898d8

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