LibrePCB Developers Documentation
libraryoverviewwidget.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_LIBRARYOVERVIEWWIDGET_H
21 #define LIBREPCB_LIBRARY_EDITOR_LIBRARYOVERVIEWWIDGET_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
26 #include "../common/editorwidgetbase.h"
27 
28 #include <QtCore>
29 #include <QtWidgets>
30 
31 /*******************************************************************************
32  * Namespace / Forward Declarations
33  ******************************************************************************/
34 namespace librepcb {
35 namespace library {
36 
37 class Library;
38 
39 namespace editor {
40 
41 class LibraryListEditorWidget;
42 
43 namespace Ui {
44 class LibraryOverviewWidget;
45 }
46 
47 /*******************************************************************************
48  * Class LibraryOverviewWidget
49  ******************************************************************************/
50 
55  Q_OBJECT
56 
57  struct LibraryMenuItem {
58  QString name;
59  QPixmap pixmap;
61  };
62 
63 public:
64  // Constructors / Destructor
65  LibraryOverviewWidget() = delete;
66  LibraryOverviewWidget(const LibraryOverviewWidget& other) = delete;
67  LibraryOverviewWidget(const Context& context, const FilePath& fp,
68  QWidget* parent = nullptr) noexcept;
69  ~LibraryOverviewWidget() noexcept;
70 
71  // Getters
72  Library& getLibrary() const noexcept { return *mLibrary; }
73 
74  // Operator Overloadings
75  LibraryOverviewWidget& operator=(const LibraryOverviewWidget& rhs) = delete;
76 
77 public slots:
78  bool save() noexcept override;
79  bool remove() noexcept override;
80 
81 signals:
82  void newComponentCategoryTriggered();
83  void newPackageCategoryTriggered();
84  void newSymbolTriggered();
85  void newPackageTriggered();
86  void newComponentTriggered();
87  void newDeviceTriggered();
88  void editComponentCategoryTriggered(const FilePath& fp);
89  void editPackageCategoryTriggered(const FilePath& fp);
90  void editSymbolTriggered(const FilePath& fp);
91  void editPackageTriggered(const FilePath& fp);
92  void editComponentTriggered(const FilePath& fp);
93  void editDeviceTriggered(const FilePath& fp);
94  void duplicateComponentCategoryTriggered(const FilePath& fp);
95  void duplicatePackageCategoryTriggered(const FilePath& fp);
96  void duplicateSymbolTriggered(const FilePath& fp);
97  void duplicatePackageTriggered(const FilePath& fp);
98  void duplicateComponentTriggered(const FilePath& fp);
99  void duplicateDeviceTriggered(const FilePath& fp);
100  void removeElementTriggered(const FilePath& fp);
101 
102 private: // Methods
103  void updateMetadata() noexcept;
104  QString commitMetadata() noexcept;
105  bool isInterfaceBroken() const noexcept override { return false; }
106  bool runChecks(LibraryElementCheckMessageList& msgs) const override;
107  template <typename MessageType>
108  void fixMsg(const MessageType& msg);
109  template <typename MessageType>
110  bool fixMsgHelper(std::shared_ptr<const LibraryElementCheckMessage> msg,
111  bool applyFix);
112  bool processCheckMessage(
113  std::shared_ptr<const LibraryElementCheckMessage> msg,
114  bool applyFix) override;
115  void updateElementLists() noexcept;
116  template <typename ElementType>
117  void updateElementList(QListWidget& listWidget, const QIcon& icon) noexcept;
118  QHash<QListWidgetItem*, FilePath> getElementListItemFilePaths(
119  const QList<QListWidgetItem*>& items) const noexcept;
120  void openContextMenuAtPos(const QPoint& pos) noexcept;
121  void newItem(QListWidget* list) noexcept;
122  void editItem(QListWidget* list, const FilePath& fp) noexcept;
123  void duplicateItem(QListWidget* list, const FilePath& fp) noexcept;
124  void removeItems(
125  const QHash<QListWidgetItem*, FilePath>& selectedItemPaths) noexcept;
126  void moveElementsToOtherLibrary(
127  const QHash<QListWidgetItem*, FilePath>& selectedItemPaths,
128  const FilePath& libFp, const QString& libName) noexcept;
129  QList<LibraryMenuItem> getLocalLibraries() const noexcept;
130 
131  // Event Handlers
132  void btnIconClicked() noexcept;
133  void lstDoubleClicked(const QModelIndex& index) noexcept;
134 
135 private: // Data
136  QScopedPointer<Ui::LibraryOverviewWidget> mUi;
137  QScopedPointer<LibraryListEditorWidget> mDependenciesEditorWidget;
138  QSharedPointer<Library> mLibrary;
139  QByteArray mIcon;
140 };
141 
142 /*******************************************************************************
143  * End of File
144  ******************************************************************************/
145 
146 } // namespace editor
147 } // namespace library
148 } // namespace librepcb
149 
150 #endif // LIBREPCB_LIBRARY_EDITOR_LIBRARYOVERVIEWWIDGET_H
QVector< std::shared_ptr< const LibraryElementCheckMessage > > LibraryElementCheckMessageList
Definition: libraryelementcheckmessage.h:96
The LibraryOverviewWidget class.
Definition: libraryoverviewwidget.h:54
Definition: mainwindow.h:10
bool isInterfaceBroken() const noexcept override
Definition: libraryoverviewwidget.h:105
The Library class represents a library directory.
Definition: library.h:46
Definition: alignment.cpp:30
QString name
Definition: libraryoverviewwidget.h:58
QSharedPointer< Library > mLibrary
Definition: libraryoverviewwidget.h:138
QScopedPointer< Ui::LibraryOverviewWidget > mUi
Definition: libraryoverviewwidget.h:136
QPixmap pixmap
Definition: libraryoverviewwidget.h:59
QByteArray mIcon
Definition: libraryoverviewwidget.h:139
This class represents absolute, well-formatted paths to files or directories.
Definition: filepath.h:127
QScopedPointer< LibraryListEditorWidget > mDependenciesEditorWidget
Definition: libraryoverviewwidget.h:137
FilePath filepath
Definition: libraryoverviewwidget.h:60
The EditorWidgetBase class.
Definition: editorwidgetbase.h:62