LibrePCB Developers Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
packagepadlisteditorwidget.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_PACKAGEPADLISTEDITORWIDGET_H
21 #define LIBREPCB_LIBRARY_EDITOR_PACKAGEPADLISTEDITORWIDGET_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 PackagePadListEditorWidget
43  ******************************************************************************/
44 
51 class PackagePadListEditorWidget final : public QWidget,
52  private PackagePadList::IF_Observer {
53  Q_OBJECT
54 
55 private: // Types
57 
58 public:
59  // Constructors / Destructor
60  explicit PackagePadListEditorWidget(QWidget* parent = nullptr) noexcept;
62  ~PackagePadListEditorWidget() noexcept;
63 
64  // Setters
65  void setReferences(PackagePadList& list, UndoStack* stack) noexcept;
66 
67  // Operator Overloadings
69  delete;
70 
71 private: // Slots
72  void currentCellChanged(int currentRow, int currentColumn, int previousRow,
73  int previousColumn) noexcept;
74  void tableCellChanged(int row, int column) noexcept;
75  void btnAddRemoveClicked() noexcept;
76 
77 private: // Methods
78  void updateTable(const tl::optional<Uuid>& selected = tl::nullopt) noexcept;
79  void setTableRowContent(int row, const tl::optional<Uuid>& uuid,
80  const QString& name) noexcept;
81  void addPad(const QString& name) noexcept;
82  void removePad(const Uuid& uuid) noexcept;
83  CircuitIdentifier setName(const Uuid& uuid, const QString& name) noexcept;
84  int getRowOfTableCellWidget(QObject* obj) const noexcept;
85  tl::optional<Uuid> getUuidOfRow(int row) const noexcept;
86  CircuitIdentifier validateNameOrThrow(const QString& name) const;
87  void executeCommand(UndoCommand* cmd);
88  QString getNextPadNameProposal() const noexcept;
89 
90  // row index <-> signal index conversion methods
91  int newPadRow() const noexcept { return mPadList->count(); }
92  int indexToRow(int index) const noexcept { return index; }
93  int rowToIndex(int row) const noexcept { return row; }
94  bool isExistingPadRow(int row) const noexcept {
95  return row >= 0 && row < mPadList->count();
96  }
97  bool isNewPadRow(int row) const noexcept { return row == newPadRow(); }
98 
99  // Observer Methods
100  void listObjectAdded(
101  const PackagePadList& list, int newIndex,
102  const std::shared_ptr<PackagePad>& ptr) noexcept override;
103  void listObjectRemoved(
104  const PackagePadList& list, int oldIndex,
105  const std::shared_ptr<PackagePad>& ptr) noexcept override;
106 
107 private: // Data
108  QTableWidget* mTable;
111  tl::optional<Uuid> mSelectedPad;
112 };
113 
114 /*******************************************************************************
115  * End of File
116  ******************************************************************************/
117 
118 } // namespace editor
119 } // namespace library
120 } // namespace librepcb
121 
122 #endif // LIBREPCB_LIBRARY_EDITOR_PACKAGEPADLISTEDITORWIDGET_H
PackagePadList * mPadList
Definition: packagepadlisteditorwidget.h:109
int rowToIndex(int row) const noexcept
Definition: packagepadlisteditorwidget.h:93
bool isExistingPadRow(int row) const noexcept
Definition: packagepadlisteditorwidget.h:94
tl::optional< Uuid > getUuidOfRow(int row) const noexcept
Definition: packagepadlisteditorwidget.cpp:261
void listObjectRemoved(const PackagePadList &list, int oldIndex, const std::shared_ptr< PackagePad > &ptr) noexceptoverride
Definition: packagepadlisteditorwidget.cpp:311
Column
Definition: packagepadlisteditorwidget.h:56
UndoStack * mUndoStack
Definition: packagepadlisteditorwidget.h:110
int count() const noexcept
Definition: serializableobjectlist.h:168
int indexToRow(int index) const noexcept
Definition: packagepadlisteditorwidget.h:92
void executeCommand(UndoCommand *cmd)
Definition: packagepadlisteditorwidget.cpp:280
void updateTable(const tl::optional< Uuid > &selected=tl::nullopt) noexcept
Definition: packagepadlisteditorwidget.cpp:138
The UndoStack class holds UndoCommand objects and provides undo/redo commands.
Definition: undostack.h:120
CircuitIdentifier validateNameOrThrow(const QString &name) const
Definition: packagepadlisteditorwidget.cpp:270
void btnAddRemoveClicked() noexcept
Definition: packagepadlisteditorwidget.cpp:121
void setReferences(PackagePadList &list, UndoStack *stack) noexcept
Definition: packagepadlisteditorwidget.cpp:81
QString getNextPadNameProposal() const noexcept
Definition: packagepadlisteditorwidget.cpp:289
void removePad(const Uuid &uuid) noexcept
Definition: packagepadlisteditorwidget.cpp:222
CircuitIdentifier setName(const Uuid &uuid, const QString &name) noexcept
Definition: packagepadlisteditorwidget.cpp:232
QTableWidget * mTable
Definition: packagepadlisteditorwidget.h:108
PackagePadListEditorWidget(QWidget *parent=nullptr) noexcept
Definition: packagepadlisteditorwidget.cpp:42
type_safe::constrained_type< QString, CircuitIdentifierConstraint, CircuitIdentifierVerifier > CircuitIdentifier
Definition: circuitidentifier.h:89
tl::optional< Uuid > mSelectedPad
Definition: packagepadlisteditorwidget.h:111
The PackagePadListEditorWidget class.
Definition: packagepadlisteditorwidget.h:51
int newPadRow() const noexcept
Definition: packagepadlisteditorwidget.h:91
The UndoCommand class represents a command which you can undo/redo.
Definition: undocommand.h:52
void listObjectAdded(const PackagePadList &list, int newIndex, const std::shared_ptr< PackagePad > &ptr) noexceptoverride
Definition: packagepadlisteditorwidget.cpp:301
void tableCellChanged(int row, int column) noexcept
Definition: packagepadlisteditorwidget.cpp:104
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:58
void addPad(const QString &name) noexcept
Definition: packagepadlisteditorwidget.cpp:210
int getRowOfTableCellWidget(QObject *obj) const noexcept
Definition: packagepadlisteditorwidget.cpp:252
void setTableRowContent(int row, const tl::optional< Uuid > &uuid, const QString &name) noexcept
Definition: packagepadlisteditorwidget.cpp:172
void currentCellChanged(int currentRow, int currentColumn, int previousRow, int previousColumn) noexcept
Definition: packagepadlisteditorwidget.cpp:95
bool isNewPadRow(int row) const noexcept
Definition: packagepadlisteditorwidget.h:97