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_EDITOR_FOOTPRINTLISTMODEL_H
21 #define LIBREPCB_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 Package;
36 
37 namespace editor {
38 
39 class UndoCommand;
40 class UndoStack;
41 
42 /*******************************************************************************
43  * Class FootprintListModel
44  ******************************************************************************/
45 
49 class FootprintListModel final : public QAbstractTableModel {
50  Q_OBJECT
51 
52 public:
53  enum Column {
63  };
64 
65  // Constructors / Destructor
66  FootprintListModel() = delete;
67  FootprintListModel(const FootprintListModel& other) = delete;
68  explicit FootprintListModel(QObject* parent = nullptr) noexcept;
69  ~FootprintListModel() noexcept;
70 
71  // Setters
72  void setPackage(Package* package) noexcept;
73  void setUndoStack(UndoStack* stack) noexcept;
74 
75  // Slots
76  void add(const QPersistentModelIndex& itemIndex) noexcept;
77  void copy(const QPersistentModelIndex& itemIndex) noexcept;
78  void remove(const QPersistentModelIndex& itemIndex) noexcept;
79  void moveUp(const QPersistentModelIndex& itemIndex) noexcept;
80  void moveDown(const QPersistentModelIndex& itemIndex) noexcept;
81 
82  // Inherited from QAbstractItemModel
83  int rowCount(const QModelIndex& parent = QModelIndex()) const override;
84  int columnCount(const QModelIndex& parent = QModelIndex()) const override;
85  QVariant data(const QModelIndex& index,
86  int role = Qt::DisplayRole) const override;
87  QVariant headerData(int section, Qt::Orientation orientation,
88  int role = Qt::DisplayRole) const override;
89  Qt::ItemFlags flags(const QModelIndex& index) const override;
90  bool setData(const QModelIndex& index, const QVariant& value,
91  int role = Qt::EditRole) override;
92 
93  // Operator Overloadings
94  FootprintListModel& operator=(const FootprintListModel& rhs) noexcept;
95 
96 private:
97  void footprintListEdited(const FootprintList& list, int index,
98  const std::shared_ptr<const Footprint>& footprint,
99  FootprintList::Event event) noexcept;
100  void execCmd(UndoCommand* cmd);
101  ElementName validateNameOrThrow(const QString& name) const;
102 
103 private: // Data
104  QPointer<Package> mPackage;
106  QString mNewName;
109 
110  // Slots
112 };
113 
114 /*******************************************************************************
115  * End of File
116  ******************************************************************************/
117 
118 } // namespace editor
119 } // namespace librepcb
120 
121 #endif
Definition: footprintlistmodel.h:61
Qt::ItemFlags flags(const QModelIndex &index) const override
Definition: footprintlistmodel.cpp:355
Definition: occmodel.cpp:77
void add(const QPersistentModelIndex &itemIndex) noexcept
Definition: footprintlistmodel.cpp:82
Definition: footprintlistmodel.h:62
The Package class represents a package of a component (including footprint and 3D model) ...
Definition: package.h:59
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Definition: footprintlistmodel.cpp:196
int columnCount(const QModelIndex &parent=QModelIndex()) const override
Definition: footprintlistmodel.cpp:189
Angle3D mNewModelRotation
Definition: footprintlistmodel.h:108
void execCmd(UndoCommand *cmd)
Definition: footprintlistmodel.cpp:450
The Footprint class represents one footprint variant of a package.
Definition: footprint.h:55
QPointer< Package > mPackage
Definition: footprintlistmodel.h:104
QString mNewName
Definition: footprintlistmodel.h:106
void remove(const QPersistentModelIndex &itemIndex) noexcept
Definition: footprintlistmodel.cpp:127
The UndoStack class holds UndoCommand objects and provides undo/redo commands.
Definition: undostack.h:106
The UndoCommand class represents a command which you can undo/redo.
Definition: undocommand.h:46
Definition: footprintlistmodel.h:54
UndoStack * mUndoStack
Definition: footprintlistmodel.h:105
void moveDown(const QPersistentModelIndex &itemIndex) noexcept
Definition: footprintlistmodel.cpp:160
ElementName validateNameOrThrow(const QString &name) const
Definition: footprintlistmodel.cpp:459
The FootprintListModel class.
Definition: footprintlistmodel.h:49
void footprintListEdited(const FootprintList &list, int index, const std::shared_ptr< const Footprint > &footprint, FootprintList::Event event) noexcept
Definition: footprintlistmodel.cpp:424
void setPackage(Package *package) noexcept
Definition: footprintlistmodel.cpp:58
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
Definition: footprintlistmodel.cpp:363
void copy(const QPersistentModelIndex &itemIndex) noexcept
Definition: footprintlistmodel.cpp:99
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Definition: footprintlistmodel.cpp:182
FootprintList::OnEditedSlot mOnEditedSlot
Definition: footprintlistmodel.h:111
std::tuple< Length, Length, Length > Point3D
Definition: length.h:989
Column
Definition: footprintlistmodel.h:53
void moveUp(const QPersistentModelIndex &itemIndex) noexcept
Definition: footprintlistmodel.cpp:142
std::tuple< Angle, Angle, Angle > Angle3D
Definition: angle.h:461
Point3D mNewModelPosition
Definition: footprintlistmodel.h:107
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
Definition: footprintlistmodel.cpp:308
void setUndoStack(UndoStack *stack) noexcept
Definition: footprintlistmodel.cpp:74
type_safe::constrained_type< QString, ElementNameConstraint, ElementNameVerifier > ElementName
Definition: elementname.h:84