LibrePCB Developers Documentation
componentsymbolvariantitemlistmodel.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_COMPONENTSYMBOLVARIANTITEMLISTMODEL_H
21 #define LIBREPCB_LIBRARY_EDITOR_COMPONENTSYMBOLVARIANTITEMLISTMODEL_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 class LibraryElementCache;
41 
42 /*******************************************************************************
43  * Class ComponentSymbolVariantItemListModel
44  ******************************************************************************/
45 
49 class ComponentSymbolVariantItemListModel final : public QAbstractTableModel {
50  Q_OBJECT
51 
52 public:
53  enum Column {
63  };
64 
65  // Constructors / Destructor
68  const ComponentSymbolVariantItemListModel& other) noexcept;
70  QObject* parent = nullptr) noexcept;
72 
73  // Setters
74  void setItemList(ComponentSymbolVariantItemList* list) noexcept;
75  void setSymbolsCache(
76  const std::shared_ptr<const LibraryElementCache>& cache) noexcept;
77  void setUndoStack(UndoStack* stack) noexcept;
78 
79  // Slots
80  void addItem(const QVariant& editData) noexcept;
81  void removeItem(const QVariant& editData) noexcept;
82  void moveItemUp(const QVariant& editData) noexcept;
83  void moveItemDown(const QVariant& editData) noexcept;
84  void changeSymbol(const QVariant& editData, const Uuid& symbol) noexcept;
85 
86  // Inherited from QAbstractItemModel
87  int rowCount(const QModelIndex& parent = QModelIndex()) const override;
88  int columnCount(const QModelIndex& parent = QModelIndex()) const override;
89  QVariant data(const QModelIndex& index,
90  int role = Qt::DisplayRole) const override;
91  QVariant headerData(int section, Qt::Orientation orientation,
92  int role = Qt::DisplayRole) const override;
93  Qt::ItemFlags flags(const QModelIndex& index) const override;
94  bool setData(const QModelIndex& index, const QVariant& value,
95  int role = Qt::EditRole) override;
96 
97  // Operator Overloadings
99  const ComponentSymbolVariantItemListModel& rhs) noexcept;
100 
101 private:
102  void itemListEdited(
103  const ComponentSymbolVariantItemList& list, int index,
104  const std::shared_ptr<const ComponentSymbolVariantItem>& item,
105  ComponentSymbolVariantItemList::Event event) noexcept;
106  void execCmd(UndoCommand* cmd);
107 
108 private: // Data
110  std::shared_ptr<const LibraryElementCache> mSymbolsCache;
112  tl::optional<Uuid> mNewSymbolUuid;
113  QString mNewSuffix;
117 
118  // Slots
120 };
121 
122 /*******************************************************************************
123  * End of File
124  ******************************************************************************/
125 
126 } // namespace editor
127 } // namespace library
128 } // namespace librepcb
129 
130 #endif
void execCmd(UndoCommand *cmd)
Definition: componentsymbolvariantitemlistmodel.cpp:507
ComponentSymbolVariantItemList * mItemList
Definition: componentsymbolvariantitemlistmodel.h:109
std::shared_ptr< const LibraryElementCache > mSymbolsCache
Definition: componentsymbolvariantitemlistmodel.h:110
Definition: componentsymbolvariantitemlistmodel.h:54
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
Definition: componentsymbolvariantitemlistmodel.cpp:411
ComponentSymbolVariantItemList::OnEditedSlot mOnEditedSlot
Definition: componentsymbolvariantitemlistmodel.h:119
Definition: airwiresbuilder.cpp:32
int columnCount(const QModelIndex &parent=QModelIndex()) const override
Definition: componentsymbolvariantitemlistmodel.cpp:225
Definition: componentsymbolvariantitemlistmodel.h:56
void moveItemUp(const QVariant &editData) noexcept
Definition: componentsymbolvariantitemlistmodel.cpp:144
void setSymbolsCache(const std::shared_ptr< const LibraryElementCache > &cache) noexcept
Definition: componentsymbolvariantitemlistmodel.cpp:80
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
Definition: componentsymbolvariantitemlistmodel.cpp:354
Angle mNewRotation
Definition: componentsymbolvariantitemlistmodel.h:116
The Angle class is used to represent an angle (for example 12.75 degrees)
Definition: angle.h:78
Definition: componentsymbolvariantitemlistmodel.h:59
void addItem(const QVariant &editData) noexcept
Definition: componentsymbolvariantitemlistmodel.cpp:96
Qt::ItemFlags flags(const QModelIndex &index) const override
Definition: componentsymbolvariantitemlistmodel.cpp:399
The UndoStack class holds UndoCommand objects and provides undo/redo commands.
Definition: undostack.h:107
Definition: componentsymbolvariantitemlistmodel.h:61
UndoStack * mUndoStack
Definition: componentsymbolvariantitemlistmodel.h:111
void removeItem(const QVariant &editData) noexcept
Definition: componentsymbolvariantitemlistmodel.cpp:129
void changeSymbol(const QVariant &editData, const Uuid &symbol) noexcept
Definition: componentsymbolvariantitemlistmodel.cpp:180
void moveItemDown(const QVariant &editData) noexcept
Definition: componentsymbolvariantitemlistmodel.cpp:162
The Point class is used to represent a point/coordinate/vector, for example (1.2mm; 5...
Definition: point.h:78
void itemListEdited(const ComponentSymbolVariantItemList &list, int index, const std::shared_ptr< const ComponentSymbolVariantItem > &item, ComponentSymbolVariantItemList::Event event) noexcept
Definition: componentsymbolvariantitemlistmodel.cpp:482
void setItemList(ComponentSymbolVariantItemList *list) noexcept
Definition: componentsymbolvariantitemlistmodel.cpp:67
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Definition: componentsymbolvariantitemlistmodel.cpp:233
Point mNewPosition
Definition: componentsymbolvariantitemlistmodel.h:115
void setUndoStack(UndoStack *stack) noexcept
Definition: componentsymbolvariantitemlistmodel.cpp:87
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Definition: componentsymbolvariantitemlistmodel.cpp:217
Definition: componentsymbolvariantitemlistmodel.h:55
The UndoCommand class represents a command which you can undo/redo.
Definition: undocommand.h:47
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:58
QString mNewSuffix
Definition: componentsymbolvariantitemlistmodel.h:113
Definition: componentsymbolvariantitemlistmodel.h:58
The ComponentSymbolVariantItem class represents one symbol of a component symbol variant.
Definition: componentsymbolvariantitem.h:58
bool mNewIsRequired
Definition: componentsymbolvariantitemlistmodel.h:114
tl::optional< Uuid > mNewSymbolUuid
Definition: componentsymbolvariantitemlistmodel.h:112
Definition: componentsymbolvariantitemlistmodel.h:62
Column
Definition: componentsymbolvariantitemlistmodel.h:53
Cache for fast access to library elements.
Definition: libraryelementcache.h:60
The ComponentSymbolVariantItemListModel class.
Definition: componentsymbolvariantitemlistmodel.h:49