LibrePCB Developers Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
bom.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_BOM_H
21 #define LIBREPCB_BOM_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
26 #include <QtCore>
27 
28 /*******************************************************************************
29  * Namespace / Forward Declarations
30  ******************************************************************************/
31 namespace librepcb {
32 
33 /*******************************************************************************
34  * Class BomItem
35  ******************************************************************************/
36 
40 class BomItem final {
41  Q_DECLARE_TR_FUNCTIONS(BomItem)
42 
43 public:
44  // Constructors / Destructor
45  BomItem() = delete;
46  BomItem(const QString& designator, const QStringList& attributes) noexcept
47  : mDesignators({designator}), mAttributes(attributes) {}
48  BomItem(const BomItem& other) noexcept
49  : mDesignators(other.mDesignators), mAttributes(other.mAttributes) {}
50  ~BomItem() noexcept {}
51 
52  // Getters
53  const QStringList& getDesignators() const noexcept { return mDesignators; }
54  const QStringList& getAttributes() const noexcept { return mAttributes; }
55 
56  // General Methods
57  void addDesignator(const QString& designator) noexcept {
58  mDesignators.append(designator);
59 
60  // sort designators to improve readability of the BOM
61  QCollator collator;
62  collator.setCaseSensitivity(Qt::CaseInsensitive);
63  collator.setIgnorePunctuation(false);
64  collator.setNumericMode(true);
65  std::sort(mDesignators.begin(), mDesignators.end(),
66  [&collator](const QString& lhs, const QString& rhs) {
67  return collator(lhs, rhs);
68  });
69  }
70 
71  // Operator Overloadings
72  BomItem& operator=(const BomItem& rhs) noexcept {
73  mDesignators = rhs.mDesignators;
74  mAttributes = rhs.mAttributes;
75  return *this;
76  }
77 
78 private:
79  QStringList mDesignators;
80  QStringList mAttributes;
81 };
82 
83 /*******************************************************************************
84  * Class Bom
85  ******************************************************************************/
86 
90 class Bom final {
91  Q_DECLARE_TR_FUNCTIONS(Bom)
92 
93 public:
94  // Constructors / Destructor
95  Bom() = delete;
96  Bom(const Bom& other) noexcept = delete;
97  explicit Bom(const QStringList& columns) noexcept;
98  ~Bom() noexcept;
99 
100  // Getters
101  const QStringList& getColumns() const noexcept { return mColumns; }
102  const QList<BomItem>& getItems() const noexcept { return mItems; }
103 
104  // General Methods
105  void addItem(const QString& designator,
106  const QStringList& attributes) noexcept;
107 
108  // Operator Overloadings
109  Bom& operator=(const Bom& rhs) noexcept = delete;
110 
111 private:
112  QStringList mColumns;
113  QList<BomItem> mItems;
114 };
115 
116 /*******************************************************************************
117  * End of File
118  ******************************************************************************/
119 
120 } // namespace librepcb
121 
122 #endif // LIBREPCB_BOM_H
The Bom class represents a bill of materials list.
Definition: bom.h:90
~Bom() noexcept
Definition: bom.cpp:39
BomItem & operator=(const BomItem &rhs) noexcept
Definition: bom.h:72
const QList< BomItem > & getItems() const noexcept
Definition: bom.h:102
BomItem(const QString &designator, const QStringList &attributes) noexcept
Definition: bom.h:46
QStringList mDesignators
Definition: bom.h:79
BomItem(const BomItem &other) noexcept
Definition: bom.h:48
const QStringList & getColumns() const noexcept
Definition: bom.h:101
~BomItem() noexcept
Definition: bom.h:50
Bom & operator=(const Bom &rhs) noexcept=delete
void addDesignator(const QString &designator) noexcept
Definition: bom.h:57
QStringList mColumns
Definition: bom.h:112
const QStringList & getDesignators() const noexcept
Definition: bom.h:53
const QStringList & getAttributes() const noexcept
Definition: bom.h:54
void addItem(const QString &designator, const QStringList &attributes) noexcept
Definition: bom.cpp:46
QList< BomItem > mItems
Definition: bom.h:113
Bom()=delete
QStringList mAttributes
Definition: bom.h:80
The BomItem class represents an item of a bill of materials list.
Definition: bom.h:40