LibrePCB Developers Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
attribute.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_ATTRIBUTE_H
21 #define LIBREPCB_ATTRIBUTE_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
26 #include "../fileio/cmd/cmdlistelementinsert.h"
27 #include "../fileio/cmd/cmdlistelementremove.h"
28 #include "../fileio/cmd/cmdlistelementsswap.h"
29 #include "../fileio/serializableobjectlist.h"
30 #include "attributekey.h"
31 
32 #include <QtCore>
33 
34 /*******************************************************************************
35  * Namespace / Forward Declarations
36  ******************************************************************************/
37 namespace librepcb {
38 
39 class AttributeType;
40 class AttributeUnit;
41 
42 /*******************************************************************************
43  * Class Attribute
44  ******************************************************************************/
45 
49 class Attribute final : public SerializableObject {
50  Q_DECLARE_TR_FUNCTIONS(Attribute)
51 
52 public:
53  // Signals
54  enum class Event {
55  KeyChanged,
57  };
60 
61  // Constructors / Destructor
62  Attribute() = delete;
63  Attribute(const Attribute& other) noexcept;
64  explicit Attribute(const SExpression& node);
65  Attribute(const AttributeKey& key, const AttributeType& type,
66  const QString& value, const AttributeUnit* unit);
67  ~Attribute() noexcept;
68 
69  // Getters
70  const AttributeKey& getKey() const noexcept { return mKey; }
71  const QString& getName() const noexcept {
72  return *mKey;
73  } // required for SerializableObjectList
74  const AttributeType& getType() const noexcept { return *mType; }
75  const AttributeUnit* getUnit() const noexcept { return mUnit; }
76  const QString& getValue() const noexcept { return mValue; }
77  QString getValueTr(bool showUnit) const noexcept;
78 
79  // Setters
80  bool setKey(const AttributeKey& key) noexcept;
81  bool setTypeValueUnit(const AttributeType& type, const QString& value,
82  const AttributeUnit* unit);
83 
84  // General Methods
85 
87  void serialize(SExpression& root) const override;
88 
89  // Operator Overloadings
90  bool operator==(const Attribute& rhs) const noexcept;
91  bool operator!=(const Attribute& rhs) const noexcept {
92  return !(*this == rhs);
93  }
94  Attribute& operator=(const Attribute& rhs) = delete;
95 
96 private: // Methods
97  bool checkAttributesValidity() const noexcept;
98 
99 private: // Data
102  QString mValue;
104 };
105 
106 /*******************************************************************************
107  * Class AttributeList
108  ******************************************************************************/
109 
111  static constexpr const char* tagname = "attribute";
112 };
113 using AttributeList =
116 using CmdAttributeInsert =
119 using CmdAttributeRemove =
122 using CmdAttributesSwap =
124 
125 /*******************************************************************************
126  * End of File
127  ******************************************************************************/
128 
129 } // namespace librepcb
130 
131 #endif // LIBREPCB_ATTRIBUTE_H
const AttributeType * mType
Definition: attribute.h:101
const AttributeUnit * getUnit() const noexcept
Definition: attribute.h:75
const AttributeType & getType() const noexcept
Definition: attribute.h:74
Attribute & operator=(const Attribute &rhs)=delete
The CmdListElementRemove class.
Definition: cmdlistelementremove.h:44
const QString & getValue() const noexcept
Definition: attribute.h:76
QString mValue
Definition: attribute.h:102
bool setKey(const AttributeKey &key) noexcept
Definition: attribute.cpp:77
type_safe::constrained_type< QString, AttributeKeyConstraint, AttributeKeyVerifier > AttributeKey
Definition: attributekey.h:83
Event
Definition: attribute.h:54
Definition: attribute.h:110
QString getValueTr(bool showUnit) const noexcept
Definition: attribute.cpp:69
bool operator!=(const Attribute &rhs) const noexcept
Definition: attribute.h:91
The SerializableObject class is the base class for all classes which need to be serializable/deserial...
Definition: serializableobject.h:43
The CmdListElementsSwap class.
Definition: cmdlistelementsswap.h:44
const AttributeKey & getKey() const noexcept
Definition: attribute.h:70
The AttributeUnit class.
Definition: attributeunit.h:42
~Attribute() noexcept
Definition: attribute.cpp:62
bool setTypeValueUnit(const AttributeType &type, const QString &value, const AttributeUnit *unit)
Definition: attribute.cpp:87
void serialize(SExpression &root) const override
Serialize the object into an existing S-Expression node.
Definition: attribute.cpp:112
const QString & getName() const noexcept
Definition: attribute.h:71
const AttributeUnit * mUnit
Definition: attribute.h:103
The Attribute class.
Definition: attribute.h:49
AttributeKey mKey
Definition: attribute.h:100
The Signal class is used to emit signals on non-QObject derived classes.
Definition: signalslot.h:65
The CmdListElementInsert class.
Definition: cmdlistelementinsert.h:44
Slot< Attribute, Event > OnEditedSlot
Definition: attribute.h:59
The AttributeType class.
Definition: attributetype.h:44
The Slot class is used to receive signals from non-QObject derived classes.
Definition: signalslot.h:36
The SExpression class.
Definition: sexpression.h:57
bool operator==(const Attribute &rhs) const noexcept
Definition: attribute.cpp:128
bool checkAttributesValidity() const noexcept
Definition: attribute.cpp:140
Signal< Attribute, Event > onEdited
Definition: attribute.h:58