LibrePCB Developers Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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_COMPONENTSYMBOLVARIANTLISTMODEL_H
21 #define LIBREPCB_LIBRARY_COMPONENTSYMBOLVARIANTLISTMODEL_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
26 #include "componentsymbolvariant.h"
27 
28 #include <QtCore>
29 
30 /*******************************************************************************
31  * Namespace / Forward Declarations
32  ******************************************************************************/
33 namespace librepcb {
34 
35 class UndoStack;
36 
37 namespace library {
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) noexcept;
63  explicit ComponentSymbolVariantListModel(QObject* parent = nullptr) noexcept;
65 
66  // Setters
68  void setUndoStack(UndoStack* stack) noexcept;
69 
70  // Slots
71  void addSymbolVariant(const QVariant& editData) noexcept;
72  void removeSymbolVariant(const QVariant& editData) noexcept;
73  void moveSymbolVariantUp(const QVariant& editData) noexcept;
74  void moveSymbolVariantDown(const QVariant& editData) 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 library
115 } // namespace librepcb
116 
117 #endif // LIBREPCB_LIBRARY_COMPONENTSYMBOLVARIANTLISTMODEL_H
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
Definition: componentsymbolvariantlistmodel.cpp:256
QString mNewName
Definition: componentsymbolvariantlistmodel.h:102
ComponentSymbolVariantList::OnEditedSlot mOnEditedSlot
Definition: componentsymbolvariantlistmodel.h:107
Definition: componentsymbolvariantlistmodel.h:51
Definition: componentsymbolvariantlistmodel.h:52
ComponentSymbolVariantList * mSymbolVariantList
Definition: componentsymbolvariantlistmodel.h:100
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
Definition: componentsymbolvariantlistmodel.cpp:305
Definition: componentsymbolvariantlistmodel.h:55
void setUndoStack(UndoStack *stack) noexcept
Definition: componentsymbolvariantlistmodel.cpp:77
The UndoStack class holds UndoCommand objects and provides undo/redo commands.
Definition: undostack.h:107
Definition: componentsymbolvariantlistmodel.h:54
void execCmd(UndoCommand *cmd)
Definition: componentsymbolvariantlistmodel.cpp:391
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
void moveSymbolVariantDown(const QVariant &editData) noexcept
Definition: componentsymbolvariantlistmodel.cpp:139
Definition: componentsymbolvariantlistmodel.h:56
void removeSymbolVariant(const QVariant &editData) noexcept
Definition: componentsymbolvariantlistmodel.cpp:106
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Definition: componentsymbolvariantlistmodel.cpp:176
QString mNewDescription
Definition: componentsymbolvariantlistmodel.h:103
Qt::ItemFlags flags(const QModelIndex &index) const override
Definition: componentsymbolvariantlistmodel.cpp:295
Definition: componentsymbolvariantlistmodel.h:53
QString mNewNorm
Definition: componentsymbolvariantlistmodel.h:104
void addSymbolVariant(const QVariant &editData) noexcept
Definition: componentsymbolvariantlistmodel.cpp:85
UndoStack * mUndoStack
Definition: componentsymbolvariantlistmodel.h:101
The UndoCommand class represents a command which you can undo/redo.
Definition: undocommand.h:47
ElementName validateNameOrThrow(const QString &name) const
Definition: componentsymbolvariantlistmodel.cpp:400
The ComponentSymbolVariant class represents a symbol variant of a component.
Definition: componentsymbolvariant.h:58
The ComponentSymbolVariantListModel class.
Definition: componentsymbolvariantlistmodel.h:46
void moveSymbolVariantUp(const QVariant &editData) noexcept
Definition: componentsymbolvariantlistmodel.cpp:121
Column
Definition: componentsymbolvariantlistmodel.h:50
void symbolVariantListEdited(const ComponentSymbolVariantList &list, int index, const std::shared_ptr< const ComponentSymbolVariant > &variant, ComponentSymbolVariantList::Event event) noexcept
Definition: componentsymbolvariantlistmodel.cpp:365
type_safe::constrained_type< QString, ElementNameConstraint, ElementNameVerifier > ElementName
Definition: elementname.h:92