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