SourceForge.net Logo
PythonQt
PythonQtStdDecorators.h
Go to the documentation of this file.
1 #ifndef _PYTHONQTSTDDECORATORS_H
2 #define _PYTHONQTSTDDECORATORS_H
3 
4 /*
5  *
6  * Copyright (C) 2010 MeVis Medical Solutions AG All Rights Reserved.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * Further, this software is distributed without any warranty that it is
19  * free of the rightful claim of any third person regarding infringement
20  * or the like. Any license provided herein, whether implied or
21  * otherwise, applies only to this software file. Patent licenses, if
22  * any, provided herein do not apply to combinations of this program with
23  * other software, or any other product whatsoever.
24  *
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
27  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28  *
29  * Contact information: MeVis Medical Solutions AG, Universitaetsallee 29,
30  * 28359 Bremen, Germany or:
31  *
32  * http://www.mevis.de
33  *
34  */
35 
36 //----------------------------------------------------------------------------------
43 //----------------------------------------------------------------------------------
44 
45 #include "PythonQtPythonInclude.h"
46 
47 #include "PythonQt.h"
48 
49 #include <QObject>
50 #include <QVariantList>
51 #include <QTextDocument>
52 #include <QColor>
53 #include <QDateTime>
54 #include <QDate>
55 #include <QTime>
56 #include <QTimer>
57 #include <QImage>
58 #include <QMetaMethod>
59 #include <QMetaEnum>
60 #include <QMetaProperty>
61 
62 class PYTHONQT_EXPORT PythonQtStdDecorators : public QObject
63 {
64  Q_OBJECT
65 
66 public Q_SLOTS:
67  bool connect(QObject* sender, const QString& signal, PyObject* callable);
68  bool connect(QObject* sender, const QString& signal, QObject* receiver, const QString& slot, Qt::ConnectionType type = Qt::AutoConnection);
69  bool connect(QObject* receiver, QObject* sender, const QString& signal, const QString& slot, Qt::ConnectionType type = Qt::AutoConnection) { return connect(sender, signal, receiver, slot, type); }
70  bool static_QObject_connect(QObject* sender, const QString& signal, PyObject* callable) { return connect(sender, signal, callable); }
71  bool static_QObject_connect(QObject* sender, const QString& signal, QObject* receiver, const QString& slot, Qt::ConnectionType type = Qt::AutoConnection) { return connect(sender, signal, receiver, slot, type); }
72  bool disconnect(QObject* sender, const QString& signal, PyObject* callable = NULL);
73  bool disconnect(QObject* sender, const QString& signal, QObject* receiver, const QString& slot);
74  bool static_QObject_disconnect(QObject* sender, const QString& signal, PyObject* callable = NULL) { return disconnect(sender, signal, callable); }
75  bool static_QObject_disconnect(QObject* sender, const QString& signal, QObject* receiver, const QString& slot) { return connect(sender, signal, receiver, slot); }
76 
77  const QMetaObject* metaObject( QObject* obj );
78 
79  QObject* parent(QObject* o);
80  void setParent(QObject* o, PythonQtNewOwnerOfThis<QObject*> parent);
81 
82  const QObjectList* children(QObject* o);
83  QObject* findChild(QObject* parent, PyObject* type, const QString& name = QString());
84  QList<QObject*> findChildren(QObject* parent, PyObject* type, const QString& name= QString());
85  QList<QObject*> findChildren(QObject* parent, PyObject* type, const QRegExp& regExp);
86 
87  bool setProperty(QObject* o, const char* name, const QVariant& value);
88  QVariant property(QObject* o, const char* name);
89 
90  double static_Qt_qAbs(double a) { return qAbs(a); }
91  double static_Qt_qBound(double a,double b,double c) { return qBound(a,b,c); }
92  void static_Qt_qDebug(const QByteArray& msg) { qDebug("%s", msg.constData()); }
93  // TODO: multi arg qDebug...
94  void static_Qt_qWarning(const QByteArray& msg) { qWarning("%s", msg.constData()); }
95  // TODO: multi arg qWarning...
96  void static_Qt_qCritical(const QByteArray& msg) { qCritical("%s", msg.constData()); }
97  // TODO: multi arg qCritical...
98  void static_Qt_qFatal(const QByteArray& msg) { qFatal("%s", msg.constData()); }
99  // TODO: multi arg qFatal...
100  bool static_Qt_qFuzzyCompare(double a, double b) { return qFuzzyCompare(a, b); }
101  double static_Qt_qMax(double a, double b) { return qMax(a, b); }
102  double static_Qt_qMin(double a, double b) { return qMin(a, b); }
103  int static_Qt_qRound(double a) { return qRound(a); }
104  qint64 static_Qt_qRound64(double a) { return qRound64(a); }
105  const char* static_Qt_qVersion() { return qVersion(); }
106  int static_Qt_qrand() { return qrand(); }
107  void static_Qt_qsrand(uint a) { qsrand(a); }
108 
109  QString tr(QObject* obj, const QByteArray& text, const QByteArray& ambig = QByteArray(), int n = -1);
110 
111  QByteArray static_Qt_SIGNAL(const QByteArray& s) { return QByteArray("2") + s; }
112  QByteArray static_Qt_SLOT(const QByteArray& s) { return QByteArray("1") + s; }
113 
114  void static_QTimer_singleShot(int msec, PyObject* callable);
115 
116 private:
117  QObject* findChild(QObject* parent, const char* typeName, const QMetaObject* meta, const QString& name);
118  int findChildren(QObject* parent, const char* typeName, const QMetaObject* meta, const QString& name, QList<QObject*>& list);
119  int findChildren(QObject* parent, const char* typeName, const QMetaObject* meta, const QRegExp& regExp, QList<QObject*>& list);
120 };
121 
122 class PythonQtSingleShotTimer : public QTimer
123 {
124  Q_OBJECT
125 public:
126  PythonQtSingleShotTimer(int msec, const PythonQtObjectPtr& callable);
127 
128 public Q_SLOTS :
129  void slotTimeout();
130 
131 private:
132  PythonQtObjectPtr _callable;
133 };
134 
135 class PythonQtWrapper_QMetaObject : public QObject
136 {
137  Q_OBJECT
138 
139 public Q_SLOTS:
140  const char *className(QMetaObject* obj) const { return obj->className(); }
141  const QMetaObject *superClass(QMetaObject* obj) const { return obj->superClass(); }
142 
143  int methodOffset(QMetaObject* obj) const { return obj->methodOffset(); }
144  int enumeratorOffset(QMetaObject* obj) const { return obj->enumeratorOffset(); }
145  int propertyOffset(QMetaObject* obj) const { return obj->propertyOffset(); }
146  int classInfoOffset(QMetaObject* obj) const { return obj->classInfoOffset(); }
147 
148  int constructorCount(QMetaObject* obj) const { return obj->constructorCount(); }
149  int methodCount(QMetaObject* obj) const { return obj->methodCount(); }
150  int enumeratorCount(QMetaObject* obj) const { return obj->enumeratorCount(); }
151  int propertyCount(QMetaObject* obj) const { return obj->propertyCount(); }
152  int classInfoCount(QMetaObject* obj) const { return obj->classInfoCount(); }
153 
154  int indexOfConstructor(QMetaObject* obj, const char *constructor) const { return obj->indexOfConstructor(constructor); }
155  int indexOfMethod(QMetaObject* obj, const char *method) const { return obj->indexOfMethod(method); }
156  int indexOfSignal(QMetaObject* obj, const char *signal) const { return obj->indexOfSignal(signal); }
157  int indexOfSlot(QMetaObject* obj, const char *slot) const { return obj->indexOfSlot(slot); }
158  int indexOfEnumerator(QMetaObject* obj, const char *name) const { return obj->indexOfEnumerator(name); }
159  int indexOfProperty(QMetaObject* obj, const char *name) const { return obj->indexOfProperty(name); }
160  int indexOfClassInfo(QMetaObject* obj, const char *name) const { return obj->indexOfClassInfo(name); }
161 
162  QMetaMethod constructor(QMetaObject* obj, int index) const { return obj->constructor(index); }
163  QMetaMethod method(QMetaObject* obj, int index) const { return obj->method(index); }
164  QMetaEnum enumerator(QMetaObject* obj, int index) const { return obj->enumerator(index); }
165  QMetaProperty property(QMetaObject* obj, int index) const { return obj->property(index); }
166  QMetaClassInfo classInfo(QMetaObject* obj, int index) const { return obj->classInfo(index); }
167  QMetaProperty userProperty(QMetaObject* obj) const { return obj->userProperty(); }
168 
169  bool static_QMetaObject_checkConnectArgs(const char *signal, const char *method) { return QMetaObject::checkConnectArgs(signal, method); }
170  QByteArray static_QMetaObject_normalizedSignature(const char *method) { return QMetaObject::normalizedSignature(method); }
171  QByteArray static_QMetaObject_normalizedType(const char *type) { return QMetaObject::normalizedType(type); }
172 
173 };
174 
176 class PYTHONQT_EXPORT PythonQtDebugAPI : public QObject
177 {
178  Q_OBJECT
179  public:
180  PythonQtDebugAPI(QObject* parent):QObject(parent) {};
181 
182  public slots:
184  bool isOwnedByPython(PyObject* object);
186  bool isDerivedShellInstance(PyObject* object);
188  bool hasExtraShellRefCount(PyObject* object);
189 
191  bool passOwnershipToCPP(PyObject* object);
193  bool passOwnershipToPython(PyObject* object);
194 
196  bool isPythonQtInstanceWrapper(PyObject* object);
198  bool isPythonQtClassWrapper(PyObject* object);
199 };
200 
201 #endif
int methodOffset(QMetaObject *obj) const
bool static_QObject_disconnect(QObject *sender, const QString &signal, PyObject *callable=NULL)
int indexOfProperty(QMetaObject *obj, const char *name) const
int indexOfConstructor(QMetaObject *obj, const char *constructor) const
double static_Qt_qMin(double a, double b)
QMetaEnum enumerator(QMetaObject *obj, int index) const
void static_Qt_qCritical(const QByteArray &msg)
QMetaMethod method(QMetaObject *obj, int index) const
QMetaMethod constructor(QMetaObject *obj, int index) const
int classInfoOffset(QMetaObject *obj) const
bool connect(QObject *receiver, QObject *sender, const QString &signal, const QString &slot, Qt::ConnectionType type=Qt::AutoConnection)
int indexOfClassInfo(QMetaObject *obj, const char *name) const
QByteArray static_Qt_SIGNAL(const QByteArray &s)
QByteArray typeName(const QMetaMethod &method)
Definition: PythonQtUtils.h:72
int indexOfSignal(QMetaObject *obj, const char *signal) const
double static_Qt_qBound(double a, double b, double c)
void static_Qt_qFatal(const QByteArray &msg)
int propertyOffset(QMetaObject *obj) const
bool static_QObject_disconnect(QObject *sender, const QString &signal, QObject *receiver, const QString &slot)
bool static_QMetaObject_checkConnectArgs(const char *signal, const char *method)
int methodCount(QMetaObject *obj) const
int classInfoCount(QMetaObject *obj) const
Some helper methods that allow testing of the ownership.
bool static_Qt_qFuzzyCompare(double a, double b)
QMetaProperty userProperty(QMetaObject *obj) const
double static_Qt_qMax(double a, double b)
int constructorCount(QMetaObject *obj) const
int indexOfEnumerator(QMetaObject *obj, const char *name) const
QMetaProperty property(QMetaObject *obj, int index) const
int enumeratorCount(QMetaObject *obj) const
int indexOfMethod(QMetaObject *obj, const char *method) const
QByteArray static_QMetaObject_normalizedType(const char *type)
QMetaClassInfo classInfo(QMetaObject *obj, int index) const
double static_Qt_qAbs(double a)
#define PYTHONQT_EXPORT
void static_Qt_qDebug(const QByteArray &msg)
struct _object PyObject
int propertyCount(QMetaObject *obj) const
void static_Qt_qWarning(const QByteArray &msg)
bool static_QObject_connect(QObject *sender, const QString &signal, PyObject *callable)
QByteArray static_Qt_SLOT(const QByteArray &s)
a smart pointer that stores a PyObject pointer and that handles reference counting automatically ...
PythonQtSingleShotTimer(int msec, const PythonQtObjectPtr &callable)
PythonQtDebugAPI(QObject *parent)
int indexOfSlot(QMetaObject *obj, const char *slot) const
QByteArray static_QMetaObject_normalizedSignature(const char *method)
const QMetaObject * superClass(QMetaObject *obj) const
const char * className(QMetaObject *obj) const
qint64 static_Qt_qRound64(double a)
bool static_QObject_connect(QObject *sender, const QString &signal, QObject *receiver, const QString &slot, Qt::ConnectionType type=Qt::AutoConnection)
int enumeratorOffset(QMetaObject *obj) const