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 
55 class CategoryListEditorWidgetBase : public QWidget {
56  Q_OBJECT
57 
58 public:
59  // Constructors / Destructor
62  QWidget* parent = nullptr) noexcept;
64  delete;
65  virtual ~CategoryListEditorWidgetBase() noexcept;
66 
67  // Getters
68  const QSet<Uuid>& getUuids() const noexcept { return mUuids; }
69 
70  // Setters
71  void setRequiresMinimumOneEntry(bool v) noexcept;
72  void setUuids(const QSet<Uuid>& uuids) noexcept;
73 
74  // General Methods
75  void openAddCategoryDialog() noexcept { btnAddClicked(); }
76 
77  // Operator Overloadings
79  const CategoryListEditorWidgetBase& rhs) = delete;
80 
81 protected:
82  virtual tl::optional<Uuid> chooseCategoryWithDialog() noexcept = 0;
83  virtual FilePath getLatestCategory(const Uuid& category) const = 0;
84  virtual QList<Uuid> getCategoryParents(const Uuid& category) const = 0;
85  virtual QString getCategoryName(const FilePath& fp) const = 0;
86 
87 private:
88  void btnAddClicked() noexcept;
89  void btnRemoveClicked() noexcept;
90  void addItem(const tl::optional<Uuid>& category) noexcept;
91  void addItem(const tl::optional<Uuid>& category,
92  const QStringList& lines) noexcept;
93  void addItem(const tl::optional<Uuid>& category,
94  const QString& text) noexcept;
95  void updateColor() noexcept;
96 
97 signals:
98  void edited();
99  void categoryAdded(const Uuid& category);
100  void categoryRemoved(const Uuid& category);
101 
102 protected: // Data
103  const workspace::Workspace& mWorkspace;
104  QScopedPointer<Ui::CategoryListEditorWidget> mUi;
106  QSet<Uuid> mUuids;
107 };
108 
109 /*******************************************************************************
110  * Class CategoryListEditorWidget
111  ******************************************************************************/
112 
116 template <typename ElementType>
118 public:
119  // Constructors / Destructor
120  CategoryListEditorWidget() = delete;
122  QWidget* parent = nullptr) noexcept;
123  CategoryListEditorWidget(const CategoryListEditorWidget& other) = delete;
124  ~CategoryListEditorWidget() noexcept;
125 
126  // Operator Overloadings
128  delete;
129 
130 private:
131  tl::optional<Uuid> chooseCategoryWithDialog() noexcept override;
132  FilePath getLatestCategory(const Uuid& category) const override;
133  QList<Uuid> getCategoryParents(const Uuid& category) const override;
134  QString getCategoryName(const FilePath& fp) const override;
135 };
136 
141 
142 /*******************************************************************************
143  * End of File
144  ******************************************************************************/
145 
146 } // namespace editor
147 } // namespace library
148 } // namespace librepcb
149 
150 #endif // LIBREPCB_LIBRARY_EDITOR_CATEGORYLISTEDITORWIDGET_H
CategoryListEditorWidget< library::PackageCategory > PackageCategoryListEditorWidget
Definition: categorylisteditorwidget.h:140
void setUuids(const QSet< Uuid > &uuids) noexcept
Definition: categorylisteditorwidget.cpp:71
bool mRequiresMinimumOneEntry
Definition: categorylisteditorwidget.h:105
The Workspace class represents a workspace with all its data (library, projects, settings, ...)
Definition: workspace.h:62
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:68
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:138
QSet< Uuid > mUuids
Definition: categorylisteditorwidget.h:106
void btnAddClicked() noexcept
Definition: categorylisteditorwidget.cpp:81
void openAddCategoryDialog() noexcept
Definition: categorylisteditorwidget.h:75
The CategoryListEditorWidget class.
Definition: categorylisteditorwidget.h:117
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:127
const workspace::Workspace & mWorkspace
Definition: categorylisteditorwidget.h:103
QScopedPointer< Ui::CategoryListEditorWidget > mUi
Definition: categorylisteditorwidget.h:104
void setRequiresMinimumOneEntry(bool v) noexcept
Definition: categorylisteditorwidget.cpp:66
The CategoryListEditorWidgetBase class.
Definition: categorylisteditorwidget.h:55
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