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