aboutsummaryrefslogtreecommitdiffstats
path: root/libpyside/dynamicqmetaobject.cpp
diff options
context:
space:
mode:
authorRenato Filho <renato.filho@openbossa.org>2011-05-19 18:12:52 -0300
committerHugo Parente Lima <hugo.pl@gmail.com>2012-03-08 16:54:25 -0300
commite13ce9212afb46f86e11f78fee98a1d1e1b1557e (patch)
tree75b6a9c5e616596b2fa5ccda2573d34f22a7dcd3 /libpyside/dynamicqmetaobject.cpp
parent5805ea4e01c463e5eae029a51978bdb1b910aad4 (diff)
Implemented PySide::ClassInfo Object.
This class reproduce the Qt macro Q_CLASSINFO behavior. Eg.: @QtCore.ClassInfo(author='PySide', url='http://www.pyside.org') fixes bug #705. Reviewer: Marcelo Lira <marcelo.lira@openbossa.org> Hugo Parente Lima <hugo.pl@gmail.com>
Diffstat (limited to 'libpyside/dynamicqmetaobject.cpp')
-rw-r--r--libpyside/dynamicqmetaobject.cpp47
1 files changed, 38 insertions, 9 deletions
diff --git a/libpyside/dynamicqmetaobject.cpp b/libpyside/dynamicqmetaobject.cpp
index 73572e3b4..86190fa5d 100644
--- a/libpyside/dynamicqmetaobject.cpp
+++ b/libpyside/dynamicqmetaobject.cpp
@@ -84,6 +84,7 @@ class DynamicQMetaObject::DynamicQMetaObjectPrivate
public:
QList<MethodData> m_methods;
QList<PropertyData> m_properties;
+ QMap<QByteArray, QByteArray> m_info;
QByteArray m_className;
void updateMetaObject(QMetaObject* metaObj);
@@ -380,6 +381,20 @@ void DynamicQMetaObject::addProperty(const char* propertyName, PyObject* data)
m_d->updateMetaObject(this);
}
+void DynamicQMetaObject::addInfo(const char* key, const char* value)
+{
+ m_d->m_info[key] = value;
+}
+
+void DynamicQMetaObject::addInfo(QMap<QByteArray, QByteArray> info)
+{
+ QMap<QByteArray, QByteArray>::const_iterator i = info.constBegin();
+ while (i != info.constEnd()) {
+ m_d->m_info[i.key()] = i.value();
+ ++i;
+ }
+ m_d->updateMetaObject(this);
+}
void DynamicQMetaObject::DynamicQMetaObjectPrivate::writeMethodsData(const QList<MethodData>& methods,
unsigned int** data,
@@ -409,21 +424,22 @@ void DynamicQMetaObject::DynamicQMetaObjectPrivate::updateMetaObject(QMetaObject
{
uint n_methods = m_methods.size();
uint n_properties = m_properties.size();
- int header[] = {3, // revision
- 0, // class name index in m_metadata
- 0, 0, // classinfo and classinfo index, not used by us
- n_methods, 0, // method count and method list index
- n_properties, 0, // prop count and prop indexes
- 0, 0, // enum count and enum index
- 0, 0, // constructors
- 0}; // flags
+ uint n_info = m_info.size();
+ int header[] = {3, // revision
+ 0, // class name index in m_metadata
+ n_info, 0, // classinfo and classinfo index
+ n_methods, 0, // method count and method list index
+ n_properties, 0, // prop count and prop indexes
+ 0, 0, // enum count and enum index
+ 0, 0, // constructors
+ 0}; // flags
const int HEADER_LENGHT = sizeof(header)/sizeof(int);
header[5] = HEADER_LENGHT;
// header size + 5 indexes per method + an ending zero
delete[] metaObj->d.data;
unsigned int* data;
- data = new unsigned int[HEADER_LENGHT + n_methods*5 + n_properties*4 + 1];
+ data = new unsigned int[HEADER_LENGHT + n_methods*5 + n_properties*4 + n_info*2 + 1];
std::memcpy(data, header, sizeof(header));
QList<QByteArray> strings;
@@ -431,6 +447,19 @@ void DynamicQMetaObject::DynamicQMetaObjectPrivate::updateMetaObject(QMetaObject
const int NULL_INDEX = registerString("", &strings); // register a null string
int index = HEADER_LENGHT;
+ //write class info
+ if (n_info) {
+ data[3] = index;
+ QMap<QByteArray, QByteArray>::const_iterator i = m_info.constBegin();
+ while (i != m_info.constEnd()) {
+ int valueIndex = registerString(i.value(), &strings);
+ int keyIndex = registerString(i.key(), &strings);
+ data[index++] = keyIndex;
+ data[index++] = valueIndex;
+ i++;
+ }
+ }
+
//write signals/slots
writeMethodsData(m_methods, &data, &strings, &index, NULL_INDEX, AccessPublic);