LibrePCB Developers Documentation
packagepadlistmodel.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_PACKAGEPADLISTMODEL_H
21 #define LIBREPCB_LIBRARY_EDITOR_PACKAGEPADLISTMODEL_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 PackagePadListModel
42  ******************************************************************************/
43 
47 class PackagePadListModel final : public QAbstractTableModel {
48  Q_OBJECT
49 
50 public:
52 
53  // Constructors / Destructor
54  PackagePadListModel() = delete;
55  PackagePadListModel(const PackagePadListModel& other) noexcept;
56  explicit PackagePadListModel(QObject* parent = nullptr) noexcept;
57  ~PackagePadListModel() noexcept;
58 
59  // Setters
60  void setPadList(PackagePadList* list) noexcept;
61  void setUndoStack(UndoStack* stack) noexcept;
62 
63  // Slots
64  void addPad(const QVariant& editData) noexcept;
65  void removePad(const QVariant& editData) noexcept;
66 
67  // Inherited from QAbstractItemModel
68  int rowCount(const QModelIndex& parent = QModelIndex()) const override;
69  int columnCount(const QModelIndex& parent = QModelIndex()) const override;
70  QVariant data(const QModelIndex& index,
71  int role = Qt::DisplayRole) const override;
72  QVariant headerData(int section, Qt::Orientation orientation,
73  int role = Qt::DisplayRole) const override;
74  Qt::ItemFlags flags(const QModelIndex& index) const override;
75  bool setData(const QModelIndex& index, const QVariant& value,
76  int role = Qt::EditRole) override;
77 
78  // Operator Overloadings
80 
81 private:
82  void padListEdited(const PackagePadList& list, int index,
83  const std::shared_ptr<const PackagePad>& pad,
84  PackagePadList::Event event) noexcept;
85  void execCmd(UndoCommand* cmd);
86  CircuitIdentifier validateNameOrThrow(const QString& name) const;
87  QString getNextPadNameProposal() const noexcept;
88 
89 private: // Data
92  QString mNewName;
93 
94  // Slots
96 };
97 
98 /*******************************************************************************
99  * End of File
100  ******************************************************************************/
101 
102 } // namespace editor
103 } // namespace library
104 } // namespace librepcb
105 
106 #endif
QString getNextPadNameProposal() const noexcept
Definition: packagepadlistmodel.cpp:314
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Definition: packagepadlistmodel.cpp:139
Qt::ItemFlags flags(const QModelIndex &index) const override
Definition: packagepadlistmodel.cpp:217
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
Definition: packagepadlistmodel.cpp:225
~PackagePadListModel() noexcept
Definition: packagepadlistmodel.cpp:51
Definition: airwiresbuilder.cpp:32
void removePad(const QVariant &editData) noexcept
Definition: packagepadlistmodel.cpp:107
CircuitIdentifier validateNameOrThrow(const QString &name) const
Definition: packagepadlistmodel.cpp:304
The UndoStack class holds UndoCommand objects and provides undo/redo commands.
Definition: undostack.h:107
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Definition: packagepadlistmodel.cpp:125
UndoStack * mUndoStack
Definition: packagepadlistmodel.h:91
void execCmd(UndoCommand *cmd)
Definition: packagepadlistmodel.cpp:295
void padListEdited(const PackagePadList &list, int index, const std::shared_ptr< const PackagePad > &pad, PackagePadList::Event event) noexcept
Definition: packagepadlistmodel.cpp:271
The PackagePadListModel class.
Definition: packagepadlistmodel.h:47
type_safe::constrained_type< QString, CircuitIdentifierConstraint, CircuitIdentifierVerifier > CircuitIdentifier
Definition: circuitidentifier.h:89
void setPadList(PackagePadList *list) noexcept
Definition: packagepadlistmodel.cpp:58
PackagePadList * mPadList
Definition: packagepadlistmodel.h:90
QString mNewName
Definition: packagepadlistmodel.h:92
PackagePadList::OnEditedSlot mOnEditedSlot
Definition: packagepadlistmodel.h:95
Column
Definition: packagepadlistmodel.h:51
The UndoCommand class represents a command which you can undo/redo.
Definition: undocommand.h:47
void setUndoStack(UndoStack *stack) noexcept
Definition: packagepadlistmodel.cpp:74
PackagePadListModel & operator=(const PackagePadListModel &rhs) noexcept
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
Definition: packagepadlistmodel.cpp:185
void addPad(const QVariant &editData) noexcept
Definition: packagepadlistmodel.cpp:82
The Slot class is used to receive signals from non-QObject derived classes.
Definition: signalslot.h:36
int columnCount(const QModelIndex &parent=QModelIndex()) const override
Definition: packagepadlistmodel.cpp:132