Proper conversion to subclasses for composer items.

git-svn-id: http://svn.osgeo.org/qgis/trunk@14766 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
wonder 2010-11-25 21:45:52 +00:00
parent 07d01b947a
commit 86af48d1e6
21 changed files with 174 additions and 19 deletions

View File

@ -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
{
@ -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 );

View File

@ -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 );

View File

@ -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 );

View File

@ -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
{

View File

@ -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 );

View File

@ -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 );

View File

@ -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 );

View File

@ -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 );

View File

@ -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 );

View File

@ -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 );

View File

@ -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
{
@ -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 );

View File

@ -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 );

View File

@ -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 );

View File

@ -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 );

View File

@ -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
{

View File

@ -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 );

View File

@ -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 );

View File

@ -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 );

View File

@ -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 );

View File

@ -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 ); }

View File

@ -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 );