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_LIBRARY_EDITOR_PACKAGEPADLISTMODEL_H 21 #define LIBREPCB_LIBRARY_EDITOR_PACKAGEPADLISTMODEL_H 22 23 /******************************************************************************* 24 * Includes 25 ******************************************************************************/ 26 #include <librepcb/library/pkg/packagepad.h> 27 28 #include <QtCore> 29 30 /******************************************************************************* 31 * Namespace / Forward Declarations 32 ******************************************************************************/ 33 namespace librepcb { 34 35 class UndoStack; 36 37 namespace library { 38 namespace editor { 39 40 /******************************************************************************* 41 * Class PackagePadListModel 42 ******************************************************************************/ 43 44 /** 45 * @brief The PackagePadListModel class 46 */ 47 class PackagePadListModel final : public QAbstractTableModel { 48 Q_OBJECT 49 50 public: 51 enum Column { COLUMN_NAME, COLUMN_ACTIONS, _COLUMN_COUNT }; 52 53 // Constructors / Destructor 54 PackagePadListModel() = delete; 55 PackagePadListModel(const PackagePadListModel& other) noexcept; 56 explicit PackagePadListModel(QObject* parent = nullptr) noexcept; 57 ~PackagePadListModel() noexcept; 58 59 // Setters 60 void setPadList(PackagePadList* list) noexcept; 61 void setUndoStack(UndoStack* stack) noexcept; 62 63 // Slots 64 void addPad(const QVariant& editData) noexcept; 65 void removePad(const QVariant& editData) noexcept; 66 67 // Inherited from QAbstractItemModel 68 int rowCount(const QModelIndex& parent = QModelIndex()) const override; 69 int columnCount(const QModelIndex& parent = QModelIndex()) const override; 70 QVariant data(const QModelIndex& index, 71 int role = Qt::DisplayRole) const override; 72 QVariant headerData(int section, Qt::Orientation orientation, 73 int role = Qt::DisplayRole) const override; 74 Qt::ItemFlags flags(const QModelIndex& index) const override; 75 bool setData(const QModelIndex& index, const QVariant& value, 76 int role = Qt::EditRole) override; 77 78 // Operator Overloadings 79 PackagePadListModel& operator=(const PackagePadListModel& rhs) noexcept; 80 81 private: 82 void padListEdited(const PackagePadList& list, int index, 83 const std::shared_ptr<const PackagePad>& pad, 84 PackagePadList::Event event) noexcept; 85 void execCmd(UndoCommand* cmd); 86 CircuitIdentifier validateNameOrThrow(const QString& name) const; 87 QString getNextPadNameProposal() const noexcept; 88 89 private: // Data 90 PackagePadList* mPadList; 91 UndoStack* mUndoStack; 92 QString mNewName; 93 94 // Slots 95 PackagePadList::OnEditedSlot mOnEditedSlot; 96 }; 97 98 /******************************************************************************* 99 * End of File 100 ******************************************************************************/ 101 102 } // namespace editor 103 } // namespace library 104 } // namespace librepcb 105 106 #endif 107