LibrePCB Developers Documentation
packagemodellistmodel.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_PACKAGEMODELLISTMODEL_H
21#define LIBREPCB_EDITOR_PACKAGEMODELLISTMODEL_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
28
29#include <QtCore>
30
31#include <memory>
32
33/*******************************************************************************
34 * Namespace / Forward Declarations
35 ******************************************************************************/
36namespace librepcb {
37
38class Package;
39
40namespace editor {
41
42class UndoCommand;
43class UndoStack;
44
45/*******************************************************************************
46 * Class PackageModelListModel
47 ******************************************************************************/
48
52class PackageModelListModel final : public QAbstractTableModel {
53 Q_OBJECT
54
55public:
57
58 // Constructors / Destructor
61 explicit PackageModelListModel(QObject* parent = nullptr) noexcept;
62 ~PackageModelListModel() noexcept;
63
64 // Setters
65 void setPackage(Package* package) noexcept;
66 void setFootprint(std::shared_ptr<Footprint> footprint) noexcept;
67 void setUndoStack(UndoStack* stack) noexcept;
68
69 // Slots
70 void add(const QPersistentModelIndex& itemIndex) noexcept;
71 void remove(const QPersistentModelIndex& itemIndex) noexcept;
72 void edit(const QPersistentModelIndex& itemIndex) noexcept;
73 void moveUp(const QPersistentModelIndex& itemIndex) noexcept;
74 void moveDown(const QPersistentModelIndex& itemIndex) noexcept;
75
76 // Inherited from QAbstractItemModel
77 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
78 int columnCount(const QModelIndex& parent = QModelIndex()) const override;
79 QVariant data(const QModelIndex& index,
80 int role = Qt::DisplayRole) const override;
81 QVariant headerData(int section, Qt::Orientation orientation,
82 int role = Qt::DisplayRole) const override;
83 Qt::ItemFlags flags(const QModelIndex& index) const override;
84 bool setData(const QModelIndex& index, const QVariant& value,
85 int role = Qt::EditRole) override;
86
87 // Operator Overloadings
88 PackageModelListModel& operator=(const PackageModelListModel& rhs) noexcept;
89
90signals:
91 void newModelAdded(int index);
92
93private:
94 void modelListEdited(const PackageModelList& list, int index,
95 const std::shared_ptr<const PackageModel>& obj,
96 PackageModelList::Event event) noexcept;
97 void footprintEdited(const Footprint& obj, Footprint::Event event) noexcept;
98 void execCmd(UndoCommand* cmd);
99 ElementName validateNameOrThrow(const QString& name) const;
100 bool chooseStepFile(QByteArray& content, FilePath* selectedFile = nullptr);
101
102private: // Data
103 QPointer<Package> mPackage;
104 std::shared_ptr<Footprint> mFootprint;
107 QString mNewName;
108
109 // Slots
112};
113
114/*******************************************************************************
115 * End of File
116 ******************************************************************************/
117
118} // namespace editor
119} // namespace librepcb
120
121#endif
This class represents absolute, well-formatted paths to files or directories.
Definition: filepath.h:129
The Footprint class represents one footprint variant of a package.
Definition: footprint.h:55
The Package class represents a package of a component (including footprint and 3D model)
Definition: package.h:59
Represents a 3D model of a librepcb::Package.
Definition: packagemodel.h:43
The PackageModelListModel class.
Definition: packagemodellistmodel.h:52
void edit(const QPersistentModelIndex &itemIndex) noexcept
Definition: packagemodellistmodel.cpp:153
Footprint::OnEditedSlot mOnFootprintEditedSlot
Definition: packagemodellistmodel.h:111
QPointer< Package > mPackage
Definition: packagemodellistmodel.h:103
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
Definition: packagemodellistmodel.cpp:291
void setPackage(Package *package) noexcept
Definition: packagemodellistmodel.cpp:68
QString mNewName
Definition: packagemodellistmodel.h:107
void execCmd(UndoCommand *cmd)
Definition: packagemodellistmodel.cpp:438
bool mNewEnabled
Definition: packagemodellistmodel.h:106
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Definition: packagemodellistmodel.cpp:217
void moveDown(const QPersistentModelIndex &itemIndex) noexcept
Definition: packagemodellistmodel.cpp:195
void footprintEdited(const Footprint &obj, Footprint::Event event) noexcept
Definition: packagemodellistmodel.cpp:429
Qt::ItemFlags flags(const QModelIndex &index) const override
Definition: packagemodellistmodel.cpp:326
PackageModelListModel(const PackageModelListModel &other)=delete
void add(const QPersistentModelIndex &itemIndex) noexcept
Definition: packagemodellistmodel.cpp:107
bool chooseStepFile(QByteArray &content, FilePath *selectedFile=nullptr)
Definition: packagemodellistmodel.cpp:457
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Definition: packagemodellistmodel.cpp:231
void setUndoStack(UndoStack *stack) noexcept
Definition: packagemodellistmodel.cpp:99
void moveUp(const QPersistentModelIndex &itemIndex) noexcept
Definition: packagemodellistmodel.cpp:177
void remove(const QPersistentModelIndex &itemIndex) noexcept
Definition: packagemodellistmodel.cpp:138
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
Definition: packagemodellistmodel.cpp:339
void setFootprint(std::shared_ptr< Footprint > footprint) noexcept
Definition: packagemodellistmodel.cpp:84
ElementName validateNameOrThrow(const QString &name) const
Definition: packagemodellistmodel.cpp:447
int columnCount(const QModelIndex &parent=QModelIndex()) const override
Definition: packagemodellistmodel.cpp:224
std::shared_ptr< Footprint > mFootprint
Definition: packagemodellistmodel.h:104
UndoStack * mUndoStack
Definition: packagemodellistmodel.h:105
PackageModelList::OnEditedSlot mOnEditedSlot
Definition: packagemodellistmodel.h:110
Column
Definition: packagemodellistmodel.h:56
@ _COLUMN_COUNT
Definition: packagemodellistmodel.h:56
@ COLUMN_NAME
Definition: packagemodellistmodel.h:56
@ COLUMN_ACTIONS
Definition: packagemodellistmodel.h:56
@ COLUMN_ENABLED
Definition: packagemodellistmodel.h:56
void modelListEdited(const PackageModelList &list, int index, const std::shared_ptr< const PackageModel > &obj, PackageModelList::Event event) noexcept
Definition: packagemodellistmodel.cpp:403
The UndoCommand class represents a command which you can undo/redo.
Definition: undocommand.h:46
The UndoStack class holds UndoCommand objects and provides undo/redo commands.
Definition: undostack.h:106
Definition: occmodel.cpp:77
type_safe::constrained_type< QString, ElementNameConstraint, ElementNameVerifier > ElementName
Definition: elementname.h:84