klog
frequency.h
1 #ifndef FREQUENCY_H
2 #define FREQUENCY_H
3 /***************************************************************************
4  frequency.h - description
5  -------------------
6  begin : Apr 2024
7  copyright : (C) 2024 by Jaime Robles
8  email : jaime@robles.es
9  ***************************************************************************/
10 
11 /*****************************************************************************
12  * This file is part of KLog. *
13  * *
14  * KLog is free software: you can redistribute it and/or modify *
15  * it under the terms of the GNU General Public License as published by *
16  * the Free Software Foundation, either version 3 of the License, or *
17  * (at your option) any later version. *
18  * *
19  * KLog is distributed in the hope that it will be useful, *
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
22  * GNU General Public License for more details. *
23  * *
24  * You should have received a copy of the GNU General Public License *
25  * along with KLog. If not, see <https://www.gnu.org/licenses/>. *
26  * *
27  *****************************************************************************/
28 /*
29  This class implements Frequency.
30 */
31 
32 #include <QObject>
33 
34 enum FreqUnits {Hz, KHz, MHz, GHz, THz};
35 
36 class Frequency: public QObject
37 {
38  Q_OBJECT
39  friend class tst_Frequency;
40 
41 public:
42  //Frequency() : freq(0.0), bandInMHz(""), tolerance(0.0) {};
43  Frequency();
44  //Frequency(const Frequency &f);
45  Frequency(const Frequency &f) : QObject(), freq(f.freq), bandInMHz(f.bandInMHz), tolerance(f.tolerance) {}
46  Frequency(const double _f, FreqUnits _u = MHz);
47  //Frequency(const QString &_parentName);
48  //Frequency(const QString &_parentName, const Frequency &_f);
49  ~Frequency();
50  void clear();
51  bool fromDouble(const double _f, FreqUnits _u = MHz);
52  bool fromQString(const QString &_f, FreqUnits _u = MHz);
53  //bool fromBand(const QString &_bandName);
54  double toDouble(FreqUnits _u = MHz) const; // Returns in MHz
55  QString toQString(FreqUnits _u = MHz) const; // Returns in MHz with decimals
56  void setTolerance(const double _t, FreqUnits _u = Hz); // Defines the tolerance
57  // qString band(); // Returns the band
58  //int bandId(); // Returns the bandId
59  bool isValid() const;
60 
61  Frequency &operator=(const Frequency &other); // Redefinition of =
62 
63  // Comparison: Always pass by const reference (const Frequency &)
64  bool operator==(const Frequency &other) const; // Redefinition of ==
65  bool operator!=(const Frequency &other) const; // Redefinition of !=
66  bool operator>(const Frequency &other) const; // Redefinition of >
67  bool operator<(const Frequency &other) const; // Redefinition of <
68  bool operator>=(const Frequency &other) const; // Redefinition of >=
69  bool operator<=(const Frequency &other) const; // Redefinition of <=
70 
71 private:
72  double normalize(const double _f, const FreqUnits _u = MHz) const;
73  double deNormalize(const double _f, const FreqUnits _u = MHz) const;
74  int getDecimals(const FreqUnits _u = MHz) const;
75  double freq = 0.0; // This must be in MHz
76  QString bandInMHz = QString(); //
77  double tolerance = 0.0; // This must be in Hz
78 };
79 
80 #endif // FREQUENCY_H
Definition: tst_frequency.cpp:34
Definition: frequency.h:36