Typica is a free program for professional coffee roasters. https://typica.us
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

measurement.w 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. @** Measurement representation.
  2. \noindent Most of the information in a roast log will be measurements of
  3. various sorts. These could be temperature measurements, control settings,
  4. data derived from other data series, and so on. There are three key elements to
  5. a measurement: the value of the measurement, the unit that the measurement was
  6. taken in, and the time the measurement was collected.
  7. Starting in Typica 1.6 the |Measurement| class implementation was changed so
  8. that every |Measurement| is a |QVariantMap|. Additional methods are provided on
  9. top of this map so that this change is transparent to code that has already
  10. been written against the old class, but over time these methods will be
  11. depreciated and code can work directly with the |QVariantMap| interface to
  12. allow |Measurement| objects to carry much more information.
  13. As |QVariantMap| is implicitly shared and |Measurement| adds no new data
  14. members we no longer require copy and assignment operators.
  15. @<Class declarations@>=
  16. class Measurement : public QVariantMap
  17. {
  18. public:
  19. Measurement(double temperature = 0, QTime time = QTime(),
  20. Units::Unit sc = Units::Fahrenheit);
  21. Measurement(double temperature);
  22. double temperature() const;
  23. QTime time() const;
  24. void setTemperature(double temperature);
  25. void setTime(QTime time);
  26. void setUnit(Units::Unit scale);
  27. Units::Unit scale() const;
  28. Measurement toFahrenheit();
  29. Measurement toCelsius();
  30. Measurement toKelvin();
  31. Measurement toRankine();
  32. };
  33. @ Time, measured value, and unit are stored at well known keys.
  34. @<Measurement implementation@>=
  35. Measurement::Measurement(double temperature, QTime time, Units::Unit sc)
  36. {
  37. insert("measurement", temperature);
  38. insert("time", time);
  39. insert("unit", sc);
  40. }
  41. Measurement::Measurement(double temperature)
  42. {
  43. insert("measurement", temperature);
  44. insert("time", QTime::currentTime());
  45. insert("unit", Units::Fahrenheit);
  46. }
  47. void Measurement::setTemperature(double temperature)
  48. {
  49. insert("measurement", temperature);
  50. }
  51. void Measurement::setTime(QTime time)
  52. {
  53. insert("time", time);
  54. }
  55. void Measurement::setUnit(Units::Unit scale)
  56. {
  57. insert("unit", scale);
  58. }
  59. double Measurement::temperature() const
  60. {
  61. return value("measurement").toDouble();
  62. }
  63. QTime Measurement::time() const
  64. {
  65. return value("time").toTime();
  66. }
  67. Units::Unit Measurement::scale() const
  68. {
  69. return (Units::Unit)(value("unit").toInt());
  70. }
  71. @ Unit conversion methods will likely be the first things to be depreciated as
  72. the functionality is fully available from the |Units| class.
  73. @<Measurement implementation@>=
  74. Measurement Measurement::toFahrenheit()
  75. {
  76. return Measurement(Units::convertTemperature(this->temperature(),
  77. this->scale(), Units::Fahrenheit),
  78. this->time(), Units::Fahrenheit);
  79. }
  80. Measurement Measurement::toCelsius()
  81. {
  82. return Measurement(Units::convertTemperature(this->temperature(),
  83. this->scale(), Units::Celsius),
  84. this->time(), Units::Celsius);
  85. }
  86. Measurement Measurement::toKelvin()
  87. {
  88. return Measurement(Units::convertTemperature(this->temperature(),
  89. this->scale(), Units::Kelvin),
  90. this->time(), Units::Kelvin);
  91. }
  92. Measurement Measurement::toRankine()
  93. {
  94. return Measurement(Units::convertTemperature(this->temperature(),
  95. this->scale(), Units::Rankine),
  96. this->time(), Units::Rankine);
  97. }
  98. @ In the future we will be able to drop the |Measurement| class entirely and
  99. just pass around |QVariantMap| but until then we need to be able to pass these
  100. objects through the signals and slots mechanism. This requires that we have a
  101. public default constructor (already defined above), a public copy constructor,
  102. and a public destructor. These latter two are default generated.
  103. @<Register meta-types@>=
  104. qRegisterMetaType<Measurement>("Measurement");