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