LibrePCB Developers Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
attributetype.h
Go to the documentation of this file.
1 /*
2  * LibrePCB - Professional EDA for everyone!
3  * Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors.
4  * https://librepcb.org/
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef LIBREPCB_ATTRIBUTETYPE_H
21 #define LIBREPCB_ATTRIBUTETYPE_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
26 #include "../fileio/sexpression.h"
27 
28 #include <QtCore>
29 
30 /*******************************************************************************
31  * Namespace / Forward Declarations
32  ******************************************************************************/
33 namespace librepcb {
34 
35 class AttributeUnit;
36 
37 /*******************************************************************************
38  * Class AttributeType
39  ******************************************************************************/
40 
45  Q_DECLARE_TR_FUNCTIONS(AttributeType)
46 
47 public:
49  enum class Type_t {
50  String = 0,
51  Resistance,
52  Capacitance,
53  Inductance,
54  Voltage,
55  Current,
56  Power,
57  Frequency,
58  _COUNT
59  };
60 
61  // Constructors / Destructor
62  AttributeType(Type_t type, const QString& typeName,
63  const QString& typeNameTr) noexcept;
64  virtual ~AttributeType() noexcept;
65 
66  // Getters
67  Type_t getType() const noexcept { return mType; }
68  const QString& getName() const noexcept { return mTypeName; }
69  const QString& getNameTr() const noexcept { return mTypeNameTr; }
70  const QList<const AttributeUnit*>& getAvailableUnits() const noexcept {
71  return mAvailableUnits;
72  }
73  const AttributeUnit* getUnitFromString(const QString& unit) const;
74  const AttributeUnit* getDefaultUnit() const noexcept { return mDefaultUnit; }
75  bool isUnitAvailable(const AttributeUnit* unit) const noexcept;
76  const AttributeUnit* tryExtractUnitFromValue(QString& value) const noexcept;
77  virtual bool isValueValid(const QString& value) const noexcept = 0;
78  virtual QString valueFromTr(const QString& value) const noexcept = 0;
79  virtual QString printableValueTr(const QString& value,
80  const AttributeUnit* unit = nullptr) const
81  noexcept = 0;
82 
83  // Static Methods
84  static QList<const AttributeType*> getAllTypes() noexcept;
85  static const AttributeType& fromString(const QString& type);
86 
87 protected:
88  // make some methods inaccessible...
89  AttributeType() = delete;
90  AttributeType(const AttributeType& other) = delete;
91  AttributeType& operator=(const AttributeType& rhs) = delete;
92 
93  // General Attributes
95  QString mTypeName;
96  QString mTypeNameTr;
99 };
100 
101 /*******************************************************************************
102  * Non-Member Functions
103  ******************************************************************************/
104 
105 template <>
107  return SExpression::createToken(obj.getName());
108 }
109 
110 /*******************************************************************************
111  * End of File
112  ******************************************************************************/
113 
114 } // namespace librepcb
115 
116 #endif // LIBREPCB_ATTRIBUTETYPE_H
static const AttributeType & fromString(const QString &type)
Definition: attributetype.cpp:118
const QString & getNameTr() const noexcept
Definition: attributetype.h:69
const QString & getName() const noexcept
Definition: attributetype.h:68
const QList< const AttributeUnit * > & getAvailableUnits() const noexcept
Definition: attributetype.h:70
const AttributeUnit * getDefaultUnit() const noexcept
Definition: attributetype.h:74
SExpression serializeToSExpression(const HAlign &obj)
Definition: alignment.h:76
const AttributeUnit * getUnitFromString(const QString &unit) const
Definition: attributetype.cpp:64
static QList< const AttributeType * > getAllTypes() noexcept
Definition: attributetype.cpp:105
QList< const AttributeUnit * > mAvailableUnits
Definition: attributetype.h:97
const AttributeUnit * mDefaultUnit
Definition: attributetype.h:98
static SExpression createToken(const QString &token)
Definition: sexpression.cpp:280
The AttributeUnit class.
Definition: attributeunit.h:42
Type_t getType() const noexcept
Definition: attributetype.h:67
QString mTypeName
Definition: attributetype.h:95
Type_t mType
Definition: attributetype.h:94
virtual bool isValueValid(const QString &value) const noexcept=0
virtual ~AttributeType() noexcept
Definition: attributetype.cpp:54
QString mTypeNameTr
Definition: attributetype.h:96
virtual QString printableValueTr(const QString &value, const AttributeUnit *unit=nullptr) const noexcept=0
virtual QString valueFromTr(const QString &value) const noexcept=0
Type_t
Available Attribute Types.
Definition: attributetype.h:49
const AttributeUnit * tryExtractUnitFromValue(QString &value) const noexcept
Definition: attributetype.cpp:87
The AttributeType class.
Definition: attributetype.h:44
The SExpression class.
Definition: sexpression.h:57
bool isUnitAvailable(const AttributeUnit *unit) const noexcept
Definition: attributetype.cpp:79