本文整理汇总了C++中QScriptValue::toBool方法的典型用法代码示例。如果您正苦于以下问题:C++ QScriptValue::toBool方法的具体用法?C++ QScriptValue::toBool怎么用?C++ QScriptValue::toBool使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QScriptValue
的用法示例。
在下文中一共展示了QScriptValue::toBool方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: handleRequest
bool HttpHandlerQtScript::handleRequest(Pillow::HttpRequest *request)
{
if (!_scriptFunction.isFunction()) return false;
QScriptEngine* engine = _scriptFunction.engine();
QScriptValue requestObject = engine->newObject();
requestObject.setProperty("nativeRequest", _scriptFunction.engine()->newQObject(request));
requestObject.setProperty("requestMethod", QUrl::fromPercentEncoding(request->requestMethod()));
requestObject.setProperty("requestUri", QUrl::fromPercentEncoding(request->requestUri()));
requestObject.setProperty("requestFragment", QUrl::fromPercentEncoding(request->requestFragment()));
requestObject.setProperty("requestPath", QUrl::fromPercentEncoding(request->requestPath()));
requestObject.setProperty("requestQueryString", QUrl::fromPercentEncoding(request->requestQueryString()));
requestObject.setProperty("requestHeaders", qScriptValueFromValue(engine, request->requestHeaders()));
QList<QPair<QString, QString> > queryParams = QUrl(request->requestUri()).queryItems();
QScriptValue queryParamsObject = engine->newObject();
for (int i = 0, iE = queryParams.size(); i < iE; ++i)
queryParamsObject.setProperty(queryParams.at(i).first, queryParams.at(i).second);
requestObject.setProperty("requestQueryParams", queryParamsObject);
QScriptValue result = _scriptFunction.call(_scriptFunction, QScriptValueList() << requestObject);
if (result.isError())
{
if (request->state() == HttpRequest::SendingHeaders)
{
// Nothing was sent yet... We have a chance to let the client know we had an error.
request->writeResponseString(500, HttpHeaderCollection(), objectToString(result));
}
engine->clearExceptions();
return true;
}
return result.toBool();
}
示例3: qobjectAsActivationObject
void tst_QScriptContext::qobjectAsActivationObject()
{
QScriptEngine eng;
QObject object;
QScriptValue scriptObject = eng.newQObject(&object);
QScriptContext *ctx = eng.pushContext();
ctx->setActivationObject(scriptObject);
QVERIFY(ctx->activationObject().equals(scriptObject));
QVERIFY(!scriptObject.property("foo").isValid());
eng.evaluate("function foo() { return 123; }");
{
QScriptValue val = scriptObject.property("foo");
QVERIFY(val.isValid());
QVERIFY(val.isFunction());
}
QVERIFY(!eng.globalObject().property("foo").isValid());
QVERIFY(!scriptObject.property("bar").isValid());
eng.evaluate("var bar = 123");
{
QScriptValue val = scriptObject.property("bar");
QVERIFY(val.isValid());
QVERIFY(val.isNumber());
QCOMPARE(val.toInt32(), 123);
}
QVERIFY(!eng.globalObject().property("bar").isValid());
{
QScriptValue val = eng.evaluate("delete foo");
QVERIFY(val.isBool());
QVERIFY(val.toBool());
QVERIFY(!scriptObject.property("foo").isValid());
}
}
示例4: engineSetup
void TestKernel::engineSetup()
{
GraphDocumentPtr document;
NodePtr nodeA, nodeB;
EdgePtr edge;
QVERIFY(GraphDocument::objects() == 0);
QVERIFY(Node::objects() == 0);
QVERIFY(Edge::objects() == 0);
// test destroy graph document
document = GraphDocument::create();
nodeA = Node::create(document);
nodeB = Node::create(document);
edge = Edge::create(nodeA, nodeB);
// create kernel
QString script = "return true;";
Kernel kernel;
QScriptValue result = kernel.execute(document, script);
QCOMPARE(result.toBool(), true);
document->destroy();
document.reset();
nodeA.reset();
nodeB.reset();
edge.reset();
QCOMPARE(Edge::objects(), uint(0));
QCOMPARE(Node::objects(), uint(0));
QCOMPARE(GraphDocument::objects(), uint(0));
}
示例5: 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);
}
示例6: startHandle
ImageDataPtr CountPixel::startHandle(ImageDataPtr src1, const ImageDataPtr)
{
QScriptEngine engine;
QString originalQuery = m_listParameters[SCRIPT]->toString();
unsigned long long int total = 0;
auto lambda = [&total, &originalQuery, &engine](unsigned char & r, unsigned char & b, unsigned char & g)
{
QString query = originalQuery;
query.replace("Gr", QString::number(0.33*b + 0.56*g + 0.11*r) );
query.replace("B", QString::number(b) );
query.replace("G", QString::number(g) );
query.replace("R", QString::number(r) );
if( ! engine.canEvaluate(query) )
total = -1;
QScriptValue value = engine.evaluate(query);
total += value.toBool();
};
src1->forEachPixel( lambda);
src1->addResults( m_listParameters[NAME]->toString(), total);
return src1;
}
示例7: updateElement
void ExposedModel::updateElement(const QString &key, QScriptValue value)
{
tinia::model::StateSchemaElement schemaElement = m_model->getStateSchemaElement(key.toStdString());
std::string type = schemaElement.getXSDType();
if(type.find("xsd:") != std::string::npos) {
type = type.substr(4);
}
if (type == std::string("double")) {
m_model->updateElement(key.toStdString(), double(value.toNumber()));
}
else if(type==std::string("integer")) {
m_model->updateElement(key.toStdString(), int(value.toNumber()));
}
else if(type==std::string("bool")) {
m_model->updateElement(key.toStdString(), value.toBool());
}
else if(type==std::string("string")) {
m_model->updateElement(key.toStdString(), value.toString().toStdString());
}
else if(type==std::string("complexType")) {
m_model->updateElement(key.toStdString(), static_cast<Viewer*>(value.toQObject())->viewer());
}
}
示例8: edgeProperties
void TestKernel::edgeProperties()
{
GraphDocumentPtr document = GraphDocument::create();
document->edgeTypes().first()->setDirection(EdgeType::Unidirectional);
NodePtr nodeA = Node::create(document);
NodePtr nodeB = Node::create(document);
EdgePtr edge = Edge::create(nodeA, nodeB);
// test nodes
Kernel kernel;
QString script;
QScriptValue result;
script = "Document.nodes()[0].edges()[0].from().id;";
result = kernel.execute(document, script);
QCOMPARE(result.toString().toInt(), nodeA->id());
script = "Document.nodes()[0].edges()[0].to().id;";
result = kernel.execute(document, script);
QCOMPARE(result.toString().toInt(), nodeB->id());
script = "Document.nodes()[0].edges()[0].directed();";
result = kernel.execute(document, script);
QCOMPARE(result.toBool(), true);
// cleanup
document->destroy();
}
示例9: setProperty
void setProperty(QScriptValue &object,
const QScriptString &name, uint, const QScriptValue & value)
{
if (name == str_forwardOnly) {
QSqlQuery query = qscriptvalue_cast<QSqlQuery>(object.data());
query.setForwardOnly(value.toBool());
}
}
示例10: validateData
void ScriptHandler::validateData(DataInformation* data)
{
if (!data)
return;
data->setHasBeenValidated(false); //not yet validated
if (data->hasChildren())
{
//first validate the children
for (uint i = 0; i < data->childCount(); ++i)
{
validateData(data->childAt(i));
}
}
//check if has a validation function:
AdditionalData* additionalData = data->additionalData();
if (additionalData && additionalData->validationFunction().isValid())
{
//value exists, we assume it has been checked to be a function
#ifdef OKTETA_DEBUG_SCRIPT
mDebugger->attachTo(mEngine);
mDebugger->action(QScriptEngineDebugger::InterruptAction)->trigger();
kDebug()
<< "validating element: " << data->name();
#endif
// QScriptValue thisObject = mEngine->newQObject(data,
// QScriptEngine::QtOwnership, QScriptEngine::ExcludeDeleteLater);
// QScriptValue mainStruct = mEngine->newQObject(data->mainStructure(),
// QScriptEngine::QtOwnership, QScriptEngine::ExcludeDeleteLater);
QScriptValue thisObject = data->toScriptValue(mEngine, &mHandlerInfo);
QScriptValue mainStruct = data->mainStructure()->toScriptValue(mEngine, &mHandlerInfo);
QScriptValueList args;
args << mainStruct;
QScriptValue result = additionalData->validationFunction().call(thisObject, args);
if (result.isError())
{
ScriptUtils::object()->logScriptError(QLatin1String("error occurred while "
"validating element ") + data->name(), result);
data->setValidationError(QLatin1String("Error occurred in validation: ")
+ result.toString());
}
if (mEngine->hasUncaughtException())
{
ScriptUtils::object()->logScriptError(
mEngine->uncaughtExceptionBacktrace());
data->setValidationError(QLatin1String("Error occurred in validation: ")
+ result.toString());
}
if (result.isBool() || result.isBoolean())
{
data->setValidationSuccessful(result.toBool());
}
}
}
示例11: evalBool
bool EnvWrap::evalBool( const QString& nm )
{
QScriptValue result = evalExp(nm);
if (result.isBool())
return result.toBool();
else
throw ExpressionHasNotThisTypeException("Bool",nm);
return false;
}
示例12: QScriptValueList
bool QtScriptForceCondition3D::isApplied(msh::PointPointer point)
{
QScriptValue func = engine_.globalObject().property("isApplied");
QScriptValue result = func.call(object_, QScriptValueList() << point->x() << point->y() << point->z());
x_ = point->x();
y_ = point->y();
z_ = point->z();
return result.toBool();
}
示例13: setProperty
/*
var conference = qutim.protocol("jabber").account("[email protected]").unit("[email protected]", false);
var msg = new Message;
msg.text = "Hi!";
conference.sendMessage(msg);
*/
void ScriptMessage::setProperty(QScriptValue &object, const QScriptString &name,
uint id, const QScriptValue &value)
{
Q_UNUSED(id);
Message *msg = message_get_value(object);
if (name == m_incoming)
msg->setIncoming(value.toBool());
else
msg->setProperty(name.toString().toUtf8(), value.toVariant());
}
示例14: save
/*! Emits the \a saving() signal which triggers any widgets to save that have a mapped \a savedMethod()
specified by \sa insert(). Also reloads metrics, privileges, preferences, and the menubar in the
main application. The screen will close if \a close is true.
\sa apply()
*/
void setup::save(bool close)
{
emit saving();
QMapIterator<QString, ItemProps> i(_itemMap);
while (i.hasNext())
{
bool ok = false;
i.next();
XAbstractConfigure *cw = qobject_cast<XAbstractConfigure*>(i.value().implementation);
QScriptEngine *engine = qobject_cast<QScriptEngine*>(i.value().implementation);
QString method = QString(i.value().saveMethod).remove("(").remove(")");
if (! i.value().implementation)
continue;
else if (cw)
ok = cw->sSave();
else if (engine && engine->globalObject().property(method).isFunction())
{
QScriptValue saveresult = engine->globalObject().property(method).call();
if (saveresult.isBool())
ok = saveresult.toBool();
else
qWarning("Problem executing %s method for script %s",
qPrintable(i.value().saveMethod), qPrintable(i.key()));
}
else
{
qWarning("Could not call save method for %s; it's a(n) %s (%p)",
qPrintable(i.key()),
qobject_cast<QObject*>(i.value().implementation) ?
qobject_cast<QObject*>(i.value().implementation)->metaObject()->className() : "unknown class",
i.value().implementation);
ok = true;
}
if (! ok)
{
setCurrentIndex(i.key());
return;
}
}
_metrics->load();
_privileges->load();
_preferences->load();
omfgThis->initMenuBar();
if (close)
accept();
}
示例15: setParams
bool display::setParams(ParameterList & params)
{
bool ret = _data->setParams(params);
if(engine() && engine()->globalObject().property("setParams").isFunction())
{
QScriptValue paramArg = ParameterListtoScriptValue(engine(), params);
QScriptValue tmp = engine()->globalObject().property("setParams").call(QScriptValue(), QScriptValueList() << paramArg);
ret = ret && tmp.toBool();
params.clear();
ParameterListfromScriptValue(paramArg, params);
}
return ret;
}