LibrePCB Developers Documentation
componentsymbolvariantlistmodel.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_COMPONENTSYMBOLVARIANTLISTMODEL_H
21 #define LIBREPCB_EDITOR_COMPONENTSYMBOLVARIANTLISTMODEL_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
27 
28 #include <QtCore>
29 
30 /*******************************************************************************
31  * Namespace / Forward Declarations
32  ******************************************************************************/
33 namespace librepcb {
34 namespace editor {
35 
36 class UndoCommand;
37 class UndoStack;
38 
39 /*******************************************************************************
40  * Class ComponentSymbolVariantListModel
41  ******************************************************************************/
42 
46 class ComponentSymbolVariantListModel final : public QAbstractTableModel {
47  Q_OBJECT
48 
49 public:
50  enum Column {
57  };
58 
59  // Constructors / Destructor
62  const ComponentSymbolVariantListModel& other) = delete;
63  explicit ComponentSymbolVariantListModel(QObject* parent = nullptr) noexcept;
65 
66  // Setters
68  void setUndoStack(UndoStack* stack) noexcept;
69 
70  // Slots
71  void add(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
89  const ComponentSymbolVariantListModel& rhs) noexcept;
90 
91 private:
93  const ComponentSymbolVariantList& list, int index,
94  const std::shared_ptr<const ComponentSymbolVariant>& variant,
95  ComponentSymbolVariantList::Event event) noexcept;
96  void execCmd(UndoCommand* cmd);
97  ElementName validateNameOrThrow(const QString& name) const;
98 
99 private: // Data
102  QString mNewName;
104  QString mNewNorm;
105 
106  // Slots
108 };
109 
110 /*******************************************************************************
111  * End of File
112  ******************************************************************************/
113 
114 } // namespace editor
115 } // namespace librepcb
116 
117 #endif
void execCmd(UndoCommand *cmd)
Definition: componentsymbolvariantlistmodel.cpp:386
Definition: componentsymbolvariantlistmodel.h:54
ComponentSymbolVariantList * mSymbolVariantList
Definition: componentsymbolvariantlistmodel.h:100
Definition: occmodel.cpp:77
UndoStack * mUndoStack
Definition: componentsymbolvariantlistmodel.h:101
void moveUp(const QPersistentModelIndex &itemIndex) noexcept
Definition: componentsymbolvariantlistmodel.cpp:121
QString mNewName
Definition: componentsymbolvariantlistmodel.h:102
Definition: componentsymbolvariantlistmodel.h:52
void setSymbolVariantList(ComponentSymbolVariantList *list) noexcept
Definition: componentsymbolvariantlistmodel.cpp:60
Column
Definition: componentsymbolvariantlistmodel.h:50
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
Definition: componentsymbolvariantlistmodel.cpp:256
void setUndoStack(UndoStack *stack) noexcept
Definition: componentsymbolvariantlistmodel.cpp:77
ElementName validateNameOrThrow(const QString &name) const
Definition: componentsymbolvariantlistmodel.cpp:395
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
int columnCount(const QModelIndex &parent=QModelIndex()) const override
Definition: componentsymbolvariantlistmodel.cpp:168
void symbolVariantListEdited(const ComponentSymbolVariantList &list, int index, const std::shared_ptr< const ComponentSymbolVariant > &variant, ComponentSymbolVariantList::Event event) noexcept
Definition: componentsymbolvariantlistmodel.cpp:359
Definition: componentsymbolvariantlistmodel.h:56
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
Definition: componentsymbolvariantlistmodel.cpp:299
Definition: componentsymbolvariantlistmodel.h:55
Definition: componentsymbolvariantlistmodel.h:51
QString mNewDescription
Definition: componentsymbolvariantlistmodel.h:103
QString mNewNorm
Definition: componentsymbolvariantlistmodel.h:104
void remove(const QPersistentModelIndex &itemIndex) noexcept
Definition: componentsymbolvariantlistmodel.cpp:106
Definition: componentsymbolvariantlistmodel.h:53
Qt::ItemFlags flags(const QModelIndex &index) const override
Definition: componentsymbolvariantlistmodel.cpp:289
The ComponentSymbolVariant class represents a symbol variant of a component.
Definition: componentsymbolvariant.h:53
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Definition: componentsymbolvariantlistmodel.cpp:161
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Definition: componentsymbolvariantlistmodel.cpp:176
ComponentSymbolVariantList::OnEditedSlot mOnEditedSlot
Definition: componentsymbolvariantlistmodel.h:107
void moveDown(const QPersistentModelIndex &itemIndex) noexcept
Definition: componentsymbolvariantlistmodel.cpp:139
void add(const QPersistentModelIndex &itemIndex) noexcept
Definition: componentsymbolvariantlistmodel.cpp:85
type_safe::constrained_type< QString, ElementNameConstraint, ElementNameVerifier > ElementName
Definition: elementname.h:84
The ComponentSymbolVariantListModel class.
Definition: componentsymbolvariantlistmodel.h:46