Fix generated property flags on metaobject.
Fixes bug #478 Reviewer: Luciano Wolf <luciano.wolf@openbossa.org> Marcelo Lira <marcelo.lira@openbossa.org>
This commit is contained in:
parent
3bc0d023c8
commit
e12197e282
4 changed files with 52 additions and 30 deletions
|
|
@ -132,7 +132,6 @@ static bool isQRealType(const char *type)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Avoid API break keep this on cpp
|
* Avoid API break keep this on cpp
|
||||||
*/
|
*/
|
||||||
|
|
@ -164,25 +163,31 @@ uint PropertyData::flags() const
|
||||||
if (PySide::Property::hasReset(m_data))
|
if (PySide::Property::hasReset(m_data))
|
||||||
flags |= Resettable;
|
flags |= Resettable;
|
||||||
|
|
||||||
if (!PySide::Property::isDesignable(m_data))
|
if (PySide::Property::isDesignable(m_data))
|
||||||
flags |= ResolveDesignable;
|
|
||||||
else
|
|
||||||
flags |= Designable;
|
flags |= Designable;
|
||||||
|
|
||||||
if (!PySide::Property::isScriptable(m_data))
|
|
||||||
flags |= ResolveScriptable;
|
|
||||||
else
|
else
|
||||||
|
flags |= ResolveDesignable;
|
||||||
|
|
||||||
|
if (PySide::Property::isScriptable(m_data))
|
||||||
flags |= Scriptable;
|
flags |= Scriptable;
|
||||||
|
|
||||||
if (!PySide::Property::isStored(m_data))
|
|
||||||
flags |= ResolveStored;
|
|
||||||
else
|
else
|
||||||
|
flags |= ResolveScriptable;
|
||||||
|
|
||||||
|
if (PySide::Property::isStored(m_data))
|
||||||
flags |= Stored;
|
flags |= Stored;
|
||||||
|
|
||||||
if (!PySide::Property::isUser(m_data))
|
|
||||||
flags |= ResolveUser;
|
|
||||||
else
|
else
|
||||||
|
flags |= ResolveStored;
|
||||||
|
|
||||||
|
//EDITABLE
|
||||||
|
flags |= ResolveEditable;
|
||||||
|
|
||||||
|
if (PySide::Property::isUser(m_data))
|
||||||
flags |= User;
|
flags |= User;
|
||||||
|
else
|
||||||
|
flags |= ResolveUser;
|
||||||
|
|
||||||
|
if (m_notifyId != -1)
|
||||||
|
flags |= Notify;
|
||||||
|
|
||||||
if (PySide::Property::isConstant(m_data))
|
if (PySide::Property::isConstant(m_data))
|
||||||
flags |= Constant;
|
flags |= Constant;
|
||||||
|
|
@ -190,9 +195,6 @@ uint PropertyData::flags() const
|
||||||
if (PySide::Property::isFinal(m_data))
|
if (PySide::Property::isFinal(m_data))
|
||||||
flags |= Final;
|
flags |= Final;
|
||||||
|
|
||||||
if (m_notifyId)
|
|
||||||
flags |= Notify;
|
|
||||||
|
|
||||||
return flags;
|
return flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -247,7 +249,7 @@ PropertyData::PropertyData()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
PropertyData::PropertyData(const char* name, uint notifyId, PySideProperty* data)
|
PropertyData::PropertyData(const char* name, int notifyId, PySideProperty* data)
|
||||||
: m_name(name), m_notifyId(notifyId), m_data(data)
|
: m_name(name), m_notifyId(notifyId), m_data(data)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
@ -268,7 +270,7 @@ QByteArray PropertyData::name() const
|
||||||
return m_name;
|
return m_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint PropertyData::notifyId() const
|
int PropertyData::notifyId() const
|
||||||
{
|
{
|
||||||
return m_notifyId;
|
return m_notifyId;
|
||||||
}
|
}
|
||||||
|
|
@ -370,10 +372,10 @@ void DynamicQMetaObject::addProperty(const char* propertyName, PyObject* data)
|
||||||
// retrieve notifyId
|
// retrieve notifyId
|
||||||
PySideProperty* property = reinterpret_cast<PySideProperty*>(data);
|
PySideProperty* property = reinterpret_cast<PySideProperty*>(data);
|
||||||
const char* signalNotify = PySide::Property::getNotifyName(property);
|
const char* signalNotify = PySide::Property::getNotifyName(property);
|
||||||
uint notifyId = 0;
|
int notifyId = -1;
|
||||||
if (signalNotify) {
|
if (signalNotify) {
|
||||||
QByteArray signalSignature(signalNotify);
|
QByteArray signalSignature(signalNotify);
|
||||||
notifyId = m_d->m_signals.indexOf(signalNotify) + 1;
|
notifyId = m_d->m_signals.indexOf(signalNotify);
|
||||||
}
|
}
|
||||||
|
|
||||||
//search for a empty space
|
//search for a empty space
|
||||||
|
|
@ -553,9 +555,8 @@ void DynamicQMetaObject::DynamicQMetaObjectPrivate::updateMetaObject(QMetaObject
|
||||||
}
|
}
|
||||||
|
|
||||||
//write properties notify
|
//write properties notify
|
||||||
foreach(PropertyData pp, m_properties) {
|
foreach(PropertyData pp, m_properties)
|
||||||
data[index++] = pp.notifyId(); //signal notify index
|
data[index++] = pp.notifyId() >= 0 ? pp.notifyId() : 0; //signal notify index
|
||||||
}
|
|
||||||
|
|
||||||
data[index++] = 0; // the end
|
data[index++] = 0; // the end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -54,18 +54,18 @@ namespace PySide
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PropertyData();
|
PropertyData();
|
||||||
PropertyData(const char* name, uint notifyId=0, PySideProperty* data = 0);
|
PropertyData(const char* name, int notifyId=0, PySideProperty* data = 0);
|
||||||
QByteArray name() const;
|
QByteArray name() const;
|
||||||
QByteArray type() const;
|
QByteArray type() const;
|
||||||
uint flags() const;
|
uint flags() const;
|
||||||
bool isValid() const;
|
bool isValid() const;
|
||||||
uint notifyId() const;
|
int notifyId() const;
|
||||||
bool operator==(const PropertyData& other) const;
|
bool operator==(const PropertyData& other) const;
|
||||||
bool operator==(const char* name) const;
|
bool operator==(const char* name) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QByteArray m_name;
|
QByteArray m_name;
|
||||||
uint m_notifyId;
|
int m_notifyId;
|
||||||
PySideProperty* m_data;
|
PySideProperty* m_data;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -117,6 +117,7 @@ int qpropertyTpInit(PyObject* self, PyObject* args, PyObject* kwds)
|
||||||
pData->fget = 0;
|
pData->fget = 0;
|
||||||
pData->freset = 0;
|
pData->freset = 0;
|
||||||
pData->fdel = 0;
|
pData->fdel = 0;
|
||||||
|
pData->final = 0;
|
||||||
pData->designable = true;
|
pData->designable = true;
|
||||||
pData->scriptable = true;
|
pData->scriptable = true;
|
||||||
pData->stored = true;
|
pData->stored = true;
|
||||||
|
|
@ -124,6 +125,7 @@ int qpropertyTpInit(PyObject* self, PyObject* args, PyObject* kwds)
|
||||||
pData->doc = 0;
|
pData->doc = 0;
|
||||||
pData->notify = 0;
|
pData->notify = 0;
|
||||||
pData->notifySignature = 0;
|
pData->notifySignature = 0;
|
||||||
|
pData->constant = 0;
|
||||||
|
|
||||||
static const char *kwlist[] = {"type", "fget", "fset", "freset", "fdel", "doc", "notify",
|
static const char *kwlist[] = {"type", "fget", "fset", "freset", "fdel", "doc", "notify",
|
||||||
"designable", "scriptable", "stored", "user",
|
"designable", "scriptable", "stored", "user",
|
||||||
|
|
@ -134,12 +136,17 @@ int qpropertyTpInit(PyObject* self, PyObject* args, PyObject* kwds)
|
||||||
/*OOO*/ &(pData->fset), &(pData->freset), &(pData->fdel),
|
/*OOO*/ &(pData->fset), &(pData->freset), &(pData->fdel),
|
||||||
/*s*/ &(pData->doc),
|
/*s*/ &(pData->doc),
|
||||||
/*O*/ &(pData->notify),
|
/*O*/ &(pData->notify),
|
||||||
/*bbbbbb*/ &(pData->designable), &(pData->scriptable), &(pData->stored), &(pData->user), &(pData->constant), &(pData->final)))
|
/*bbbbbb*/ &(pData->designable), &(pData->scriptable), &(pData->stored), &(pData->user), &(pData->constant), &(pData->final))) {
|
||||||
|
free(pData);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pData->constant && (pData->fset || pData->notify)) {
|
||||||
|
free(pData);
|
||||||
|
PyErr_SetString(PyExc_AttributeError, "A constant property cannot have a WRITE method or a NOTIFY signal.");
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (!pData->fset && pData->fget)
|
}
|
||||||
pData->constant = true;
|
|
||||||
|
|
||||||
pData->typeName = PySide::Signal::getTypeName(type);
|
pData->typeName = PySide::Signal::getTypeName(type);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -188,6 +188,20 @@ class PropertyWithNotify(unittest.TestCase):
|
||||||
obj.myProperty = 10
|
obj.myProperty = 10
|
||||||
self.assert_(self.called_)
|
self.assert_(self.called_)
|
||||||
|
|
||||||
|
class MetaPropertyTest(unittest.TestCase):
|
||||||
|
def testConstant(self):
|
||||||
|
obj = MyObject()
|
||||||
|
mo = obj.metaObject()
|
||||||
|
self.assertEqual(mo.propertyCount(), 2)
|
||||||
|
p = mo.property(1)
|
||||||
|
self.assertTrue(p.isConstant())
|
||||||
|
|
||||||
|
obj = MyObjectWithNotifyProperty()
|
||||||
|
mo = obj.metaObject()
|
||||||
|
self.assertEqual(mo.propertyCount(), 2)
|
||||||
|
p = mo.property(1)
|
||||||
|
self.assertFalsee(p.isConstant())
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue