LibrePCB Developers Documentation
componentsignallistmodel.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_COMPONENTSIGNALLISTMODEL_H
21 #define LIBREPCB_LIBRARY_EDITOR_COMPONENTSIGNALLISTMODEL_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
27 
28 #include <QtCore>
29 
30 /*******************************************************************************
31  * Namespace / Forward Declarations
32  ******************************************************************************/
33 namespace librepcb {
34 
35 class UndoStack;
36 
37 namespace library {
38 namespace editor {
39 
40 /*******************************************************************************
41  * Class ComponentSignalListModel
42  ******************************************************************************/
43 
47 class ComponentSignalListModel final : public QAbstractTableModel {
48  Q_OBJECT
49 
50 public:
51  enum Column {
57  };
58 
59  // Constructors / Destructor
60  ComponentSignalListModel() = delete;
62  explicit ComponentSignalListModel(QObject* parent = nullptr) noexcept;
63  ~ComponentSignalListModel() noexcept;
64 
65  // Setters
66  void setSignalList(ComponentSignalList* list) noexcept;
67  void setUndoStack(UndoStack* stack) noexcept;
68 
69  // Slots
70  void addSignal(const QVariant& editData) noexcept;
71  void removeSignal(const QVariant& editData) noexcept;
72 
73  // Inherited from QAbstractItemModel
74  int rowCount(const QModelIndex& parent = QModelIndex()) const override;
75  int columnCount(const QModelIndex& parent = QModelIndex()) const override;
76  QVariant data(const QModelIndex& index,
77  int role = Qt::DisplayRole) const override;
78  QVariant headerData(int section, Qt::Orientation orientation,
79  int role = Qt::DisplayRole) const override;
80  Qt::ItemFlags flags(const QModelIndex& index) const override;
81  bool setData(const QModelIndex& index, const QVariant& value,
82  int role = Qt::EditRole) override;
83 
84  // Operator Overloadings
85  ComponentSignalListModel& operator=(
86  const ComponentSignalListModel& rhs) noexcept;
87 
88 private:
89  void signalListEdited(const ComponentSignalList& list, int index,
90  const std::shared_ptr<const ComponentSignal>& signal,
91  ComponentSignalList::Event event) noexcept;
92  void execCmd(UndoCommand* cmd);
93  CircuitIdentifier validateNameOrThrow(const QString& name) const;
94  static QString cleanForcedNetName(const QString& name) noexcept;
95 
96 private: // Data
99  QString mNewName;
102 
103  // Slots
105 };
106 
107 /*******************************************************************************
108  * End of File
109  ******************************************************************************/
110 
111 } // namespace editor
112 } // namespace library
113 } // namespace librepcb
114 
115 #endif
Column
Definition: componentsignallistmodel.h:51
void execCmd(UndoCommand *cmd)
Definition: componentsignallistmodel.cpp:347
ComponentSignalList * mSignalList
Definition: componentsignallistmodel.h:97
The ComponentSignal class represents one signal of a component.
Definition: componentsignal.h:49
Definition: airwiresbuilder.cpp:32
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
Definition: componentsignallistmodel.cpp:214
The ComponentSignalListModel class.
Definition: componentsignallistmodel.h:47
void removeSignal(const QVariant &editData) noexcept
Definition: componentsignallistmodel.cpp:110
The UndoStack class holds UndoCommand objects and provides undo/redo commands.
Definition: undostack.h:107
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
Definition: componentsignallistmodel.cpp:260
int columnCount(const QModelIndex &parent=QModelIndex()) const override
Definition: componentsignallistmodel.cpp:135
static QString cleanForcedNetName(const QString &name) noexcept
Definition: componentsignallistmodel.cpp:367
Qt::ItemFlags flags(const QModelIndex &index) const override
Definition: componentsignallistmodel.cpp:250
void setSignalList(ComponentSignalList *list) noexcept
Definition: componentsignallistmodel.cpp:60
type_safe::constrained_type< QString, CircuitIdentifierConstraint, CircuitIdentifierVerifier > CircuitIdentifier
Definition: circuitidentifier.h:89
void addSignal(const QVariant &editData) noexcept
Definition: componentsignallistmodel.cpp:85
ComponentSignalList::OnEditedSlot mOnEditedSlot
Definition: componentsignallistmodel.h:104
The UndoCommand class represents a command which you can undo/redo.
Definition: undocommand.h:47
QString mNewForcedNetName
Definition: componentsignallistmodel.h:101
void setUndoStack(UndoStack *stack) noexcept
Definition: componentsignallistmodel.cpp:77
void signalListEdited(const ComponentSignalList &list, int index, const std::shared_ptr< const ComponentSignal > &signal, ComponentSignalList::Event event) noexcept
Definition: componentsignallistmodel.cpp:322
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Definition: componentsignallistmodel.cpp:128
QString mNewName
Definition: componentsignallistmodel.h:99
bool mNewIsRequired
Definition: componentsignallistmodel.h:100
UndoStack * mUndoStack
Definition: componentsignallistmodel.h:98
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Definition: componentsignallistmodel.cpp:142
CircuitIdentifier validateNameOrThrow(const QString &name) const
Definition: componentsignallistmodel.cpp:356