LibrePCB Developers Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
componentsignallisteditorwidget.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_COMPONENTSIGNALLISTEDITORWIDGET_H
21 #define LIBREPCB_LIBRARY_EDITOR_COMPONENTSIGNALLISTEDITORWIDGET_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 ComponentSignalListEditorWidget
43  ******************************************************************************/
44 
52  : public QWidget,
53  private ComponentSignalList::IF_Observer {
54  Q_OBJECT
55 
56 private: // Types
57  enum Column {
59  // COLUMN_ROLE,
61  // COLUMN_ISNEGATED,
62  // COLUMN_ISCLOCK,
66  };
67 
68 public:
69  // Constructors / Destructor
70  explicit ComponentSignalListEditorWidget(QWidget* parent = nullptr) noexcept;
72  const ComponentSignalListEditorWidget& other) = delete;
74 
75  // Setters
76  void setReferences(UndoStack* undoStack, ComponentSignalList* list) noexcept;
77 
78  // Operator Overloadings
80  const ComponentSignalListEditorWidget& rhs) = delete;
81 
82 private: // Slots
83  void currentCellChanged(int currentRow, int currentColumn, int previousRow,
84  int previousColumn) noexcept;
85  void tableCellChanged(int row, int column) noexcept;
86  // void signalRoleChanged(const SignalRole& role) noexcept;
87  void isRequiredChanged(bool checked) noexcept;
88  // void isNegatedChanged(bool checked) noexcept;
89  // void isClockChanged(bool checked) noexcept;
90  void btnAddRemoveClicked() noexcept;
91 
92 private: // Observer
93  void listObjectAdded(
94  const ComponentSignalList& list, int newIndex,
95  const std::shared_ptr<ComponentSignal>& ptr) noexcept override;
96  void listObjectRemoved(
97  const ComponentSignalList& list, int oldIndex,
98  const std::shared_ptr<ComponentSignal>& ptr) noexcept override;
99 
100 private: // Methods
101  void updateTable() noexcept;
102  void setTableRowContent(int row, const tl::optional<Uuid>& uuid,
103  const QString& name,
104  /*const SignalRole& role,*/ bool required,
105  /*bool negated,
106 bool clock,*/ const QString& forcedNetName) noexcept;
107  void addSignal(
108  const QString& name, /*const SignalRole& role,*/ bool required,
109  /*bool negated, bool clock,*/ const QString& forcedNetName) noexcept;
110  void removeSignal(const Uuid& uuid) noexcept;
111  bool setName(const Uuid& uuid, const QString& name) noexcept;
112  // void setRole(const Uuid& uuid, const SignalRole& role) noexcept;
113  void setIsRequired(const Uuid& uuid, bool required) noexcept;
114  // void setIsNegated(const Uuid& uuid, bool negated) noexcept;
115  // void setIsClock(const Uuid& uuid, bool clock) noexcept;
116  void setForcedNetName(const Uuid& uuid, const QString& netname) noexcept;
117  int getRowOfTableCellWidget(QObject* obj) const noexcept;
118  tl::optional<Uuid> getUuidOfRow(int row) const noexcept;
119  CircuitIdentifier validateNameOrThrow(const QString& name) const;
120  static QString cleanForcedNetName(const QString& name) noexcept;
121 
122  // row index <-> signal index conversion methods
123  int newSignalRow() const noexcept { return mSignalList->count(); }
124  int indexToRow(int index) const noexcept { return index; }
125  int rowToIndex(int row) const noexcept { return row; }
126  bool isExistingSignalRow(int row) const noexcept {
127  return row >= 0 && row < mSignalList->count();
128  }
129  bool isNewSignalRow(int row) const noexcept { return row == newSignalRow(); }
130 
131 private: // Data
132  QTableWidget* mTable;
135  tl::optional<Uuid> mSelectedSignal;
136 };
137 
138 /*******************************************************************************
139  * End of File
140  ******************************************************************************/
141 
142 } // namespace editor
143 } // namespace library
144 } // namespace librepcb
145 
146 #endif // LIBREPCB_LIBRARY_EDITOR_COMPONENTSIGNALLISTEDITORWIDGET_H
ComponentSignalListEditorWidget(QWidget *parent=nullptr) noexcept
Definition: componentsignallisteditorwidget.cpp:44
void listObjectRemoved(const ComponentSignalList &list, int oldIndex, const std::shared_ptr< ComponentSignal > &ptr) noexceptoverride
Definition: componentsignallisteditorwidget.cpp:255
void updateTable() noexcept
Definition: componentsignallisteditorwidget.cpp:270
int newSignalRow() const noexcept
Definition: componentsignallisteditorwidget.h:123
bool isExistingSignalRow(int row) const noexcept
Definition: componentsignallisteditorwidget.h:126
tl::optional< Uuid > getUuidOfRow(int row) const noexcept
Definition: componentsignallisteditorwidget.cpp:551
void setTableRowContent(int row, const tl::optional< Uuid > &uuid, const QString &name, bool required, const QString &forcedNetName) noexcept
Definition: componentsignallisteditorwidget.cpp:315
The ComponentSignal class represents one signal of a component.
Definition: componentsignal.h:49
void btnAddRemoveClicked() noexcept
Definition: componentsignallisteditorwidget.cpp:205
CircuitIdentifier validateNameOrThrow(const QString &name) const
Definition: componentsignallisteditorwidget.cpp:560
void setForcedNetName(const Uuid &uuid, const QString &netname) noexcept
Definition: componentsignallisteditorwidget.cpp:524
int count() const noexcept
Definition: serializableobjectlist.h:168
QTableWidget * mTable
Definition: componentsignallisteditorwidget.h:132
int rowToIndex(int row) const noexcept
Definition: componentsignallisteditorwidget.h:125
ComponentSignalList * mSignalList
Definition: componentsignallisteditorwidget.h:134
void setReferences(UndoStack *undoStack, ComponentSignalList *list) noexcept
Definition: componentsignallisteditorwidget.cpp:110
The UndoStack class holds UndoCommand objects and provides undo/redo commands.
Definition: undostack.h:120
bool setName(const Uuid &uuid, const QString &name) noexcept
Definition: componentsignallisteditorwidget.cpp:427
Column
Definition: componentsignallisteditorwidget.h:57
void addSignal(const QString &name, bool required, const QString &forcedNetName) noexcept
Definition: componentsignallisteditorwidget.cpp:394
void listObjectAdded(const ComponentSignalList &list, int newIndex, const std::shared_ptr< ComponentSignal > &ptr) noexceptoverride
Definition: componentsignallisteditorwidget.cpp:244
tl::optional< Uuid > mSelectedSignal
Definition: componentsignallisteditorwidget.h:135
static QString cleanForcedNetName(const QString &name) noexcept
Definition: componentsignallisteditorwidget.cpp:571
bool isNewSignalRow(int row) const noexcept
Definition: componentsignallisteditorwidget.h:129
UndoStack * mUndoStack
Definition: componentsignallisteditorwidget.h:133
type_safe::constrained_type< QString, CircuitIdentifierConstraint, CircuitIdentifierVerifier > CircuitIdentifier
Definition: circuitidentifier.h:89
The ComponentSignalListEditorWidget class.
Definition: componentsignallisteditorwidget.h:51
void tableCellChanged(int row, int column) noexcept
Definition: componentsignallisteditorwidget.cpp:146
void currentCellChanged(int currentRow, int currentColumn, int previousRow, int previousColumn) noexcept
Definition: componentsignallisteditorwidget.cpp:136
int indexToRow(int index) const noexcept
Definition: componentsignallisteditorwidget.h:124
void removeSignal(const Uuid &uuid) noexcept
Definition: componentsignallisteditorwidget.cpp:413
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:58
Definition: componentsignallisteditorwidget.h:58
int getRowOfTableCellWidget(QObject *obj) const noexcept
Definition: componentsignallisteditorwidget.cpp:542
void isRequiredChanged(bool checked) noexcept
Definition: componentsignallisteditorwidget.cpp:178
void setIsRequired(const Uuid &uuid, bool required) noexcept
Definition: componentsignallisteditorwidget.cpp:470