LibrePCB Developers Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
attributelisteditorwidget.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_ATTRIBUTELISTEDITORWIDGET_H
21 #define LIBREPCB_ATTRIBUTELISTEDITORWIDGET_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
26 #include "../attributes/attribute.h"
27 
28 #include <QtCore>
29 #include <QtWidgets>
30 
31 /*******************************************************************************
32  * Namespace / Forward Declarations
33  ******************************************************************************/
34 namespace librepcb {
35 
36 /*******************************************************************************
37  * Class AttributeListEditorWidget
38  ******************************************************************************/
39 
46 class AttributeListEditorWidget final : public QWidget {
47  Q_OBJECT
48 
49 private: // Types
50  enum Column {
57  };
58 
59 public:
60  // Constructors / Destructor
61  explicit AttributeListEditorWidget(QWidget* parent = nullptr) noexcept;
63  ~AttributeListEditorWidget() noexcept;
64 
65  // Getters
66  const AttributeList& getAttributeList() const noexcept {
67  return mAttributeList;
68  }
69 
70  // Setters
71  void setAttributeList(const AttributeList& list) noexcept;
72 
73  // Operator Overloadings
75  delete;
76 
77 signals:
78  void edited(const AttributeList& attributes);
79 
80 private: // Slots
81  void currentCellChanged(int currentRow, int currentColumn, int previousRow,
82  int previousColumn) noexcept;
83  void tableCellChanged(int row, int column) noexcept;
84  void attributeTypeChanged(const AttributeType* type) noexcept;
85  void attributeUnitChanged(const AttributeUnit* unit) noexcept;
86  void btnAddRemoveClicked() noexcept;
87  void btnUpClicked() noexcept;
88  void btnDownClicked() noexcept;
89 
90 private: // Methods
91  void updateTable(const Attribute* selected = nullptr) noexcept;
92  void setTableRowContent(int row, const QString& key,
93  const AttributeType& type, const QString& value,
94  const AttributeUnit* unit) noexcept;
95  void getTableRowContent(int row, QString& key, const AttributeType*& type,
96  QString& value, const AttributeUnit*& unit) const
97  noexcept;
98  void addAttribute(const QString& key, const AttributeType& type,
99  const QString& value, const AttributeUnit* unit) noexcept;
100  void removeAttribute(int index) noexcept;
101  void moveAttributeUp(int index) noexcept;
102  void moveAttributeDown(int index) noexcept;
103  AttributeKey setKey(int index, const QString& key) noexcept;
104  void setType(int index, const AttributeType& type) noexcept;
105  QString setValue(int index, const QString& value) noexcept;
106  void setUnit(int index, const AttributeUnit* unit) noexcept;
107  int getRowOfTableCellWidget(QObject* obj) const noexcept;
108  AttributeKey convertStringToKeyOrThrow(const QString& key) const;
109  void throwIfValueInvalid(const AttributeType& type,
110  const QString& value) const;
111 
112  // row index <-> attribute index conversion methods
113  int newAttributeRow() const noexcept { return mAttributeList.count(); }
114  int indexToRow(int index) const noexcept { return index; }
115  int rowToIndex(int row) const noexcept { return row; }
116  bool isExistingAttributeRow(int row) const noexcept {
117  return row >= 0 && row < mAttributeList.count();
118  }
119  bool isNewAttributeRow(int row) const noexcept {
120  return row == newAttributeRow();
121  }
122 
123 private: // Data
124  QTableWidget* mTable;
126  const Attribute*
128 };
129 
130 /*******************************************************************************
131  * End of File
132  ******************************************************************************/
133 
134 } // namespace librepcb
135 
136 #endif // LIBREPCB_ATTRIBUTELISTEDITORWIDGET_H
void addAttribute(const QString &key, const AttributeType &type, const QString &value, const AttributeUnit *unit) noexcept
Definition: attributelisteditorwidget.cpp:333
void moveAttributeUp(int index) noexcept
Definition: attributelisteditorwidget.cpp:355
QTableWidget * mTable
Definition: attributelisteditorwidget.h:124
void moveAttributeDown(int index) noexcept
Definition: attributelisteditorwidget.cpp:362
Definition: attributelisteditorwidget.h:52
void setType(int index, const AttributeType &type) noexcept
Definition: attributelisteditorwidget.cpp:387
void btnUpClicked() noexcept
Definition: attributelisteditorwidget.cpp:170
AttributeListEditorWidget(QWidget *parent=nullptr) noexcept
Definition: attributelisteditorwidget.cpp:43
The AttributeListEditorWidget class.
Definition: attributelisteditorwidget.h:46
bool isNewAttributeRow(int row) const noexcept
Definition: attributelisteditorwidget.h:119
Definition: attributelisteditorwidget.h:51
AttributeList mAttributeList
Definition: attributelisteditorwidget.h:125
void getTableRowContent(int row, QString &key, const AttributeType *&type, QString &value, const AttributeUnit *&unit) const noexcept
Definition: attributelisteditorwidget.cpp:305
int newAttributeRow() const noexcept
Definition: attributelisteditorwidget.h:113
type_safe::constrained_type< QString, AttributeKeyConstraint, AttributeKeyVerifier > AttributeKey
Definition: attributekey.h:83
int count() const noexcept
Definition: serializableobjectlist.h:168
void attributeUnitChanged(const AttributeUnit *unit) noexcept
Definition: attributelisteditorwidget.cpp:149
int indexToRow(int index) const noexcept
Definition: attributelisteditorwidget.h:114
AttributeListEditorWidget & operator=(const AttributeListEditorWidget &rhs)=delete
const Attribute * mSelectedAttribute
do NOT dereference it (could be dangling)!
Definition: attributelisteditorwidget.h:127
The AttributeUnit class.
Definition: attributeunit.h:42
Definition: attributelisteditorwidget.h:56
void setUnit(int index, const AttributeUnit *unit) noexcept
Definition: attributelisteditorwidget.cpp:440
Definition: attributelisteditorwidget.h:54
void setAttributeList(const AttributeList &list) noexcept
Definition: attributelisteditorwidget.cpp:91
AttributeKey convertStringToKeyOrThrow(const QString &key) const
Definition: attributelisteditorwidget.cpp:460
AttributeKey setKey(int index, const QString &key) noexcept
Definition: attributelisteditorwidget.cpp:369
QString setValue(int index, const QString &value) noexcept
Definition: attributelisteditorwidget.cpp:422
void btnAddRemoveClicked() noexcept
Definition: attributelisteditorwidget.cpp:157
Column
Definition: attributelisteditorwidget.h:50
The Attribute class.
Definition: attribute.h:49
int rowToIndex(int row) const noexcept
Definition: attributelisteditorwidget.h:115
int getRowOfTableCellWidget(QObject *obj) const noexcept
Definition: attributelisteditorwidget.cpp:451
const AttributeList & getAttributeList() const noexcept
Definition: attributelisteditorwidget.h:66
void btnDownClicked() noexcept
Definition: attributelisteditorwidget.cpp:178
bool isExistingAttributeRow(int row) const noexcept
Definition: attributelisteditorwidget.h:116
void tableCellChanged(int row, int column) noexcept
Definition: attributelisteditorwidget.cpp:111
void setTableRowContent(int row, const QString &key, const AttributeType &type, const QString &value, const AttributeUnit *unit) noexcept
Definition: attributelisteditorwidget.cpp:226
Definition: attributelisteditorwidget.h:53
void removeAttribute(int index) noexcept
Definition: attributelisteditorwidget.cpp:348
void throwIfValueInvalid(const AttributeType &type, const QString &value) const
Definition: attributelisteditorwidget.cpp:475
void attributeTypeChanged(const AttributeType *type) noexcept
Definition: attributelisteditorwidget.cpp:128
void currentCellChanged(int currentRow, int currentColumn, int previousRow, int previousColumn) noexcept
Definition: attributelisteditorwidget.cpp:102
Definition: attributelisteditorwidget.h:55
The AttributeType class.
Definition: attributetype.h:44
void updateTable(const Attribute *selected=nullptr) noexcept
Definition: attributelisteditorwidget.cpp:190
void edited(const AttributeList &attributes)