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