##// END OF EJS Templates
- added hasOwner method to manage ownership more nicely...
florianlink -
r15:ae998290bf19
parent child
Show More
@@ -1,177 +1,179
1 #ifndef PYTHONQTWRAPPER_QGRAPHICSITEM_H
1 #ifndef PYTHONQTWRAPPER_QGRAPHICSITEM_H
2 #define PYTHONQTWRAPPER_QGRAPHICSITEM_H
2 #define PYTHONQTWRAPPER_QGRAPHICSITEM_H
3
3
4 #include <qgraphicsitem.h>
4 #include <qgraphicsitem.h>
5 #include <QObject>
5 #include <QObject>
6
6
7 #include <QVariant>
7 #include <QVariant>
8 #include <qcoreevent.h>
8 #include <qcoreevent.h>
9 #include <qcursor.h>
9 #include <qcursor.h>
10 #include <qevent.h>
10 #include <qevent.h>
11 #include <qgraphicsitem.h>
11 #include <qgraphicsitem.h>
12 #include <qgraphicsscene.h>
12 #include <qgraphicsscene.h>
13 #include <qgraphicssceneevent.h>
13 #include <qgraphicssceneevent.h>
14 #include <qgraphicswidget.h>
14 #include <qgraphicswidget.h>
15 #include <qlist.h>
15 #include <qlist.h>
16 #include <qpainter.h>
16 #include <qpainter.h>
17 #include <qpainterpath.h>
17 #include <qpainterpath.h>
18 #include <qpoint.h>
18 #include <qpoint.h>
19 #include <qpolygon.h>
19 #include <qpolygon.h>
20 #include <qrect.h>
20 #include <qrect.h>
21 #include <qregion.h>
21 #include <qregion.h>
22 #include <qsize.h>
22 #include <qsize.h>
23 #include <qstyleoption.h>
23 #include <qstyleoption.h>
24 #include <qtransform.h>
24 #include <qtransform.h>
25 #include <qwidget.h>
25 #include <qwidget.h>
26
26
27 class PythonQtWrapper_QGraphicsItem : public QObject
27 class PythonQtWrapper_QGraphicsItem : public QObject
28 { Q_OBJECT
28 { Q_OBJECT
29 public:
29 public:
30 Q_ENUMS(CacheMode enum_1 GraphicsItemFlag GraphicsItemChange )
30 Q_ENUMS(CacheMode enum_1 GraphicsItemFlag GraphicsItemChange )
31 enum CacheMode{
31 enum CacheMode{
32 NoCache = QGraphicsItem::NoCache, ItemCoordinateCache = QGraphicsItem::ItemCoordinateCache, DeviceCoordinateCache = QGraphicsItem::DeviceCoordinateCache};
32 NoCache = QGraphicsItem::NoCache, ItemCoordinateCache = QGraphicsItem::ItemCoordinateCache, DeviceCoordinateCache = QGraphicsItem::DeviceCoordinateCache};
33 enum enum_1{
33 enum enum_1{
34 Type = QGraphicsItem::Type, UserType = QGraphicsItem::UserType};
34 Type = QGraphicsItem::Type, UserType = QGraphicsItem::UserType};
35 enum GraphicsItemFlag{
35 enum GraphicsItemFlag{
36 ItemIsMovable = QGraphicsItem::ItemIsMovable, ItemIsSelectable = QGraphicsItem::ItemIsSelectable, ItemIsFocusable = QGraphicsItem::ItemIsFocusable, ItemClipsToShape = QGraphicsItem::ItemClipsToShape, ItemClipsChildrenToShape = QGraphicsItem::ItemClipsChildrenToShape, ItemIgnoresTransformations = QGraphicsItem::ItemIgnoresTransformations};
36 ItemIsMovable = QGraphicsItem::ItemIsMovable, ItemIsSelectable = QGraphicsItem::ItemIsSelectable, ItemIsFocusable = QGraphicsItem::ItemIsFocusable, ItemClipsToShape = QGraphicsItem::ItemClipsToShape, ItemClipsChildrenToShape = QGraphicsItem::ItemClipsChildrenToShape, ItemIgnoresTransformations = QGraphicsItem::ItemIgnoresTransformations};
37 enum GraphicsItemChange{
37 enum GraphicsItemChange{
38 ItemPositionChange = QGraphicsItem::ItemPositionChange, ItemMatrixChange = QGraphicsItem::ItemMatrixChange, ItemVisibleChange = QGraphicsItem::ItemVisibleChange, ItemEnabledChange = QGraphicsItem::ItemEnabledChange, ItemSelectedChange = QGraphicsItem::ItemSelectedChange, ItemParentChange = QGraphicsItem::ItemParentChange, ItemChildAddedChange = QGraphicsItem::ItemChildAddedChange, ItemChildRemovedChange = QGraphicsItem::ItemChildRemovedChange, ItemTransformChange = QGraphicsItem::ItemTransformChange, ItemPositionHasChanged = QGraphicsItem::ItemPositionHasChanged, ItemTransformHasChanged = QGraphicsItem::ItemTransformHasChanged, ItemSceneChange = QGraphicsItem::ItemSceneChange, ItemVisibleHasChanged = QGraphicsItem::ItemVisibleHasChanged, ItemEnabledHasChanged = QGraphicsItem::ItemEnabledHasChanged, ItemSelectedHasChanged = QGraphicsItem::ItemSelectedHasChanged, ItemParentHasChanged = QGraphicsItem::ItemParentHasChanged, ItemSceneHasChanged = QGraphicsItem::ItemSceneHasChanged, ItemCursorChange = QGraphicsItem::ItemCursorChange, ItemCursorHasChanged = QGraphicsItem::ItemCursorHasChanged, ItemToolTipChange = QGraphicsItem::ItemToolTipChange, ItemToolTipHasChanged = QGraphicsItem::ItemToolTipHasChanged, ItemFlagsChange = QGraphicsItem::ItemFlagsChange, ItemFlagsHaveChanged = QGraphicsItem::ItemFlagsHaveChanged, ItemZValueChange = QGraphicsItem::ItemZValueChange, ItemZValueHasChanged = QGraphicsItem::ItemZValueHasChanged};
38 ItemPositionChange = QGraphicsItem::ItemPositionChange, ItemMatrixChange = QGraphicsItem::ItemMatrixChange, ItemVisibleChange = QGraphicsItem::ItemVisibleChange, ItemEnabledChange = QGraphicsItem::ItemEnabledChange, ItemSelectedChange = QGraphicsItem::ItemSelectedChange, ItemParentChange = QGraphicsItem::ItemParentChange, ItemChildAddedChange = QGraphicsItem::ItemChildAddedChange, ItemChildRemovedChange = QGraphicsItem::ItemChildRemovedChange, ItemTransformChange = QGraphicsItem::ItemTransformChange, ItemPositionHasChanged = QGraphicsItem::ItemPositionHasChanged, ItemTransformHasChanged = QGraphicsItem::ItemTransformHasChanged, ItemSceneChange = QGraphicsItem::ItemSceneChange, ItemVisibleHasChanged = QGraphicsItem::ItemVisibleHasChanged, ItemEnabledHasChanged = QGraphicsItem::ItemEnabledHasChanged, ItemSelectedHasChanged = QGraphicsItem::ItemSelectedHasChanged, ItemParentHasChanged = QGraphicsItem::ItemParentHasChanged, ItemSceneHasChanged = QGraphicsItem::ItemSceneHasChanged, ItemCursorChange = QGraphicsItem::ItemCursorChange, ItemCursorHasChanged = QGraphicsItem::ItemCursorHasChanged, ItemToolTipChange = QGraphicsItem::ItemToolTipChange, ItemToolTipHasChanged = QGraphicsItem::ItemToolTipHasChanged, ItemFlagsChange = QGraphicsItem::ItemFlagsChange, ItemFlagsHaveChanged = QGraphicsItem::ItemFlagsHaveChanged, ItemZValueChange = QGraphicsItem::ItemZValueChange, ItemZValueHasChanged = QGraphicsItem::ItemZValueHasChanged};
39 public slots:
39 public slots:
40 bool hasOwner(QGraphicsItem* theWrappedObject) { return theWrappedObject->scene()!=NULL || theWrappedObject->parentItem()!=NULL; }
41
40 void delete_QGraphicsItem(QGraphicsItem* obj) { delete obj; }
42 void delete_QGraphicsItem(QGraphicsItem* obj) { delete obj; }
41 bool acceptDrops(QGraphicsItem* theWrappedObject) const;
43 bool acceptDrops(QGraphicsItem* theWrappedObject) const;
42 bool acceptHoverEvents(QGraphicsItem* theWrappedObject) const;
44 bool acceptHoverEvents(QGraphicsItem* theWrappedObject) const;
43 Qt::MouseButtons acceptedMouseButtons(QGraphicsItem* theWrappedObject) const;
45 Qt::MouseButtons acceptedMouseButtons(QGraphicsItem* theWrappedObject) const;
44 bool acceptsHoverEvents(QGraphicsItem* theWrappedObject) const;
46 bool acceptsHoverEvents(QGraphicsItem* theWrappedObject) const;
45 void advance(QGraphicsItem* theWrappedObject, int phase);
47 void advance(QGraphicsItem* theWrappedObject, int phase);
46 QRectF boundingRect(QGraphicsItem* theWrappedObject) const;
48 QRectF boundingRect(QGraphicsItem* theWrappedObject) const;
47 QRegion boundingRegion(QGraphicsItem* theWrappedObject, const QTransform& itemToDeviceTransform) const;
49 QRegion boundingRegion(QGraphicsItem* theWrappedObject, const QTransform& itemToDeviceTransform) const;
48 qreal boundingRegionGranularity(QGraphicsItem* theWrappedObject) const;
50 qreal boundingRegionGranularity(QGraphicsItem* theWrappedObject) const;
49 QGraphicsItem::CacheMode cacheMode(QGraphicsItem* theWrappedObject) const;
51 QGraphicsItem::CacheMode cacheMode(QGraphicsItem* theWrappedObject) const;
50 QList<QGraphicsItem* > childItems(QGraphicsItem* theWrappedObject) const;
52 QList<QGraphicsItem* > childItems(QGraphicsItem* theWrappedObject) const;
51 QRectF childrenBoundingRect(QGraphicsItem* theWrappedObject) const;
53 QRectF childrenBoundingRect(QGraphicsItem* theWrappedObject) const;
52 void clearFocus(QGraphicsItem* theWrappedObject);
54 void clearFocus(QGraphicsItem* theWrappedObject);
53 bool collidesWithItem(QGraphicsItem* theWrappedObject, const QGraphicsItem* other, Qt::ItemSelectionMode mode = Qt::IntersectsItemShape) const;
55 bool collidesWithItem(QGraphicsItem* theWrappedObject, const QGraphicsItem* other, Qt::ItemSelectionMode mode = Qt::IntersectsItemShape) const;
54 bool collidesWithPath(QGraphicsItem* theWrappedObject, const QPainterPath& path, Qt::ItemSelectionMode mode = Qt::IntersectsItemShape) const;
56 bool collidesWithPath(QGraphicsItem* theWrappedObject, const QPainterPath& path, Qt::ItemSelectionMode mode = Qt::IntersectsItemShape) const;
55 QList<QGraphicsItem* > collidingItems(QGraphicsItem* theWrappedObject, Qt::ItemSelectionMode mode = Qt::IntersectsItemShape) const;
57 QList<QGraphicsItem* > collidingItems(QGraphicsItem* theWrappedObject, Qt::ItemSelectionMode mode = Qt::IntersectsItemShape) const;
56 QGraphicsItem* commonAncestorItem(QGraphicsItem* theWrappedObject, const QGraphicsItem* other) const;
58 QGraphicsItem* commonAncestorItem(QGraphicsItem* theWrappedObject, const QGraphicsItem* other) const;
57 bool contains(QGraphicsItem* theWrappedObject, const QPointF& point) const;
59 bool contains(QGraphicsItem* theWrappedObject, const QPointF& point) const;
58 QCursor cursor(QGraphicsItem* theWrappedObject) const;
60 QCursor cursor(QGraphicsItem* theWrappedObject) const;
59 QVariant data(QGraphicsItem* theWrappedObject, int key) const;
61 QVariant data(QGraphicsItem* theWrappedObject, int key) const;
60 QTransform deviceTransform(QGraphicsItem* theWrappedObject, const QTransform& viewportTransform) const;
62 QTransform deviceTransform(QGraphicsItem* theWrappedObject, const QTransform& viewportTransform) const;
61 void ensureVisible(QGraphicsItem* theWrappedObject, const QRectF& rect = QRectF(), int xmargin = 50, int ymargin = 50);
63 void ensureVisible(QGraphicsItem* theWrappedObject, const QRectF& rect = QRectF(), int xmargin = 50, int ymargin = 50);
62 void ensureVisible(QGraphicsItem* theWrappedObject, qreal x, qreal y, qreal w, qreal h, int xmargin = 50, int ymargin = 50);
64 void ensureVisible(QGraphicsItem* theWrappedObject, qreal x, qreal y, qreal w, qreal h, int xmargin = 50, int ymargin = 50);
63 QGraphicsItem::GraphicsItemFlags flags(QGraphicsItem* theWrappedObject) const;
65 QGraphicsItem::GraphicsItemFlags flags(QGraphicsItem* theWrappedObject) const;
64 void grabKeyboard(QGraphicsItem* theWrappedObject);
66 void grabKeyboard(QGraphicsItem* theWrappedObject);
65 void grabMouse(QGraphicsItem* theWrappedObject);
67 void grabMouse(QGraphicsItem* theWrappedObject);
66 QGraphicsItemGroup* group(QGraphicsItem* theWrappedObject) const;
68 QGraphicsItemGroup* group(QGraphicsItem* theWrappedObject) const;
67 bool handlesChildEvents(QGraphicsItem* theWrappedObject) const;
69 bool handlesChildEvents(QGraphicsItem* theWrappedObject) const;
68 bool hasCursor(QGraphicsItem* theWrappedObject) const;
70 bool hasCursor(QGraphicsItem* theWrappedObject) const;
69 bool hasFocus(QGraphicsItem* theWrappedObject) const;
71 bool hasFocus(QGraphicsItem* theWrappedObject) const;
70 void hide(QGraphicsItem* theWrappedObject);
72 void hide(QGraphicsItem* theWrappedObject);
71 void installSceneEventFilter(QGraphicsItem* theWrappedObject, QGraphicsItem* filterItem);
73 void installSceneEventFilter(QGraphicsItem* theWrappedObject, QGraphicsItem* filterItem);
72 bool isAncestorOf(QGraphicsItem* theWrappedObject, const QGraphicsItem* child) const;
74 bool isAncestorOf(QGraphicsItem* theWrappedObject, const QGraphicsItem* child) const;
73 bool isEnabled(QGraphicsItem* theWrappedObject) const;
75 bool isEnabled(QGraphicsItem* theWrappedObject) const;
74 bool isObscured(QGraphicsItem* theWrappedObject) const;
76 bool isObscured(QGraphicsItem* theWrappedObject) const;
75 bool isObscured(QGraphicsItem* theWrappedObject, const QRectF& rect) const;
77 bool isObscured(QGraphicsItem* theWrappedObject, const QRectF& rect) const;
76 bool isObscured(QGraphicsItem* theWrappedObject, qreal x, qreal y, qreal w, qreal h) const;
78 bool isObscured(QGraphicsItem* theWrappedObject, qreal x, qreal y, qreal w, qreal h) const;
77 bool isObscuredBy(QGraphicsItem* theWrappedObject, const QGraphicsItem* item) const;
79 bool isObscuredBy(QGraphicsItem* theWrappedObject, const QGraphicsItem* item) const;
78 bool isSelected(QGraphicsItem* theWrappedObject) const;
80 bool isSelected(QGraphicsItem* theWrappedObject) const;
79 bool isUnderMouse(QGraphicsItem* theWrappedObject) const;
81 bool isUnderMouse(QGraphicsItem* theWrappedObject) const;
80 bool isVisible(QGraphicsItem* theWrappedObject) const;
82 bool isVisible(QGraphicsItem* theWrappedObject) const;
81 bool isVisibleTo(QGraphicsItem* theWrappedObject, const QGraphicsItem* parent) const;
83 bool isVisibleTo(QGraphicsItem* theWrappedObject, const QGraphicsItem* parent) const;
82 bool isWidget(QGraphicsItem* theWrappedObject) const;
84 bool isWidget(QGraphicsItem* theWrappedObject) const;
83 bool isWindow(QGraphicsItem* theWrappedObject) const;
85 bool isWindow(QGraphicsItem* theWrappedObject) const;
84 QPainterPath mapFromItem(QGraphicsItem* theWrappedObject, const QGraphicsItem* item, const QPainterPath& path) const;
86 QPainterPath mapFromItem(QGraphicsItem* theWrappedObject, const QGraphicsItem* item, const QPainterPath& path) const;
85 QPointF mapFromItem(QGraphicsItem* theWrappedObject, const QGraphicsItem* item, const QPointF& point) const;
87 QPointF mapFromItem(QGraphicsItem* theWrappedObject, const QGraphicsItem* item, const QPointF& point) const;
86 QPolygonF mapFromItem(QGraphicsItem* theWrappedObject, const QGraphicsItem* item, const QPolygonF& polygon) const;
88 QPolygonF mapFromItem(QGraphicsItem* theWrappedObject, const QGraphicsItem* item, const QPolygonF& polygon) const;
87 QPolygonF mapFromItem(QGraphicsItem* theWrappedObject, const QGraphicsItem* item, const QRectF& rect) const;
89 QPolygonF mapFromItem(QGraphicsItem* theWrappedObject, const QGraphicsItem* item, const QRectF& rect) const;
88 QPointF mapFromItem(QGraphicsItem* theWrappedObject, const QGraphicsItem* item, qreal x, qreal y) const;
90 QPointF mapFromItem(QGraphicsItem* theWrappedObject, const QGraphicsItem* item, qreal x, qreal y) const;
89 QPolygonF mapFromItem(QGraphicsItem* theWrappedObject, const QGraphicsItem* item, qreal x, qreal y, qreal w, qreal h) const;
91 QPolygonF mapFromItem(QGraphicsItem* theWrappedObject, const QGraphicsItem* item, qreal x, qreal y, qreal w, qreal h) const;
90 QPainterPath mapFromParent(QGraphicsItem* theWrappedObject, const QPainterPath& path) const;
92 QPainterPath mapFromParent(QGraphicsItem* theWrappedObject, const QPainterPath& path) const;
91 QPointF mapFromParent(QGraphicsItem* theWrappedObject, const QPointF& point) const;
93 QPointF mapFromParent(QGraphicsItem* theWrappedObject, const QPointF& point) const;
92 QPolygonF mapFromParent(QGraphicsItem* theWrappedObject, const QPolygonF& polygon) const;
94 QPolygonF mapFromParent(QGraphicsItem* theWrappedObject, const QPolygonF& polygon) const;
93 QPolygonF mapFromParent(QGraphicsItem* theWrappedObject, const QRectF& rect) const;
95 QPolygonF mapFromParent(QGraphicsItem* theWrappedObject, const QRectF& rect) const;
94 QPointF mapFromParent(QGraphicsItem* theWrappedObject, qreal x, qreal y) const;
96 QPointF mapFromParent(QGraphicsItem* theWrappedObject, qreal x, qreal y) const;
95 QPolygonF mapFromParent(QGraphicsItem* theWrappedObject, qreal x, qreal y, qreal w, qreal h) const;
97 QPolygonF mapFromParent(QGraphicsItem* theWrappedObject, qreal x, qreal y, qreal w, qreal h) const;
96 QPainterPath mapFromScene(QGraphicsItem* theWrappedObject, const QPainterPath& path) const;
98 QPainterPath mapFromScene(QGraphicsItem* theWrappedObject, const QPainterPath& path) const;
97 QPointF mapFromScene(QGraphicsItem* theWrappedObject, const QPointF& point) const;
99 QPointF mapFromScene(QGraphicsItem* theWrappedObject, const QPointF& point) const;
98 QPolygonF mapFromScene(QGraphicsItem* theWrappedObject, const QPolygonF& polygon) const;
100 QPolygonF mapFromScene(QGraphicsItem* theWrappedObject, const QPolygonF& polygon) const;
99 QPolygonF mapFromScene(QGraphicsItem* theWrappedObject, const QRectF& rect) const;
101 QPolygonF mapFromScene(QGraphicsItem* theWrappedObject, const QRectF& rect) const;
100 QPointF mapFromScene(QGraphicsItem* theWrappedObject, qreal x, qreal y) const;
102 QPointF mapFromScene(QGraphicsItem* theWrappedObject, qreal x, qreal y) const;
101 QPolygonF mapFromScene(QGraphicsItem* theWrappedObject, qreal x, qreal y, qreal w, qreal h) const;
103 QPolygonF mapFromScene(QGraphicsItem* theWrappedObject, qreal x, qreal y, qreal w, qreal h) const;
102 QPainterPath mapToItem(QGraphicsItem* theWrappedObject, const QGraphicsItem* item, const QPainterPath& path) const;
104 QPainterPath mapToItem(QGraphicsItem* theWrappedObject, const QGraphicsItem* item, const QPainterPath& path) const;
103 QPointF mapToItem(QGraphicsItem* theWrappedObject, const QGraphicsItem* item, const QPointF& point) const;
105 QPointF mapToItem(QGraphicsItem* theWrappedObject, const QGraphicsItem* item, const QPointF& point) const;
104 QPolygonF mapToItem(QGraphicsItem* theWrappedObject, const QGraphicsItem* item, const QPolygonF& polygon) const;
106 QPolygonF mapToItem(QGraphicsItem* theWrappedObject, const QGraphicsItem* item, const QPolygonF& polygon) const;
105 QPolygonF mapToItem(QGraphicsItem* theWrappedObject, const QGraphicsItem* item, const QRectF& rect) const;
107 QPolygonF mapToItem(QGraphicsItem* theWrappedObject, const QGraphicsItem* item, const QRectF& rect) const;
106 QPointF mapToItem(QGraphicsItem* theWrappedObject, const QGraphicsItem* item, qreal x, qreal y) const;
108 QPointF mapToItem(QGraphicsItem* theWrappedObject, const QGraphicsItem* item, qreal x, qreal y) const;
107 QPolygonF mapToItem(QGraphicsItem* theWrappedObject, const QGraphicsItem* item, qreal x, qreal y, qreal w, qreal h) const;
109 QPolygonF mapToItem(QGraphicsItem* theWrappedObject, const QGraphicsItem* item, qreal x, qreal y, qreal w, qreal h) const;
108 QPainterPath mapToParent(QGraphicsItem* theWrappedObject, const QPainterPath& path) const;
110 QPainterPath mapToParent(QGraphicsItem* theWrappedObject, const QPainterPath& path) const;
109 QPointF mapToParent(QGraphicsItem* theWrappedObject, const QPointF& point) const;
111 QPointF mapToParent(QGraphicsItem* theWrappedObject, const QPointF& point) const;
110 QPolygonF mapToParent(QGraphicsItem* theWrappedObject, const QPolygonF& polygon) const;
112 QPolygonF mapToParent(QGraphicsItem* theWrappedObject, const QPolygonF& polygon) const;
111 QPolygonF mapToParent(QGraphicsItem* theWrappedObject, const QRectF& rect) const;
113 QPolygonF mapToParent(QGraphicsItem* theWrappedObject, const QRectF& rect) const;
112 QPointF mapToParent(QGraphicsItem* theWrappedObject, qreal x, qreal y) const;
114 QPointF mapToParent(QGraphicsItem* theWrappedObject, qreal x, qreal y) const;
113 QPolygonF mapToParent(QGraphicsItem* theWrappedObject, qreal x, qreal y, qreal w, qreal h) const;
115 QPolygonF mapToParent(QGraphicsItem* theWrappedObject, qreal x, qreal y, qreal w, qreal h) const;
114 QPainterPath mapToScene(QGraphicsItem* theWrappedObject, const QPainterPath& path) const;
116 QPainterPath mapToScene(QGraphicsItem* theWrappedObject, const QPainterPath& path) const;
115 QPointF mapToScene(QGraphicsItem* theWrappedObject, const QPointF& point) const;
117 QPointF mapToScene(QGraphicsItem* theWrappedObject, const QPointF& point) const;
116 QPolygonF mapToScene(QGraphicsItem* theWrappedObject, const QPolygonF& polygon) const;
118 QPolygonF mapToScene(QGraphicsItem* theWrappedObject, const QPolygonF& polygon) const;
117 QPolygonF mapToScene(QGraphicsItem* theWrappedObject, const QRectF& rect) const;
119 QPolygonF mapToScene(QGraphicsItem* theWrappedObject, const QRectF& rect) const;
118 QPointF mapToScene(QGraphicsItem* theWrappedObject, qreal x, qreal y) const;
120 QPointF mapToScene(QGraphicsItem* theWrappedObject, qreal x, qreal y) const;
119 QPolygonF mapToScene(QGraphicsItem* theWrappedObject, qreal x, qreal y, qreal w, qreal h) const;
121 QPolygonF mapToScene(QGraphicsItem* theWrappedObject, qreal x, qreal y, qreal w, qreal h) const;
120 void moveBy(QGraphicsItem* theWrappedObject, qreal dx, qreal dy);
122 void moveBy(QGraphicsItem* theWrappedObject, qreal dx, qreal dy);
121 QPainterPath opaqueArea(QGraphicsItem* theWrappedObject) const;
123 QPainterPath opaqueArea(QGraphicsItem* theWrappedObject) const;
122 void paint(QGraphicsItem* theWrappedObject, QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0);
124 void paint(QGraphicsItem* theWrappedObject, QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0);
123 QGraphicsItem* parentItem(QGraphicsItem* theWrappedObject) const;
125 QGraphicsItem* parentItem(QGraphicsItem* theWrappedObject) const;
124 QGraphicsWidget* parentWidget(QGraphicsItem* theWrappedObject) const;
126 QGraphicsWidget* parentWidget(QGraphicsItem* theWrappedObject) const;
125 QPointF pos(QGraphicsItem* theWrappedObject) const;
127 QPointF pos(QGraphicsItem* theWrappedObject) const;
126 void removeSceneEventFilter(QGraphicsItem* theWrappedObject, QGraphicsItem* filterItem);
128 void removeSceneEventFilter(QGraphicsItem* theWrappedObject, QGraphicsItem* filterItem);
127 void resetTransform(QGraphicsItem* theWrappedObject);
129 void resetTransform(QGraphicsItem* theWrappedObject);
128 void rotate(QGraphicsItem* theWrappedObject, qreal angle);
130 void rotate(QGraphicsItem* theWrappedObject, qreal angle);
129 void scale(QGraphicsItem* theWrappedObject, qreal sx, qreal sy);
131 void scale(QGraphicsItem* theWrappedObject, qreal sx, qreal sy);
130 QGraphicsScene* scene(QGraphicsItem* theWrappedObject) const;
132 QGraphicsScene* scene(QGraphicsItem* theWrappedObject) const;
131 QRectF sceneBoundingRect(QGraphicsItem* theWrappedObject) const;
133 QRectF sceneBoundingRect(QGraphicsItem* theWrappedObject) const;
132 QPointF scenePos(QGraphicsItem* theWrappedObject) const;
134 QPointF scenePos(QGraphicsItem* theWrappedObject) const;
133 QTransform sceneTransform(QGraphicsItem* theWrappedObject) const;
135 QTransform sceneTransform(QGraphicsItem* theWrappedObject) const;
134 void scroll(QGraphicsItem* theWrappedObject, qreal dx, qreal dy, const QRectF& rect = QRectF());
136 void scroll(QGraphicsItem* theWrappedObject, qreal dx, qreal dy, const QRectF& rect = QRectF());
135 void setAcceptDrops(QGraphicsItem* theWrappedObject, bool on);
137 void setAcceptDrops(QGraphicsItem* theWrappedObject, bool on);
136 void setAcceptHoverEvents(QGraphicsItem* theWrappedObject, bool enabled);
138 void setAcceptHoverEvents(QGraphicsItem* theWrappedObject, bool enabled);
137 void setAcceptedMouseButtons(QGraphicsItem* theWrappedObject, Qt::MouseButtons buttons);
139 void setAcceptedMouseButtons(QGraphicsItem* theWrappedObject, Qt::MouseButtons buttons);
138 void setAcceptsHoverEvents(QGraphicsItem* theWrappedObject, bool enabled);
140 void setAcceptsHoverEvents(QGraphicsItem* theWrappedObject, bool enabled);
139 void setBoundingRegionGranularity(QGraphicsItem* theWrappedObject, qreal granularity);
141 void setBoundingRegionGranularity(QGraphicsItem* theWrappedObject, qreal granularity);
140 void setCacheMode(QGraphicsItem* theWrappedObject, QGraphicsItem::CacheMode mode, const QSize& cacheSize = QSize());
142 void setCacheMode(QGraphicsItem* theWrappedObject, QGraphicsItem::CacheMode mode, const QSize& cacheSize = QSize());
141 void setCursor(QGraphicsItem* theWrappedObject, const QCursor& cursor);
143 void setCursor(QGraphicsItem* theWrappedObject, const QCursor& cursor);
142 void setData(QGraphicsItem* theWrappedObject, int key, const QVariant& value);
144 void setData(QGraphicsItem* theWrappedObject, int key, const QVariant& value);
143 void setEnabled(QGraphicsItem* theWrappedObject, bool enabled);
145 void setEnabled(QGraphicsItem* theWrappedObject, bool enabled);
144 void setFlag(QGraphicsItem* theWrappedObject, QGraphicsItem::GraphicsItemFlag flag, bool enabled = true);
146 void setFlag(QGraphicsItem* theWrappedObject, QGraphicsItem::GraphicsItemFlag flag, bool enabled = true);
145 void setFlags(QGraphicsItem* theWrappedObject, QGraphicsItem::GraphicsItemFlags flags);
147 void setFlags(QGraphicsItem* theWrappedObject, QGraphicsItem::GraphicsItemFlags flags);
146 void setFocus(QGraphicsItem* theWrappedObject, Qt::FocusReason focusReason = Qt::OtherFocusReason);
148 void setFocus(QGraphicsItem* theWrappedObject, Qt::FocusReason focusReason = Qt::OtherFocusReason);
147 void setGroup(QGraphicsItem* theWrappedObject, QGraphicsItemGroup* group);
149 void setGroup(QGraphicsItem* theWrappedObject, QGraphicsItemGroup* group);
148 void setHandlesChildEvents(QGraphicsItem* theWrappedObject, bool enabled);
150 void setHandlesChildEvents(QGraphicsItem* theWrappedObject, bool enabled);
149 void setParentItem(QGraphicsItem* theWrappedObject, QGraphicsItem* parent);
151 void setParentItem(QGraphicsItem* theWrappedObject, QGraphicsItem* parent);
150 void setPos(QGraphicsItem* theWrappedObject, const QPointF& pos);
152 void setPos(QGraphicsItem* theWrappedObject, const QPointF& pos);
151 void setPos(QGraphicsItem* theWrappedObject, qreal x, qreal y);
153 void setPos(QGraphicsItem* theWrappedObject, qreal x, qreal y);
152 void setSelected(QGraphicsItem* theWrappedObject, bool selected);
154 void setSelected(QGraphicsItem* theWrappedObject, bool selected);
153 void setToolTip(QGraphicsItem* theWrappedObject, const QString& toolTip);
155 void setToolTip(QGraphicsItem* theWrappedObject, const QString& toolTip);
154 void setTransform(QGraphicsItem* theWrappedObject, const QTransform& matrix, bool combine = false);
156 void setTransform(QGraphicsItem* theWrappedObject, const QTransform& matrix, bool combine = false);
155 void setVisible(QGraphicsItem* theWrappedObject, bool visible);
157 void setVisible(QGraphicsItem* theWrappedObject, bool visible);
156 void setZValue(QGraphicsItem* theWrappedObject, qreal z);
158 void setZValue(QGraphicsItem* theWrappedObject, qreal z);
157 QPainterPath shape(QGraphicsItem* theWrappedObject) const;
159 QPainterPath shape(QGraphicsItem* theWrappedObject) const;
158 void shear(QGraphicsItem* theWrappedObject, qreal sh, qreal sv);
160 void shear(QGraphicsItem* theWrappedObject, qreal sh, qreal sv);
159 void show(QGraphicsItem* theWrappedObject);
161 void show(QGraphicsItem* theWrappedObject);
160 QString toolTip(QGraphicsItem* theWrappedObject) const;
162 QString toolTip(QGraphicsItem* theWrappedObject) const;
161 QGraphicsItem* topLevelItem(QGraphicsItem* theWrappedObject) const;
163 QGraphicsItem* topLevelItem(QGraphicsItem* theWrappedObject) const;
162 QGraphicsWidget* topLevelWidget(QGraphicsItem* theWrappedObject) const;
164 QGraphicsWidget* topLevelWidget(QGraphicsItem* theWrappedObject) const;
163 QTransform transform(QGraphicsItem* theWrappedObject) const;
165 QTransform transform(QGraphicsItem* theWrappedObject) const;
164 void translate(QGraphicsItem* theWrappedObject, qreal dx, qreal dy);
166 void translate(QGraphicsItem* theWrappedObject, qreal dx, qreal dy);
165 int type(QGraphicsItem* theWrappedObject) const;
167 int type(QGraphicsItem* theWrappedObject) const;
166 void ungrabKeyboard(QGraphicsItem* theWrappedObject);
168 void ungrabKeyboard(QGraphicsItem* theWrappedObject);
167 void ungrabMouse(QGraphicsItem* theWrappedObject);
169 void ungrabMouse(QGraphicsItem* theWrappedObject);
168 void unsetCursor(QGraphicsItem* theWrappedObject);
170 void unsetCursor(QGraphicsItem* theWrappedObject);
169 void update(QGraphicsItem* theWrappedObject, const QRectF& rect = QRectF());
171 void update(QGraphicsItem* theWrappedObject, const QRectF& rect = QRectF());
170 void update(QGraphicsItem* theWrappedObject, qreal x, qreal y, qreal width, qreal height);
172 void update(QGraphicsItem* theWrappedObject, qreal x, qreal y, qreal width, qreal height);
171 QGraphicsWidget* window(QGraphicsItem* theWrappedObject) const;
173 QGraphicsWidget* window(QGraphicsItem* theWrappedObject) const;
172 qreal x(QGraphicsItem* theWrappedObject) const;
174 qreal x(QGraphicsItem* theWrappedObject) const;
173 qreal y(QGraphicsItem* theWrappedObject) const;
175 qreal y(QGraphicsItem* theWrappedObject) const;
174 qreal zValue(QGraphicsItem* theWrappedObject) const;
176 qreal zValue(QGraphicsItem* theWrappedObject) const;
175 };
177 };
176
178
177 #endif // PYTHONQTWRAPPER_QGRAPHICSITEM_H
179 #endif // PYTHONQTWRAPPER_QGRAPHICSITEM_H
@@ -1,93 +1,95
1 #ifndef PYTHONQTWRAPPER_QTREEWIDGETITEM_H
1 #ifndef PYTHONQTWRAPPER_QTREEWIDGETITEM_H
2 #define PYTHONQTWRAPPER_QTREEWIDGETITEM_H
2 #define PYTHONQTWRAPPER_QTREEWIDGETITEM_H
3
3
4 #include <qtreewidget.h>
4 #include <qtreewidget.h>
5 #include <QObject>
5 #include <QObject>
6
6
7 #include <QVariant>
7 #include <QVariant>
8 #include <qbrush.h>
8 #include <qbrush.h>
9 #include <qdatastream.h>
9 #include <qdatastream.h>
10 #include <qfont.h>
10 #include <qfont.h>
11 #include <qicon.h>
11 #include <qicon.h>
12 #include <qlist.h>
12 #include <qlist.h>
13 #include <qsize.h>
13 #include <qsize.h>
14 #include <qstringlist.h>
14 #include <qstringlist.h>
15 #include <qtreewidget.h>
15 #include <qtreewidget.h>
16
16
17 class PythonQtWrapper_QTreeWidgetItem : public QObject
17 class PythonQtWrapper_QTreeWidgetItem : public QObject
18 { Q_OBJECT
18 { Q_OBJECT
19 public:
19 public:
20 Q_ENUMS(ItemType ChildIndicatorPolicy )
20 Q_ENUMS(ItemType ChildIndicatorPolicy )
21 enum ItemType{
21 enum ItemType{
22 Type = QTreeWidgetItem::Type, UserType = QTreeWidgetItem::UserType};
22 Type = QTreeWidgetItem::Type, UserType = QTreeWidgetItem::UserType};
23 enum ChildIndicatorPolicy{
23 enum ChildIndicatorPolicy{
24 ShowIndicator = QTreeWidgetItem::ShowIndicator, DontShowIndicator = QTreeWidgetItem::DontShowIndicator, DontShowIndicatorWhenChildless = QTreeWidgetItem::DontShowIndicatorWhenChildless};
24 ShowIndicator = QTreeWidgetItem::ShowIndicator, DontShowIndicator = QTreeWidgetItem::DontShowIndicator, DontShowIndicatorWhenChildless = QTreeWidgetItem::DontShowIndicatorWhenChildless};
25 public slots:
25 public slots:
26 bool hasOwner(QTreeWidgetItem* theWrappedObject) { return theWrappedObject->treeWidget()!=NULL || theWrappedObject->parent()!=NULL; }
27
26 QTreeWidgetItem* new_QTreeWidgetItem(QTreeWidget* view, QTreeWidgetItem* after, int type = Type);
28 QTreeWidgetItem* new_QTreeWidgetItem(QTreeWidget* view, QTreeWidgetItem* after, int type = Type);
27 QTreeWidgetItem* new_QTreeWidgetItem(QTreeWidget* view, const QStringList& strings, int type = Type);
29 QTreeWidgetItem* new_QTreeWidgetItem(QTreeWidget* view, const QStringList& strings, int type = Type);
28 QTreeWidgetItem* new_QTreeWidgetItem(QTreeWidget* view, int type = Type);
30 QTreeWidgetItem* new_QTreeWidgetItem(QTreeWidget* view, int type = Type);
29 QTreeWidgetItem* new_QTreeWidgetItem(QTreeWidgetItem* parent, QTreeWidgetItem* after, int type = Type);
31 QTreeWidgetItem* new_QTreeWidgetItem(QTreeWidgetItem* parent, QTreeWidgetItem* after, int type = Type);
30 QTreeWidgetItem* new_QTreeWidgetItem(QTreeWidgetItem* parent, const QStringList& strings, int type = Type);
32 QTreeWidgetItem* new_QTreeWidgetItem(QTreeWidgetItem* parent, const QStringList& strings, int type = Type);
31 QTreeWidgetItem* new_QTreeWidgetItem(QTreeWidgetItem* parent, int type = Type);
33 QTreeWidgetItem* new_QTreeWidgetItem(QTreeWidgetItem* parent, int type = Type);
32 QTreeWidgetItem* new_QTreeWidgetItem(const QStringList& strings, int type = Type);
34 QTreeWidgetItem* new_QTreeWidgetItem(const QStringList& strings, int type = Type);
33 QTreeWidgetItem* new_QTreeWidgetItem(int type = Type);
35 QTreeWidgetItem* new_QTreeWidgetItem(int type = Type);
34 void delete_QTreeWidgetItem(QTreeWidgetItem* obj) { delete obj; }
36 void delete_QTreeWidgetItem(QTreeWidgetItem* obj) { delete obj; }
35 void addChild(QTreeWidgetItem* theWrappedObject, QTreeWidgetItem* child);
37 void addChild(QTreeWidgetItem* theWrappedObject, QTreeWidgetItem* child);
36 void addChildren(QTreeWidgetItem* theWrappedObject, const QList<QTreeWidgetItem* >& children);
38 void addChildren(QTreeWidgetItem* theWrappedObject, const QList<QTreeWidgetItem* >& children);
37 QBrush background(QTreeWidgetItem* theWrappedObject, int column) const;
39 QBrush background(QTreeWidgetItem* theWrappedObject, int column) const;
38 Qt::CheckState checkState(QTreeWidgetItem* theWrappedObject, int column) const;
40 Qt::CheckState checkState(QTreeWidgetItem* theWrappedObject, int column) const;
39 QTreeWidgetItem* child(QTreeWidgetItem* theWrappedObject, int index) const;
41 QTreeWidgetItem* child(QTreeWidgetItem* theWrappedObject, int index) const;
40 int childCount(QTreeWidgetItem* theWrappedObject) const;
42 int childCount(QTreeWidgetItem* theWrappedObject) const;
41 QTreeWidgetItem::ChildIndicatorPolicy childIndicatorPolicy(QTreeWidgetItem* theWrappedObject) const;
43 QTreeWidgetItem::ChildIndicatorPolicy childIndicatorPolicy(QTreeWidgetItem* theWrappedObject) const;
42 QTreeWidgetItem* clone(QTreeWidgetItem* theWrappedObject) const;
44 QTreeWidgetItem* clone(QTreeWidgetItem* theWrappedObject) const;
43 int columnCount(QTreeWidgetItem* theWrappedObject) const;
45 int columnCount(QTreeWidgetItem* theWrappedObject) const;
44 QVariant data(QTreeWidgetItem* theWrappedObject, int column, int role) const;
46 QVariant data(QTreeWidgetItem* theWrappedObject, int column, int role) const;
45 Qt::ItemFlags flags(QTreeWidgetItem* theWrappedObject) const;
47 Qt::ItemFlags flags(QTreeWidgetItem* theWrappedObject) const;
46 QFont font(QTreeWidgetItem* theWrappedObject, int column) const;
48 QFont font(QTreeWidgetItem* theWrappedObject, int column) const;
47 QBrush foreground(QTreeWidgetItem* theWrappedObject, int column) const;
49 QBrush foreground(QTreeWidgetItem* theWrappedObject, int column) const;
48 QIcon icon(QTreeWidgetItem* theWrappedObject, int column) const;
50 QIcon icon(QTreeWidgetItem* theWrappedObject, int column) const;
49 int indexOfChild(QTreeWidgetItem* theWrappedObject, QTreeWidgetItem* child) const;
51 int indexOfChild(QTreeWidgetItem* theWrappedObject, QTreeWidgetItem* child) const;
50 void insertChild(QTreeWidgetItem* theWrappedObject, int index, QTreeWidgetItem* child);
52 void insertChild(QTreeWidgetItem* theWrappedObject, int index, QTreeWidgetItem* child);
51 void insertChildren(QTreeWidgetItem* theWrappedObject, int index, const QList<QTreeWidgetItem* >& children);
53 void insertChildren(QTreeWidgetItem* theWrappedObject, int index, const QList<QTreeWidgetItem* >& children);
52 bool isDisabled(QTreeWidgetItem* theWrappedObject) const;
54 bool isDisabled(QTreeWidgetItem* theWrappedObject) const;
53 bool isExpanded(QTreeWidgetItem* theWrappedObject) const;
55 bool isExpanded(QTreeWidgetItem* theWrappedObject) const;
54 bool isFirstColumnSpanned(QTreeWidgetItem* theWrappedObject) const;
56 bool isFirstColumnSpanned(QTreeWidgetItem* theWrappedObject) const;
55 bool isHidden(QTreeWidgetItem* theWrappedObject) const;
57 bool isHidden(QTreeWidgetItem* theWrappedObject) const;
56 bool isSelected(QTreeWidgetItem* theWrappedObject) const;
58 bool isSelected(QTreeWidgetItem* theWrappedObject) const;
57 void writeTo(QTreeWidgetItem* theWrappedObject, QDataStream& out);
59 void writeTo(QTreeWidgetItem* theWrappedObject, QDataStream& out);
58 void readFrom(QTreeWidgetItem* theWrappedObject, QDataStream& in);
60 void readFrom(QTreeWidgetItem* theWrappedObject, QDataStream& in);
59 QTreeWidgetItem* parent(QTreeWidgetItem* theWrappedObject) const;
61 QTreeWidgetItem* parent(QTreeWidgetItem* theWrappedObject) const;
60 void removeChild(QTreeWidgetItem* theWrappedObject, QTreeWidgetItem* child);
62 void removeChild(QTreeWidgetItem* theWrappedObject, QTreeWidgetItem* child);
61 void setBackground(QTreeWidgetItem* theWrappedObject, int column, const QBrush& brush);
63 void setBackground(QTreeWidgetItem* theWrappedObject, int column, const QBrush& brush);
62 void setCheckState(QTreeWidgetItem* theWrappedObject, int column, Qt::CheckState state);
64 void setCheckState(QTreeWidgetItem* theWrappedObject, int column, Qt::CheckState state);
63 void setChildIndicatorPolicy(QTreeWidgetItem* theWrappedObject, QTreeWidgetItem::ChildIndicatorPolicy policy);
65 void setChildIndicatorPolicy(QTreeWidgetItem* theWrappedObject, QTreeWidgetItem::ChildIndicatorPolicy policy);
64 void setData(QTreeWidgetItem* theWrappedObject, int column, int role, const QVariant& value);
66 void setData(QTreeWidgetItem* theWrappedObject, int column, int role, const QVariant& value);
65 void setDisabled(QTreeWidgetItem* theWrappedObject, bool disabled);
67 void setDisabled(QTreeWidgetItem* theWrappedObject, bool disabled);
66 void setExpanded(QTreeWidgetItem* theWrappedObject, bool expand);
68 void setExpanded(QTreeWidgetItem* theWrappedObject, bool expand);
67 void setFirstColumnSpanned(QTreeWidgetItem* theWrappedObject, bool span);
69 void setFirstColumnSpanned(QTreeWidgetItem* theWrappedObject, bool span);
68 void setFlags(QTreeWidgetItem* theWrappedObject, Qt::ItemFlags flags);
70 void setFlags(QTreeWidgetItem* theWrappedObject, Qt::ItemFlags flags);
69 void setFont(QTreeWidgetItem* theWrappedObject, int column, const QFont& font);
71 void setFont(QTreeWidgetItem* theWrappedObject, int column, const QFont& font);
70 void setForeground(QTreeWidgetItem* theWrappedObject, int column, const QBrush& brush);
72 void setForeground(QTreeWidgetItem* theWrappedObject, int column, const QBrush& brush);
71 void setHidden(QTreeWidgetItem* theWrappedObject, bool hide);
73 void setHidden(QTreeWidgetItem* theWrappedObject, bool hide);
72 void setIcon(QTreeWidgetItem* theWrappedObject, int column, const QIcon& icon);
74 void setIcon(QTreeWidgetItem* theWrappedObject, int column, const QIcon& icon);
73 void setSelected(QTreeWidgetItem* theWrappedObject, bool select);
75 void setSelected(QTreeWidgetItem* theWrappedObject, bool select);
74 void setSizeHint(QTreeWidgetItem* theWrappedObject, int column, const QSize& size);
76 void setSizeHint(QTreeWidgetItem* theWrappedObject, int column, const QSize& size);
75 void setStatusTip(QTreeWidgetItem* theWrappedObject, int column, const QString& statusTip);
77 void setStatusTip(QTreeWidgetItem* theWrappedObject, int column, const QString& statusTip);
76 void setText(QTreeWidgetItem* theWrappedObject, int column, const QString& text);
78 void setText(QTreeWidgetItem* theWrappedObject, int column, const QString& text);
77 void setTextAlignment(QTreeWidgetItem* theWrappedObject, int column, int alignment);
79 void setTextAlignment(QTreeWidgetItem* theWrappedObject, int column, int alignment);
78 void setToolTip(QTreeWidgetItem* theWrappedObject, int column, const QString& toolTip);
80 void setToolTip(QTreeWidgetItem* theWrappedObject, int column, const QString& toolTip);
79 void setWhatsThis(QTreeWidgetItem* theWrappedObject, int column, const QString& whatsThis);
81 void setWhatsThis(QTreeWidgetItem* theWrappedObject, int column, const QString& whatsThis);
80 QSize sizeHint(QTreeWidgetItem* theWrappedObject, int column) const;
82 QSize sizeHint(QTreeWidgetItem* theWrappedObject, int column) const;
81 void sortChildren(QTreeWidgetItem* theWrappedObject, int column, Qt::SortOrder order);
83 void sortChildren(QTreeWidgetItem* theWrappedObject, int column, Qt::SortOrder order);
82 QString statusTip(QTreeWidgetItem* theWrappedObject, int column) const;
84 QString statusTip(QTreeWidgetItem* theWrappedObject, int column) const;
83 QTreeWidgetItem* takeChild(QTreeWidgetItem* theWrappedObject, int index);
85 QTreeWidgetItem* takeChild(QTreeWidgetItem* theWrappedObject, int index);
84 QList<QTreeWidgetItem* > takeChildren(QTreeWidgetItem* theWrappedObject);
86 QList<QTreeWidgetItem* > takeChildren(QTreeWidgetItem* theWrappedObject);
85 QString text(QTreeWidgetItem* theWrappedObject, int column) const;
87 QString text(QTreeWidgetItem* theWrappedObject, int column) const;
86 int textAlignment(QTreeWidgetItem* theWrappedObject, int column) const;
88 int textAlignment(QTreeWidgetItem* theWrappedObject, int column) const;
87 QString toolTip(QTreeWidgetItem* theWrappedObject, int column) const;
89 QString toolTip(QTreeWidgetItem* theWrappedObject, int column) const;
88 QTreeWidget* treeWidget(QTreeWidgetItem* theWrappedObject) const;
90 QTreeWidget* treeWidget(QTreeWidgetItem* theWrappedObject) const;
89 int type(QTreeWidgetItem* theWrappedObject) const;
91 int type(QTreeWidgetItem* theWrappedObject) const;
90 QString whatsThis(QTreeWidgetItem* theWrappedObject, int column) const;
92 QString whatsThis(QTreeWidgetItem* theWrappedObject, int column) const;
91 };
93 };
92
94
93 #endif // PYTHONQTWRAPPER_QTREEWIDGETITEM_H
95 #endif // PYTHONQTWRAPPER_QTREEWIDGETITEM_H
@@ -1,158 +1,163
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
3 ** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
4 **
4 **
5 ** This file is part of the Qt Script Generator project on Trolltech Labs.
5 ** This file is part of the Qt Script Generator project on Trolltech Labs.
6 **
6 **
7 ** This file may be used under the terms of the GNU General Public
7 ** This file may be used under the terms of the GNU General Public
8 ** License version 2.0 as published by the Free Software Foundation
8 ** License version 2.0 as published by the Free Software Foundation
9 ** and appearing in the file LICENSE.GPL included in the packaging of
9 ** and appearing in the file LICENSE.GPL included in the packaging of
10 ** this file. Please review the following information to ensure GNU
10 ** this file. Please review the following information to ensure GNU
11 ** General Public Licensing requirements will be met:
11 ** General Public Licensing requirements will be met:
12 ** http://www.trolltech.com/products/qt/opensource.html
12 ** http://www.trolltech.com/products/qt/opensource.html
13 **
13 **
14 ** If you are unsure which license is appropriate for your use, please
14 ** If you are unsure which license is appropriate for your use, please
15 ** review the following information:
15 ** review the following information:
16 ** http://www.trolltech.com/products/qt/licensing.html or contact the
16 ** http://www.trolltech.com/products/qt/licensing.html or contact the
17 ** sales department at sales@trolltech.com.
17 ** sales department at sales@trolltech.com.
18 **
18 **
19 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
19 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
20 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
21 **
21 **
22 ****************************************************************************/
22 ****************************************************************************/
23
23
24 #include "shellheadergenerator.h"
24 #include "shellheadergenerator.h"
25 #include "fileout.h"
25 #include "fileout.h"
26 #include "classgenerator.h"
26 #include "classgenerator.h"
27
27
28 #include <QtCore/QDir>
28 #include <QtCore/QDir>
29
29
30 #include <qdebug.h>
30 #include <qdebug.h>
31
31
32 QString ShellHeaderGenerator::fileNameForClass(const AbstractMetaClass *meta_class) const
32 QString ShellHeaderGenerator::fileNameForClass(const AbstractMetaClass *meta_class) const
33 {
33 {
34 return QString("PythonQtWrapper_%1.h").arg(meta_class->name());
34 return QString("PythonQtWrapper_%1.h").arg(meta_class->name());
35 }
35 }
36
36
37 void writeQtScriptQtBindingsLicense(QTextStream &stream);
37 void writeQtScriptQtBindingsLicense(QTextStream &stream);
38
38
39 void ShellHeaderGenerator::write(QTextStream &s, const AbstractMetaClass *meta_class)
39 void ShellHeaderGenerator::write(QTextStream &s, const AbstractMetaClass *meta_class)
40 {
40 {
41
41
42 setupGenerator->addClass(meta_class);
42 setupGenerator->addClass(meta_class);
43
43
44 if (FileOut::license)
44 if (FileOut::license)
45 writeQtScriptQtBindingsLicense(s);
45 writeQtScriptQtBindingsLicense(s);
46
46
47 QString include_block = "PYTHONQTWRAPPER_" + meta_class->name().toUpper() + "_H";
47 QString include_block = "PYTHONQTWRAPPER_" + meta_class->name().toUpper() + "_H";
48
48
49 s << "#ifndef " << include_block << endl
49 s << "#ifndef " << include_block << endl
50 << "#define " << include_block << endl << endl;
50 << "#define " << include_block << endl << endl;
51
51
52 Include inc = meta_class->typeEntry()->include();
52 Include inc = meta_class->typeEntry()->include();
53 ClassGenerator::writeInclude(s, inc);
53 ClassGenerator::writeInclude(s, inc);
54
54
55 s << "#include <QObject>" << endl << endl;
55 s << "#include <QObject>" << endl << endl;
56
56
57 IncludeList list = meta_class->typeEntry()->extraIncludes();
57 IncludeList list = meta_class->typeEntry()->extraIncludes();
58 qSort(list.begin(), list.end());
58 qSort(list.begin(), list.end());
59 foreach (const Include &inc, list) {
59 foreach (const Include &inc, list) {
60 ClassGenerator::writeInclude(s, inc);
60 ClassGenerator::writeInclude(s, inc);
61 }
61 }
62 s << endl;
62 s << endl;
63
63
64 QString pro_file_name = meta_class->package().replace(".", "_") + "/" + meta_class->package().replace(".", "_") + ".pri";
64 QString pro_file_name = meta_class->package().replace(".", "_") + "/" + meta_class->package().replace(".", "_") + ".pri";
65
65
66 // if (!meta_class->generateShellClass()) {
66 // if (!meta_class->generateShellClass()) {
67 // s << "#endif" << endl << endl;
67 // s << "#endif" << endl << endl;
68 // priGenerator->addHeader(pro_file_name, fileNameForClass(meta_class));
68 // priGenerator->addHeader(pro_file_name, fileNameForClass(meta_class));
69 // return ;
69 // return ;
70 // }
70 // }
71
71
72 s << "class " << shellClassName(meta_class)
72 s << "class " << shellClassName(meta_class)
73 << " : public QObject" << endl
73 << " : public QObject" << endl
74 << "{ Q_OBJECT" << endl;
74 << "{ Q_OBJECT" << endl;
75
75
76 s << "public:" << endl;
76 s << "public:" << endl;
77
77
78 AbstractMetaEnumList enums1 = meta_class->enums();
78 AbstractMetaEnumList enums1 = meta_class->enums();
79 AbstractMetaEnumList enums;
79 AbstractMetaEnumList enums;
80 foreach(AbstractMetaEnum* enum1, enums1) {
80 foreach(AbstractMetaEnum* enum1, enums1) {
81 if (enum1->isPublic() && !enum1->hasQEnumsDeclaration()) {
81 if (enum1->isPublic() && !enum1->hasQEnumsDeclaration()) {
82 enums << enum1;
82 enums << enum1;
83 }
83 }
84 }
84 }
85 if (enums.count()) {
85 if (enums.count()) {
86 s << "Q_ENUMS(";
86 s << "Q_ENUMS(";
87 foreach(AbstractMetaEnum* enum1, enums) {
87 foreach(AbstractMetaEnum* enum1, enums) {
88 s << enum1->name() << " ";
88 s << enum1->name() << " ";
89 }
89 }
90 s << ")" << endl;
90 s << ")" << endl;
91
91
92 foreach(AbstractMetaEnum* enum1, enums) {
92 foreach(AbstractMetaEnum* enum1, enums) {
93 s << "enum " << enum1->name() << "{" << endl;
93 s << "enum " << enum1->name() << "{" << endl;
94 bool first = true;
94 bool first = true;
95 foreach(AbstractMetaEnumValue* value, enum1->values()) {
95 foreach(AbstractMetaEnumValue* value, enum1->values()) {
96 if (first) { first = false; }
96 if (first) { first = false; }
97 else { s << ", "; }
97 else { s << ", "; }
98 s << " " << value->name() << " = " << meta_class->qualifiedCppName() << "::" << value->name();
98 s << " " << value->name() << " = " << meta_class->qualifiedCppName() << "::" << value->name();
99 }
99 }
100 s << "};" << endl;
100 s << "};" << endl;
101 }
101 }
102 }
102 }
103
103
104 s << "public slots:" << endl;
104 s << "public slots:" << endl;
105 if (!meta_class->isAbstract()) {
105 if (!meta_class->isAbstract()) {
106 AbstractMetaFunctionList ctors;
106 AbstractMetaFunctionList ctors;
107 ctors = meta_class->queryFunctions(AbstractMetaClass::Constructors
107 ctors = meta_class->queryFunctions(AbstractMetaClass::Constructors
108 | AbstractMetaClass::WasVisible
108 | AbstractMetaClass::WasVisible
109 | AbstractMetaClass::NotRemovedFromTargetLang);
109 | AbstractMetaClass::NotRemovedFromTargetLang);
110
110
111 foreach (const AbstractMetaFunction *function, ctors) {
111 foreach (const AbstractMetaFunction *function, ctors) {
112 if (!function->isPublic() || function->isAbstract()) { continue; }
112 if (!function->isPublic() || function->isAbstract()) { continue; }
113 s << meta_class->qualifiedCppName() << "* ";
113 s << meta_class->qualifiedCppName() << "* ";
114 writeFunctionSignature(s, function, 0, "new_",
114 writeFunctionSignature(s, function, 0, "new_",
115 Option(IncludeDefaultExpression | OriginalName | ShowStatic));
115 Option(IncludeDefaultExpression | OriginalName | ShowStatic));
116 s << ";" << endl;
116 s << ";" << endl;
117 }
117 }
118 }
118 }
119 if (meta_class->hasPublicDestructor() && !meta_class->isNamespace()) {
119 if (meta_class->hasPublicDestructor() && !meta_class->isNamespace()) {
120 s << "void delete_" << meta_class->name() << "(" << meta_class->qualifiedCppName() << "* obj) { delete obj; } ";
120 s << "void delete_" << meta_class->name() << "(" << meta_class->qualifiedCppName() << "* obj) { delete obj; } ";
121 s << endl;
121 s << endl;
122 }
122 }
123 if (meta_class->name()=="QTreeWidgetItem") {
124 s << "bool hasOwner(QTreeWidgetItem* theWrappedObject) { return theWrappedObject->treeWidget()!=NULL || theWrappedObject->parent()!=NULL; }" << endl;
125 } else if (meta_class->name()=="QGraphicsItem") {
126 s << "bool hasOwner(QGraphicsItem* theWrappedObject) { return theWrappedObject->scene()!=NULL || theWrappedObject->parentItem()!=NULL; }" << endl;
127 }
123
128
124 AbstractMetaFunctionList functions = meta_class->queryFunctions(
129 AbstractMetaFunctionList functions = meta_class->queryFunctions(
125 AbstractMetaClass::NormalFunctions | AbstractMetaClass::WasVisible | AbstractMetaClass::WasPublic
130 AbstractMetaClass::NormalFunctions | AbstractMetaClass::WasVisible | AbstractMetaClass::WasPublic
126 | AbstractMetaClass::NotRemovedFromTargetLang | AbstractMetaClass::ClassImplements
131 | AbstractMetaClass::NotRemovedFromTargetLang | AbstractMetaClass::ClassImplements
127 );
132 );
128
133
129 foreach (const AbstractMetaFunction *function, functions) {
134 foreach (const AbstractMetaFunction *function, functions) {
130 if (!function->isSlot()) {
135 if (!function->isSlot()) {
131 s << " ";
136 s << " ";
132 writeFunctionSignature(s, function, 0, QString(),
137 writeFunctionSignature(s, function, 0, QString(),
133 Option(IncludeDefaultExpression | OriginalName | ShowStatic | UnderscoreSpaces));
138 Option(IncludeDefaultExpression | OriginalName | ShowStatic | UnderscoreSpaces));
134 s << ";" << endl;
139 s << ";" << endl;
135 }
140 }
136 }
141 }
137
142
138 // writeInjectedCode(s, meta_class);
143 // writeInjectedCode(s, meta_class);
139
144
140 // s << endl << " QScriptValue __qtscript_self;" << endl;
145 // s << endl << " QScriptValue __qtscript_self;" << endl;
141
146
142 s << "};" << endl << endl
147 s << "};" << endl << endl
143 << "#endif // " << include_block << endl;
148 << "#endif // " << include_block << endl;
144
149
145 if (!ClassGenerator::isBuiltIn(meta_class->name())) {
150 if (!ClassGenerator::isBuiltIn(meta_class->name())) {
146 priGenerator->addHeader(pro_file_name, fileNameForClass(meta_class));
151 priGenerator->addHeader(pro_file_name, fileNameForClass(meta_class));
147 }
152 }
148 }
153 }
149
154
150 void ShellHeaderGenerator::writeInjectedCode(QTextStream &s, const AbstractMetaClass *meta_class)
155 void ShellHeaderGenerator::writeInjectedCode(QTextStream &s, const AbstractMetaClass *meta_class)
151 {
156 {
152 CodeSnipList code_snips = meta_class->typeEntry()->codeSnips();
157 CodeSnipList code_snips = meta_class->typeEntry()->codeSnips();
153 foreach (const CodeSnip &cs, code_snips) {
158 foreach (const CodeSnip &cs, code_snips) {
154 if (cs.language == TypeSystem::ShellDeclaration) {
159 if (cs.language == TypeSystem::ShellDeclaration) {
155 s << cs.code() << endl;
160 s << cs.code() << endl;
156 }
161 }
157 }
162 }
158 }
163 }
@@ -1,643 +1,659
1 /*
1 /*
2 *
2 *
3 * Copyright (C) 2006 MeVis Research GmbH All Rights Reserved.
3 * Copyright (C) 2006 MeVis Research GmbH All Rights Reserved.
4 *
4 *
5 * This library is free software; you can redistribute it and/or
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
8 * version 2.1 of the License, or (at your option) any later version.
9 *
9 *
10 * This library is distributed in the hope that it will be useful,
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
13 * Lesser General Public License for more details.
14 *
14 *
15 * Further, this software is distributed without any warranty that it is
15 * Further, this software is distributed without any warranty that it is
16 * free of the rightful claim of any third person regarding infringement
16 * free of the rightful claim of any third person regarding infringement
17 * or the like. Any license provided herein, whether implied or
17 * or the like. Any license provided herein, whether implied or
18 * otherwise, applies only to this software file. Patent licenses, if
18 * otherwise, applies only to this software file. Patent licenses, if
19 * any, provided herein do not apply to combinations of this program with
19 * any, provided herein do not apply to combinations of this program with
20 * other software, or any other product whatsoever.
20 * other software, or any other product whatsoever.
21 *
21 *
22 * You should have received a copy of the GNU Lesser General Public
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this library; if not, write to the Free Software
23 * License along with this library; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 *
25 *
26 * Contact information: MeVis Research GmbH, Universitaetsallee 29,
26 * Contact information: MeVis Research GmbH, Universitaetsallee 29,
27 * 28359 Bremen, Germany or:
27 * 28359 Bremen, Germany or:
28 *
28 *
29 * http://www.mevis.de
29 * http://www.mevis.de
30 *
30 *
31 */
31 */
32
32
33 //----------------------------------------------------------------------------------
33 //----------------------------------------------------------------------------------
34 /*!
34 /*!
35 // \file PythonQt.cpp
35 // \file PythonQt.cpp
36 // \author Florian Link
36 // \author Florian Link
37 // \author Last changed by $Author: florian $
37 // \author Last changed by $Author: florian $
38 // \date 2006-05
38 // \date 2006-05
39 */
39 */
40 //----------------------------------------------------------------------------------
40 //----------------------------------------------------------------------------------
41
41
42 #include "PythonQtClassInfo.h"
42 #include "PythonQtClassInfo.h"
43 #include "PythonQtMethodInfo.h"
43 #include "PythonQtMethodInfo.h"
44 #include "PythonQt.h"
44 #include "PythonQt.h"
45 #include <QMetaMethod>
45 #include <QMetaMethod>
46
46
47 QHash<QByteArray, int> PythonQtMethodInfo::_parameterTypeDict;
47 QHash<QByteArray, int> PythonQtMethodInfo::_parameterTypeDict;
48
48
49 PythonQtClassInfo::PythonQtClassInfo(const QMetaObject* meta, const QByteArray& wrappedClassName) {
49 PythonQtClassInfo::PythonQtClassInfo(const QMetaObject* meta, const QByteArray& wrappedClassName) {
50 _meta = meta;
50 _meta = meta;
51 _wrappedClassName = wrappedClassName;
51 _wrappedClassName = wrappedClassName;
52 _constructors = NULL;
52 _constructors = NULL;
53 _parentClassInfo = NULL;
53 _parentClassInfo = NULL;
54 _parentClassInfoResolved = false;
54 _parentClassInfoResolved = false;
55 _decoratorProvider = NULL;
55 _decoratorProvider = NULL;
56 _decoratorProviderCB = NULL;
56 _decoratorProviderCB = NULL;
57 if (wrappedClassName.isEmpty()) {
57 if (wrappedClassName.isEmpty()) {
58 _metaTypeId = -1;
58 _metaTypeId = -1;
59 } else {
59 } else {
60 _metaTypeId = QMetaType::type(wrappedClassName);
60 _metaTypeId = QMetaType::type(wrappedClassName);
61 }
61 }
62 }
62 }
63
63
64 PythonQtClassInfo::~PythonQtClassInfo()
64 PythonQtClassInfo::~PythonQtClassInfo()
65 {
65 {
66 clearCachedMembers();
66 clearCachedMembers();
67 }
67 }
68
68
69 void PythonQtClassInfo::clearCachedMembers()
69 void PythonQtClassInfo::clearCachedMembers()
70 {
70 {
71 QHashIterator<QByteArray, PythonQtMemberInfo> i(_cachedMembers);
71 QHashIterator<QByteArray, PythonQtMemberInfo> i(_cachedMembers);
72 while (i.hasNext()) {
72 while (i.hasNext()) {
73 PythonQtMemberInfo member = i.next().value();
73 PythonQtMemberInfo member = i.next().value();
74 if (member._type== PythonQtMemberInfo::Slot) {
74 if (member._type== PythonQtMemberInfo::Slot) {
75 PythonQtSlotInfo* info = member._slot;
75 PythonQtSlotInfo* info = member._slot;
76 while (info) {
76 while (info) {
77 PythonQtSlotInfo* next = info->nextInfo();
77 PythonQtSlotInfo* next = info->nextInfo();
78 delete info;
78 delete info;
79 info = next;
79 info = next;
80 }
80 }
81 }
81 }
82 }
82 }
83 }
83 }
84
84
85 void PythonQtClassInfo::resolveParentClassInfo()
85 void PythonQtClassInfo::resolveParentClassInfo()
86 {
86 {
87 if (!_parentClassInfoResolved) {
87 if (!_parentClassInfoResolved) {
88 _parentClassInfoResolved = true;
88 _parentClassInfoResolved = true;
89 if (isCPPWrapper()) {
89 if (isCPPWrapper()) {
90 if (!_wrappedClassName.isEmpty()) {
90 if (!_wrappedClassName.isEmpty()) {
91 _parentClassInfo = PythonQt::priv()->getClassInfo(_wrappedParentClassName);
91 _parentClassInfo = PythonQt::priv()->getClassInfo(_wrappedParentClassName);
92 }
92 }
93 } else {
93 } else {
94 if (_meta->superClass()) {
94 if (_meta->superClass()) {
95 _parentClassInfo = PythonQt::priv()->getClassInfo(_meta->superClass());
95 _parentClassInfo = PythonQt::priv()->getClassInfo(_meta->superClass());
96 }
96 }
97 }
97 }
98 }
98 }
99 }
99 }
100
100
101 int PythonQtClassInfo::findCharOffset(const char* sigStart, char someChar)
101 int PythonQtClassInfo::findCharOffset(const char* sigStart, char someChar)
102 {
102 {
103 const char* sigEnd = sigStart;
103 const char* sigEnd = sigStart;
104 char c;
104 char c;
105 do {
105 do {
106 c = *sigEnd++;
106 c = *sigEnd++;
107 } while (c!=someChar && c!=0);
107 } while (c!=someChar && c!=0);
108 return sigEnd-sigStart-1;
108 return sigEnd-sigStart-1;
109 }
109 }
110
110
111 bool PythonQtClassInfo::lookForPropertyAndCache(const char* memberName)
111 bool PythonQtClassInfo::lookForPropertyAndCache(const char* memberName)
112 {
112 {
113 bool found = false;
113 bool found = false;
114 bool nameMapped = false;
114 bool nameMapped = false;
115 const char* attributeName = memberName;
115 const char* attributeName = memberName;
116 // look for properties
116 // look for properties
117 int i = _meta->indexOfProperty(attributeName);
117 int i = _meta->indexOfProperty(attributeName);
118 if (i==-1) {
118 if (i==-1) {
119 // try to map name to objectName
119 // try to map name to objectName
120 if (qstrcmp(attributeName, "name")==0) {
120 if (qstrcmp(attributeName, "name")==0) {
121 attributeName = "objectName";
121 attributeName = "objectName";
122 nameMapped = true;
122 nameMapped = true;
123 i = _meta->indexOfProperty(attributeName);
123 i = _meta->indexOfProperty(attributeName);
124 }
124 }
125 }
125 }
126 if (i!=-1) {
126 if (i!=-1) {
127 PythonQtMemberInfo newInfo(_meta->property(i));
127 PythonQtMemberInfo newInfo(_meta->property(i));
128 _cachedMembers.insert(attributeName, newInfo);
128 _cachedMembers.insert(attributeName, newInfo);
129 if (nameMapped) {
129 if (nameMapped) {
130 _cachedMembers.insert(memberName, newInfo);
130 _cachedMembers.insert(memberName, newInfo);
131 }
131 }
132 #ifdef PYTHONQT_DEBUG
132 #ifdef PYTHONQT_DEBUG
133 std::cout << "caching property " << memberName << " on " << _meta->className() << std::endl;
133 std::cout << "caching property " << memberName << " on " << _meta->className() << std::endl;
134 #endif
134 #endif
135 found = true;
135 found = true;
136 }
136 }
137 return found;
137 return found;
138 }
138 }
139
139
140 PythonQtSlotInfo* PythonQtClassInfo::findDecoratorSlotsFromDecoratorProvider(const char* memberName, PythonQtSlotInfo* tail, bool &found, QHash<QByteArray, PythonQtMemberInfo>& memberCache) {
140 PythonQtSlotInfo* PythonQtClassInfo::findDecoratorSlotsFromDecoratorProvider(const char* memberName, PythonQtSlotInfo* tail, bool &found, QHash<QByteArray, PythonQtMemberInfo>& memberCache) {
141 QObject* decoratorProvider = decorator();
141 QObject* decoratorProvider = decorator();
142 if (decoratorProvider) {
142 if (decoratorProvider) {
143 const QMetaObject* meta = decoratorProvider->metaObject();
143 const QMetaObject* meta = decoratorProvider->metaObject();
144 int memberNameLen = strlen(memberName);
144 int memberNameLen = strlen(memberName);
145 int numMethods = meta->methodCount();
145 int numMethods = meta->methodCount();
146 int startFrom = QObject::staticMetaObject.methodCount();
146 int startFrom = QObject::staticMetaObject.methodCount();
147 for (int i = startFrom; i < numMethods; i++) {
147 for (int i = startFrom; i < numMethods; i++) {
148 QMetaMethod m = meta->method(i);
148 QMetaMethod m = meta->method(i);
149 if ((m.methodType() == QMetaMethod::Method ||
149 if ((m.methodType() == QMetaMethod::Method ||
150 m.methodType() == QMetaMethod::Slot) && m.access() == QMetaMethod::Public) {
150 m.methodType() == QMetaMethod::Slot) && m.access() == QMetaMethod::Public) {
151
151
152 const char* sigStart = m.signature();
152 const char* sigStart = m.signature();
153 bool isClassDeco = false;
153 bool isClassDeco = false;
154 if (qstrncmp(sigStart, "static_", 7)==0) {
154 if (qstrncmp(sigStart, "static_", 7)==0) {
155 // skip the static_classname_ part of the string
155 // skip the static_classname_ part of the string
156 sigStart += 7 + 1 + strlen(className());
156 sigStart += 7 + 1 + strlen(className());
157 isClassDeco = true;
157 isClassDeco = true;
158 } else if (qstrncmp(sigStart, "new_", 4)==0) {
158 } else if (qstrncmp(sigStart, "new_", 4)==0) {
159 isClassDeco = true;
159 isClassDeco = true;
160 } else if (qstrncmp(sigStart, "delete_", 7)==0) {
160 } else if (qstrncmp(sigStart, "delete_", 7)==0) {
161 isClassDeco = true;
161 isClassDeco = true;
162 }
162 }
163 // find the first '('
163 // find the first '('
164 int offset = findCharOffset(sigStart, '(');
164 int offset = findCharOffset(sigStart, '(');
165
165
166 // XXX no checking is currently done if the slots have correct first argument or not...
166 // XXX no checking is currently done if the slots have correct first argument or not...
167
167
168 // check if same length and same name
168 // check if same length and same name
169 if (memberNameLen == offset && qstrncmp(memberName, sigStart, offset)==0) {
169 if (memberNameLen == offset && qstrncmp(memberName, sigStart, offset)==0) {
170 found = true;
170 found = true;
171 PythonQtSlotInfo* info = new PythonQtSlotInfo(m, i, decoratorProvider, isClassDeco?PythonQtSlotInfo::ClassDecorator:PythonQtSlotInfo::InstanceDecorator);
171 PythonQtSlotInfo* info = new PythonQtSlotInfo(m, i, decoratorProvider, isClassDeco?PythonQtSlotInfo::ClassDecorator:PythonQtSlotInfo::InstanceDecorator);
172 if (tail) {
172 if (tail) {
173 tail->setNextInfo(info);
173 tail->setNextInfo(info);
174 } else {
174 } else {
175 PythonQtMemberInfo newInfo(info);
175 PythonQtMemberInfo newInfo(info);
176 memberCache.insert(memberName, newInfo);
176 memberCache.insert(memberName, newInfo);
177 }
177 }
178 tail = info;
178 tail = info;
179 }
179 }
180 }
180 }
181 }
181 }
182 }
182 }
183 return tail;
183 return tail;
184 }
184 }
185
185
186 bool PythonQtClassInfo::lookForMethodAndCache(const char* memberName)
186 bool PythonQtClassInfo::lookForMethodAndCache(const char* memberName)
187 {
187 {
188 bool found = false;
188 bool found = false;
189 int memberNameLen = strlen(memberName);
189 int memberNameLen = strlen(memberName);
190 PythonQtSlotInfo* tail = NULL;
190 PythonQtSlotInfo* tail = NULL;
191 if (_meta) {
191 if (_meta) {
192 int numMethods = _meta->methodCount();
192 int numMethods = _meta->methodCount();
193 for (int i = 0; i < numMethods; i++) {
193 for (int i = 0; i < numMethods; i++) {
194 QMetaMethod m = _meta->method(i);
194 QMetaMethod m = _meta->method(i);
195 if ((m.methodType() == QMetaMethod::Method ||
195 if ((m.methodType() == QMetaMethod::Method ||
196 m.methodType() == QMetaMethod::Slot) && m.access() == QMetaMethod::Public) {
196 m.methodType() == QMetaMethod::Slot) && m.access() == QMetaMethod::Public) {
197
197
198 const char* sigStart = m.signature();
198 const char* sigStart = m.signature();
199 // find the first '('
199 // find the first '('
200 int offset = findCharOffset(sigStart, '(');
200 int offset = findCharOffset(sigStart, '(');
201
201
202 // check if same length and same name
202 // check if same length and same name
203 if (memberNameLen == offset && qstrncmp(memberName, sigStart, offset)==0) {
203 if (memberNameLen == offset && qstrncmp(memberName, sigStart, offset)==0) {
204 found = true;
204 found = true;
205 PythonQtSlotInfo* info = new PythonQtSlotInfo(m, i);
205 PythonQtSlotInfo* info = new PythonQtSlotInfo(m, i);
206 if (tail) {
206 if (tail) {
207 tail->setNextInfo(info);
207 tail->setNextInfo(info);
208 } else {
208 } else {
209 PythonQtMemberInfo newInfo(info);
209 PythonQtMemberInfo newInfo(info);
210 _cachedMembers.insert(memberName, newInfo);
210 _cachedMembers.insert(memberName, newInfo);
211 }
211 }
212 tail = info;
212 tail = info;
213 }
213 }
214 }
214 }
215 }
215 }
216 }
216 }
217
217
218 // look for dynamic decorators in this class and in derived classes
218 // look for dynamic decorators in this class and in derived classes
219 PythonQtClassInfo* info = this;
219 PythonQtClassInfo* info = this;
220 while (info) {
220 while (info) {
221 tail = info->findDecoratorSlotsFromDecoratorProvider(memberName, tail, found, _cachedMembers);
221 tail = info->findDecoratorSlotsFromDecoratorProvider(memberName, tail, found, _cachedMembers);
222 if (!info->_parentClassInfoResolved) {
222 if (!info->_parentClassInfoResolved) {
223 info->resolveParentClassInfo();
223 info->resolveParentClassInfo();
224 }
224 }
225 info = info->_parentClassInfo;
225 info = info->_parentClassInfo;
226 }
226 }
227
227
228 // look for decorators
228 // look for decorators
229 if (!_wrappedClassName.isEmpty()) {
229 if (!_wrappedClassName.isEmpty()) {
230 tail = findDecoratorSlots(_wrappedClassName.constData(), memberName, memberNameLen, tail, found);
230 tail = findDecoratorSlots(_wrappedClassName.constData(), memberName, memberNameLen, tail, found);
231 }
231 }
232
232
233 const QMetaObject* meta = _meta;
233 const QMetaObject* meta = _meta;
234 while (meta) {
234 while (meta) {
235 tail = findDecoratorSlots(meta->className(), memberName, memberNameLen, tail, found);
235 tail = findDecoratorSlots(meta->className(), memberName, memberNameLen, tail, found);
236 meta = meta->superClass();
236 meta = meta->superClass();
237 }
237 }
238 return found;
238 return found;
239 }
239 }
240
240
241 bool PythonQtClassInfo::lookForEnumAndCache(const QMetaObject* meta, const char* memberName)
241 bool PythonQtClassInfo::lookForEnumAndCache(const QMetaObject* meta, const char* memberName)
242 {
242 {
243 bool found = false;
243 bool found = false;
244 // look for enum values
244 // look for enum values
245 int enumCount = meta->enumeratorCount();
245 int enumCount = meta->enumeratorCount();
246 for (int i=0;i<enumCount; i++) {
246 for (int i=0;i<enumCount; i++) {
247 QMetaEnum e = meta->enumerator(i);
247 QMetaEnum e = meta->enumerator(i);
248 for (int j=0; j < e.keyCount(); j++) {
248 for (int j=0; j < e.keyCount(); j++) {
249 if (qstrcmp(e.key(j), memberName)==0) {
249 if (qstrcmp(e.key(j), memberName)==0) {
250 PythonQtMemberInfo newInfo(e.value(j));
250 PythonQtMemberInfo newInfo(e.value(j));
251 _cachedMembers.insert(memberName, newInfo);
251 _cachedMembers.insert(memberName, newInfo);
252 #ifdef PYTHONQT_DEBUG
252 #ifdef PYTHONQT_DEBUG
253 std::cout << "caching enum " << memberName << " on " << meta->className() << std::endl;
253 std::cout << "caching enum " << memberName << " on " << meta->className() << std::endl;
254 #endif
254 #endif
255 found = true;
255 found = true;
256 }
256 }
257 }
257 }
258 }
258 }
259 return found;
259 return found;
260 }
260 }
261
261
262 PythonQtMemberInfo PythonQtClassInfo::member(const char* memberName)
262 PythonQtMemberInfo PythonQtClassInfo::member(const char* memberName)
263 {
263 {
264 PythonQtMemberInfo info = _cachedMembers.value(memberName);
264 PythonQtMemberInfo info = _cachedMembers.value(memberName);
265 if (info._type != PythonQtMemberInfo::Invalid) {
265 if (info._type != PythonQtMemberInfo::Invalid) {
266 return info;
266 return info;
267 } else {
267 } else {
268 bool found = false;
268 bool found = false;
269
269
270 found = lookForPropertyAndCache(memberName);
270 found = lookForPropertyAndCache(memberName);
271 if (!found) {
271 if (!found) {
272 found = lookForMethodAndCache(memberName);
272 found = lookForMethodAndCache(memberName);
273 }
273 }
274 if (!found) {
274 if (!found) {
275 if (_meta) {
275 if (_meta) {
276 // check enums in our meta object directly
276 // check enums in our meta object directly
277 found = lookForEnumAndCache(_meta, memberName);
277 found = lookForEnumAndCache(_meta, memberName);
278 }
278 }
279 if (!found) {
279 if (!found) {
280 // check enums in the class hierachy of CPP classes
280 // check enums in the class hierachy of CPP classes
281 // look for dynamic decorators in this class and in derived classes
281 // look for dynamic decorators in this class and in derived classes
282 PythonQtClassInfo* info = this;
282 PythonQtClassInfo* info = this;
283 while (info && !found) {
283 while (info && !found) {
284 QObject* deco = info->decorator();
284 QObject* deco = info->decorator();
285 if (deco) {
285 if (deco) {
286 // call on ourself for caching, but with different metaObject():
286 // call on ourself for caching, but with different metaObject():
287 found = lookForEnumAndCache(deco->metaObject(), memberName);
287 found = lookForEnumAndCache(deco->metaObject(), memberName);
288 }
288 }
289 if (!info->_parentClassInfoResolved) {
289 if (!info->_parentClassInfoResolved) {
290 info->resolveParentClassInfo();
290 info->resolveParentClassInfo();
291 }
291 }
292 info = info->_parentClassInfo;
292 info = info->_parentClassInfo;
293 }
293 }
294 }
294 }
295 }
295 }
296 if (!found) {
296 if (!found) {
297 // we store a NotFound member, so that we get a quick result for non existing members (e.g. operator_equal lookup)
297 // we store a NotFound member, so that we get a quick result for non existing members (e.g. operator_equal lookup)
298 info._type = PythonQtMemberInfo::NotFound;
298 info._type = PythonQtMemberInfo::NotFound;
299 _cachedMembers.insert(memberName, info);
299 _cachedMembers.insert(memberName, info);
300 }
300 }
301 }
301 }
302
302
303 return _cachedMembers.value(memberName);
303 return _cachedMembers.value(memberName);
304 }
304 }
305
305
306 PythonQtSlotInfo* PythonQtClassInfo::findDecoratorSlots(const char* classname, const char* memberName, int memberNameLen, PythonQtSlotInfo* tail, bool& found)
306 PythonQtSlotInfo* PythonQtClassInfo::findDecoratorSlots(const char* classname, const char* memberName, int memberNameLen, PythonQtSlotInfo* tail, bool& found)
307 {
307 {
308 QListIterator<PythonQtSlotInfo*> it(PythonQt::priv()->getDecoratorSlots(classname));
308 QListIterator<PythonQtSlotInfo*> it(PythonQt::priv()->getDecoratorSlots(classname));
309 while (it.hasNext()) {
309 while (it.hasNext()) {
310
310
311 PythonQtSlotInfo* infoOrig = it.next();
311 PythonQtSlotInfo* infoOrig = it.next();
312
312
313 const char* sigStart = infoOrig->metaMethod()->signature();
313 const char* sigStart = infoOrig->metaMethod()->signature();
314 if (qstrncmp("static_", sigStart, 7)==0) {
314 if (qstrncmp("static_", sigStart, 7)==0) {
315 sigStart += 7;
315 sigStart += 7;
316 sigStart += findCharOffset(sigStart, '_')+1;
316 sigStart += findCharOffset(sigStart, '_')+1;
317 }
317 }
318 int offset = findCharOffset(sigStart, '(');
318 int offset = findCharOffset(sigStart, '(');
319 if (memberNameLen == offset && qstrncmp(memberName, sigStart, offset)==0) {
319 if (memberNameLen == offset && qstrncmp(memberName, sigStart, offset)==0) {
320 //make a copy, otherwise we will have trouble on overloads!
320 //make a copy, otherwise we will have trouble on overloads!
321 PythonQtSlotInfo* info = new PythonQtSlotInfo(*infoOrig);
321 PythonQtSlotInfo* info = new PythonQtSlotInfo(*infoOrig);
322 found = true;
322 found = true;
323 if (tail) {
323 if (tail) {
324 tail->setNextInfo(info);
324 tail->setNextInfo(info);
325 } else {
325 } else {
326 PythonQtMemberInfo newInfo(info);
326 PythonQtMemberInfo newInfo(info);
327 _cachedMembers.insert(memberName, newInfo);
327 _cachedMembers.insert(memberName, newInfo);
328 }
328 }
329 tail = info;
329 tail = info;
330 }
330 }
331 }
331 }
332 return tail;
332 return tail;
333 }
333 }
334
334
335 void PythonQtClassInfo::listDecoratorSlotsFromDecoratorProvider(QStringList& list, bool metaOnly) {
335 void PythonQtClassInfo::listDecoratorSlotsFromDecoratorProvider(QStringList& list, bool metaOnly) {
336 QObject* decoratorProvider = decorator();
336 QObject* decoratorProvider = decorator();
337 if (decoratorProvider) {
337 if (decoratorProvider) {
338 const QMetaObject* meta = decoratorProvider->metaObject();
338 const QMetaObject* meta = decoratorProvider->metaObject();
339 int numMethods = meta->methodCount();
339 int numMethods = meta->methodCount();
340 int startFrom = QObject::staticMetaObject.methodCount();
340 int startFrom = QObject::staticMetaObject.methodCount();
341 for (int i = startFrom; i < numMethods; i++) {
341 for (int i = startFrom; i < numMethods; i++) {
342 QMetaMethod m = meta->method(i);
342 QMetaMethod m = meta->method(i);
343 if ((m.methodType() == QMetaMethod::Method ||
343 if ((m.methodType() == QMetaMethod::Method ||
344 m.methodType() == QMetaMethod::Slot) && m.access() == QMetaMethod::Public) {
344 m.methodType() == QMetaMethod::Slot) && m.access() == QMetaMethod::Public) {
345
345
346 const char* sigStart = m.signature();
346 const char* sigStart = m.signature();
347 bool isClassDeco = false;
347 bool isClassDeco = false;
348 if (qstrncmp(sigStart, "static_", 7)==0) {
348 if (qstrncmp(sigStart, "static_", 7)==0) {
349 // skip the static_classname_ part of the string
349 // skip the static_classname_ part of the string
350 sigStart += 7 + 1 + strlen(className());
350 sigStart += 7 + 1 + strlen(className());
351 isClassDeco = true;
351 isClassDeco = true;
352 } else if (qstrncmp(sigStart, "new_", 4)==0) {
352 } else if (qstrncmp(sigStart, "new_", 4)==0) {
353 sigStart += 4 + 1 + strlen(className());
353 sigStart += 4 + 1 + strlen(className());
354 isClassDeco = true;
354 isClassDeco = true;
355 } else if (qstrncmp(sigStart, "delete_", 7)==0) {
355 } else if (qstrncmp(sigStart, "delete_", 7)==0) {
356 sigStart += 7 + 1 + strlen(className());
356 sigStart += 7 + 1 + strlen(className());
357 isClassDeco = true;
357 isClassDeco = true;
358 }
358 }
359 // find the first '('
359 // find the first '('
360 int offset = findCharOffset(sigStart, '(');
360 int offset = findCharOffset(sigStart, '(');
361
361
362 // XXX no checking is currently done if the slots have correct first argument or not...
362 // XXX no checking is currently done if the slots have correct first argument or not...
363 if (!metaOnly || isClassDeco) {
363 if (!metaOnly || isClassDeco) {
364 list << QString::fromLatin1(sigStart, offset);
364 list << QString::fromLatin1(sigStart, offset);
365 }
365 }
366 }
366 }
367 }
367 }
368 }
368 }
369 }
369 }
370
370
371 QStringList PythonQtClassInfo::memberList(bool metaOnly)
371 QStringList PythonQtClassInfo::memberList(bool metaOnly)
372 {
372 {
373 resolveParentClassInfo();
373 resolveParentClassInfo();
374 decorator();
374 decorator();
375
375
376 QStringList l;
376 QStringList l;
377 QString h;
377 QString h;
378 if (_wrappedClassName.isEmpty() && _meta) {
378 if (_wrappedClassName.isEmpty() && _meta) {
379 int i;
379 int i;
380 int numProperties = _meta->propertyCount();
380 int numProperties = _meta->propertyCount();
381 for (i = 0; i < numProperties; i++) {
381 for (i = 0; i < numProperties; i++) {
382 QMetaProperty p = _meta->property(i);
382 QMetaProperty p = _meta->property(i);
383 l << QString(p.name());
383 l << QString(p.name());
384 }
384 }
385 }
385 }
386
386
387 // normal slots of QObject (or wrapper QObject)
387 // normal slots of QObject (or wrapper QObject)
388 if (!metaOnly && _meta) {
388 if (!metaOnly && _meta) {
389 int numMethods = _meta->methodCount();
389 int numMethods = _meta->methodCount();
390 bool skipQObj = !_wrappedClassName.isEmpty();
390 bool skipQObj = !_wrappedClassName.isEmpty();
391 for (int i = skipQObj?QObject::staticMetaObject.methodCount():0; i < numMethods; i++) {
391 for (int i = skipQObj?QObject::staticMetaObject.methodCount():0; i < numMethods; i++) {
392 QMetaMethod m = _meta->method(i);
392 QMetaMethod m = _meta->method(i);
393 if ((m.methodType() == QMetaMethod::Method ||
393 if ((m.methodType() == QMetaMethod::Method ||
394 m.methodType() == QMetaMethod::Slot) && m.access() == QMetaMethod::Public) {
394 m.methodType() == QMetaMethod::Slot) && m.access() == QMetaMethod::Public) {
395 QByteArray signa(m.signature());
395 QByteArray signa(m.signature());
396 if (signa.startsWith("new_")) continue;
396 if (signa.startsWith("new_")) continue;
397 if (signa.startsWith("delete_")) continue;
397 if (signa.startsWith("delete_")) continue;
398 if (signa.startsWith("static_")) continue;
398 if (signa.startsWith("static_")) continue;
399 PythonQtSlotInfo slot(m, i);
399 PythonQtSlotInfo slot(m, i);
400 l << slot.slotName();
400 l << slot.slotName();
401 }
401 }
402 }
402 }
403 }
403 }
404
404
405 {
405 {
406 // look for dynamic decorators in this class and in derived classes
406 // look for dynamic decorators in this class and in derived classes
407 PythonQtClassInfo* info = this;
407 PythonQtClassInfo* info = this;
408 while (info) {
408 while (info) {
409 info->listDecoratorSlotsFromDecoratorProvider(l, metaOnly);
409 info->listDecoratorSlotsFromDecoratorProvider(l, metaOnly);
410 if (!info->_parentClassInfoResolved) {
410 if (!info->_parentClassInfoResolved) {
411 info->resolveParentClassInfo();
411 info->resolveParentClassInfo();
412 }
412 }
413 info = info->_parentClassInfo;
413 info = info->_parentClassInfo;
414 }
414 }
415 }
415 }
416
416
417 // look for decorators
417 // look for decorators
418 QList<const char*> names;
418 QList<const char*> names;
419 if (!_wrappedClassName.isEmpty()) {
419 if (!_wrappedClassName.isEmpty()) {
420 // CPP wrapper case:
420 // CPP wrapper case:
421 names << _wrappedClassName.constData();
421 names << _wrappedClassName.constData();
422 // for CPP classes which are wrapped, we do not want to look for decorators of the wrapping qobjects, since they
422 // for CPP classes which are wrapped, we do not want to look for decorators of the wrapping qobjects, since they
423 // would require a different pointer on the decorator slot call
423 // would require a different pointer on the decorator slot call
424 } else {
424 } else {
425 // QObject case:
425 // QObject case:
426 const QMetaObject* meta = _meta;
426 const QMetaObject* meta = _meta;
427 while (meta) {
427 while (meta) {
428 if (meta==&QObject::staticMetaObject && !_wrappedClassName.isEmpty()) break;
428 if (meta==&QObject::staticMetaObject && !_wrappedClassName.isEmpty()) break;
429 names << meta->className();
429 names << meta->className();
430 meta = meta->superClass();
430 meta = meta->superClass();
431 }
431 }
432 }
432 }
433
433
434 QListIterator<const char*> nameIt(names);
434 QListIterator<const char*> nameIt(names);
435 while (nameIt.hasNext()) {
435 while (nameIt.hasNext()) {
436 QListIterator<PythonQtSlotInfo*> it(PythonQt::priv()->getDecoratorSlots(nameIt.next()));
436 QListIterator<PythonQtSlotInfo*> it(PythonQt::priv()->getDecoratorSlots(nameIt.next()));
437 while (it.hasNext()) {
437 while (it.hasNext()) {
438 PythonQtSlotInfo* slot = it.next();
438 PythonQtSlotInfo* slot = it.next();
439 if (metaOnly) {
439 if (metaOnly) {
440 if (slot->isClassDecorator()) {
440 if (slot->isClassDecorator()) {
441 QByteArray first = slot->slotName();
441 QByteArray first = slot->slotName();
442 if (first.startsWith("static_")) {
442 if (first.startsWith("static_")) {
443 int idx = first.indexOf('_');
443 int idx = first.indexOf('_');
444 idx = first.indexOf('_', idx+1);
444 idx = first.indexOf('_', idx+1);
445 first = first.mid(idx+1);
445 first = first.mid(idx+1);
446 }
446 }
447 l << first;
447 l << first;
448 }
448 }
449 } else {
449 } else {
450 l << slot->slotName();
450 l << slot->slotName();
451 }
451 }
452 }
452 }
453 }
453 }
454
454
455 // List enumerator keys...
455 // List enumerator keys...
456 QList<const QMetaObject*> enumMetaObjects;
456 QList<const QMetaObject*> enumMetaObjects;
457 if (_meta) {
457 if (_meta) {
458 enumMetaObjects << _meta;
458 enumMetaObjects << _meta;
459 }
459 }
460 // check enums in the class hierachy of CPP classes
460 // check enums in the class hierachy of CPP classes
461 PythonQtClassInfo* info = this;
461 PythonQtClassInfo* info = this;
462 while (info) {
462 while (info) {
463 QObject* deco = info->decorator();
463 QObject* deco = info->decorator();
464 if (deco) {
464 if (deco) {
465 enumMetaObjects << deco->metaObject();
465 enumMetaObjects << deco->metaObject();
466 }
466 }
467 if (!info->_parentClassInfoResolved) {
467 if (!info->_parentClassInfoResolved) {
468 info->resolveParentClassInfo();
468 info->resolveParentClassInfo();
469 }
469 }
470 info = info->_parentClassInfo;
470 info = info->_parentClassInfo;
471 }
471 }
472
472
473 foreach(const QMetaObject* meta, enumMetaObjects) {
473 foreach(const QMetaObject* meta, enumMetaObjects) {
474 for (int i = 0; i<meta->enumeratorCount(); i++) {
474 for (int i = 0; i<meta->enumeratorCount(); i++) {
475 QMetaEnum e = meta->enumerator(i);
475 QMetaEnum e = meta->enumerator(i);
476 for (int j=0; j < e.keyCount(); j++) {
476 for (int j=0; j < e.keyCount(); j++) {
477 l << QString(e.key(j));
477 l << QString(e.key(j));
478 }
478 }
479 }
479 }
480 }
480 }
481 return l;
481 return l;
482 }
482 }
483
483
484 const char* PythonQtClassInfo::className()
484 const char* PythonQtClassInfo::className()
485 {
485 {
486 if (!_wrappedClassName.isEmpty()) {
486 if (!_wrappedClassName.isEmpty()) {
487 return _wrappedClassName.constData();
487 return _wrappedClassName.constData();
488 } else {
488 } else {
489 return _meta->className();
489 return _meta->className();
490 }
490 }
491 }
491 }
492
492
493 bool PythonQtClassInfo::inherits(const char* name)
493 bool PythonQtClassInfo::inherits(const char* name)
494 {
494 {
495 resolveParentClassInfo();
495 resolveParentClassInfo();
496 if (isCPPWrapper()) {
496 if (isCPPWrapper()) {
497 PythonQtClassInfo* info = this;
497 PythonQtClassInfo* info = this;
498 while (info) {
498 while (info) {
499 if (_wrappedClassName == name) {
499 if (_wrappedClassName == name) {
500 return true;
500 return true;
501 }
501 }
502 if (!info->_parentClassInfoResolved) {
502 if (!info->_parentClassInfoResolved) {
503 info->resolveParentClassInfo();
503 info->resolveParentClassInfo();
504 }
504 }
505 info = info->_parentClassInfo;
505 info = info->_parentClassInfo;
506 }
506 }
507 } else {
507 } else {
508 const QMetaObject* m = _meta;
508 const QMetaObject* m = _meta;
509 while (m) {
509 while (m) {
510 if (strcmp(name, m->className())==0) {
510 if (strcmp(name, m->className())==0) {
511 return true;
511 return true;
512 }
512 }
513 m = m->superClass();
513 m = m->superClass();
514 }
514 }
515 }
515 }
516 return false;
516 return false;
517 }
517 }
518
518
519 QString PythonQtClassInfo::help()
519 QString PythonQtClassInfo::help()
520 {
520 {
521 resolveParentClassInfo();
521 resolveParentClassInfo();
522 decorator();
522 decorator();
523 QString h;
523 QString h;
524 h += QString("--- ") + QString(className()) + QString(" ---\n");
524 h += QString("--- ") + QString(className()) + QString(" ---\n");
525
525
526 if (_wrappedClassName.isEmpty()) {
526 if (_wrappedClassName.isEmpty()) {
527 h += "Properties:\n";
527 h += "Properties:\n";
528
528
529 int i;
529 int i;
530 int numProperties = _meta->propertyCount();
530 int numProperties = _meta->propertyCount();
531 for (i = 0; i < numProperties; i++) {
531 for (i = 0; i < numProperties; i++) {
532 QMetaProperty p = _meta->property(i);
532 QMetaProperty p = _meta->property(i);
533 h += QString(p.name()) + " (" + QString(p.typeName()) + " )\n";
533 h += QString(p.name()) + " (" + QString(p.typeName()) + " )\n";
534 }
534 }
535 }
535 }
536
536
537 if (constructors()) {
537 if (constructors()) {
538 h += "Constructors:\n";
538 h += "Constructors:\n";
539 PythonQtSlotInfo* constr = constructors();
539 PythonQtSlotInfo* constr = constructors();
540 while (constr) {
540 while (constr) {
541 h += constr->fullSignature(false) + "\n";
541 h += constr->fullSignature(false) + "\n";
542 constr = constr->nextInfo();
542 constr = constr->nextInfo();
543 }
543 }
544 }
544 }
545
545
546 h += "Slots:\n";
546 h += "Slots:\n";
547 h += "QString help()\n";
547 h += "QString help()\n";
548 h += "QString className()\n";
548 h += "QString className()\n";
549
549
550 if (_meta) {
550 if (_meta) {
551 int numMethods = _meta->methodCount();
551 int numMethods = _meta->methodCount();
552 for (int i = 0; i < numMethods; i++) {
552 for (int i = 0; i < numMethods; i++) {
553 QMetaMethod m = _meta->method(i);
553 QMetaMethod m = _meta->method(i);
554 if ((m.methodType() == QMetaMethod::Method ||
554 if ((m.methodType() == QMetaMethod::Method ||
555 m.methodType() == QMetaMethod::Slot) && m.access() == QMetaMethod::Public) {
555 m.methodType() == QMetaMethod::Slot) && m.access() == QMetaMethod::Public) {
556 QByteArray signa(m.signature());
556 QByteArray signa(m.signature());
557 if (signa.startsWith("new_")) continue;
557 if (signa.startsWith("new_")) continue;
558 if (signa.startsWith("delete_")) continue;
558 if (signa.startsWith("delete_")) continue;
559 if (signa.startsWith("static_")) continue;
559 if (signa.startsWith("static_")) continue;
560 PythonQtSlotInfo slot(m, i);
560 PythonQtSlotInfo slot(m, i);
561 h += slot.fullSignature(false)+ "\n";
561 h += slot.fullSignature(false)+ "\n";
562 }
562 }
563 }
563 }
564 }
564 }
565
565
566 // TODO xxx : decorators and enums from decorator() are missing...
566 // TODO xxx : decorators and enums from decorator() are missing...
567 // maybe we can reuse memberlist()?
567 // maybe we can reuse memberlist()?
568
568
569 // look for decorators
569 // look for decorators
570 QList<const char*> names;
570 QList<const char*> names;
571 if (!_wrappedClassName.isEmpty()) {
571 if (!_wrappedClassName.isEmpty()) {
572 names << _wrappedClassName.constData();
572 names << _wrappedClassName.constData();
573 }
573 }
574 const QMetaObject* meta = _meta;
574 const QMetaObject* meta = _meta;
575 while (meta) {
575 while (meta) {
576 names << meta->className();
576 names << meta->className();
577 meta = meta->superClass();
577 meta = meta->superClass();
578 }
578 }
579
579
580 QListIterator<const char*> nameIt(names);
580 QListIterator<const char*> nameIt(names);
581 while (nameIt.hasNext()) {
581 while (nameIt.hasNext()) {
582 QListIterator<PythonQtSlotInfo*> it(PythonQt::priv()->getDecoratorSlots(nameIt.next()));
582 QListIterator<PythonQtSlotInfo*> it(PythonQt::priv()->getDecoratorSlots(nameIt.next()));
583 while (it.hasNext()) {
583 while (it.hasNext()) {
584 PythonQtSlotInfo* slot = it.next();
584 PythonQtSlotInfo* slot = it.next();
585 h += slot->fullSignature(slot->isInstanceDecorator()) + "\n";
585 h += slot->fullSignature(slot->isInstanceDecorator()) + "\n";
586 }
586 }
587 }
587 }
588
588
589 if (_meta && _meta->enumeratorCount()) {
589 if (_meta && _meta->enumeratorCount()) {
590 h += "Enums:\n";
590 h += "Enums:\n";
591 for (int i = 0; i<_meta->enumeratorCount(); i++) {
591 for (int i = 0; i<_meta->enumeratorCount(); i++) {
592 QMetaEnum e = _meta->enumerator(i);
592 QMetaEnum e = _meta->enumerator(i);
593 h += QString(e.name()) + " {";
593 h += QString(e.name()) + " {";
594 for (int j=0; j < e.keyCount(); j++) {
594 for (int j=0; j < e.keyCount(); j++) {
595 if (j) { h+= ", "; }
595 if (j) { h+= ", "; }
596 h += e.key(j);
596 h += e.key(j);
597 }
597 }
598 h += " }\n";
598 h += " }\n";
599 }
599 }
600 }
600 }
601
601
602 if (_wrappedClassName.isEmpty() && _meta) {
602 if (_wrappedClassName.isEmpty() && _meta) {
603 int numMethods = _meta->methodCount();
603 int numMethods = _meta->methodCount();
604 if (numMethods>0) {
604 if (numMethods>0) {
605 h += "Signals:\n";
605 h += "Signals:\n";
606 for (int i = 0; i < numMethods; i++) {
606 for (int i = 0; i < numMethods; i++) {
607 QMetaMethod m = _meta->method(i);
607 QMetaMethod m = _meta->method(i);
608 if (m.methodType() == QMetaMethod::Signal) {
608 if (m.methodType() == QMetaMethod::Signal) {
609 h += QString(m.signature()) + "\n";
609 h += QString(m.signature()) + "\n";
610 }
610 }
611 }
611 }
612 }
612 }
613 }
613 }
614 return h;
614 return h;
615 }
615 }
616
616
617 PythonQtSlotInfo* PythonQtClassInfo::constructors()
617 PythonQtSlotInfo* PythonQtClassInfo::constructors()
618 {
618 {
619 if (!_constructors) {
619 if (!_constructors) {
620 // force creation of lazy decorator, which will register the decorators
620 // force creation of lazy decorator, which will register the decorators
621 decorator();
621 decorator();
622 _constructors = PythonQt::priv()->getConstructorSlot(!_wrappedClassName.isEmpty()?_wrappedClassName:QByteArray(_meta->className()));
622 _constructors = PythonQt::priv()->getConstructorSlot(!_wrappedClassName.isEmpty()?_wrappedClassName:QByteArray(_meta->className()));
623 }
623 }
624 return _constructors;
624 return _constructors;
625 }
625 }
626
626
627 void PythonQtClassInfo::setMetaObject(const QMetaObject* meta)
627 void PythonQtClassInfo::setMetaObject(const QMetaObject* meta)
628 {
628 {
629 _meta = meta;
629 _meta = meta;
630 clearCachedMembers();
630 clearCachedMembers();
631 }
631 }
632
632
633 QObject* PythonQtClassInfo::decorator()
633 QObject* PythonQtClassInfo::decorator()
634 {
634 {
635 if (!_decoratorProvider && _decoratorProviderCB) {
635 if (!_decoratorProvider && _decoratorProviderCB) {
636 _decoratorProvider = (*_decoratorProviderCB)();
636 _decoratorProvider = (*_decoratorProviderCB)();
637 if (_decoratorProvider) {
637 if (_decoratorProvider) {
638 _decoratorProvider->setParent(PythonQt::priv());
638 _decoratorProvider->setParent(PythonQt::priv());
639 PythonQt::priv()->addDecorators(_decoratorProvider, PythonQtPrivate::ConstructorDecorator | PythonQtPrivate::DestructorDecorator);
639 PythonQt::priv()->addDecorators(_decoratorProvider, PythonQtPrivate::ConstructorDecorator | PythonQtPrivate::DestructorDecorator);
640 }
640 }
641 }
641 }
642 return _decoratorProvider;
642 return _decoratorProvider;
643 }
643 }
644
645 bool PythonQtClassInfo::hasOwnerMethodButNoOwner(void* object)
646 {
647 PythonQtMemberInfo info = member("hasOwner");
648 if (info._type == PythonQtMemberInfo::Slot) {
649 void* obj = object;
650 bool result = false;
651 void* args[2];
652 args[0] = &result;
653 args[1] = &obj;
654 info._slot->decorator()->qt_metacall(QMetaObject::InvokeMetaMethod, info._slot->slotIndex(), args);
655 return !result;
656 } else {
657 return false;
658 }
659 }
@@ -1,158 +1,161
1 #ifndef _PYTHONQTCLASSINFO_H
1 #ifndef _PYTHONQTCLASSINFO_H
2 #define _PYTHONQTCLASSINFO_H
2 #define _PYTHONQTCLASSINFO_H
3
3
4 /*
4 /*
5 *
5 *
6 * Copyright (C) 2006 MeVis Research GmbH All Rights Reserved.
6 * Copyright (C) 2006 MeVis Research GmbH All Rights Reserved.
7 *
7 *
8 * This library is free software; you can redistribute it and/or
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
11 * version 2.1 of the License, or (at your option) any later version.
12 *
12 *
13 * This library is distributed in the hope that it will be useful,
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
16 * Lesser General Public License for more details.
17 *
17 *
18 * Further, this software is distributed without any warranty that it is
18 * Further, this software is distributed without any warranty that it is
19 * free of the rightful claim of any third person regarding infringement
19 * free of the rightful claim of any third person regarding infringement
20 * or the like. Any license provided herein, whether implied or
20 * or the like. Any license provided herein, whether implied or
21 * otherwise, applies only to this software file. Patent licenses, if
21 * otherwise, applies only to this software file. Patent licenses, if
22 * any, provided herein do not apply to combinations of this program with
22 * any, provided herein do not apply to combinations of this program with
23 * other software, or any other product whatsoever.
23 * other software, or any other product whatsoever.
24 *
24 *
25 * You should have received a copy of the GNU Lesser General Public
25 * You should have received a copy of the GNU Lesser General Public
26 * License along with this library; if not, write to the Free Software
26 * License along with this library; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 *
28 *
29 * Contact information: MeVis Research GmbH, Universitaetsallee 29,
29 * Contact information: MeVis Research GmbH, Universitaetsallee 29,
30 * 28359 Bremen, Germany or:
30 * 28359 Bremen, Germany or:
31 *
31 *
32 * http://www.mevis.de
32 * http://www.mevis.de
33 *
33 *
34 */
34 */
35
35
36 #include <QMetaObject>
36 #include <QMetaObject>
37 #include <QMetaMethod>
37 #include <QMetaMethod>
38 #include <QHash>
38 #include <QHash>
39 #include <QByteArray>
39 #include <QByteArray>
40 #include <QList>
40 #include <QList>
41 #include "PythonQt.h"
41 #include "PythonQt.h"
42
42
43 class PythonQtSlotInfo;
43 class PythonQtSlotInfo;
44
44
45 struct PythonQtMemberInfo {
45 struct PythonQtMemberInfo {
46 enum Type {
46 enum Type {
47 Invalid, Slot, EnumValue, Property, NotFound
47 Invalid, Slot, EnumValue, Property, NotFound
48 };
48 };
49
49
50 PythonQtMemberInfo():_slot(NULL),_enumValue(0),_type(Invalid) { }
50 PythonQtMemberInfo():_slot(NULL),_enumValue(0),_type(Invalid) { }
51
51
52 PythonQtMemberInfo(PythonQtSlotInfo* info) {
52 PythonQtMemberInfo(PythonQtSlotInfo* info) {
53 _type = Slot;
53 _type = Slot;
54 _slot = info;
54 _slot = info;
55 _enumValue = 0;
55 _enumValue = 0;
56 }
56 }
57
57
58 PythonQtMemberInfo(unsigned int enumValue) {
58 PythonQtMemberInfo(unsigned int enumValue) {
59 _type = EnumValue;
59 _type = EnumValue;
60 _slot = NULL;
60 _slot = NULL;
61 _enumValue = enumValue;
61 _enumValue = enumValue;
62 }
62 }
63
63
64 PythonQtMemberInfo(const QMetaProperty& prop) {
64 PythonQtMemberInfo(const QMetaProperty& prop) {
65 _type = Property;
65 _type = Property;
66 _slot = NULL;
66 _slot = NULL;
67 _enumValue = 0;
67 _enumValue = 0;
68 _property = prop;
68 _property = prop;
69 }
69 }
70
70
71 PythonQtSlotInfo* _slot;
71 PythonQtSlotInfo* _slot;
72 unsigned int _enumValue;
72 unsigned int _enumValue;
73 QMetaProperty _property;
73 QMetaProperty _property;
74 Type _type;
74 Type _type;
75 };
75 };
76
76
77 //! a class that stores all required information about a Qt object (and an optional associated C++ class name)
77 //! a class that stores all required information about a Qt object (and an optional associated C++ class name)
78 /*! for fast lookup of slots when calling the object from Python
78 /*! for fast lookup of slots when calling the object from Python
79 */
79 */
80 class PythonQtClassInfo {
80 class PythonQtClassInfo {
81
81
82 public:
82 public:
83 PythonQtClassInfo(const QMetaObject* meta, const QByteArray& wrappedClassName = QByteArray());
83 PythonQtClassInfo(const QMetaObject* meta, const QByteArray& wrappedClassName = QByteArray());
84
84
85 ~PythonQtClassInfo();
85 ~PythonQtClassInfo();
86
86
87 //! get the Python method definition for a given slot name (without return type and signature)
87 //! get the Python method definition for a given slot name (without return type and signature)
88 PythonQtMemberInfo member(const char* member);
88 PythonQtMemberInfo member(const char* member);
89
89
90 PythonQtSlotInfo* constructors();
90 PythonQtSlotInfo* constructors();
91
91
92 //! get the classname (either of the QObject or of the wrapped CPP object)
92 //! get the classname (either of the QObject or of the wrapped CPP object)
93 const char* className();
93 const char* className();
94
94
95 //! returns if the object is a CPP wrapper
95 //! returns if the object is a CPP wrapper
96 bool isCPPWrapper() { return !_wrappedClassName.isEmpty(); }
96 bool isCPPWrapper() { return !_wrappedClassName.isEmpty(); }
97
97
98 //! get the meta object
98 //! get the meta object
99 const QMetaObject* metaObject() { return _meta; }
99 const QMetaObject* metaObject() { return _meta; }
100
100
101 //! set the meta object, this will reset the caching
101 //! set the meta object, this will reset the caching
102 void setMetaObject(const QMetaObject* meta);
102 void setMetaObject(const QMetaObject* meta);
103
103
104 //! returns if the meta object inherits the given classname
104 //! returns if the meta object inherits the given classname
105 bool inherits(const char* name);
105 bool inherits(const char* name);
106
106
107 //! get help string for the metaobject
107 //! get help string for the metaobject
108 QString help();
108 QString help();
109
109
110 //! get list of all members
110 //! get list of all members
111 QStringList memberList(bool metaOnly = false);
111 QStringList memberList(bool metaOnly = false);
112
112
113 //! get the meta type id of this class (only valid for isCPPWrapper() == true)
113 //! get the meta type id of this class (only valid for isCPPWrapper() == true)
114 int metaTypeId() { return _metaTypeId; }
114 int metaTypeId() { return _metaTypeId; }
115
115
116 //! set an additional decorator provider that offers additional decorator slots for this class
116 //! set an additional decorator provider that offers additional decorator slots for this class
117 void setDecoratorProvider(PythonQtQObjectCreatorFunctionCB* cb) { _decoratorProviderCB = cb; _decoratorProvider = NULL; }
117 void setDecoratorProvider(PythonQtQObjectCreatorFunctionCB* cb) { _decoratorProviderCB = cb; _decoratorProvider = NULL; }
118
118
119 //! get the decorator qobject instance
119 //! get the decorator qobject instance
120 QObject* decorator();
120 QObject* decorator();
121
121
122 //! set the parent class name of a wrapped CPP pointer
122 //! set the parent class name of a wrapped CPP pointer
123 void setWrappedParentClassName(const QByteArray& name) { _wrappedParentClassName = name; _parentClassInfo = NULL; _parentClassInfoResolved = false; }
123 void setWrappedParentClassName(const QByteArray& name) { _wrappedParentClassName = name; _parentClassInfo = NULL; _parentClassInfoResolved = false; }
124
124
125 //! check if the special method "hasOwner" is implemented and if it returns false, which means that the object may be destroyed
126 bool hasOwnerMethodButNoOwner(void* object);
127
125 private:
128 private:
126 //! resolve the parent class from either meta object or cpp parent class name
129 //! resolve the parent class from either meta object or cpp parent class name
127 void resolveParentClassInfo();
130 void resolveParentClassInfo();
128
131
129 //! clear all cached members
132 //! clear all cached members
130 void clearCachedMembers();
133 void clearCachedMembers();
131
134
132 PythonQtSlotInfo* findDecoratorSlotsFromDecoratorProvider(const char* memberName, PythonQtSlotInfo* inputInfo, bool &found, QHash<QByteArray, PythonQtMemberInfo>& memberCache);
135 PythonQtSlotInfo* findDecoratorSlotsFromDecoratorProvider(const char* memberName, PythonQtSlotInfo* inputInfo, bool &found, QHash<QByteArray, PythonQtMemberInfo>& memberCache);
133 void listDecoratorSlotsFromDecoratorProvider(QStringList& list, bool metaOnly);
136 void listDecoratorSlotsFromDecoratorProvider(QStringList& list, bool metaOnly);
134
137
135 bool lookForPropertyAndCache(const char* memberName);
138 bool lookForPropertyAndCache(const char* memberName);
136 bool lookForMethodAndCache(const char* memberName);
139 bool lookForMethodAndCache(const char* memberName);
137 bool lookForEnumAndCache(const QMetaObject* m, const char* memberName);
140 bool lookForEnumAndCache(const QMetaObject* m, const char* memberName);
138
141
139 PythonQtSlotInfo* findDecoratorSlots(const char* classname, const char* memberName, int memberNameLen, PythonQtSlotInfo* tail, bool &found);
142 PythonQtSlotInfo* findDecoratorSlots(const char* classname, const char* memberName, int memberNameLen, PythonQtSlotInfo* tail, bool &found);
140 int findCharOffset(const char* sigStart, char someChar);
143 int findCharOffset(const char* sigStart, char someChar);
141 QHash<QByteArray, PythonQtMemberInfo> _cachedMembers;
144 QHash<QByteArray, PythonQtMemberInfo> _cachedMembers;
142 PythonQtSlotInfo* _constructors;
145 PythonQtSlotInfo* _constructors;
143 const QMetaObject* _meta;
146 const QMetaObject* _meta;
144 QByteArray _wrappedClassName;
147 QByteArray _wrappedClassName;
145 QByteArray _wrappedParentClassName;
148 QByteArray _wrappedParentClassName;
146 QObject* _decoratorProvider;
149 QObject* _decoratorProvider;
147 PythonQtQObjectCreatorFunctionCB* _decoratorProviderCB;
150 PythonQtQObjectCreatorFunctionCB* _decoratorProviderCB;
148 PythonQtClassInfo* _parentClassInfo;
151 PythonQtClassInfo* _parentClassInfo;
149
152
150 bool _parentClassInfoResolved;
153 bool _parentClassInfoResolved;
151 int _metaTypeId;
154 int _metaTypeId;
152
155
153 };
156 };
154
157
155 //---------------------------------------------------------------
158 //---------------------------------------------------------------
156
159
157
160
158 #endif
161 #endif
@@ -1,484 +1,485
1 /*
1 /*
2 *
2 *
3 * Copyright (C) 2006 MeVis Research GmbH All Rights Reserved.
3 * Copyright (C) 2006 MeVis Research GmbH All Rights Reserved.
4 *
4 *
5 * This library is free software; you can redistribute it and/or
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
8 * version 2.1 of the License, or (at your option) any later version.
9 *
9 *
10 * This library is distributed in the hope that it will be useful,
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
13 * Lesser General Public License for more details.
14 *
14 *
15 * Further, this software is distributed without any warranty that it is
15 * Further, this software is distributed without any warranty that it is
16 * free of the rightful claim of any third person regarding infringement
16 * free of the rightful claim of any third person regarding infringement
17 * or the like. Any license provided herein, whether implied or
17 * or the like. Any license provided herein, whether implied or
18 * otherwise, applies only to this software file. Patent licenses, if
18 * otherwise, applies only to this software file. Patent licenses, if
19 * any, provided herein do not apply to combinations of this program with
19 * any, provided herein do not apply to combinations of this program with
20 * other software, or any other product whatsoever.
20 * other software, or any other product whatsoever.
21 *
21 *
22 * You should have received a copy of the GNU Lesser General Public
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this library; if not, write to the Free Software
23 * License along with this library; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 *
25 *
26 * Contact information: MeVis Research GmbH, Universitaetsallee 29,
26 * Contact information: MeVis Research GmbH, Universitaetsallee 29,
27 * 28359 Bremen, Germany or:
27 * 28359 Bremen, Germany or:
28 *
28 *
29 * http://www.mevis.de
29 * http://www.mevis.de
30 *
30 *
31 */
31 */
32
32
33 //----------------------------------------------------------------------------------
33 //----------------------------------------------------------------------------------
34 /*!
34 /*!
35 // \file PythonQtWrapper.cpp
35 // \file PythonQtWrapper.cpp
36 // \author Florian Link
36 // \author Florian Link
37 // \author Last changed by $Author: florian $
37 // \author Last changed by $Author: florian $
38 // \date 2006-05
38 // \date 2006-05
39 */
39 */
40 //----------------------------------------------------------------------------------
40 //----------------------------------------------------------------------------------
41
41
42 #include "PythonQtWrapper.h"
42 #include "PythonQtWrapper.h"
43 #include <QObject>
43 #include <QObject>
44 #include "PythonQt.h"
44 #include "PythonQt.h"
45 #include "PythonQtSlot.h"
45 #include "PythonQtSlot.h"
46 #include "PythonQtClassInfo.h"
46 #include "PythonQtClassInfo.h"
47 #include "PythonQtConversion.h"
47 #include "PythonQtConversion.h"
48
48
49 static void PythonQtWrapper_deleteObject(PythonQtWrapper* self) {
49 static void PythonQtWrapper_deleteObject(PythonQtWrapper* self, bool force = false) {
50
51 // is this a C++ wrapper?
50 if (self->_wrappedPtr) {
52 if (self->_wrappedPtr) {
51
52 //mlabDebugConst("Python","c++ wrapper removed " << self->_wrappedPtr << " " << self->_obj->className() << " " << self->_info->wrappedClassName().latin1());
53 //mlabDebugConst("Python","c++ wrapper removed " << self->_wrappedPtr << " " << self->_obj->className() << " " << self->_info->wrappedClassName().latin1());
53
54
54 PythonQt::priv()->removeWrapperPointer(self->_wrappedPtr);
55 PythonQt::priv()->removeWrapperPointer(self->_wrappedPtr);
55 // we own our qobject, so we delete it now:
56 // we own our qobject, so we delete it now:
56 delete self->_obj;
57 delete self->_obj;
57 self->_obj = NULL;
58 self->_obj = NULL;
58 if (self->_ownedByPythonQt) {
59 if (force || self->_info->hasOwnerMethodButNoOwner(self->_wrappedPtr) || self->_ownedByPythonQt) {
59 int type = self->_info->metaTypeId();
60 int type = self->_info->metaTypeId();
60 if (self->_useQMetaTypeDestroy && type>=0) {
61 if (self->_useQMetaTypeDestroy && type>=0) {
61 // use QMetaType to destroy the object
62 // use QMetaType to destroy the object
62 QMetaType::destroy(type, self->_wrappedPtr);
63 QMetaType::destroy(type, self->_wrappedPtr);
63 } else {
64 } else {
64 PythonQtSlotInfo* slot = PythonQt::priv()->getDestructorSlot(self->_info->className());
65 PythonQtSlotInfo* slot = PythonQt::priv()->getDestructorSlot(self->_info->className());
65 if (slot) {
66 if (slot) {
66 void* args[2];
67 void* args[2];
67 args[0] = NULL;
68 args[0] = NULL;
68 args[1] = &self->_wrappedPtr;
69 args[1] = &self->_wrappedPtr;
69 slot->decorator()->qt_metacall(QMetaObject::InvokeMetaMethod, slot->slotIndex(), args);
70 slot->decorator()->qt_metacall(QMetaObject::InvokeMetaMethod, slot->slotIndex(), args);
70 self->_wrappedPtr = NULL;
71 self->_wrappedPtr = NULL;
71 } else {
72 } else {
72 if (type>=0) {
73 if (type>=0) {
73 // use QMetaType to destroy the object
74 // use QMetaType to destroy the object
74 QMetaType::destroy(type, self->_wrappedPtr);
75 QMetaType::destroy(type, self->_wrappedPtr);
75 } else {
76 } else {
76 // TODO: warn about not being able to destroy the object?
77 // TODO: warn about not being able to destroy the object?
77 }
78 }
78 }
79 }
79 }
80 }
80 }
81 }
81 } else {
82 } else {
82 //mlabDebugConst("Python","qobject wrapper removed " << self->_obj->className() << " " << self->_info->wrappedClassName().latin1());
83 //mlabDebugConst("Python","qobject wrapper removed " << self->_obj->className() << " " << self->_info->wrappedClassName().latin1());
83 if (self->_objPointerCopy) {
84 if (self->_objPointerCopy) {
84 PythonQt::priv()->removeWrapperPointer(self->_objPointerCopy);
85 PythonQt::priv()->removeWrapperPointer(self->_objPointerCopy);
85 }
86 }
86 if (self->_obj) {
87 if (self->_obj) {
87 if (self->_ownedByPythonQt) {
88 if (force || self->_ownedByPythonQt) {
88 if (!self->_obj->parent()) {
89 if (force || !self->_obj->parent()) {
89 delete self->_obj;
90 delete self->_obj;
90 }
91 }
91 } else {
92 } else {
92 if (self->_obj->parent()==NULL) {
93 if (self->_obj->parent()==NULL) {
93 // tell someone who is interested that the qobject is no longer wrapped, if it has no parent
94 // tell someone who is interested that the qobject is no longer wrapped, if it has no parent
94 PythonQt::qObjectNoLongerWrappedCB(self->_obj);
95 PythonQt::qObjectNoLongerWrappedCB(self->_obj);
95 }
96 }
96 }
97 }
97 }
98 }
98 }
99 }
99 self->_obj = NULL;
100 self->_obj = NULL;
100 }
101 }
101
102
102 static void PythonQtWrapper_dealloc(PythonQtWrapper* self)
103 static void PythonQtWrapper_dealloc(PythonQtWrapper* self)
103 {
104 {
104 PythonQtWrapper_deleteObject(self);
105 PythonQtWrapper_deleteObject(self);
105 self->_obj.~QPointer<QObject>();
106 self->_obj.~QPointer<QObject>();
106 self->ob_type->tp_free((PyObject*)self);
107 self->ob_type->tp_free((PyObject*)self);
107 }
108 }
108
109
109 static PyObject* PythonQtWrapper_new(PyTypeObject *type, PyObject * /*args*/, PyObject * /*kwds*/)
110 static PyObject* PythonQtWrapper_new(PyTypeObject *type, PyObject * /*args*/, PyObject * /*kwds*/)
110 {
111 {
111 PythonQtWrapper *self;
112 PythonQtWrapper *self;
112
113
113 self = (PythonQtWrapper *)type->tp_alloc(type, 0);
114 self = (PythonQtWrapper *)type->tp_alloc(type, 0);
114 if (self != NULL) {
115 if (self != NULL) {
115 self->_info = NULL;
116 self->_info = NULL;
116 new (&self->_obj) QPointer<QObject>();
117 new (&self->_obj) QPointer<QObject>();
117 self->_wrappedPtr = NULL;
118 self->_wrappedPtr = NULL;
118 self->_ownedByPythonQt = false;
119 self->_ownedByPythonQt = false;
119 self->_useQMetaTypeDestroy = false;
120 self->_useQMetaTypeDestroy = false;
120 }
121 }
121 return (PyObject *)self;
122 return (PyObject *)self;
122 }
123 }
123
124
124 static int PythonQtWrapper_init(PythonQtWrapper * /*self*/, PyObject * /*args*/, PyObject * /*kwds*/)
125 static int PythonQtWrapper_init(PythonQtWrapper * /*self*/, PyObject * /*args*/, PyObject * /*kwds*/)
125 {
126 {
126 return 0;
127 return 0;
127 }
128 }
128
129
129 static PyObject *PythonQtWrapper_classname(PythonQtWrapper* type)
130 static PyObject *PythonQtWrapper_classname(PythonQtWrapper* type)
130 {
131 {
131 return PyString_FromString(type->_info->className());
132 return PyString_FromString(type->_info->className());
132 }
133 }
133
134
134 static PyObject *PythonQtWrapper_help(PythonQtWrapper* type)
135 static PyObject *PythonQtWrapper_help(PythonQtWrapper* type)
135 {
136 {
136 return PythonQt::self()->helpCalled(type->_info);
137 return PythonQt::self()->helpCalled(type->_info);
137 }
138 }
138
139
139 static PyObject *PythonQtWrapper_delete(PythonQtWrapper * self)
140 static PyObject *PythonQtWrapper_delete(PythonQtWrapper * self)
140 {
141 {
141 PythonQtWrapper_deleteObject(self);
142 PythonQtWrapper_deleteObject(self, true);
142 Py_INCREF(Py_None);
143 Py_INCREF(Py_None);
143 return Py_None;
144 return Py_None;
144 }
145 }
145
146
146
147
147 static PyMethodDef PythonQtWrapper_methods[] = {
148 static PyMethodDef PythonQtWrapper_methods[] = {
148 {"className", (PyCFunction)PythonQtWrapper_classname, METH_NOARGS,
149 {"className", (PyCFunction)PythonQtWrapper_classname, METH_NOARGS,
149 "Return the classname of the object"
150 "Return the classname of the object"
150 },
151 },
151 {"help", (PyCFunction)PythonQtWrapper_help, METH_NOARGS,
152 {"help", (PyCFunction)PythonQtWrapper_help, METH_NOARGS,
152 "Shows the help of available methods for this class"
153 "Shows the help of available methods for this class"
153 },
154 },
154 {"delete", (PyCFunction)PythonQtWrapper_delete, METH_NOARGS,
155 {"delete", (PyCFunction)PythonQtWrapper_delete, METH_NOARGS,
155 "Deletes the C++ object (at your own risk, my friend!)"
156 "Deletes the C++ object (at your own risk, my friend!)"
156 },
157 },
157 {NULL, NULL, 0, NULL} /* Sentinel */
158 {NULL, NULL, 0, NULL} /* Sentinel */
158 };
159 };
159
160
160
161
161 static PyObject *PythonQtWrapper_getattro(PyObject *obj,PyObject *name)
162 static PyObject *PythonQtWrapper_getattro(PyObject *obj,PyObject *name)
162 {
163 {
163 const char *attributeName;
164 const char *attributeName;
164 PythonQtWrapper *wt = (PythonQtWrapper *)obj;
165 PythonQtWrapper *wt = (PythonQtWrapper *)obj;
165
166
166 if ((attributeName = PyString_AsString(name)) == NULL) {
167 if ((attributeName = PyString_AsString(name)) == NULL) {
167 return NULL;
168 return NULL;
168 }
169 }
169
170
170 if (!wt->_obj && !wt->_wrappedPtr) {
171 if (!wt->_obj && !wt->_wrappedPtr) {
171 QString error = QString("Trying to read attribute '") + attributeName + "' from a destroyed " + wt->_info->className() + " object";
172 QString error = QString("Trying to read attribute '") + attributeName + "' from a destroyed " + wt->_info->className() + " object";
172 PyErr_SetString(PyExc_ValueError, error.toLatin1().data());
173 PyErr_SetString(PyExc_ValueError, error.toLatin1().data());
173 return NULL;
174 return NULL;
174 }
175 }
175
176
176 // mlabDebugConst("Python","get " << attributeName);
177 // mlabDebugConst("Python","get " << attributeName);
177
178
178 // TODO: dynamic properties are missing
179 // TODO: dynamic properties are missing
179
180
180 PythonQtMemberInfo member = wt->_info->member(attributeName);
181 PythonQtMemberInfo member = wt->_info->member(attributeName);
181 switch (member._type) {
182 switch (member._type) {
182 case PythonQtMemberInfo::Property:
183 case PythonQtMemberInfo::Property:
183 if (wt->_obj) {
184 if (wt->_obj) {
184 return PythonQtConv::QVariantToPyObject(member._property.read(wt->_obj));
185 return PythonQtConv::QVariantToPyObject(member._property.read(wt->_obj));
185 }
186 }
186 break;
187 break;
187 case PythonQtMemberInfo::Slot:
188 case PythonQtMemberInfo::Slot:
188 return PythonQtSlotFunction_New(member._slot, obj, NULL);
189 return PythonQtSlotFunction_New(member._slot, obj, NULL);
189 break;
190 break;
190 case PythonQtMemberInfo::EnumValue:
191 case PythonQtMemberInfo::EnumValue:
191 return PyInt_FromLong(member._enumValue);
192 return PyInt_FromLong(member._enumValue);
192 break;
193 break;
193 default:
194 default:
194 // is an invalid type, go on
195 // is an invalid type, go on
195 break;
196 break;
196 }
197 }
197
198
198 // look for the interal methods (className(), help())
199 // look for the interal methods (className(), help())
199 PyObject* internalMethod = Py_FindMethod( PythonQtWrapper_methods, obj, (char*)attributeName);
200 PyObject* internalMethod = Py_FindMethod( PythonQtWrapper_methods, obj, (char*)attributeName);
200 if (internalMethod) {
201 if (internalMethod) {
201 return internalMethod;
202 return internalMethod;
202 }
203 }
203 PyErr_Clear();
204 PyErr_Clear();
204
205
205 if (wt->_obj) {
206 if (wt->_obj) {
206 // look for a child
207 // look for a child
207 QObjectList children = wt->_obj->children();
208 QObjectList children = wt->_obj->children();
208 for (int i = 0; i < children.count(); i++) {
209 for (int i = 0; i < children.count(); i++) {
209 QObject *child = children.at(i);
210 QObject *child = children.at(i);
210 if (child->objectName() == attributeName) {
211 if (child->objectName() == attributeName) {
211 return PythonQt::self()->priv()->wrapQObject(child);
212 return PythonQt::self()->priv()->wrapQObject(child);
212 }
213 }
213 }
214 }
214 }
215 }
215
216
216 if (qstrcmp(attributeName, "__dict__")==0) {
217 if (qstrcmp(attributeName, "__dict__")==0) {
217 QStringList l = wt->_info->memberList(false);
218 QStringList l = wt->_info->memberList(false);
218 PyObject* dict = PyDict_New();
219 PyObject* dict = PyDict_New();
219 foreach (QString name, l) {
220 foreach (QString name, l) {
220 //PyObject* o = PyObject_GetAttrString(obj, name.toLatin1().data());
221 //PyObject* o = PyObject_GetAttrString(obj, name.toLatin1().data());
221 PyDict_SetItemString(dict, name.toLatin1().data(), Py_None);
222 PyDict_SetItemString(dict, name.toLatin1().data(), Py_None);
222 //Py_DECREF(o);
223 //Py_DECREF(o);
223 }
224 }
224 // Note: we do not put children into the dict, is would look confusing?!
225 // Note: we do not put children into the dict, is would look confusing?!
225 return dict;
226 return dict;
226 }
227 }
227
228
228
229
229 QString error = QString(wt->_info->className()) + " has no attribute named '" + QString(attributeName) + "'";
230 QString error = QString(wt->_info->className()) + " has no attribute named '" + QString(attributeName) + "'";
230 PyErr_SetString(PyExc_AttributeError, error.toLatin1().data());
231 PyErr_SetString(PyExc_AttributeError, error.toLatin1().data());
231 return NULL;
232 return NULL;
232 }
233 }
233
234
234 static int PythonQtWrapper_setattro(PyObject *obj,PyObject *name,PyObject *value)
235 static int PythonQtWrapper_setattro(PyObject *obj,PyObject *name,PyObject *value)
235 {
236 {
236 QString error;
237 QString error;
237 char *attributeName;
238 char *attributeName;
238 PythonQtWrapper *wt = (PythonQtWrapper *)obj;
239 PythonQtWrapper *wt = (PythonQtWrapper *)obj;
239
240
240 if ((attributeName = PyString_AsString(name)) == NULL)
241 if ((attributeName = PyString_AsString(name)) == NULL)
241 return -1;
242 return -1;
242
243
243 if (!wt->_obj) {
244 if (!wt->_obj) {
244 error = QString("Trying to set attribute '") + attributeName + "' on a destroyed " + wt->_info->className() + " object";
245 error = QString("Trying to set attribute '") + attributeName + "' on a destroyed " + wt->_info->className() + " object";
245 PyErr_SetString(PyExc_AttributeError, error.toLatin1().data());
246 PyErr_SetString(PyExc_AttributeError, error.toLatin1().data());
246 return -1;
247 return -1;
247 }
248 }
248
249
249 PythonQtMemberInfo member = wt->_info->member(attributeName);
250 PythonQtMemberInfo member = wt->_info->member(attributeName);
250 if (member._type == PythonQtMemberInfo::Property) {
251 if (member._type == PythonQtMemberInfo::Property) {
251 QMetaProperty prop = member._property;
252 QMetaProperty prop = member._property;
252 if (prop.isWritable()) {
253 if (prop.isWritable()) {
253 QVariant v;
254 QVariant v;
254 if (prop.isEnumType()) {
255 if (prop.isEnumType()) {
255 // this will give us either a string or an int, everything else will probably be an error
256 // this will give us either a string or an int, everything else will probably be an error
256 v = PythonQtConv::PyObjToQVariant(value);
257 v = PythonQtConv::PyObjToQVariant(value);
257 } else {
258 } else {
258 int t = prop.userType();
259 int t = prop.userType();
259 v = PythonQtConv::PyObjToQVariant(value, t);
260 v = PythonQtConv::PyObjToQVariant(value, t);
260 }
261 }
261 bool success = false;
262 bool success = false;
262 if (v.isValid()) {
263 if (v.isValid()) {
263 success = prop.write(wt->_obj, v);
264 success = prop.write(wt->_obj, v);
264 }
265 }
265 if (success) {
266 if (success) {
266 return 0;
267 return 0;
267 } else {
268 } else {
268 error = QString("Property '") + attributeName + "' of type '" +
269 error = QString("Property '") + attributeName + "' of type '" +
269 prop.typeName() + "' does not accept an object of type "
270 prop.typeName() + "' does not accept an object of type "
270 + QString(value->ob_type->tp_name) + " (" + PythonQtConv::PyObjGetRepresentation(value) + ")";
271 + QString(value->ob_type->tp_name) + " (" + PythonQtConv::PyObjGetRepresentation(value) + ")";
271 }
272 }
272 } else {
273 } else {
273 error = QString("Property '") + attributeName + "' of " + wt->_info->className() + " object is not writable";
274 error = QString("Property '") + attributeName + "' of " + wt->_info->className() + " object is not writable";
274 }
275 }
275 } else {
276 } else {
276 if (member._type == PythonQtMemberInfo::Slot) {
277 if (member._type == PythonQtMemberInfo::Slot) {
277 error = QString("Slot '") + attributeName + "' can not be overwritten on " + wt->_info->className() + " object";
278 error = QString("Slot '") + attributeName + "' can not be overwritten on " + wt->_info->className() + " object";
278 } else if (member._type == PythonQtMemberInfo::EnumValue) {
279 } else if (member._type == PythonQtMemberInfo::EnumValue) {
279 error = QString("EnumValue '") + attributeName + "' can not be overwritten on " + wt->_info->className() + " object";
280 error = QString("EnumValue '") + attributeName + "' can not be overwritten on " + wt->_info->className() + " object";
280 }
281 }
281 }
282 }
282
283
283 PyErr_SetString(PyExc_AttributeError, error.toLatin1().data());
284 PyErr_SetString(PyExc_AttributeError, error.toLatin1().data());
284 return -1;
285 return -1;
285 }
286 }
286
287
287 static PyObject * PythonQtWrapper_str(PyObject * obj)
288 static PyObject * PythonQtWrapper_str(PyObject * obj)
288 {
289 {
289 PythonQtWrapper* wt = (PythonQtWrapper*)obj;
290 PythonQtWrapper* wt = (PythonQtWrapper*)obj;
290 QObject *qobj = wt->_obj;
291 QObject *qobj = wt->_obj;
291 if (wt->_wrappedPtr) {
292 if (wt->_wrappedPtr) {
292 QString str = PythonQtConv::CPPObjectToString(wt->_info->metaTypeId(), wt->_wrappedPtr);
293 QString str = PythonQtConv::CPPObjectToString(wt->_info->metaTypeId(), wt->_wrappedPtr);
293 if (!str.isEmpty()) {
294 if (!str.isEmpty()) {
294 return PyString_FromFormat("%s", str.toLatin1().constData());
295 return PyString_FromFormat("%s", str.toLatin1().constData());
295 } else
296 } else
296 if (wt->_obj) {
297 if (wt->_obj) {
297 return PyString_FromFormat("%s (C++ Object %p wrapped by %s %p))", wt->_info->className(), wt->_wrappedPtr, wt->_obj->metaObject()->className(), qobj);
298 return PyString_FromFormat("%s (C++ Object %p wrapped by %s %p))", wt->_info->className(), wt->_wrappedPtr, wt->_obj->metaObject()->className(), qobj);
298 } else {
299 } else {
299 return PyString_FromFormat("%s (C++ Object %p)", wt->_info->className(), wt->_wrappedPtr);
300 return PyString_FromFormat("%s (C++ Object %p)", wt->_info->className(), wt->_wrappedPtr);
300 }
301 }
301 } else {
302 } else {
302 return PyString_FromFormat("%s (QObject %p)", wt->_info->className(), qobj);
303 return PyString_FromFormat("%s (QObject %p)", wt->_info->className(), qobj);
303 }
304 }
304 }
305 }
305
306
306 static PyObject * PythonQtWrapper_repr(PyObject * obj)
307 static PyObject * PythonQtWrapper_repr(PyObject * obj)
307 {
308 {
308 PythonQtWrapper* wt = (PythonQtWrapper*)obj;
309 PythonQtWrapper* wt = (PythonQtWrapper*)obj;
309 QObject *qobj = wt->_obj;
310 QObject *qobj = wt->_obj;
310 if (wt->_wrappedPtr) {
311 if (wt->_wrappedPtr) {
311 QString str = PythonQtConv::CPPObjectToString(wt->_info->metaTypeId(), wt->_wrappedPtr);
312 QString str = PythonQtConv::CPPObjectToString(wt->_info->metaTypeId(), wt->_wrappedPtr);
312 if (!str.isEmpty()) {
313 if (!str.isEmpty()) {
313 return PyString_FromFormat("%s(%s, %p)", QMetaType::typeName(wt->_info->metaTypeId()), str.toLatin1().constData(), wt->_wrappedPtr);
314 return PyString_FromFormat("%s(%s, %p)", QMetaType::typeName(wt->_info->metaTypeId()), str.toLatin1().constData(), wt->_wrappedPtr);
314 } else
315 } else
315 if (wt->_obj) {
316 if (wt->_obj) {
316 return PyString_FromFormat("%s (C++ Object %p wrapped by %s %p))", wt->_info->className(), wt->_wrappedPtr, wt->_obj->metaObject()->className(), qobj);
317 return PyString_FromFormat("%s (C++ Object %p wrapped by %s %p))", wt->_info->className(), wt->_wrappedPtr, wt->_obj->metaObject()->className(), qobj);
317 } else {
318 } else {
318 return PyString_FromFormat("%s (C++ Object %p)", wt->_info->className(), wt->_wrappedPtr);
319 return PyString_FromFormat("%s (C++ Object %p)", wt->_info->className(), wt->_wrappedPtr);
319 }
320 }
320 } else {
321 } else {
321 return PyString_FromFormat("%s (QObject %p)", wt->_info->className(), qobj);
322 return PyString_FromFormat("%s (QObject %p)", wt->_info->className(), qobj);
322 }
323 }
323 }
324 }
324
325
325 static int PythonQtWrapper_compare(PyObject * obj1, PyObject * obj2)
326 static int PythonQtWrapper_compare(PyObject * obj1, PyObject * obj2)
326 {
327 {
327 if (obj1->ob_type == &PythonQtWrapper_Type &&
328 if (obj1->ob_type == &PythonQtWrapper_Type &&
328 obj2->ob_type == &PythonQtWrapper_Type) {
329 obj2->ob_type == &PythonQtWrapper_Type) {
329
330
330 PythonQtWrapper* w1 = (PythonQtWrapper*)obj1;
331 PythonQtWrapper* w1 = (PythonQtWrapper*)obj1;
331 PythonQtWrapper* w2 = (PythonQtWrapper*)obj2;
332 PythonQtWrapper* w2 = (PythonQtWrapper*)obj2;
332 // check pointers directly first:
333 // check pointers directly first:
333 if (w1->_wrappedPtr != NULL) {
334 if (w1->_wrappedPtr != NULL) {
334 if (w1->_wrappedPtr == w2->_wrappedPtr) {
335 if (w1->_wrappedPtr == w2->_wrappedPtr) {
335 return 0;
336 return 0;
336 }
337 }
337 } else if (w1->_obj == w2->_obj) {
338 } else if (w1->_obj == w2->_obj) {
338 return 0;
339 return 0;
339 }
340 }
340 const char* class1 = w1->_info->className();
341 const char* class1 = w1->_info->className();
341 const char* class2 = w2->_info->className();
342 const char* class2 = w2->_info->className();
342 if (strcmp(class1, class2) == 0) {
343 if (strcmp(class1, class2) == 0) {
343 // same class names, so we can try the operator_equal
344 // same class names, so we can try the operator_equal
344 PythonQtMemberInfo info = w1->_info->member("operator_equal");
345 PythonQtMemberInfo info = w1->_info->member("operator_equal");
345 if (info._type == PythonQtMemberInfo::Slot) {
346 if (info._type == PythonQtMemberInfo::Slot) {
346 bool result = false;
347 bool result = false;
347 void* obj1 = w1->_wrappedPtr;
348 void* obj1 = w1->_wrappedPtr;
348 if (!obj1) {
349 if (!obj1) {
349 obj1 = w1->_obj;
350 obj1 = w1->_obj;
350 }
351 }
351 if (!obj1) { return -1; }
352 if (!obj1) { return -1; }
352 void* obj2 = w2->_wrappedPtr;
353 void* obj2 = w2->_wrappedPtr;
353 if (!obj2) {
354 if (!obj2) {
354 obj2 = w2->_obj;
355 obj2 = w2->_obj;
355 }
356 }
356 if (!obj2) { return -1; }
357 if (!obj2) { return -1; }
357 if (info._slot->isInstanceDecorator()) {
358 if (info._slot->isInstanceDecorator()) {
358 // call on decorator QObject
359 // call on decorator QObject
359 void* args[3];
360 void* args[3];
360 args[0] = &result;
361 args[0] = &result;
361 args[1] = &obj1; // this is a pointer, so it needs a pointer to a pointer
362 args[1] = &obj1; // this is a pointer, so it needs a pointer to a pointer
362 args[2] = obj2; // this is a reference, so it needs the direct pointer
363 args[2] = obj2; // this is a reference, so it needs the direct pointer
363 info._slot->decorator()->qt_metacall(QMetaObject::InvokeMetaMethod, info._slot->slotIndex(), args);
364 info._slot->decorator()->qt_metacall(QMetaObject::InvokeMetaMethod, info._slot->slotIndex(), args);
364 return result?0:-1;
365 return result?0:-1;
365 } else {
366 } else {
366 // call directly on QObject
367 // call directly on QObject
367 if (w1->_obj && w2->_obj) {
368 if (w1->_obj && w2->_obj) {
368 void* args[2];
369 void* args[2];
369 args[0] = &result;
370 args[0] = &result;
370 args[2] = obj2; // this is a reference, so it needs the direct pointer
371 args[2] = obj2; // this is a reference, so it needs the direct pointer
371 w1->_obj->qt_metacall(QMetaObject::InvokeMetaMethod, info._slot->slotIndex(), args);
372 w1->_obj->qt_metacall(QMetaObject::InvokeMetaMethod, info._slot->slotIndex(), args);
372 }
373 }
373 }
374 }
374 }
375 }
375 }
376 }
376 }
377 }
377 return -1;
378 return -1;
378 }
379 }
379
380
380 static int PythonQtWrapper_nonzero(PyObject *obj)
381 static int PythonQtWrapper_nonzero(PyObject *obj)
381 {
382 {
382 PythonQtWrapper* wt = (PythonQtWrapper*)obj;
383 PythonQtWrapper* wt = (PythonQtWrapper*)obj;
383 return (wt->_wrappedPtr == NULL && wt->_obj == NULL)?0:1;
384 return (wt->_wrappedPtr == NULL && wt->_obj == NULL)?0:1;
384 }
385 }
385
386
386
387
387 static long PythonQtWrapper_hash(PythonQtWrapper *obj)
388 static long PythonQtWrapper_hash(PythonQtWrapper *obj)
388 {
389 {
389 if (obj->_wrappedPtr != NULL) {
390 if (obj->_wrappedPtr != NULL) {
390 return reinterpret_cast<long>(obj->_wrappedPtr);
391 return reinterpret_cast<long>(obj->_wrappedPtr);
391 } else {
392 } else {
392 QObject* qobj = obj->_obj; // get pointer from QPointer wrapper
393 QObject* qobj = obj->_obj; // get pointer from QPointer wrapper
393 return reinterpret_cast<long>(qobj);
394 return reinterpret_cast<long>(qobj);
394 }
395 }
395 }
396 }
396
397
397
398
398
399
399 // we override nb_nonzero, so that one can do 'if' expressions to test for a NULL ptr
400 // we override nb_nonzero, so that one can do 'if' expressions to test for a NULL ptr
400 static PyNumberMethods PythonQtWrapper_as_number = {
401 static PyNumberMethods PythonQtWrapper_as_number = {
401 0, /* nb_add */
402 0, /* nb_add */
402 0, /* nb_subtract */
403 0, /* nb_subtract */
403 0, /* nb_multiply */
404 0, /* nb_multiply */
404 0, /* nb_divide */
405 0, /* nb_divide */
405 0, /* nb_remainder */
406 0, /* nb_remainder */
406 0, /* nb_divmod */
407 0, /* nb_divmod */
407 0, /* nb_power */
408 0, /* nb_power */
408 0, /* nb_negative */
409 0, /* nb_negative */
409 0, /* nb_positive */
410 0, /* nb_positive */
410 0, /* nb_absolute */
411 0, /* nb_absolute */
411 PythonQtWrapper_nonzero, /* nb_nonzero */
412 PythonQtWrapper_nonzero, /* nb_nonzero */
412 0, /* nb_invert */
413 0, /* nb_invert */
413 0, /* nb_lshift */
414 0, /* nb_lshift */
414 0, /* nb_rshift */
415 0, /* nb_rshift */
415 0, /* nb_and */
416 0, /* nb_and */
416 0, /* nb_xor */
417 0, /* nb_xor */
417 0, /* nb_or */
418 0, /* nb_or */
418 0, /* nb_coerce */
419 0, /* nb_coerce */
419 0, /* nb_int */
420 0, /* nb_int */
420 0, /* nb_long */
421 0, /* nb_long */
421 0, /* nb_float */
422 0, /* nb_float */
422 0, /* nb_oct */
423 0, /* nb_oct */
423 0, /* nb_hex */
424 0, /* nb_hex */
424 0, /* nb_inplace_add */
425 0, /* nb_inplace_add */
425 0, /* nb_inplace_subtract */
426 0, /* nb_inplace_subtract */
426 0, /* nb_inplace_multiply */
427 0, /* nb_inplace_multiply */
427 0, /* nb_inplace_divide */
428 0, /* nb_inplace_divide */
428 0, /* nb_inplace_remainder */
429 0, /* nb_inplace_remainder */
429 0, /* nb_inplace_power */
430 0, /* nb_inplace_power */
430 0, /* nb_inplace_lshift */
431 0, /* nb_inplace_lshift */
431 0, /* nb_inplace_rshift */
432 0, /* nb_inplace_rshift */
432 0, /* nb_inplace_and */
433 0, /* nb_inplace_and */
433 0, /* nb_inplace_xor */
434 0, /* nb_inplace_xor */
434 0, /* nb_inplace_or */
435 0, /* nb_inplace_or */
435 0, /* nb_floor_divide */
436 0, /* nb_floor_divide */
436 0, /* nb_true_divide */
437 0, /* nb_true_divide */
437 0, /* nb_inplace_floor_divide */
438 0, /* nb_inplace_floor_divide */
438 0, /* nb_inplace_true_divide */
439 0, /* nb_inplace_true_divide */
439 };
440 };
440
441
441 PyTypeObject PythonQtWrapper_Type = {
442 PyTypeObject PythonQtWrapper_Type = {
442 PyObject_HEAD_INIT(NULL)
443 PyObject_HEAD_INIT(NULL)
443 0, /*ob_size*/
444 0, /*ob_size*/
444 "PythonQt.PythonQtWrapper", /*tp_name*/
445 "PythonQt.PythonQtWrapper", /*tp_name*/
445 sizeof(PythonQtWrapper), /*tp_basicsize*/
446 sizeof(PythonQtWrapper), /*tp_basicsize*/
446 0, /*tp_itemsize*/
447 0, /*tp_itemsize*/
447 (destructor)PythonQtWrapper_dealloc, /*tp_dealloc*/
448 (destructor)PythonQtWrapper_dealloc, /*tp_dealloc*/
448 0, /*tp_print*/
449 0, /*tp_print*/
449 0, /*tp_getattr*/
450 0, /*tp_getattr*/
450 0, /*tp_setattr*/
451 0, /*tp_setattr*/
451 PythonQtWrapper_compare, /*tp_compare*/
452 PythonQtWrapper_compare, /*tp_compare*/
452 PythonQtWrapper_repr, /*tp_repr*/
453 PythonQtWrapper_repr, /*tp_repr*/
453 &PythonQtWrapper_as_number, /*tp_as_number*/
454 &PythonQtWrapper_as_number, /*tp_as_number*/
454 0, /*tp_as_sequence*/
455 0, /*tp_as_sequence*/
455 0, /*tp_as_mapping*/
456 0, /*tp_as_mapping*/
456 (hashfunc)PythonQtWrapper_hash, /*tp_hash */
457 (hashfunc)PythonQtWrapper_hash, /*tp_hash */
457 0, /*tp_call*/
458 0, /*tp_call*/
458 PythonQtWrapper_str, /*tp_str*/
459 PythonQtWrapper_str, /*tp_str*/
459 PythonQtWrapper_getattro, /*tp_getattro*/
460 PythonQtWrapper_getattro, /*tp_getattro*/
460 PythonQtWrapper_setattro, /*tp_setattro*/
461 PythonQtWrapper_setattro, /*tp_setattro*/
461 0, /*tp_as_buffer*/
462 0, /*tp_as_buffer*/
462 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
463 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
463 "PythonQtWrapper object", /* tp_doc */
464 "PythonQtWrapper object", /* tp_doc */
464 0, /* tp_traverse */
465 0, /* tp_traverse */
465 0, /* tp_clear */
466 0, /* tp_clear */
466 0, /* tp_richcompare */
467 0, /* tp_richcompare */
467 0, /* tp_weaklistoffset */
468 0, /* tp_weaklistoffset */
468 0, /* tp_iter */
469 0, /* tp_iter */
469 0, /* tp_iternext */
470 0, /* tp_iternext */
470 0, /* tp_methods */
471 0, /* tp_methods */
471 0, /* tp_members */
472 0, /* tp_members */
472 0, /* tp_getset */
473 0, /* tp_getset */
473 0, /* tp_base */
474 0, /* tp_base */
474 0, /* tp_dict */
475 0, /* tp_dict */
475 0, /* tp_descr_get */
476 0, /* tp_descr_get */
476 0, /* tp_descr_set */
477 0, /* tp_descr_set */
477 0, /* tp_dictoffset */
478 0, /* tp_dictoffset */
478 (initproc)PythonQtWrapper_init, /* tp_init */
479 (initproc)PythonQtWrapper_init, /* tp_init */
479 0, /* tp_alloc */
480 0, /* tp_alloc */
480 PythonQtWrapper_new, /* tp_new */
481 PythonQtWrapper_new, /* tp_new */
481 };
482 };
482
483
483 //-------------------------------------------------------
484 //-------------------------------------------------------
484
485
General Comments 0
You need to be logged in to leave comments. Login now