Skip to content

Commit

Permalink
Proper conversion to subclasses for composer items.
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@14766 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder committed Nov 25, 2010
1 parent 07d01b9 commit 86af48d
Show file tree
Hide file tree
Showing 21 changed files with 174 additions and 19 deletions.
106 changes: 90 additions & 16 deletions python/core/qgscomposeritem.sip
Expand Up @@ -5,33 +5,104 @@ class QgsComposerItem: QObject, QGraphicsRectItem
{
%TypeHeaderCode
#include <qgscomposeritem.h>
//#include <qgscomposerarrow.h>
//#include <qgscomposeritemgroup.h>
#include <qgscomposerlabel.h>
#include <qgscomposerlegend.h>
#include <qgscomposermap.h>
#include <qgspaperitem.h>
#include <qgscomposerpicture.h>
#include <qgscomposerscalebar.h>
#include <qgscomposershape.h>
//#include <qgscomposertable.h>
//#include <qgscomposerattributetable.h>
//#include <qgscomposertexttable.h>
%End

%ConvertToSubClassCode
if (dynamic_cast<QgsComposerLabel*>(sipCpp) != NULL)
sipClass = sipClass_QgsComposerLabel;
else if (dynamic_cast<QgsComposerLegend*>(sipCpp) != NULL)
sipClass = sipClass_QgsComposerLegend;
else if (dynamic_cast<QgsComposerMap*>(sipCpp) != NULL)
sipClass = sipClass_QgsComposerMap;
else if (dynamic_cast<QgsComposerPicture*>(sipCpp) != NULL)
sipClass = sipClass_QgsComposerPicture;
else if (dynamic_cast<QgsComposerScaleBar*>(sipCpp) != NULL)
sipClass = sipClass_QgsComposerScaleBar;
else if (dynamic_cast<QgsComposerShape*>(sipCpp) != NULL)
sipClass = sipClass_QgsComposerShape;
else
sipClass = 0;
// the conversions have to be static, because they're using multiple inheritance
// (seen in PyQt4 .sip files for some QGraphicsItem classes)
switch (sipCpp->type())
{
case QgsComposerItem::ComposerItem:
sipType = sipType_QgsComposerItem;
*sipCppRet = static_cast<QgsComposerItem*>(sipCpp);
break;
/* case QgsComposerItem::ComposerArrow:
sipType = sipType_QgsComposerArrow;
*sipCppRet = static_cast<QgsComposerArrow*>(sipCpp);
break;
case QgsComposerItem::ComposerItemGroup:
sipType = sipType_QgsComposerItemGroup;
*sipCppRet = static_cast<QgsComposerItemGroup*>(sipCpp);
break;*/
case QgsComposerItem::ComposerLabel:
sipType = sipType_QgsComposerLabel;
*sipCppRet = static_cast<QgsComposerLabel*>(sipCpp);
break;
case QgsComposerItem::ComposerLegend:
sipType = sipType_QgsComposerLegend;
*sipCppRet = static_cast<QgsComposerLegend*>(sipCpp);
break;
case QgsComposerItem::ComposerMap:
sipType = sipType_QgsComposerMap;
*sipCppRet = static_cast<QgsComposerMap*>(sipCpp);
break;
case QgsComposerItem::ComposerPaper:
sipType = sipType_QgsPaperItem;
*sipCppRet = static_cast<QgsPaperItem*>(sipCpp);
break;
case QgsComposerItem::ComposerPicture:
sipType = sipType_QgsComposerPicture;
*sipCppRet = static_cast<QgsComposerPicture*>(sipCpp);
break;
case QgsComposerItem::ComposerScaleBar:
sipType = sipType_QgsComposerScaleBar;
*sipCppRet = static_cast<QgsComposerScaleBar*>(sipCpp);
break;
case QgsComposerItem::ComposerShape:
sipType = sipType_QgsComposerShape;
*sipCppRet = static_cast<QgsComposerShape*>(sipCpp);
break;
/* case QgsComposerItem::ComposerTable:
sipType = sipType_QgsComposerTable;
*sipCppRet = static_cast<QgsComposerTable*>(sipCpp);
break;
case QgsComposerItem::ComposerAttributeTable:
sipType = sipType_QgsComposerAttributeTable;
*sipCppRet = static_cast<QgsComposerAttributeTable*>(sipCpp);
break;
case QgsComposerItem::ComposerTextTable:
sipType = sipType_QgsComposerTextTable;
*sipCppRet = static_cast<QgsComposerTextTable*>(sipCpp);
break;*/
default:
sipType = 0;
}
%End

public:

enum ItemType
{
// base class for the items
ComposerItem = 65636, /* UserType + 100 ... SIP does not do arithmetic */

// derived classes
ComposerArrow,
ComposerItemGroup,
ComposerLabel,
ComposerLegend,
ComposerMap,
ComposerPaper, // QgsPaperItem
ComposerPicture,
ComposerScaleBar,
ComposerShape,
ComposerTable,
ComposerAttributeTable,
ComposerTextTable
};

/**Describes the action (move or resize in different directon) to be done during mouse move*/
enum MouseMoveAction
{
Expand Down Expand Up @@ -61,12 +132,15 @@ class QgsComposerItem: QObject, QGraphicsRectItem

/**Constructor
@param manageZValue true if the z-Value of this object should be managed by mComposition*/
QgsComposerItem( QgsComposition* composition, bool manageZValue = true );
QgsComposerItem( QgsComposition* composition /TransferThis/, bool manageZValue = true );
/**Constructor with box position and composer object
@param manageZValue true if the z-Value of this object should be managed by mComposition*/
QgsComposerItem( qreal x, qreal y, qreal width, qreal height, QgsComposition* composition, bool manageZValue = true );
QgsComposerItem( qreal x, qreal y, qreal width, qreal height, QgsComposition* composition /TransferThis/, bool manageZValue = true );
virtual ~QgsComposerItem();

/** return correct graphics item type. Added in v1.7 */
virtual int type() const;

/** \brief Set selected, selected item should be highlighted */
virtual void setSelected( bool s );

Expand Down
3 changes: 3 additions & 0 deletions python/core/qgscomposerlabel.sip
Expand Up @@ -10,6 +10,9 @@ class QgsComposerLabel: QgsComposerItem
QgsComposerLabel( QgsComposition *composition /TransferThis/);
~QgsComposerLabel();

/** return correct graphics item type. Added in v1.7 */
virtual int type() const;

/** \brief Reimplementation of QCanvasItem::paint*/
void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget );

Expand Down
3 changes: 3 additions & 0 deletions python/core/qgscomposerlegend.sip
Expand Up @@ -11,6 +11,9 @@ class QgsComposerLegend: QgsComposerItem
QgsComposerLegend( QgsComposition* composition /TransferThis/);
~QgsComposerLegend();

/** return correct graphics item type. Added in v1.7 */
virtual int type() const;

/** \brief Reimplementation of QCanvasItem::paint*/
void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget );

Expand Down
3 changes: 3 additions & 0 deletions python/core/qgscomposermap.sip
Expand Up @@ -16,6 +16,9 @@ class QgsComposerMap : QgsComposerItem
QgsComposerMap( QgsComposition *composition /TransferThis/ );
~QgsComposerMap();

/** return correct graphics item type. Added in v1.7 */
virtual int type() const;

/** \brief Preview style */
enum PreviewMode
{
Expand Down
3 changes: 3 additions & 0 deletions python/core/qgscomposerpicture.sip
Expand Up @@ -12,6 +12,9 @@ class QgsComposerPicture: QgsComposerItem
QgsComposerPicture( QgsComposition *composition /TransferThis/);
~QgsComposerPicture();

/** return correct graphics item type. Added in v1.7 */
virtual int type() const;

/**Reimplementation of QCanvasItem::paint*/
void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget );

Expand Down
3 changes: 3 additions & 0 deletions python/core/qgscomposerscalebar.sip
Expand Up @@ -12,6 +12,9 @@ class QgsComposerScaleBar: QgsComposerItem
QgsComposerScaleBar( QgsComposition* composition /TransferThis/);
~QgsComposerScaleBar();

/** return correct graphics item type. Added in v1.7 */
virtual int type() const;

/** \brief Reimplementation of QCanvasItem::paint*/
void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget );

Expand Down
3 changes: 3 additions & 0 deletions python/core/qgscomposershape.sip
Expand Up @@ -17,6 +17,9 @@ class QgsComposerShape: QgsComposerItem
QgsComposerShape( qreal x, qreal y, qreal width, qreal height, QgsComposition* composition /TransferThis/);
~QgsComposerShape();

/** return correct graphics item type. Added in v1.7 */
virtual int type() const;

/** \brief Reimplementation of QCanvasItem::paint - draw on canvas */
void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget );

Expand Down
9 changes: 6 additions & 3 deletions python/core/qgspaperitem.sip
Expand Up @@ -6,10 +6,13 @@ class QgsPaperItem: QgsComposerItem
#include <qgspaperitem.h>
%End
public:
QgsPaperItem( QgsComposition* c );
QgsPaperItem( qreal x, qreal y, qreal width, qreal height, QgsComposition* composition );
QgsPaperItem( QgsComposition* c /TransferThis/ );
QgsPaperItem( qreal x, qreal y, qreal width, qreal height, QgsComposition* composition /TransferThis/ );
~QgsPaperItem();

/** return correct graphics item type. Added in v1.7 */
virtual int type() const;

/** \brief Reimplementation of QCanvasItem::paint*/
void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget );

Expand All @@ -26,4 +29,4 @@ class QgsPaperItem: QgsComposerItem

private:
QgsPaperItem();
};
};
3 changes: 3 additions & 0 deletions src/core/composer/qgscomposerarrow.h
Expand Up @@ -36,6 +36,9 @@ class CORE_EXPORT QgsComposerArrow: public QgsComposerItem
QgsComposerArrow( const QPointF& startPoint, const QPointF& stopPoint, QgsComposition* c );
~QgsComposerArrow();

/** return correct graphics item type. Added in v1.7 */
virtual int type() const { return ComposerArrow; }

/** \brief Reimplementation of QCanvasItem::paint - draw on canvas */
void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget );

Expand Down
3 changes: 3 additions & 0 deletions src/core/composer/qgscomposerattributetable.h
Expand Up @@ -44,6 +44,9 @@ class CORE_EXPORT QgsComposerAttributeTable: public QgsComposerTable
QgsComposerAttributeTable( QgsComposition* composition );
~QgsComposerAttributeTable();

/** return correct graphics item type. Added in v1.7 */
virtual int type() const { return ComposerAttributeTable; }

/** \brief Reimplementation of QCanvasItem::paint*/
virtual void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget );

Expand Down
23 changes: 23 additions & 0 deletions src/core/composer/qgscomposeritem.h
Expand Up @@ -35,6 +35,26 @@ class CORE_EXPORT QgsComposerItem: public QObject, public QGraphicsRectItem
Q_OBJECT
public:

enum ItemType
{
// base class for the items
ComposerItem = UserType + 100,

// derived classes
ComposerArrow,
ComposerItemGroup,
ComposerLabel,
ComposerLegend,
ComposerMap,
ComposerPaper, // QgsPaperItem
ComposerPicture,
ComposerScaleBar,
ComposerShape,
ComposerTable,
ComposerAttributeTable,
ComposerTextTable
};

/**Describes the action (move or resize in different directon) to be done during mouse move*/
enum MouseMoveAction
{
Expand Down Expand Up @@ -77,6 +97,9 @@ class CORE_EXPORT QgsComposerItem: public QObject, public QGraphicsRectItem
QgsComposerItem( qreal x, qreal y, qreal width, qreal height, QgsComposition* composition, bool manageZValue = true );
virtual ~QgsComposerItem();

/** return correct graphics item type. Added in v1.7 */
virtual int type() const { return ComposerItem; }

/** \brief Set selected, selected item should be highlighted */
virtual void setSelected( bool s );

Expand Down
4 changes: 4 additions & 0 deletions src/core/composer/qgscomposeritemgroup.h
Expand Up @@ -27,6 +27,10 @@ class CORE_EXPORT QgsComposerItemGroup: public QgsComposerItem
public:
QgsComposerItemGroup( QgsComposition* c );
~QgsComposerItemGroup();

/** return correct graphics item type. Added in v1.7 */
virtual int type() const { return ComposerItemGroup; }

/**Adds an item to the group. All the group members are deleted
if the group is deleted*/
void addItem( QgsComposerItem* item );
Expand Down
3 changes: 3 additions & 0 deletions src/core/composer/qgscomposerlabel.h
Expand Up @@ -28,6 +28,9 @@ class CORE_EXPORT QgsComposerLabel: public QgsComposerItem
QgsComposerLabel( QgsComposition *composition );
~QgsComposerLabel();

/** return correct graphics item type. Added in v1.7 */
virtual int type() const { return ComposerLabel; }

/** \brief Reimplementation of QCanvasItem::paint*/
void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget );

Expand Down
3 changes: 3 additions & 0 deletions src/core/composer/qgscomposerlegend.h
Expand Up @@ -37,6 +37,9 @@ class CORE_EXPORT QgsComposerLegend: public QgsComposerItem
QgsComposerLegend( QgsComposition* composition );
~QgsComposerLegend();

/** return correct graphics item type. Added in v1.7 */
virtual int type() const { return ComposerLegend; }

/** \brief Reimplementation of QCanvasItem::paint*/
void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget );

Expand Down
3 changes: 3 additions & 0 deletions src/core/composer/qgscomposermap.h
Expand Up @@ -46,6 +46,9 @@ class CORE_EXPORT QgsComposerMap : public QgsComposerItem
QgsComposerMap( QgsComposition *composition );
~QgsComposerMap();

/** return correct graphics item type. Added in v1.7 */
virtual int type() const { return ComposerMap; }

/** \brief Preview style */
enum PreviewMode
{
Expand Down
3 changes: 3 additions & 0 deletions src/core/composer/qgscomposerpicture.h
Expand Up @@ -31,6 +31,9 @@ class CORE_EXPORT QgsComposerPicture: public QgsComposerItem
QgsComposerPicture( QgsComposition *composition );
~QgsComposerPicture();

/** return correct graphics item type. Added in v1.7 */
virtual int type() const { return ComposerPicture; }

/**Reimplementation of QCanvasItem::paint*/
void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget );

Expand Down
3 changes: 3 additions & 0 deletions src/core/composer/qgscomposerscalebar.h
Expand Up @@ -35,6 +35,9 @@ class CORE_EXPORT QgsComposerScaleBar: public QgsComposerItem
QgsComposerScaleBar( QgsComposition* composition );
~QgsComposerScaleBar();

/** return correct graphics item type. Added in v1.7 */
virtual int type() const { return ComposerScaleBar; }

/** \brief Reimplementation of QCanvasItem::paint*/
void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget );

Expand Down
3 changes: 3 additions & 0 deletions src/core/composer/qgscomposershape.h
Expand Up @@ -37,6 +37,9 @@ class CORE_EXPORT QgsComposerShape: public QgsComposerItem
QgsComposerShape( qreal x, qreal y, qreal width, qreal height, QgsComposition* composition );
~QgsComposerShape();

/** return correct graphics item type. Added in v1.7 */
virtual int type() const { return ComposerShape; }

/** \brief Reimplementation of QCanvasItem::paint - draw on canvas */
void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget );

Expand Down
3 changes: 3 additions & 0 deletions src/core/composer/qgscomposertable.h
Expand Up @@ -31,6 +31,9 @@ class CORE_EXPORT QgsComposerTable: public QgsComposerItem
QgsComposerTable( QgsComposition* composition );
virtual ~QgsComposerTable();

/** return correct graphics item type. Added in v1.7 */
virtual int type() const { return ComposerTable; }

/** \brief Reimplementation of QCanvasItem::paint*/
virtual void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget );

Expand Down
3 changes: 3 additions & 0 deletions src/core/composer/qgscomposertexttable.h
Expand Up @@ -27,6 +27,9 @@ class CORE_EXPORT QgsComposerTextTable: public QgsComposerTable
QgsComposerTextTable( QgsComposition* c );
~QgsComposerTextTable();

/** return correct graphics item type. Added in v1.7 */
virtual int type() const { return ComposerTextTable; }

void setHeaderLabels( const QStringList& l ) { mHeaderLabels = l; }
void addRow( const QStringList& row ) { mRowText.append( row ); }

Expand Down
3 changes: 3 additions & 0 deletions src/core/composer/qgspaperitem.h
Expand Up @@ -29,6 +29,9 @@ class CORE_EXPORT QgsPaperItem: public QgsComposerItem
QgsPaperItem( qreal x, qreal y, qreal width, qreal height, QgsComposition* composition );
~QgsPaperItem();

/** return correct graphics item type. Added in v1.7 */
virtual int type() const { return ComposerPaper; }

/** \brief Reimplementation of QCanvasItem::paint*/
void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget );

Expand Down

0 comments on commit 86af48d

Please sign in to comment.