Переглянути джерело

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

Neal Wilson 11 роки тому
джерело
коміт
cd7b30aca2

+ 2
- 2
config/Windows/offline.xml Переглянути файл

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

+ 4
- 4
config/Windows/productionroaster.xml Переглянути файл

@@ -573,18 +573,18 @@
573 573
         showC.triggered.connect(function() {
574 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 579
             graph.showC();
580 580
         });
581 581
         var showF = findChildObject(this, 'showF');
582 582
         showF.triggered.connect(function() {
583 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 588
             graph.showF();
589 589
         });
590 590
 		var clear = findChildObject(this, 'clear');

+ 2
- 2
config/Windows/profilehistory.xml Переглянути файл

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

+ 39
- 0
src/typica.w Переглянути файл

@@ -7230,6 +7230,8 @@ object to the scripting engine.
7230 7230
 QScriptValue constructTemperatureDisplay(QScriptContext *context,
7231 7231
                                          QScriptEngine *engine);
7232 7232
 void setTemperatureDisplayProperties(QScriptValue value, QScriptEngine *engine);
7233
+QScriptValue TemperatureDisplay_setDisplayUnits(QScriptContext *context,
7234
+                                                QScriptEngine *engine);
7233 7235
 
7234 7236
 @ The scripting engine must be informed of this function.
7235 7237
 
@@ -7253,6 +7255,24 @@ QScriptValue constructTemperatureDisplay(QScriptContext *,
7253 7255
 void setTemperatureDisplayProperties(QScriptValue value, QScriptEngine *engine)
7254 7256
 {
7255 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 7278
 @* The MeasurementTimeOffset class.
@@ -8611,6 +8631,8 @@ QScriptValue ZoomLog_restoreState(QScriptContext *context,
8611 8631
 QScriptValue ZoomLog_lastTime(QScriptContext *context, QScriptEngine *engine);
8612 8632
 QScriptValue ZoomLog_saveTemporary(QScriptContext *context,
8613 8633
                                    QScriptEngine *engnie);
8634
+QScriptValue ZoomLog_setDisplayUnits(QScriptContext *context,
8635
+                                     QScriptEngine *engine);
8614 8636
 
8615 8637
 @ Of these, the global object only needs to know about the constructor.
8616 8638
 
@@ -8641,6 +8663,7 @@ void setZoomLogProperties(QScriptValue value, QScriptEngine *engine)
8641 8663
 	value.setProperty("lastTime", engine->newFunction(ZoomLog_lastTime));
8642 8664
 	value.setProperty("saveTemporary",
8643 8665
 	                  engine->newFunction(ZoomLog_saveTemporary));
8666
+	value.setProperty("setDisplayUnits", engine->newFunction(ZoomLog_setDisplayUnits));
8644 8667
 }
8645 8668
 
8646 8669
 @ The functions for saving data are simple wrappers around the corresponding
@@ -8741,6 +8764,22 @@ QScriptValue ZoomLog_lastTime(QScriptContext *context, QScriptEngine *engine)
8741 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 8783
 @* A model for roasting data.
8745 8784
 
8746 8785
 \noindent Qt provides a tool called the model view architecture. This provides a

+ 9
- 0
src/units.w Переглянути файл

@@ -147,3 +147,12 @@ double Units::convertTemperature(double value, Unit fromUnit, Unit toUnit)
147 147
 	}
148 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
+

Завантаження…
Відмінити
Зберегти