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 QByteArray& signal, PyObject* callable);
68  bool connect(QObject* sender, const QByteArray& signal, QObject* receiver, const QByteArray& slot, Qt::ConnectionType type = Qt::AutoConnection);
69  bool connect(QObject* receiver, QObject* sender, const QByteArray& signal, const QByteArray& slot, Qt::ConnectionType type = Qt::AutoConnection) { return connect(sender, signal, receiver, slot, type); }
70  bool static_QObject_connect(QObject* sender, const QByteArray& signal, PyObject* callable) { return connect(sender, signal, callable); }
71  bool static_QObject_connect(QObject* sender, const QByteArray& signal, QObject* receiver, const QByteArray& slot, Qt::ConnectionType type = Qt::AutoConnection) { return connect(sender, signal, receiver, slot, type); }
72  bool disconnect(QObject* sender, const QByteArray& signal, PyObject* callable = NULL);
73  bool disconnect(QObject* sender, const QByteArray& signal, QObject* receiver, const QByteArray& slot);
74  bool static_QObject_disconnect(QObject* sender, const QByteArray& signal, PyObject* callable = NULL) { return disconnect(sender, signal, callable); }
75  bool static_QObject_disconnect(QObject* sender, const QByteArray& signal, QObject* receiver, const QByteArray& slot) { return disconnect(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 QString& text, const QString& ambig = QString(), int n = -1);
110 
111  QString static_Qt_SIGNAL(const QString& s) { return QString("2") + s; }
112  QString static_Qt_SLOT(const QString& s) { return QString("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  // Python 3: PythonQt shadows className, so we need an extra getClassName method...
141  const char *getClassName(QMetaObject* obj) const { return obj->className(); }
142  const QMetaObject *superClass(QMetaObject* obj) const { return obj->superClass(); }
143 
144  int methodOffset(QMetaObject* obj) const { return obj->methodOffset(); }
145  int enumeratorOffset(QMetaObject* obj) const { return obj->enumeratorOffset(); }
146  int propertyOffset(QMetaObject* obj) const { return obj->propertyOffset(); }
147  int classInfoOffset(QMetaObject* obj) const { return obj->classInfoOffset(); }
148 
149  int constructorCount(QMetaObject* obj) const { return obj->constructorCount(); }
150  int methodCount(QMetaObject* obj) const { return obj->methodCount(); }
151  int enumeratorCount(QMetaObject* obj) const { return obj->enumeratorCount(); }
152  int propertyCount(QMetaObject* obj) const { return obj->propertyCount(); }
153  int classInfoCount(QMetaObject* obj) const { return obj->classInfoCount(); }
154 
155  int indexOfConstructor(QMetaObject* obj, const char *constructor) const { return obj->indexOfConstructor(constructor); }
156  int indexOfMethod(QMetaObject* obj, const char *method) const { return obj->indexOfMethod(method); }
157  int indexOfSignal(QMetaObject* obj, const char *signal) const { return obj->indexOfSignal(signal); }
158  int indexOfSlot(QMetaObject* obj, const char *slot) const { return obj->indexOfSlot(slot); }
159  int indexOfEnumerator(QMetaObject* obj, const char *name) const { return obj->indexOfEnumerator(name); }
160  int indexOfProperty(QMetaObject* obj, const char *name) const { return obj->indexOfProperty(name); }
161  int indexOfClassInfo(QMetaObject* obj, const char *name) const { return obj->indexOfClassInfo(name); }
162 
163  QMetaMethod constructor(QMetaObject* obj, int index) const { return obj->constructor(index); }
164  QMetaMethod method(QMetaObject* obj, int index) const { return obj->method(index); }
165  QMetaEnum enumerator(QMetaObject* obj, int index) const { return obj->enumerator(index); }
166  QMetaProperty property(QMetaObject* obj, int index) const { return obj->property(index); }
167  QMetaClassInfo classInfo(QMetaObject* obj, int index) const { return obj->classInfo(index); }
168  QMetaProperty userProperty(QMetaObject* obj) const { return obj->userProperty(); }
169 
170  bool static_QMetaObject_checkConnectArgs(const char *signal, const char *method) { return QMetaObject::checkConnectArgs(signal, method); }
171  QByteArray static_QMetaObject_normalizedSignature(const char *method) { return QMetaObject::normalizedSignature(method); }
172  QByteArray static_QMetaObject_normalizedType(const char *type) { return QMetaObject::normalizedType(type); }
173 
174 };
175 
177 class PYTHONQT_EXPORT PythonQtDebugAPI : public QObject
178 {
179  Q_OBJECT
180  public:
181  PythonQtDebugAPI(QObject* parent):QObject(parent) {};
182 
183  public slots:
185  bool isOwnedByPython(PyObject* object);
190 
195 
200 };
201 
202 #endif
struct _object PyObject
#define PYTHONQT_EXPORT
Some helper methods that allow testing of the ownership.
bool isDerivedShellInstance(PyObject *object)
Returns if the C++ object is an instance of a Python class that derives a C++ class.
bool isOwnedByPython(PyObject *object)
Returns if the C++ object is owned by PythonQt and will be deleted when the reference goes away.
PythonQtDebugAPI(QObject *parent)
bool isPythonQtClassWrapper(PyObject *object)
Returns if the given object is a PythonQt class wrapper (or derived class)
bool isPythonQtInstanceWrapper(PyObject *object)
Returns if the given object is a PythonQt instance wrapper (or derived class)
bool passOwnershipToPython(PyObject *object)
Pass the ownership of the given object to Python (so that the C++ object will be deleted when the Pyt...
bool passOwnershipToCPP(PyObject *object)
Pass the ownership of the given object to CPP (so that it will not be deleted by Python if the refere...
bool hasExtraShellRefCount(PyObject *object)
Returns if the shell instance has an extra ref count from the C++ side.
a smart pointer that stores a PyObject pointer and that handles reference counting automatically
PythonQtSingleShotTimer(int msec, const PythonQtObjectPtr &callable)
bool static_QObject_disconnect(QObject *sender, const QByteArray &signal, PyObject *callable=NULL)
QList< QObject * > findChildren(QObject *parent, PyObject *type, const QRegExp &regExp)
double static_Qt_qMin(double a, double b)
void static_Qt_qDebug(const QByteArray &msg)
double static_Qt_qMax(double a, double b)
bool connect(QObject *receiver, QObject *sender, const QByteArray &signal, const QByteArray &slot, Qt::ConnectionType type=Qt::AutoConnection)
void static_QTimer_singleShot(int msec, PyObject *callable)
void static_Qt_qCritical(const QByteArray &msg)
double static_Qt_qAbs(double a)
QObject * parent(QObject *o)
void static_Qt_qWarning(const QByteArray &msg)
QObject * findChild(QObject *parent, PyObject *type, const QString &name=QString())
const QMetaObject * metaObject(QObject *obj)
QString tr(QObject *obj, const QString &text, const QString &ambig=QString(), int n=-1)
QString static_Qt_SIGNAL(const QString &s)
bool connect(QObject *sender, const QByteArray &signal, PyObject *callable)
bool static_QObject_disconnect(QObject *sender, const QByteArray &signal, QObject *receiver, const QByteArray &slot)
QString static_Qt_SLOT(const QString &s)
void static_Qt_qFatal(const QByteArray &msg)
double static_Qt_qBound(double a, double b, double c)
qint64 static_Qt_qRound64(double a)
bool static_QObject_connect(QObject *sender, const QByteArray &signal, QObject *receiver, const QByteArray &slot, Qt::ConnectionType type=Qt::AutoConnection)
void setParent(QObject *o, PythonQtNewOwnerOfThis< QObject * > parent)
bool static_Qt_qFuzzyCompare(double a, double b)
bool static_QObject_connect(QObject *sender, const QByteArray &signal, PyObject *callable)
bool disconnect(QObject *sender, const QByteArray &signal, QObject *receiver, const QByteArray &slot)
const QObjectList * children(QObject *o)
bool disconnect(QObject *sender, const QByteArray &signal, PyObject *callable=NULL)
QList< QObject * > findChildren(QObject *parent, PyObject *type, const QString &name=QString())
bool connect(QObject *sender, const QByteArray &signal, QObject *receiver, const QByteArray &slot, Qt::ConnectionType type=Qt::AutoConnection)
QVariant property(QObject *o, const char *name)
bool setProperty(QObject *o, const char *name, const QVariant &value)
int methodCount(QMetaObject *obj) const
int indexOfProperty(QMetaObject *obj, const char *name) const
QMetaMethod method(QMetaObject *obj, int index) const
int methodOffset(QMetaObject *obj) const
int enumeratorOffset(QMetaObject *obj) const
int classInfoCount(QMetaObject *obj) const
QMetaClassInfo classInfo(QMetaObject *obj, int index) const
int indexOfClassInfo(QMetaObject *obj, const char *name) const
QMetaEnum enumerator(QMetaObject *obj, int index) const
QByteArray static_QMetaObject_normalizedType(const char *type)
QMetaMethod constructor(QMetaObject *obj, int index) const
int propertyCount(QMetaObject *obj) const
const char * getClassName(QMetaObject *obj) const
int indexOfConstructor(QMetaObject *obj, const char *constructor) const
int indexOfMethod(QMetaObject *obj, const char *method) const
QByteArray static_QMetaObject_normalizedSignature(const char *method)
int enumeratorCount(QMetaObject *obj) const
int propertyOffset(QMetaObject *obj) const
int constructorCount(QMetaObject *obj) const
int indexOfSlot(QMetaObject *obj, const char *slot) const
bool static_QMetaObject_checkConnectArgs(const char *signal, const char *method)
int classInfoOffset(QMetaObject *obj) const
int indexOfEnumerator(QMetaObject *obj, const char *name) const
QMetaProperty userProperty(QMetaObject *obj) const
const QMetaObject * superClass(QMetaObject *obj) const
int indexOfSignal(QMetaObject *obj, const char *signal) const
QMetaProperty property(QMetaObject *obj, int index) const
QByteArray typeName(const QMetaMethod &method)
Definition: PythonQtUtils.h:72