本文整理汇总了C++中QScriptValue::isDate方法的典型用法代码示例。如果您正苦于以下问题:C++ QScriptValue::isDate方法的具体用法?C++ QScriptValue::isDate怎么用?C++ QScriptValue::isDate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QScriptValue
的用法示例。
在下文中一共展示了QScriptValue::isDate方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: 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);
}
}
}
示例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;
}
示例4: 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;
}
示例5: 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();
}
}
示例6: 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 {
//.........这里部分代码省略.........
示例7: marshall_basetype
//.........这里部分代码省略.........
if (value.isNull()) {
m->item().s_enum = 0;
} else if (value.instanceOf(JSmoke::Global::QtEnum)) {
m->item().s_enum = value.property("value").toUInt32();
} else {
m->item().s_enum = value.toUInt32();
}
break;
}
case Marshall::ToQScriptValue:
{
QScriptValueList args;
args << (uint) m->item().s_enum << m->type().name();
*(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()) );
示例8: isDate_test
void tst_QScriptValueGenerated::isDate_test(const char*, const QScriptValue& value)
{
QFETCH(bool, expected);
QCOMPARE(value.isDate(), expected);
QCOMPARE(value.isDate(), expected);
}