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 ******************************************************************************/
35namespace librepcb {
36namespace editor {
37
38class UndoCommand;
39class UndoStack;
40
41/*******************************************************************************
42 * Class AttributeListModel
43 ******************************************************************************/
44
48class AttributeListModel final : public QAbstractTableModel {
49 Q_OBJECT
50
51public:
52 enum Column {
59 };
60
61 // Constructors / Destructor
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
91private:
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
100private: // 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
The Attribute class.
Definition: attribute.h:46
The AttributeType class.
Definition: attributetype.h:42
The AttributeUnit class.
Definition: attributeunit.h:40
The AttributeListModel class.
Definition: attributelistmodel.h:48
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
Definition: attributelistmodel.cpp:265
void attributeListEdited(const AttributeList &list, int index, const std::shared_ptr< const Attribute > &attribute, AttributeList::Event event) noexcept
Definition: attributelistmodel.cpp:393
void execCmd(UndoCommand *cmd)
Definition: attributelistmodel.cpp:419
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Definition: attributelistmodel.cpp:165
void moveDown(const QPersistentModelIndex &itemIndex) noexcept
Definition: attributelistmodel.cpp:144
Qt::ItemFlags flags(const QModelIndex &index) const override
Definition: attributelistmodel.cpp:297
void setAttributeList(AttributeList *list) noexcept
Definition: attributelistmodel.cpp:69
void add(const QPersistentModelIndex &itemIndex) noexcept
Definition: attributelistmodel.cpp:93
const AttributeUnit * mNewUnit
Definition: attributelistmodel.h:107
QString mNewValue
Definition: attributelistmodel.h:106
AttributeListModel(const AttributeListModel &other)=delete
AttributeKey validateKeyOrThrow(const QString &key) const
Definition: attributelistmodel.cpp:428
AttributeList * mAttributeList
Definition: attributelistmodel.h:101
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Definition: attributelistmodel.cpp:179
void setUndoStack(UndoStack *stack) noexcept
Definition: attributelistmodel.cpp:85
void moveUp(const QPersistentModelIndex &itemIndex) noexcept
Definition: attributelistmodel.cpp:127
void remove(const QPersistentModelIndex &itemIndex) noexcept
Definition: attributelistmodel.cpp:112
QString mNewKey
Definition: attributelistmodel.h:104
AttributeList::OnEditedSlot mOnEditedSlot
Definition: attributelistmodel.h:110
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
Definition: attributelistmodel.cpp:313
ComboBoxDelegate::Items mTypeComboBoxItems
Definition: attributelistmodel.h:103
const AttributeType * mNewType
Definition: attributelistmodel.h:105
int columnCount(const QModelIndex &parent=QModelIndex()) const override
Definition: attributelistmodel.cpp:172
UndoStack * mUndoStack
Definition: attributelistmodel.h:102
static ComboBoxDelegate::Items buildUnitComboBoxData(const AttributeType &type) noexcept
Definition: attributelistmodel.cpp:437
Column
Definition: attributelistmodel.h:52
@ COLUMN_TYPE
Definition: attributelistmodel.h:54
@ COLUMN_VALUE
Definition: attributelistmodel.h:55
@ _COLUMN_COUNT
Definition: attributelistmodel.h:58
@ COLUMN_KEY
Definition: attributelistmodel.h:53
@ COLUMN_UNIT
Definition: attributelistmodel.h:56
@ COLUMN_ACTIONS
Definition: attributelistmodel.h:57
Subclass of QStyledItemDelegate which uses QComboBox as item editor.
Definition: comboboxdelegate.h:42
The UndoCommand class represents a command which you can undo/redo.
Definition: undocommand.h:46
The UndoStack class holds UndoCommand objects and provides undo/redo commands.
Definition: undostack.h:106
Definition: occmodel.cpp:77
type_safe::constrained_type< QString, AttributeKeyConstraint, AttributeKeyVerifier > AttributeKey
Definition: attributekey.h:84