LibrePCB Developers Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
componentsymbolvariantitemlisteditorwidget.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_COMPONENTSYMBOLVARIANTITEMLISTEDITORWIDGET_H
21 #define LIBREPCB_LIBRARY_EDITOR_COMPONENTSYMBOLVARIANTITEMLISTEDITORWIDGET_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
27 
28 #include <QtCore>
29 #include <QtWidgets>
30 
31 /*******************************************************************************
32  * Namespace / Forward Declarations
33  ******************************************************************************/
34 namespace librepcb {
35 
36 class CenteredCheckBox;
37 class IF_GraphicsLayerProvider;
38 
39 namespace workspace {
40 class Workspace;
41 }
42 
43 namespace library {
44 namespace editor {
45 
46 /*******************************************************************************
47  * Class ComponentSymbolVariantItemListEditorWidget
48  ******************************************************************************/
49 
56 class ComponentSymbolVariantItemListEditorWidget final : public QWidget {
57  Q_OBJECT
58 
59 private: // Types
60  enum Column {
70  };
71 
72 public:
73  // Constructors / Destructor
75  QWidget* parent = nullptr) noexcept;
77  const ComponentSymbolVariantItemListEditorWidget& other) = delete;
79 
80  // Setters
81  void setVariant(const workspace::Workspace& ws,
82  const IF_GraphicsLayerProvider& layerProvider,
83  ComponentSymbolVariantItemList& items) noexcept;
84 
85  // Operator Overloadings
87  const ComponentSymbolVariantItemListEditorWidget& rhs) = delete;
88 
89 signals:
90  void edited();
91 
92 private: // Slots
93  void currentCellChanged(int currentRow, int currentColumn, int previousRow,
94  int previousColumn) noexcept;
95  void tableCellChanged(int row, int column) noexcept;
96  void isRequiredChanged(bool checked) noexcept;
97  void btnChooseSymbolClicked() noexcept;
98  void btnAddRemoveClicked() noexcept;
99  void btnUpClicked() noexcept;
100  void btnDownClicked() noexcept;
101 
102 private: // Methods
103  void updateTable(tl::optional<Uuid> selected = tl::nullopt) noexcept;
104  void setTableRowContent(int row, int number, const tl::optional<Uuid>& uuid,
105  const tl::optional<Uuid>& symbol,
106  const QString& suffix, bool required,
107  const Point& pos, const Angle& rot) noexcept;
108  void addItem(const Uuid& symbol, const QString& suffix, bool required,
109  const Point& pos, const Angle& rot) noexcept;
110  void removeItem(const Uuid& uuid) noexcept;
111  void moveItemUp(int index) noexcept;
112  void moveItemDown(int index) noexcept;
113  void setSymbolUuid(const Uuid& uuid, const Uuid& symbol) noexcept;
114  void setIsRequired(const Uuid& uuid, bool required) noexcept;
115  void setSuffix(const Uuid& uuid, const QString& suffix) noexcept;
116  void setPosX(const Uuid& uuid, const Length& x) noexcept;
117  void setPosY(const Uuid& uuid, const Length& y) noexcept;
118  void setRotation(const Uuid& uuid, const Angle& rot) noexcept;
119  int getRowOfTableCellWidget(QObject* obj) const noexcept;
120  tl::optional<Uuid> getUuidOfRow(int row) const noexcept;
121 
122  // row index <-> item index conversion methods
123  int newItemRow() const noexcept { return mItems->count(); }
124  int indexToRow(int index) const noexcept { return index; }
125  int rowToIndex(int row) const noexcept { return row; }
126  bool isExistingItemRow(int row) const noexcept {
127  return row >= 0 && row < mItems->count();
128  }
129  bool isNewItemRow(int row) const noexcept { return row == newItemRow(); }
130 
131 private: // Data
132  QTableWidget* mTable;
136  tl::optional<Uuid> mSelectedItem;
139 };
140 
141 /*******************************************************************************
142  * End of File
143  ******************************************************************************/
144 
145 } // namespace editor
146 } // namespace library
147 } // namespace librepcb
148 
149 #endif // LIBREPCB_LIBRARY_EDITOR_COMPONENTSYMBOLVARIANTITEMLISTEDITORWIDGET_H
Definition: componentsymbolvariantitemlisteditorwidget.h:63
void setPosX(const Uuid &uuid, const Length &x) noexcept
Definition: componentsymbolvariantitemlisteditorwidget.cpp:533
void btnDownClicked() noexcept
Definition: componentsymbolvariantitemlisteditorwidget.cpp:252
void btnAddRemoveClicked() noexcept
Definition: componentsymbolvariantitemlisteditorwidget.cpp:216
Definition: componentsymbolvariantitemlisteditorwidget.h:67
The Workspace class represents a workspace with all its data (library, projects, settings, ...)
Definition: workspace.h:65
void btnChooseSymbolClicked() noexcept
Definition: componentsymbolvariantitemlisteditorwidget.cpp:201
CenteredCheckBox * mNewRequiredCheckbox
Definition: componentsymbolvariantitemlisteditorwidget.h:138
void currentCellChanged(int currentRow, int currentColumn, int previousRow, int previousColumn) noexcept
Definition: componentsymbolvariantitemlisteditorwidget.cpp:134
Definition: componentsymbolvariantitemlisteditorwidget.h:66
int count() const noexcept
Definition: serializableobjectlist.h:168
void isRequiredChanged(bool checked) noexcept
Definition: componentsymbolvariantitemlisteditorwidget.cpp:191
void updateTable(tl::optional< Uuid > selected=tl::nullopt) noexcept
Definition: componentsymbolvariantitemlisteditorwidget.cpp:264
void addItem(const Uuid &symbol, const QString &suffix, bool required, const Point &pos, const Angle &rot) noexcept
Definition: componentsymbolvariantitemlisteditorwidget.cpp:452
Definition: componentsymbolvariantitemlisteditorwidget.h:69
ComponentSymbolVariantItemListEditorWidget(QWidget *parent=nullptr) noexcept
Definition: componentsymbolvariantitemlisteditorwidget.cpp:49
int indexToRow(int index) const noexcept
Definition: componentsymbolvariantitemlisteditorwidget.h:124
bool isNewItemRow(int row) const noexcept
Definition: componentsymbolvariantitemlisteditorwidget.h:129
The Angle class is used to represent an angle (for example 12.75 degrees)
Definition: angle.h:81
int getRowOfTableCellWidget(QObject *obj) const noexcept
Definition: componentsymbolvariantitemlisteditorwidget.cpp:558
The IF_GraphicsLayerProvider class defines an interface for classes which provide layers...
Definition: graphicslayer.h:250
void setIsRequired(const Uuid &uuid, bool required) noexcept
Definition: componentsymbolvariantitemlisteditorwidget.cpp:514
void removeItem(const Uuid &uuid) noexcept
Definition: componentsymbolvariantitemlisteditorwidget.cpp:473
Definition: componentsymbolvariantitemlisteditorwidget.h:68
tl::optional< Uuid > mSelectedItem
Definition: componentsymbolvariantitemlisteditorwidget.h:136
void setTableRowContent(int row, int number, const tl::optional< Uuid > &uuid, const tl::optional< Uuid > &symbol, const QString &suffix, bool required, const Point &pos, const Angle &rot) noexcept
Definition: componentsymbolvariantitemlisteditorwidget.cpp:312
void setSymbolUuid(const Uuid &uuid, const Uuid &symbol) noexcept
Definition: componentsymbolvariantitemlisteditorwidget.cpp:497
Definition: componentsymbolvariantitemlisteditorwidget.h:64
void setPosY(const Uuid &uuid, const Length &y) noexcept
Definition: componentsymbolvariantitemlisteditorwidget.cpp:542
The Point class is used to represent a point/coordinate/vector, for example (1.2mm; 5...
Definition: point.h:81
void moveItemUp(int index) noexcept
Definition: componentsymbolvariantitemlisteditorwidget.cpp:481
ComponentSymbolVariantItemList * mItems
Definition: componentsymbolvariantitemlisteditorwidget.h:135
Definition: componentsymbolvariantitemlisteditorwidget.h:65
void setVariant(const workspace::Workspace &ws, const IF_GraphicsLayerProvider &layerProvider, ComponentSymbolVariantItemList &items) noexcept
Definition: componentsymbolvariantitemlisteditorwidget.cpp:119
int newItemRow() const noexcept
Definition: componentsymbolvariantitemlisteditorwidget.h:123
tl::optional< Uuid > getUuidOfRow(int row) const noexcept
Definition: componentsymbolvariantitemlisteditorwidget.cpp:567
void setRotation(const Uuid &uuid, const Angle &rot) noexcept
Definition: componentsymbolvariantitemlisteditorwidget.cpp:551
bool isExistingItemRow(int row) const noexcept
Definition: componentsymbolvariantitemlisteditorwidget.h:126
const IF_GraphicsLayerProvider * mLayerProvider
Definition: componentsymbolvariantitemlisteditorwidget.h:134
The ComponentSymbolVariantItemListEditorWidget class.
Definition: componentsymbolvariantitemlisteditorwidget.h:56
The CenteredCheckBox class is a centered variant of the QCheckBox.
Definition: centeredcheckbox.h:44
void moveItemDown(int index) noexcept
Definition: componentsymbolvariantitemlisteditorwidget.cpp:489
int rowToIndex(int row) const noexcept
Definition: componentsymbolvariantitemlisteditorwidget.h:125
void setSuffix(const Uuid &uuid, const QString &suffix) noexcept
Definition: componentsymbolvariantitemlisteditorwidget.cpp:521
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:58
The Length class is used to represent a length (for example 12.75 millimeters)
Definition: length.h:85
const workspace::Workspace * mWorkspace
Definition: componentsymbolvariantitemlisteditorwidget.h:133
Definition: componentsymbolvariantitemlisteditorwidget.h:62
Column
Definition: componentsymbolvariantitemlisteditorwidget.h:60
void btnUpClicked() noexcept
Definition: componentsymbolvariantitemlisteditorwidget.cpp:244
Definition: componentsymbolvariantitemlisteditorwidget.h:61
QLabel * mNewSymbolLabel
Definition: componentsymbolvariantitemlisteditorwidget.h:137
QTableWidget * mTable
Definition: componentsymbolvariantitemlisteditorwidget.h:132
void tableCellChanged(int row, int column) noexcept
Definition: componentsymbolvariantitemlisteditorwidget.cpp:143