Quellcode durchsuchen

Wrap host exposed methods taking Units::Unit to enforce type cast

Neal Wilson vor 12 Jahren
Ursprung
Commit
cd7b30aca2
5 geänderte Dateien mit 56 neuen und 8 gelöschten Zeilen
  1. 2
    2
      config/Windows/offline.xml
  2. 4
    4
      config/Windows/productionroaster.xml
  3. 2
    2
      config/Windows/profilehistory.xml
  4. 39
    0
      src/typica.w
  5. 9
    0
      src/units.w

+ 2
- 2
config/Windows/offline.xml Datei anzeigen

91
 			});
91
 			});
92
 			var showC = findChildObject(this, 'showC');
92
 			var showC = findChildObject(this, 'showC');
93
 			showC.triggered.connect(function() {
93
 			showC.triggered.connect(function() {
94
-				log.setDisplayUnits(DAQ.Celsius);
94
+				log.setDisplayUnits(Units.Celsius);
95
 				graph.showC();
95
 				graph.showC();
96
 			});
96
 			});
97
 			var showF = findChildObject(this, 'showF');
97
 			var showF = findChildObject(this, 'showF');
98
 			showF.triggered.connect(function() {
98
 			showF.triggered.connect(function() {
99
-				log.setDisplayUnits(DAQ.Fahrenheit);
99
+				log.setDisplayUnits(Units.Fahrenheit);
100
 				graph.showF();
100
 				graph.showF();
101
 			});
101
 			});
102
 			var v1 = findChildObject(this, 'ms');
102
 			var v1 = findChildObject(this, 'ms');

+ 4
- 4
config/Windows/productionroaster.xml Datei anzeigen

573
         showC.triggered.connect(function() {
573
         showC.triggered.connect(function() {
574
 			for(var i = 0; i < temperatureDisplays.length; i++)
574
 			for(var i = 0; i < temperatureDisplays.length; i++)
575
 			{
575
 			{
576
-				temperatureDisplays[i].setDisplayUnits(DAQ.Celsius);
576
+				temperatureDisplays[i].setDisplayUnits(Units.Celsius);
577
 			}
577
 			}
578
-            log.setDisplayUnits(DAQ.Celsius);
578
+            log.setDisplayUnits(Units.Celsius);
579
             graph.showC();
579
             graph.showC();
580
         });
580
         });
581
         var showF = findChildObject(this, 'showF');
581
         var showF = findChildObject(this, 'showF');
582
         showF.triggered.connect(function() {
582
         showF.triggered.connect(function() {
583
 			for(var i = 0; i < temperatureDisplays.length; i++)
583
 			for(var i = 0; i < temperatureDisplays.length; i++)
584
 			{
584
 			{
585
-				temperatureDisplays[i].setDisplayUnits(DAQ.Fahrenheit);
585
+				temperatureDisplays[i].setDisplayUnits(Units.Fahrenheit);
586
 			}
586
 			}
587
-            log.setDisplayUnits(DAQ.Fahrenheit);
587
+            log.setDisplayUnits(Units.Fahrenheit);
588
             graph.showF();
588
             graph.showF();
589
         });
589
         });
590
 		var clear = findChildObject(this, 'clear');
590
 		var clear = findChildObject(this, 'clear');

+ 2
- 2
config/Windows/profilehistory.xml Datei anzeigen

120
         v7.triggered.connect(log.LOD_1m);
120
         v7.triggered.connect(log.LOD_1m);
121
 		var showC = findChildObject(this, 'showC');
121
 		var showC = findChildObject(this, 'showC');
122
 		showC.triggered.connect(function() {
122
 		showC.triggered.connect(function() {
123
-			log.setDisplayUnits(DAQ.Celsius);
123
+			log.setDisplayUnits(Units.Celsius);
124
 			graph.showC();
124
 			graph.showC();
125
 		});
125
 		});
126
 		var showF = findChildObject(this, 'showF');
126
 		var showF = findChildObject(this, 'showF');
127
 		showF.triggered.connect(function() {
127
 		showF.triggered.connect(function() {
128
-			log.setDisplayUnits(DAQ.Fahrenheit);
128
+			log.setDisplayUnits(Units.Fahrenheit);
129
 			graph.showF();
129
 			graph.showF();
130
 		});
130
 		});
131
 	]]>
131
 	]]>

+ 39
- 0
src/typica.w Datei anzeigen

7230
 QScriptValue constructTemperatureDisplay(QScriptContext *context,
7230
 QScriptValue constructTemperatureDisplay(QScriptContext *context,
7231
                                          QScriptEngine *engine);
7231
                                          QScriptEngine *engine);
7232
 void setTemperatureDisplayProperties(QScriptValue value, QScriptEngine *engine);
7232
 void setTemperatureDisplayProperties(QScriptValue value, QScriptEngine *engine);
7233
+QScriptValue TemperatureDisplay_setDisplayUnits(QScriptContext *context,
7234
+                                                QScriptEngine *engine);
7233
 
7235
 
7234
 @ The scripting engine must be informed of this function.
7236
 @ The scripting engine must be informed of this function.
7235
 
7237
 
7253
 void setTemperatureDisplayProperties(QScriptValue value, QScriptEngine *engine)
7255
 void setTemperatureDisplayProperties(QScriptValue value, QScriptEngine *engine)
7254
 {
7256
 {
7255
 	setQLCDNumberProperties(value, engine);
7257
 	setQLCDNumberProperties(value, engine);
7258
+	value.setProperty("setDisplayUnits",
7259
+	                  engine->newFunction(TemperatureDisplay_setDisplayUnits));
7260
+}
7261
+
7262
+@ There seems to be a bad interaction when enumerated value types as used as
7263
+the argument to slot methods called through QtScript. Script code that attempts
7264
+to make use of the enumeration appears to get the value without any type
7265
+information. When attempting to use that value as an argument the meta-object
7266
+system cannot find an appropriate match and the script just hangs silently.
7267
+The solution is to wrap such methods in the script bindings and explicitly cast
7268
+the argument value to the enumerated type. This looks stupid but it works.
7269
+
7270
+@<Functions for scripting@>=
7271
+QScriptValue TemperatureDisplay_setDisplayUnits(QScriptContext *context, QScriptEngine *)
7272
+{
7273
+	TemperatureDisplay *self = getself<@[TemperatureDisplay *@]>(context);
7274
+	self->setDisplayUnits((Units::Unit)argument<int>(0, context));
7275
+	return QScriptValue();
7256
 }
7276
 }
7257
 
7277
 
7258
 @* The MeasurementTimeOffset class.
7278
 @* The MeasurementTimeOffset class.
8611
 QScriptValue ZoomLog_lastTime(QScriptContext *context, QScriptEngine *engine);
8631
 QScriptValue ZoomLog_lastTime(QScriptContext *context, QScriptEngine *engine);
8612
 QScriptValue ZoomLog_saveTemporary(QScriptContext *context,
8632
 QScriptValue ZoomLog_saveTemporary(QScriptContext *context,
8613
                                    QScriptEngine *engnie);
8633
                                    QScriptEngine *engnie);
8634
+QScriptValue ZoomLog_setDisplayUnits(QScriptContext *context,
8635
+                                     QScriptEngine *engine);
8614
 
8636
 
8615
 @ Of these, the global object only needs to know about the constructor.
8637
 @ Of these, the global object only needs to know about the constructor.
8616
 
8638
 
8641
 	value.setProperty("lastTime", engine->newFunction(ZoomLog_lastTime));
8663
 	value.setProperty("lastTime", engine->newFunction(ZoomLog_lastTime));
8642
 	value.setProperty("saveTemporary",
8664
 	value.setProperty("saveTemporary",
8643
 	                  engine->newFunction(ZoomLog_saveTemporary));
8665
 	                  engine->newFunction(ZoomLog_saveTemporary));
8666
+	value.setProperty("setDisplayUnits", engine->newFunction(ZoomLog_setDisplayUnits));
8644
 }
8667
 }
8645
 
8668
 
8646
 @ The functions for saving data are simple wrappers around the corresponding
8669
 @ The functions for saving data are simple wrappers around the corresponding
8741
 	return QScriptValue(engine, self->lastTime(argument<int>(0, context)));
8764
 	return QScriptValue(engine, self->lastTime(argument<int>(0, context)));
8742
 }
8765
 }
8743
 
8766
 
8767
+@ There seems to be a bad interaction when enumerated value types as used as
8768
+the argument to slot methods called through QtScript. Script code that attempts
8769
+to make use of the enumeration appears to get the value without any type
8770
+information. When attempting to use that value as an argument the meta-object
8771
+system cannot find an appropriate match and the script just hangs silently.
8772
+The solution is to wrap such methods in the script bindings and explicitly cast
8773
+the argument value to the enumerated type. This looks stupid but it works.
8774
+
8775
+@<Functions for scripting@>=
8776
+QScriptValue ZoomLog_setDisplayUnits(QScriptContext *context, QScriptEngine *)
8777
+{
8778
+	ZoomLog *self = getself<@[ZoomLog *@]>(context);
8779
+	self->setDisplayUnits((Units::Unit)argument<int>(0, context));
8780
+	return QScriptValue();
8781
+}
8782
+
8744
 @* A model for roasting data.
8783
 @* A model for roasting data.
8745
 
8784
 
8746
 \noindent Qt provides a tool called the model view architecture. This provides a
8785
 \noindent Qt provides a tool called the model view architecture. This provides a

+ 9
- 0
src/units.w Datei anzeigen

147
 	}
147
 	}
148
 	return 0;
148
 	return 0;
149
 }
149
 }
150
+
151
+@ This class is exposed to the host environment. Note the lack of constructor.
152
+We do not wish to create any instances, just have access to the |Unit|
153
+enumeration.
154
+
155
+@<Set up the scripting engine@>=
156
+value = engine->newQMetaObject(&Units::staticMetaObject);
157
+engine->globalObject().setProperty("Units", value);
158
+

Laden…
Abbrechen
Speichern