Skip to content

Commit

Permalink
Add some unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Dec 6, 2017
1 parent b74a0ef commit f60da58
Show file tree
Hide file tree
Showing 8 changed files with 276 additions and 13 deletions.
53 changes: 51 additions & 2 deletions python/core/composer/qgscomposeritem.sip
Expand Up @@ -30,8 +30,17 @@ class QgsComposerItem: QgsComposerObject, QGraphicsRectItem
#include <qgscomposerpolygon.h>
#include <qgscomposerpolyline.h>
#include <qgscomposertexttable.h>
#include <qgslayoutitemshape.h>
#include <qgslayoutitempage.h>
#include "qgslayoutitemgroup.h"
#include "qgslayoutitemmap.h"
#include "qgslayoutitempicture.h"
#include "qgslayoutitemlabel.h"
#include "qgslayoutitemlegend.h"
#include "qgslayoutitempolygon.h"
#include "qgslayoutitempolyline.h"
#include "qgslayoutitemscalebar.h"
#include "qgslayoutframe.h"
#include "qgslayoutitemshape.h"
#include "qgslayoutitempage.h"
%End
%ConvertToSubClassCode
// the conversions have to be static, because they're using multiple inheritance
Expand Down Expand Up @@ -102,9 +111,49 @@ class QgsComposerItem: QgsComposerObject, QGraphicsRectItem
{
// really, these *should* use the constants from QgsLayoutItemRegistry, but sip doesn't like that!
case QGraphicsItem::UserType + 101:
sipType = sipType_QgsLayoutItemGroup;
*sipCppRet = static_cast<QgsLayoutItemGroup *>( sipCpp );
break;
case QGraphicsItem::UserType + 102:
sipType = sipType_QgsLayoutItemPage;
*sipCppRet = static_cast<QgsLayoutItemPage *>( sipCpp );
break;
case QGraphicsItem::UserType + 103:
sipType = sipType_QgsLayoutItemMap;
*sipCppRet = static_cast<QgsLayoutItemMap *>( sipCpp );
break;
case QGraphicsItem::UserType + 104:
sipType = sipType_QgsLayoutItemPicture;
*sipCppRet = static_cast<QgsLayoutItemPicture *>( sipCpp );
break;
case QGraphicsItem::UserType + 105:
sipType = sipType_QgsLayoutItemLabel;
*sipCppRet = static_cast<QgsLayoutItemLabel *>( sipCpp );
break;
case QGraphicsItem::UserType + 106:
sipType = sipType_QgsLayoutItemLegend;
*sipCppRet = static_cast<QgsLayoutItemLegend *>( sipCpp );
break;
case QGraphicsItem::UserType + 107:
sipType = sipType_QgsLayoutItemShape;
*sipCppRet = static_cast<QgsLayoutItemShape *>( sipCpp );
break;
case QGraphicsItem::UserType + 108:
sipType = sipType_QgsLayoutItemPolygon;
*sipCppRet = static_cast<QgsLayoutItemPolygon *>( sipCpp );
break;
case QGraphicsItem::UserType + 109:
sipType = sipType_QgsLayoutItemPolyline;
*sipCppRet = static_cast<QgsLayoutItemPolyline *>( sipCpp );
break;
case QGraphicsItem::UserType + 110:
sipType = sipType_QgsLayoutItemScaleBar;
*sipCppRet = static_cast<QgsLayoutItemScaleBar *>( sipCpp );
break;
case QGraphicsItem::UserType + 111:
sipType = sipType_QgsLayoutFrame;
*sipCppRet = static_cast<QgsLayoutFrame *>( sipCpp );
break;
default:
sipType = 0;
}
Expand Down
2 changes: 1 addition & 1 deletion python/core/layout/qgslayout.sip
Expand Up @@ -424,7 +424,7 @@ class QgsLayout : QGraphicsScene, QgsExpressionContextGenerator, QgsLayoutUndoOb
:rtype: bool
%End

QVector< QgsLayoutItem * > addItemsFromXml( const QDomElement &parentElement, const QDomDocument &document,
QList< QgsLayoutItem * > addItemsFromXml( const QDomElement &parentElement, const QDomDocument &document,
const QgsReadWriteContext &context,
QPointF *position = 0, bool pasteInPlace = false );
%Docstring
Expand Down
53 changes: 51 additions & 2 deletions python/core/layout/qgslayoutitem.sip
Expand Up @@ -18,8 +18,17 @@ class QgsLayoutItem : QgsLayoutObject, QGraphicsRectItem, QgsLayoutUndoObjectInt

%TypeHeaderCode
#include "qgslayoutitem.h"
#include <qgslayoutitemshape.h>
#include <qgslayoutitempage.h>
#include "qgslayoutitemgroup.h"
#include "qgslayoutitemmap.h"
#include "qgslayoutitempicture.h"
#include "qgslayoutitemlabel.h"
#include "qgslayoutitemlegend.h"
#include "qgslayoutitempolygon.h"
#include "qgslayoutitempolyline.h"
#include "qgslayoutitemscalebar.h"
#include "qgslayoutframe.h"
#include "qgslayoutitemshape.h"
#include "qgslayoutitempage.h"
%End
%ConvertToSubClassCode
// the conversions have to be static, because they're using multiple inheritance
Expand All @@ -28,9 +37,49 @@ class QgsLayoutItem : QgsLayoutObject, QGraphicsRectItem, QgsLayoutUndoObjectInt
{
// really, these *should* use the constants from QgsLayoutItemRegistry, but sip doesn't like that!
case QGraphicsItem::UserType + 101:
sipType = sipType_QgsLayoutItemGroup;
*sipCppRet = static_cast<QgsLayoutItemGroup *>( sipCpp );
break;
case QGraphicsItem::UserType + 102:
sipType = sipType_QgsLayoutItemPage;
*sipCppRet = static_cast<QgsLayoutItemPage *>( sipCpp );
break;
case QGraphicsItem::UserType + 103:
sipType = sipType_QgsLayoutItemMap;
*sipCppRet = static_cast<QgsLayoutItemMap *>( sipCpp );
break;
case QGraphicsItem::UserType + 104:
sipType = sipType_QgsLayoutItemPicture;
*sipCppRet = static_cast<QgsLayoutItemPicture *>( sipCpp );
break;
case QGraphicsItem::UserType + 105:
sipType = sipType_QgsLayoutItemLabel;
*sipCppRet = static_cast<QgsLayoutItemLabel *>( sipCpp );
break;
case QGraphicsItem::UserType + 106:
sipType = sipType_QgsLayoutItemLegend;
*sipCppRet = static_cast<QgsLayoutItemLegend *>( sipCpp );
break;
case QGraphicsItem::UserType + 107:
sipType = sipType_QgsLayoutItemShape;
*sipCppRet = static_cast<QgsLayoutItemShape *>( sipCpp );
break;
case QGraphicsItem::UserType + 108:
sipType = sipType_QgsLayoutItemPolygon;
*sipCppRet = static_cast<QgsLayoutItemPolygon *>( sipCpp );
break;
case QGraphicsItem::UserType + 109:
sipType = sipType_QgsLayoutItemPolyline;
*sipCppRet = static_cast<QgsLayoutItemPolyline *>( sipCpp );
break;
case QGraphicsItem::UserType + 110:
sipType = sipType_QgsLayoutItemScaleBar;
*sipCppRet = static_cast<QgsLayoutItemScaleBar *>( sipCpp );
break;
case QGraphicsItem::UserType + 111:
sipType = sipType_QgsLayoutFrame;
*sipCppRet = static_cast<QgsLayoutFrame *>( sipCpp );
break;
default:
sipType = 0;
}
Expand Down
53 changes: 51 additions & 2 deletions src/core/composer/qgscomposeritem.h
Expand Up @@ -54,8 +54,17 @@ class CORE_EXPORT QgsComposerItem: public QgsComposerObject, public QGraphicsRec
#include <qgscomposerpolygon.h>
#include <qgscomposerpolyline.h>
#include <qgscomposertexttable.h>
#include <qgslayoutitemshape.h>
#include <qgslayoutitempage.h>
#include "qgslayoutitemgroup.h"
#include "qgslayoutitemmap.h"
#include "qgslayoutitempicture.h"
#include "qgslayoutitemlabel.h"
#include "qgslayoutitemlegend.h"
#include "qgslayoutitempolygon.h"
#include "qgslayoutitempolyline.h"
#include "qgslayoutitemscalebar.h"
#include "qgslayoutframe.h"
#include "qgslayoutitemshape.h"
#include "qgslayoutitempage.h"
#endif


Expand Down Expand Up @@ -129,9 +138,49 @@ class CORE_EXPORT QgsComposerItem: public QgsComposerObject, public QGraphicsRec
{
// really, these *should* use the constants from QgsLayoutItemRegistry, but sip doesn't like that!
case QGraphicsItem::UserType + 101:
sipType = sipType_QgsLayoutItemGroup;
*sipCppRet = static_cast<QgsLayoutItemGroup *>( sipCpp );
break;
case QGraphicsItem::UserType + 102:
sipType = sipType_QgsLayoutItemPage;
*sipCppRet = static_cast<QgsLayoutItemPage *>( sipCpp );
break;
case QGraphicsItem::UserType + 103:
sipType = sipType_QgsLayoutItemMap;
*sipCppRet = static_cast<QgsLayoutItemMap *>( sipCpp );
break;
case QGraphicsItem::UserType + 104:
sipType = sipType_QgsLayoutItemPicture;
*sipCppRet = static_cast<QgsLayoutItemPicture *>( sipCpp );
break;
case QGraphicsItem::UserType + 105:
sipType = sipType_QgsLayoutItemLabel;
*sipCppRet = static_cast<QgsLayoutItemLabel *>( sipCpp );
break;
case QGraphicsItem::UserType + 106:
sipType = sipType_QgsLayoutItemLegend;
*sipCppRet = static_cast<QgsLayoutItemLegend *>( sipCpp );
break;
case QGraphicsItem::UserType + 107:
sipType = sipType_QgsLayoutItemShape;
*sipCppRet = static_cast<QgsLayoutItemShape *>( sipCpp );
break;
case QGraphicsItem::UserType + 108:
sipType = sipType_QgsLayoutItemPolygon;
*sipCppRet = static_cast<QgsLayoutItemPolygon *>( sipCpp );
break;
case QGraphicsItem::UserType + 109:
sipType = sipType_QgsLayoutItemPolyline;
*sipCppRet = static_cast<QgsLayoutItemPolyline *>( sipCpp );
break;
case QGraphicsItem::UserType + 110:
sipType = sipType_QgsLayoutItemScaleBar;
*sipCppRet = static_cast<QgsLayoutItemScaleBar *>( sipCpp );
break;
case QGraphicsItem::UserType + 111:
sipType = sipType_QgsLayoutFrame;
*sipCppRet = static_cast<QgsLayoutFrame *>( sipCpp );
break;
default:
sipType = 0;
}
Expand Down
6 changes: 3 additions & 3 deletions src/core/layout/qgslayout.cpp
Expand Up @@ -716,11 +716,11 @@ bool QgsLayout::readXml( const QDomElement &layoutElement, const QDomDocument &d
return true;
}

QVector< QgsLayoutItem * > QgsLayout::addItemsFromXml( const QDomElement &parentElement, const QDomDocument &document, const QgsReadWriteContext &context, QPointF *position, bool pasteInPlace )
QList< QgsLayoutItem * > QgsLayout::addItemsFromXml( const QDomElement &parentElement, const QDomDocument &document, const QgsReadWriteContext &context, QPointF *position, bool pasteInPlace )
{
std::unique_ptr< QPointF > pasteInPlacePt;
QVector< QgsLayoutItem * > newItems;
QVector< QgsLayoutMultiFrame * > newMultiFrames;
QList< QgsLayoutItem * > newItems;
QList< QgsLayoutMultiFrame * > newMultiFrames;

//if we are adding items to a layout which already contains items, we need to make sure
//these items are placed at the top of the layout and that zValues are not duplicated
Expand Down
2 changes: 1 addition & 1 deletion src/core/layout/qgslayout.h
Expand Up @@ -482,7 +482,7 @@ class CORE_EXPORT QgsLayout : public QGraphicsScene, public QgsExpressionContext
*
* A list of the newly added items is returned.
*/
QVector< QgsLayoutItem * > addItemsFromXml( const QDomElement &parentElement, const QDomDocument &document,
QList< QgsLayoutItem * > addItemsFromXml( const QDomElement &parentElement, const QDomDocument &document,
const QgsReadWriteContext &context,
QPointF *position = nullptr, bool pasteInPlace = false );

Expand Down
53 changes: 51 additions & 2 deletions src/core/layout/qgslayoutitem.h
Expand Up @@ -41,8 +41,17 @@ class QgsLayoutEffect;
class CORE_EXPORT QgsLayoutItem : public QgsLayoutObject, public QGraphicsRectItem, public QgsLayoutUndoObjectInterface
{
#ifdef SIP_RUN
#include <qgslayoutitemshape.h>
#include <qgslayoutitempage.h>
#include "qgslayoutitemgroup.h"
#include "qgslayoutitemmap.h"
#include "qgslayoutitempicture.h"
#include "qgslayoutitemlabel.h"
#include "qgslayoutitemlegend.h"
#include "qgslayoutitempolygon.h"
#include "qgslayoutitempolyline.h"
#include "qgslayoutitemscalebar.h"
#include "qgslayoutframe.h"
#include "qgslayoutitemshape.h"
#include "qgslayoutitempage.h"
#endif


Expand All @@ -54,9 +63,49 @@ class CORE_EXPORT QgsLayoutItem : public QgsLayoutObject, public QGraphicsRectIt
{
// really, these *should* use the constants from QgsLayoutItemRegistry, but sip doesn't like that!
case QGraphicsItem::UserType + 101:
sipType = sipType_QgsLayoutItemGroup;
*sipCppRet = static_cast<QgsLayoutItemGroup *>( sipCpp );
break;
case QGraphicsItem::UserType + 102:
sipType = sipType_QgsLayoutItemPage;
*sipCppRet = static_cast<QgsLayoutItemPage *>( sipCpp );
break;
case QGraphicsItem::UserType + 103:
sipType = sipType_QgsLayoutItemMap;
*sipCppRet = static_cast<QgsLayoutItemMap *>( sipCpp );
break;
case QGraphicsItem::UserType + 104:
sipType = sipType_QgsLayoutItemPicture;
*sipCppRet = static_cast<QgsLayoutItemPicture *>( sipCpp );
break;
case QGraphicsItem::UserType + 105:
sipType = sipType_QgsLayoutItemLabel;
*sipCppRet = static_cast<QgsLayoutItemLabel *>( sipCpp );
break;
case QGraphicsItem::UserType + 106:
sipType = sipType_QgsLayoutItemLegend;
*sipCppRet = static_cast<QgsLayoutItemLegend *>( sipCpp );
break;
case QGraphicsItem::UserType + 107:
sipType = sipType_QgsLayoutItemShape;
*sipCppRet = static_cast<QgsLayoutItemShape *>( sipCpp );
break;
case QGraphicsItem::UserType + 108:
sipType = sipType_QgsLayoutItemPolygon;
*sipCppRet = static_cast<QgsLayoutItemPolygon *>( sipCpp );
break;
case QGraphicsItem::UserType + 109:
sipType = sipType_QgsLayoutItemPolyline;
*sipCppRet = static_cast<QgsLayoutItemPolyline *>( sipCpp );
break;
case QGraphicsItem::UserType + 110:
sipType = sipType_QgsLayoutItemScaleBar;
*sipCppRet = static_cast<QgsLayoutItemScaleBar *>( sipCpp );
break;
case QGraphicsItem::UserType + 111:
sipType = sipType_QgsLayoutFrame;
*sipCppRet = static_cast<QgsLayoutFrame *>( sipCpp );
break;
default:
sipType = 0;
}
Expand Down

0 comments on commit f60da58

Please sign in to comment.