LibrePCB Developers Documentation
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_CORE_ATTRIBUTETYPE_H
21#define LIBREPCB_CORE_ATTRIBUTETYPE_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
26#include <QtCore>
27
28/*******************************************************************************
29 * Namespace / Forward Declarations
30 ******************************************************************************/
31namespace librepcb {
32
33class AttributeUnit;
34
35/*******************************************************************************
36 * Class AttributeType
37 ******************************************************************************/
38
43 Q_DECLARE_TR_FUNCTIONS(AttributeType)
44
45public:
47 enum class Type_t {
48 String = 0,
49 Resistance,
50 Capacitance,
51 Inductance,
52 Voltage,
53 Current,
54 Power,
55 Frequency,
56 _COUNT
57 };
58
59 // Constructors / Destructor
60 AttributeType() = delete;
61 AttributeType(const AttributeType& other) = delete;
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(
80 const QString& value,
81 const AttributeUnit* unit = nullptr) const noexcept = 0;
82
83 // Static Methods
84 static QList<const AttributeType*> getAllTypes() noexcept;
85 static const AttributeType& fromString(const QString& type);
86
87 // Operator Overloadings
88 AttributeType& operator=(const AttributeType& rhs) = delete;
89
90protected:
91 // General Attributes
93 QString mTypeName;
94 QString mTypeNameTr;
97};
98
99/*******************************************************************************
100 * End of File
101 ******************************************************************************/
102
103} // namespace librepcb
104
105#endif
The AttributeType class.
Definition: attributetype.h:42
const QString & getNameTr() const noexcept
Definition: attributetype.h:69
QString mTypeName
Definition: attributetype.h:93
Type_t
Available Attribute Types.
Definition: attributetype.h:47
const QString & getName() const noexcept
Definition: attributetype.h:68
const AttributeUnit * mDefaultUnit
Definition: attributetype.h:96
virtual QString printableValueTr(const QString &value, const AttributeUnit *unit=nullptr) const noexcept=0
const AttributeUnit * tryExtractUnitFromValue(QString &value) const noexcept
Definition: attributetype.cpp:88
Type_t getType() const noexcept
Definition: attributetype.h:67
static QList< const AttributeType * > getAllTypes() noexcept
Definition: attributetype.cpp:106
Type_t mType
Definition: attributetype.h:92
static const AttributeType & fromString(const QString &type)
Definition: attributetype.cpp:119
AttributeType(const AttributeType &other)=delete
const QList< const AttributeUnit * > & getAvailableUnits() const noexcept
Definition: attributetype.h:70
const AttributeUnit * getUnitFromString(const QString &unit) const
Definition: attributetype.cpp:66
virtual bool isValueValid(const QString &value) const noexcept=0
QList< const AttributeUnit * > mAvailableUnits
Definition: attributetype.h:95
virtual QString valueFromTr(const QString &value) const noexcept=0
virtual ~AttributeType() noexcept
Definition: attributetype.cpp:56
QString mTypeNameTr
Definition: attributetype.h:94
const AttributeUnit * getDefaultUnit() const noexcept
Definition: attributetype.h:74
bool isUnitAvailable(const AttributeUnit *unit) const noexcept
Definition: attributetype.cpp:80
The AttributeUnit class.
Definition: attributeunit.h:40
Definition: occmodel.cpp:77