예제 #1
0
/*!
  \since 4.4

  Returns the custom script class that this script object is an
  instance of, or 0 if the object is not of a custom class.

  \sa setScriptClass()
*/
QScriptClass *QScriptValue::scriptClass() const
{
    Q_D(const QScriptValue);
    if (!d || !d->value.isObject())
        return 0;
    QScriptClassInfo *info = d->value.classInfo();
    if ((info->type() & QScriptClassInfo::TypeMask) < QScriptClassInfo::CustomType)
        return 0;
    return QScriptClassPrivate::classFromInfo(info);
}
/*!
  \since 4.4

  Returns the custom script class that this script object is an
  instance of, or 0 if the object is not of a custom class.

  \sa setScriptClass()
*/
QScriptClass *QScriptValue::scriptClass() const
{
    if (!isObject())
        return 0;
    QScriptValueImpl self = QScriptValuePrivate::valueOf(*this);
    QScriptClassInfo *info = self.classInfo();
    if ((info->type() & QScriptClassInfo::TypeMask) < QScriptClassInfo::CustomType)
        return 0;
    return QScriptClassPrivate::classFromInfo(info);
}
/*!
  \since 4.4

  Sets the custom script class of this script object to \a scriptClass.
  This can be used to "promote" a plain script object (e.g. created
  by the "new" operator in a script, or by QScriptEngine::newObject() in C++)
  to an object of a custom type.

  \sa scriptClass(), setData()
*/
void QScriptValue::setScriptClass(QScriptClass *scriptClass)
{
    if (!isObject() || !scriptClass)
        return;
    QScriptClassPrivate *cls_p = QScriptClassPrivate::get(scriptClass);
    QScriptClassInfo *info = cls_p->classInfo();
    if ((info->type() & QScriptClassInfo::TypeMask) < QScriptClassInfo::CustomType)
        return;
    QScriptValueImpl self = QScriptValuePrivate::valueOf(*this);
    self.setClassInfo(info);
}