Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add missing sip casting for layout multiframe objects
  • Loading branch information
nyalldawson committed Jan 22, 2018
1 parent 77b570d commit d9b6c8b
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 2 deletions.
8 changes: 8 additions & 0 deletions python/core/layout/qgslayoutitemregistry.sip.in
Expand Up @@ -154,6 +154,10 @@ of layout items.
LayoutGroup,

// known

// WARNING
// values,

LayoutPage,
LayoutMap,
LayoutPicture,
Expand All @@ -166,6 +170,10 @@ of layout items.
LayoutFrame,

// known

// WARNING
// values,

LayoutHtml,
LayoutAttributeTable,
LayoutTextTable,
Expand Down
32 changes: 32 additions & 0 deletions python/core/layout/qgslayoutmultiframe.sip.in
Expand Up @@ -21,6 +21,38 @@ several frames (QgsLayoutFrame items).

%TypeHeaderCode
#include "qgslayoutmultiframe.h"
#include "qgslayoutitemhtml.h"
#include "qgslayoutitemattributetable.h"
#include "qgslayoutitemtexttable.h"
%End
%ConvertToSubClassCode
// the conversions have to be static, because they're using multiple inheritance
// (seen in PyQt4 .sip files for some QGraphicsItem classes)
if ( QgsLayoutMultiFrame *mf = qobject_cast< QgsLayoutMultiFrame *>( sipCpp ) )
{
switch ( mf->type() )
{
// really, these *should* use the constants from QgsLayoutItemRegistry, but sip doesn't like that!
case QGraphicsItem::UserType + 112:
sipType = sipType_QgsLayoutItemHtml;
*sipCppRet = static_cast<QgsLayoutItemHtml *>( sipCpp );
break;
case QGraphicsItem::UserType + 113:
sipType = sipType_QgsLayoutItemAttributeTable;
*sipCppRet = static_cast<QgsLayoutItemAttributeTable *>( sipCpp );
break;
case QGraphicsItem::UserType + 114:
sipType = sipType_QgsLayoutItemTextTable;
*sipCppRet = static_cast<QgsLayoutItemTextTable *>( sipCpp );
break;
default:
sipType = 0;
}
}
else
{
sipType = 0;
}
%End
public:

Expand Down
10 changes: 9 additions & 1 deletion src/core/layout/qgslayoutitemregistry.h
Expand Up @@ -296,6 +296,10 @@ class CORE_EXPORT QgsLayoutItemRegistry : public QObject
LayoutGroup, //!< Grouped item

// known item types

// WARNING!!!! SIP CASTING OF QgsLayoutItem and QgsLayoutMultiFrame DEPENDS on these
// values, and must be updated if any additional types are added

LayoutPage, //!< Page items
LayoutMap, //!< Map item
LayoutPicture, //!< Picture item
Expand All @@ -308,12 +312,16 @@ class CORE_EXPORT QgsLayoutItemRegistry : public QObject
LayoutFrame, //!< Frame item, part of a QgsLayoutMultiFrame object

// known multi-frame types

// WARNING!!!! SIP CASTING OF QgsLayoutItem and QgsLayoutMultiFrame DEPENDS on these
// values, and must be updated if any additional types are added

LayoutHtml, //!< Html multiframe item
LayoutAttributeTable, //!< Attribute table
LayoutTextTable, //!< Preset text table

// item types provided by plugins
PluginItem = LayoutTextTable + 1000, //!< Starting point for plugin item types
PluginItem = LayoutTextTable + 10000, //!< Starting point for plugin item types
};

/**
Expand Down
40 changes: 39 additions & 1 deletion src/core/layout/qgslayoutmultiframe.h
Expand Up @@ -45,6 +45,44 @@ class QgsRenderContext;

class CORE_EXPORT QgsLayoutMultiFrame: public QgsLayoutObject, public QgsLayoutUndoObjectInterface
{
#ifdef SIP_RUN
#include "qgslayoutitemhtml.h"
#include "qgslayoutitemattributetable.h"
#include "qgslayoutitemtexttable.h"
#endif


#ifdef SIP_RUN
SIP_CONVERT_TO_SUBCLASS_CODE
// the conversions have to be static, because they're using multiple inheritance
// (seen in PyQt4 .sip files for some QGraphicsItem classes)
if ( QgsLayoutMultiFrame *mf = qobject_cast< QgsLayoutMultiFrame *>( sipCpp ) )
{
switch ( mf->type() )
{
// really, these *should* use the constants from QgsLayoutItemRegistry, but sip doesn't like that!
case QGraphicsItem::UserType + 112:
sipType = sipType_QgsLayoutItemHtml;
*sipCppRet = static_cast<QgsLayoutItemHtml *>( sipCpp );
break;
case QGraphicsItem::UserType + 113:
sipType = sipType_QgsLayoutItemAttributeTable;
*sipCppRet = static_cast<QgsLayoutItemAttributeTable *>( sipCpp );
break;
case QGraphicsItem::UserType + 114:
sipType = sipType_QgsLayoutItemTextTable;
*sipCppRet = static_cast<QgsLayoutItemTextTable *>( sipCpp );
break;
default:
sipType = 0;
}
}
else
{
sipType = 0;
}
SIP_END
#endif

Q_OBJECT

Expand All @@ -62,7 +100,7 @@ class CORE_EXPORT QgsLayoutMultiFrame: public QgsLayoutObject, public QgsLayoutU
until the entire multiframe content is visible */
};

//! Multiframe item undo commands, used for collapsing undo commands
//! Multiframe item undo commands, used for collapsing undo commands
enum UndoCommand
{
UndoHtmlBreakDistance, //!< HTML page break distance
Expand Down

0 comments on commit d9b6c8b

Please sign in to comment.