LibrePCB Developers Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
footprintlisteditorwidget.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_LIBRARY_EDITOR_FOOTPRINTLISTEDITORWIDGET_H
21 #define LIBREPCB_LIBRARY_EDITOR_FOOTPRINTLISTEDITORWIDGET_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
27 
28 #include <QtCore>
29 #include <QtWidgets>
30 
31 /*******************************************************************************
32  * Namespace / Forward Declarations
33  ******************************************************************************/
34 namespace librepcb {
35 
36 class UndoStack;
37 
38 namespace library {
39 namespace editor {
40 
41 /*******************************************************************************
42  * Class FootprintListEditorWidget
43  ******************************************************************************/
44 
51 class FootprintListEditorWidget final : public QWidget,
52  private FootprintList::IF_Observer {
53  Q_OBJECT
54 
55 private: // Types
57 
58 public:
59  // Constructors / Destructor
60  explicit FootprintListEditorWidget(QWidget* parent = nullptr) noexcept;
62  ~FootprintListEditorWidget() noexcept;
63 
64  // Setters
65  void setReferences(FootprintList& list, UndoStack& stack) noexcept;
66 
67  // General Methods
68  void addDefaultFootprint();
69 
70  // Operator Overloadings
72  delete;
73 
74 signals:
75  void currentFootprintChanged(int index);
76 
77 private: // Slots
78  void currentCellChanged(int currentRow, int currentColumn, int previousRow,
79  int previousColumn) noexcept;
80  void tableCellChanged(int row, int column) noexcept;
81  void btnUpClicked() noexcept;
82  void btnDownClicked() noexcept;
83  void btnCopyClicked() noexcept;
84  void btnAddRemoveClicked() noexcept;
85 
86 private: // Methods
87  void updateTable(tl::optional<Uuid> selected = tl::nullopt) noexcept;
88  void setTableRowContent(int row, const tl::optional<Uuid>& uuid,
89  const QString& name) noexcept;
90  void addFootprint(const QString& name) noexcept;
91  void removeFootprint(const Uuid& uuid) noexcept;
92  void moveFootprintUp(int index) noexcept;
93  void moveFootprintDown(int index) noexcept;
94  void copyFootprint(const Uuid& uuid) noexcept;
95  ElementName setName(const Uuid& uuid, const QString& name) noexcept;
96  int getRowOfTableCellWidget(QObject* obj) const noexcept;
97  tl::optional<Uuid> getUuidOfRow(int row) const noexcept;
98  ElementName validateNameOrThrow(const QString& name) const;
99 
100  // row index <-> signal index conversion methods
101  int newFootprintRow() const noexcept { return mFootprintList->count(); }
102  int indexToRow(int index) const noexcept { return index; }
103  int rowToIndex(int row) const noexcept { return row; }
104  bool isExistingFootprintRow(int row) const noexcept {
105  return row >= 0 && row < mFootprintList->count();
106  }
107  bool isNewFootprintRow(int row) const noexcept {
108  return row == newFootprintRow();
109  }
110 
111  // Observer Methods
112  void listObjectAdded(const FootprintList& list, int newIndex,
113  const std::shared_ptr<Footprint>& ptr) noexcept override;
114  void listObjectRemoved(
115  const FootprintList& list, int oldIndex,
116  const std::shared_ptr<Footprint>& ptr) noexcept override;
117 
118 private: // Data
119  QTableWidget* mTable;
122  tl::optional<Uuid> mSelectedFootprint;
123 };
124 
125 /*******************************************************************************
126  * End of File
127  ******************************************************************************/
128 
129 } // namespace editor
130 } // namespace library
131 } // namespace librepcb
132 
133 #endif // LIBREPCB_LIBRARY_EDITOR_FOOTPRINTLISTEDITORWIDGET_H
int getRowOfTableCellWidget(QObject *obj) const noexcept
Definition: footprintlisteditorwidget.cpp:373
bool isNewFootprintRow(int row) const noexcept
Definition: footprintlisteditorwidget.h:107
UndoStack * mUndoStack
Definition: footprintlisteditorwidget.h:121
int count() const noexcept
Definition: serializableobjectlist.h:168
FootprintList * mFootprintList
Definition: footprintlisteditorwidget.h:120
The UndoStack class holds UndoCommand objects and provides undo/redo commands.
Definition: undostack.h:120
void btnCopyClicked() noexcept
Definition: footprintlisteditorwidget.cpp:144
bool isExistingFootprintRow(int row) const noexcept
Definition: footprintlisteditorwidget.h:104
void listObjectAdded(const FootprintList &list, int newIndex, const std::shared_ptr< Footprint > &ptr) noexceptoverride
Definition: footprintlisteditorwidget.cpp:408
The FootprintListEditorWidget class.
Definition: footprintlisteditorwidget.h:51
void addDefaultFootprint()
Definition: footprintlisteditorwidget.cpp:94
void moveFootprintDown(int index) noexcept
Definition: footprintlisteditorwidget.cpp:322
void btnUpClicked() noexcept
Definition: footprintlisteditorwidget.cpp:128
void addFootprint(const QString &name) noexcept
Definition: footprintlisteditorwidget.cpp:289
ElementName setName(const Uuid &uuid, const QString &name) noexcept
Definition: footprintlisteditorwidget.cpp:353
void btnDownClicked() noexcept
Definition: footprintlisteditorwidget.cpp:136
void removeFootprint(const Uuid &uuid) noexcept
Definition: footprintlisteditorwidget.cpp:302
void tableCellChanged(int row, int column) noexcept
Definition: footprintlisteditorwidget.cpp:112
tl::optional< Uuid > getUuidOfRow(int row) const noexcept
Definition: footprintlisteditorwidget.cpp:382
void setTableRowContent(int row, const tl::optional< Uuid > &uuid, const QString &name) noexcept
Definition: footprintlisteditorwidget.cpp:210
ElementName validateNameOrThrow(const QString &name) const
Definition: footprintlisteditorwidget.cpp:391
void setReferences(FootprintList &list, UndoStack &stack) noexcept
Definition: footprintlisteditorwidget.cpp:81
int indexToRow(int index) const noexcept
Definition: footprintlisteditorwidget.h:102
void updateTable(tl::optional< Uuid > selected=tl::nullopt) noexcept
Definition: footprintlisteditorwidget.cpp:168
void moveFootprintUp(int index) noexcept
Definition: footprintlisteditorwidget.cpp:312
int newFootprintRow() const noexcept
Definition: footprintlisteditorwidget.h:101
tl::optional< Uuid > mSelectedFootprint
Definition: footprintlisteditorwidget.h:122
void currentCellChanged(int currentRow, int currentColumn, int previousRow, int previousColumn) noexcept
Definition: footprintlisteditorwidget.cpp:102
void copyFootprint(const Uuid &uuid) noexcept
Definition: footprintlisteditorwidget.cpp:332
int rowToIndex(int row) const noexcept
Definition: footprintlisteditorwidget.h:103
void listObjectRemoved(const FootprintList &list, int oldIndex, const std::shared_ptr< Footprint > &ptr) noexceptoverride
Definition: footprintlisteditorwidget.cpp:418
Column
Definition: footprintlisteditorwidget.h:56
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:58
QTableWidget * mTable
Definition: footprintlisteditorwidget.h:119
FootprintListEditorWidget(QWidget *parent=nullptr) noexcept
Definition: footprintlisteditorwidget.cpp:42
void btnAddRemoveClicked() noexcept
Definition: footprintlisteditorwidget.cpp:152
type_safe::constrained_type< QString, ElementNameConstraint, ElementNameVerifier > ElementName
Definition: elementname.h:92