LibrePCB Developers Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
componentsymbolvariantlistwidget.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_LIBRARY_EDITOR_COMPONENTSYMBOLVARIANTLISTWIDGET_H
21 #define LIBREPCB_LIBRARY_EDITOR_COMPONENTSYMBOLVARIANTLISTWIDGET_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
27 
29 
30 #include <QtCore>
31 #include <QtWidgets>
32 
33 /*******************************************************************************
34  * Namespace / Forward Declarations
35  ******************************************************************************/
36 namespace librepcb {
37 
38 class UndoStack;
39 
40 namespace library {
41 namespace editor {
42 
43 /*******************************************************************************
44  * Class ComponentSymbolVariantListWidget
45  ******************************************************************************/
46 
54  : public QWidget,
55  private ComponentSymbolVariantList::IF_Observer {
56  Q_OBJECT
57 
58 private: // Types
59  enum Column {
66  };
67 
68 public:
69  // Constructors / Destructor
70  explicit ComponentSymbolVariantListWidget(QWidget* parent = nullptr) noexcept;
72  const ComponentSymbolVariantListWidget& other) = delete;
74 
75  // Setters
76  void setReferences(
77  UndoStack* undoStack, ComponentSymbolVariantList* variants,
78  IF_ComponentSymbolVariantEditorProvider* editorProvider) noexcept;
79 
80  // General Methods
82 
83  // Operator Overloadings
85  const ComponentSymbolVariantListWidget& rhs) = delete;
86 
87 private: // Slots
88  void currentCellChanged(int currentRow, int currentColumn, int previousRow,
89  int previousColumn) noexcept;
90  void cellDoubleClicked(int row, int column) noexcept;
91  void btnEditClicked() noexcept;
92  void btnAddRemoveClicked() noexcept;
93  void btnUpClicked() noexcept;
94  void btnDownClicked() noexcept;
95 
96 private: // Observer
97  void listObjectAdded(
98  const ComponentSymbolVariantList& list, int newIndex,
99  const std::shared_ptr<ComponentSymbolVariant>& ptr) noexcept override;
100  void listObjectRemoved(
101  const ComponentSymbolVariantList& list, int oldIndex,
102  const std::shared_ptr<ComponentSymbolVariant>& ptr) noexcept override;
103 
104 private: // Methods
105  void updateTable() noexcept;
106  void setTableRowContent(int row, const tl::optional<Uuid>& uuid,
107  const QString& name, const QString& desc,
108  const QString& norm, int symbolCount) noexcept;
109  void addVariant(const QString& name, const QString& desc,
110  const QString& norm) noexcept;
111  void removeVariant(const Uuid& uuid) noexcept;
112  void moveVariantUp(int index) noexcept;
113  void moveVariantDown(int index) noexcept;
114  void editVariant(const Uuid& uuid) noexcept;
115  int getRowOfTableCellWidget(QObject* obj) const noexcept;
116  tl::optional<Uuid> getUuidOfRow(int row) const noexcept;
117  bool allReferencesValid() const noexcept {
119  }
120 
121  // row index <-> symbol variant index conversion methods
122  int newVariantRow() const noexcept { return mVariantList->count(); }
123  int indexToRow(int index) const noexcept { return index; }
124  int rowToIndex(int row) const noexcept { return row; }
125  bool isExistingVariantRow(int row) const noexcept {
126  return row >= 0 && row < mVariantList->count();
127  }
128  bool isNewVariantRow(int row) const noexcept {
129  return row == newVariantRow();
130  }
131 
132 private: // Data
133  QTableWidget* mTable;
137  tl::optional<Uuid> mSelectedVariant;
138 };
139 
140 /*******************************************************************************
141  * End of File
142  ******************************************************************************/
143 
144 } // namespace editor
145 } // namespace library
146 } // namespace librepcb
147 
148 #endif // LIBREPCB_LIBRARY_EDITOR_COMPONENTSYMBOLVARIANTLISTWIDGET_H
Column
Definition: componentsymbolvariantlistwidget.h:59
void moveVariantDown(int index) noexcept
Definition: componentsymbolvariantlistwidget.cpp:419
IF_ComponentSymbolVariantEditorProvider * mEditorProvider
Definition: componentsymbolvariantlistwidget.h:136
bool isNewVariantRow(int row) const noexcept
Definition: componentsymbolvariantlistwidget.h:128
void moveVariantUp(int index) noexcept
Definition: componentsymbolvariantlistwidget.cpp:408
void addDefaultSymbolVariant()
Definition: componentsymbolvariantlistwidget.cpp:126
ComponentSymbolVariantListWidget(QWidget *parent=nullptr) noexcept
Definition: componentsymbolvariantlistwidget.cpp:42
void setReferences(UndoStack *undoStack, ComponentSymbolVariantList *variants, IF_ComponentSymbolVariantEditorProvider *editorProvider) noexcept
Definition: componentsymbolvariantlistwidget.cpp:98
void listObjectRemoved(const ComponentSymbolVariantList &list, int oldIndex, const std::shared_ptr< ComponentSymbolVariant > &ptr) noexceptoverride
Definition: componentsymbolvariantlistwidget.cpp:215
ComponentSymbolVariantList * mVariantList
Definition: componentsymbolvariantlistwidget.h:135
UndoStack * mUndoStack
Definition: componentsymbolvariantlistwidget.h:134
int getRowOfTableCellWidget(QObject *obj) const noexcept
Definition: componentsymbolvariantlistwidget.cpp:450
int rowToIndex(int row) const noexcept
Definition: componentsymbolvariantlistwidget.h:124
Definition: componentsymbolvariantlistwidget.h:60
int count() const noexcept
Definition: serializableobjectlist.h:168
bool isExistingVariantRow(int row) const noexcept
Definition: componentsymbolvariantlistwidget.h:125
int indexToRow(int index) const noexcept
Definition: componentsymbolvariantlistwidget.h:123
void btnAddRemoveClicked() noexcept
Definition: componentsymbolvariantlistwidget.cpp:164
The UndoStack class holds UndoCommand objects and provides undo/redo commands.
Definition: undostack.h:120
void updateTable() noexcept
Definition: componentsymbolvariantlistwidget.cpp:230
tl::optional< Uuid > getUuidOfRow(int row) const noexcept
Definition: componentsymbolvariantlistwidget.cpp:459
void btnEditClicked() noexcept
Definition: componentsymbolvariantlistwidget.cpp:155
void listObjectAdded(const ComponentSymbolVariantList &list, int newIndex, const std::shared_ptr< ComponentSymbolVariant > &ptr) noexceptoverride
Definition: componentsymbolvariantlistwidget.cpp:204
Definition: componentsymbolvariantlistwidget.h:62
tl::optional< Uuid > mSelectedVariant
Definition: componentsymbolvariantlistwidget.h:137
The IF_ComponentSymbolVariantEditorProvider interface.
Definition: if_componentsymbolvarianteditorprovider.h:48
void editVariant(const Uuid &uuid) noexcept
Definition: componentsymbolvariantlistwidget.cpp:430
int newVariantRow() const noexcept
Definition: componentsymbolvariantlistwidget.h:122
void setTableRowContent(int row, const tl::optional< Uuid > &uuid, const QString &name, const QString &desc, const QString &norm, int symbolCount) noexcept
Definition: componentsymbolvariantlistwidget.cpp:272
void removeVariant(const Uuid &uuid) noexcept
Definition: componentsymbolvariantlistwidget.cpp:395
The ComponentSymbolVariantListWidget class.
Definition: componentsymbolvariantlistwidget.h:53
void btnDownClicked() noexcept
Definition: componentsymbolvariantlistwidget.cpp:191
The ComponentSymbolVariant class represents a symbol variant of a component.
Definition: componentsymbolvariant.h:58
bool allReferencesValid() const noexcept
Definition: componentsymbolvariantlistwidget.h:117
QTableWidget * mTable
Definition: componentsymbolvariantlistwidget.h:133
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:58
void currentCellChanged(int currentRow, int currentColumn, int previousRow, int previousColumn) noexcept
Definition: componentsymbolvariantlistwidget.cpp:135
void cellDoubleClicked(int row, int column) noexcept
Definition: componentsymbolvariantlistwidget.cpp:145
void addVariant(const QString &name, const QString &desc, const QString &norm) noexcept
Definition: componentsymbolvariantlistwidget.cpp:382
void btnUpClicked() noexcept
Definition: componentsymbolvariantlistwidget.cpp:182