LibrePCB Developers Documentation
footprintlistmodel.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_FOOTPRINTLISTMODEL_H
21 #define LIBREPCB_LIBRARY_EDITOR_FOOTPRINTLISTMODEL_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 FootprintListModel
42  ******************************************************************************/
43 
47 class FootprintListModel final : public QAbstractTableModel {
48  Q_OBJECT
49 
50 public:
52 
53  // Constructors / Destructor
54  FootprintListModel() = delete;
55  FootprintListModel(const FootprintListModel& other) noexcept;
56  explicit FootprintListModel(QObject* parent = nullptr) noexcept;
57  ~FootprintListModel() noexcept;
58 
59  // Setters
60  void setFootprintList(FootprintList* list) noexcept;
61  void setUndoStack(UndoStack* stack) noexcept;
62 
63  // Slots
64  void addFootprint(const QVariant& editData) noexcept;
65  void copyFootprint(const QVariant& editData) noexcept;
66  void removeFootprint(const QVariant& editData) noexcept;
67  void moveFootprintUp(const QVariant& editData) noexcept;
68  void moveFootprintDown(const QVariant& editData) noexcept;
69 
70  // Inherited from QAbstractItemModel
71  int rowCount(const QModelIndex& parent = QModelIndex()) const override;
72  int columnCount(const QModelIndex& parent = QModelIndex()) const override;
73  QVariant data(const QModelIndex& index,
74  int role = Qt::DisplayRole) const override;
75  QVariant headerData(int section, Qt::Orientation orientation,
76  int role = Qt::DisplayRole) const override;
77  Qt::ItemFlags flags(const QModelIndex& index) const override;
78  bool setData(const QModelIndex& index, const QVariant& value,
79  int role = Qt::EditRole) override;
80 
81  // Operator Overloadings
82  FootprintListModel& operator=(const FootprintListModel& rhs) noexcept;
83 
84 private:
85  void footprintListEdited(const FootprintList& list, int index,
86  const std::shared_ptr<const Footprint>& footprint,
87  FootprintList::Event event) noexcept;
88  void execCmd(UndoCommand* cmd);
89  ElementName validateNameOrThrow(const QString& name) const;
90 
91 private: // Data
94  QString mNewName;
95 
96  // Slots
98 };
99 
100 /*******************************************************************************
101  * End of File
102  ******************************************************************************/
103 
104 } // namespace editor
105 } // namespace library
106 } // namespace librepcb
107 
108 #endif
void removeFootprint(const QVariant &editData) noexcept
Definition: footprintlistmodel.cpp:120
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
Definition: footprintlistmodel.cpp:229
void moveFootprintDown(const QVariant &editData) noexcept
Definition: footprintlistmodel.cpp:150
void footprintListEdited(const FootprintList &list, int index, const std::shared_ptr< const Footprint > &footprint, FootprintList::Event event) noexcept
Definition: footprintlistmodel.cpp:310
void setFootprintList(FootprintList *list) noexcept
Definition: footprintlistmodel.cpp:56
Qt::ItemFlags flags(const QModelIndex &index) const override
Definition: footprintlistmodel.cpp:261
ElementName validateNameOrThrow(const QString &name) const
Definition: footprintlistmodel.cpp:344
Definition: airwiresbuilder.cpp:32
Column
Definition: footprintlistmodel.h:51
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Definition: footprintlistmodel.cpp:184
void copyFootprint(const QVariant &editData) noexcept
Definition: footprintlistmodel.cpp:96
void moveFootprintUp(const QVariant &editData) noexcept
Definition: footprintlistmodel.cpp:134
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: footprintlistmodel.cpp:269
FootprintList::OnEditedSlot mOnEditedSlot
Definition: footprintlistmodel.h:97
FootprintListModel & operator=(const FootprintListModel &rhs) noexcept
The FootprintListModel class.
Definition: footprintlistmodel.h:47
FootprintList * mFootprintList
Definition: footprintlistmodel.h:92
UndoStack * mUndoStack
Definition: footprintlistmodel.h:93
The UndoCommand class represents a command which you can undo/redo.
Definition: undocommand.h:47
int columnCount(const QModelIndex &parent=QModelIndex()) const override
Definition: footprintlistmodel.cpp:177
QString mNewName
Definition: footprintlistmodel.h:94
The Slot class is used to receive signals from non-QObject derived classes.
Definition: signalslot.h:36
void addFootprint(const QVariant &editData) noexcept
Definition: footprintlistmodel.cpp:80
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Definition: footprintlistmodel.cpp:170
~FootprintListModel() noexcept
Definition: footprintlistmodel.cpp:49
void execCmd(UndoCommand *cmd)
Definition: footprintlistmodel.cpp:335
type_safe::constrained_type< QString, ElementNameConstraint, ElementNameVerifier > ElementName
Definition: elementname.h:92
void setUndoStack(UndoStack *stack) noexcept
Definition: footprintlistmodel.cpp:72