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_ATTRIBUTELISTMODEL_H
21 #define LIBREPCB_ATTRIBUTELISTMODEL_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
26 #include "../model/comboboxdelegate.h"
27 #include "attribute.h"
28 
29 #include <QtCore>
30 
31 /*******************************************************************************
32  * Namespace / Forward Declarations
33  ******************************************************************************/
34 namespace librepcb {
35 
36 class UndoStack;
37 
38 /*******************************************************************************
39  * Class AttributeListModel
40  ******************************************************************************/
41 
45 class AttributeListModel final : public QAbstractTableModel {
46  Q_OBJECT
47 
48 public:
49  enum Column {
56  };
57 
58  // Constructors / Destructor
59  AttributeListModel() = delete;
60  AttributeListModel(const AttributeListModel& other) noexcept;
61  explicit AttributeListModel(QObject* parent = nullptr) noexcept;
62  ~AttributeListModel() noexcept;
63 
64  // Setters
65  void setAttributeList(AttributeList* list) noexcept;
66  void setUndoStack(UndoStack* stack) noexcept;
67 
68  // Slots
69  void addAttribute(const QVariant& editData) noexcept;
70  void removeAttribute(const QVariant& editData) noexcept;
71  void moveAttributeUp(const QVariant& editData) noexcept;
72  void moveAttributeDown(const QVariant& editData) noexcept;
73 
74  // Inherited from QAbstractItemModel
75  int rowCount(const QModelIndex& parent = QModelIndex()) const override;
76  int columnCount(const QModelIndex& parent = QModelIndex()) const override;
77  QVariant data(const QModelIndex& index,
78  int role = Qt::DisplayRole) const override;
79  QVariant headerData(int section, Qt::Orientation orientation,
80  int role = Qt::DisplayRole) const override;
81  Qt::ItemFlags flags(const QModelIndex& index) const override;
82  bool setData(const QModelIndex& index, const QVariant& value,
83  int role = Qt::EditRole) override;
84 
85  // Operator Overloadings
86  AttributeListModel& operator=(const AttributeListModel& rhs) noexcept;
87 
88 private:
89  void attributeListEdited(const AttributeList& list, int index,
90  const std::shared_ptr<const Attribute>& attribute,
91  AttributeList::Event event) noexcept;
92  void execCmd(UndoCommand* cmd);
93  AttributeKey validateKeyOrThrow(const QString& key) const;
95  const AttributeType& type) noexcept;
96 
97 private: // Data
101  QString mNewKey;
103  QString mNewValue;
105 
106  // Slots
108 };
109 
110 /*******************************************************************************
111  * End of File
112  ******************************************************************************/
113 
114 } // namespace librepcb
115 
116 #endif // LIBREPCB_ATTRIBUTELISTMODEL_H
AttributeList::OnEditedSlot mOnEditedSlot
Definition: attributelistmodel.h:107
void addAttribute(const QVariant &editData) noexcept
Definition: attributelistmodel.cpp:92
const AttributeUnit * mNewUnit
Definition: attributelistmodel.h:104
Definition: attributelistmodel.h:50
void execCmd(UndoCommand *cmd)
Definition: attributelistmodel.cpp:423
Definition: attributelistmodel.h:55
Subclass of QStyledItemDelegate which uses QComboBox as item editor.
Definition: comboboxdelegate.h:43
Definition: airwiresbuilder.cpp:32
type_safe::constrained_type< QString, AttributeKeyConstraint, AttributeKeyVerifier > AttributeKey
Definition: attributekey.h:83
void setAttributeList(AttributeList *list) noexcept
Definition: attributelistmodel.cpp:68
The UndoStack class holds UndoCommand objects and provides undo/redo commands.
Definition: undostack.h:107
QString mNewValue
Definition: attributelistmodel.h:103
Definition: attributelistmodel.h:54
UndoStack * mUndoStack
Definition: attributelistmodel.h:99
The AttributeUnit class.
Definition: attributeunit.h:42
AttributeKey validateKeyOrThrow(const QString &key) const
Definition: attributelistmodel.cpp:432
void moveAttributeUp(const QVariant &editData) noexcept
Definition: attributelistmodel.cpp:125
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
Definition: attributelistmodel.cpp:318
Column
Definition: attributelistmodel.h:49
QString mNewKey
Definition: attributelistmodel.h:101
The AttributeListModel class.
Definition: attributelistmodel.h:45
Definition: attributelistmodel.h:51
ComboBoxDelegate::Items mTypeComboBoxItems
Definition: attributelistmodel.h:100
The Attribute class.
Definition: attribute.h:49
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
Definition: attributelistmodel.cpp:261
The UndoCommand class represents a command which you can undo/redo.
Definition: undocommand.h:47
Definition: attributelistmodel.h:52
Definition: attributelistmodel.h:53
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Definition: attributelistmodel.cpp:161
static ComboBoxDelegate::Items buildUnitComboBoxData(const AttributeType &type) noexcept
Definition: attributelistmodel.cpp:442
void removeAttribute(const QVariant &editData) noexcept
Definition: attributelistmodel.cpp:111
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Definition: attributelistmodel.cpp:175
void setUndoStack(UndoStack *stack) noexcept
Definition: attributelistmodel.cpp:84
void moveAttributeDown(const QVariant &editData) noexcept
Definition: attributelistmodel.cpp:141
int columnCount(const QModelIndex &parent=QModelIndex()) const override
Definition: attributelistmodel.cpp:168
Qt::ItemFlags flags(const QModelIndex &index) const override
Definition: attributelistmodel.cpp:302
const AttributeType * mNewType
Definition: attributelistmodel.h:102
AttributeList * mAttributeList
Definition: attributelistmodel.h:98
The AttributeType class.
Definition: attributetype.h:44
void attributeListEdited(const AttributeList &list, int index, const std::shared_ptr< const Attribute > &attribute, AttributeList::Event event) noexcept
Definition: attributelistmodel.cpp:398