|
@@ -197,6 +197,94 @@ constructor = engine->newFunction(constructSerialScale);
|
197
|
197
|
value = engine->newQMetaObject(&SerialScale::staticMetaObject, constructor);
|
198
|
198
|
engine->globalObject().setProperty("SerialScale", value);
|
199
|
199
|
|
|
200
|
+@ If we are to set up the serial ports from the host environment, a few
|
|
201
|
+enumerated types must be made known to the meta-object system.
|
|
202
|
+
|
|
203
|
+@<Class declarations@>=
|
|
204
|
+Q_DECLARE_METATYPE(BaudRateType)
|
|
205
|
+Q_DECLARE_METATYPE(DataBitsType)
|
|
206
|
+Q_DECLARE_METATYPE(ParityType)
|
|
207
|
+Q_DECLARE_METATYPE(StopBitsType)
|
|
208
|
+Q_DECLARE_METATYPE(FlowType)
|
|
209
|
+
|
|
210
|
+@ For each of these, a pair of functions converts values to script values and
|
|
211
|
+back. This is a very annoying aspect of the version of QextSerialPort currently
|
|
212
|
+used by \pn{}.
|
|
213
|
+
|
|
214
|
+@<Function prototypes for scripting@>=
|
|
215
|
+QScriptValue BaudRateType_toScriptValue(QScriptEngine *engine, const BaudRateType &value);
|
|
216
|
+void BaudRateType_fromScriptValue(const QScriptValue &sv, BaudRateType &value);
|
|
217
|
+QScriptValue DataBitsType_toScriptValue(QScriptEngine *engine, const DataBitsType &value);
|
|
218
|
+void DataBitsType_fromScriptValue(const QScriptValue &sv, DataBitsType &value);
|
|
219
|
+QScriptValue ParityType_toScriptValue(QScriptEngine *engine, const ParityType &value);
|
|
220
|
+void ParityType_fromScriptValue(const QScriptValue &sv, ParityType &value);
|
|
221
|
+QScriptValue StopBitsType_toScriptValue(QScriptEngine *engine, const StopBitsType &value);
|
|
222
|
+void StopBitsType_fromScriptValue(const QScriptValue &sv, StopBitsType &value);
|
|
223
|
+QScriptValue FlowType_toScriptValue(QScriptEngine *engine, const FlowType &value);
|
|
224
|
+void FlowType_fromScriptValue(const QScriptValue &sv, FlowType &value);
|
|
225
|
+
|
|
226
|
+@ These are implemented thusly.
|
|
227
|
+
|
|
228
|
+@<Functions for scripting@>=
|
|
229
|
+QScriptValue BaudRateType_toScriptValue(QScriptEngine *engine, const BaudRateType &value)
|
|
230
|
+{
|
|
231
|
+ return engine->newVariant(QVariant((int)(value)));
|
|
232
|
+}
|
|
233
|
+
|
|
234
|
+void BaudRateType_fromScriptValue(const QScriptValue &sv, BaudRateType &value)
|
|
235
|
+{
|
|
236
|
+ value = (BaudRateType)(sv.toVariant().toInt());
|
|
237
|
+}
|
|
238
|
+
|
|
239
|
+QScriptValue DataBitsType_toScriptValue(QScriptEngine *engine, const DataBitsType &value)
|
|
240
|
+{
|
|
241
|
+ return engine->newVariant(QVariant((int)(value)));
|
|
242
|
+}
|
|
243
|
+
|
|
244
|
+void DataBitsType_fromScriptValue(const QScriptValue &sv, DataBitsType &value)
|
|
245
|
+{
|
|
246
|
+ value = (DataBitsType)(sv.toVariant().toInt());
|
|
247
|
+}
|
|
248
|
+
|
|
249
|
+QScriptValue ParityType_toScriptValue(QScriptEngine *engine, const ParityType &value)
|
|
250
|
+{
|
|
251
|
+ return engine->newVariant(QVariant((int)(value)));
|
|
252
|
+}
|
|
253
|
+
|
|
254
|
+void ParityType_fromScriptValue(const QScriptValue &sv, ParityType &value)
|
|
255
|
+{
|
|
256
|
+ value = (ParityType)(sv.toVariant().toInt());
|
|
257
|
+}
|
|
258
|
+
|
|
259
|
+QScriptValue StopBitsType_toScriptValue(QScriptEngine *engine, const StopBitsType &value)
|
|
260
|
+{
|
|
261
|
+ return engine->newVariant(QVariant((int)(value)));
|
|
262
|
+}
|
|
263
|
+
|
|
264
|
+void StopBitsType_fromScriptValue(const QScriptValue &sv, StopBitsType &value)
|
|
265
|
+{
|
|
266
|
+ value = (StopBitsType)(sv.toVariant().toInt());
|
|
267
|
+}
|
|
268
|
+
|
|
269
|
+QScriptValue FlowType_toScriptValue(QScriptEngine *engine, const FlowType &value)
|
|
270
|
+{
|
|
271
|
+ return engine->newVariant(QVariant((int)(value)));
|
|
272
|
+}
|
|
273
|
+
|
|
274
|
+void FlowType_fromScriptValue(const QScriptValue &sv, FlowType &value)
|
|
275
|
+{
|
|
276
|
+ value = (FlowType)(sv.toVariant().toInt());
|
|
277
|
+}
|
|
278
|
+
|
|
279
|
+@ These conversion functions are then registered.
|
|
280
|
+
|
|
281
|
+@<Set up the scripting engine@>=
|
|
282
|
+qScriptRegisterMetaType(engine, BaudRateType_toScriptValue, BaudRateType_fromScriptValue);
|
|
283
|
+qScriptRegisterMetaType(engine, DataBitsType_toScriptValue, DataBitsType_fromScriptValue);
|
|
284
|
+qScriptRegisterMetaType(engine, ParityType_toScriptValue, ParityType_fromScriptValue);
|
|
285
|
+qScriptRegisterMetaType(engine, StopBitsType_toScriptValue, StopBitsType_fromScriptValue);
|
|
286
|
+qScriptRegisterMetaType(engine, FlowType_toScriptValue, FlowType_fromScriptValue);
|
|
287
|
+
|
200
|
288
|
@ In order to make this class available to the host environment, we must also
|
201
|
289
|
include the appropriate header file.
|
202
|
290
|
|