LibrePCB Developers Documentation
componentchooserdialog.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_COMPONENTCHOOSERDIALOG_H
21 #define LIBREPCB_LIBRARY_EDITOR_COMPONENTCHOOSERDIALOG_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
27 #include <librepcb/common/uuid.h>
28 
29 #include <QtCore>
30 #include <QtWidgets>
31 
32 #include <memory>
33 
34 /*******************************************************************************
35  * Namespace / Forward Declarations
36  ******************************************************************************/
37 namespace librepcb {
38 
39 class GraphicsScene;
40 class IF_GraphicsLayerProvider;
41 
42 namespace workspace {
43 class Workspace;
44 }
45 
46 namespace library {
47 
48 class Component;
49 class Symbol;
50 class SymbolPreviewGraphicsItem;
51 
52 namespace editor {
53 
54 namespace Ui {
55 class ComponentChooserDialog;
56 }
57 
58 /*******************************************************************************
59  * Class ComponentChooserDialog
60  ******************************************************************************/
61 
65 class ComponentChooserDialog final : public QDialog {
66  Q_OBJECT
67 
68 public:
69  // Constructors / Destructor
70  ComponentChooserDialog() = delete;
71  ComponentChooserDialog(const ComponentChooserDialog& other) = delete;
73  const IF_GraphicsLayerProvider* layerProvider,
74  QWidget* parent = nullptr) noexcept;
75  ~ComponentChooserDialog() noexcept;
76 
77  // Getters
78  const tl::optional<Uuid>& getSelectedComponentUuid() const noexcept {
79  return mSelectedComponentUuid;
80  }
81 
82  // Operator Overloadings
83  ComponentChooserDialog& operator=(const ComponentChooserDialog& rhs) = delete;
84 
85 private: // Methods
86  void searchEditTextChanged(const QString& text) noexcept;
87  void treeCategories_currentItemChanged(const QModelIndex& current,
88  const QModelIndex& previous) noexcept;
89  void listComponents_currentItemChanged(QListWidgetItem* current,
90  QListWidgetItem* previous) noexcept;
91  void listComponents_itemDoubleClicked(QListWidgetItem* item) noexcept;
92  void searchComponents(const QString& input);
93  void setSelectedCategory(const tl::optional<Uuid>& uuid) noexcept;
94  void setSelectedComponent(const tl::optional<Uuid>& uuid) noexcept;
95  void updatePreview(const FilePath& fp) noexcept;
96  void accept() noexcept override;
97  const QStringList& localeOrder() const noexcept;
98 
99 private: // Data
102  QScopedPointer<Ui::ComponentChooserDialog> mUi;
103  QScopedPointer<QAbstractItemModel> mCategoryTreeModel;
104  tl::optional<Uuid> mSelectedCategoryUuid;
105  tl::optional<Uuid> mSelectedComponentUuid;
106 
107  // preview
108  QScopedPointer<Component> mComponent;
109  QScopedPointer<GraphicsScene> mGraphicsScene;
110  QList<std::shared_ptr<Symbol>> mSymbols;
111  QList<std::shared_ptr<SymbolPreviewGraphicsItem>> mSymbolGraphicsItems;
112 };
113 
114 /*******************************************************************************
115  * End of File
116  ******************************************************************************/
117 
118 } // namespace editor
119 } // namespace library
120 } // namespace librepcb
121 
122 #endif // LIBREPCB_LIBRARY_EDITOR_COMPONENTCHOOSERDIALOG_H
The Workspace class represents a workspace with all its data (library, projects, settings, ...)
Definition: workspace.h:62
Definition: mainwindow.h:10
Definition: airwiresbuilder.cpp:32
QScopedPointer< Component > mComponent
Definition: componentchooserdialog.h:108
The IF_GraphicsLayerProvider class defines an interface for classes which provide layers...
Definition: graphicslayer.h:227
The ComponentChooserDialog class.
Definition: componentchooserdialog.h:65
const tl::optional< Uuid > & getSelectedComponentUuid() const noexcept
Definition: componentchooserdialog.h:78
tl::optional< Uuid > mSelectedComponentUuid
Definition: componentchooserdialog.h:105
This class represents absolute, well-formatted paths to files or directories.
Definition: filepath.h:127
QScopedPointer< QAbstractItemModel > mCategoryTreeModel
Definition: componentchooserdialog.h:103
tl::optional< Uuid > mSelectedCategoryUuid
Definition: componentchooserdialog.h:104
QScopedPointer< GraphicsScene > mGraphicsScene
Definition: componentchooserdialog.h:109
QScopedPointer< Ui::ComponentChooserDialog > mUi
Definition: componentchooserdialog.h:102
const workspace::Workspace & mWorkspace
Definition: componentchooserdialog.h:100
QList< std::shared_ptr< SymbolPreviewGraphicsItem > > mSymbolGraphicsItems
Definition: componentchooserdialog.h:111
QList< std::shared_ptr< Symbol > > mSymbols
Definition: componentchooserdialog.h:110
const IF_GraphicsLayerProvider * mLayerProvider
Definition: componentchooserdialog.h:101