本文整理汇总了C++中QScriptEngine::newFunction方法的典型用法代码示例。如果您正苦于以下问题:C++ QScriptEngine::newFunction方法的具体用法?C++ QScriptEngine::newFunction怎么用?C++ QScriptEngine::newFunction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QScriptEngine
的用法示例。
在下文中一共展示了QScriptEngine::newFunction方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: initEcma
void REcmaSharedPointerRay::initEcma(QScriptEngine& engine, QScriptValue* proto
)
{
bool protoCreated = false;
if(proto == NULL){
proto = new QScriptValue(engine.newVariant(qVariantFromValue(
(RRayPointer*) 0)));
protoCreated = true;
}
// primary base class RXLine:
proto->setPrototype(engine.defaultPrototype(
qMetaTypeId<RXLinePointer>()));
/*
*/
QScriptValue fun;
// toString:
REcmaHelper::registerFunction(&engine, proto, toString, "toString");
// copy:
REcmaHelper::registerFunction(&engine, proto, copy, "copy");
// shared pointer support:
REcmaHelper::registerFunction(&engine, proto, data, "data");
REcmaHelper::registerFunction(&engine, proto, isNull, "isNull");
// destroy:
REcmaHelper::registerFunction(&engine, proto, destroy, "destroy");
// conversion for base class RXLine
REcmaHelper::registerFunction(&engine, proto, getRXLine, "getRXLine");
// conversion for base class RShape
REcmaHelper::registerFunction(&engine, proto, getRShape, "getRShape");
// conversion for base class RDirected
REcmaHelper::registerFunction(&engine, proto, getRDirected, "getRDirected");
// get class name
REcmaHelper::registerFunction(&engine, proto, getClassName, "getClassName");
// conversion to all base classes (multiple inheritance):
REcmaHelper::registerFunction(&engine, proto, getBaseClasses, "getBaseClasses");
// properties:
// methods:
REcmaHelper::registerFunction(&engine, proto, clone, "clone");
REcmaHelper::registerFunction(&engine, proto, trimEndPoint, "trimEndPoint");
REcmaHelper::registerFunction(&engine, proto, getPointsWithDistanceToEnd, "getPointsWithDistanceToEnd");
REcmaHelper::registerFunction(&engine, proto, reverse, "reverse");
REcmaHelper::registerFunction(&engine, proto, getClippedLine, "getClippedLine");
REcmaHelper::registerFunction(&engine, proto, getVectorTo, "getVectorTo");
REcmaHelper::registerFunction(&engine, proto, stretch, "stretch");
engine.setDefaultPrototype(
qMetaTypeId<RRayPointer>(), *proto);
QScriptValue ctor = engine.newFunction(createEcma, *proto, 2);
// static methods:
// static properties:
// enum values:
// enum conversions:
// init class:
engine.globalObject().setProperty("RRayPointer",
//.........这里部分代码省略.........
示例2: init
// includes for base ecma wrapper classes
void REcmaPenListener::init(QScriptEngine& engine, QScriptValue* proto
)
{
bool protoCreated = false;
if(proto == NULL) {
proto = new QScriptValue(engine.newVariant(qVariantFromValue(
(RPenListener*) 0)));
protoCreated = true;
}
QScriptValue fun;
// toString:
REcmaHelper::registerFunction(&engine, proto, toString, "toString");
// destroy:
REcmaHelper::registerFunction(&engine, proto, destroy, "destroy");
// get class name
REcmaHelper::registerFunction(&engine, proto, getClassName, "getClassName");
// conversion to all base classes (multiple inheritance):
REcmaHelper::registerFunction(&engine, proto, getBaseClasses, "getBaseClasses");
// properties:
// methods:
REcmaHelper::registerFunction(&engine, proto, updatePen, "updatePen");
REcmaHelper::registerFunction(&engine, proto, clearPen, "clearPen");
engine.setDefaultPrototype(
qMetaTypeId<RPenListener*>(), *proto);
QScriptValue ctor = engine.newFunction(create, *proto, 2);
// static methods:
// static properties:
// enum values:
// enum conversions:
// init class:
engine.globalObject().setProperty("RPenListener",
ctor, QScriptValue::SkipInEnumeration);
if( protoCreated ) {
delete proto;
}
}
示例3: testPlayerScript
bool testPlayerScript(QString path, int player, int difficulty)
{
QScriptEngine *engine = new QScriptEngine();
QFile input(path);
input.open(QIODevice::ReadOnly);
QString source(QString::fromUtf8(input.readAll()));
input.close();
// Special functions
engine->globalObject().setProperty("setTimer", engine->newFunction(js_setTimer));
engine->globalObject().setProperty("queue", engine->newFunction(js_queue));
engine->globalObject().setProperty("removeTimer", engine->newFunction(js_removeTimer));
engine->globalObject().setProperty("include", engine->newFunction(js_include));
engine->globalObject().setProperty("bind", engine->newFunction(js_bind));
// Special global variables
engine->globalObject().setProperty("version", 1, QScriptValue::ReadOnly | QScriptValue::Undeletable);
engine->globalObject().setProperty("selectedPlayer", 0, QScriptValue::ReadOnly | QScriptValue::Undeletable);
engine->globalObject().setProperty("gameTime", 2, QScriptValue::ReadOnly | QScriptValue::Undeletable);
engine->globalObject().setProperty("difficulty", 1, QScriptValue::ReadOnly | QScriptValue::Undeletable);
engine->globalObject().setProperty("mapName", "TEST", QScriptValue::ReadOnly | QScriptValue::Undeletable);
engine->globalObject().setProperty("baseType", 1, QScriptValue::ReadOnly | QScriptValue::Undeletable);
engine->globalObject().setProperty("alliancesType", 2, QScriptValue::ReadOnly | QScriptValue::Undeletable);
engine->globalObject().setProperty("powerType", 1, QScriptValue::ReadOnly | QScriptValue::Undeletable);
engine->globalObject().setProperty("maxPlayers", CUR_PLAYERS, QScriptValue::ReadOnly | QScriptValue::Undeletable);
engine->globalObject().setProperty("scavengers", true, QScriptValue::ReadOnly | QScriptValue::Undeletable);
engine->globalObject().setProperty("mapWidth", 80, QScriptValue::ReadOnly | QScriptValue::Undeletable);
engine->globalObject().setProperty("mapHeight", 80, QScriptValue::ReadOnly | QScriptValue::Undeletable);
// Most special global
engine->globalObject().setProperty("me", player, QScriptValue::ReadOnly | QScriptValue::Undeletable);
// Register functions to the script engine here
engine->globalObject().setProperty("_", engine->newFunction(js_translate));
engine->globalObject().setProperty("label", engine->newFunction(js_label));
engine->globalObject().setProperty("enumLabels", engine->newFunction(js_enumLabels));
engine->globalObject().setProperty("enumGateways", engine->newFunction(js_enumGateways));
// horrible hacks follow -- do not rely on these being present!
engine->globalObject().setProperty("hackNetOff", engine->newFunction(js_hackNetOff));
engine->globalObject().setProperty("hackNetOn", engine->newFunction(js_hackNetOn));
engine->globalObject().setProperty("objFromId", engine->newFunction(js_objFromId));
// General functions -- geared for use in AI scripts
engine->globalObject().setProperty("debug", engine->newFunction(js_debug));
engine->globalObject().setProperty("console", engine->newFunction(js_console));
engine->globalObject().setProperty("structureIdle", engine->newFunction(js_structureIdle));
engine->globalObject().setProperty("enumStruct", engine->newFunction(js_enumStruct));
engine->globalObject().setProperty("enumStructOffWorld", engine->newFunction(js_enumStructOffWorld));
engine->globalObject().setProperty("enumDroid", engine->newFunction(js_enumDroid));
engine->globalObject().setProperty("enumGroup", engine->newFunction(js_enumGroup));
engine->globalObject().setProperty("enumFeature", engine->newFunction(js_enumFeature));
engine->globalObject().setProperty("enumBlips", engine->newFunction(js_enumBlips));
engine->globalObject().setProperty("enumResearch", engine->newFunction(js_enumResearch));
engine->globalObject().setProperty("getResearch", engine->newFunction(js_getResearch));
engine->globalObject().setProperty("pursueResearch", engine->newFunction(js_pursueResearch));
engine->globalObject().setProperty("distBetweenTwoPoints", engine->newFunction(js_distBetweenTwoPoints));
engine->globalObject().setProperty("newGroup", engine->newFunction(js_newGroup));
engine->globalObject().setProperty("groupAddArea", engine->newFunction(js_groupAddArea));
engine->globalObject().setProperty("groupAddDroid", engine->newFunction(js_groupAddDroid));
engine->globalObject().setProperty("groupSize", engine->newFunction(js_groupSize));
engine->globalObject().setProperty("orderDroidLoc", engine->newFunction(js_orderDroidLoc));
engine->globalObject().setProperty("playerPower", engine->newFunction(js_playerPower));
engine->globalObject().setProperty("isStructureAvailable", engine->newFunction(js_isStructureAvailable));
engine->globalObject().setProperty("pickStructLocation", engine->newFunction(js_pickStructLocation));
engine->globalObject().setProperty("droidCanReach", engine->newFunction(js_droidCanReach));
engine->globalObject().setProperty("orderDroidStatsLoc", engine->newFunction(js_orderDroidBuild)); // deprecated
engine->globalObject().setProperty("orderDroidBuild", engine->newFunction(js_orderDroidBuild));
engine->globalObject().setProperty("orderDroidObj", engine->newFunction(js_orderDroidObj));
engine->globalObject().setProperty("orderDroid", engine->newFunction(js_orderDroid));
engine->globalObject().setProperty("buildDroid", engine->newFunction(js_buildDroid));
engine->globalObject().setProperty("addDroid", engine->newFunction(js_addDroid));
engine->globalObject().setProperty("addFeature", engine->newFunction(js_addFeature));
engine->globalObject().setProperty("componentAvailable", engine->newFunction(js_componentAvailable));
engine->globalObject().setProperty("isVTOL", engine->newFunction(js_isVTOL));
engine->globalObject().setProperty("safeDest", engine->newFunction(js_safeDest));
engine->globalObject().setProperty("activateStructure", engine->newFunction(js_activateStructure));
engine->globalObject().setProperty("chat", engine->newFunction(js_chat));
// Functions that operate on the current player only
engine->globalObject().setProperty("centreView", engine->newFunction(js_centreView));
engine->globalObject().setProperty("playSound", engine->newFunction(js_playSound));
engine->globalObject().setProperty("gameOverMessage", engine->newFunction(js_gameOverMessage));
// Global state manipulation -- not for use with skirmish AI (unless you want it to cheat, obviously)
engine->globalObject().setProperty("setStructureLimits", engine->newFunction(js_setStructureLimits));
engine->globalObject().setProperty("applyLimitSet", engine->newFunction(js_applyLimitSet));
engine->globalObject().setProperty("setMissionTime", engine->newFunction(js_setMissionTime));
engine->globalObject().setProperty("setReinforcementTime", engine->newFunction(js_setReinforcementTime));
engine->globalObject().setProperty("completeResearch", engine->newFunction(js_completeResearch));
engine->globalObject().setProperty("enableResearch", engine->newFunction(js_enableResearch));
engine->globalObject().setProperty("setPower", engine->newFunction(js_setPower));
engine->globalObject().setProperty("setTutorialMode", engine->newFunction(js_setTutorialMode));
engine->globalObject().setProperty("setDesign", engine->newFunction(js_setDesign));
engine->globalObject().setProperty("setMiniMap", engine->newFunction(js_setMiniMap));
engine->globalObject().setProperty("addReticuleButton", engine->newFunction(js_addReticuleButton));
engine->globalObject().setProperty("removeReticuleButton", engine->newFunction(js_removeReticuleButton));
engine->globalObject().setProperty("enableStructure", engine->newFunction(js_enableStructure));
engine->globalObject().setProperty("makeComponentAvailable", engine->newFunction(js_makeComponentAvailable));
engine->globalObject().setProperty("enableComponent", engine->newFunction(js_enableComponent));
//.........这里部分代码省略.........
示例4: main
int main(int argc, char *argv[])
{
QApplication *app;
if (argc >= 2 && !qstrcmp(argv[1], "-tty")) {
++argv;
--argc;
app = new QApplication(argc, argv, QApplication::Tty);
} else {
app = new QApplication(argc, argv);
}
QScriptEngine *eng = new QScriptEngine();
QScriptValue globalObject = eng->globalObject();
globalObject.setProperty("load", eng->newFunction(loadScripts, /*length=*/1));
{
if (!globalObject.property("qt").isObject())
globalObject.setProperty("qt", eng->newObject());
QScriptValue qscript = eng->newObject();
qscript.setProperty("importExtension", eng->newFunction(importExtension));
globalObject.property("qt").setProperty("script", qscript);
}
ByteArrayClass *byteArrayClass = new ByteArrayClass(eng);
globalObject.setProperty("ByteArray", byteArrayClass->constructor());
if (! *++argv) {
interactive(eng);
return EXIT_SUCCESS;
}
while (const char *arg = *argv++) {
QString fn = QString::fromLocal8Bit(arg);
if (fn == QLatin1String("-i")) {
interactive(eng);
break;
}
QString contents;
int lineNumber = 1;
if (fn == QLatin1String("-")) {
QTextStream stream(stdin, QFile::ReadOnly);
contents = stream.readAll();
}
else {
QFile file(fn);
if (file.open(QFile::ReadOnly)) {
QTextStream stream(&file);
contents = stream.readAll();
file.close();
// strip off #!/usr/bin/env qscript line
if (contents.startsWith("#!")) {
contents.remove(0, contents.indexOf("\n"));
++lineNumber;
}
}
}
if (contents.isEmpty())
continue;
QScriptValue r = eng->evaluate(contents, fn, lineNumber);
if (eng->hasUncaughtException()) {
QStringList backtrace = eng->uncaughtExceptionBacktrace();
fprintf (stderr, " %s\n%s\n\n", qPrintable(r.toString()),
qPrintable(backtrace.join("\n")));
return EXIT_FAILURE;
}
}
delete eng;
delete app;
return EXIT_SUCCESS;
}
示例5: init
void REcmaDimRotatedData::init(QScriptEngine& engine, QScriptValue* proto
)
{
bool protoCreated = false;
if(proto == NULL){
proto = new QScriptValue(engine.newVariant(qVariantFromValue(
(RDimRotatedData*) 0)));
protoCreated = true;
}
// primary base class RDimLinearData:
QScriptValue dpt = engine.defaultPrototype(
qMetaTypeId<RDimLinearData*>());
if (dpt.isValid()) {
proto->setPrototype(dpt);
}
/*
*/
QScriptValue fun;
// toString:
REcmaHelper::registerFunction(&engine, proto, toString, "toString");
// destroy:
REcmaHelper::registerFunction(&engine, proto, destroy, "destroy");
// conversion for base class RDimLinearData
REcmaHelper::registerFunction(&engine, proto, getRDimLinearData, "getRDimLinearData");
// conversion for base class RDimensionData
REcmaHelper::registerFunction(&engine, proto, getRDimensionData, "getRDimensionData");
// conversion for base class REntityData
REcmaHelper::registerFunction(&engine, proto, getREntityData, "getREntityData");
// get class name
REcmaHelper::registerFunction(&engine, proto, getClassName, "getClassName");
// conversion to all base classes (multiple inheritance):
REcmaHelper::registerFunction(&engine, proto, getBaseClasses, "getBaseClasses");
// properties:
// methods:
REcmaHelper::registerFunction(&engine, proto, isValid, "isValid");
REcmaHelper::registerFunction(&engine, proto, setRotation, "setRotation");
REcmaHelper::registerFunction(&engine, proto, getRotation, "getRotation");
REcmaHelper::registerFunction(&engine, proto, getReferencePoints, "getReferencePoints");
REcmaHelper::registerFunction(&engine, proto, rotate, "rotate");
REcmaHelper::registerFunction(&engine, proto, mirror, "mirror");
REcmaHelper::registerFunction(&engine, proto, getShapes, "getShapes");
REcmaHelper::registerFunction(&engine, proto, getMeasuredValue, "getMeasuredValue");
REcmaHelper::registerFunction(&engine, proto, getAutoLabel, "getAutoLabel");
engine.setDefaultPrototype(
qMetaTypeId<RDimRotatedData*>(), *proto);
QScriptValue ctor = engine.newFunction(create, *proto, 2);
// static methods:
// static properties:
// enum values:
// enum conversions:
// init class:
engine.globalObject().setProperty("RDimRotatedData",
//.........这里部分代码省略.........
示例6: addCustomFile
bool DSO::addCustomFile(const QString &fileName)
{
m_lastCustomError = "";
SkFile file(fileName);
if (!file.open(SkFile::ReadOnly | SkFile::Text))
{
m_lastCustomError = tr("File not found!");
return false;
}
QString code;
do
{
if (file.atEnd())
{
break;
}
QString line = file.readLine();
if (line.simplified() == "*DATA")
{
break;
}
code += line;
} while (true);
QScriptEngine engine;
scriptNewTypes.clear();
engine.globalObject().setProperty("AUTHOR", "");
engine.globalObject().setProperty("EPOCH", 2000);
engine.globalObject().setProperty("DESCRIPTION", "");
engine.globalObject().setProperty("POINT_SOURCE", 0);
engine.globalObject().setProperty("CIRCLE", 1);
engine.globalObject().setProperty("CROSS", 2);
engine.globalObject().setProperty("RECTANGLE", 3);
QScriptValue fun = engine.newFunction(DEFINE_CUSTOM_OBJECT, 3);
engine.globalObject().setProperty("DEFINE_CUSTOM_OBJECT", fun);
QScriptValue result = engine.evaluate(code);
if (engine.hasUncaughtException())
{
int line = engine.uncaughtExceptionLineNumber();
m_lastCustomError = QString("uncaught exception at line ") + line + " : " + result.toString();
return false;
}
QString author;
QString description;
double epoch;
int nameOffset = 0; // TODO: dat globalne
QScriptValueIterator it(engine.globalObject());
while (it.hasNext())
{
it.next();
if (it.name() == "AUTHOR")
{
author = it.value().toString();
}
else
if (it.name() == "DESCRIPTION")
{
description = it.value().toString();
}
else
if (it.name() == "EPOCH")
{
epoch = it.value().toNumber();
}
}
do
{
if (file.atEnd())
{
break;
}
QString line = file.readLine().simplified();
if (line.startsWith("//"))
{
continue;
}
if (line.size() == 0)
{
continue;
}
QStringList list = line.split("|");
//.........这里部分代码省略.........
示例7: doImport
//.........这里部分代码省略.........
return;
}
fileName = tempFilename;
qDebug() << "TextImportDialog::doImport(): Preprocessor completed, using preproc temp file: "<<tempFilename;
}
// Load text file
QFile file(fileName);
if(!file.open(QIODevice::ReadOnly))
{
QMessageBox::critical(this,tr("Can't Read File"),QString(tr("Unable to open %1")).arg(fileName));
return;
}
QTextStream stream(&file);
QString fileContents = stream.readAll();
if(!tempFilename.isEmpty())
file.remove(); // file is closed before it is removed
// Remove the paste buffer
//if(!pastedTempfile.isEmpty())
// QFile(pastedTempfile).remove();
// Load script file
QScriptEngine scriptEngine;
if(!scriptFilename.isEmpty())
{
// For debug output
static_currentScriptFile = scriptFilename;
// Install some custom functions for the script
QScriptValue fDebug = scriptEngine.newFunction(TextImportDialog_script_qDebug);
QScriptValue fFindTextItem = scriptEngine.newFunction(TextImportDialog_script_findTextItem);
QScriptValue fChangeFntSz = scriptEngine.newFunction(TextImportDialog_script_changeFontSize);
QScriptValue fFindFntSz = scriptEngine.newFunction(TextImportDialog_script_findFontSize);
QScriptValue fCntrTextBox = scriptEngine.newFunction(TextImportDialog_script_intelligentCenterTextbox);
QScriptValue fFileList = scriptEngine.newFunction(TextImportDialog_script_getFileList);
QScriptValue fChangeBg = scriptEngine.newFunction(TextImportDialog_script_changeSlideBackground);
QScriptValue fGuessTimeout = scriptEngine.newFunction(TextImportDialog_script_guessSlideTimeout);
scriptEngine.globalObject().setProperty("debug", fDebug);
scriptEngine.globalObject().setProperty("findTextItem", fFindTextItem);
scriptEngine.globalObject().setProperty("changeFontSize", fChangeFntSz);
scriptEngine.globalObject().setProperty("findFontSize", fFindFntSz);
scriptEngine.globalObject().setProperty("intelligentCenterTextbox", fCntrTextBox);
scriptEngine.globalObject().setProperty("getFileList", fFileList);
scriptEngine.globalObject().setProperty("changeSlideBackground", fChangeBg);
scriptEngine.globalObject().setProperty("guessSlideTimeout", fGuessTimeout);
scriptEngine.globalObject().setProperty("InPrimaryGroup", true);
QScriptValue scriptBibleBrowser = scriptEngine.newQObject(MainWindow::mw()->bibleBrowser());
scriptEngine.globalObject().setProperty("BibleBrowser", scriptBibleBrowser);
// Read the file
QFile scriptFile(scriptFilename);
if(!scriptFile.open(QIODevice::ReadOnly))
{
QMessageBox::critical(this,tr("Can't Read Script"),QString(tr("Unable to open script %1")).arg(fileName));
return;
}
// Evaulate the contents of the file
QTextStream stream(&scriptFile);
示例8: Register
void QHistogram::Register(QScriptEngine& engine)
{
QScriptValue ctor = engine.newFunction(QHistogram::New);
QScriptValue metaObject = engine.newQMetaObject(&QHistogram::staticMetaObject, ctor);
engine.globalObject().setProperty("Histogram", metaObject);
}
示例9: initEcma
void REcmaSpatialIndexNavel::initEcma(QScriptEngine& engine, QScriptValue* proto
)
{
bool protoCreated = false;
if(proto == NULL){
proto = new QScriptValue(engine.newVariant(qVariantFromValue(
(RSpatialIndexNavel*) 0)));
protoCreated = true;
}
// primary base class RSpatialIndex:
QScriptValue dpt = engine.defaultPrototype(
qMetaTypeId<RSpatialIndex*>());
if (dpt.isValid()) {
proto->setPrototype(dpt);
}
/*
*/
QScriptValue fun;
// toString:
REcmaHelper::registerFunction(&engine, proto, toString, "toString");
// destroy:
REcmaHelper::registerFunction(&engine, proto, destroy, "destroy");
// conversion for base class RSpatialIndex
REcmaHelper::registerFunction(&engine, proto, getRSpatialIndex, "getRSpatialIndex");
// conversion for base class RRequireHeap
REcmaHelper::registerFunction(&engine, proto, getRRequireHeap, "getRRequireHeap");
// get class name
REcmaHelper::registerFunction(&engine, proto, getClassName, "getClassName");
// conversion to all base classes (multiple inheritance):
REcmaHelper::registerFunction(&engine, proto, getBaseClasses, "getBaseClasses");
// properties:
// methods:
REcmaHelper::registerFunction(&engine, proto, clear, "clear");
REcmaHelper::registerFunction(&engine, proto, bulkLoad, "bulkLoad");
REcmaHelper::registerFunction(&engine, proto, addToIndex, "addToIndex");
REcmaHelper::registerFunction(&engine, proto, removeFromIndex, "removeFromIndex");
REcmaHelper::registerFunction(&engine, proto, queryIntersected, "queryIntersected");
REcmaHelper::registerFunction(&engine, proto, queryIntersectedSimple, "queryIntersectedSimple");
REcmaHelper::registerFunction(&engine, proto, queryContained, "queryContained");
REcmaHelper::registerFunction(&engine, proto, queryNearestNeighbor, "queryNearestNeighbor");
engine.setDefaultPrototype(
qMetaTypeId<RSpatialIndexNavel*>(), *proto);
QScriptValue ctor = engine.newFunction(create, *proto, 2);
// static methods:
// static properties:
// enum values:
// enum conversions:
// init class:
engine.globalObject().setProperty("RSpatialIndexNavel",
ctor, QScriptValue::SkipInEnumeration);
if( protoCreated ){
delete proto;
}
//.........这里部分代码省略.........
示例10: initEcma
// includes for base ecma wrapper classes
void REcmaLinetypeCombo::initEcma(QScriptEngine& engine, QScriptValue* proto
)
{
bool protoCreated = false;
if(proto == NULL){
proto = new QScriptValue(engine.newVariant(qVariantFromValue(
(RLinetypeCombo*) 0)));
protoCreated = true;
}
// primary base class QComboBox:
QScriptValue dpt = engine.defaultPrototype(
qMetaTypeId<QComboBox*>());
if (dpt.isValid()) {
proto->setPrototype(dpt);
}
/*
*/
QScriptValue fun;
// toString:
REcmaHelper::registerFunction(&engine, proto, toString, "toString");
// destroy:
REcmaHelper::registerFunction(&engine, proto, destroy, "destroy");
// conversion for base class QComboBox
REcmaHelper::registerFunction(&engine, proto, getQComboBox, "getQComboBox");
// get class name
REcmaHelper::registerFunction(&engine, proto, getClassName, "getClassName");
// conversion to all base classes (multiple inheritance):
REcmaHelper::registerFunction(&engine, proto, getBaseClasses, "getBaseClasses");
// properties:
// methods:
REcmaHelper::registerFunction(&engine, proto, init, "init");
REcmaHelper::registerFunction(&engine, proto, reinit, "reinit");
REcmaHelper::registerFunction(&engine, proto, getLinetypePattern, "getLinetypePattern");
REcmaHelper::registerFunction(&engine, proto, getLinetypePatternAt, "getLinetypePatternAt");
REcmaHelper::registerFunction(&engine, proto, setLinetypePattern, "setLinetypePattern");
REcmaHelper::registerFunction(&engine, proto, getOnlyFixed, "getOnlyFixed");
REcmaHelper::registerFunction(&engine, proto, setOnlyFixed, "setOnlyFixed");
REcmaHelper::registerFunction(&engine, proto, linetypePatternChanged, "linetypePatternChanged");
engine.setDefaultPrototype(
qMetaTypeId<RLinetypeCombo*>(), *proto);
qScriptRegisterMetaType<
RLinetypeCombo*>(
&engine, toScriptValue, fromScriptValue, *proto);
QScriptValue ctor = engine.newFunction(createEcma, *proto, 2);
// static methods:
// static properties:
// enum values:
// enum conversions:
// init class:
engine.globalObject().setProperty("RLinetypeCombo",
ctor, QScriptValue::SkipInEnumeration);
if( protoCreated ){
//.........这里部分代码省略.........
示例11: initEcma
// includes for base ecma wrapper classes
void REcmaImporter::initEcma(QScriptEngine& engine, QScriptValue* proto
)
{
bool protoCreated = false;
if(proto == NULL){
proto = new QScriptValue(engine.newVariant(qVariantFromValue(
(RImporter*) 0)));
protoCreated = true;
}
QScriptValue fun;
// toString:
REcmaHelper::registerFunction(&engine, proto, toString, "toString");
// destroy:
REcmaHelper::registerFunction(&engine, proto, destroy, "destroy");
// get class name
REcmaHelper::registerFunction(&engine, proto, getClassName, "getClassName");
// conversion to all base classes (multiple inheritance):
REcmaHelper::registerFunction(&engine, proto, getBaseClasses, "getBaseClasses");
// properties:
// methods:
REcmaHelper::registerFunction(&engine, proto, startImport, "startImport");
REcmaHelper::registerFunction(&engine, proto, endImport, "endImport");
REcmaHelper::registerFunction(&engine, proto, importObject, "importObject");
REcmaHelper::registerFunction(&engine, proto, setCurrentBlockId, "setCurrentBlockId");
REcmaHelper::registerFunction(&engine, proto, getCurrentBlockId, "getCurrentBlockId");
REcmaHelper::registerFunction(&engine, proto, getDocument, "getDocument");
REcmaHelper::registerFunction(&engine, proto, setDocument, "setDocument");
REcmaHelper::registerFunction(&engine, proto, setKnownVariable, "setKnownVariable");
engine.setDefaultPrototype(
qMetaTypeId<RImporter*>(), *proto);
QScriptValue ctor = engine.newFunction(create, *proto, 2);
// static methods:
// static properties:
// enum values:
// enum conversions:
// init class:
engine.globalObject().setProperty("RImporter",
ctor, QScriptValue::SkipInEnumeration);
if( protoCreated ){
delete proto;
}
}
示例12: init
// includes for base ecma wrapper classes
void REcmaLinetypePattern::init(QScriptEngine& engine, QScriptValue* proto
)
{
bool protoCreated = false;
if(proto == NULL){
proto = new QScriptValue(engine.newVariant(qVariantFromValue(
(RLinetypePattern*) 0)));
protoCreated = true;
}
QScriptValue fun;
// toString:
REcmaHelper::registerFunction(&engine, proto, toString, "toString");
// copy:
REcmaHelper::registerFunction(&engine, proto, copy, "copy");
// destroy:
REcmaHelper::registerFunction(&engine, proto, destroy, "destroy");
// get class name
REcmaHelper::registerFunction(&engine, proto, getClassName, "getClassName");
// conversion to all base classes (multiple inheritance):
REcmaHelper::registerFunction(&engine, proto, getBaseClasses, "getBaseClasses");
// properties:
// methods:
REcmaHelper::registerFunction(&engine, proto, set, "set");
REcmaHelper::registerFunction(&engine, proto, isValid, "isValid");
REcmaHelper::registerFunction(&engine, proto, getNumDashes, "getNumDashes");
REcmaHelper::registerFunction(&engine, proto, getPatternLength, "getPatternLength");
REcmaHelper::registerFunction(&engine, proto, getDashLengthAt, "getDashLengthAt");
REcmaHelper::registerFunction(&engine, proto, getLargestGap, "getLargestGap");
REcmaHelper::registerFunction(&engine, proto, hasDashAt, "hasDashAt");
REcmaHelper::registerFunction(&engine, proto, getDelta, "getDelta");
REcmaHelper::registerFunction(&engine, proto, isSymmetrical, "isSymmetrical");
REcmaHelper::registerFunction(&engine, proto, scale, "scale");
REcmaHelper::registerFunction(&engine, proto, operator_assign, "operator_assign");
REcmaHelper::registerFunction(&engine, proto, equals, "equals");
engine.setDefaultPrototype(
qMetaTypeId<RLinetypePattern*>(), *proto);
engine.setDefaultPrototype(qMetaTypeId<
RLinetypePattern
> (), *proto);
QScriptValue ctor = engine.newFunction(create, *proto, 2);
// static methods:
// static properties:
// enum values:
// enum conversions:
// init class:
engine.globalObject().setProperty("RLinetypePattern",
ctor, QScriptValue::SkipInEnumeration);
if( protoCreated ){
delete proto;
}
}
示例13: init
void REcmaPointEntity::init(QScriptEngine& engine, QScriptValue* proto
)
{
bool protoCreated = false;
if(proto == NULL){
proto = new QScriptValue(engine.newVariant(qVariantFromValue(
(RPointEntity*) 0)));
protoCreated = true;
}
// primary base class REntity:
QScriptValue dpt = engine.defaultPrototype(
qMetaTypeId<REntity*>());
if (dpt.isValid()) {
proto->setPrototype(dpt);
}
/*
*/
QScriptValue fun;
// toString:
REcmaHelper::registerFunction(&engine, proto, toString, "toString");
// destroy:
REcmaHelper::registerFunction(&engine, proto, destroy, "destroy");
// conversion for base class REntity
REcmaHelper::registerFunction(&engine, proto, getREntity, "getREntity");
// conversion for base class RObject
REcmaHelper::registerFunction(&engine, proto, getRObject, "getRObject");
// get class name
REcmaHelper::registerFunction(&engine, proto, getClassName, "getClassName");
// conversion to all base classes (multiple inheritance):
REcmaHelper::registerFunction(&engine, proto, getBaseClasses, "getBaseClasses");
// properties:
// methods:
REcmaHelper::registerFunction(&engine, proto, clone, "clone");
REcmaHelper::registerFunction(&engine, proto, getType, "getType");
REcmaHelper::registerFunction(&engine, proto, setProperty, "setProperty");
REcmaHelper::registerFunction(&engine, proto, getProperty, "getProperty");
REcmaHelper::registerFunction(&engine, proto, exportEntity, "exportEntity");
REcmaHelper::registerFunction(&engine, proto, getData, "getData");
REcmaHelper::registerFunction(&engine, proto, getPosition, "getPosition");
engine.setDefaultPrototype(
qMetaTypeId<RPointEntity*>(), *proto);
QScriptValue ctor = engine.newFunction(create, *proto, 2);
// static methods:
REcmaHelper::registerFunction(&engine, &ctor, init, "init");
// static properties:
ctor.setProperty("PropertyCustom",
qScriptValueFromValue(&engine, RPointEntity::PropertyCustom),
QScriptValue::SkipInEnumeration | QScriptValue::ReadOnly);
ctor.setProperty("PropertyHandle",
qScriptValueFromValue(&engine, RPointEntity::PropertyHandle),
QScriptValue::SkipInEnumeration | QScriptValue::ReadOnly);
ctor.setProperty("PropertyType",
qScriptValueFromValue(&engine, RPointEntity::PropertyType),
QScriptValue::SkipInEnumeration | QScriptValue::ReadOnly);
ctor.setProperty("PropertyBlock",
qScriptValueFromValue(&engine, RPointEntity::PropertyBlock),
//.........这里部分代码省略.........
示例14: init
void REcmaLeaderData::init(QScriptEngine& engine, QScriptValue* proto
)
{
bool protoCreated = false;
if(proto == NULL){
proto = new QScriptValue(engine.newVariant(qVariantFromValue(
(RLeaderData*) 0)));
protoCreated = true;
}
// primary base class REntityData:
QScriptValue dpt = engine.defaultPrototype(
qMetaTypeId<REntityData*>());
if (dpt.isValid()) {
proto->setPrototype(dpt);
}
/*
REcmaPolyline::init(engine, proto);
*/
QScriptValue fun;
// toString:
REcmaHelper::registerFunction(&engine, proto, toString, "toString");
// destroy:
REcmaHelper::registerFunction(&engine, proto, destroy, "destroy");
// conversion for base class REntityData
REcmaHelper::registerFunction(&engine, proto, getREntityData, "getREntityData");
// get class name
REcmaHelper::registerFunction(&engine, proto, getClassName, "getClassName");
// conversion to all base classes (multiple inheritance):
REcmaHelper::registerFunction(&engine, proto, getBaseClasses, "getBaseClasses");
// properties:
// methods:
REcmaHelper::registerFunction(&engine, proto, castToShape, "castToShape");
REcmaHelper::registerFunction(&engine, proto, getDimasz, "getDimasz");
REcmaHelper::registerFunction(&engine, proto, getDimscale, "getDimscale");
REcmaHelper::registerFunction(&engine, proto, setArrowHead, "setArrowHead");
REcmaHelper::registerFunction(&engine, proto, hasArrowHead, "hasArrowHead");
REcmaHelper::registerFunction(&engine, proto, getEndPoint, "getEndPoint");
REcmaHelper::registerFunction(&engine, proto, getStartPoint, "getStartPoint");
REcmaHelper::registerFunction(&engine, proto, countVertices, "countVertices");
REcmaHelper::registerFunction(&engine, proto, countSegments, "countSegments");
REcmaHelper::registerFunction(&engine, proto, appendVertex, "appendVertex");
REcmaHelper::registerFunction(&engine, proto, getReferencePoints, "getReferencePoints");
REcmaHelper::registerFunction(&engine, proto, moveReferencePoint, "moveReferencePoint");
REcmaHelper::registerFunction(&engine, proto, getExploded, "getExploded");
REcmaHelper::registerFunction(&engine, proto, getShapes, "getShapes");
REcmaHelper::registerFunction(&engine, proto, getArrowShape, "getArrowShape");
engine.setDefaultPrototype(
qMetaTypeId<RLeaderData*>(), *proto);
QScriptValue ctor = engine.newFunction(create, *proto, 2);
// static methods:
// static properties:
// enum values:
//.........这里部分代码省略.........
示例15: throwError
void tst_QScriptContext::throwError()
{
QScriptEngine eng;
{
QScriptValue fun = eng.newFunction(throw_Error);
eng.globalObject().setProperty("throw_Error", fun);
QScriptValue result = eng.evaluate("throw_Error()");
QCOMPARE(eng.hasUncaughtException(), true);
QCOMPARE(result.isError(), true);
QCOMPARE(result.toString(), QString("Error: foo"));
}
{
QScriptValue fun = eng.newFunction(throw_TypeError);
eng.globalObject().setProperty("throw_TypeError", fun);
QScriptValue result = eng.evaluate("throw_TypeError()");
QCOMPARE(eng.hasUncaughtException(), true);
QCOMPARE(result.isError(), true);
QCOMPARE(result.toString(), QString("TypeError: foo"));
}
{
QScriptValue fun = eng.newFunction(throw_ReferenceError);
eng.globalObject().setProperty("throw_ReferenceError", fun);
QScriptValue result = eng.evaluate("throw_ReferenceError()");
QCOMPARE(eng.hasUncaughtException(), true);
QCOMPARE(result.isError(), true);
QCOMPARE(result.toString(), QString("ReferenceError: foo"));
}
{
QScriptValue fun = eng.newFunction(throw_SyntaxError);
eng.globalObject().setProperty("throw_SyntaxError", fun);
QScriptValue result = eng.evaluate("throw_SyntaxError()");
QCOMPARE(eng.hasUncaughtException(), true);
QCOMPARE(result.isError(), true);
QCOMPARE(result.toString(), QString("SyntaxError: foo"));
}
{
QScriptValue fun = eng.newFunction(throw_RangeError);
eng.globalObject().setProperty("throw_RangeError", fun);
QScriptValue result = eng.evaluate("throw_RangeError()");
QCOMPARE(eng.hasUncaughtException(), true);
QCOMPARE(result.isError(), true);
QCOMPARE(result.toString(), QString("RangeError: foo"));
}
{
QScriptValue fun = eng.newFunction(throw_URIError);
eng.globalObject().setProperty("throw_URIError", fun);
QScriptValue result = eng.evaluate("throw_URIError()");
QCOMPARE(eng.hasUncaughtException(), true);
QCOMPARE(result.isError(), true);
QCOMPARE(result.toString(), QString("URIError: foo"));
}
{
QScriptValue fun = eng.newFunction(throw_ErrorAndReturnUndefined);
eng.globalObject().setProperty("throw_ErrorAndReturnUndefined", fun);
QScriptValue result = eng.evaluate("throw_ErrorAndReturnUndefined()");
QVERIFY(eng.hasUncaughtException());
QVERIFY(result.isError());
QCOMPARE(result.toString(), QString("Error: foo"));
}
}