Qt 4.8
Public Functions | Protected Functions | Private Functions | Static Private Functions | Properties | List of all members
QDeclarativeObjectMethodScriptClass Class Reference

#include <qdeclarativeobjectscriptclass_p.h>

Inheritance diagram for QDeclarativeObjectMethodScriptClass:
QScriptDeclarativeClass

Public Functions

QScriptValue newMethod (QObject *, const QDeclarativePropertyCache::Data *)
 
 QDeclarativeObjectMethodScriptClass (QDeclarativeEngine *)
 
 ~QDeclarativeObjectMethodScriptClass ()
 
- Public Functions inherited from QScriptDeclarativeClass
virtual bool compare (Object *, Object *)
 
QScriptContextcontext () const
 
PersistentIdentifier createPersistentIdentifier (const QString &)
 
PersistentIdentifier createPersistentIdentifier (const Identifier &)
 
QScriptEngineengine () const
 
virtual bool isQObject () const
 
virtual QScriptValue::PropertyFlags propertyFlags (Object *, const Identifier &)
 
virtual QStringList propertyNames (Object *)
 
 QScriptDeclarativeClass (QScriptEngine *engine)
 
virtual void setProperty (Object *, const Identifier &name, const QScriptValue &)
 
void setSupportsCall (bool)
 
bool startsWithUpper (const Identifier &)
 
bool supportsCall () const
 
quint32 toArrayIndex (const Identifier &, bool *ok)
 
virtual QObjecttoQObject (Object *, bool *ok=0)
 
QString toString (const Identifier &)
 
virtual QVariant toVariant (Object *, bool *ok=0)
 
virtual ~QScriptDeclarativeClass ()
 

Protected Functions

virtual Value call (Object *, QScriptContext *)
 
virtual Value property (Object *, const Identifier &)
 
virtual QScriptClass::QueryFlags queryProperty (Object *, const Identifier &, QScriptClass::QueryFlags flags)
 

Private Functions

Value callMethod (QObject *, int index, int returnType, int argCount, int *argTypes, QScriptContext *ctxt)
 
Value callOverloaded (MethodData *, QScriptContext *)
 Resolve the overloaded method to call. More...
 
Value callPrecise (QObject *, const QDeclarativePropertyCache::Data &, QScriptContext *)
 
int enumType (const QMetaObject *, const QString &)
 
int matchScore (const QScriptValue &, int, const QByteArray &)
 Returns the match score for converting actual to be of type conversionType. More...
 
QDeclarativePropertyCache::DatarelatedMethod (QObject *, QDeclarativePropertyCache::Data *current, QDeclarativePropertyCache::Data &dummy)
 Returns the next related method, if one, or 0. More...
 

Static Private Functions

static QScriptValue connect (QScriptContext *context, QScriptEngine *engine)
 
static QScriptValue disconnect (QScriptContext *context, QScriptEngine *engine)
 

Properties

QDeclarativeEngineengine
 
QScriptValue m_connect
 
PersistentIdentifier m_connectId
 
QScriptValue m_disconnect
 
PersistentIdentifier m_disconnectId
 

Additional Inherited Members

- Public Types inherited from QScriptDeclarativeClass
typedef void * Identifier
 
- Static Public Functions inherited from QScriptDeclarativeClass
static QScriptValue function (const QScriptValue &, const Identifier &)
 
static Value functionValue (const QScriptValue &, const Identifier &)
 
static QScriptValue newObject (QScriptEngine *, QScriptDeclarativeClass *, Object *)
 
static Value newObjectValue (QScriptEngine *, QScriptDeclarativeClass *, Object *)
 
static QScriptValue newStaticScopeObject (QScriptEngine *, int propertyCount, const QString *names, const QScriptValue *values, const QScriptValue::PropertyFlags *flags)
 Creates a scope object with a fixed set of undeletable properties. More...
 
static QScriptValue newStaticScopeObject (QScriptEngine *)
 Creates a static scope object that's initially empty, but to which new properties can be added. More...
 
static Objectobject (const QScriptValue &)
 
static QScriptValue property (const QScriptValue &, const Identifier &)
 
static Value propertyValue (const QScriptValue &, const Identifier &)
 
static QScriptContextpushCleanContext (QScriptEngine *)
 Enters a new execution context and returns the associated QScriptContext object. More...
 
static QScriptValue scopeChainValue (QScriptContext *, int index)
 
static QScriptDeclarativeClassscriptClass (const QScriptValue &)
 
- Protected Variables inherited from QScriptDeclarativeClass
QScopedPointer< QScriptDeclarativeClassPrivated_ptr
 

Detailed Description

Definition at line 70 of file qdeclarativeobjectscriptclass_p.h.

Constructors and Destructors

◆ QDeclarativeObjectMethodScriptClass()

QDeclarativeObjectMethodScriptClass::QDeclarativeObjectMethodScriptClass ( QDeclarativeEngine bindEngine)

Definition at line 571 of file qdeclarativeobjectscriptclass.cpp.

573  engine(bindEngine)
574 {
575  qRegisterMetaType<QList<QObject *> >("QList<QObject *>");
576 
577  setSupportsCall(true);
578 
580 
581  m_connect = scriptEngine->newFunction(connect);
583  m_disconnect = scriptEngine->newFunction(disconnect);
585 }
QScriptValue newFunction(FunctionSignature signature, int length=0)
Creates a QScriptValue that wraps a native (C++) function.
static QScriptEngine * getScriptEngine(QDeclarativeEngine *e)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
PersistentIdentifier createPersistentIdentifier(const QString &)
The QScriptEngine class provides an environment for evaluating Qt Script code.
QScriptEngine * engine() const
static QScriptValue connect(QScriptContext *context, QScriptEngine *engine)
static QScriptValue disconnect(QScriptContext *context, QScriptEngine *engine)
QScriptDeclarativeClass(QScriptEngine *engine)

◆ ~QDeclarativeObjectMethodScriptClass()

QDeclarativeObjectMethodScriptClass::~QDeclarativeObjectMethodScriptClass ( )

Definition at line 587 of file qdeclarativeobjectscriptclass.cpp.

588 {
589 }

Functions

◆ call()

QDeclarativeObjectMethodScriptClass::Value QDeclarativeObjectMethodScriptClass::call ( Object o,
QScriptContext ctxt 
)
protectedvirtual

Reimplemented from QScriptDeclarativeClass.

Definition at line 917 of file qdeclarativeobjectscriptclass.cpp.

918 {
919  MethodData *method = static_cast<MethodData *>(o);
920 
921  if (method->data.relatedIndex == -1)
922  return callPrecise(method->object, method->data, ctxt);
923  else
924  return callOverloaded(method, ctxt);
925 }
Value callPrecise(QObject *, const QDeclarativePropertyCache::Data &, QScriptContext *)
QDeclarativePropertyCache::Data data
Value callOverloaded(MethodData *, QScriptContext *)
Resolve the overloaded method to call.
QDeclarativeGuard< QObject > object

◆ callMethod()

QDeclarativeObjectMethodScriptClass::Value QDeclarativeObjectMethodScriptClass::callMethod ( QObject object,
int  index,
int  returnType,
int  argCount,
int *  argTypes,
QScriptContext ctxt 
)
private

Definition at line 959 of file qdeclarativeobjectscriptclass.cpp.

Referenced by callPrecise().

962 {
963  if (argCount > 0) {
964 
965  QVarLengthArray<MetaCallArgument, 9> args(argCount + 1);
966  args[0].initAsType(returnType, engine);
967 
968  for (int ii = 0; ii < argCount; ++ii)
969  args[ii + 1].fromScriptValue(argTypes[ii], engine, ctxt->argument(ii));
970 
971  QVarLengthArray<void *, 9> argData(args.count());
972  for (int ii = 0; ii < args.count(); ++ii)
973  argData[ii] = args[ii].dataPtr();
974 
976 
977  return args[0].toValue(engine);
978 
979  } else if (returnType != 0) {
980 
981  MetaCallArgument arg;
982  arg.initAsType(returnType, engine);
983 
984  void *args[] = { arg.dataPtr() };
985 
987 
988  return arg.toValue(engine);
989 
990  } else {
991 
992  void *args[] = { 0 };
994  return Value();
995 
996  }
997 }
static int metacall(QObject *, Call, int, void **)
QScriptEngine * engine() const
static JSAgentWatchData fromScriptValue(const QString &expression, const QScriptValue &value)
quint16 index
QScriptValue argument(int index) const
Returns the function argument at the given index.

◆ callOverloaded()

QDeclarativeObjectMethodScriptClass::Value QDeclarativeObjectMethodScriptClass::callOverloaded ( MethodData method,
QScriptContext ctxt 
)
private

Resolve the overloaded method to call.

The algorithm works conceptually like this:

  1. Resolve the set of overloads it is possible to call. Impossible overloads include those that have too many parameters or have parameters of unknown type.
  2. Filter the set of overloads to only contain those with the closest number of parameters. For example, if we are called with 3 parameters and there are 2 overloads that take 2 parameters and one that takes 3, eliminate the 2 parameter overloads.
  3. Find the best remaining overload based on its match score. If two or more overloads have the same match score, call the last one. The match score is constructed by adding the matchScore() result for each of the parameters.

Definition at line 1013 of file qdeclarativeobjectscriptclass.cpp.

Referenced by call().

1014 {
1015  int argumentCount = ctxt->argumentCount();
1016 
1018  int bestParameterScore = INT_MAX;
1019  int bestMatchScore = INT_MAX;
1020 
1022  QDeclarativePropertyCache::Data *attempt = &method->data;
1023 
1024  do {
1025  QList<QByteArray> methodArgTypeNames;
1026 
1028  methodArgTypeNames = method->object->metaObject()->method(attempt->coreIndex).parameterTypes();
1029 
1030  int methodArgumentCount = methodArgTypeNames.count();
1031 
1032  if (methodArgumentCount > argumentCount)
1033  continue; // We don't have sufficient arguments to call this method
1034 
1035  int methodParameterScore = argumentCount - methodArgumentCount;
1036  if (methodParameterScore > bestParameterScore)
1037  continue; // We already have a better option
1038 
1039  int methodMatchScore = 0;
1040  QVarLengthArray<int, 9> methodArgTypes(methodArgumentCount);
1041 
1042  bool unknownArgument = false;
1043  for (int ii = 0; ii < methodArgumentCount; ++ii) {
1044  methodArgTypes[ii] = QMetaType::type(methodArgTypeNames.at(ii));
1045  if (methodArgTypes[ii] == QVariant::Invalid)
1046  methodArgTypes[ii] = enumType(method->object->metaObject(),
1047  QString::fromLatin1(methodArgTypeNames.at(ii)));
1048  if (methodArgTypes[ii] == QVariant::Invalid) {
1049  unknownArgument = true;
1050  break;
1051  }
1052  methodMatchScore += matchScore(ctxt->argument(ii), methodArgTypes[ii], methodArgTypeNames.at(ii));
1053  }
1054  if (unknownArgument)
1055  continue; // We don't understand all the parameters
1056 
1057  if (bestParameterScore > methodParameterScore || bestMatchScore > methodMatchScore) {
1058  best = attempt;
1059  bestParameterScore = methodParameterScore;
1060  bestMatchScore = methodMatchScore;
1061  }
1062 
1063  if (bestParameterScore == 0 && bestMatchScore == 0)
1064  break; // We can't get better than that
1065 
1066  } while((attempt = relatedMethod(method->object, attempt, dummy)) != 0);
1067 
1068  if (best) {
1069  return callPrecise(method->object, *best, ctxt);
1070  } else {
1071  QString error = QLatin1String("Unable to determine callable overload. Candidates are:");
1072  QDeclarativePropertyCache::Data *candidate = &method->data;
1073  while (candidate) {
1074  error += QLatin1String("\n ") + QString::fromUtf8(method->object->metaObject()->method(candidate->coreIndex).signature());
1075  candidate = relatedMethod(method->object, candidate, dummy);
1076  }
1077  return Value(ctxt, ctxt->throwError(error));
1078  }
1079 }
Value callPrecise(QObject *, const QDeclarativePropertyCache::Data &, QScriptContext *)
#define error(msg)
QScriptValue throwError(Error error, const QString &text)
Throws an error with the given text.
QDeclarativePropertyCache::Data data
int matchScore(const QScriptValue &, int, const QByteArray &)
Returns the match score for converting actual to be of type conversionType.
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
The QString class provides a Unicode character string.
Definition: qstring.h:83
int enumType(const QMetaObject *, const QString &)
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
static QString fromUtf8(const char *, int size=-1)
Returns a QString initialized with the first size bytes of the UTF-8 string str.
Definition: qstring.cpp:4302
QDeclarativeGuard< QObject > object
static int type(const char *typeName)
Returns a handle to the type called typeName, or 0 if there is no such type.
Definition: qmetatype.cpp:607
int argumentCount() const
Returns the number of arguments passed to the function in this invocation.
QList< QByteArray > parameterTypes() const
Returns a list of parameter types.
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
QDeclarativePropertyCache::Data * relatedMethod(QObject *, QDeclarativePropertyCache::Data *current, QDeclarativePropertyCache::Data &dummy)
Returns the next related method, if one, or 0.
QMetaMethod method(int index) const
Returns the meta-data for the method with the given index.
const char * signature() const
Returns the signature of this method (e.g., setValue(double)).
QScriptValue argument(int index) const
Returns the function argument at the given index.
#define INT_MAX
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.

◆ callPrecise()

QDeclarativeObjectMethodScriptClass::Value QDeclarativeObjectMethodScriptClass::callPrecise ( QObject object,
const QDeclarativePropertyCache::Data data,
QScriptContext ctxt 
)
private

Definition at line 928 of file qdeclarativeobjectscriptclass.cpp.

Referenced by call(), and callOverloaded().

930 {
932 
933  QMetaMethod m = object->metaObject()->method(data.coreIndex);
934  QList<QByteArray> argTypeNames = m.parameterTypes();
935  QVarLengthArray<int, 9> argTypes(argTypeNames.count());
936 
937  // ### Cache
938  for (int ii = 0; ii < argTypeNames.count(); ++ii) {
939  argTypes[ii] = QMetaType::type(argTypeNames.at(ii));
940  if (argTypes[ii] == QVariant::Invalid)
941  argTypes[ii] = enumType(object->metaObject(), QString::fromLatin1(argTypeNames.at(ii)));
942  if (argTypes[ii] == QVariant::Invalid)
943  return Value(ctxt, ctxt->throwError(QString::fromLatin1("Unknown method parameter type: %1").arg(QLatin1String(argTypeNames.at(ii)))));
944  }
945 
946  if (argTypes.count() > ctxt->argumentCount())
947  return Value(ctxt, ctxt->throwError(QLatin1String("Insufficient arguments")));
948 
949  return callMethod(object, data.coreIndex, data.propType, argTypes.count(), argTypes.data(), ctxt);
950 
951  } else {
952 
953  return callMethod(object, data.coreIndex, data.propType, 0, 0, ctxt);
954 
955  }
956 }
QScriptValue throwError(Error error, const QString &text)
Throws an error with the given text.
Value callMethod(QObject *, int index, int returnType, int argCount, int *argTypes, QScriptContext *ctxt)
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
int enumType(const QMetaObject *, const QString &)
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
static int type(const char *typeName)
Returns a handle to the type called typeName, or 0 if there is no such type.
Definition: qmetatype.cpp:607
int argumentCount() const
Returns the number of arguments passed to the function in this invocation.
QList< QByteArray > parameterTypes() const
Returns a list of parameter types.
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
Definition: qstring.cpp:7186
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
The QMetaMethod class provides meta-data about a member function.
Definition: qmetaobject.h:56
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.

◆ connect()

QScriptValue QDeclarativeObjectMethodScriptClass::connect ( QScriptContext context,
QScriptEngine engine 
)
staticprivate

Definition at line 598 of file qdeclarativeobjectscriptclass.cpp.

Referenced by QDeclarativeObjectMethodScriptClass().

599 {
601 
602  QScriptValue that = context->thisObject();
603  if (&p->objectClass->methods != scriptClass(that))
604  return engine->undefinedValue();
605 
606  MethodData *data = (MethodData *)object(that);
607 
608  if (!data->object || context->argumentCount() == 0)
609  return engine->undefinedValue();
610 
611  QByteArray signal("2");
612  signal.append(data->object->metaObject()->method(data->data.coreIndex).signature());
613 
614  if (context->argumentCount() == 1) {
615  qScriptConnect(data->object, signal.constData(), QScriptValue(), context->argument(0));
616  } else {
617  qScriptConnect(data->object, signal.constData(), context->argument(0), context->argument(1));
618  }
619 
620  return engine->undefinedValue();
621 }
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QDeclarativePropertyCache::Data data
static QDeclarativeEnginePrivate * get(QDeclarativeEngine *e)
QDeclarativeGuard< QObject > object
static const char * data(const QByteArray &arr)
int argumentCount() const
Returns the number of arguments passed to the function in this invocation.
QDeclarativeObjectMethodScriptClass methods
QDeclarativeObjectScriptClass * objectClass
Q_SCRIPT_EXPORT bool qScriptConnect(QObject *sender, const char *signal, const QScriptValue &receiver, const QScriptValue &function)
static QScriptDeclarativeClass * scriptClass(const QScriptValue &)
QMetaMethod method(int index) const
Returns the meta-data for the method with the given index.
QScriptValue undefinedValue()
Returns a QScriptValue of the primitive type Undefined.
const char * signature() const
Returns the signature of this method (e.g., setValue(double)).
QScriptValue thisObject() const
Returns the `this&#39; object associated with this QScriptContext.
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57
QScriptValue argument(int index) const
Returns the function argument at the given index.
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.

◆ disconnect()

QScriptValue QDeclarativeObjectMethodScriptClass::disconnect ( QScriptContext context,
QScriptEngine engine 
)
staticprivate

Definition at line 623 of file qdeclarativeobjectscriptclass.cpp.

Referenced by QDeclarativeObjectMethodScriptClass().

624 {
626 
627  QScriptValue that = context->thisObject();
628  if (&p->objectClass->methods != scriptClass(that))
629  return engine->undefinedValue();
630 
631  MethodData *data = (MethodData *)object(that);
632 
633  if (!data->object || context->argumentCount() == 0)
634  return engine->undefinedValue();
635 
636  QByteArray signal("2");
637  signal.append(data->object->metaObject()->method(data->data.coreIndex).signature());
638 
639  if (context->argumentCount() == 1) {
640  qScriptDisconnect(data->object, signal.constData(), QScriptValue(), context->argument(0));
641  } else {
642  qScriptDisconnect(data->object, signal.constData(), context->argument(0), context->argument(1));
643  }
644 
645  return engine->undefinedValue();
646 }
Q_SCRIPT_EXPORT bool qScriptDisconnect(QObject *sender, const char *signal, const QScriptValue &receiver, const QScriptValue &function)
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QDeclarativePropertyCache::Data data
static QDeclarativeEnginePrivate * get(QDeclarativeEngine *e)
QDeclarativeGuard< QObject > object
static const char * data(const QByteArray &arr)
int argumentCount() const
Returns the number of arguments passed to the function in this invocation.
QDeclarativeObjectMethodScriptClass methods
QDeclarativeObjectScriptClass * objectClass
static QScriptDeclarativeClass * scriptClass(const QScriptValue &)
QMetaMethod method(int index) const
Returns the meta-data for the method with the given index.
QScriptValue undefinedValue()
Returns a QScriptValue of the primitive type Undefined.
const char * signature() const
Returns the signature of this method (e.g., setValue(double)).
QScriptValue thisObject() const
Returns the `this&#39; object associated with this QScriptContext.
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57
QScriptValue argument(int index) const
Returns the function argument at the given index.
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.

◆ enumType()

int QDeclarativeObjectMethodScriptClass::enumType ( const QMetaObject meta,
const QString strname 
)
private

Definition at line 897 of file qdeclarativeobjectscriptclass.cpp.

Referenced by callOverloaded(), and callPrecise().

898 {
899  QByteArray str = strname.toUtf8();
900  QByteArray scope;
902  int scopeIdx = str.lastIndexOf("::");
903  if (scopeIdx != -1) {
904  scope = str.left(scopeIdx);
905  name = str.mid(scopeIdx + 2);
906  } else {
907  name = str;
908  }
909  for (int i = meta->enumeratorCount() - 1; i >= 0; --i) {
910  QMetaEnum m = meta->enumerator(i);
911  if ((m.name() == name) && (scope.isEmpty() || (m.scope() == scope)))
912  return QVariant::Int;
913  }
914  return QVariant::Invalid;
915 }
The QMetaEnum class provides meta-data about an enumerator.
Definition: qmetaobject.h:147
QByteArray toUtf8() const Q_REQUIRED_RESULT
Returns a UTF-8 representation of the string as a QByteArray.
Definition: qstring.cpp:4074
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
const char * scope() const
Returns the scope this enumerator was declared in.
const char * name() const
Returns the name of the enumerator (without the scope).
int lastIndexOf(char c, int from=-1) const
Returns the index position of the last occurrence of character ch in the byte array, searching backward from index position from.
const char * name
int enumeratorCount() const
Returns the number of enumerators in this class.
QByteArray left(int len) const
Returns a byte array that contains the leftmost len bytes of this byte array.
QByteArray mid(int index, int len=-1) const
Returns a byte array containing len bytes from this byte array, starting at position pos...
QMetaEnum enumerator(int index) const
Returns the meta-data for the enumerator with the given index.
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421

◆ matchScore()

int QDeclarativeObjectMethodScriptClass::matchScore ( const QScriptValue actual,
int  conversionType,
const QByteArray conversionTypeName 
)
private

Returns the match score for converting actual to be of type conversionType.

A zero score means "perfect match" whereas a higher score is worse.

The conversion table is copied out of the QtScript callQtMethod() function.

Definition at line 1087 of file qdeclarativeobjectscriptclass.cpp.

Referenced by callOverloaded().

1089 {
1090  if (actual.isNumber()) {
1091  switch (conversionType) {
1092  case QMetaType::Double:
1093  return 0;
1094  case QMetaType::Float:
1095  return 1;
1096  case QMetaType::LongLong:
1097  case QMetaType::ULongLong:
1098  return 2;
1099  case QMetaType::Long:
1100  case QMetaType::ULong:
1101  return 3;
1102  case QMetaType::Int:
1103  case QMetaType::UInt:
1104  return 4;
1105  case QMetaType::Short:
1106  case QMetaType::UShort:
1107  return 5;
1108  break;
1109  case QMetaType::Char:
1110  case QMetaType::UChar:
1111  return 6;
1112  default:
1113  return 10;
1114  }
1115  } else if (actual.isString()) {
1116  switch (conversionType) {
1117  case QMetaType::QString:
1118  return 0;
1119  default:
1120  return 10;
1121  }
1122  } else if (actual.isBoolean()) {
1123  switch (conversionType) {
1124  case QMetaType::Bool:
1125  return 0;
1126  default:
1127  return 10;
1128  }
1129  } else if (actual.isDate()) {
1130  switch (conversionType) {
1131  case QMetaType::QDateTime:
1132  return 0;
1133  case QMetaType::QDate:
1134  return 1;
1135  case QMetaType::QTime:
1136  return 2;
1137  default:
1138  return 10;
1139  }
1140  } else if (actual.isRegExp()) {
1141  switch (conversionType) {
1142  case QMetaType::QRegExp:
1143  return 0;
1144  default:
1145  return 10;
1146  }
1147  } else if (actual.isVariant()) {
1148  if (conversionType == qMetaTypeId<QVariant>())
1149  return 0;
1150  else if (actual.toVariant().userType() == conversionType)
1151  return 0;
1152  else
1153  return 10;
1154  } else if (actual.isArray()) {
1155  switch (conversionType) {
1158  return 5;
1159  default:
1160  return 10;
1161  }
1162  } else if (actual.isQObject()) {
1163  switch (conversionType) {
1165  return 0;
1166  default:
1167  return 10;
1168  }
1169  } else if (actual.isNull()) {
1170  switch (conversionType) {
1171  case QMetaType::VoidStar:
1173  return 0;
1174  default:
1175  if (!conversionTypeName.endsWith('*'))
1176  return 10;
1177  else
1178  return 0;
1179  }
1180  } else {
1181  return 10;
1182  }
1183 }
bool isNull() const
Returns true if this QScriptValue is of the primitive type Null; otherwise returns false...
bool isBoolean() const
Use isBool() instead.
bool isString() const
Returns true if this QScriptValue is of the primitive type String; otherwise returns false...
QVariant toVariant() const
Returns the QVariant value of this QScriptValue, if it can be converted to a QVariant; otherwise retu...
bool isVariant() const
Returns true if this QScriptValue is a variant value; otherwise returns false.
bool isNumber() const
Returns true if this QScriptValue is of the primitive type Number; otherwise returns false...
int userType() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1913
bool isRegExp() const
Returns true if this QScriptValue is an object of the RegExp class; otherwise returns false...
bool isQObject() const
Returns true if this QScriptValue is a QObject; otherwise returns false.
bool isDate() const
Returns true if this QScriptValue is an object of the Date class; otherwise returns false...
bool isArray() const
Returns true if this QScriptValue is an object of the Array class; otherwise returns false...
bool endsWith(const QByteArray &a) const
Returns true if this byte array ends with byte array ba; otherwise returns false. ...

◆ newMethod()

QScriptValue QDeclarativeObjectMethodScriptClass::newMethod ( QObject object,
const QDeclarativePropertyCache::Data method 
)

Definition at line 591 of file qdeclarativeobjectscriptclass.cpp.

Referenced by QDeclarativeObjectScriptClass::property().

592 {
594 
595  return newObject(scriptEngine, this, new MethodData(object, *method));
596 }
static QScriptEngine * getScriptEngine(QDeclarativeEngine *e)
static QScriptValue newObject(QScriptEngine *, QScriptDeclarativeClass *, Object *)
The QScriptEngine class provides an environment for evaluating Qt Script code.
QScriptEngine * engine() const

◆ property()

QDeclarativeObjectMethodScriptClass::Value QDeclarativeObjectMethodScriptClass::property ( Object ,
const Identifier name 
)
protectedvirtual

Reimplemented from QScriptDeclarativeClass.

Definition at line 661 of file qdeclarativeobjectscriptclass.cpp.

662 {
664 
665  if (name == m_connectId.identifier)
666  return Value(scriptEngine, m_connect);
667  else if (name == m_disconnectId.identifier)
668  return Value(scriptEngine, m_disconnect);
669  else
670  return Value();
671 }
static QScriptEngine * getScriptEngine(QDeclarativeEngine *e)
The QScriptEngine class provides an environment for evaluating Qt Script code.
const char * name
QScriptEngine * engine() const

◆ queryProperty()

QScriptClass::QueryFlags QDeclarativeObjectMethodScriptClass::queryProperty ( Object ,
const Identifier name,
QScriptClass::QueryFlags  flags 
)
protectedvirtual

Reimplemented from QScriptDeclarativeClass.

Definition at line 649 of file qdeclarativeobjectscriptclass.cpp.

651 {
652  Q_UNUSED(flags);
655  else
656  return 0;
657 
658 }
const char * name
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ relatedMethod()

QDeclarativePropertyCache::Data * QDeclarativeObjectMethodScriptClass::relatedMethod ( QObject object,
QDeclarativePropertyCache::Data current,
QDeclarativePropertyCache::Data dummy 
)
private

Returns the next related method, if one, or 0.

Definition at line 1212 of file qdeclarativeobjectscriptclass.cpp.

Referenced by callOverloaded().

1214 {
1216  if (current->relatedIndex == -1)
1217  return 0;
1218 
1219  if (cache) {
1220  return cache->method(current->relatedIndex);
1221  } else {
1222  const QMetaObject *mo = object->metaObject();
1223  int methodOffset = mo->methodCount() - QMetaObject_methods(mo);
1224 
1225  while (methodOffset > current->relatedIndex) {
1226  mo = mo->superClass();
1227  methodOffset -= QMetaObject_methods(mo);
1228  }
1229 
1230  QMetaMethod method = mo->method(current->relatedIndex);
1231  dummy.load(method);
1232 
1233  // Look for overloaded methods
1235  for (int ii = current->relatedIndex - 1; ii >= methodOffset; --ii) {
1236  if (methodName == QMetaMethod_name(mo->method(ii))) {
1237  dummy.relatedIndex = ii;
1238  return &dummy;
1239  }
1240  }
1241 
1242  return &dummy;
1243  }
1244 }
The QMetaObject class contains meta-information about Qt objects.
Definition: qobjectdefs.h:304
QDeclarativePropertyCache * propertyCache
static QDeclarativeData * get(const QObject *object, bool create=false)
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
void load(const QMetaProperty &, QDeclarativeEngine *engine=0)
const QMetaObject * superClass() const
Returns the meta-object of the superclass, or 0 if there is no such object.
Definition: qobjectdefs.h:494
static QByteArray QMetaMethod_name(const QMetaMethod &m)
static QByteArray methodName(const char *signature, int nameLength)
Makes a deep copy of the first nameLength characters of the given method signature and returns the co...
QMetaMethod method(int index) const
Returns the meta-data for the method with the given index.
int methodCount() const
Returns the number of methods known to the meta-object system in this class, including the number of ...
The QMetaMethod class provides meta-data about a member function.
Definition: qmetaobject.h:56
static int QMetaObject_methods(const QMetaObject *metaObject)

Properties

◆ engine

QDeclarativeEngine* QDeclarativeObjectMethodScriptClass::engine
private

Definition at line 102 of file qdeclarativeobjectscriptclass_p.h.

◆ m_connect

QScriptValue QDeclarativeObjectMethodScriptClass::m_connect
private

◆ m_connectId

PersistentIdentifier QDeclarativeObjectMethodScriptClass::m_connectId
private

◆ m_disconnect

QScriptValue QDeclarativeObjectMethodScriptClass::m_disconnect
private

◆ m_disconnectId

PersistentIdentifier QDeclarativeObjectMethodScriptClass::m_disconnectId
private

The documentation for this class was generated from the following files: