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