本文整理汇总了C++中QScriptValue::isArray方法的典型用法代码示例。如果您正苦于以下问题:C++ QScriptValue::isArray方法的具体用法?C++ QScriptValue::isArray怎么用?C++ QScriptValue::isArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QScriptValue
的用法示例。
在下文中一共展示了QScriptValue::isArray方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parseCategories
void YTCategories::parseCategories(QByteArray bytes) {
QList<YTCategory> categories;
QScriptEngine engine;
QScriptValue json = engine.evaluate("(" + QString::fromUtf8(bytes) + ")");
QScriptValue items = json.property("items");
if (items.isArray()) {
QScriptValueIterator it(items);
while (it.hasNext()) {
it.next();
QScriptValue item = it.value();
// For some reason the array has an additional element containing its size.
if (!item.isObject()) continue;
QScriptValue snippet = item.property("snippet");
bool isAssignable = snippet.property("assignable").toBool();
if (!isAssignable) continue;
YTCategory category;
category.term = item.property("id").toString();
category.label = snippet.property("title").toString();
categories << category;
}
}
emit categoriesLoaded(categories);
}
示例2: setObjectValue
bool ModelNode::setObjectValue(const QScriptValue& valuemap, bool writeToCache)
{
bool emitItemsChanged = false;
QScriptValueIterator it(valuemap);
while (it.hasNext()) {
it.next();
ModelNode *prev = properties.value(it.name());
ModelNode *value = new ModelNode(m_model);
QScriptValue v = it.value();
if (v.isArray()) {
value->isArray = true;
value->setListValue(v);
if (writeToCache && objectCache)
objectCache->setValue(it.name().toUtf8(), QVariant::fromValue(value->model(m_model)));
emitItemsChanged = true; // for now, too inefficient to check whether list and sublists have changed
} else {
value->values << v.toVariant();
if (writeToCache && objectCache)
objectCache->setValue(it.name().toUtf8(), value->values.last());
if (!emitItemsChanged && prev && prev->values.count() == 1
&& prev->values[0] != value->values.last()) {
emitItemsChanged = true;
}
}
if (properties.contains(it.name()))
delete properties[it.name()];
properties.insert(it.name(), value);
}
return emitItemsChanged;
}
示例3: valueToIntList
static void valueToIntList(const QScriptValue &arr, QList<int> &list) {
list.clear();
if (arr.isArray()) {
int length = arr.property("length").toInteger();
for (int i = 0; i < length; i++) list.append(arr.property(i).toInteger());
}
}
示例4: add
QScriptValue UniversalInputDialogScript::add(const QScriptValue& def, const QScriptValue& description, const QScriptValue& id){
QWidget* w = 0;
if (def.isArray()) {
QStringList options;
QScriptValueIterator it(def);
while (it.hasNext()) {
it.next();
if (it.flags() & QScriptValue::SkipInEnumeration)
continue;
if (it.value().isString() || it.value().isNumber()) options << it.value().toString();
else engine->currentContext()->throwError("Invalid default value in array (must be string or number): "+it.value().toString());
}
w = addComboBox(ManagedProperty::fromValue(options), description.toString());
} else if (def.isBool()) {
w = addCheckBox(ManagedProperty::fromValue(def.toBool()), description.toString());
} else if (def.isNumber()) {
w = addDoubleSpinBox(ManagedProperty::fromValue(def.toNumber()), description.toString());
} else if (def.isString()) {
w = addLineEdit(ManagedProperty::fromValue(def.toString()), description.toString());
} else {
engine->currentContext()->throwError(tr("Invalid default value: %1").arg(def.toString()));
return QScriptValue();
}
if (id.isValid()) properties.last().name = id.toString();
return engine->newQObject(w);
}
示例5: to_source_f_object
QString to_source_f<QScriptValue>::operator()( QScriptValue const & x ) const
{
if( x.isUndefined() ) return "undefined";
if( x.isNull() ) return "null";
if(0) qDebug() << "to_source_f<QScriptValue>("<<x.toString()<<")";
#define TODO(A,B,C)
#define DO(IS,T,TO) \
if( x.IS() ) {\
if(0) qDebug() << "to_source_f<QScriptValue>(is-a: "<<# IS<<")"; \
return toSource<T>( x.TO() );\
}
DO(isVariant,QVariant,toVariant); // must come before the others!
DO(isBoolean,bool,toBoolean);
DO(isNumber,qreal,toNumber);
DO(isString,QString,toString);
TODO(isRegExp,QRegExp,toRegExp);
if( x.isArray() || x.isObject() )
{
if(0) qDebug() << "to_source_f<QScriptValue>(is-a: array or object)";
return to_source_f_object()( x );
}
#undef DO
#undef TODO
return QString("undefined");
}
示例6: it
QList<ScraperSearchResult> IMDB::parseSearch(QString json)
{
QList<ScraperSearchResult> results;
QScriptValue sc;
QScriptEngine engine;
sc = engine.evaluate("(" + QString(json) + ")");
if (sc.isArray() ) {
QScriptValueIterator it(sc);
while (it.hasNext() ) {
it.next();
if (it.value().property("imdb_id").toString().isEmpty())
continue;
ScraperSearchResult result;
result.name = Helper::urlDecode(it.value().property("title").toString());
result.id = it.value().property("imdb_id").toString();
result.released = QDate::fromString(it.value().property("year").toString(), "yyyy");
results.append(result);
}
} else {
if (!sc.property("imdb_id").toString().isEmpty()) {
ScraperSearchResult result;
result.name = Helper::urlDecode(sc.property("title").toString());
result.id = sc.property("imdb_id").toString();
result.released = QDate::fromString(sc.property("year").toString(), "yyyy");
results.append(result);
}
}
return results;
}
示例7: createMenu
QAction *KWin::AbstractScript::scriptValueToAction(QScriptValue &value, QMenu *parent)
{
QScriptValue titleValue = value.property(QStringLiteral("text"));
QScriptValue checkableValue = value.property(QStringLiteral("checkable"));
QScriptValue checkedValue = value.property(QStringLiteral("checked"));
QScriptValue itemsValue = value.property(QStringLiteral("items"));
QScriptValue triggeredValue = value.property(QStringLiteral("triggered"));
if (!titleValue.isValid()) {
// title not specified - does not make any sense to include
return nullptr;
}
const QString title = titleValue.toString();
const bool checkable = checkableValue.isValid() && checkableValue.toBool();
const bool checked = checkable && checkedValue.isValid() && checkedValue.toBool();
// either a menu or a menu item
if (itemsValue.isValid()) {
if (!itemsValue.isArray()) {
// not an array, so cannot be a menu
return nullptr;
}
QScriptValue lengthValue = itemsValue.property(QStringLiteral("length"));
if (!lengthValue.isValid() || !lengthValue.isNumber() || lengthValue.toInteger() == 0) {
// length property missing
return nullptr;
}
return createMenu(title, itemsValue, parent);
} else if (triggeredValue.isValid()) {
// normal item
return createAction(title, checkable, checked, triggeredValue, parent);
}
return nullptr;
}
示例8: if
ST convert_script_value_f_size<ST>::operator()( QScriptEngine *,
const QScriptValue & args ) const
{
typedef typename point_valtype<ST>::value_type value_type;
value_type w = 0;
value_type h = 0;
QScriptValue obj;
bool smellArray = ( args.isArray() ||
! args.property("length").isUndefined() );
if( smellArray )
{
obj = args.property(0);
}
else if( args.isObject() )
{
obj = args;
}
if( smellArray && !obj.isObject() )
{
#define ARG(X) value_type(args.property(X).toNumber())
w = ARG(0);
h = ARG(1);
#undef ARG
}
else
{
#define ARG(X) value_type(obj.property(X).toNumber())
w = ARG("width");
h = ARG("height");
#undef ARG
}
return ST(w,h);
}
示例9: parseResponse
void YTChannel::parseResponse(const QByteArray &bytes) {
QScriptEngine engine;
QScriptValue json = engine.evaluate("(" + QString::fromUtf8(bytes) + ")");
QScriptValue items = json.property("items");
if (items.isArray()) {
QScriptValueIterator it(items);
while (it.hasNext()) {
it.next();
QScriptValue item = it.value();
// For some reason the array has an additional element containing its size.
if (item.isObject()) {
QScriptValue snippet = item.property("snippet");
displayName = snippet.property("title").toString();
description = snippet.property("description").toString();
QScriptValue thumbnails = snippet.property("thumbnails");
thumbnailUrl = thumbnails.property("medium").property("url").toString();
qDebug() << displayName << description << thumbnailUrl;
}
}
}
emit infoLoaded();
storeInfo();
loading = false;
}
示例10: newInstance
void tst_QScriptClass::newInstance()
{
QScriptEngine eng;
TestClass cls(&eng);
QScriptValue obj1 = eng.newObject(&cls);
QVERIFY(!obj1.data().isValid());
QVERIFY(obj1.prototype().strictlyEquals(cls.prototype()));
QEXPECT_FAIL("", "classname is not implemented", Continue);
QCOMPARE(obj1.toString(), QString::fromLatin1("[object TestClass]"));
QCOMPARE(obj1.scriptClass(), (QScriptClass*)&cls);
QScriptValue num(&eng, 456);
QScriptValue obj2 = eng.newObject(&cls, num);
QVERIFY(obj2.data().strictlyEquals(num));
QVERIFY(obj2.prototype().strictlyEquals(cls.prototype()));
QCOMPARE(obj2.scriptClass(), (QScriptClass*)&cls);
QScriptValue obj3 = eng.newObject();
QCOMPARE(obj3.scriptClass(), (QScriptClass*)0);
obj3.setScriptClass(&cls);
QCOMPARE(obj3.scriptClass(), (QScriptClass*)&cls);
obj3.setScriptClass(0);
QCOMPARE(obj3.scriptClass(), (QScriptClass*)0);
obj3.setScriptClass(&cls);
QCOMPARE(obj3.scriptClass(), (QScriptClass*)&cls);
TestClass cls2(&eng);
obj3.setScriptClass(&cls2);
QCOMPARE(obj3.scriptClass(), (QScriptClass*)&cls2);
// undefined behavior really, but shouldn't crash
QScriptValue arr = eng.newArray();
QVERIFY(arr.isArray());
QCOMPARE(arr.scriptClass(), (QScriptClass*)0);
QTest::ignoreMessage(QtWarningMsg, "QScriptValue::setScriptClass() failed: cannot change class of non-QScriptObject");
arr.setScriptClass(&cls);
QEXPECT_FAIL("", "Changing class of arbitrary script object is not allowed (it's OK)", Continue);
QCOMPARE(arr.scriptClass(), (QScriptClass*)&cls);
QEXPECT_FAIL("", "Changing class of arbitrary script object is not allowed (it's OK)", Continue);
QVERIFY(!arr.isArray());
QVERIFY(arr.isObject());
}
示例11: append
/*!
\qmlmethod ListModel::append(jsobject dict)
Adds a new item to the end of the list model, with the
values in \a dict.
\code
fruitModel.append({"cost": 5.95, "name":"Pizza"})
\endcode
\sa set() remove()
*/
void QDeclarativeListModel::append(const QScriptValue& valuemap)
{
if (!valuemap.isObject() || valuemap.isArray()) {
qmlInfo(this) << tr("append: value is not an object");
return;
}
insert(count(), valuemap);
}
示例12: GetObjectInformation
void JavascriptInstance::GetObjectInformation(const QScriptValue &object, QSet<qint64> &ids, uint &valueCount, uint &objectCount, uint &nullCount, uint &numberCount,
uint &boolCount, uint &stringCount, uint &arrayCount, uint &funcCount, uint &qobjCount, uint &qobjMethodCount)
{
if (!ids.contains(object.objectId()))
ids << object.objectId();
QScriptValueIterator iter(object);
while(iter.hasNext())
{
iter.next();
QScriptValue v = iter.value();
if (ids.contains(v.objectId()))
continue;
ids << v.objectId();
valueCount++;
if (v.isNull())
nullCount++;
if (v.isNumber())
numberCount++;
else if (v.isBool())
boolCount++;
else if (v.isString())
stringCount++;
else if (v.isArray())
arrayCount++;
else if (v.isFunction())
funcCount++;
else if (v.isQObject())
qobjCount++;
if (v.isObject())
objectCount++;
if (v.isQMetaObject())
qobjMethodCount += v.toQMetaObject()->methodCount();
// Recurse
if ((v.isObject() || v.isArray()) && !v.isFunction() && !v.isString() && !v.isNumber() && !v.isBool() && !v.isQObject() && !v.isQMetaObject())
GetObjectInformation(v, ids, valueCount, objectCount, nullCount, numberCount, boolCount, stringCount, arrayCount, funcCount, qobjCount, qobjMethodCount);
}
}
示例13: 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;
}
示例14: createObject
/*!
\internal
Overloadable method allows properties to be set during creation
*/
QScriptValue QDeclarativeComponent::createObject(QObject* parent, const QScriptValue& valuemap)
{
Q_D(QDeclarativeComponent);
if (!valuemap.isObject() || valuemap.isArray()) {
qmlInfo(this) << tr("createObject: value is not an object");
return QScriptValue(QScriptValue::NullValue);
}
return d->createObject(parent, valuemap);
}
示例15: updateQueryPane
void DynamicConnectionPageWindow::updateQueryPane()
{
QScriptValue val = scriptRunner.callFunction("getScript");
QString script;
if(val.isArray()){
script = val.toVariant().toStringList().join("\n");
}else{
script = val.toString();
}
editor->setPlainText(script);
}