LibrePCB Developers Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 "attribute.h"
27 
28 #include <QtCore>
29 
30 /*******************************************************************************
31  * Namespace / Forward Declarations
32  ******************************************************************************/
33 namespace librepcb {
34 
35 class UndoStack;
36 
37 /*******************************************************************************
38  * Class AttributeListModel
39  ******************************************************************************/
40 
44 class AttributeListModel final : public QAbstractTableModel {
45  Q_OBJECT
46 
47 public:
48  enum Column {
55  };
56 
57  // Constructors / Destructor
58  AttributeListModel() = delete;
59  AttributeListModel(const AttributeListModel& other) noexcept;
60  explicit AttributeListModel(QObject* parent = nullptr) noexcept;
61  ~AttributeListModel() noexcept;
62 
63  // Setters
64  void setAttributeList(AttributeList* list) noexcept;
65  void setUndoStack(UndoStack* stack) noexcept;
66 
67  // Slots
68  void addAttribute(const QVariant& editData) noexcept;
69  void removeAttribute(const QVariant& editData) noexcept;
70  void moveAttributeUp(const QVariant& editData) noexcept;
71  void moveAttributeDown(const QVariant& editData) noexcept;
72 
73  // Inherited from QAbstractItemModel
74  int rowCount(const QModelIndex& parent = QModelIndex()) const override;
75  int columnCount(const QModelIndex& parent = QModelIndex()) const override;
76  QVariant data(const QModelIndex& index,
77  int role = Qt::DisplayRole) const override;
78  QVariant headerData(int section, Qt::Orientation orientation,
79  int role = Qt::DisplayRole) const override;
80  Qt::ItemFlags flags(const QModelIndex& index) const override;
81  bool setData(const QModelIndex& index, const QVariant& value,
82  int role = Qt::EditRole) override;
83 
84  // Operator Overloadings
85  AttributeListModel& operator=(const AttributeListModel& rhs) noexcept;
86 
87 private:
88  void attributeListEdited(const AttributeList& list, int index,
89  const std::shared_ptr<const Attribute>& attribute,
90  AttributeList::Event event) noexcept;
91  void execCmd(UndoCommand* cmd);
92  AttributeKey validateKeyOrThrow(const QString& key) const;
93  static QVector<QPair<QString, QVariant>> buildUnitComboBoxData(
94  const AttributeType& type) noexcept;
95 
96 private: // Data
99  QVector<QPair<QString, QVariant>> mTypeComboBoxItems;
100  QString mNewKey;
102  QString mNewValue;
104 
105  // Slots
107 };
108 
109 /*******************************************************************************
110  * End of File
111  ******************************************************************************/
112 
113 } // namespace librepcb
114 
115 #endif // LIBREPCB_ATTRIBUTELISTMODEL_H
AttributeList::OnEditedSlot mOnEditedSlot
Definition: attributelistmodel.h:106
void addAttribute(const QVariant &editData) noexcept
Definition: attributelistmodel.cpp:98
const AttributeUnit * mNewUnit
Definition: attributelistmodel.h:103
Definition: attributelistmodel.h:49
void execCmd(UndoCommand *cmd)
Definition: attributelistmodel.cpp:429
Definition: attributelistmodel.h:54
type_safe::constrained_type< QString, AttributeKeyConstraint, AttributeKeyVerifier > AttributeKey
Definition: attributekey.h:83
void setAttributeList(AttributeList *list) noexcept
Definition: attributelistmodel.cpp:74
The UndoStack class holds UndoCommand objects and provides undo/redo commands.
Definition: undostack.h:107
QString mNewValue
Definition: attributelistmodel.h:102
Definition: attributelistmodel.h:53
UndoStack * mUndoStack
Definition: attributelistmodel.h:98
The AttributeUnit class.
Definition: attributeunit.h:42
void moveAttributeUp(const QVariant &editData) noexcept
Definition: attributelistmodel.cpp:131
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
Definition: attributelistmodel.cpp:324
Column
Definition: attributelistmodel.h:48
QString mNewKey
Definition: attributelistmodel.h:100
QVector< QPair< QString, QVariant > > mTypeComboBoxItems
Definition: attributelistmodel.h:99
static QVector< QPair< QString, QVariant > > buildUnitComboBoxData(const AttributeType &type) noexcept
Definition: attributelistmodel.cpp:448
The AttributeListModel class.
Definition: attributelistmodel.h:44
Definition: attributelistmodel.h:50
The Attribute class.
Definition: attribute.h:49
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
Definition: attributelistmodel.cpp:267
AttributeKey validateKeyOrThrow(const QString &key) const
Definition: attributelistmodel.cpp:438
The UndoCommand class represents a command which you can undo/redo.
Definition: undocommand.h:47
Definition: attributelistmodel.h:51
Definition: attributelistmodel.h:52
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Definition: attributelistmodel.cpp:167
void removeAttribute(const QVariant &editData) noexcept
Definition: attributelistmodel.cpp:117
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Definition: attributelistmodel.cpp:181
void setUndoStack(UndoStack *stack) noexcept
Definition: attributelistmodel.cpp:90
void moveAttributeDown(const QVariant &editData) noexcept
Definition: attributelistmodel.cpp:147
int columnCount(const QModelIndex &parent=QModelIndex()) const override
Definition: attributelistmodel.cpp:174
Qt::ItemFlags flags(const QModelIndex &index) const override
Definition: attributelistmodel.cpp:308
const AttributeType * mNewType
Definition: attributelistmodel.h:101
AttributeList * mAttributeList
Definition: attributelistmodel.h:97
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:404