소스 검색

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);

Loading…
취소
저장