QSObject QSAEditor::queryQSObject( const QMetaObject *meta, const QString &property, bool /*includeSuperClass*/ ) const { int propertyIndex = -1; const QMetaObject *m = meta; propertyIndex = m->indexOfProperty(property.toLatin1().constData()); if (propertyIndex >= 0) { QMetaProperty mp = m->property(propertyIndex); QSObject o = vTypeToQSType( QString::fromLatin1(mp.typeName()) ); if ( !o.isNull() && !o.isUndefined() ) return o; } m = meta; for (int i=0; i<m->methodCount(); ++i) { QMetaMethod mm = m->method(i); if (mm.methodType() == QMetaMethod::Slot) { QString n = QLatin1String(mm.methodSignature()); n = n.left(n.indexOf('(')); if ( property != n ) continue; return vTypeToQSType(mm.typeName()); } } return env()->createUndefined(); }
QSObject QSAEditor::queryQSObject( const QVector<QObject *> &objects, const QString &property ) const { for ( int i = 0; i < objects.count(); i++ ) { const QMetaObject *mo = objects[i]->metaObject(); QSObject qso = queryQSObject( mo, property, i == 0 ); if ( !qso.isNull() && !qso.isUndefined() ) return qso; } return env()->createUndefined(); }
/*! Returns all the classes declared in the context \a context. \sa functions(), variables() */ QStringList QSInterpreter::classes(QObject *context) const { if (!context) { #if defined( QT_RANGE_CHECK ) qWarning("QSInterpreter::classesOf: context is null"); #endif return QStringList(); } startInterpreter(); QSObject obj = d->interpreter->wrap(context); QStringList lst; if (!obj.isUndefined()) lst = d->interpreter->classesOf(obj); stopInterpreter(); return lst; }
/*! Returns all script functions which have been defined in the context \a context. If \a flags includes \c FunctionSignatures, then each function name returned will be of the following form: \code functionName( typeOfArg1, typeOfArg2, ... ) \endcode Otherwise just the names will be returned (which is the default). \sa classes(), variables() */ QStringList QSInterpreter::functions(QObject *context, FunctionFlags flags) const { if (!context) { #if defined( QT_RANGE_CHECK ) qWarning("QSInterpreter::functions: context is null"); #endif return QStringList(); } startInterpreter(); QStringList lst; QSObject obj = d->interpreter->wrap(context); if (!obj.isUndefined()) lst = d->interpreter->functionsOf(obj, flags & FunctionSignatures); stopInterpreter(); return lst; }
/*! Returns all the variables declared in the contenxt \a context. \sa functions(), classes() */ QStringList QSInterpreter::variables(QObject *context, bool includeStatic, bool includeCustom, bool includeMemberVariables) const { if (!context) { #if defined( QT_RANGE_CHECK ) qWarning("QSInterpreter::variablesOf: context is null"); #endif return QStringList(); } startInterpreter(); QSObject obj = d->interpreter->wrap(context); QStringList lst; if (!obj.isUndefined()) lst = d->interpreter->variablesOf(obj, includeStatic, includeCustom, includeMemberVariables); stopInterpreter(); return lst; }
void QSAEditor::completeQMetaObject( const QMetaObject *meta, const QString &, QVector<CompletionEntry> &res, int flags, QSObject &obj ) { QMap<QString, bool> propMap; bool includeSuperClass = (flags & IncludeSuperClass) == IncludeSuperClass; // properties const QMetaObject *m = meta; int num = m->propertyCount(); for ( int j = 0; j < num; ++j ) { const QMetaProperty mp = m->property( j ); if ( propMap.find( QString::fromLatin1(mp.name()) ) != propMap.end() ) continue; CompletionEntry c; propMap[QLatin1String(mp.name())] = false; c.type = QLatin1String("property"); c.text = mp.name(); c.prefix = QString(); c.postfix2 = mp.typeName(); QuickInterpreter::cleanType( c.postfix2 ); if ( !c.postfix2.isEmpty() ) c.postfix2.prepend( QLatin1String(" : ") ); res.append( c ); } if ( includeSuperClass && obj.isValid() && !obj.isUndefined() ) { QStringList vars = interpreter()->variablesOf( obj, true ); QStringList::iterator it; for ( it = vars.begin(); it != vars.end(); ++it ) { CompletionEntry c; c.type = QLatin1String("variable"); c.text = *it; c.prefix = QString(); c.postfix2 = QString(); res << c; } } // functions QList<Property> lst; QList<Property>::Iterator pit; getSlots( meta, lst, includeSuperClass, false, false ); for ( pit = lst.begin(); pit != lst.end(); ++pit ) { CompletionEntry c; c.type = QLatin1String("function"); c.text = (*pit).name; c.postfix = QLatin1String("()"); c.postfix2 = (*pit).type; if ( !c.postfix2.isEmpty() ) c.postfix2.prepend( QString::fromLatin1(" : ") ); res << c; } if ( includeSuperClass && obj.isValid() && !obj.isUndefined() ) { QStringList funcs = interpreter()->functionsOf( obj, true, true, true ); QStringList::Iterator it; for ( it = funcs.begin(); it != funcs.end(); ++it ) { CompletionEntry c; c.type = QLatin1String("function"); c.text = *it; c.prefix = QString(); c.postfix2 = QString(); res << c; } } // enum values m = meta; for (int k=0; k<m->enumeratorCount(); ++k) { QMetaEnum me = m->enumerator(k); for (int l=0; l<me.keyCount(); ++l) { CompletionEntry c; c.type = QLatin1String("enum"); c.text = QLatin1String(me.key(l)); c.prefix = QString(); c.postfix2 = QLatin1String(me.name()); if (!c.postfix2.isEmpty()) c.postfix2.prepend( QString::fromLatin1(" : ") ); res << c; } } if ( includeSuperClass && obj.isValid() && !obj.isUndefined() ) { QStringList classes = interpreter()->classesOf( obj ); QStringList::Iterator it; for ( it = classes.begin(); it != classes.end(); ++it ) { CompletionEntry c; c.type = QLatin1String("class"); c.text = *it; c.prefix = QString(); c.postfix2 = QString(); res << c; } } }