LibrePCB Developers Documentation
Loading...
Searching...
No Matches
librarytab.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_EDITOR_LIBRARYTAB_H
21#define LIBREPCB_EDITOR_LIBRARYTAB_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
26#include "../libraryeditortab.h"
27
31
32#include <QtCore>
33
34#include <optional>
35
36/*******************************************************************************
37 * Namespace / Forward Declarations
38 ******************************************************************************/
39namespace librepcb {
40
41class Library;
42class WorkspaceLibraryDb;
43
44namespace editor {
45
46class LibraryDependenciesModel;
47class LibraryEditor;
48
49/*******************************************************************************
50 * Class LibraryTab
51 ******************************************************************************/
52
56class LibraryTab final : public LibraryEditorTab {
57 Q_OBJECT
58
59 struct TreeItem {
60 ui::LibraryTreeViewItemType type;
61 FilePath path; // Only when part of this library.
62 QString name;
63 QString summary;
64 bool isExternal = false;
65 QString userData; // UUID for categories, filepath for elements
66 QVector<std::shared_ptr<TreeItem>> childs;
67 };
68
69public:
70 // Signals
72
73 // Constructors / Destructor
74 LibraryTab() = delete;
75 LibraryTab(const LibraryTab& other) = delete;
76 explicit LibraryTab(LibraryEditor& editor, bool wizardMode,
77 QObject* parent = nullptr) noexcept;
78 ~LibraryTab() noexcept;
79
80 // General Methods
81 FilePath getDirectoryPath() const noexcept override;
82 ui::TabData getUiData() const noexcept override;
83 void setUiData(const ui::TabData& data) noexcept override;
84 ui::LibraryTabData getDerivedUiData() const noexcept;
85 void setDerivedUiData(const ui::LibraryTabData& data) noexcept;
86 void trigger(ui::TabAction a) noexcept override;
87
88 // Operator Overloadings
89 LibraryTab& operator=(const LibraryTab& rhs) = delete;
90
91signals:
93 const FilePath& fp, bool copyFrom);
95 bool copyFrom);
97 bool copyFrom);
101
102protected:
103 std::optional<std::pair<RuleCheckMessageList, QSet<SExpression>>>
104 runChecksImpl() override;
105 bool autoFixImpl(const std::shared_ptr<const RuleCheckMessage>& msg,
106 bool checkOnly) override;
107 template <typename MessageType>
108 bool autoFixHelper(const std::shared_ptr<const RuleCheckMessage>& msg,
109 bool checkOnly);
110 template <typename MessageType>
111 void autoFix(const MessageType& msg);
112 void messageApprovalChanged(const SExpression& approval,
113 bool approved) noexcept override;
114 void notifyDerivedUiDataChanged() noexcept override;
115
116private:
117 void refreshUiData() noexcept;
118 void commitUiData() noexcept;
119 void refreshLibElements() noexcept;
120 std::shared_ptr<TreeItem> createRootItem(
121 ui::LibraryTreeViewItemType type) noexcept;
122 template <typename CategoryType>
123 void loadCategories(ui::LibraryTreeViewItemType type, TreeItem& root);
124 template <typename CategoryType>
125 std::shared_ptr<TreeItem> getOrCreateCategory(
126 ui::LibraryTreeViewItemType type, const Uuid& uuid, TreeItem& root);
127 template <typename ElementType, typename CategoryType>
128 void loadElements(ui::LibraryTreeViewItemType type,
129 ui::LibraryTreeViewItemType catType, TreeItem& root,
130 int& count);
131 void sortItemsRecursive(QVector<std::shared_ptr<TreeItem>>& items) noexcept;
132 void addCategoriesToModel(ui::LibraryTreeViewItemType type, TreeItem& root,
133 int count) noexcept;
135 TreeItem& item, ui::LibraryTreeViewItemType type,
136 slint::VectorModel<ui::LibraryTreeViewItemData>& model,
137 int level) noexcept;
139 const std::optional<ui::LibraryTreeViewItemData>& data) noexcept;
140 void getChildsRecursive(TreeItem& item,
141 QSet<std::shared_ptr<TreeItem>>& childs) noexcept;
142 QList<std::shared_ptr<TreeItem>> getSelectedCategories() const noexcept;
143 QList<std::shared_ptr<TreeItem>> getSelectedElements() const noexcept;
145 const QList<std::shared_ptr<TreeItem>>& items) noexcept;
146 void moveElementsTo(const QList<std::shared_ptr<TreeItem>>& items,
147 const FilePath& dstLib) noexcept;
148 void deleteElements(const QList<std::shared_ptr<TreeItem>>& items) noexcept;
149
150private:
153 const QStringList& mLocaleOrder;
154
155 // State
160 QString mFilterTerm;
161
162 // Library metadata to be applied
163 QByteArray mIcon;
164 slint::SharedString mName;
165 slint::SharedString mNameError;
167 slint::SharedString mDescription;
168 slint::SharedString mKeywords;
169 slint::SharedString mAuthor;
170 slint::SharedString mVersion;
171 slint::SharedString mVersionError;
174 slint::SharedString mUrl;
175 slint::SharedString mUrlError;
177 slint::SharedString mManufacturer;
178
179 // Library content
186 QHash<QString, std::shared_ptr<TreeItem>> mLibElementsMap; // Key: user-data
187 std::shared_ptr<slint::VectorModel<ui::LibraryTreeViewItemData>> mCategories;
188 std::shared_ptr<slint::VectorModel<ui::LibraryTreeViewItemData>> mElements;
189 std::shared_ptr<slint::FilterModel<ui::LibraryTreeViewItemData>>
191};
192
193/*******************************************************************************
194 * End of File
195 ******************************************************************************/
196
197} // namespace editor
198} // namespace librepcb
199
200#endif
This class represents absolute, well-formatted paths to files or directories.
Definition filepath.h:127
The Library class represents a library directory.
Definition library.h:46
The RuleCheckMessage class.
Definition rulecheckmessage.h:45
The SExpression class.
Definition sexpression.h:69
The Signal class is used to emit signals on non-QObject derived classes.
Definition signalslot.h:65
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition uuid.h:56
The Version class represents a version number in the format "1.42.7".
Definition version.h:58
The WorkspaceLibraryDb class.
Definition workspacelibrarydb.h:58
The LibraryDependenciesModel class.
Definition librarydependenciesmodel.h:50
The LibraryEditor class.
Definition libraryeditor.h:57
Specialized base class for all library editor tabs.
Definition libraryeditortab.h:54
The LibraryTab class.
Definition librarytab.h:56
void autoFix(const MessageType &msg)
slint::SharedString mVersionError
Definition librarytab.h:171
QHash< FilePath, Uuid > mLibCategories
Definition librarytab.h:180
std::optional< std::pair< RuleCheckMessageList, QSet< SExpression > > > runChecksImpl() override
Definition librarytab.cpp:389
Library & mLibrary
Definition librarytab.h:151
int mCurrentCategoryIndex
Definition librarytab.h:158
slint::SharedString mName
Definition librarytab.h:164
QHash< QString, std::shared_ptr< TreeItem > > mLibElementsMap
Definition librarytab.h:186
const WorkspaceLibraryDb & mDb
Definition librarytab.h:152
void sortItemsRecursive(QVector< std::shared_ptr< TreeItem > > &items) noexcept
Definition librarytab.cpp:670
QList< std::shared_ptr< TreeItem > > getSelectedElements() const noexcept
Definition librarytab.cpp:810
slint::SharedString mDescription
Definition librarytab.h:167
void deleteElements(const QList< std::shared_ptr< TreeItem > > &items) noexcept
Definition librarytab.cpp:968
std::shared_ptr< TreeItem > mUncategorizedRoot
Definition librarytab.h:181
slint::SharedString mVersion
Definition librarytab.h:170
void componentEditorRequested(LibraryEditor &editor, const FilePath &fp)
std::shared_ptr< TreeItem > mCmpCatRoot
Definition librarytab.h:182
void setSelectedCategory(const std::optional< ui::LibraryTreeViewItemData > &data) noexcept
Definition librarytab.cpp:727
void componentCategoryEditorRequested(LibraryEditor &editor, const FilePath &fp, bool copyFrom)
bool mWizardMode
Definition librarytab.h:156
bool mDeprecated
Definition librarytab.h:173
QString mFilterTerm
Definition librarytab.h:160
void packageCategoryEditorRequested(LibraryEditor &editor, const FilePath &fp, bool copyFrom)
int mCmpCatElementCount
Definition librarytab.h:183
std::shared_ptr< TreeItem > mPkgCatRoot
Definition librarytab.h:184
void messageApprovalChanged(const SExpression &approval, bool approved) noexcept override
Definition librarytab.cpp:412
QList< std::shared_ptr< TreeItem > > getSelectedCategories() const noexcept
Definition librarytab.cpp:797
void refreshLibElements() noexcept
Definition librarytab.cpp:490
bool autoFixImpl(const std::shared_ptr< const RuleCheckMessage > &msg, bool checkOnly) override
Definition librarytab.cpp:393
void moveElementsTo(const QList< std::shared_ptr< TreeItem > > &items, const FilePath &dstLib) noexcept
Definition librarytab.cpp:861
FilePath getDirectoryPath() const noexcept override
Definition librarytab.cpp:126
QByteArray mIcon
Definition librarytab.h:163
std::shared_ptr< slint::VectorModel< ui::LibraryTreeViewItemData > > mCategories
Definition librarytab.h:187
bool autoFixHelper(const std::shared_ptr< const RuleCheckMessage > &msg, bool checkOnly)
Definition librarytab.cpp:401
void setUiData(const ui::TabData &data) noexcept override
Definition librarytab.cpp:151
std::shared_ptr< TreeItem > createRootItem(ui::LibraryTreeViewItemType type) noexcept
Definition librarytab.cpp:562
Version mVersionParsed
Definition librarytab.h:172
LibraryTab(const LibraryTab &other)=delete
std::shared_ptr< LibraryDependenciesModel > mDependencies
Definition librarytab.h:176
void commitUiData() noexcept
Definition librarytab.cpp:465
slint::SharedString mNameError
Definition librarytab.h:165
int mPkgCatElementCount
Definition librarytab.h:185
slint::SharedString mKeywords
Definition librarytab.h:168
void packageEditorRequested(LibraryEditor &editor, const FilePath &fp)
const QStringList & mLocaleOrder
Definition librarytab.h:153
void trigger(ui::TabAction a) noexcept override
Definition librarytab.cpp:243
std::shared_ptr< slint::FilterModel< ui::LibraryTreeViewItemData > > mFilteredElements
Definition librarytab.h:190
void loadElements(ui::LibraryTreeViewItemType type, ui::LibraryTreeViewItemType catType, TreeItem &root, int &count)
Definition librarytab.cpp:636
std::shared_ptr< TreeItem > getOrCreateCategory(ui::LibraryTreeViewItemType type, const Uuid &uuid, TreeItem &root)
Definition librarytab.cpp:594
slint::SharedString mManufacturer
Definition librarytab.h:177
void duplicateElements(const QList< std::shared_ptr< TreeItem > > &items) noexcept
Definition librarytab.cpp:823
void notifyDerivedUiDataChanged() noexcept override
Definition librarytab.cpp:419
slint::SharedString mUrl
Definition librarytab.h:174
void symbolEditorRequested(LibraryEditor &editor, const FilePath &fp, bool copyFrom)
ElementName mNameParsed
Definition librarytab.h:166
int mCurrentElementIndex
Definition librarytab.h:159
void getChildsRecursive(TreeItem &item, QSet< std::shared_ptr< TreeItem > > &childs) noexcept
Definition librarytab.cpp:789
slint::SharedString mAuthor
Definition librarytab.h:169
ui::TabData getUiData() const noexcept override
Definition librarytab.cpp:130
slint::SharedString mUrlError
Definition librarytab.h:175
void loadCategories(ui::LibraryTreeViewItemType type, TreeItem &root)
Definition librarytab.cpp:579
int mCurrentPageIndex
Definition librarytab.h:157
Signal< LibraryTab > onDerivedUiDataChanged
Definition librarytab.h:71
void setDerivedUiData(const ui::LibraryTabData &data) noexcept
Definition librarytab.cpp:198
void refreshUiData() noexcept
Definition librarytab.cpp:444
ui::LibraryTabData getDerivedUiData() const noexcept
Definition librarytab.cpp:162
void deviceEditorRequested(LibraryEditor &editor, const FilePath &fp)
void addCategoriesToModel(ui::LibraryTreeViewItemType type, TreeItem &root, int count) noexcept
Definition librarytab.cpp:688
std::shared_ptr< slint::VectorModel< ui::LibraryTreeViewItemData > > mElements
Definition librarytab.h:188
Definition occmodel.cpp:77
QVector< std::shared_ptr< const RuleCheckMessage > > RuleCheckMessageList
Definition rulecheckmessage.h:104
type_safe::constrained_type< QString, ElementNameConstraint, ElementNameVerifier > ElementName
Definition elementname.h:84
Definition uuid.h:186
Definition librarytab.h:59
QVector< std::shared_ptr< TreeItem > > childs
Definition librarytab.h:66
FilePath path
Definition librarytab.h:61
ui::LibraryTreeViewItemType type
Definition librarytab.h:60
QString userData
Definition librarytab.h:65
QString summary
Definition librarytab.h:63
QString name
Definition librarytab.h:62
bool isExternal
Definition librarytab.h:64