LibrePCB Developers Documentation
componentsymbolvariantlistmodel.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_COMPONENTSYMBOLVARIANTLISTMODEL_H
21#define LIBREPCB_EDITOR_COMPONENTSYMBOLVARIANTLISTMODEL_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
27
28#include <QtCore>
29
30/*******************************************************************************
31 * Namespace / Forward Declarations
32 ******************************************************************************/
33namespace librepcb {
34namespace editor {
35
36class UndoCommand;
37class UndoStack;
38
39/*******************************************************************************
40 * Class ComponentSymbolVariantListModel
41 ******************************************************************************/
42
46class ComponentSymbolVariantListModel final : public QAbstractTableModel {
47 Q_OBJECT
48
49public:
50 enum Column {
57 };
58
59 // Constructors / Destructor
62 const ComponentSymbolVariantListModel& other) = delete;
63 explicit ComponentSymbolVariantListModel(QObject* parent = nullptr) noexcept;
65
66 // Setters
68 void setUndoStack(UndoStack* stack) noexcept;
69
70 // Slots
71 void add(const QPersistentModelIndex& itemIndex) noexcept;
72 void remove(const QPersistentModelIndex& itemIndex) noexcept;
73 void moveUp(const QPersistentModelIndex& itemIndex) noexcept;
74 void moveDown(const QPersistentModelIndex& itemIndex) noexcept;
75
76 // Inherited from QAbstractItemModel
77 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
78 int columnCount(const QModelIndex& parent = QModelIndex()) const override;
79 QVariant data(const QModelIndex& index,
80 int role = Qt::DisplayRole) const override;
81 QVariant headerData(int section, Qt::Orientation orientation,
82 int role = Qt::DisplayRole) const override;
83 Qt::ItemFlags flags(const QModelIndex& index) const override;
84 bool setData(const QModelIndex& index, const QVariant& value,
85 int role = Qt::EditRole) override;
86
87 // Operator Overloadings
89 const ComponentSymbolVariantListModel& rhs) noexcept;
90
91private:
93 const ComponentSymbolVariantList& list, int index,
94 const std::shared_ptr<const ComponentSymbolVariant>& variant,
95 ComponentSymbolVariantList::Event event) noexcept;
96 void execCmd(UndoCommand* cmd);
97 ElementName validateNameOrThrow(const QString& name) const;
98
99private: // Data
102 QString mNewName;
104 QString mNewNorm;
105
106 // Slots
108};
109
110/*******************************************************************************
111 * End of File
112 ******************************************************************************/
113
114} // namespace editor
115} // namespace librepcb
116
117#endif
The ComponentSymbolVariant class represents a symbol variant of a component.
Definition: componentsymbolvariant.h:53
The ComponentSymbolVariantListModel class.
Definition: componentsymbolvariantlistmodel.h:46
void setSymbolVariantList(ComponentSymbolVariantList *list) noexcept
Definition: componentsymbolvariantlistmodel.cpp:60
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
Definition: componentsymbolvariantlistmodel.cpp:256
QString mNewName
Definition: componentsymbolvariantlistmodel.h:102
void execCmd(UndoCommand *cmd)
Definition: componentsymbolvariantlistmodel.cpp:386
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Definition: componentsymbolvariantlistmodel.cpp:161
ComponentSymbolVariantListModel(const ComponentSymbolVariantListModel &other)=delete
void moveDown(const QPersistentModelIndex &itemIndex) noexcept
Definition: componentsymbolvariantlistmodel.cpp:139
Qt::ItemFlags flags(const QModelIndex &index) const override
Definition: componentsymbolvariantlistmodel.cpp:289
void add(const QPersistentModelIndex &itemIndex) noexcept
Definition: componentsymbolvariantlistmodel.cpp:85
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Definition: componentsymbolvariantlistmodel.cpp:176
void setUndoStack(UndoStack *stack) noexcept
Definition: componentsymbolvariantlistmodel.cpp:77
void moveUp(const QPersistentModelIndex &itemIndex) noexcept
Definition: componentsymbolvariantlistmodel.cpp:121
void remove(const QPersistentModelIndex &itemIndex) noexcept
Definition: componentsymbolvariantlistmodel.cpp:106
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
Definition: componentsymbolvariantlistmodel.cpp:299
ElementName validateNameOrThrow(const QString &name) const
Definition: componentsymbolvariantlistmodel.cpp:395
ComponentSymbolVariantList * mSymbolVariantList
Definition: componentsymbolvariantlistmodel.h:100
QString mNewNorm
Definition: componentsymbolvariantlistmodel.h:104
int columnCount(const QModelIndex &parent=QModelIndex()) const override
Definition: componentsymbolvariantlistmodel.cpp:168
UndoStack * mUndoStack
Definition: componentsymbolvariantlistmodel.h:101
QString mNewDescription
Definition: componentsymbolvariantlistmodel.h:103
void symbolVariantListEdited(const ComponentSymbolVariantList &list, int index, const std::shared_ptr< const ComponentSymbolVariant > &variant, ComponentSymbolVariantList::Event event) noexcept
Definition: componentsymbolvariantlistmodel.cpp:359
Column
Definition: componentsymbolvariantlistmodel.h:50
@ _COLUMN_COUNT
Definition: componentsymbolvariantlistmodel.h:56
@ COLUMN_NORM
Definition: componentsymbolvariantlistmodel.h:53
@ COLUMN_DESCRIPTION
Definition: componentsymbolvariantlistmodel.h:52
@ COLUMN_NAME
Definition: componentsymbolvariantlistmodel.h:51
@ COLUMN_SYMBOLCOUNT
Definition: componentsymbolvariantlistmodel.h:54
@ COLUMN_ACTIONS
Definition: componentsymbolvariantlistmodel.h:55
ComponentSymbolVariantList::OnEditedSlot mOnEditedSlot
Definition: componentsymbolvariantlistmodel.h:107
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, ElementNameConstraint, ElementNameVerifier > ElementName
Definition: elementname.h:84