|
@@ -5749,7 +5749,14 @@ temperature and the time at which that measurement was taken.
|
5749
|
5749
|
|
5750
|
5750
|
Measurement times are represented as instances of |QTime|.
|
5751
|
5751
|
|
5752
|
|
-The declaration of |Measurement| is reasonably straightforward. Measurements
|
|
5752
|
+@i units.w
|
|
5753
|
+
|
|
5754
|
+@ We will require the |units.h| header.
|
|
5755
|
+
|
|
5756
|
+@<Header files to include@>=
|
|
5757
|
+#include "units.h"
|
|
5758
|
+
|
|
5759
|
+@ The declaration of |Measurement| is reasonably straightforward. Measurements
|
5753
|
5760
|
will often be passed around to a number of different objects through the signals
|
5754
|
5761
|
and slots mechanism of Qt. The simplest way to make this work is to provide a
|
5755
|
5762
|
copy constructor and an assignment operator.
|
|
@@ -5762,21 +5769,9 @@ This can almost certainly be handled better.
|
5762
|
5769
|
@<Class declarations@>=
|
5763
|
5770
|
class Measurement@/
|
5764
|
5771
|
{
|
5765
|
|
- public:@/
|
5766
|
|
- enum TemperatureUnits
|
5767
|
|
- {
|
5768
|
|
- Fahrenheit = 10144,
|
5769
|
|
- Celsius = 10143,
|
5770
|
|
- Kelvin = 10325,
|
5771
|
|
- Rankine = 10145
|
5772
|
|
- };
|
5773
|
|
- private:@/
|
5774
|
|
- double theTemperature;
|
5775
|
|
- QTime theTime;
|
5776
|
|
- TemperatureUnits unit;
|
5777
|
5772
|
public:@;
|
5778
|
5773
|
Measurement(double temperature = 0, QTime time = QTime(),@|
|
5779
|
|
- TemperatureUnits sc = Fahrenheit);
|
|
5774
|
+ Units::Unit sc = Units::Fahrenheit);
|
5780
|
5775
|
Measurement(double temperature);
|
5781
|
5776
|
Measurement(const Measurement &x);
|
5782
|
5777
|
Measurement& operator=(Measurement &x);
|
|
@@ -5785,12 +5780,16 @@ class Measurement@/
|
5785
|
5780
|
QTime time() const;
|
5786
|
5781
|
void setTemperature(double temperature);
|
5787
|
5782
|
void setTime(QTime time);
|
5788
|
|
- void setUnit(TemperatureUnits scale);
|
5789
|
|
- TemperatureUnits scale();
|
|
5783
|
+ void setUnit(Units::Unit scale);
|
|
5784
|
+ Units::Unit scale();
|
5790
|
5785
|
Measurement toFahrenheit();
|
5791
|
5786
|
Measurement toCelsius();
|
5792
|
5787
|
Measurement toKelvin();
|
5793
|
5788
|
Measurement toRankine();
|
|
5789
|
+ private:@/
|
|
5790
|
+ double theTemperature;
|
|
5791
|
+ QTime theTime;
|
|
5792
|
+ Units::Unit unit;
|
5794
|
5793
|
};
|
5795
|
5794
|
|
5796
|
5795
|
@ There are two constructors that can create |Measurement| objects. The
|
|
@@ -5801,7 +5800,7 @@ current time.
|
5801
|
5800
|
|
5802
|
5801
|
@<Measurement implementation@>=
|
5803
|
5802
|
Measurement::Measurement(double temperature, QTime time,
|
5804
|
|
- TemperatureUnits sc) :@;
|
|
5803
|
+ Units::Unit sc) :@;
|
5805
|
5804
|
@t\kern2em@>theTemperature(temperature), theTime(time), unit(sc)@;
|
5806
|
5805
|
{
|
5807
|
5806
|
/* Nothing has to be done here. */
|
|
@@ -5809,7 +5808,7 @@ Measurement::Measurement(double temperature, QTime time,
|
5809
|
5808
|
|
5810
|
5809
|
Measurement::Measurement(double temperature) :@;
|
5811
|
5810
|
@t\kern2em@>theTemperature(temperature), theTime(QTime::currentTime()),
|
5812
|
|
- unit(Fahrenheit)@;
|
|
5811
|
+ unit(Units::Fahrenheit)@;
|
5813
|
5812
|
{
|
5814
|
5813
|
/* Nothing has to be done here. */
|
5815
|
5814
|
}@;
|
|
@@ -5884,122 +5883,47 @@ unit to another, use the appropriate |to[Fahrenheit||Celsius||Kelvin||Rankine]|
|
5884
|
5883
|
method.
|
5885
|
5884
|
|
5886
|
5885
|
@<Measurement implementation@>=
|
5887
|
|
-void Measurement::setUnit(TemperatureUnits scale)
|
|
5886
|
+void Measurement::setUnit(Units::Unit scale)
|
5888
|
5887
|
{
|
5889
|
5888
|
unit = scale;
|
5890
|
5889
|
}
|
5891
|
5890
|
|
5892
|
|
-Measurement::TemperatureUnits Measurement::scale()
|
|
5891
|
+Units::Unit Measurement::scale()
|
5893
|
5892
|
{
|
5894
|
5893
|
return unit;
|
5895
|
5894
|
}
|
5896
|
5895
|
|
5897
|
5896
|
@ Four methods create a new |Measurement| from the object the method is called
|
5898
|
|
-on representing the same measurement expressed in different units. The
|
5899
|
|
-conversion formul\ae{} come from Wikipedia.\nfnote{%
|
5900
|
|
-\pdfURL{Temperature Conversion}{%
|
5901
|
|
-http://en.wikipedia.org/%
|
5902
|
|
-w/index.php?title=Temperature_conversion&oldid=226047163}}
|
5903
|
|
-
|
5904
|
|
-The |toFahrenheit()| method converts a measurement to Fahrenheit.
|
|
5897
|
+on representing the same measurement expressed in different units. The value
|
|
5898
|
+conversions are handled in the |Units| class.
|
5905
|
5899
|
|
5906
|
5900
|
@<Measurement implementation@>=
|
5907
|
5901
|
Measurement Measurement::toFahrenheit()
|
5908
|
5902
|
{
|
5909
|
|
- switch(unit)
|
5910
|
|
- {
|
5911
|
|
- case Celsius:
|
5912
|
|
- return Measurement(this->temperature() * 9 / 5 + 32, this->time(),
|
5913
|
|
- Fahrenheit);
|
5914
|
|
- break;
|
5915
|
|
- case Kelvin:
|
5916
|
|
- return Measurement(this->temperature() * 5 / 9 - 459.67,
|
5917
|
|
- this->time(), Fahrenheit);
|
5918
|
|
- break;
|
5919
|
|
- case Rankine:
|
5920
|
|
- return Measurement(this->temperature() - 459.67, this->time(),
|
5921
|
|
- Fahrenheit);
|
5922
|
|
- break;
|
5923
|
|
- default:
|
5924
|
|
- return Measurement(this->temperature(), this->time(), Fahrenheit);
|
5925
|
|
- break;
|
5926
|
|
- }
|
|
5903
|
+ return Measurement(Units::convertTemperature(this->temperature(),
|
|
5904
|
+ this->unit, Units::Fahrenheit),
|
|
5905
|
+ this->time(), Units::Fahrenheit);
|
5927
|
5906
|
}
|
5928
|
5907
|
|
5929
|
|
-@ Similarly, the following converts to Celsius.
|
5930
|
|
-
|
5931
|
|
-@<Measurement implementation@>=
|
5932
|
5908
|
Measurement Measurement::toCelsius()
|
5933
|
5909
|
{
|
5934
|
|
- switch(unit)
|
5935
|
|
- {
|
5936
|
|
- case Fahrenheit:
|
5937
|
|
- return Measurement((this->temperature() - 32) * 5 / 9, this->time(),
|
5938
|
|
- Celsius);
|
5939
|
|
- break;
|
5940
|
|
- case Kelvin:
|
5941
|
|
- return Measurement(this->temperature() - 273.15, this->time(),
|
5942
|
|
- Celsius);
|
5943
|
|
- break;
|
5944
|
|
- case Rankine:
|
5945
|
|
- return Measurement((this->temperature() - 491.67) * 5 / 9,
|
5946
|
|
- this->time(), Celsius);
|
5947
|
|
- break;
|
5948
|
|
- default:
|
5949
|
|
- return Measurement(this->temperature(), this->time(), Celsius);
|
5950
|
|
- break;
|
5951
|
|
- }
|
|
5910
|
+ return Measurement(Units::convertTemperature(this->temperature(),
|
|
5911
|
+ this->unit, Units::Celsius),
|
|
5912
|
+ this->time(), Units::Celsius);
|
5952
|
5913
|
}
|
5953
|
5914
|
|
5954
|
|
-@ For those who prefer absolute scales, a method is provided to convert to
|
5955
|
|
-Kelvin.
|
5956
|
|
-
|
5957
|
|
-@<Measurement implementation@>=
|
5958
|
5915
|
Measurement Measurement::toKelvin()
|
5959
|
5916
|
{
|
5960
|
|
- switch(unit)
|
5961
|
|
- {
|
5962
|
|
- case Fahrenheit:
|
5963
|
|
- return Measurement((this->temperature() + 459.67) * 5 / 9,
|
5964
|
|
- this->time(), Kelvin);
|
5965
|
|
- break;
|
5966
|
|
- case Celsius:
|
5967
|
|
- return Measurement(this->temperature() + 273.15, this->time(),
|
5968
|
|
- Kelvin);
|
5969
|
|
- break;
|
5970
|
|
- case Rankine:
|
5971
|
|
- return Measurement(this->temperature() * 5 / 9, this->time(),
|
5972
|
|
- Kelvin);
|
5973
|
|
- break;
|
5974
|
|
- default:
|
5975
|
|
- return Measurement(this->temperature(), this->time(), Kelvin);
|
5976
|
|
- break;
|
5977
|
|
- }
|
|
5917
|
+ return Measurement(Units::convertTemperature(this->temperature(),
|
|
5918
|
+ this->unit, Units::Kelvin),
|
|
5919
|
+ this->time(), Units::Kelvin);
|
5978
|
5920
|
}
|
5979
|
5921
|
|
5980
|
|
-@ Finally, conversion to Rankine is also allowed.
|
5981
|
|
-
|
5982
|
|
-@<Measurement implementation@>=
|
5983
|
5922
|
Measurement Measurement::toRankine()
|
5984
|
5923
|
{
|
5985
|
|
- switch(unit)
|
5986
|
|
- {
|
5987
|
|
- case Fahrenheit:
|
5988
|
|
- return Measurement(this->temperature() + 459.67, this->time(),
|
5989
|
|
- Rankine);
|
5990
|
|
- break;
|
5991
|
|
- case Celsius:
|
5992
|
|
- return Measurement((this->temperature() + 273.15) * 9 / 5,
|
5993
|
|
- this->time(), Rankine);
|
5994
|
|
- break;
|
5995
|
|
- case Kelvin:
|
5996
|
|
- return Measurement(this->temperature() * 9 / 5, this->time(),
|
5997
|
|
- Rankine);
|
5998
|
|
- break;
|
5999
|
|
- default:
|
6000
|
|
- return Measurement(this->temperature(), this->time(), Rankine);
|
6001
|
|
- break;
|
6002
|
|
- }
|
|
5924
|
+ return Measurement(Units::convertTemperature(this->temperature(),
|
|
5925
|
+ this->unit, Units::Rankine),
|
|
5926
|
+ this->time(), Units::Rankine);
|
6003
|
5927
|
}
|
6004
|
5928
|
|
6005
|
5929
|
@** The Main Measurement Pipeline.
|
|
@@ -6068,7 +5992,6 @@ class DAQImplementation;@/
|
6068
|
5992
|
class DAQ : public QObject@;@/
|
6069
|
5993
|
{@t\1@>@/
|
6070
|
5994
|
Q_OBJECT@/
|
6071
|
|
- Q_ENUMS(TemperatureUnits)@/
|
6072
|
5995
|
Q_ENUMS(ThermocoupleType)@;@/
|
6073
|
5996
|
DAQImplementation *imp;@/
|
6074
|
5997
|
@t\4@>private slots@t\kern-3pt@>:@/
|
|
@@ -6080,13 +6003,6 @@ class DAQ : public QObject@;@/
|
6080
|
6003
|
@[Q_INVOKABLE@,@, void@]@, setClockRate(double Hz);@t\2\2@>@/
|
6081
|
6004
|
@[Q_INVOKABLE@,@, void@]@, start();@t\2\2@>@/
|
6082
|
6005
|
@[Q_INVOKABLE@]@, void stop();
|
6083
|
|
- enum TemperatureUnits@/
|
6084
|
|
- {
|
6085
|
|
- @!Fahrenheit = 10144,
|
6086
|
|
- @!Celsius = 10143,
|
6087
|
|
- @!Kelvin = 10325,
|
6088
|
|
- @!Rankine = 10145
|
6089
|
|
- };
|
6090
|
6006
|
enum ThermocoupleType@/
|
6091
|
6007
|
{
|
6092
|
6008
|
@!TypeJ = 10072,
|
|
@@ -6152,7 +6068,7 @@ int error;
|
6152
|
6068
|
int channels;
|
6153
|
6069
|
bool ready;
|
6154
|
6070
|
QLibrary driver;
|
6155
|
|
-QVector<Measurement::TemperatureUnits> unitMap;
|
|
6071
|
+QVector<Units::Unit> unitMap;
|
6156
|
6072
|
|
6157
|
6073
|
@ Most of the interesting work associated with the |DAQ| class is handled in
|
6158
|
6074
|
the |measure()| method of |DAQImplementation|. This function will block until a
|
|
@@ -6375,7 +6291,7 @@ Channel* DAQ::newChannel(int units, int thermocouple)
|
6375
|
6291
|
{
|
6376
|
6292
|
Channel *retval = new Channel();
|
6377
|
6293
|
imp->channelMap[imp->channels] = retval;
|
6378
|
|
- imp->unitMap[imp->channels] = (Measurement::TemperatureUnits)units;
|
|
6294
|
+ imp->unitMap[imp->channels] = (Units::Unit)units;
|
6379
|
6295
|
imp->channels++;
|
6380
|
6296
|
if(imp->ready)
|
6381
|
6297
|
{
|
|
@@ -6567,11 +6483,18 @@ QScriptValue constructDAQ(QScriptContext *context, QScriptEngine *engine);
|
6567
|
6483
|
QScriptValue DAQ_newChannel(QScriptContext *context, QScriptEngine *engine);
|
6568
|
6484
|
void setDAQProperties(QScriptValue value, QScriptEngine *engine);
|
6569
|
6485
|
|
6570
|
|
-@ First we make these functions known to the scripting engine.
|
|
6486
|
+@ First we make these functions known to the scripting engine. We also add
|
|
6487
|
+the values from |Units::Unit| as this was widely used in configurations
|
|
6488
|
+before this enumeration was removed from the |DAQ| class. As these properties
|
|
6489
|
+must be available without an instance, the properties must be added here.
|
6571
|
6490
|
|
6572
|
6491
|
@<Set up the scripting engine@>=
|
6573
|
6492
|
constructor = engine->newFunction(constructDAQ);
|
6574
|
6493
|
value = engine->newQMetaObject(&DAQ::staticMetaObject, constructor);
|
|
6494
|
+value.setProperty("Fahrenheit", Units::Fahrenheit);
|
|
6495
|
+value.setProperty("Celsius", Units::Celsius);
|
|
6496
|
+value.setProperty("Kelvin", Units::Kelvin);
|
|
6497
|
+value.setProperty("Rankine", Units::Rankine);
|
6575
|
6498
|
engine->globalObject().setProperty("DAQ", value);
|
6576
|
6499
|
|
6577
|
6500
|
@ When creating a new |DAQ|, we make sure that it is owned by the script engine.
|
|
@@ -7223,23 +7146,14 @@ This is a specialization of |QLCDNumber|.
|
7223
|
7146
|
class TemperatureDisplay : public QLCDNumber@/
|
7224
|
7147
|
{@t\1@>@/
|
7225
|
7148
|
Q_OBJECT@;
|
7226
|
|
- Q_ENUMS(DisplayUnits)
|
7227
|
7149
|
int unit;
|
7228
|
7150
|
public:@/
|
7229
|
|
- enum DisplayUnits
|
7230
|
|
- {
|
7231
|
|
- Auto = -1,
|
7232
|
|
- Fahrenheit = 10144,
|
7233
|
|
- Celsius = 10143,
|
7234
|
|
- Kelvin = 10325,
|
7235
|
|
- Rankine = 10145
|
7236
|
|
- };
|
7237
|
7151
|
TemperatureDisplay(QWidget *parent = NULL);
|
7238
|
7152
|
~TemperatureDisplay();@/
|
7239
|
7153
|
@t\4@>public slots@t\kern-3pt@>:@/
|
7240
|
7154
|
void setValue(Measurement temperature);
|
7241
|
7155
|
void invalidate();
|
7242
|
|
- void setDisplayUnits(DisplayUnits scale);@t\2@>@/
|
|
7156
|
+ void setDisplayUnits(Units::Unit scale);@t\2@>@/
|
7243
|
7157
|
};
|
7244
|
7158
|
|
7245
|
7159
|
@ Displaying a temperature is a simple matter of taking the temperature
|
|
@@ -7259,47 +7173,47 @@ void TemperatureDisplay::setValue(Measurement temperature)
|
7259
|
7173
|
QString number;
|
7260
|
7174
|
switch(unit)
|
7261
|
7175
|
{
|
7262
|
|
- case Auto:
|
7263
|
|
- switch(temperature.scale())
|
7264
|
|
- {
|
7265
|
|
- case Fahrenheit:
|
7266
|
|
- display(QString("%1'F").
|
7267
|
|
- arg(number.setNum(temperature.temperature(), 'f', 2)));
|
7268
|
|
- break;
|
7269
|
|
- case Celsius:
|
7270
|
|
- display(QString("%1'C").
|
7271
|
|
- arg(number.setNum(temperature.temperature(), 'f', 2)));
|
7272
|
|
- break;
|
7273
|
|
- case Kelvin:
|
7274
|
|
- display(QString("%1").
|
7275
|
|
- arg(number.setNum(temperature.temperature(), 'f', 2)));
|
7276
|
|
- break;
|
7277
|
|
- case Rankine:
|
7278
|
|
- display(QString("%1'r").
|
7279
|
|
- arg(number.setNum(temperature.temperature(), 'f', 2)));
|
7280
|
|
- break;
|
7281
|
|
- }
|
7282
|
|
- break;
|
7283
|
|
- case Fahrenheit:
|
|
7176
|
+ case Units::Fahrenheit:
|
7284
|
7177
|
display(QString("%1'F").
|
7285
|
7178
|
arg(number.setNum(temperature.toFahrenheit().temperature(), 'f',
|
7286
|
7179
|
2)));
|
7287
|
7180
|
break;
|
7288
|
|
- case Celsius:
|
|
7181
|
+ case Units::Celsius:
|
7289
|
7182
|
display(QString("%1'C").
|
7290
|
7183
|
arg(number.setNum(temperature.toCelsius().temperature(), 'f',
|
7291
|
7184
|
2)));
|
7292
|
7185
|
break;
|
7293
|
|
- case Kelvin:
|
|
7186
|
+ case Units::Kelvin:
|
7294
|
7187
|
display(QString("%1").
|
7295
|
7188
|
arg(number.setNum(temperature.toKelvin().temperature(), 'f',
|
7296
|
7189
|
2)));
|
7297
|
7190
|
break;
|
7298
|
|
- case Rankine:
|
|
7191
|
+ case Units::Rankine:
|
7299
|
7192
|
display(QString("%1'r").
|
7300
|
7193
|
arg(number.setNum(temperature.toRankine().temperature(), 'f',
|
7301
|
7194
|
2)));
|
7302
|
7195
|
break;
|
|
7196
|
+ default:
|
|
7197
|
+ switch(temperature.scale())
|
|
7198
|
+ {
|
|
7199
|
+ case Units::Fahrenheit:
|
|
7200
|
+ display(QString("%1'F").
|
|
7201
|
+ arg(number.setNum(temperature.temperature(), 'f', 2)));
|
|
7202
|
+ break;
|
|
7203
|
+ case Units::Celsius:
|
|
7204
|
+ display(QString("%1'C").
|
|
7205
|
+ arg(number.setNum(temperature.temperature(), 'f', 2)));
|
|
7206
|
+ break;
|
|
7207
|
+ case Units::Kelvin:
|
|
7208
|
+ display(QString("%1").
|
|
7209
|
+ arg(number.setNum(temperature.temperature(), 'f', 2)));
|
|
7210
|
+ break;
|
|
7211
|
+ case Units::Rankine:
|
|
7212
|
+ display(QString("%1'r").
|
|
7213
|
+ arg(number.setNum(temperature.temperature(), 'f', 2)));
|
|
7214
|
+ break;
|
|
7215
|
+ }
|
|
7216
|
+ break;
|
7303
|
7217
|
}
|
7304
|
7218
|
}
|
7305
|
7219
|
|
|
@@ -7315,7 +7229,7 @@ the usual |QLCDNumber| methods.
|
7315
|
7229
|
|
7316
|
7230
|
@<TemperatureDisplay Implementation@>=
|
7317
|
7231
|
TemperatureDisplay::TemperatureDisplay(QWidget *parent) :
|
7318
|
|
- QLCDNumber(8, parent), unit(Auto)@/
|
|
7232
|
+ QLCDNumber(8, parent), unit(Units::Fahrenheit)@/
|
7319
|
7233
|
{
|
7320
|
7234
|
setSegmentStyle(Filled);
|
7321
|
7235
|
display("---.--'F");
|
|
@@ -7342,7 +7256,7 @@ the scale to a different supported scale and convert measurements to that scale
|
7342
|
7256
|
prior to display.
|
7343
|
7257
|
|
7344
|
7258
|
@<TemperatureDisplay Implementation@>=
|
7345
|
|
-void TemperatureDisplay::setDisplayUnits(DisplayUnits scale)
|
|
7259
|
+void TemperatureDisplay::setDisplayUnits(Units::Unit scale)
|
7346
|
7260
|
{
|
7347
|
7261
|
unit = scale;
|
7348
|
7262
|
}
|
|
@@ -7362,6 +7276,8 @@ object to the scripting engine.
|
7362
|
7276
|
QScriptValue constructTemperatureDisplay(QScriptContext *context,
|
7363
|
7277
|
QScriptEngine *engine);
|
7364
|
7278
|
void setTemperatureDisplayProperties(QScriptValue value, QScriptEngine *engine);
|
|
7279
|
+QScriptValue TemperatureDisplay_setDisplayUnits(QScriptContext *context,
|
|
7280
|
+ QScriptEngine *engine);
|
7365
|
7281
|
|
7366
|
7282
|
@ The scripting engine must be informed of this function.
|
7367
|
7283
|
|
|
@@ -7385,6 +7301,24 @@ QScriptValue constructTemperatureDisplay(QScriptContext *,
|
7385
|
7301
|
void setTemperatureDisplayProperties(QScriptValue value, QScriptEngine *engine)
|
7386
|
7302
|
{
|
7387
|
7303
|
setQLCDNumberProperties(value, engine);
|
|
7304
|
+ value.setProperty("setDisplayUnits",
|
|
7305
|
+ engine->newFunction(TemperatureDisplay_setDisplayUnits));
|
|
7306
|
+}
|
|
7307
|
+
|
|
7308
|
+@ There seems to be a bad interaction when enumerated value types as used as
|
|
7309
|
+the argument to slot methods called through QtScript. Script code that attempts
|
|
7310
|
+to make use of the enumeration appears to get the value without any type
|
|
7311
|
+information. When attempting to use that value as an argument the meta-object
|
|
7312
|
+system cannot find an appropriate match and the script just hangs silently.
|
|
7313
|
+The solution is to wrap such methods in the script bindings and explicitly cast
|
|
7314
|
+the argument value to the enumerated type. This looks stupid but it works.
|
|
7315
|
+
|
|
7316
|
+@<Functions for scripting@>=
|
|
7317
|
+QScriptValue TemperatureDisplay_setDisplayUnits(QScriptContext *context, QScriptEngine *)
|
|
7318
|
+{
|
|
7319
|
+ TemperatureDisplay *self = getself<@[TemperatureDisplay *@]>(context);
|
|
7320
|
+ self->setDisplayUnits((Units::Unit)argument<int>(0, context));
|
|
7321
|
+ return QScriptValue();
|
7388
|
7322
|
}
|
7389
|
7323
|
|
7390
|
7324
|
@* The MeasurementTimeOffset class.
|
|
@@ -8202,7 +8136,7 @@ class ZoomLog : public QTableView@/
|
8202
|
8136
|
bool saveXML(QIODevice *device);
|
8203
|
8137
|
bool saveCSV(QIODevice *device);
|
8204
|
8138
|
QString lastTime(int series);
|
8205
|
|
- @[Q_INVOKABLE@,@, int displayUnits()@];@t\2\2@>@/
|
|
8139
|
+ @[Q_INVOKABLE@,@, Units::Unit displayUnits()@];@t\2\2@>@/
|
8206
|
8140
|
@[public slots@]:@/
|
8207
|
8141
|
void setVisible(bool visibility);
|
8208
|
8142
|
void setHeaderData(int section, QString text);
|
|
@@ -8220,7 +8154,7 @@ class ZoomLog : public QTableView@/
|
8220
|
8154
|
void addOutputTemperatureColumn(int column);
|
8221
|
8155
|
void addOutputAnnotationColumn(int column);
|
8222
|
8156
|
void clearOutputColumns();
|
8223
|
|
- void setDisplayUnits(int scale);
|
|
8157
|
+ void setDisplayUnits(Units::Unit scale);
|
8224
|
8158
|
void addToCurrentColumnSet(int column);
|
8225
|
8159
|
void clearCurrentColumnSet();@/
|
8226
|
8160
|
protected:@/
|
|
@@ -8519,10 +8453,10 @@ users will never notice this.
|
8519
|
8453
|
@<ZoomLog Implementation@>=
|
8520
|
8454
|
bool ZoomLog::saveXML(QIODevice *device)
|
8521
|
8455
|
{
|
8522
|
|
- int prevUnits = model_ms->displayUnits();
|
8523
|
|
- if(prevUnits != 10144)
|
|
8456
|
+ Units::Unit prevUnits = model_ms->displayUnits();
|
|
8457
|
+ if(prevUnits != Units::Fahrenheit)
|
8524
|
8458
|
{
|
8525
|
|
- model_ms->setDisplayUnits(10144);
|
|
8459
|
+ model_ms->setDisplayUnits(Units::Fahrenheit);
|
8526
|
8460
|
}
|
8527
|
8461
|
XMLOutput writer(model_ms, device, 0);
|
8528
|
8462
|
int c;
|
|
@@ -8537,7 +8471,7 @@ bool ZoomLog::saveXML(QIODevice *device)
|
8537
|
8471
|
toString(), c);
|
8538
|
8472
|
}
|
8539
|
8473
|
bool retval = writer.output();
|
8540
|
|
- if(prevUnits != 10144)
|
|
8474
|
+ if(prevUnits != Units::Fahrenheit)
|
8541
|
8475
|
{
|
8542
|
8476
|
model_ms->setDisplayUnits(prevUnits);
|
8543
|
8477
|
}
|
|
@@ -8620,7 +8554,7 @@ so, we simply tell all of the models which unit to provide data in. It is also
|
8620
|
8554
|
possible to obtain the currently selected unit.
|
8621
|
8555
|
|
8622
|
8556
|
@<ZoomLog Implementation@>=
|
8623
|
|
-void ZoomLog::setDisplayUnits(int scale)
|
|
8557
|
+void ZoomLog::setDisplayUnits(Units::Unit scale)
|
8624
|
8558
|
{
|
8625
|
8559
|
model_ms->setDisplayUnits(scale);
|
8626
|
8560
|
model_1s->setDisplayUnits(scale);
|
|
@@ -8631,7 +8565,7 @@ void ZoomLog::setDisplayUnits(int scale)
|
8631
|
8565
|
model_1m->setDisplayUnits(scale);
|
8632
|
8566
|
}
|
8633
|
8567
|
|
8634
|
|
-int ZoomLog::displayUnits()
|
|
8568
|
+Units::Unit ZoomLog::displayUnits()
|
8635
|
8569
|
{
|
8636
|
8570
|
return model_ms->displayUnits();
|
8637
|
8571
|
}
|
|
@@ -8743,6 +8677,8 @@ QScriptValue ZoomLog_restoreState(QScriptContext *context,
|
8743
|
8677
|
QScriptValue ZoomLog_lastTime(QScriptContext *context, QScriptEngine *engine);
|
8744
|
8678
|
QScriptValue ZoomLog_saveTemporary(QScriptContext *context,
|
8745
|
8679
|
QScriptEngine *engnie);
|
|
8680
|
+QScriptValue ZoomLog_setDisplayUnits(QScriptContext *context,
|
|
8681
|
+ QScriptEngine *engine);
|
8746
|
8682
|
|
8747
|
8683
|
@ Of these, the global object only needs to know about the constructor.
|
8748
|
8684
|
|
|
@@ -8773,6 +8709,7 @@ void setZoomLogProperties(QScriptValue value, QScriptEngine *engine)
|
8773
|
8709
|
value.setProperty("lastTime", engine->newFunction(ZoomLog_lastTime));
|
8774
|
8710
|
value.setProperty("saveTemporary",
|
8775
|
8711
|
engine->newFunction(ZoomLog_saveTemporary));
|
|
8712
|
+ value.setProperty("setDisplayUnits", engine->newFunction(ZoomLog_setDisplayUnits));
|
8776
|
8713
|
}
|
8777
|
8714
|
|
8778
|
8715
|
@ The functions for saving data are simple wrappers around the corresponding
|
|
@@ -8873,6 +8810,22 @@ QScriptValue ZoomLog_lastTime(QScriptContext *context, QScriptEngine *engine)
|
8873
|
8810
|
return QScriptValue(engine, self->lastTime(argument<int>(0, context)));
|
8874
|
8811
|
}
|
8875
|
8812
|
|
|
8813
|
+@ There seems to be a bad interaction when enumerated value types as used as
|
|
8814
|
+the argument to slot methods called through QtScript. Script code that attempts
|
|
8815
|
+to make use of the enumeration appears to get the value without any type
|
|
8816
|
+information. When attempting to use that value as an argument the meta-object
|
|
8817
|
+system cannot find an appropriate match and the script just hangs silently.
|
|
8818
|
+The solution is to wrap such methods in the script bindings and explicitly cast
|
|
8819
|
+the argument value to the enumerated type. This looks stupid but it works.
|
|
8820
|
+
|
|
8821
|
+@<Functions for scripting@>=
|
|
8822
|
+QScriptValue ZoomLog_setDisplayUnits(QScriptContext *context, QScriptEngine *)
|
|
8823
|
+{
|
|
8824
|
+ ZoomLog *self = getself<@[ZoomLog *@]>(context);
|
|
8825
|
+ self->setDisplayUnits((Units::Unit)argument<int>(0, context));
|
|
8826
|
+ return QScriptValue();
|
|
8827
|
+}
|
|
8828
|
+
|
8876
|
8829
|
@* A model for roasting data.
|
8877
|
8830
|
|
8878
|
8831
|
\noindent Qt provides a tool called the model view architecture. This provides a
|
|
@@ -8886,22 +8839,13 @@ class MeasurementList;@/
|
8886
|
8839
|
class MeasurementModel : public QAbstractItemModel@/
|
8887
|
8840
|
{@t\1@>@/
|
8888
|
8841
|
Q_OBJECT@;
|
8889
|
|
- Q_ENUMS(DisplayUnits);
|
8890
|
|
- int unit;
|
|
8842
|
+ Units::Unit unit;
|
8891
|
8843
|
QList<MeasurementList *> *entries;
|
8892
|
8844
|
QStringList *hData;
|
8893
|
8845
|
int colcount;
|
8894
|
8846
|
QHash<int, int> *lastTemperature;
|
8895
|
8847
|
QList<MeasurementList *>::iterator@, lastInsertion;
|
8896
|
8848
|
public:@/
|
8897
|
|
- enum DisplayUnits
|
8898
|
|
- {
|
8899
|
|
- Auto = -1,
|
8900
|
|
- Fahrenheit = 10144,
|
8901
|
|
- Celsius = 10143,
|
8902
|
|
- Kelvin = 10325,
|
8903
|
|
- Rankine = 10145
|
8904
|
|
- };
|
8905
|
8849
|
MeasurementModel(QObject *parent = NULL);
|
8906
|
8850
|
~MeasurementModel();
|
8907
|
8851
|
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
|
@@ -8917,13 +8861,13 @@ class MeasurementModel : public QAbstractItemModel@/
|
8917
|
8861
|
QModelIndex index(int row, int column,
|
8918
|
8862
|
const QModelIndex &parent = QModelIndex()) const;
|
8919
|
8863
|
QModelIndex parent(const QModelIndex &index) const;
|
8920
|
|
- int displayUnits();@/
|
|
8864
|
+ Units::Unit displayUnits();@/
|
8921
|
8865
|
@t\4@>public slots@t\kern-3pt@>:@/
|
8922
|
8866
|
void newMeasurement(Measurement measure, int tempcolumn);
|
8923
|
8867
|
void newAnnotation(QString annotation, int tempcolumn,
|
8924
|
8868
|
int annotationColumn);
|
8925
|
8869
|
void clear();
|
8926
|
|
- void setDisplayUnits(int scale);
|
|
8870
|
+ void setDisplayUnits(Units::Unit scale);
|
8927
|
8871
|
signals:@/
|
8928
|
8872
|
void rowChanged(int);@t\2@>@/
|
8929
|
8873
|
}@t\kern-3pt@>;
|
|
@@ -9332,7 +9276,7 @@ constructor.
|
9332
|
9276
|
|
9333
|
9277
|
@<MeasurementModel Implementation@>=
|
9334
|
9278
|
MeasurementModel::MeasurementModel(QObject *parent) : QAbstractItemModel(parent),
|
9335
|
|
- unit(Fahrenheit), hData(new QStringList),
|
|
9279
|
+ unit(Units::Fahrenheit), hData(new QStringList),
|
9336
|
9280
|
lastTemperature(new QHash<int, int>)@/
|
9337
|
9281
|
{
|
9338
|
9282
|
colcount = 1;
|
|
@@ -9423,14 +9367,14 @@ performed before sending that information to the view. Another method is
|
9423
|
9367
|
available to request a number identifyin the currently displayed units.
|
9424
|
9368
|
|
9425
|
9369
|
@<MeasurementModel Implementation@>=
|
9426
|
|
-void MeasurementModel::setDisplayUnits(int scale)
|
|
9370
|
+void MeasurementModel::setDisplayUnits(Units::Unit scale)
|
9427
|
9371
|
{
|
9428
|
9372
|
beginResetModel();
|
9429
|
9373
|
unit = scale;
|
9430
|
9374
|
endResetModel();
|
9431
|
9375
|
}
|
9432
|
9376
|
|
9433
|
|
-int MeasurementModel::displayUnits()
|
|
9377
|
+Units::Unit MeasurementModel::displayUnits()
|
9434
|
9378
|
{
|
9435
|
9379
|
return unit;
|
9436
|
9380
|
}
|
|
@@ -9475,23 +9419,23 @@ QVariant MeasurementModel::data(const QModelIndex &index, int role) const@/
|
9475
|
9419
|
}
|
9476
|
9420
|
switch(unit)
|
9477
|
9421
|
{
|
9478
|
|
- case Auto:
|
9479
|
|
- case Fahrenheit:
|
|
9422
|
+ case Units::Fahrenheit:
|
9480
|
9423
|
return QVariant(row->at(index.column()).toString());
|
9481
|
9424
|
break;
|
9482
|
|
- case Celsius:
|
|
9425
|
+ case Units::Celsius:
|
9483
|
9426
|
return QVariant((row->at(index.column()).toDouble() -
|
9484
|
9427
|
32) * 5 / 9);
|
9485
|
9428
|
break;
|
9486
|
|
- case Kelvin:
|
|
9429
|
+ case Units::Kelvin:
|
9487
|
9430
|
return QVariant((row->at(index.column()).toDouble() +
|
9488
|
9431
|
459.67) * 5 / 9);
|
9489
|
9432
|
break;
|
9490
|
|
- case Rankine:
|
|
9433
|
+ case Units::Rankine:
|
9491
|
9434
|
return QVariant(row->at(index.column()).toDouble() +
|
9492
|
9435
|
459.67);
|
9493
|
9436
|
break;
|
9494
|
9437
|
default:
|
|
9438
|
+ return QVariant(row->at(index.column()).toString());
|
9495
|
9439
|
break;
|
9496
|
9440
|
}
|
9497
|
9441
|
}
|
|
@@ -17369,8 +17313,8 @@ if(!unitIsF)
|
17369
|
17313
|
pvOut = pvOut * 9 / 5 + 32;
|
17370
|
17314
|
svOut = svOut * 9 / 5 + 32;
|
17371
|
17315
|
}
|
17372
|
|
-Measurement pvm(pvOut, time, Measurement::Fahrenheit);
|
17373
|
|
-Measurement svm(svOut, time, Measurement::Fahrenheit);
|
|
17316
|
+Measurement pvm(pvOut, time, Units::Fahrenheit);
|
|
17317
|
+Measurement svm(svOut, time, Units::Fahrenheit);
|
17374
|
17318
|
channels.at(0)->input(pvm);
|
17375
|
17319
|
channels.at(1)->input(svm);
|
17376
|
17320
|
|
|
@@ -17394,15 +17338,15 @@ if(!unitIsF)
|
17394
|
17338
|
}
|
17395
|
17339
|
if(!svenabled)
|
17396
|
17340
|
{
|
17397
|
|
- Measurement vm(valueOut, time, Measurement::Fahrenheit);
|
|
17341
|
+ Measurement vm(valueOut, time, Units::Fahrenheit);
|
17398
|
17342
|
channels.at(0)->input(vm);
|
17399
|
17343
|
}
|
17400
|
17344
|
else
|
17401
|
17345
|
{
|
17402
|
17346
|
if(readingsv)
|
17403
|
17347
|
{
|
17404
|
|
- Measurement pvm(savedpv, time, Measurement::Fahrenheit);
|
17405
|
|
- Measurement svm(valueOut, time, Measurement::Fahrenheit);
|
|
17348
|
+ Measurement pvm(savedpv, time, Units::Fahrenheit);
|
|
17349
|
+ Measurement svm(valueOut, time, Units::Fahrenheit);
|
17406
|
17350
|
channels.at(0)->input(pvm);
|
17407
|
17351
|
channels.at(1)->input(svm);
|
17408
|
17352
|
readingsv = false;
|