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 
63 public:
64  // Constructors / Destructor / Operator Overloadings
65  AttributeProvider() noexcept {}
66  AttributeProvider(const AttributeProvider& other) = delete;
67  AttributeProvider& operator=(const AttributeProvider& rhs) = delete;
68  virtual ~AttributeProvider() noexcept {}
69 
78  QString getAttributeValue(const QString& key) const noexcept;
79 
87  virtual QString getUserDefinedAttributeValue(const QString& key) const
88  noexcept {
89  Q_UNUSED(key);
90  return QString();
91  }
92 
100  virtual QString getBuiltInAttributeValue(const QString& key) const noexcept {
101  Q_UNUSED(key);
102  return QString();
103  }
104 
111  virtual QVector<const AttributeProvider*> getAttributeProviderParents() const
112  noexcept {
113  return QVector<const AttributeProvider*>();
114  }
115 
116 signals:
117 
125  virtual void attributesChanged() = 0;
126 
127 private:
128  QString getAttributeValue(const QString& key,
129  QVector<const AttributeProvider*>& backtrace) const
130  noexcept;
131 };
132 
133 // Make sure that the AttributeProvider class does not contain any data (except
134 // the vptr). Otherwise it could introduce issues when using multiple
135 // inheritance.
136 static_assert(sizeof(AttributeProvider) == sizeof(void*),
137  "AttributeProvider must not contain any data!");
138 
139 /*******************************************************************************
140  * End of File
141  ******************************************************************************/
142 
143 } // namespace librepcb
144 
145 #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:87
virtual QVector< const AttributeProvider * > getAttributeProviderParents() const noexcept
Get all parent attribute providers (fallback if attribute not found)
Definition: attributeprovider.h:111
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:100
virtual ~AttributeProvider() noexcept
Definition: attributeprovider.h:68
The AttributeProvider class defines an interface for classes which provides some attributes which can...
Definition: attributeprovider.h:62
AttributeProvider() noexcept
Definition: attributeprovider.h:65