浏览代码

Compatibility shim for replacing Measurement with QVariantMap.

Neal Wilson 11 年前
父节点
当前提交
aae24ad6a9
共有 2 个文件被更改,包括 125 次插入169 次删除
  1. 124
    0
      src/measurement.w
  2. 1
    169
      src/typica.w

+ 124
- 0
src/measurement.w 查看文件

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

+ 1
- 169
src/typica.w 查看文件

@@ -5757,175 +5757,7 @@ Measurement times are represented as instances of |QTime|.
5757 5757
 @<Header files to include@>=
5758 5758
 #include "units.h"
5759 5759
 
5760
-@ The declaration of |Measurement| is reasonably straightforward. Measurements
5761
-will often be passed around to a number of different objects through the signals
5762
-and slots mechanism of Qt. The simplest way to make this work is to provide a
5763
-copy constructor and an assignment operator.
5764
-
5765
-Starting with version 1.1.2 the |Measurement| class contains an indication of
5766
-the measurement unit and methods for converting a measurement from one unit to
5767
-another. The units are represented by the same constants as the |DAQ| class.
5768
-This can almost certainly be handled better.
5769
-
5770
-@<Class declarations@>=
5771
-class Measurement@/
5772
-{
5773
-	public:@;
5774
-		Measurement(double temperature = 0, QTime time = QTime(),@|
5775
-		            Units::Unit sc = Units::Fahrenheit);
5776
-		Measurement(double temperature);
5777
-		Measurement(const Measurement &x);
5778
-		Measurement& operator=(Measurement &x);
5779
-		~Measurement();
5780
-		double temperature() const;
5781
-		QTime time() const;
5782
-		void setTemperature(double temperature);
5783
-		void setTime(QTime time);
5784
-		void setUnit(Units::Unit scale);
5785
-		Units::Unit scale();
5786
-		Measurement toFahrenheit();
5787
-		Measurement toCelsius();
5788
-		Measurement toKelvin();
5789
-		Measurement toRankine();
5790
-	private:@/
5791
-		double theTemperature;
5792
-		QTime theTime;
5793
-		Units::Unit unit;
5794
-};
5795
-
5796
-@ There are two constructors that can create |Measurement| objects. The
5797
-constructor that takes both a temperature and a time is declared as a default
5798
-constructor because one is needed to pass objects through |QMetaType|. The
5799
-constructor that only takes a temperature uses the measured temperature and the
5800
-current time.
5801
-
5802
-@<Measurement implementation@>=
5803
-Measurement::Measurement(double temperature, QTime time,
5804
-                         Units::Unit sc) :@;
5805
-	@t\kern2em@>theTemperature(temperature), theTime(time), unit(sc)@;
5806
-{
5807
-	/* Nothing has to be done here. */
5808
-}@;
5809
-
5810
-Measurement::Measurement(double temperature) :@;
5811
-	@t\kern2em@>theTemperature(temperature), theTime(QTime::currentTime()),
5812
-	unit(Units::Fahrenheit)@;
5813
-{
5814
-	/* Nothing has to be done here. */
5815
-}@;
5816
-
5817
-@ Qt uses |QMetaType| in queued signals and slots connections such as those
5818
-between objects in different execution threads. To pass |Measurement| objects
5819
-through this mechanism we must register it with that class. This only needs to
5820
-be done once and can be done in the |main()| function during program
5821
-initialization.
5822
-
5823
-@<Register meta-types@>=
5824
-qRegisterMetaType<Measurement>("Measurement");@/
5825
-
5826
-@ To successfully register a class with |QMetaType| it must have a public
5827
-default constructor (already defined above), a public copy constructor, and a
5828
-public destructor.
5829
-
5830
-@<Measurement implementation@>=
5831
-Measurement::Measurement(const Measurement &x) :@;
5832
-	@t\kern2em@>theTemperature(x.temperature()), theTime(x.time()),
5833
-	unit(x.unit)
5834
-{
5835
-	/* Nothing has to be done here. */
5836
-}@;
5837
-
5838
-Measurement::~Measurement()
5839
-{
5840
-	/* Nothing has to be done here. */
5841
-}
5842
-
5843
-@ Once the assignment operator is implemented it is possible to get measurements
5844
-to all of the objects that need them.
5845
-
5846
-@<Measurement implementation@>=
5847
-Measurement&@,@, Measurement::operator=(Measurement &x)
5848
-{
5849
-	theTemperature = x.temperature();
5850
-	theTime = x.time();
5851
-	unit = x.unit;
5852
-	return *this;
5853
-}
5854
-
5855
-@ Four member functions are used to get and set the time and temperature data of
5856
-a measurement. A measurement might need to be modified to convert from one
5857
-temperature unit to another or to convert a measurement time from system time to
5858
-a time relative to the start of a batch.
5859
-
5860
-@<Measurement implementation@>=
5861
-double Measurement::temperature() const
5862
-{
5863
-	return theTemperature;
5864
-}
5865
-
5866
-QTime Measurement::time() const
5867
-{
5868
-	return theTime;
5869
-}
5870
-
5871
-void Measurement::setTemperature(double temperature)
5872
-{
5873
-	theTemperature = temperature;
5874
-}
5875
-
5876
-void Measurement::setTime(QTime time)
5877
-{
5878
-	theTime = time;
5879
-}
5880
-
5881
-@ This method changes the scale of the measurement. Note that this does not
5882
-alter the number holding the measurement. To convert a measurement from one
5883
-unit to another, use the appropriate |to[Fahrenheit||Celsius||Kelvin||Rankine]|
5884
-method.
5885
-
5886
-@<Measurement implementation@>=
5887
-void Measurement::setUnit(Units::Unit scale)
5888
-{
5889
-	unit = scale;
5890
-}
5891
-
5892
-Units::Unit Measurement::scale()
5893
-{
5894
-	return unit;
5895
-}
5896
-
5897
-@ Four methods create a new |Measurement| from the object the method is called
5898
-on representing the same measurement expressed in different units. The value
5899
-conversions are handled in the |Units| class.
5900
-
5901
-@<Measurement implementation@>=
5902
-Measurement Measurement::toFahrenheit()
5903
-{
5904
-	return Measurement(Units::convertTemperature(this->temperature(),
5905
-	                                             this->unit, Units::Fahrenheit),
5906
-	                   this->time(), Units::Fahrenheit);
5907
-}
5908
-
5909
-Measurement Measurement::toCelsius()
5910
-{
5911
-	return Measurement(Units::convertTemperature(this->temperature(),
5912
-	                                             this->unit, Units::Celsius),
5913
-	                   this->time(), Units::Celsius);
5914
-}
5915
-
5916
-Measurement Measurement::toKelvin()
5917
-{
5918
-	return Measurement(Units::convertTemperature(this->temperature(),
5919
-	                                             this->unit, Units::Kelvin),
5920
-	                   this->time(), Units::Kelvin);
5921
-}
5922
-
5923
-Measurement Measurement::toRankine()
5924
-{
5925
-	return Measurement(Units::convertTemperature(this->temperature(),
5926
-	                                             this->unit, Units::Rankine),
5927
-	                   this->time(), Units::Rankine);
5928
-}
5760
+@i measurement.w
5929 5761
 
5930 5762
 @** The Main Measurement Pipeline.
5931 5763
 

正在加载...
取消
保存