class MOADynamicObject:public QObject
{
public:
- virtual bool hasValue(QString n){return hasMetaValue(this,n);}
- virtual QVariant getValue(QString n){return getMetaValue(this,n);}
+ virtual bool hasValue(QString n)//{return hasMetaValue(this,n);}
+ {
+ const QMetaObject*mobj=metaObject();
+ //look for property
+ int id=mobj->indexOfProperty(n.toLatin1().data());
+ if(id>=0)return true;
+ //look for method
+ id=mobj->indexOfMethod(n.toLatin1().data());
+ if(id<0)return false;
+ QMetaMethod mm=mobj->method(id);
+ if(mm.parameterNames().size()!=0)return false;
+ if(QString(mm.typeName()).isEmpty())return false;
+ return true;
+ }
+ virtual QVariant getValue(QString n)//{return getMetaValue(this,n);}
+ {
+ const QMetaObject*mobj=metaObject();
+ //look for property
+ int id=mobj->indexOfProperty(n.toLatin1().data());
+ if(id>=0)return mobj->property(id).read(this);
+ //look for method
+ id=mobj->indexOfMethod(n.toLatin1().data());
+ if(id<0)return QVariant();
+ QMetaMethod mm=mobj->method(id);
+ if(mm.parameterNames().size()!=0)return QVariant();
+ if(QString(mm.typeName()).isEmpty())return QVariant();
+ //try to invoke
+ int dataid=QMetaType::type(mm.typeName());
+ void *data=QMetaType::create(dataid);
+ QVariant ret;
+ if(mm.invoke(this, Qt::DirectConnection, QGenericReturnArgument(mm.typeName(),data)))
+ ret=QVariant(dataid,data);
+ QMetaType::destroy(dataid,data);
+ return ret;
+ }
};
class MOAItem:public MOADynamicObject