LibrePCB Developers Documentation
addcomponentdialog.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_ADDCOMPONENTDIALOG_H
21#define LIBREPCB_EDITOR_ADDCOMPONENTDIALOG_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
26#include "../workspace/categorytreemodel.h"
28
33#include <optional/tl/optional.hpp>
34
35#include <QtCore>
36#include <QtWidgets>
37
38#include <memory>
39
40/*******************************************************************************
41 * Namespace / Forward Declarations
42 ******************************************************************************/
43namespace librepcb {
44
45class Component;
46class ComponentSymbolVariant;
47class Device;
48class Part;
49class Symbol;
50class WorkspaceLibraryDb;
51class WorkspaceSettings;
52
53namespace editor {
54
55class DefaultGraphicsLayerProvider;
56class FootprintGraphicsItem;
57class GraphicsScene;
58class PartInformationProvider;
59class PartInformationToolTip;
60class SymbolGraphicsItem;
61
62namespace Ui {
63class AddComponentDialog;
64}
65
66/*******************************************************************************
67 * Class AddComponentDialog
68 ******************************************************************************/
69
73class AddComponentDialog final : public QDialog {
74 Q_OBJECT
75
76 // Types
78 tl::optional<Uuid> uuid;
79 QString name;
80 bool deprecated = false;
82 QString pkgName;
84 bool match = false;
85 };
86
88 QString name;
89 bool deprecated = false;
90 QHash<FilePath, SearchResultDevice> devices;
91 bool match = false;
92 };
93
94 struct SearchResult {
95 QHash<FilePath, SearchResultComponent> components;
96 int deviceCount = 0;
97 int partsCount = 0;
98 };
99
100public:
101 // Constructors / Destructor
102 explicit AddComponentDialog(const WorkspaceLibraryDb& db,
103 const WorkspaceSettings& settings,
104 const QStringList& localeOrder,
105 const QStringList& normOrder,
106 QWidget* parent = nullptr);
107 ~AddComponentDialog() noexcept;
108
109 // Getters
110 std::shared_ptr<const Component> getSelectedComponent() const noexcept {
111 return mSelectedComponent;
112 }
113 std::shared_ptr<const ComponentSymbolVariant> getSelectedSymbolVariant()
114 const noexcept {
115 return mSelectedSymbVar;
116 }
117 std::shared_ptr<const Device> getSelectedDevice() const noexcept {
118 return mSelectedDevice;
119 }
120 std::shared_ptr<const Part> getSelectedPart() const noexcept {
121 return mSelectedPart;
122 }
123 tl::optional<Package::AssemblyType> getSelectedPackageAssemblyType()
124 const noexcept;
125
136 bool getAutoOpenAgain() const noexcept;
137
138 // Setters
139 void setLocaleOrder(const QStringList& order) noexcept;
140 void setNormOrder(const QStringList& order) noexcept { mNormOrder = order; }
141
142 // General Methods
144 const QString keyword,
145 const tl::optional<Uuid>& selectedDevice = tl::nullopt) noexcept;
146 virtual bool eventFilter(QObject* obj, QEvent* e) noexcept override;
147
148protected:
149 virtual bool event(QEvent* event) noexcept override;
150
151private slots:
152 void searchEditTextChanged(const QString& text) noexcept;
153 void treeCategories_currentItemChanged(const QModelIndex& current,
154 const QModelIndex& previous) noexcept;
155 void treeComponents_currentItemChanged(QTreeWidgetItem* current,
156 QTreeWidgetItem* previous) noexcept;
157 void treeComponents_itemDoubleClicked(QTreeWidgetItem* item,
158 int column) noexcept;
159 void treeComponents_itemExpanded(QTreeWidgetItem* item) noexcept;
160 void cbxSymbVar_currentIndexChanged(int index) noexcept;
161 void customComponentsContextMenuRequested(const QPoint& pos) noexcept;
162
163private:
164 // Private Methods
165 void searchComponents(const QString& input,
166 const tl::optional<Uuid>& selectedDevice = tl::nullopt,
167 bool selectFirstDevice = false);
168 SearchResult search(const QString& input);
169 void setSelectedCategory(const tl::optional<Uuid>& categoryUuid);
170 void setSelectedComponent(std::shared_ptr<const Component> cmp);
172 std::shared_ptr<const ComponentSymbolVariant> symbVar);
173 void setSelectedDevice(std::shared_ptr<const Device> dev);
174 void setSelectedPart(std::shared_ptr<const Part> part);
175 void addPartItem(std::shared_ptr<Part> part, QTreeWidgetItem* parent);
176 void schedulePartsInformationUpdate() noexcept;
177 void updatePartsInformation(int downloadDelayMs = 0) noexcept;
178 virtual void accept() noexcept override;
179
180 // General
183 QStringList mLocaleOrder;
184 QStringList mNormOrder;
185 QScopedPointer<Ui::AddComponentDialog> mUi;
196
197 // Attributes
199 std::shared_ptr<const Component> mSelectedComponent;
201 std::shared_ptr<const Device> mSelectedDevice;
202 std::unique_ptr<Package> mSelectedPackage;
203 std::shared_ptr<const Part> mSelectedPart;
204 QList<std::shared_ptr<Symbol>> mPreviewSymbols;
207
208 // Actions
209 QScopedPointer<QAction> mActionCopyMpn;
210};
211
212/*******************************************************************************
213 * End of File
214 ******************************************************************************/
215
216} // namespace editor
217} // namespace librepcb
218
219#endif
The Component class represents a "generic" device in the library.
Definition: component.h:73
The ComponentSymbolVariant class represents a symbol variant of a component.
Definition: componentsymbolvariant.h:53
The Device class represents an instance of a component (a "real" component)
Definition: device.h:55
This class represents absolute, well-formatted paths to files or directories.
Definition: filepath.h:129
The Package class represents a package of a component (including footprint and 3D model)
Definition: package.h:59
The Part class.
Definition: part.h:46
The Symbol class represents the part of a component which is added to schematics.
Definition: symbol.h:55
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:58
The WorkspaceLibraryDb class.
Definition: workspacelibrarydb.h:57
Container for all workspace related settings.
Definition: workspacesettings.h:60
The AddComponentDialog class.
Definition: addcomponentdialog.h:73
void treeComponents_itemExpanded(QTreeWidgetItem *item) noexcept
Definition: addcomponentdialog.cpp:429
void treeComponents_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous) noexcept
Definition: addcomponentdialog.cpp:362
QScopedPointer< FootprintGraphicsItem > mPreviewFootprintGraphicsItem
Definition: addcomponentdialog.h:206
std::shared_ptr< const Device > getSelectedDevice() const noexcept
Definition: addcomponentdialog.h:117
QList< std::shared_ptr< SymbolGraphicsItem > > mPreviewSymbolGraphicsItems
Definition: addcomponentdialog.h:205
void updatePartsInformation(int downloadDelayMs=0) noexcept
Definition: addcomponentdialog.cpp:912
QScopedPointer< PartInformationToolTip > mPartToolTip
Definition: addcomponentdialog.h:190
uint mPartInfoProgress
Definition: addcomponentdialog.h:191
void setSelectedSymbVar(std::shared_ptr< const ComponentSymbolVariant > symbVar)
Definition: addcomponentdialog.cpp:818
void customComponentsContextMenuRequested(const QPoint &pos) noexcept
Definition: addcomponentdialog.cpp:450
std::shared_ptr< const Component > mSelectedComponent
Definition: addcomponentdialog.h:199
tl::optional< Package::AssemblyType > getSelectedPackageAssemblyType() const noexcept
Definition: addcomponentdialog.cpp:279
const WorkspaceLibraryDb & mDb
Definition: addcomponentdialog.h:181
std::shared_ptr< const ComponentSymbolVariant > getSelectedSymbolVariant() const noexcept
Definition: addcomponentdialog.h:113
QScopedPointer< Ui::AddComponentDialog > mUi
Definition: addcomponentdialog.h:185
QScopedPointer< GraphicsScene > mDevicePreviewScene
Definition: addcomponentdialog.h:187
QScopedPointer< DefaultGraphicsLayerProvider > mGraphicsLayerProvider
Definition: addcomponentdialog.h:188
bool getAutoOpenAgain() const noexcept
Check if dialog shall be opened again after the current component.
Definition: addcomponentdialog.cpp:286
std::shared_ptr< const Device > mSelectedDevice
Definition: addcomponentdialog.h:201
tl::optional< Uuid > mSelectedCategoryUuid
Definition: addcomponentdialog.h:198
void addPartItem(std::shared_ptr< Part > part, QTreeWidgetItem *parent)
Definition: addcomponentdialog.cpp:888
void treeCategories_currentItemChanged(const QModelIndex &current, const QModelIndex &previous) noexcept
Definition: addcomponentdialog.cpp:348
void cbxSymbVar_currentIndexChanged(int index) noexcept
Definition: addcomponentdialog.cpp:436
QScopedPointer< CategoryTreeModel > mCategoryTreeModel
Definition: addcomponentdialog.h:189
void setSelectedCategory(const tl::optional< Uuid > &categoryUuid)
Definition: addcomponentdialog.cpp:710
virtual bool event(QEvent *event) noexcept override
Definition: addcomponentdialog.cpp:318
qint64 mUpdatePartInformationDownloadStart
Definition: addcomponentdialog.h:193
void setSelectedDevice(std::shared_ptr< const Device > dev)
Definition: addcomponentdialog.cpp:848
QScopedPointer< QAction > mActionCopyMpn
Definition: addcomponentdialog.h:209
SearchResult search(const QString &input)
Definition: addcomponentdialog.cpp:590
void setNormOrder(const QStringList &order) noexcept
Definition: addcomponentdialog.h:140
const WorkspaceSettings & mSettings
Definition: addcomponentdialog.h:182
void treeComponents_itemDoubleClicked(QTreeWidgetItem *item, int column) noexcept
Definition: addcomponentdialog.cpp:415
std::shared_ptr< const Part > mSelectedPart
Definition: addcomponentdialog.h:203
void setSelectedPart(std::shared_ptr< const Part > part)
Definition: addcomponentdialog.cpp:882
void searchEditTextChanged(const QString &text) noexcept
Definition: addcomponentdialog.cpp:329
~AddComponentDialog() noexcept
Definition: addcomponentdialog.cpp:256
void schedulePartsInformationUpdate() noexcept
Definition: addcomponentdialog.cpp:908
QStringList mNormOrder
Definition: addcomponentdialog.h:184
void setSelectedComponent(std::shared_ptr< const Component > cmp)
Definition: addcomponentdialog.cpp:784
std::shared_ptr< const ComponentSymbolVariant > mSelectedSymbVar
Definition: addcomponentdialog.h:200
bool mUpdatePartInformationOnExpand
Definition: addcomponentdialog.h:194
void selectComponentByKeyword(const QString keyword, const tl::optional< Uuid > &selectedDevice=tl::nullopt) noexcept
Definition: addcomponentdialog.cpp:294
QString mCurrentSearchTerm
Definition: addcomponentdialog.h:195
AddComponentDialog(const WorkspaceLibraryDb &db, const WorkspaceSettings &settings, const QStringList &localeOrder, const QStringList &normOrder, QWidget *parent=nullptr)
Definition: addcomponentdialog.cpp:64
bool mUpdatePartInformationScheduled
Definition: addcomponentdialog.h:192
std::shared_ptr< const Component > getSelectedComponent() const noexcept
Definition: addcomponentdialog.h:110
QScopedPointer< GraphicsScene > mComponentPreviewScene
Definition: addcomponentdialog.h:186
std::shared_ptr< const Part > getSelectedPart() const noexcept
Definition: addcomponentdialog.h:120
QStringList mLocaleOrder
Definition: addcomponentdialog.h:183
std::unique_ptr< Package > mSelectedPackage
Definition: addcomponentdialog.h:202
void setLocaleOrder(const QStringList &order) noexcept
Definition: addcomponentdialog.cpp:269
QList< std::shared_ptr< Symbol > > mPreviewSymbols
Definition: addcomponentdialog.h:204
virtual bool eventFilter(QObject *obj, QEvent *e) noexcept override
Definition: addcomponentdialog.cpp:304
void searchComponents(const QString &input, const tl::optional< Uuid > &selectedDevice=tl::nullopt, bool selectFirstDevice=false)
Definition: addcomponentdialog.cpp:496
virtual void accept() noexcept override
Definition: addcomponentdialog.cpp:998
The CategoryTreeModel class.
Definition: categorytreemodel.h:48
The DefaultGraphicsLayerProvider class.
Definition: defaultgraphicslayerprovider.h:46
The FootprintGraphicsItem class.
Definition: footprintgraphicsitem.h:66
The GraphicsScene class.
Definition: graphicsscene.h:45
The PartInformationToolTip class.
Definition: partinformationtooltip.h:56
The SymbolGraphicsItem class.
Definition: symbolgraphicsitem.h:56
Definition: occmodel.cpp:77
Definition: uuid.h:183
bool deprecated
Definition: addcomponentdialog.h:89
bool match
Definition: addcomponentdialog.h:91
QString name
Definition: addcomponentdialog.h:88
QHash< FilePath, SearchResultDevice > devices
Definition: addcomponentdialog.h:90
bool deprecated
Definition: addcomponentdialog.h:80
bool match
Definition: addcomponentdialog.h:84
tl::optional< Uuid > uuid
Definition: addcomponentdialog.h:78
QString name
Definition: addcomponentdialog.h:79
PartList parts
Definition: addcomponentdialog.h:83
FilePath pkgFp
Definition: addcomponentdialog.h:81
QString pkgName
Definition: addcomponentdialog.h:82
Definition: addcomponentdialog.h:94
int partsCount
Definition: addcomponentdialog.h:97
QHash< FilePath, SearchResultComponent > components
Definition: addcomponentdialog.h:95
int deviceCount
Definition: addcomponentdialog.h:96