Skip to content
Permalink
Browse files

Port and fix unit tests

  • Loading branch information
nyalldawson committed Nov 24, 2017
1 parent f90c500 commit f29eb7b19e837932c27b4ce019cb91e40bfb7c56
Showing with 1,409 additions and 55 deletions.
  1. +5 −0 python/core/layout/qgslayoutframe.sip
  2. +1 −1 python/core/layout/qgslayoutitem.sip
  3. +3 −1 python/core/layout/qgslayoutitemattributetable.sip
  4. +3 −1 python/core/layout/qgslayoutitemhtml.sip
  5. +3 −1 python/core/layout/qgslayoutitemtexttable.sip
  6. +24 −34 src/core/layout/qgslayoutframe.cpp
  7. +3 −4 src/core/layout/qgslayoutframe.h
  8. +8 −1 src/core/layout/qgslayoutitem.cpp
  9. +1 −1 src/core/layout/qgslayoutitem.h
  10. +8 −2 src/core/layout/qgslayoutitemattributetable.cpp
  11. +3 −1 src/core/layout/qgslayoutitemattributetable.h
  12. +3 −1 src/core/layout/qgslayoutitemhtml.h
  13. +3 −1 src/core/layout/qgslayoutitemtexttable.h
  14. +1 −4 src/core/layout/qgslayoutmultiframe.cpp
  15. +1 −0 tests/src/core/CMakeLists.txt
  16. +7 −2 tests/src/core/testqgslayoutitem.cpp
  17. +1,332 −0 tests/src/core/testqgslayouttable.cpp
  18. BIN ...mposer_table/expected_composerattributetable_align/expected_composerattributetable_align_mask.png
  19. BIN ..._table/expected_composerattributetable_autowrap/expected_composerattributetable_autowrap_mask.png
  20. BIN ...able/expected_composerattributetable_cellstyle/expected_composerattributetable_cellstyle_mask.png
  21. BIN .../expected_composerattributetable_columnwidth/expected_composerattributetable_columnwidth_mask.png
  22. BIN ...able/expected_composerattributetable_drawempty/expected_composerattributetable_drawempty_mask.png
  23. BIN .../expected_composerattributetable_headersonly/expected_composerattributetable_headersonly_mask.png
  24. BIN ...able/expected_composerattributetable_hidetable/expected_composerattributetable_hidetable_mask.png
  25. BIN ...ted_composerattributetable_horizontalgrid/expected_composerattributetable_horizontalgrid_mask.png
  26. BIN ...able/expected_composerattributetable_multiline/expected_composerattributetable_multiline_mask.png
  27. BIN ...oser_table/expected_composerattributetable_render/expected_composerattributetable_render_mask.png
  28. BIN .../expected_composerattributetable_showmessage/expected_composerattributetable_showmessage_mask.png
  29. BIN ...xpected_composerattributetable_verticalgrid/expected_composerattributetable_verticalgrid_mask.png
@@ -56,6 +56,11 @@ class QgsLayoutFrame: QgsLayoutItem
:rtype: QgsLayoutMultiFrame
%End

virtual QgsLayoutSize minimumSize() const;

virtual QgsLayoutSize fixedSize() const;



QRectF extent() const;
%Docstring
@@ -276,7 +276,7 @@ class QgsLayoutItem : QgsLayoutObject, QGraphicsRectItem, QgsLayoutUndoObjectInt
:rtype: ReferencePoint
%End

QgsLayoutSize fixedSize() const;
virtual QgsLayoutSize fixedSize() const;
%Docstring
Returns the fixed size of the item, if applicable, or an empty size if item can be freely
resized.
@@ -29,9 +29,11 @@ class QgsLayoutItemAttributeTable: QgsLayoutTable
RelationChildren
};

QgsLayoutItemAttributeTable( QgsLayout *layout );
QgsLayoutItemAttributeTable( QgsLayout *layout /TransferThis/ );
%Docstring
Constructor for QgsLayoutItemAttributeTable, attached to the specified ``layout``.

Ownership is transferred to the layout.
%End

virtual int type() const;
@@ -27,9 +27,11 @@ class QgsLayoutItemHtml: QgsLayoutMultiFrame
ManualHtml
};

QgsLayoutItemHtml( QgsLayout *layout );
QgsLayoutItemHtml( QgsLayout *layout /TransferThis/ );
%Docstring
Constructor for QgsLayoutItemHtml, with the specified parent ``layout``.

Ownership is transferred to the layout.
%End

~QgsLayoutItemHtml();
@@ -21,9 +21,11 @@ class QgsLayoutItemTextTable : QgsLayoutTable
%End
public:

QgsLayoutItemTextTable( QgsLayout *layout );
QgsLayoutItemTextTable( QgsLayout *layout /TransferThis/ );
%Docstring
Constructor for QgsLayoutItemTextTable, for the specified ``layout``.

Ownership is transferred to the layout.
%End

virtual int type() const;
@@ -35,10 +35,8 @@ QgsLayoutFrame::QgsLayoutFrame( QgsLayout *layout, QgsLayoutMultiFrame *multiFra
update();
} );

#if 0 //TODO
//force recalculation of rect, so that multiframe specified sizes can be applied
setSceneRect( QRectF( pos().x(), pos().y(), rect().width(), rect().height() ) );
#endif
refreshItemSize();
}
}

@@ -51,6 +49,29 @@ QgsLayoutMultiFrame *QgsLayoutFrame::multiFrame() const
{
return mMultiFrame;
}

QgsLayoutSize QgsLayoutFrame::minimumSize() const
{
if ( !mMultiFrame )
return QgsLayoutSize();

//calculate index of frame
int frameIndex = mMultiFrame->frameIndex( const_cast< QgsLayoutFrame * >( this ) );
//check minimum size
return QgsLayoutSize( mMultiFrame->minFrameSize( frameIndex ), QgsUnitTypes::LayoutMillimeters );
}

QgsLayoutSize QgsLayoutFrame::fixedSize() const
{
if ( !mMultiFrame )
return QgsLayoutSize();

//calculate index of frame
int frameIndex = mMultiFrame->frameIndex( const_cast< QgsLayoutFrame * >( this ) );
//check fixed size
return QgsLayoutSize( mMultiFrame->fixedFrameSize( frameIndex ), QgsUnitTypes::LayoutMillimeters );
}

#if 0// TODO - save/restore multiframe uuid!
bool QgsLayoutFrame::writeXml( QDomElement &elem, QDomDocument &doc ) const
{
@@ -168,37 +189,6 @@ QString QgsLayoutFrame::displayName() const
return tr( "<Frame>" );
}

#if 0 //TODO
void QgsLayoutFrame::setSceneRect( const QRectF &rectangle )
{
QRectF fixedRect = rectangle;

if ( mMultiFrame )
{
//calculate index of frame
int frameIndex = mMultiFrame->frameIndex( this );

QSizeF fixedSize = mMultiFrame->fixedFrameSize( frameIndex );
if ( fixedSize.width() > 0 )
{
fixedRect.setWidth( fixedSize.width() );
}
if ( fixedSize.height() > 0 )
{
fixedRect.setHeight( fixedSize.height() );
}

//check minimum size
QSizeF minSize = mMultiFrame->minFrameSize( frameIndex );
fixedRect.setWidth( std::max( minSize.width(), fixedRect.width() ) );
fixedRect.setHeight( std::max( minSize.height(), fixedRect.height() ) );
}

QgsComposerItem::setSceneRect( fixedRect );
}
#endif


void QgsLayoutFrame::draw( QgsRenderContext &context, const QStyleOptionGraphicsItem *itemStyle )
{
if ( mMultiFrame )
@@ -64,11 +64,10 @@ class CORE_EXPORT QgsLayoutFrame: public QgsLayoutItem
*/
QgsLayoutMultiFrame *multiFrame() const;

#if 0 //TODO
//Overridden to handle fixed frame sizes set by multi frame
void setSceneRect( const QRectF &rectangle ) override;
QgsLayoutSize minimumSize() const override;
QgsLayoutSize fixedSize() const override;

void paint( QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget ) override;
#if 0 //TODO
void beginItemCommand( const QString &text ) override;
void endItemCommand() override;
bool writeXml( QDomElement &elem, QDomDocument &doc ) const override;
@@ -1200,8 +1200,15 @@ QSizeF QgsLayoutItem::applyFixedSize( const QSizeF &targetSize )
{
return targetSize;
}

QSizeF size = targetSize;
QSizeF fixedSizeLayoutUnits = mLayout->convertToLayoutUnits( fixedSize() );
return targetSize.expandedTo( fixedSizeLayoutUnits );
if ( fixedSizeLayoutUnits.width() > 0 )
size.setWidth( fixedSizeLayoutUnits.width() );
if ( fixedSizeLayoutUnits.height() > 0 )
size.setHeight( fixedSizeLayoutUnits.height() );

return size;
}

void QgsLayoutItem::refreshItemRotation( QPointF *origin )
@@ -299,7 +299,7 @@ class CORE_EXPORT QgsLayoutItem : public QgsLayoutObject, public QGraphicsRectIt
* \see setFixedSize()
* \see minimumSize()
*/
QgsLayoutSize fixedSize() const { return mFixedSize; }
virtual QgsLayoutSize fixedSize() const { return mFixedSize; }

/**
* Returns the minimum allowed size of the item, if applicable, or an empty size if item can be freely
@@ -679,8 +679,11 @@ void QgsLayoutItemAttributeTable::setWrapString( const QString &wrapString )
emit changed();
}

bool QgsLayoutItemAttributeTable::writePropertiesToElement( QDomElement &tableElem, QDomDocument &, const QgsReadWriteContext & ) const
bool QgsLayoutItemAttributeTable::writePropertiesToElement( QDomElement &tableElem, QDomDocument &doc, const QgsReadWriteContext &context ) const
{
if ( !QgsLayoutTable::writePropertiesToElement( tableElem, doc, context ) )
return false;

tableElem.setAttribute( QStringLiteral( "source" ), QString::number( static_cast< int >( mSource ) ) );
tableElem.setAttribute( QStringLiteral( "relationId" ), mRelationId );
tableElem.setAttribute( QStringLiteral( "showUniqueRowsOnly" ), mShowUniqueRowsOnly );
@@ -706,7 +709,7 @@ bool QgsLayoutItemAttributeTable::writePropertiesToElement( QDomElement &tableEl
return true;
}

bool QgsLayoutItemAttributeTable::readPropertiesFromElement( const QDomElement &itemElem, const QDomDocument &, const QgsReadWriteContext & )
bool QgsLayoutItemAttributeTable::readPropertiesFromElement( const QDomElement &itemElem, const QDomDocument &doc, const QgsReadWriteContext &context )
{
QgsVectorLayer *prevLayer = sourceLayer();
if ( prevLayer )
@@ -715,6 +718,9 @@ bool QgsLayoutItemAttributeTable::readPropertiesFromElement( const QDomElement &
disconnect( prevLayer, &QgsVectorLayer::layerModified, this, &QgsLayoutTable::refreshAttributes );
}

if ( !QgsLayoutTable::readPropertiesFromElement( itemElem, doc, context ) )
return false;

mSource = QgsLayoutItemAttributeTable::ContentSource( itemElem.attribute( QStringLiteral( "source" ), QStringLiteral( "0" ) ).toInt() );
mRelationId = itemElem.attribute( QStringLiteral( "relationId" ), QLatin1String( "" ) );

@@ -50,8 +50,10 @@ class CORE_EXPORT QgsLayoutItemAttributeTable: public QgsLayoutTable

/**
* Constructor for QgsLayoutItemAttributeTable, attached to the specified \a layout.
*
* Ownership is transferred to the layout.
*/
QgsLayoutItemAttributeTable( QgsLayout *layout );
QgsLayoutItemAttributeTable( QgsLayout *layout SIP_TRANSFERTHIS );

int type() const override;
QString stringType() const override;
@@ -48,8 +48,10 @@ class CORE_EXPORT QgsLayoutItemHtml: public QgsLayoutMultiFrame

/**
* Constructor for QgsLayoutItemHtml, with the specified parent \a layout.
*
* Ownership is transferred to the layout.
*/
QgsLayoutItemHtml( QgsLayout *layout );
QgsLayoutItemHtml( QgsLayout *layout SIP_TRANSFERTHIS );

~QgsLayoutItemHtml();

@@ -36,8 +36,10 @@ class CORE_EXPORT QgsLayoutItemTextTable : public QgsLayoutTable

/**
* Constructor for QgsLayoutItemTextTable, for the specified \a layout.
*
* Ownership is transferred to the layout.
*/
QgsLayoutItemTextTable( QgsLayout *layout );
QgsLayoutItemTextTable( QgsLayout *layout SIP_TRANSFERTHIS );

int type() const override;
QString stringType() const override;
@@ -220,7 +220,6 @@ void QgsLayoutMultiFrame::recalculateFrameSizes()

void QgsLayoutMultiFrame::recalculateFrameRects()
{
#if 0 //TODO
if ( mFrameItems.empty() )
{
//no frames, nothing to do
@@ -230,10 +229,8 @@ void QgsLayoutMultiFrame::recalculateFrameRects()
const QList< QgsLayoutFrame * > frames = mFrameItems;
for ( QgsLayoutFrame *frame : frames )
{
frame->setSceneRect( QRectF( frame->scenePos().x(), frame->scenePos().y(),
frame->rect().width(), frame->rect().height() ) );
frame->refreshItemSize();
}
#endif
}

QgsLayoutFrame *QgsLayoutMultiFrame::createNewFrame( QgsLayoutFrame *currentFrame, QPointF pos, QSizeF size )
@@ -147,6 +147,7 @@ SET(TESTS
testqgslayoutpicture.cpp
testqgslayoutscalebar.cpp
testqgslayoutshapes.cpp
testqgslayouttable.cpp
testqgslayoutunits.cpp
testqgslayoututils.cpp
testqgslegendrenderer.cpp
@@ -1074,6 +1074,11 @@ void TestQgsLayoutItem::fixedSize()
QGSCOMPARENEAR( item->rect().width(), 2.0 * 25.4, 4 * DBL_EPSILON );
QGSCOMPARENEAR( item->rect().height(), 4.0 * 25.4, 4 * DBL_EPSILON );

item->attemptResize( QgsLayoutSize( 7.0, 8.0, QgsUnitTypes::LayoutInches ) );
//check size matches fixed item size converted to mm
QGSCOMPARENEAR( item->rect().width(), 2.0 * 25.4, 4 * DBL_EPSILON );
QGSCOMPARENEAR( item->rect().height(), 4.0 * 25.4, 4 * DBL_EPSILON );

//check that setting a fixed size applies this size immediately
item->updateFixedSize( QgsLayoutSize( 150, 250, QgsUnitTypes::LayoutMillimeters ) );
QGSCOMPARENEAR( item->rect().width(), 150.0, 4 * DBL_EPSILON );
@@ -1119,8 +1124,8 @@ void TestQgsLayoutItem::minSize()
//try to resize to less than minimum size
fixedMinItem->attemptResize( QgsLayoutSize( 1.0, 0.5, QgsUnitTypes::LayoutPoints ) );
//check size matches fixed item size, not minimum size (converted to mm)
QGSCOMPARENEAR( fixedMinItem->rect().width(), 50.0, 4 * DBL_EPSILON );
QGSCOMPARENEAR( fixedMinItem->rect().height(), 90.0, 4 * DBL_EPSILON );
QGSCOMPARENEAR( fixedMinItem->rect().width(), 20.0, 4 * DBL_EPSILON );
QGSCOMPARENEAR( fixedMinItem->rect().height(), 40.0, 4 * DBL_EPSILON );
}

void TestQgsLayoutItem::move()

0 comments on commit f29eb7b

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