LibrePCB Developers Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
text.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_TEXT_H
21 #define LIBREPCB_TEXT_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
26 #include "../alignment.h"
27 #include "../fileio/cmd/cmdlistelementinsert.h"
28 #include "../fileio/cmd/cmdlistelementremove.h"
29 #include "../fileio/cmd/cmdlistelementsswap.h"
30 #include "../fileio/serializableobjectlist.h"
31 #include "../graphics/graphicslayername.h"
32 #include "../units/all_length_units.h"
33 
34 #include <QtCore>
35 
36 /*******************************************************************************
37  * Namespace / Forward Declarations
38  ******************************************************************************/
39 namespace librepcb {
40 
41 /*******************************************************************************
42  * Interface IF_TextObserver
43  ******************************************************************************/
44 
52 public:
53  virtual void textLayerNameChanged(
54  const GraphicsLayerName& newLayerName) noexcept = 0;
55  virtual void textTextChanged(const QString& newText) noexcept = 0;
56  virtual void textPositionChanged(const Point& newPos) noexcept = 0;
57  virtual void textRotationChanged(const Angle& newRot) noexcept = 0;
58  virtual void textHeightChanged(const PositiveLength& newHeight) noexcept = 0;
59  virtual void textAlignChanged(const Alignment& newAlign) noexcept = 0;
60 
61 protected:
62  IF_TextObserver() noexcept {}
63  explicit IF_TextObserver(const IF_TextObserver& other) = delete;
64  virtual ~IF_TextObserver() noexcept {}
65  IF_TextObserver& operator=(const IF_TextObserver& rhs) = delete;
66 };
67 
68 /*******************************************************************************
69  * Class Text
70  ******************************************************************************/
71 
75 class Text final : public SerializableObject {
76  Q_DECLARE_TR_FUNCTIONS(Text)
77 
78 public:
79  // Constructors / Destructor
80  Text() = delete;
81  Text(const Text& other) noexcept;
82  Text(const Uuid& uuid, const Text& other) noexcept;
83  Text(const Uuid& uuid, const GraphicsLayerName& layerName,
84  const QString& text, const Point& pos, const Angle& rotation,
85  const PositiveLength& height, const Alignment& align) noexcept;
86  explicit Text(const SExpression& node);
87  ~Text() noexcept;
88 
89  // Getters
90  const Uuid& getUuid() const noexcept { return mUuid; }
91  const GraphicsLayerName& getLayerName() const noexcept { return mLayerName; }
92  const Point& getPosition() const noexcept { return mPosition; }
93  const Angle& getRotation() const noexcept { return mRotation; }
94  const PositiveLength& getHeight() const noexcept { return mHeight; }
95  const Alignment& getAlign() const noexcept { return mAlign; }
96  const QString& getText() const noexcept { return mText; }
97 
98  // Setters
99  void setLayerName(const GraphicsLayerName& name) noexcept;
100  void setText(const QString& text) noexcept;
101  void setPosition(const Point& pos) noexcept;
102  void setRotation(const Angle& rotation) noexcept;
103  void setHeight(const PositiveLength& height) noexcept;
104  void setAlign(const Alignment& align) noexcept;
105 
106  // General Methods
107  void registerObserver(IF_TextObserver& object) const noexcept;
108  void unregisterObserver(IF_TextObserver& object) const noexcept;
109 
111  void serialize(SExpression& root) const override;
112 
113  // Operator Overloadings
114  bool operator==(const Text& rhs) const noexcept;
115  bool operator!=(const Text& rhs) const noexcept { return !(*this == rhs); }
116  Text& operator=(const Text& rhs) noexcept;
117 
118 private: // Data
121  QString mText;
126 
127  // Misc
128  mutable QSet<IF_TextObserver*>
130 };
131 
132 /*******************************************************************************
133  * Class TextList
134  ******************************************************************************/
135 
137  static constexpr const char* tagname = "text";
138 };
143 
144 /*******************************************************************************
145  * End of File
146  ******************************************************************************/
147 
148 } // namespace librepcb
149 
150 #endif // LIBREPCB_TEXT_H
virtual ~IF_TextObserver() noexcept
Definition: text.h:64
bool operator==(const Text &rhs) const noexcept
Definition: text.cpp:178
Alignment mAlign
Definition: text.h:125
Uuid mUuid
Definition: text.h:119
void serialize(SExpression &root) const override
Serialize the object into an existing S-Expression node.
Definition: text.cpp:164
The CmdListElementRemove class.
Definition: cmdlistelementremove.h:44
virtual void textPositionChanged(const Point &newPos) noexcept=0
IF_TextObserver() noexcept
Definition: text.h:62
The Alignment class.
Definition: alignment.h:193
IF_TextObserver & operator=(const IF_TextObserver &rhs)=delete
PositiveLength mHeight
Definition: text.h:124
virtual void textHeightChanged(const PositiveLength &newHeight) noexcept=0
virtual void textLayerNameChanged(const GraphicsLayerName &newLayerName) noexcept=0
type_safe::constrained_type< QString, GraphicsLayerNameConstraint, GraphicsLayerNameVerifier > GraphicsLayerName
Definition: graphicslayername.h:78
const PositiveLength & getHeight() const noexcept
Definition: text.h:94
void setHeight(const PositiveLength &height) noexcept
Definition: text.cpp:136
~Text() noexcept
Definition: text.cpp:97
void setPosition(const Point &pos) noexcept
Definition: text.cpp:120
void setAlign(const Alignment &align) noexcept
Definition: text.cpp:144
The Angle class is used to represent an angle (for example 12.75 degrees)
Definition: angle.h:81
GraphicsLayerName mLayerName
Definition: text.h:120
The SerializableObject class is the base class for all classes which need to be serializable/deserial...
Definition: serializableobject.h:46
The CmdListElementsSwap class.
Definition: cmdlistelementsswap.h:44
QSet< IF_TextObserver * > mObservers
A list of all observer objects.
Definition: text.h:129
const Alignment & getAlign() const noexcept
Definition: text.h:95
const Point & getPosition() const noexcept
Definition: text.h:92
const GraphicsLayerName & getLayerName() const noexcept
Definition: text.h:91
Text & operator=(const Text &rhs) noexcept
Definition: text.cpp:189
The Point class is used to represent a point/coordinate/vector, for example (1.2mm; 5...
Definition: point.h:81
bool operator!=(const Text &rhs) const noexcept
Definition: text.h:115
const QString & getText() const noexcept
Definition: text.h:96
static constexpr const char * tagname
Definition: text.h:137
virtual void textRotationChanged(const Angle &newRot) noexcept=0
Point mPosition
Definition: text.h:122
void setLayerName(const GraphicsLayerName &name) noexcept
Definition: text.cpp:104
void unregisterObserver(IF_TextObserver &object) const noexcept
Definition: text.cpp:160
const Uuid & getUuid() const noexcept
Definition: text.h:90
type_safe::constrained_type< Length, PositiveLengthConstraint, PositiveLengthVerifier > PositiveLength
Definition: length.h:783
void registerObserver(IF_TextObserver &object) const noexcept
Definition: text.cpp:156
The CmdListElementInsert class.
Definition: cmdlistelementinsert.h:44
QString mText
Definition: text.h:121
const Angle & getRotation() const noexcept
Definition: text.h:93
virtual void textAlignChanged(const Alignment &newAlign) noexcept=0
The Text class.
Definition: text.h:75
virtual void textTextChanged(const QString &newText) noexcept=0
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:58
Angle mRotation
Definition: text.h:123
The IF_TextObserver class.
Definition: text.h:51
The SExpression class.
Definition: sexpression.h:60
void setText(const QString &text) noexcept
Definition: text.cpp:112
Definition: text.h:136
void setRotation(const Angle &rotation) noexcept
Definition: text.cpp:128