LibrePCB Developers Documentation
attributelistmodel.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_ATTRIBUTELISTMODEL_H
21 #define LIBREPCB_EDITOR_ATTRIBUTELISTMODEL_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
26 #include "../modelview/comboboxdelegate.h"
27 
29 
30 #include <QtCore>
31 
32 /*******************************************************************************
33  * Namespace / Forward Declarations
34  ******************************************************************************/
35 namespace librepcb {
36 namespace editor {
37 
38 class UndoCommand;
39 class UndoStack;
40 
41 /*******************************************************************************
42  * Class AttributeListModel
43  ******************************************************************************/
44 
48 class AttributeListModel final : public QAbstractTableModel {
49  Q_OBJECT
50 
51 public:
52  enum Column {
59  };
60 
61  // Constructors / Destructor
62  AttributeListModel() = delete;
63  AttributeListModel(const AttributeListModel& other) = delete;
64  explicit AttributeListModel(QObject* parent = nullptr) noexcept;
65  ~AttributeListModel() noexcept;
66 
67  // Setters
68  void setAttributeList(AttributeList* list) noexcept;
69  void setUndoStack(UndoStack* stack) noexcept;
70 
71  // Slots
72  void add(const QPersistentModelIndex& itemIndex) noexcept;
73  void remove(const QPersistentModelIndex& itemIndex) noexcept;
74  void moveUp(const QPersistentModelIndex& itemIndex) noexcept;
75  void moveDown(const QPersistentModelIndex& itemIndex) 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
89  AttributeListModel& operator=(const AttributeListModel& rhs) noexcept;
90 
91 private:
92  void attributeListEdited(const AttributeList& list, int index,
93  const std::shared_ptr<const Attribute>& attribute,
94  AttributeList::Event event) noexcept;
95  void execCmd(UndoCommand* cmd);
96  AttributeKey validateKeyOrThrow(const QString& key) const;
98  const AttributeType& type) noexcept;
99 
100 private: // Data
104  QString mNewKey;
106  QString mNewValue;
108 
109  // Slots
111 };
112 
113 /*******************************************************************************
114  * End of File
115  ******************************************************************************/
116 
117 } // namespace editor
118 } // namespace librepcb
119 
120 #endif
int columnCount(const QModelIndex &parent=QModelIndex()) const override
Definition: attributelistmodel.cpp:172
Definition: attributelistmodel.h:57
Definition: attributelistmodel.h:58
Column
Definition: attributelistmodel.h:52
The AttributeListModel class.
Definition: attributelistmodel.h:48
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Definition: attributelistmodel.cpp:179
Definition: attributelistmodel.h:53
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
Definition: attributelistmodel.cpp:313
Definition: occmodel.cpp:77
void attributeListEdited(const AttributeList &list, int index, const std::shared_ptr< const Attribute > &attribute, AttributeList::Event event) noexcept
Definition: attributelistmodel.cpp:393
type_safe::constrained_type< QString, AttributeKeyConstraint, AttributeKeyVerifier > AttributeKey
Definition: attributekey.h:84
Definition: attributelistmodel.h:55
QString mNewValue
Definition: attributelistmodel.h:106
AttributeList * mAttributeList
Definition: attributelistmodel.h:101
void setUndoStack(UndoStack *stack) noexcept
Definition: attributelistmodel.cpp:85
static ComboBoxDelegate::Items buildUnitComboBoxData(const AttributeType &type) noexcept
Definition: attributelistmodel.cpp:437
AttributeKey validateKeyOrThrow(const QString &key) const
Definition: attributelistmodel.cpp:428
The AttributeUnit class.
Definition: attributeunit.h:40
QString mNewKey
Definition: attributelistmodel.h:104
The UndoStack class holds UndoCommand objects and provides undo/redo commands.
Definition: undostack.h:106
Definition: attributelistmodel.h:54
The UndoCommand class represents a command which you can undo/redo.
Definition: undocommand.h:46
Definition: attributelistmodel.h:56
Subclass of QStyledItemDelegate which uses QComboBox as item editor.
Definition: comboboxdelegate.h:42
AttributeList::OnEditedSlot mOnEditedSlot
Definition: attributelistmodel.h:110
void remove(const QPersistentModelIndex &itemIndex) noexcept
Definition: attributelistmodel.cpp:112
UndoStack * mUndoStack
Definition: attributelistmodel.h:102
void moveUp(const QPersistentModelIndex &itemIndex) noexcept
Definition: attributelistmodel.cpp:127
The Attribute class.
Definition: attribute.h:46
void execCmd(UndoCommand *cmd)
Definition: attributelistmodel.cpp:419
void moveDown(const QPersistentModelIndex &itemIndex) noexcept
Definition: attributelistmodel.cpp:144
Qt::ItemFlags flags(const QModelIndex &index) const override
Definition: attributelistmodel.cpp:297
const AttributeUnit * mNewUnit
Definition: attributelistmodel.h:107
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
Definition: attributelistmodel.cpp:265
void setAttributeList(AttributeList *list) noexcept
Definition: attributelistmodel.cpp:69
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Definition: attributelistmodel.cpp:165
void add(const QPersistentModelIndex &itemIndex) noexcept
Definition: attributelistmodel.cpp:93
ComboBoxDelegate::Items mTypeComboBoxItems
Definition: attributelistmodel.h:103
The AttributeType class.
Definition: attributetype.h:42
const AttributeType * mNewType
Definition: attributelistmodel.h:105