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 isDeprecated = false;
65 bool isExternal = false;
66 QString userData; // UUID for categories, filepath for elements
67 QVector<std::shared_ptr<TreeItem>> childs;
68 };
69
70public:
71 // Signals
73
74 // Constructors / Destructor
75 LibraryTab() = delete;
76 LibraryTab(const LibraryTab& other) = delete;
77 explicit LibraryTab(LibraryEditor& editor, bool wizardMode,
78 QObject* parent = nullptr) noexcept;
79 ~LibraryTab() noexcept;
80
81 // General Methods
82 FilePath getDirectoryPath() const noexcept override;
83 ui::TabData getUiData() const noexcept override;
84 void setUiData(const ui::TabData& data) noexcept override;
85 ui::LibraryTabData getDerivedUiData() const noexcept;
86 void setDerivedUiData(const ui::LibraryTabData& data) noexcept;
87 void trigger(ui::TabAction a) noexcept override;
88
89 // Operator Overloadings
90 LibraryTab& operator=(const LibraryTab& rhs) = delete;
91
92signals:
94 const FilePath& fp, bool copyFrom);
96 bool copyFrom);
98 bool copyFrom);
100 bool copyFrom);
102 bool copyFrom);
104 bool copyFrom);
106 bool copyFrom);
107
108protected:
109 std::optional<std::pair<RuleCheckMessageList, QSet<SExpression>>>
110 runChecksImpl() override;
111 bool autoFixImpl(const std::shared_ptr<const RuleCheckMessage>& msg,
112 bool checkOnly) override;
113 template <typename MessageType>
114 bool autoFixHelper(const std::shared_ptr<const RuleCheckMessage>& msg,
115 bool checkOnly);
116 template <typename MessageType>
117 bool autoFix(const MessageType& msg);
118 void messageApprovalChanged(const SExpression& approval,
119 bool approved) noexcept override;
120 void notifyDerivedUiDataChanged() noexcept override;
121
122private:
123 void refreshUiData() noexcept;
124 void commitUiData() noexcept;
125 void refreshLibElements() noexcept;
126 std::shared_ptr<TreeItem> createRootItem(
127 ui::LibraryTreeViewItemType type) noexcept;
128 template <typename CategoryType>
129 void loadCategories(ui::LibraryTreeViewItemType type, TreeItem& root);
130 template <typename CategoryType>
131 std::shared_ptr<TreeItem> getOrCreateCategory(
132 ui::LibraryTreeViewItemType type, const Uuid& uuid, TreeItem& root);
133 template <typename ElementType, typename CategoryType>
134 void loadElements(ui::LibraryTreeViewItemType type,
135 ui::LibraryTreeViewItemType catType, TreeItem& root,
136 int& count);
137 void loadOrganizations();
138 void sortItemsRecursive(QVector<std::shared_ptr<TreeItem>>& items) noexcept;
139 void addCategoriesToModel(ui::LibraryTreeViewItemType type, TreeItem& root,
140 int count) noexcept;
142 TreeItem& item, ui::LibraryTreeViewItemType type,
143 slint::VectorModel<ui::LibraryTreeViewItemData>& model,
144 int level) noexcept;
146 const std::optional<ui::LibraryTreeViewItemData>& data) noexcept;
147 void getChildsRecursive(TreeItem& item,
148 QSet<std::shared_ptr<TreeItem>>& childs) noexcept;
149 QList<std::shared_ptr<TreeItem>> getSelectedCategories() const noexcept;
150 QList<std::shared_ptr<TreeItem>> getSelectedElements() const noexcept;
152 const QList<std::shared_ptr<TreeItem>>& items) noexcept;
153 void moveOrCopyElementsTo(const QList<std::shared_ptr<TreeItem>>& items,
154 const FilePath& dstLib, bool move) noexcept;
155 void deleteElements(const QList<std::shared_ptr<TreeItem>>& items) noexcept;
156
157private:
160 const QStringList& mLocaleOrder;
161
162 // State
167 std::shared_ptr<slint::VectorModel<float>> mViewsScrollPositions;
168 QString mFilterTerm;
169
170 // Library metadata to be applied
171 QByteArray mIcon;
172 slint::SharedString mName;
173 slint::SharedString mNameError;
175 slint::SharedString mDescription;
176 slint::SharedString mKeywords;
177 slint::SharedString mAuthor;
178 slint::SharedString mVersion;
179 slint::SharedString mVersionError;
182 slint::SharedString mUrl;
183 slint::SharedString mUrlError;
185 slint::SharedString mManufacturer;
186
187 // Library content
196 QHash<QString, std::shared_ptr<TreeItem>> mLibElementsMap; // Key: user-data
197 std::shared_ptr<slint::VectorModel<ui::LibraryTreeViewItemData>> mCategories;
198 std::shared_ptr<slint::VectorModel<ui::LibraryTreeViewItemData>> mElements;
199 std::shared_ptr<slint::FilterModel<ui::LibraryTreeViewItemData>>
201 slint::SharedString mMoveOrCopyToLibraryPath;
202};
203
204/*******************************************************************************
205 * End of File
206 ******************************************************************************/
207
208} // namespace editor
209} // namespace librepcb
210
211#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:59
The LibraryDependenciesModel class.
Definition librarydependenciesmodel.h:50
The LibraryEditor class.
Definition libraryeditor.h:56
Specialized base class for all library editor tabs.
Definition libraryeditortab.h:55
The LibraryTab class.
Definition librarytab.h:56
slint::SharedString mVersionError
Definition librarytab.h:179
QHash< FilePath, Uuid > mLibCategories
Definition librarytab.h:188
std::optional< std::pair< RuleCheckMessageList, QSet< SExpression > > > runChecksImpl() override
Definition librarytab.cpp:407
void componentEditorRequested(LibraryEditor &editor, const FilePath &fp, bool copyFrom)
Library & mLibrary
Definition librarytab.h:158
int mCurrentCategoryIndex
Definition librarytab.h:165
slint::SharedString mName
Definition librarytab.h:172
QHash< QString, std::shared_ptr< TreeItem > > mLibElementsMap
Definition librarytab.h:196
const WorkspaceLibraryDb & mDb
Definition librarytab.h:159
void loadOrganizations()
Definition librarytab.cpp:726
void sortItemsRecursive(QVector< std::shared_ptr< TreeItem > > &items) noexcept
Definition librarytab.cpp:748
QList< std::shared_ptr< TreeItem > > getSelectedElements() const noexcept
Definition librarytab.cpp:894
slint::SharedString mDescription
Definition librarytab.h:175
void deleteElements(const QList< std::shared_ptr< TreeItem > > &items) noexcept
Definition librarytab.cpp:1055
std::shared_ptr< TreeItem > mUncategorizedRoot
Definition librarytab.h:189
slint::SharedString mVersion
Definition librarytab.h:178
std::shared_ptr< TreeItem > mCmpCatRoot
Definition librarytab.h:190
void setSelectedCategory(const std::optional< ui::LibraryTreeViewItemData > &data) noexcept
Definition librarytab.cpp:807
void componentCategoryEditorRequested(LibraryEditor &editor, const FilePath &fp, bool copyFrom)
int mOrganizationsElementCount
Definition librarytab.h:195
bool mWizardMode
Definition librarytab.h:163
bool mDeprecated
Definition librarytab.h:181
QString mFilterTerm
Definition librarytab.h:168
void packageCategoryEditorRequested(LibraryEditor &editor, const FilePath &fp, bool copyFrom)
int mCmpCatElementCount
Definition librarytab.h:191
std::shared_ptr< TreeItem > mPkgCatRoot
Definition librarytab.h:192
void messageApprovalChanged(const SExpression &approval, bool approved) noexcept override
Definition librarytab.cpp:433
QList< std::shared_ptr< TreeItem > > getSelectedCategories() const noexcept
Definition librarytab.cpp:881
void refreshLibElements() noexcept
Definition librarytab.cpp:522
bool autoFixImpl(const std::shared_ptr< const RuleCheckMessage > &msg, bool checkOnly) override
Definition librarytab.cpp:411
FilePath getDirectoryPath() const noexcept override
Definition librarytab.cpp:128
QByteArray mIcon
Definition librarytab.h:171
std::shared_ptr< slint::VectorModel< ui::LibraryTreeViewItemData > > mCategories
Definition librarytab.h:197
bool autoFixHelper(const std::shared_ptr< const RuleCheckMessage > &msg, bool checkOnly)
Definition librarytab.cpp:419
void setUiData(const ui::TabData &data) noexcept override
Definition librarytab.cpp:153
std::shared_ptr< TreeItem > createRootItem(ui::LibraryTreeViewItemType type) noexcept
Definition librarytab.cpp:613
Version mVersionParsed
Definition librarytab.h:180
void packageEditorRequested(LibraryEditor &editor, const FilePath &fp, bool copyFrom)
LibraryTab(const LibraryTab &other)=delete
std::shared_ptr< LibraryDependenciesModel > mDependencies
Definition librarytab.h:184
void commitUiData() noexcept
Definition librarytab.cpp:488
bool autoFix(const MessageType &msg)
slint::SharedString mNameError
Definition librarytab.h:173
std::shared_ptr< slint::VectorModel< float > > mViewsScrollPositions
Definition librarytab.h:167
int mPkgCatElementCount
Definition librarytab.h:193
slint::SharedString mKeywords
Definition librarytab.h:176
const QStringList & mLocaleOrder
Definition librarytab.h:160
void organizationEditorRequested(LibraryEditor &editor, const FilePath &fp, bool copyFrom)
void trigger(ui::TabAction a) noexcept override
Definition librarytab.cpp:256
void deviceEditorRequested(LibraryEditor &editor, const FilePath &fp, bool copyFrom)
std::shared_ptr< slint::FilterModel< ui::LibraryTreeViewItemData > > mFilteredElements
Definition librarytab.h:200
void loadElements(ui::LibraryTreeViewItemType type, ui::LibraryTreeViewItemType catType, TreeItem &root, int &count)
Definition librarytab.cpp:691
std::shared_ptr< TreeItem > getOrCreateCategory(ui::LibraryTreeViewItemType type, const Uuid &uuid, TreeItem &root)
Definition librarytab.cpp:646
slint::SharedString mManufacturer
Definition librarytab.h:185
std::shared_ptr< TreeItem > mOrganizationsRoot
Definition librarytab.h:194
void duplicateElements(const QList< std::shared_ptr< TreeItem > > &items) noexcept
Definition librarytab.cpp:907
slint::SharedString mMoveOrCopyToLibraryPath
Definition librarytab.h:201
void notifyDerivedUiDataChanged() noexcept override
Definition librarytab.cpp:440
slint::SharedString mUrl
Definition librarytab.h:182
void symbolEditorRequested(LibraryEditor &editor, const FilePath &fp, bool copyFrom)
ElementName mNameParsed
Definition librarytab.h:174
int mCurrentElementIndex
Definition librarytab.h:166
void getChildsRecursive(TreeItem &item, QSet< std::shared_ptr< TreeItem > > &childs) noexcept
Definition librarytab.cpp:873
slint::SharedString mAuthor
Definition librarytab.h:177
ui::TabData getUiData() const noexcept override
Definition librarytab.cpp:132
slint::SharedString mUrlError
Definition librarytab.h:183
void loadCategories(ui::LibraryTreeViewItemType type, TreeItem &root)
Definition librarytab.cpp:631
int mCurrentPageIndex
Definition librarytab.h:164
Signal< LibraryTab > onDerivedUiDataChanged
Definition librarytab.h:72
void moveOrCopyElementsTo(const QList< std::shared_ptr< TreeItem > > &items, const FilePath &dstLib, bool move) noexcept
Definition librarytab.cpp:950
void setDerivedUiData(const ui::LibraryTabData &data) noexcept
Definition librarytab.cpp:201
void refreshUiData() noexcept
Definition librarytab.cpp:467
ui::LibraryTabData getDerivedUiData() const noexcept
Definition librarytab.cpp:164
void addCategoriesToModel(ui::LibraryTreeViewItemType type, TreeItem &root, int count) noexcept
Definition librarytab.cpp:766
std::shared_ptr< slint::VectorModel< ui::LibraryTreeViewItemData > > mElements
Definition librarytab.h:198
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:67
FilePath path
Definition librarytab.h:61
ui::LibraryTreeViewItemType type
Definition librarytab.h:60
QString userData
Definition librarytab.h:66
QString summary
Definition librarytab.h:63
QString name
Definition librarytab.h:62
bool isDeprecated
Definition librarytab.h:64
bool isExternal
Definition librarytab.h:65