|
@@ -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
|
|