浏览代码

Units can be passed through signals to script handlers

Neal Wilson 11 年前
父节点
当前提交
09aa7caad8
共有 1 个文件被更改,包括 29 次插入0 次删除
  1. 29
    0
      src/units.w

+ 29
- 0
src/units.w 查看文件

@@ -370,3 +370,32 @@ enumeration.
370 370
 value = engine->newQMetaObject(&Units::staticMetaObject);
371 371
 engine->globalObject().setProperty("Units", value);
372 372
 
373
+@ While the above is sufficient for some uses, others require some additional
374
+work.
375
+
376
+@<Class declarations@>=
377
+Q_DECLARE_METATYPE(Units::Unit)
378
+
379
+@ A pair of conversion methods is required.
380
+
381
+@<Function prototypes for scripting@>=
382
+QScriptValue Unit_toScriptValue(QScriptEngine *engine, const Units::Unit &value);
383
+void Unit_fromScriptValue(const QScriptValue &sv, Units::Unit &value);
384
+
385
+@ These are implemented thusly.
386
+
387
+@<Functions for scripting@>=
388
+QScriptValue Unit_toScriptValue(QScriptEngine *engine, const Units::Unit &value)
389
+{
390
+	return engine->newVariant(QVariant(value));
391
+}
392
+
393
+void Unit_fromScriptValue(const QScriptValue &sv, Units::Unit &value)
394
+{
395
+	value = sv.toVariant().value<Units::Unit>();
396
+}
397
+
398
+@ These conversion functions are registered.
399
+
400
+@<Set up the scripting engine@>=
401
+qScriptRegisterMetaType(engine, Unit_toScriptValue, Unit_fromScriptValue);

正在加载...
取消
保存