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_EDITOR_COMPONENTSYMBOLVARIANTITEMLISTMODEL_H
21 #define LIBREPCB_EDITOR_COMPONENTSYMBOLVARIANTITEMLISTMODEL_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 LibraryElementCache;
37 class UndoCommand;
38 class UndoStack;
39 
40 /*******************************************************************************
41  * Class ComponentSymbolVariantItemListModel
42  ******************************************************************************/
43 
47 class ComponentSymbolVariantItemListModel final : public QAbstractTableModel {
48  Q_OBJECT
49 
50 public:
51  enum Column {
60  };
61 
62  // Constructors / Destructor
65  const ComponentSymbolVariantItemListModel& other) = delete;
67  QObject* parent = nullptr) noexcept;
69 
70  // Setters
71  void setItemList(ComponentSymbolVariantItemList* list) noexcept;
72  void setSymbolsCache(
73  const std::shared_ptr<const LibraryElementCache>& cache) noexcept;
74  void setUndoStack(UndoStack* stack) noexcept;
75 
76  // Slots
77  void add(const QPersistentModelIndex& itemIndex) noexcept;
78  void remove(const QPersistentModelIndex& itemIndex) noexcept;
79  void moveUp(const QPersistentModelIndex& itemIndex) noexcept;
80  void moveDown(const QPersistentModelIndex& itemIndex) noexcept;
81  void browse(const QPersistentModelIndex& itemIndex,
82  const Uuid& symbol) noexcept;
83 
84  // Inherited from QAbstractItemModel
85  int rowCount(const QModelIndex& parent = QModelIndex()) const override;
86  int columnCount(const QModelIndex& parent = QModelIndex()) const override;
87  QVariant data(const QModelIndex& index,
88  int role = Qt::DisplayRole) const override;
89  QVariant headerData(int section, Qt::Orientation orientation,
90  int role = Qt::DisplayRole) const override;
91  Qt::ItemFlags flags(const QModelIndex& index) const override;
92  bool setData(const QModelIndex& index, const QVariant& value,
93  int role = Qt::EditRole) override;
94 
95  // Operator Overloadings
97  const ComponentSymbolVariantItemListModel& rhs) noexcept;
98 
99 private:
100  void itemListEdited(
101  const ComponentSymbolVariantItemList& list, int index,
102  const std::shared_ptr<const ComponentSymbolVariantItem>& item,
103  ComponentSymbolVariantItemList::Event event) noexcept;
104  void execCmd(UndoCommand* cmd);
105 
106 private: // Data
108  std::shared_ptr<const LibraryElementCache> mSymbolsCache;
110  tl::optional<Uuid> mNewSymbolUuid;
111  QString mNewSuffix;
115 
116  // Slots
118 };
119 
120 /*******************************************************************************
121  * End of File
122  ******************************************************************************/
123 
124 } // namespace editor
125 } // namespace librepcb
126 
127 #endif
Definition: componentsymbolvariantitemlistmodel.h:55
void remove(const QPersistentModelIndex &itemIndex) noexcept
Definition: componentsymbolvariantitemlistmodel.cpp:128
Definition: componentsymbolvariantitemlistmodel.h:58
int columnCount(const QModelIndex &parent=QModelIndex()) const override
Definition: componentsymbolvariantitemlistmodel.cpp:224
Definition: componentsymbolvariantitemlistmodel.h:53
Definition: componentsymbolvariantitemlistmodel.h:56
void itemListEdited(const ComponentSymbolVariantItemList &list, int index, const std::shared_ptr< const ComponentSymbolVariantItem > &item, ComponentSymbolVariantItemList::Event event) noexcept
Definition: componentsymbolvariantitemlistmodel.cpp:465
Definition: componentsymbolvariantitemlistmodel.h:52
Definition: occmodel.cpp:77
void add(const QPersistentModelIndex &itemIndex) noexcept
Definition: componentsymbolvariantitemlistmodel.cpp:96
Cache for fast access to library elements.
Definition: libraryelementcache.h:55
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
Definition: componentsymbolvariantitemlistmodel.cpp:394
The Angle class is used to represent an angle (for example 12.75 degrees)
Definition: angle.h:78
Qt::ItemFlags flags(const QModelIndex &index) const override
Definition: componentsymbolvariantitemlistmodel.cpp:382
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Definition: componentsymbolvariantitemlistmodel.cpp:216
void execCmd(UndoCommand *cmd)
Definition: componentsymbolvariantitemlistmodel.cpp:491
void moveDown(const QPersistentModelIndex &itemIndex) noexcept
Definition: componentsymbolvariantitemlistmodel.cpp:161
The ComponentSymbolVariantItem class represents one symbol of a component symbol variant.
Definition: componentsymbolvariantitem.h:54
void browse(const QPersistentModelIndex &itemIndex, const Uuid &symbol) noexcept
Definition: componentsymbolvariantitemlistmodel.cpp:179
void moveUp(const QPersistentModelIndex &itemIndex) noexcept
Definition: componentsymbolvariantitemlistmodel.cpp:143
Definition: componentsymbolvariantitemlistmodel.h:59
Definition: componentsymbolvariantitemlistmodel.h:57
The UndoStack class holds UndoCommand objects and provides undo/redo commands.
Definition: undostack.h:106
The Point class is used to represent a point/coordinate/vector, for example (1.2mm; 5...
Definition: point.h:79
The UndoCommand class represents a command which you can undo/redo.
Definition: undocommand.h:46
Column
Definition: componentsymbolvariantitemlistmodel.h:51
UndoStack * mUndoStack
Definition: componentsymbolvariantitemlistmodel.h:109
Angle mNewRotation
Definition: componentsymbolvariantitemlistmodel.h:114
Point mNewPosition
Definition: componentsymbolvariantitemlistmodel.h:113
ComponentSymbolVariantItemList::OnEditedSlot mOnEditedSlot
Definition: componentsymbolvariantitemlistmodel.h:117
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:345
bool mNewIsRequired
Definition: componentsymbolvariantitemlistmodel.h:112
std::shared_ptr< const LibraryElementCache > mSymbolsCache
Definition: componentsymbolvariantitemlistmodel.h:108
QString mNewSuffix
Definition: componentsymbolvariantitemlistmodel.h:111
void setUndoStack(UndoStack *stack) noexcept
Definition: componentsymbolvariantitemlistmodel.cpp:87
Definition: uuid.h:183
void setItemList(ComponentSymbolVariantItemList *list) noexcept
Definition: componentsymbolvariantitemlistmodel.cpp:67
The ComponentSymbolVariantItemListModel class.
Definition: componentsymbolvariantitemlistmodel.h:47
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Definition: componentsymbolvariantitemlistmodel.cpp:232
ComponentSymbolVariantItemList * mItemList
Definition: componentsymbolvariantitemlistmodel.h:107
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:58
Definition: componentsymbolvariantitemlistmodel.h:54
tl::optional< Uuid > mNewSymbolUuid
Definition: componentsymbolvariantitemlistmodel.h:110