Skip to content

Commit 86af48d

Browse files
author
wonder
committed
Proper conversion to subclasses for composer items.
git-svn-id: http://svn.osgeo.org/qgis/trunk@14766 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 07d01b9 commit 86af48d

21 files changed

+174
-19
lines changed

python/core/qgscomposeritem.sip

Lines changed: 90 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,104 @@ class QgsComposerItem: QObject, QGraphicsRectItem
55
{
66
%TypeHeaderCode
77
#include <qgscomposeritem.h>
8+
//#include <qgscomposerarrow.h>
9+
//#include <qgscomposeritemgroup.h>
810
#include <qgscomposerlabel.h>
911
#include <qgscomposerlegend.h>
1012
#include <qgscomposermap.h>
13+
#include <qgspaperitem.h>
1114
#include <qgscomposerpicture.h>
1215
#include <qgscomposerscalebar.h>
1316
#include <qgscomposershape.h>
17+
//#include <qgscomposertable.h>
18+
//#include <qgscomposerattributetable.h>
19+
//#include <qgscomposertexttable.h>
1420
%End
1521

1622
%ConvertToSubClassCode
17-
if (dynamic_cast<QgsComposerLabel*>(sipCpp) != NULL)
18-
sipClass = sipClass_QgsComposerLabel;
19-
else if (dynamic_cast<QgsComposerLegend*>(sipCpp) != NULL)
20-
sipClass = sipClass_QgsComposerLegend;
21-
else if (dynamic_cast<QgsComposerMap*>(sipCpp) != NULL)
22-
sipClass = sipClass_QgsComposerMap;
23-
else if (dynamic_cast<QgsComposerPicture*>(sipCpp) != NULL)
24-
sipClass = sipClass_QgsComposerPicture;
25-
else if (dynamic_cast<QgsComposerScaleBar*>(sipCpp) != NULL)
26-
sipClass = sipClass_QgsComposerScaleBar;
27-
else if (dynamic_cast<QgsComposerShape*>(sipCpp) != NULL)
28-
sipClass = sipClass_QgsComposerShape;
29-
else
30-
sipClass = 0;
23+
// the conversions have to be static, because they're using multiple inheritance
24+
// (seen in PyQt4 .sip files for some QGraphicsItem classes)
25+
switch (sipCpp->type())
26+
{
27+
case QgsComposerItem::ComposerItem:
28+
sipType = sipType_QgsComposerItem;
29+
*sipCppRet = static_cast<QgsComposerItem*>(sipCpp);
30+
break;
31+
/* case QgsComposerItem::ComposerArrow:
32+
sipType = sipType_QgsComposerArrow;
33+
*sipCppRet = static_cast<QgsComposerArrow*>(sipCpp);
34+
break;
35+
case QgsComposerItem::ComposerItemGroup:
36+
sipType = sipType_QgsComposerItemGroup;
37+
*sipCppRet = static_cast<QgsComposerItemGroup*>(sipCpp);
38+
break;*/
39+
case QgsComposerItem::ComposerLabel:
40+
sipType = sipType_QgsComposerLabel;
41+
*sipCppRet = static_cast<QgsComposerLabel*>(sipCpp);
42+
break;
43+
case QgsComposerItem::ComposerLegend:
44+
sipType = sipType_QgsComposerLegend;
45+
*sipCppRet = static_cast<QgsComposerLegend*>(sipCpp);
46+
break;
47+
case QgsComposerItem::ComposerMap:
48+
sipType = sipType_QgsComposerMap;
49+
*sipCppRet = static_cast<QgsComposerMap*>(sipCpp);
50+
break;
51+
case QgsComposerItem::ComposerPaper:
52+
sipType = sipType_QgsPaperItem;
53+
*sipCppRet = static_cast<QgsPaperItem*>(sipCpp);
54+
break;
55+
case QgsComposerItem::ComposerPicture:
56+
sipType = sipType_QgsComposerPicture;
57+
*sipCppRet = static_cast<QgsComposerPicture*>(sipCpp);
58+
break;
59+
case QgsComposerItem::ComposerScaleBar:
60+
sipType = sipType_QgsComposerScaleBar;
61+
*sipCppRet = static_cast<QgsComposerScaleBar*>(sipCpp);
62+
break;
63+
case QgsComposerItem::ComposerShape:
64+
sipType = sipType_QgsComposerShape;
65+
*sipCppRet = static_cast<QgsComposerShape*>(sipCpp);
66+
break;
67+
/* case QgsComposerItem::ComposerTable:
68+
sipType = sipType_QgsComposerTable;
69+
*sipCppRet = static_cast<QgsComposerTable*>(sipCpp);
70+
break;
71+
case QgsComposerItem::ComposerAttributeTable:
72+
sipType = sipType_QgsComposerAttributeTable;
73+
*sipCppRet = static_cast<QgsComposerAttributeTable*>(sipCpp);
74+
break;
75+
case QgsComposerItem::ComposerTextTable:
76+
sipType = sipType_QgsComposerTextTable;
77+
*sipCppRet = static_cast<QgsComposerTextTable*>(sipCpp);
78+
break;*/
79+
default:
80+
sipType = 0;
81+
}
3182
%End
3283

3384
public:
3485

86+
enum ItemType
87+
{
88+
// base class for the items
89+
ComposerItem = 65636, /* UserType + 100 ... SIP does not do arithmetic */
90+
91+
// derived classes
92+
ComposerArrow,
93+
ComposerItemGroup,
94+
ComposerLabel,
95+
ComposerLegend,
96+
ComposerMap,
97+
ComposerPaper, // QgsPaperItem
98+
ComposerPicture,
99+
ComposerScaleBar,
100+
ComposerShape,
101+
ComposerTable,
102+
ComposerAttributeTable,
103+
ComposerTextTable
104+
};
105+
35106
/**Describes the action (move or resize in different directon) to be done during mouse move*/
36107
enum MouseMoveAction
37108
{
@@ -61,12 +132,15 @@ class QgsComposerItem: QObject, QGraphicsRectItem
61132

62133
/**Constructor
63134
@param manageZValue true if the z-Value of this object should be managed by mComposition*/
64-
QgsComposerItem( QgsComposition* composition, bool manageZValue = true );
135+
QgsComposerItem( QgsComposition* composition /TransferThis/, bool manageZValue = true );
65136
/**Constructor with box position and composer object
66137
@param manageZValue true if the z-Value of this object should be managed by mComposition*/
67-
QgsComposerItem( qreal x, qreal y, qreal width, qreal height, QgsComposition* composition, bool manageZValue = true );
138+
QgsComposerItem( qreal x, qreal y, qreal width, qreal height, QgsComposition* composition /TransferThis/, bool manageZValue = true );
68139
virtual ~QgsComposerItem();
69140

141+
/** return correct graphics item type. Added in v1.7 */
142+
virtual int type() const;
143+
70144
/** \brief Set selected, selected item should be highlighted */
71145
virtual void setSelected( bool s );
72146

python/core/qgscomposerlabel.sip

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ class QgsComposerLabel: QgsComposerItem
1010
QgsComposerLabel( QgsComposition *composition /TransferThis/);
1111
~QgsComposerLabel();
1212

13+
/** return correct graphics item type. Added in v1.7 */
14+
virtual int type() const;
15+
1316
/** \brief Reimplementation of QCanvasItem::paint*/
1417
void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget );
1518

python/core/qgscomposerlegend.sip

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ class QgsComposerLegend: QgsComposerItem
1111
QgsComposerLegend( QgsComposition* composition /TransferThis/);
1212
~QgsComposerLegend();
1313

14+
/** return correct graphics item type. Added in v1.7 */
15+
virtual int type() const;
16+
1417
/** \brief Reimplementation of QCanvasItem::paint*/
1518
void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget );
1619

python/core/qgscomposermap.sip

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ class QgsComposerMap : QgsComposerItem
1616
QgsComposerMap( QgsComposition *composition /TransferThis/ );
1717
~QgsComposerMap();
1818

19+
/** return correct graphics item type. Added in v1.7 */
20+
virtual int type() const;
21+
1922
/** \brief Preview style */
2023
enum PreviewMode
2124
{

python/core/qgscomposerpicture.sip

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ class QgsComposerPicture: QgsComposerItem
1212
QgsComposerPicture( QgsComposition *composition /TransferThis/);
1313
~QgsComposerPicture();
1414

15+
/** return correct graphics item type. Added in v1.7 */
16+
virtual int type() const;
17+
1518
/**Reimplementation of QCanvasItem::paint*/
1619
void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget );
1720

python/core/qgscomposerscalebar.sip

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ class QgsComposerScaleBar: QgsComposerItem
1212
QgsComposerScaleBar( QgsComposition* composition /TransferThis/);
1313
~QgsComposerScaleBar();
1414

15+
/** return correct graphics item type. Added in v1.7 */
16+
virtual int type() const;
17+
1518
/** \brief Reimplementation of QCanvasItem::paint*/
1619
void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget );
1720

python/core/qgscomposershape.sip

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ class QgsComposerShape: QgsComposerItem
1717
QgsComposerShape( qreal x, qreal y, qreal width, qreal height, QgsComposition* composition /TransferThis/);
1818
~QgsComposerShape();
1919

20+
/** return correct graphics item type. Added in v1.7 */
21+
virtual int type() const;
22+
2023
/** \brief Reimplementation of QCanvasItem::paint - draw on canvas */
2124
void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget );
2225

python/core/qgspaperitem.sip

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@ class QgsPaperItem: QgsComposerItem
66
#include <qgspaperitem.h>
77
%End
88
public:
9-
QgsPaperItem( QgsComposition* c );
10-
QgsPaperItem( qreal x, qreal y, qreal width, qreal height, QgsComposition* composition );
9+
QgsPaperItem( QgsComposition* c /TransferThis/ );
10+
QgsPaperItem( qreal x, qreal y, qreal width, qreal height, QgsComposition* composition /TransferThis/ );
1111
~QgsPaperItem();
1212

13+
/** return correct graphics item type. Added in v1.7 */
14+
virtual int type() const;
15+
1316
/** \brief Reimplementation of QCanvasItem::paint*/
1417
void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget );
1518

@@ -26,4 +29,4 @@ class QgsPaperItem: QgsComposerItem
2629

2730
private:
2831
QgsPaperItem();
29-
};
32+
};

src/core/composer/qgscomposerarrow.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ class CORE_EXPORT QgsComposerArrow: public QgsComposerItem
3636
QgsComposerArrow( const QPointF& startPoint, const QPointF& stopPoint, QgsComposition* c );
3737
~QgsComposerArrow();
3838

39+
/** return correct graphics item type. Added in v1.7 */
40+
virtual int type() const { return ComposerArrow; }
41+
3942
/** \brief Reimplementation of QCanvasItem::paint - draw on canvas */
4043
void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget );
4144

src/core/composer/qgscomposerattributetable.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ class CORE_EXPORT QgsComposerAttributeTable: public QgsComposerTable
4444
QgsComposerAttributeTable( QgsComposition* composition );
4545
~QgsComposerAttributeTable();
4646

47+
/** return correct graphics item type. Added in v1.7 */
48+
virtual int type() const { return ComposerAttributeTable; }
49+
4750
/** \brief Reimplementation of QCanvasItem::paint*/
4851
virtual void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget );
4952

src/core/composer/qgscomposeritem.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,26 @@ class CORE_EXPORT QgsComposerItem: public QObject, public QGraphicsRectItem
3535
Q_OBJECT
3636
public:
3737

38+
enum ItemType
39+
{
40+
// base class for the items
41+
ComposerItem = UserType + 100,
42+
43+
// derived classes
44+
ComposerArrow,
45+
ComposerItemGroup,
46+
ComposerLabel,
47+
ComposerLegend,
48+
ComposerMap,
49+
ComposerPaper, // QgsPaperItem
50+
ComposerPicture,
51+
ComposerScaleBar,
52+
ComposerShape,
53+
ComposerTable,
54+
ComposerAttributeTable,
55+
ComposerTextTable
56+
};
57+
3858
/**Describes the action (move or resize in different directon) to be done during mouse move*/
3959
enum MouseMoveAction
4060
{
@@ -77,6 +97,9 @@ class CORE_EXPORT QgsComposerItem: public QObject, public QGraphicsRectItem
7797
QgsComposerItem( qreal x, qreal y, qreal width, qreal height, QgsComposition* composition, bool manageZValue = true );
7898
virtual ~QgsComposerItem();
7999

100+
/** return correct graphics item type. Added in v1.7 */
101+
virtual int type() const { return ComposerItem; }
102+
80103
/** \brief Set selected, selected item should be highlighted */
81104
virtual void setSelected( bool s );
82105

src/core/composer/qgscomposeritemgroup.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ class CORE_EXPORT QgsComposerItemGroup: public QgsComposerItem
2727
public:
2828
QgsComposerItemGroup( QgsComposition* c );
2929
~QgsComposerItemGroup();
30+
31+
/** return correct graphics item type. Added in v1.7 */
32+
virtual int type() const { return ComposerItemGroup; }
33+
3034
/**Adds an item to the group. All the group members are deleted
3135
if the group is deleted*/
3236
void addItem( QgsComposerItem* item );

src/core/composer/qgscomposerlabel.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ class CORE_EXPORT QgsComposerLabel: public QgsComposerItem
2828
QgsComposerLabel( QgsComposition *composition );
2929
~QgsComposerLabel();
3030

31+
/** return correct graphics item type. Added in v1.7 */
32+
virtual int type() const { return ComposerLabel; }
33+
3134
/** \brief Reimplementation of QCanvasItem::paint*/
3235
void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget );
3336

src/core/composer/qgscomposerlegend.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ class CORE_EXPORT QgsComposerLegend: public QgsComposerItem
3737
QgsComposerLegend( QgsComposition* composition );
3838
~QgsComposerLegend();
3939

40+
/** return correct graphics item type. Added in v1.7 */
41+
virtual int type() const { return ComposerLegend; }
42+
4043
/** \brief Reimplementation of QCanvasItem::paint*/
4144
void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget );
4245

src/core/composer/qgscomposermap.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ class CORE_EXPORT QgsComposerMap : public QgsComposerItem
4646
QgsComposerMap( QgsComposition *composition );
4747
~QgsComposerMap();
4848

49+
/** return correct graphics item type. Added in v1.7 */
50+
virtual int type() const { return ComposerMap; }
51+
4952
/** \brief Preview style */
5053
enum PreviewMode
5154
{

src/core/composer/qgscomposerpicture.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ class CORE_EXPORT QgsComposerPicture: public QgsComposerItem
3131
QgsComposerPicture( QgsComposition *composition );
3232
~QgsComposerPicture();
3333

34+
/** return correct graphics item type. Added in v1.7 */
35+
virtual int type() const { return ComposerPicture; }
36+
3437
/**Reimplementation of QCanvasItem::paint*/
3538
void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget );
3639

src/core/composer/qgscomposerscalebar.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ class CORE_EXPORT QgsComposerScaleBar: public QgsComposerItem
3535
QgsComposerScaleBar( QgsComposition* composition );
3636
~QgsComposerScaleBar();
3737

38+
/** return correct graphics item type. Added in v1.7 */
39+
virtual int type() const { return ComposerScaleBar; }
40+
3841
/** \brief Reimplementation of QCanvasItem::paint*/
3942
void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget );
4043

src/core/composer/qgscomposershape.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ class CORE_EXPORT QgsComposerShape: public QgsComposerItem
3737
QgsComposerShape( qreal x, qreal y, qreal width, qreal height, QgsComposition* composition );
3838
~QgsComposerShape();
3939

40+
/** return correct graphics item type. Added in v1.7 */
41+
virtual int type() const { return ComposerShape; }
42+
4043
/** \brief Reimplementation of QCanvasItem::paint - draw on canvas */
4144
void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget );
4245

src/core/composer/qgscomposertable.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ class CORE_EXPORT QgsComposerTable: public QgsComposerItem
3131
QgsComposerTable( QgsComposition* composition );
3232
virtual ~QgsComposerTable();
3333

34+
/** return correct graphics item type. Added in v1.7 */
35+
virtual int type() const { return ComposerTable; }
36+
3437
/** \brief Reimplementation of QCanvasItem::paint*/
3538
virtual void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget );
3639

src/core/composer/qgscomposertexttable.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ class CORE_EXPORT QgsComposerTextTable: public QgsComposerTable
2727
QgsComposerTextTable( QgsComposition* c );
2828
~QgsComposerTextTable();
2929

30+
/** return correct graphics item type. Added in v1.7 */
31+
virtual int type() const { return ComposerTextTable; }
32+
3033
void setHeaderLabels( const QStringList& l ) { mHeaderLabels = l; }
3134
void addRow( const QStringList& row ) { mRowText.append( row ); }
3235

src/core/composer/qgspaperitem.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ class CORE_EXPORT QgsPaperItem: public QgsComposerItem
2929
QgsPaperItem( qreal x, qreal y, qreal width, qreal height, QgsComposition* composition );
3030
~QgsPaperItem();
3131

32+
/** return correct graphics item type. Added in v1.7 */
33+
virtual int type() const { return ComposerPaper; }
34+
3235
/** \brief Reimplementation of QCanvasItem::paint*/
3336
void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget );
3437

0 commit comments

Comments
 (0)