コード例 #1
0
ファイル: qqmlmetatype.cpp プロジェクト: ghjinlei/qt5
QObject *QQmlMetaType::toQObject(const QVariant &v, bool *ok)
{
    if (!isQObject(v.userType())) {
        if (ok) *ok = false;
        return 0;
    }

    if (ok) *ok = true;

    return *(QObject **)v.constData();
}
コード例 #2
0
QVariant QScriptValueImpl::toVariant() const
{
    switch (m_type) {
    case QScript::InvalidType:
        return QVariant();

    case QScript::UndefinedType:
    case QScript::NullType:
    case QScript::PointerType:
    case QScript::ReferenceType:
        break;

    case QScript::BooleanType:
        return QVariant(m_bool_value);

    case QScript::IntegerType:
        return QVariant(m_int_value);

    case QScript::NumberType:
        return QVariant(m_number_value);

    case QScript::StringType:
        return QVariant(m_string_value->s);

    case QScript::LazyStringType:
        return QVariant(*m_lazy_string_value);

    case QScript::ObjectType:
        if (isDate())
            return QVariant(toDateTime());

#ifndef QT_NO_REGEXP
        if (isRegExp())
            return QVariant(toRegExp());
#endif
        if (isVariant())
            return variantValue();

#ifndef QT_NO_QOBJECT
        if (isQObject())        
            return qVariantFromValue(toQObject());
#endif

        QScriptValueImpl v = engine()->toPrimitive(*this);
        if (!v.isObject())
            return v.toVariant();
        break;
    } // switch
    return QVariant();
}
コード例 #3
0
ファイル: lrxmlwriter.cpp プロジェクト: PepaRokos/LimeReport
void XMLWriter::saveProperty(QString name, QObject* item, QDomElement *node)
{
    QString typeName;
    if (name.compare("itemIndexMethod")==0)
        typeName = item->metaObject()->property(item->metaObject()->indexOfProperty(name.toLatin1())).typeName();
    else
        typeName = item->property(name.toLatin1()).typeName();

    CreateSerializator creator=0;
    if (isCollection(name,item)) { saveCollection(name,item,node); return;}
    if (isQObject(name,item)) {
        if (qvariant_cast<QObject *>(item->property(name.toLatin1())))
            putQObjectProperty(name,qvariant_cast<QObject *>(item->property(name.toLatin1())),node);
        else {
            qDebug()<<"Warnig property can`t be casted to QObject"<<name;
        }
        return;
    }

    if (enumOrFlag(name,item))
        creator=XMLAbstractSerializatorFactory::instance().objectCreator(
                    "enumAndFlags"
                );
    else
    try {
        creator=XMLAbstractSerializatorFactory::instance().objectCreator(typeName);
    } catch (LimeReport::ReportError &exception){
        qDebug()<<"class name ="<<item->metaObject()->className()
               <<"property name="<<name<<" property type="<<typeName
               <<exception.what();

    }

    if (creator) {
        QScopedPointer<SerializatorIntf> serializator(creator(m_doc.data(),node));
        serializator->save(
            item->property(name.toLatin1()),
            name
        );
    }
}