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