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_LIBRARY_EDITOR_COMPONENTSYMBOLVARIANTLISTMODEL_H
21 #define LIBREPCB_LIBRARY_EDITOR_COMPONENTSYMBOLVARIANTLISTMODEL_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
27 
28 #include <QtCore>
29 
30 /*******************************************************************************
31  * Namespace / Forward Declarations
32  ******************************************************************************/
33 namespace librepcb {
34 
35 class UndoStack;
36 
37 namespace library {
38 namespace editor {
39 
40 /*******************************************************************************
41  * Class ComponentSymbolVariantListModel
42  ******************************************************************************/
43 
47 class ComponentSymbolVariantListModel final : public QAbstractTableModel {
48  Q_OBJECT
49 
50 public:
51  enum Column {
58  };
59 
60  // Constructors / Destructor
63  const ComponentSymbolVariantListModel& other) noexcept;
64  explicit ComponentSymbolVariantListModel(QObject* parent = nullptr) noexcept;
66 
67  // Setters
69  void setUndoStack(UndoStack* stack) noexcept;
70 
71  // Slots
72  void addSymbolVariant(const QVariant& editData) noexcept;
73  void removeSymbolVariant(const QVariant& editData) noexcept;
74  void moveSymbolVariantUp(const QVariant& editData) noexcept;
75  void moveSymbolVariantDown(const QVariant& editData) noexcept;
76 
77  // Inherited from QAbstractItemModel
78  int rowCount(const QModelIndex& parent = QModelIndex()) const override;
79  int columnCount(const QModelIndex& parent = QModelIndex()) const override;
80  QVariant data(const QModelIndex& index,
81  int role = Qt::DisplayRole) const override;
82  QVariant headerData(int section, Qt::Orientation orientation,
83  int role = Qt::DisplayRole) const override;
84  Qt::ItemFlags flags(const QModelIndex& index) const override;
85  bool setData(const QModelIndex& index, const QVariant& value,
86  int role = Qt::EditRole) override;
87 
88  // Operator Overloadings
90  const ComponentSymbolVariantListModel& rhs) noexcept;
91 
92 private:
94  const ComponentSymbolVariantList& list, int index,
95  const std::shared_ptr<const ComponentSymbolVariant>& variant,
96  ComponentSymbolVariantList::Event event) noexcept;
97  void execCmd(UndoCommand* cmd);
98  ElementName validateNameOrThrow(const QString& name) const;
99 
100 private: // Data
103  QString mNewName;
105  QString mNewNorm;
106 
107  // Slots
109 };
110 
111 /*******************************************************************************
112  * End of File
113  ******************************************************************************/
114 
115 } // namespace editor
116 } // namespace library
117 } // namespace librepcb
118 
119 #endif
void moveSymbolVariantUp(const QVariant &editData) noexcept
Definition: componentsymbolvariantlistmodel.cpp:121
void symbolVariantListEdited(const ComponentSymbolVariantList &list, int index, const std::shared_ptr< const ComponentSymbolVariant > &variant, ComponentSymbolVariantList::Event event) noexcept
Definition: componentsymbolvariantlistmodel.cpp:365
QString mNewNorm
Definition: componentsymbolvariantlistmodel.h:105
void addSymbolVariant(const QVariant &editData) noexcept
Definition: componentsymbolvariantlistmodel.cpp:85
Definition: airwiresbuilder.cpp:32
void execCmd(UndoCommand *cmd)
Definition: componentsymbolvariantlistmodel.cpp:391
Definition: componentsymbolvariantlistmodel.h:52
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Definition: componentsymbolvariantlistmodel.cpp:176
The UndoStack class holds UndoCommand objects and provides undo/redo commands.
Definition: undostack.h:107
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
Definition: componentsymbolvariantlistmodel.cpp:305
ComponentSymbolVariantList * mSymbolVariantList
Definition: componentsymbolvariantlistmodel.h:101
UndoStack * mUndoStack
Definition: componentsymbolvariantlistmodel.h:102
Column
Definition: componentsymbolvariantlistmodel.h:51
The ComponentSymbolVariantListModel class.
Definition: componentsymbolvariantlistmodel.h:47
void moveSymbolVariantDown(const QVariant &editData) noexcept
Definition: componentsymbolvariantlistmodel.cpp:139
ComponentSymbolVariantList::OnEditedSlot mOnEditedSlot
Definition: componentsymbolvariantlistmodel.h:108
The UndoCommand class represents a command which you can undo/redo.
Definition: undocommand.h:47
QString mNewName
Definition: componentsymbolvariantlistmodel.h:103
ElementName validateNameOrThrow(const QString &name) const
Definition: componentsymbolvariantlistmodel.cpp:400
void setUndoStack(UndoStack *stack) noexcept
Definition: componentsymbolvariantlistmodel.cpp:77
The ComponentSymbolVariant class represents a symbol variant of a component.
Definition: componentsymbolvariant.h:58
Definition: componentsymbolvariantlistmodel.h:54
int columnCount(const QModelIndex &parent=QModelIndex()) const override
Definition: componentsymbolvariantlistmodel.cpp:168
void setSymbolVariantList(ComponentSymbolVariantList *list) noexcept
Definition: componentsymbolvariantlistmodel.cpp:60
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Definition: componentsymbolvariantlistmodel.cpp:161
QString mNewDescription
Definition: componentsymbolvariantlistmodel.h:104
void removeSymbolVariant(const QVariant &editData) noexcept
Definition: componentsymbolvariantlistmodel.cpp:106
Qt::ItemFlags flags(const QModelIndex &index) const override
Definition: componentsymbolvariantlistmodel.cpp:295
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
Definition: componentsymbolvariantlistmodel.cpp:256
type_safe::constrained_type< QString, ElementNameConstraint, ElementNameVerifier > ElementName
Definition: elementname.h:92