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 #if QT_VERSION >= 0x060000
62 #include <QRandomGenerator>
63 #endif
64 
65 class PYTHONQT_EXPORT PythonQtStdDecorators : public QObject
66 {
67  Q_OBJECT
68 
69 public Q_SLOTS:
70  bool connect(QObject* sender, const QByteArray& signal, PyObject* callable);
71  bool connect(QObject* sender, const QByteArray& signal, QObject* receiver, const QByteArray& slot, Qt::ConnectionType type = Qt::AutoConnection);
72  bool connect(QObject* receiver, QObject* sender, const QByteArray& signal, const QByteArray& slot, Qt::ConnectionType type = Qt::AutoConnection) { return connect(sender, signal, receiver, slot, type); }
73  bool static_QObject_connect(QObject* sender, const QByteArray& signal, PyObject* callable) { return connect(sender, signal, callable); }
74  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); }
75  bool disconnect(QObject* sender, const QByteArray& signal, PyObject* callable = nullptr);
76  bool disconnect(QObject* sender, const QByteArray& signal, QObject* receiver, const QByteArray& slot);
77  bool static_QObject_disconnect(QObject* sender, const QByteArray& signal, PyObject* callable = nullptr) { return disconnect(sender, signal, callable); }
78  bool static_QObject_disconnect(QObject* sender, const QByteArray& signal, QObject* receiver, const QByteArray& slot) { return disconnect(sender, signal, receiver, slot); }
79 
80  const QMetaObject* metaObject( QObject* obj );
81 
82  QObject* parent(QObject* o);
83  void setParent(QObject* o, PythonQtNewOwnerOfThis<QObject*> parent);
84 
85  const QObjectList* children(QObject* o);
86  QObject* findChild(QObject* parent, PyObject* type, const QString& name = QString());
87  QList<QObject*> findChildren(QObject* parent, PyObject* type, const QString& name= QString());
88  QList<QObject*> findChildren(QObject* parent, PyObject* type, const QRegularExpression& regExp);
89 
90  bool setProperty(QObject* o, const char* name, const QVariant& value);
91  QVariant property(QObject* o, const char* name);
92 
93  double static_Qt_qAbs(double a) { return qAbs(a); }
94  double static_Qt_qBound(double a,double b,double c) { return qBound(a,b,c); }
95  void static_Qt_qDebug(const QByteArray& msg) { qDebug("%s", msg.constData()); }
96  // TODO: multi arg qDebug...
97  void static_Qt_qWarning(const QByteArray& msg) { qWarning("%s", msg.constData()); }
98  // TODO: multi arg qWarning...
99  void static_Qt_qCritical(const QByteArray& msg) { qCritical("%s", msg.constData()); }
100  // TODO: multi arg qCritical...
101  void static_Qt_qFatal(const QByteArray& msg) { qFatal("%s", msg.constData()); }
102  // TODO: multi arg qFatal...
103  bool static_Qt_qFuzzyCompare(double a, double b) { return qFuzzyCompare(a, b); }
104  double static_Qt_qMax(double a, double b) { return qMax(a, b); }
105  double static_Qt_qMin(double a, double b) { return qMin(a, b); }
106  int static_Qt_qRound(double a) { return qRound(a); }
107  qint64 static_Qt_qRound64(double a) { return qRound64(a); }
108  const char* static_Qt_qVersion() { return qVersion(); }
109 
111  {
112 #if QT_VERSION < 0x060000
113  return qrand();
114 #else
115  return QRandomGenerator::global()->generate();
116 #endif
117  }
118 
119  void static_Qt_qsrand(uint a)
120  {
121 #if QT_VERSION < 0x060000
122  qsrand(a);
123 #else
124  QRandomGenerator::global()->seed(a);
125 #endif
126  }
127 
128  QString tr(QObject* obj, const QString& text, const QString& ambig = QString(), int n = -1);
129 
130  QString static_Qt_SIGNAL(const QString& s) { return QString("2") + s; }
131  QString static_Qt_SLOT(const QString& s) { return QString("1") + s; }
132 
133  void static_QTimer_singleShot(int msec, PyObject* callable);
134 
135 private:
136  QObject* findChild(QObject* parent, const char* typeName, const QMetaObject* meta, const QString& name);
137  int findChildren(QObject* parent, const char* typeName, const QMetaObject* meta, const QString& name, QList<QObject*>& list);
138  int findChildren(QObject* parent, const char* typeName, const QMetaObject* meta, const QRegularExpression& regExp, QList<QObject*>& list);
139 };
140 
141 class PythonQtSingleShotTimer : public QTimer
142 {
143  Q_OBJECT
144 public:
145  PythonQtSingleShotTimer(int msec, const PythonQtObjectPtr& callable);
147 
148 public Q_SLOTS :
149  void slotTimeout();
150 
151 private:
152  PythonQtObjectPtr _callable;
153 };
154 
155 class PythonQtWrapper_QMetaObject : public QObject
156 {
157  Q_OBJECT
158 
159 public Q_SLOTS:
160  // Python 3: PythonQt shadows className, so we need an extra getClassName method...
161  const char *getClassName(QMetaObject* obj) const { return obj->className(); }
162  const QMetaObject *superClass(QMetaObject* obj) const { return obj->superClass(); }
163 
164  int methodOffset(QMetaObject* obj) const { return obj->methodOffset(); }
165  int enumeratorOffset(QMetaObject* obj) const { return obj->enumeratorOffset(); }
166  int propertyOffset(QMetaObject* obj) const { return obj->propertyOffset(); }
167  int classInfoOffset(QMetaObject* obj) const { return obj->classInfoOffset(); }
168 
169  int constructorCount(QMetaObject* obj) const { return obj->constructorCount(); }
170  int methodCount(QMetaObject* obj) const { return obj->methodCount(); }
171  int enumeratorCount(QMetaObject* obj) const { return obj->enumeratorCount(); }
172  int propertyCount(QMetaObject* obj) const { return obj->propertyCount(); }
173  int classInfoCount(QMetaObject* obj) const { return obj->classInfoCount(); }
174 
175  int indexOfConstructor(QMetaObject* obj, const char *constructor) const { return obj->indexOfConstructor(constructor); }
176  int indexOfMethod(QMetaObject* obj, const char *method) const { return obj->indexOfMethod(method); }
177  int indexOfSignal(QMetaObject* obj, const char *signal) const { return obj->indexOfSignal(signal); }
178  int indexOfSlot(QMetaObject* obj, const char *slot) const { return obj->indexOfSlot(slot); }
179  int indexOfEnumerator(QMetaObject* obj, const char *name) const { return obj->indexOfEnumerator(name); }
180  int indexOfProperty(QMetaObject* obj, const char *name) const { return obj->indexOfProperty(name); }
181  int indexOfClassInfo(QMetaObject* obj, const char *name) const { return obj->indexOfClassInfo(name); }
182 
183  QMetaMethod constructor(QMetaObject* obj, int index) const { return obj->constructor(index); }
184  QMetaMethod method(QMetaObject* obj, int index) const { return obj->method(index); }
185  QMetaEnum enumerator(QMetaObject* obj, int index) const { return obj->enumerator(index); }
186  QMetaProperty property(QMetaObject* obj, int index) const { return obj->property(index); }
187  QMetaClassInfo classInfo(QMetaObject* obj, int index) const { return obj->classInfo(index); }
188  QMetaProperty userProperty(QMetaObject* obj) const { return obj->userProperty(); }
189 
190  bool static_QMetaObject_checkConnectArgs(const char *signal, const char *method) { return QMetaObject::checkConnectArgs(signal, method); }
191  QByteArray static_QMetaObject_normalizedSignature(const char *method) { return QMetaObject::normalizedSignature(method); }
192  QByteArray static_QMetaObject_normalizedType(const char *type) { return QMetaObject::normalizedType(type); }
193 
194 };
195 
197 class PYTHONQT_EXPORT PythonQtConfigAPI : public QObject
198 {
199  Q_OBJECT
200 public:
201  PythonQtConfigAPI(QObject* parent):QObject(parent) {};
202 
203 public slots:
207 };
208 
209 
211 class PYTHONQT_EXPORT PythonQtDebugAPI : public QObject
212 {
213  Q_OBJECT
214  public:
215  PythonQtDebugAPI(QObject* parent):QObject(parent) {};
216 
217  public slots:
219  bool isOwnedByPython(PyObject* object);
224 
229 
234 };
235 
236 #endif
struct _object PyObject
#define PYTHONQT_EXPORT
Some methods to set properties of PythonQt from Python.
PythonQtConfigAPI(QObject *parent)
void setTaskDoneCallback(PyObject *object)
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)
~PythonQtSingleShotTimer() override
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)
bool static_QObject_disconnect(QObject *sender, const QByteArray &signal, PyObject *callable=nullptr)
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=nullptr)
QList< QObject * > findChildren(QObject *parent, PyObject *type, const QString &name=QString())
QList< QObject * > findChildren(QObject *parent, PyObject *type, const QRegularExpression &regExp)
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