aboutsummaryrefslogtreecommitdiffstats
path: root/libpyside/dynamicqmetaobject.h
blob: 22387a6e3f0ee08a1b11444b8a11055b4b48eb6f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
* This file is part of the PySide project.
*
* Copyright (C) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
*
* Contact: PySide team <contact@pyside.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*/

#ifndef DYNAMICQMETAOBJECT_H
#define DYNAMICQMETAOBJECT_H

#include "pysidemacros.h"
#include <Python.h>
#include <QMetaObject>
#include <QLinkedList>
#include <QByteArray>
#include <QSharedPointer>

#define PYSIDE_SLOT_LIST_ATTR "_slots"

class QObject;

namespace PySide
{

class MethodData
{
public:
    MethodData(){}
    MethodData(const char* signature, const char* type);
    void clear();
    bool isValid() const;
    QByteArray signature() const;
    QByteArray type() const;
    bool operator==(const MethodData& other) const;
    bool operator==(const char* other) const;

private:
    QSharedPointer<QByteArray> m_signature;
    QSharedPointer<QByteArray> m_type;
};

class PropertyData
{
public:
    PropertyData();
    PropertyData(const char*name, PyObject *data);
    QByteArray name() const;
    QByteArray type() const;
    uint flags() const;
    bool isValid() const;
    bool operator==(const PropertyData& other) const;
    bool operator==(const char* name) const;

private:
    QByteArray m_name;
    PyObject* m_data;
};

class PYSIDE_API DynamicQMetaObject : public QMetaObject
{
public:
    DynamicQMetaObject(const char* className, const QMetaObject* metaObject);
    ~DynamicQMetaObject();

    void addSignal(const char* signal, const char* type=0);
    void addSlot(const char* slot, const char* type=0);
    void addProperty(const char* property, PyObject* data);

    void removeSignal(uint idex);
    void removeSlot(uint index);
    void removeProperty(uint index);

    //Retrieve Python metadata to create QMetaObject (class name, signals, slot)
    static DynamicQMetaObject* createBasedOn(PyObject* obj, PyTypeObject* type, const QMetaObject* base);

private:
    QLinkedList<MethodData> m_signals;
    QLinkedList<MethodData> m_slots;
    QLinkedList<PropertyData> m_properties;
    QByteArray m_className;

    void updateMetaObject();
    void writeMethodsData(QLinkedList<MethodData>& methods, unsigned int **data, QList<QByteArray> *strings, int *index, int max_count, int null_index, int flags);
};

PYSIDE_API inline void deleteDynamicQMetaObject(void* data)
{
    delete reinterpret_cast<DynamicQMetaObject*>(data);
}

}
#endif