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
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 >= QT_VERSION_CHECK(5, 15, 0))
62 #include <QRandomGenerator>
63#endif
64
66{
68
69public 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,
72 Qt::ConnectionType type = Qt::AutoConnection);
73 bool connect(QObject* receiver, QObject* sender, const QByteArray& signal, const QByteArray& slot,
74 Qt::ConnectionType type = Qt::AutoConnection)
75 {
76 return connect(sender, signal, receiver, slot, type);
77 }
79 {
80 return connect(sender, signal, callable);
81 }
82 bool static_QObject_connect(QObject* sender, const QByteArray& signal, QObject* receiver, const QByteArray& slot,
83 Qt::ConnectionType type = Qt::AutoConnection)
84 {
85 return connect(sender, signal, receiver, slot, type);
86 }
87 bool disconnect(QObject* sender, const QByteArray& signal, PyObject* callable = nullptr);
88 bool disconnect(QObject* sender, const QByteArray& signal, QObject* receiver, const QByteArray& slot);
90 {
91 return disconnect(sender, signal, callable);
92 }
93 bool static_QObject_disconnect(QObject* sender, const QByteArray& signal, QObject* receiver, const QByteArray& slot)
94 {
95 return disconnect(sender, signal, receiver, slot);
96 }
97
98 const QMetaObject* metaObject(QObject* obj);
99
100 QObject* parent(QObject* o);
102
103 const QObjectList* children(QObject* o);
104 QObject* findChild(QObject* parent, PyObject* type, const QString& name = QString());
105 QList<QObject*> findChildren(QObject* parent, PyObject* type, const QString& name = QString());
107
108 bool setProperty(QObject* o, const char* name, const QVariant& value);
109 QVariant property(QObject* o, const char* name);
110
111 double static_Qt_qAbs(double a) { return qAbs(a); }
112 double static_Qt_qBound(double a, double b, double c) { return qBound(a, b, c); }
113 void static_Qt_qDebug(const QByteArray& msg) { qDebug("%s", msg.constData()); }
114 // TODO: multi arg qDebug...
115 void static_Qt_qWarning(const QByteArray& msg) { qWarning("%s", msg.constData()); }
116 // TODO: multi arg qWarning...
117 void static_Qt_qCritical(const QByteArray& msg) { qCritical("%s", msg.constData()); }
118 // TODO: multi arg qCritical...
119 void static_Qt_qFatal(const QByteArray& msg) { qFatal("%s", msg.constData()); }
120 // TODO: multi arg qFatal...
121 bool static_Qt_qFuzzyCompare(double a, double b) { return qFuzzyCompare(a, b); }
122 double static_Qt_qMax(double a, double b) { return qMax(a, b); }
123 double static_Qt_qMin(double a, double b) { return qMin(a, b); }
124 int static_Qt_qRound(double a) { return qRound(a); }
125 qint64 static_Qt_qRound64(double a) { return qRound64(a); }
126 const char* static_Qt_qVersion() { return qVersion(); }
127
129 {
130#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 0))
131 return qrand();
132#else
133 return QRandomGenerator::global()->generate();
134#endif
135 }
136
138 {
139#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 0))
140 qsrand(a);
141#else
142 QRandomGenerator::global()->seed(a);
143#endif
144 }
145
146 QString tr(QObject* obj, const QString& text, const QString& ambig = QString(), int n = -1);
147
148 QString static_Qt_SIGNAL(const QString& s) { return QString("2") + s; }
149 QString static_Qt_SLOT(const QString& s) { return QString("1") + s; }
150
152
153private:
154 QObject* findChild(QObject* parent, const char* typeName, const QMetaObject* meta, const QString& name);
155 int findChildren(QObject* parent, const char* typeName, const QMetaObject* meta, const QString& name,
157 int findChildren(QObject* parent, const char* typeName, const QMetaObject* meta, const QRegularExpression& regExp,
159};
160
161class PythonQtSingleShotTimer : public QTimer
162{
164public:
167
168public Q_SLOTS:
170
171private:
172 PythonQtObjectPtr _callable;
173};
174
175class PythonQtWrapper_QMetaObject : public QObject
176{
178
179public Q_SLOTS:
180 // Python 3: PythonQt shadows className, so we need an extra getClassName method...
181 const char* getClassName(QMetaObject* obj) const { return obj->className(); }
182 const QMetaObject* superClass(QMetaObject* obj) const { return obj->superClass(); }
183
184 int methodOffset(QMetaObject* obj) const { return obj->methodOffset(); }
185 int enumeratorOffset(QMetaObject* obj) const { return obj->enumeratorOffset(); }
186 int propertyOffset(QMetaObject* obj) const { return obj->propertyOffset(); }
187 int classInfoOffset(QMetaObject* obj) const { return obj->classInfoOffset(); }
188
189 int constructorCount(QMetaObject* obj) const { return obj->constructorCount(); }
190 int methodCount(QMetaObject* obj) const { return obj->methodCount(); }
191 int enumeratorCount(QMetaObject* obj) const { return obj->enumeratorCount(); }
192 int propertyCount(QMetaObject* obj) const { return obj->propertyCount(); }
193 int classInfoCount(QMetaObject* obj) const { return obj->classInfoCount(); }
194
196 {
197 return obj->indexOfConstructor(constructor);
198 }
199 int indexOfMethod(QMetaObject* obj, const char* method) const { return obj->indexOfMethod(method); }
200 int indexOfSignal(QMetaObject* obj, const char* signal) const { return obj->indexOfSignal(signal); }
201 int indexOfSlot(QMetaObject* obj, const char* slot) const { return obj->indexOfSlot(slot); }
202 int indexOfEnumerator(QMetaObject* obj, const char* name) const { return obj->indexOfEnumerator(name); }
203 int indexOfProperty(QMetaObject* obj, const char* name) const { return obj->indexOfProperty(name); }
204 int indexOfClassInfo(QMetaObject* obj, const char* name) const { return obj->indexOfClassInfo(name); }
205
206 QMetaMethod constructor(QMetaObject* obj, int index) const { return obj->constructor(index); }
207 QMetaMethod method(QMetaObject* obj, int index) const { return obj->method(index); }
208 QMetaEnum enumerator(QMetaObject* obj, int index) const { return obj->enumerator(index); }
209 QMetaProperty property(QMetaObject* obj, int index) const { return obj->property(index); }
210 QMetaClassInfo classInfo(QMetaObject* obj, int index) const { return obj->classInfo(index); }
211 QMetaProperty userProperty(QMetaObject* obj) const { return obj->userProperty(); }
212
213 bool static_QMetaObject_checkConnectArgs(const char* signal, const char* method)
214 {
215 return QMetaObject::checkConnectArgs(signal, method);
216 }
218 {
219 return QMetaObject::normalizedSignature(method);
220 }
221 QByteArray static_QMetaObject_normalizedType(const char* type) { return QMetaObject::normalizedType(type); }
222};
223
225class PYTHONQT_EXPORT PythonQtConfigAPI : public QObject
226{
228public:
229 PythonQtConfigAPI(QObject* parent)
230 : QObject(parent) {};
231
232public slots:
236};
237
239class PYTHONQT_EXPORT PythonQtDebugAPI : public QObject
240{
242public:
243 PythonQtDebugAPI(QObject* parent)
244 : QObject(parent) {};
245
246public slots:
253
258
263};
264
265#endif
PyObject * PythonQtConvertPairToPython(const void *inPair, int metaTypeId)
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)
QList< QObject * > findChildren(QObject *parent, PyObject *type, const QString &name=QString())
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)
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())
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)
const QMetaObject * metaObject(QObject *obj)
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)
QList< QObject * > findChildren(QObject *parent, PyObject *type, const QRegularExpression &regExp)
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)
QObject * parent(QObject *o)
bool disconnect(QObject *sender, const QByteArray &signal, PyObject *callable=nullptr)
const QObjectList * children(QObject *o)
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
int indexOfConstructor(QMetaObject *obj, const char *constructor) const
const QMetaObject * superClass(QMetaObject *obj) 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 char * getClassName(QMetaObject *obj) const
int indexOfSignal(QMetaObject *obj, const char *signal) const
QMetaProperty property(QMetaObject *obj, int index) const