当前位置: 首页>>代码示例>>C++>>正文


C++ QScriptValue::isRegExp方法代码示例

本文整理汇总了C++中QScriptValue::isRegExp方法的典型用法代码示例。如果您正苦于以下问题:C++ QScriptValue::isRegExp方法的具体用法?C++ QScriptValue::isRegExp怎么用?C++ QScriptValue::isRegExp使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QScriptValue的用法示例。


在下文中一共展示了QScriptValue::isRegExp方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: setProperty

void FlatListScriptClass::setProperty(Object *obj, const Identifier &name, const QScriptValue &value)
{
    if (!value.isVariant() && !value.isRegExp() && !value.isDate() && value.isObject()) {
        qmlInfo(m_model->m_listModel) << "Cannot add list-type data when modifying or after modification from a worker script";
        return;
    }

    FlatNodeObjectData *objData = static_cast<FlatNodeObjectData*>(obj);
    if (!objData->nodeData) // item at this index has been deleted
        return;

    int index = objData->nodeData->index;
    QString propName = toString(name);

    int role = m_model->m_strings.value(propName, -1);
    if (role >= 0 && index >= 0) {
        QHash<int, QVariant> &row = m_model->m_values[index];
        row[role] = value.toVariant();

        QList<int> roles;
        roles << role;
        if (m_model->m_parentAgent) {
            // This is the list in the worker thread, so tell the agent to
            // emit itemsChanged() later
            m_model->m_parentAgent->changedData(index, 1, roles);
        } else {
            // This is the list in the main thread, so emit itemsChanged()
            emit m_model->m_listModel->itemsChanged(index, 1, roles);
        }
    }
}
开发者ID:BGmot,项目名称:Qt,代码行数:31,代码来源:qdeclarativelistmodel.cpp

示例2: addValue

bool FlatListModel::addValue(const QScriptValue &value, QHash<int, QVariant> *row, QList<int> *roles)
{
    QScriptValueIterator it(value);
    while (it.hasNext()) {
        it.next();
        QScriptValue value = it.value();
        if (!value.isVariant() && !value.isRegExp() && !value.isDate() && value.isObject()) {
            qmlInfo(m_listModel) << "Cannot add list-type data when modifying or after modification from a worker script";
            return false;
        }

        QString name = it.name();
        QVariant v = it.value().toVariant();

        QHash<QString, int>::Iterator iter = m_strings.find(name);
        if (iter == m_strings.end()) {
            int role = m_roles.count();
            m_roles.insert(role, name);
            iter = m_strings.insert(name, role);
            if (roles)
                roles->append(role);
        } else {
            int role = iter.value();
            if (roles && row->contains(role) && row->value(role) != v)
                roles->append(role);
        }
        row->insert(*iter, v);
    }
    return true;
}
开发者ID:BGmot,项目名称:Qt,代码行数:30,代码来源:qdeclarativelistmodel.cpp

示例3: fromScriptValue

static JSAgentWatchData fromScriptValue(const QString &expression,
                                        const QScriptValue &value)
{
    static const QString arrayStr = QCoreApplication::translate
            ("Debugger::JSAgentWatchData", "[Array of length %1]");
    static const QString undefinedStr = QCoreApplication::translate
            ("Debugger::JSAgentWatchData", "<undefined>");

    JSAgentWatchData data;
    data.exp = expression.toUtf8();
    data.name = data.exp;
    data.hasChildren = false;
    data.value = value.toString().toUtf8();
    data.objectId = value.objectId();
    if (value.isArray()) {
        data.type = "Array";
        data.value = arrayStr.arg(value.property(QLatin1String("length")).toString()).toUtf8();
        data.hasChildren = true;
    } else if (value.isBool()) {
        data.type = "Bool";
        // data.value = value.toBool() ? "true" : "false";
    } else if (value.isDate()) {
        data.type = "Date";
        data.value = value.toDateTime().toString().toUtf8();
    } else if (value.isError()) {
        data.type = "Error";
    } else if (value.isFunction()) {
        data.type = "Function";
    } else if (value.isUndefined()) {
        data.type = undefinedStr.toUtf8();
    } else if (value.isNumber()) {
        data.type = "Number";
    } else if (value.isRegExp()) {
        data.type = "RegExp";
    } else if (value.isString()) {
        data.type = "String";
    } else if (value.isVariant()) {
        data.type = "Variant";
    } else if (value.isQObject()) {
        const QObject *obj = value.toQObject();
        data.type = "Object";
        data.value += '[';
        data.value += obj->metaObject()->className();
        data.value += ']';
        data.hasChildren = true;
    } else if (value.isObject()) {
        data.type = "Object";
        data.hasChildren = true;
        data.value = "[Object]";
    } else if (value.isNull()) {
        data.type = "<null>";
    } else {
        data.type = "<unknown>";
    }
    return data;
}
开发者ID:Drakey83,项目名称:steamlink-sdk,代码行数:56,代码来源:qjsdebuggeragent.cpp

示例4: setProperty

void QDeclarativeValueTypeScriptClass::setProperty(Object *obj, const Identifier &,
                                                   const QScriptValue &value)
{
    QDeclarativeValueTypeObject *o = static_cast<QDeclarativeValueTypeObject *>(obj);

    QVariant v = QDeclarativeEnginePrivate::get(engine)->scriptValueToVariant(value);

    if (o->objectType == QDeclarativeValueTypeObject::Reference) {
        QDeclarativeValueTypeReference *ref = static_cast<QDeclarativeValueTypeReference *>(obj);

        ref->type->read(ref->object, ref->property);
        QMetaProperty p = ref->type->metaObject()->property(m_lastIndex);

        QDeclarativeBinding *newBinding = 0;
        if (value.isFunction() && !value.isRegExp()) {
            QDeclarativeContextData *ctxt = QDeclarativeEnginePrivate::get(engine)->getContext(context());

            QDeclarativePropertyCache::Data cacheData;
            cacheData.flags = QDeclarativePropertyCache::Data::IsWritable;
            cacheData.propType = ref->object->metaObject()->property(ref->property).userType();
            cacheData.coreIndex = ref->property;

            QDeclarativePropertyCache::ValueTypeData valueTypeData;
            valueTypeData.valueTypeCoreIdx = m_lastIndex;
            valueTypeData.valueTypePropType = p.userType();

            newBinding = new QDeclarativeBinding(value, ref->object, ctxt);
            QScriptContextInfo ctxtInfo(context());
            newBinding->setSourceLocation(ctxtInfo.fileName(), ctxtInfo.functionStartLineNumber());
            QDeclarativeProperty prop = QDeclarativePropertyPrivate::restore(cacheData, valueTypeData, ref->object, ctxt);
            newBinding->setTarget(prop);
            if (newBinding->expression().contains(QLatin1String("this")))
                newBinding->setEvaluateFlags(newBinding->evaluateFlags() | QDeclarativeBinding::RequiresThisObject);
        }

        QDeclarativeAbstractBinding *delBinding =
            QDeclarativePropertyPrivate::setBinding(ref->object, ref->property, m_lastIndex, newBinding);
        if (delBinding)
            delBinding->destroy();

        if (p.isEnumType() && (QMetaType::Type)v.type() == QMetaType::Double)
            v = v.toInt();
        p.write(ref->type, v);
        ref->type->write(ref->object, ref->property, 0);

    } else {
        QDeclarativeValueTypeCopy *copy = static_cast<QDeclarativeValueTypeCopy *>(obj);
        copy->type->setValue(copy->value);
        QMetaProperty p = copy->type->metaObject()->property(m_lastIndex);
        p.write(copy->type, v);
        copy->value = copy->type->value();
    }
}
开发者ID:venkatarajasekhar,项目名称:Qt,代码行数:53,代码来源:qdeclarativevaluetypescriptclass.cpp

示例5: scriptValueToVariant

QVariant scriptValueToVariant(const QScriptValue &value)
{
	QVariant var;
	if (value.isBool() || value.isNumber()
		|| value.isString() || value.isVariant()
		|| value.isDate() || value.isRegExp()) {
		var = value.toVariant();
	} else if (value.isArray()) {
		QVariantList list;
		int len = value.property(QLatin1String("length")).toInt32();
		for (int i = 0; i < len; i++)
			list << scriptValueToVariant(value.property(i));
		var = list;
	} else if (value.isObject()) {
		QVariantMap map;
		QScriptValueIterator it(value);
		while (it.hasNext()) {
			it.next();
			map.insert(it.name(), scriptValueToVariant(it.value()));
		}
		var = map;
	}
	return var;
}
开发者ID:CyberSys,项目名称:qutim,代码行数:24,代码来源:scriptengine.cpp

示例6: if

bool operator==(const QScriptValue& first, const QScriptValue& second) {
    if (first.isUndefined()) {
        return second.isUndefined();
        
    } else if (first.isNull()) {
        return second.isNull();
    
    } else if (first.isBool()) {
        return second.isBool() && first.toBool() == second.toBool();
    
    } else if (first.isNumber()) {
        return second.isNumber() && first.toNumber() == second.toNumber();
    
    } else if (first.isString()) {
        return second.isString() && first.toString() == second.toString();
    
    } else if (first.isVariant()) {
        return second.isVariant() && first.toVariant() == second.toVariant();
        
    } else if (first.isQObject()) {
        return second.isQObject() && first.toQObject() == second.toQObject();
    
    } else if (first.isQMetaObject()) {
        return second.isQMetaObject() && first.toQMetaObject() == second.toQMetaObject();
        
    } else if (first.isDate()) {
        return second.isDate() && first.toDateTime() == second.toDateTime();
    
    } else if (first.isRegExp()) {
        return second.isRegExp() && first.toRegExp() == second.toRegExp();
    
    } else if (first.isArray()) {
        if (!second.isArray()) {
            return false;
        }
        int length = first.property(ScriptCache::getInstance()->getLengthString()).toInt32();
        if (second.property(ScriptCache::getInstance()->getLengthString()).toInt32() != length) {
            return false;
        }
        for (int i = 0; i < length; i++) {
            if (first.property(i) != second.property(i)) {
                return false;
            }
        }
        return true;
        
    } else if (first.isObject()) {
        if (!second.isObject()) {
            return false;
        }
        int propertyCount = 0;
        for (QScriptValueIterator it(first); it.hasNext(); ) {
            it.next();
            if (second.property(it.scriptName()) != it.value()) {
                return false;
            }
            propertyCount++;
        }
        // make sure the second has exactly as many properties as the first
        for (QScriptValueIterator it(second); it.hasNext(); ) {
            it.next();
            if (--propertyCount < 0) {
                return false;
            }
        }
        return true;
        
    } else {
        // if none of the above tests apply, first must be invalid
        return !second.isValid();
    }
}
开发者ID:ey6es,项目名称:hifi,代码行数:72,代码来源:ScriptCache.cpp

示例7: setProperty

void QDeclarativeObjectScriptClass::setProperty(QObject *obj,
                                                const Identifier &name,
                                                const QScriptValue &value,
                                                QScriptContext *context,
                                                QDeclarativeContextData *evalContext)
{
    Q_UNUSED(name);

    Q_ASSERT(obj);
    Q_ASSERT(lastData);
    Q_ASSERT(context);

    if (!lastData->isValid()) {
        QString error = QLatin1String("Cannot assign to non-existent property \"") +
                        toString(name) + QLatin1Char('\"');
        context->throwError(error);
        return;
    }

    if (!(lastData->flags & QDeclarativePropertyCache::Data::IsWritable) && 
        !(lastData->flags & QDeclarativePropertyCache::Data::IsQList)) {
        QString error = QLatin1String("Cannot assign to read-only property \"") +
                        toString(name) + QLatin1Char('\"');
        context->throwError(error);
        return;
    }

    QDeclarativeEnginePrivate *enginePriv = QDeclarativeEnginePrivate::get(engine);

    if (!evalContext) {
        // Global object, QScriptContext activation object, QDeclarativeContext object
        QScriptValue scopeNode = scopeChainValue(context, -3);
        if (scopeNode.isValid()) {
            Q_ASSERT(scriptClass(scopeNode) == enginePriv->contextClass);

            evalContext = enginePriv->contextClass->contextFromValue(scopeNode);
        }
    }

    QDeclarativeBinding *newBinding = 0;
    if (value.isFunction() && !value.isRegExp()) {
        QScriptContextInfo ctxtInfo(context);
        QDeclarativePropertyCache::ValueTypeData valueTypeData;

        newBinding = new QDeclarativeBinding(value, obj, evalContext);
        newBinding->setSourceLocation(ctxtInfo.fileName(), ctxtInfo.functionStartLineNumber());
        newBinding->setTarget(QDeclarativePropertyPrivate::restore(*lastData, valueTypeData, obj, evalContext));
        if (newBinding->expression().contains(QLatin1String("this")))
            newBinding->setEvaluateFlags(newBinding->evaluateFlags() | QDeclarativeBinding::RequiresThisObject);
    }

    QDeclarativeAbstractBinding *delBinding =
        QDeclarativePropertyPrivate::setBinding(obj, lastData->coreIndex, -1, newBinding);
    if (delBinding)
        delBinding->destroy();

    if (value.isNull() && lastData->flags & QDeclarativePropertyCache::Data::IsQObjectDerived) {
        QObject *o = 0;
        int status = -1;
        int flags = 0;
        void *argv[] = { &o, 0, &status, &flags };
        QMetaObject::metacall(obj, QMetaObject::WriteProperty, lastData->coreIndex, argv);
    } else if (value.isUndefined() && lastData->flags & QDeclarativePropertyCache::Data::IsResettable) {
        void *a[] = { 0 };
        QMetaObject::metacall(obj, QMetaObject::ResetProperty, lastData->coreIndex, a);
    } else if (value.isUndefined() && lastData->propType == qMetaTypeId<QVariant>()) {
        QDeclarativePropertyPrivate::write(obj, *lastData, QVariant(), evalContext);
    } else if (value.isUndefined()) {
        QString error = QLatin1String("Cannot assign [undefined] to ") +
                        QLatin1String(QMetaType::typeName(lastData->propType));
        context->throwError(error);
    } else if (value.isFunction() && !value.isRegExp()) {
        // this is handled by the binding creation above
    } else {
        //### expand optimization for other known types
        if (lastData->propType == QMetaType::Int && value.isNumber()) {
            int rawValue = qRoundDouble(value.toNumber());
            int status = -1;
            int flags = 0;
            void *a[] = { (void *)&rawValue, 0, &status, &flags };
            QMetaObject::metacall(obj, QMetaObject::WriteProperty,
                                  lastData->coreIndex, a);
            return;
        } else if (lastData->propType == QMetaType::QReal && value.isNumber()) {
            qreal rawValue = qreal(value.toNumber());
            int status = -1;
            int flags = 0;
            void *a[] = { (void *)&rawValue, 0, &status, &flags };
            QMetaObject::metacall(obj, QMetaObject::WriteProperty,
                                  lastData->coreIndex, a);
            return;
        } else if (lastData->propType == QMetaType::QString && value.isString()) {
            const QString &rawValue = value.toString();
            int status = -1;
            int flags = 0;
            void *a[] = { (void *)&rawValue, 0, &status, &flags };
            QMetaObject::metacall(obj, QMetaObject::WriteProperty,
                                  lastData->coreIndex, a);
            return;
        }
//.........这里部分代码省略.........
开发者ID:fluxer,项目名称:katie,代码行数:101,代码来源:qdeclarativeobjectscriptclass.cpp

示例8: matchScore

/*!
    Returns the match score for converting \a actual to be of type \a conversionType.  A 
    zero score means "perfect match" whereas a higher score is worse.

    The conversion table is copied out of the QtScript callQtMethod() function.
*/
int QDeclarativeObjectMethodScriptClass::matchScore(const QScriptValue &actual, int conversionType, 
                                                    const QByteArray &conversionTypeName)
{
    if (actual.isNumber()) {
        switch (conversionType) {
        case QMetaType::Double:
            return 0;
        case QMetaType::Float:
            return 1;
        case QMetaType::LongLong:
        case QMetaType::ULongLong:
            return 2;
        case QMetaType::Long:
        case QMetaType::ULong:
            return 3;
        case QMetaType::Int:
        case QMetaType::UInt:
            return 4;
        case QMetaType::Short:
        case QMetaType::UShort:
            return 5;
            break;
        case QMetaType::Char:
        case QMetaType::UChar:
            return 6;
        default:
            return 10;
        }
    } else if (actual.isString()) {
        switch (conversionType) {
        case QMetaType::QString:
            return 0;
        default:
            return 10;
        }
    } else if (actual.isBoolean()) {
        switch (conversionType) {
        case QMetaType::Bool:
            return 0;
        default:
            return 10;
        }
    } else if (actual.isDate()) {
        switch (conversionType) {
        case QMetaType::QDateTime:
            return 0;
        case QMetaType::QDate:
            return 1;
        case QMetaType::QTime:
            return 2;
        default:
            return 10;
        }
    } else if (actual.isRegExp()) {
        switch (conversionType) {
        case QMetaType::QRegExp:
            return 0;
        default:
            return 10;
        }
    } else if (actual.isVariant()) {
        if (conversionType == qMetaTypeId<QVariant>())
            return 0;
        else if (actual.toVariant().userType() == conversionType)
            return 0;
        else
            return 10;
    } else if (actual.isArray()) {
        switch (conversionType) {
        case QMetaType::QStringList:
        case QMetaType::QVariantList:
            return 5;
        default:
            return 10;
        }
    } else if (actual.isQObject()) {
        switch (conversionType) {
        case QMetaType::QObjectStar:
            return 0;
        default:
            return 10;
        }
    } else if (actual.isNull()) {
        switch (conversionType) {
        case QMetaType::VoidStar:
        case QMetaType::QObjectStar:
            return 0;
        default:
            if (!conversionTypeName.endsWith('*'))
                return 10;
            else
                return 0;
        }
    } else {
//.........这里部分代码省略.........
开发者ID:fluxer,项目名称:katie,代码行数:101,代码来源:qdeclarativeobjectscriptclass.cpp

示例9: marshall_basetype


//.........这里部分代码省略.........
            *(m->var()) = JSmoke::Global::QtEnum.call(QScriptValue(), args);
            break;
        }
        default:
            m->unsupported();
            break;
        }
        break;
        
    case Smoke::t_class:
        switch(m->action()) {
        case Marshall::FromQScriptValue:
        {
            QScriptValue value = *(m->var());

            if (value.isNull()) {
                m->item().s_class = 0;
                return;
            }
            
            if (value.isDate()) {
                Smoke::ModuleIndex classId = Smoke::findClass(m->smoke()->classes[m->type().classId()].className);
                if (classId == JSmoke::Global::QDateClassId) {
                    m->item().s_class = new QDate(value.toDateTime().date());
                } else if (classId == JSmoke::Global::QDateTimeClassId) {
                     m->item().s_class = new QDateTime(value.toDateTime());
                } else if (classId == JSmoke::Global::QTimeClassId) {
                     m->item().s_class = new QTime(value.toDateTime().time());
                } else {
                    m->item().s_class = 0;
                }
                
                return;
            } else if (value.isRegExp()) {
                m->item().s_class = new QRegExp(value.toRegExp());
                return;
            }
            
            if (!Object::Instance::isSmokeObject(value)) {
                m->item().s_class = 0;
                return;
            }
            
            Object::Instance * instance = Object::Instance::get(value);
            void * ptr = instance->value;
            
            if (!m->cleanup() && m->type().isStack()) {
                ptr = constructCopy(instance);
            }
            
            ptr = instance->classId.smoke->cast(    ptr, 
                                                    instance->classId, 
                                                    Smoke::ModuleIndex(m->smoke(), m->type().classId()) );
            
            m->item().s_class = ptr;
            break;
        }
        
        case Marshall::ToQScriptValue:
        {
            if (m->item().s_voidp == 0) {
                *(m->var()) = m->engine()->nullValue();
                return;
            }
            
            void * ptr = m->item().s_voidp;
开发者ID:KDE,项目名称:jsmoke,代码行数:67,代码来源:handlers.cpp

示例10: isRegExp_test

void tst_QScriptValueGenerated::isRegExp_test(const char*, const QScriptValue& value)
{
    QFETCH(bool, expected);
    QCOMPARE(value.isRegExp(), expected);
    QCOMPARE(value.isRegExp(), expected);
}
开发者ID:mortenelund,项目名称:qt,代码行数:6,代码来源:tst_qscriptvalue_generated_isXXX.cpp


注:本文中的QScriptValue::isRegExp方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。