LibrePCB Developers Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
attributeprovider.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_ATTRIBUTEPROVIDER_H
21 #define LIBREPCB_ATTRIBUTEPROVIDER_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
26 #include <QtCore>
27 
28 /*******************************************************************************
29  * Namespace / Forward Declarations
30  ******************************************************************************/
31 namespace librepcb {
32 
33 /*******************************************************************************
34  * Interface AttributeProvider
35  ******************************************************************************/
36 
60 public:
61  // Constructors / Destructor / Operator Overloadings
62  AttributeProvider() noexcept {}
63  AttributeProvider(const AttributeProvider& other) = delete;
64  AttributeProvider& operator=(const AttributeProvider& rhs) = delete;
65  virtual ~AttributeProvider() noexcept {}
66 
75  QString getAttributeValue(const QString& key) const noexcept;
76 
84  virtual QString getUserDefinedAttributeValue(const QString& key) const
85  noexcept {
86  Q_UNUSED(key);
87  return QString();
88  }
89 
97  virtual QString getBuiltInAttributeValue(const QString& key) const noexcept {
98  Q_UNUSED(key);
99  return QString();
100  }
101 
108  virtual QVector<const AttributeProvider*> getAttributeProviderParents() const
109  noexcept {
110  return QVector<const AttributeProvider*>();
111  }
112 
113 signals:
114 
122  virtual void attributesChanged() = 0;
123 
124 private:
125  QString getAttributeValue(const QString& key,
126  QVector<const AttributeProvider*>& backtrace) const
127  noexcept;
128 };
129 
130 // Make sure that the AttributeProvider class does not contain any data (except
131 // the vptr). Otherwise it could introduce issues when using multiple
132 // inheritance.
133 static_assert(sizeof(AttributeProvider) == sizeof(void*),
134  "AttributeProvider must not contain any data!");
135 
136 /*******************************************************************************
137  * End of File
138  ******************************************************************************/
139 
140 } // namespace librepcb
141 
142 #endif // LIBREPCB_ATTRIBUTEPROVIDER_H
AttributeProvider & operator=(const AttributeProvider &rhs)=delete
QString getAttributeValue(const QString &key) const noexcept
Get the value of an attribute which can be used in texts (like "{{NAME}}")
Definition: attributeprovider.cpp:36
virtual QString getUserDefinedAttributeValue(const QString &key) const noexcept
Get the value of a user defined attribute (if available)
Definition: attributeprovider.h:84
virtual QVector< const AttributeProvider * > getAttributeProviderParents() const noexcept
Get all parent attribute providers (fallback if attribute not found)
Definition: attributeprovider.h:108
virtual void attributesChanged()=0
This signal is emited when the value of attributes has changed.
virtual QString getBuiltInAttributeValue(const QString &key) const noexcept
Get the value of a built-in attribute (if available)
Definition: attributeprovider.h:97
virtual ~AttributeProvider() noexcept
Definition: attributeprovider.h:65
The AttributeProvider class defines an interface for classes which provides some attributes which can...
Definition: attributeprovider.h:59
AttributeProvider() noexcept
Definition: attributeprovider.h:62