LibrePCB Developers Documentation
Loading...
Searching...
No Matches
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
34#include <QtCore>
35#include <QtWidgets>
36
37#include <memory>
38#include <optional>
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 std::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 std::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 std::optional<Uuid>& selectedDevice = std::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(
166 const QString& input,
167 const std::optional<Uuid>& selectedDevice = std::nullopt,
168 bool selectFirstDevice = false);
169 SearchResult search(const QString& input);
170 void setSelectedCategory(const std::optional<Uuid>& categoryUuid);
171 void setSelectedComponent(std::shared_ptr<const Component> cmp);
173 std::shared_ptr<const ComponentSymbolVariant> symbVar);
174 void setSelectedDevice(std::shared_ptr<const Device> dev);
175 void setSelectedPart(std::shared_ptr<const Part> part);
176 void addPartItem(std::shared_ptr<Part> part, QTreeWidgetItem* parent);
177 void schedulePartsInformationUpdate() noexcept;
178 void updatePartsInformation(int downloadDelayMs = 0) noexcept;
179 virtual void accept() noexcept override;
180
181 // General
184 QStringList mLocaleOrder;
185 QStringList mNormOrder;
186 QScopedPointer<Ui::AddComponentDialog> mUi;
197
198 // Attributes
200 std::shared_ptr<const Component> mSelectedComponent;
202 std::shared_ptr<const Device> mSelectedDevice;
204 std::shared_ptr<const Part> mSelectedPart;
205 QList<std::shared_ptr<Symbol>> mPreviewSymbols;
208
209 // Actions
210 QScopedPointer<QAction> mActionCopyMpn;
211};
212
213/*******************************************************************************
214 * End of File
215 ******************************************************************************/
216
217} // namespace editor
218} // namespace librepcb
219
220#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:127
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:56
The WorkspaceLibraryDb class.
Definition workspacelibrarydb.h:58
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:207
void selectComponentByKeyword(const QString keyword, const std::optional< Uuid > &selectedDevice=std::nullopt) noexcept
Definition addcomponentdialog.cpp:294
std::shared_ptr< const Device > getSelectedDevice() const noexcept
Definition addcomponentdialog.h:117
std::optional< Package::AssemblyType > getSelectedPackageAssemblyType() const noexcept
Definition addcomponentdialog.cpp:279
QList< std::shared_ptr< SymbolGraphicsItem > > mPreviewSymbolGraphicsItems
Definition addcomponentdialog.h:206
void updatePartsInformation(int downloadDelayMs=0) noexcept
Definition addcomponentdialog.cpp:912
QScopedPointer< PartInformationToolTip > mPartToolTip
Definition addcomponentdialog.h:191
uint mPartInfoProgress
Definition addcomponentdialog.h:192
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:200
const WorkspaceLibraryDb & mDb
Definition addcomponentdialog.h:182
std::shared_ptr< const ComponentSymbolVariant > getSelectedSymbolVariant() const noexcept
Definition addcomponentdialog.h:113
QScopedPointer< Ui::AddComponentDialog > mUi
Definition addcomponentdialog.h:186
QScopedPointer< GraphicsScene > mDevicePreviewScene
Definition addcomponentdialog.h:188
QScopedPointer< DefaultGraphicsLayerProvider > mGraphicsLayerProvider
Definition addcomponentdialog.h:189
std::optional< Uuid > mSelectedCategoryUuid
Definition addcomponentdialog.h:199
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:202
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:190
virtual bool event(QEvent *event) noexcept override
Definition addcomponentdialog.cpp:318
qint64 mUpdatePartInformationDownloadStart
Definition addcomponentdialog.h:194
void searchComponents(const QString &input, const std::optional< Uuid > &selectedDevice=std::nullopt, bool selectFirstDevice=false)
Definition addcomponentdialog.cpp:496
void setSelectedDevice(std::shared_ptr< const Device > dev)
Definition addcomponentdialog.cpp:848
QScopedPointer< QAction > mActionCopyMpn
Definition addcomponentdialog.h:210
SearchResult search(const QString &input)
Definition addcomponentdialog.cpp:590
void setSelectedCategory(const std::optional< Uuid > &categoryUuid)
Definition addcomponentdialog.cpp:710
void setNormOrder(const QStringList &order) noexcept
Definition addcomponentdialog.h:140
const WorkspaceSettings & mSettings
Definition addcomponentdialog.h:183
void treeComponents_itemDoubleClicked(QTreeWidgetItem *item, int column) noexcept
Definition addcomponentdialog.cpp:415
std::shared_ptr< const Part > mSelectedPart
Definition addcomponentdialog.h:204
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:185
void setSelectedComponent(std::shared_ptr< const Component > cmp)
Definition addcomponentdialog.cpp:784
std::shared_ptr< const ComponentSymbolVariant > mSelectedSymbVar
Definition addcomponentdialog.h:201
bool mUpdatePartInformationOnExpand
Definition addcomponentdialog.h:195
QString mCurrentSearchTerm
Definition addcomponentdialog.h:196
bool mUpdatePartInformationScheduled
Definition addcomponentdialog.h:193
std::shared_ptr< const Component > getSelectedComponent() const noexcept
Definition addcomponentdialog.h:110
QScopedPointer< GraphicsScene > mComponentPreviewScene
Definition addcomponentdialog.h:187
std::shared_ptr< const Part > getSelectedPart() const noexcept
Definition addcomponentdialog.h:120
QStringList mLocaleOrder
Definition addcomponentdialog.h:184
std::unique_ptr< Package > mSelectedPackage
Definition addcomponentdialog.h:203
void setLocaleOrder(const QStringList &order) noexcept
Definition addcomponentdialog.cpp:269
QList< std::shared_ptr< Symbol > > mPreviewSymbols
Definition addcomponentdialog.h:205
virtual bool eventFilter(QObject *obj, QEvent *e) noexcept override
Definition addcomponentdialog.cpp:304
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:76
Definition uuid.h:186
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
std::optional< Uuid > uuid
Definition addcomponentdialog.h:78
bool match
Definition addcomponentdialog.h:84
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