LibrePCB Developers Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
categorylisteditorwidget.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_CATEGORYLISTEDITORWIDGET_H
21 #define LIBREPCB_LIBRARY_EDITOR_CATEGORYLISTEDITORWIDGET_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
28 
29 #include <QtCore>
30 #include <QtWidgets>
31 
32 /*******************************************************************************
33  * Namespace / Forward Declarations
34  ******************************************************************************/
35 namespace librepcb {
36 
37 namespace workspace {
38 class Workspace;
39 }
40 
41 namespace library {
42 namespace editor {
43 
44 namespace Ui {
45 class CategoryListEditorWidget;
46 }
47 
48 /*******************************************************************************
49  * Class CategoryListEditorWidgetBase
50  ******************************************************************************/
51 
58 class CategoryListEditorWidgetBase : public QWidget {
59  Q_OBJECT
60 
61 public:
62  // Constructors / Destructor
65  QWidget* parent = nullptr) noexcept;
67  delete;
68  virtual ~CategoryListEditorWidgetBase() noexcept;
69 
70  // Getters
71  const QSet<Uuid>& getUuids() const noexcept { return mUuids; }
72 
73  // Setters
74  void setRequiresMinimumOneEntry(bool v) noexcept;
75  void setUuids(const QSet<Uuid>& uuids) noexcept;
76 
77  // General Methods
78  void openAddCategoryDialog() noexcept { btnAddClicked(); }
79 
80  // Operator Overloadings
82  const CategoryListEditorWidgetBase& rhs) = delete;
83 
84 protected:
85  virtual tl::optional<Uuid> chooseCategoryWithDialog() noexcept = 0;
86  virtual FilePath getLatestCategory(const Uuid& category) const = 0;
87  virtual QList<Uuid> getCategoryParents(const Uuid& category) const = 0;
88  virtual QString getCategoryName(const FilePath& fp) const = 0;
89 
90 private:
91  void btnAddClicked() noexcept;
92  void btnRemoveClicked() noexcept;
93  void addItem(const tl::optional<Uuid>& category) noexcept;
94  void addItem(const tl::optional<Uuid>& category,
95  const QStringList& lines) noexcept;
96  void addItem(const tl::optional<Uuid>& category,
97  const QString& text) noexcept;
98  void updateColor() noexcept;
99 
100 signals:
101  void edited();
102  void categoryAdded(const Uuid& category);
103  void categoryRemoved(const Uuid& category);
104 
105 protected: // Data
106  const workspace::Workspace& mWorkspace;
107  QScopedPointer<Ui::CategoryListEditorWidget> mUi;
109  QSet<Uuid> mUuids;
110 };
111 
112 /*******************************************************************************
113  * Class CategoryListEditorWidget
114  ******************************************************************************/
115 
122 template <typename ElementType>
124 public:
125  // Constructors / Destructor
126  CategoryListEditorWidget() = delete;
128  QWidget* parent = nullptr) noexcept;
129  CategoryListEditorWidget(const CategoryListEditorWidget& other) = delete;
130  ~CategoryListEditorWidget() noexcept;
131 
132  // Operator Overloadings
134  delete;
135 
136 private:
137  tl::optional<Uuid> chooseCategoryWithDialog() noexcept override;
138  FilePath getLatestCategory(const Uuid& category) const override;
139  QList<Uuid> getCategoryParents(const Uuid& category) const override;
140  QString getCategoryName(const FilePath& fp) const override;
141 };
142 
147 
148 /*******************************************************************************
149  * End of File
150  ******************************************************************************/
151 
152 } // namespace editor
153 } // namespace library
154 } // namespace librepcb
155 
156 #endif // LIBREPCB_LIBRARY_EDITOR_CATEGORYLISTEDITORWIDGET_H
CategoryListEditorWidget< library::PackageCategory > PackageCategoryListEditorWidget
Definition: categorylisteditorwidget.h:146
void setUuids(const QSet< Uuid > &uuids) noexcept
Definition: categorylisteditorwidget.cpp:71
bool mRequiresMinimumOneEntry
Definition: categorylisteditorwidget.h:108
The Workspace class represents a workspace with all its data (library, projects, settings, ...)
Definition: workspace.h:65
void addItem(const tl::optional< Uuid > &category) noexcept
Definition: categorylisteditorwidget.cpp:107
void btnRemoveClicked() noexcept
Definition: categorylisteditorwidget.cpp:91
const QSet< Uuid > & getUuids() const noexcept
Definition: categorylisteditorwidget.h:71
CategoryListEditorWidgetBase & operator=(const CategoryListEditorWidgetBase &rhs)=delete
virtual ~CategoryListEditorWidgetBase() noexcept
Definition: categorylisteditorwidget.cpp:59
virtual QString getCategoryName(const FilePath &fp) const =0
CategoryListEditorWidget< library::ComponentCategory > ComponentCategoryListEditorWidget
Definition: categorylisteditorwidget.h:144
QSet< Uuid > mUuids
Definition: categorylisteditorwidget.h:109
void btnAddClicked() noexcept
Definition: categorylisteditorwidget.cpp:81
void openAddCategoryDialog() noexcept
Definition: categorylisteditorwidget.h:78
The CategoryListEditorWidget class.
Definition: categorylisteditorwidget.h:123
virtual FilePath getLatestCategory(const Uuid &category) const =0
virtual QList< Uuid > getCategoryParents(const Uuid &category) const =0
This class represents absolute, well-formatted paths to files or directories.
Definition: filepath.h:130
const workspace::Workspace & mWorkspace
Definition: categorylisteditorwidget.h:106
QScopedPointer< Ui::CategoryListEditorWidget > mUi
Definition: categorylisteditorwidget.h:107
void setRequiresMinimumOneEntry(bool v) noexcept
Definition: categorylisteditorwidget.cpp:66
The CategoryListEditorWidgetBase class.
Definition: categorylisteditorwidget.h:58
void updateColor() noexcept
Definition: categorylisteditorwidget.cpp:148
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:58
virtual tl::optional< Uuid > chooseCategoryWithDialog() noexcept=0