LibrePCB Developers Documentation
partlistmodel.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_PARTLISTMODEL_H
21#define LIBREPCB_EDITOR_PARTLISTMODEL_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
27
28#include <QtCore>
29
30/*******************************************************************************
31 * Namespace / Forward Declarations
32 ******************************************************************************/
33namespace librepcb {
34namespace editor {
35
36class UndoCommand;
37class UndoStack;
38
39/*******************************************************************************
40 * Class PartListModel
41 ******************************************************************************/
42
46class PartListModel final : public QAbstractTableModel {
47 Q_OBJECT
48
49public:
50 enum Column {
56 };
57
58 // Constructors / Destructor
59 PartListModel() = delete;
60 PartListModel(const PartListModel& other) = delete;
61 explicit PartListModel(QObject* parent = nullptr) noexcept;
62 ~PartListModel() noexcept;
63
64 // Setters
65 void setInitialManufacturer(const SimpleString& value) noexcept;
66 void setPartList(PartList* list) noexcept;
67 void setUndoStack(UndoStack* stack) noexcept;
68
69 // Slots
70 void add(const QPersistentModelIndex& itemIndex) noexcept;
71 void copy(const QPersistentModelIndex& itemIndex) noexcept;
72 void remove(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 PartListModel& operator=(const PartListModel& rhs) noexcept;
89
90private:
91 void partListEdited(const PartList& list, int index,
92 const std::shared_ptr<const Part>& part,
93 PartList::Event event) noexcept;
94 void execCmd(UndoCommand* cmd);
95
96private: // Data
99 QString mNewMpn;
101
102 // Slots
103 PartList::OnEditedSlot mOnEditedSlot;
104};
105
106/*******************************************************************************
107 * End of File
108 ******************************************************************************/
109
110} // namespace editor
111} // namespace librepcb
112
113#endif
The Part class.
Definition: part.h:46
The PartListModel class.
Definition: partlistmodel.h:46
QString mNewManufacturer
Definition: partlistmodel.h:100
PartList * mPartList
Definition: partlistmodel.h:97
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
Definition: partlistmodel.cpp:248
PartList::OnEditedSlot mOnEditedSlot
Definition: partlistmodel.h:103
void execCmd(UndoCommand *cmd)
Definition: partlistmodel.cpp:367
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Definition: partlistmodel.cpp:170
void moveDown(const QPersistentModelIndex &itemIndex) noexcept
Definition: partlistmodel.cpp:151
Qt::ItemFlags flags(const QModelIndex &index) const override
Definition: partlistmodel.cpp:277
void add(const QPersistentModelIndex &itemIndex) noexcept
Definition: partlistmodel.cpp:87
void partListEdited(const PartList &list, int index, const std::shared_ptr< const Part > &part, PartList::Event event) noexcept
Definition: partlistmodel.cpp:332
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Definition: partlistmodel.cpp:184
void copy(const QPersistentModelIndex &itemIndex) noexcept
Definition: partlistmodel.cpp:104
void setUndoStack(UndoStack *stack) noexcept
Definition: partlistmodel.cpp:79
void moveUp(const QPersistentModelIndex &itemIndex) noexcept
Definition: partlistmodel.cpp:136
void remove(const QPersistentModelIndex &itemIndex) noexcept
Definition: partlistmodel.cpp:121
void setPartList(PartList *list) noexcept
Definition: partlistmodel.cpp:63
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
Definition: partlistmodel.cpp:286
void setInitialManufacturer(const SimpleString &value) noexcept
Definition: partlistmodel.cpp:59
int columnCount(const QModelIndex &parent=QModelIndex()) const override
Definition: partlistmodel.cpp:177
PartListModel(const PartListModel &other)=delete
UndoStack * mUndoStack
Definition: partlistmodel.h:98
Column
Definition: partlistmodel.h:50
@ _COLUMN_COUNT
Definition: partlistmodel.h:55
@ COLUMN_MPN
Definition: partlistmodel.h:51
@ COLUMN_ATTRIBUTES
Definition: partlistmodel.h:53
@ COLUMN_MANUFACTURER
Definition: partlistmodel.h:52
@ COLUMN_ACTIONS
Definition: partlistmodel.h:54
QString mNewMpn
Definition: partlistmodel.h:99
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, SimpleStringConstraint, SimpleStringVerifier > SimpleString
Definition: simplestring.h:80