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  // Setters
72  void setFilter(const QString& filter) noexcept;
73 
74  // Getters
75  Library& getLibrary() const noexcept { return *mLibrary; }
76 
77  // Operator Overloadings
78  LibraryOverviewWidget& operator=(const LibraryOverviewWidget& rhs) = delete;
79 
80 public slots:
81  bool save() noexcept override;
82  bool remove() noexcept override;
83 
84 signals:
85  void newComponentCategoryTriggered();
86  void newPackageCategoryTriggered();
87  void newSymbolTriggered();
88  void newPackageTriggered();
89  void newComponentTriggered();
90  void newDeviceTriggered();
91  void editComponentCategoryTriggered(const FilePath& fp);
92  void editPackageCategoryTriggered(const FilePath& fp);
93  void editSymbolTriggered(const FilePath& fp);
94  void editPackageTriggered(const FilePath& fp);
95  void editComponentTriggered(const FilePath& fp);
96  void editDeviceTriggered(const FilePath& fp);
97  void duplicateComponentCategoryTriggered(const FilePath& fp);
98  void duplicatePackageCategoryTriggered(const FilePath& fp);
99  void duplicateSymbolTriggered(const FilePath& fp);
100  void duplicatePackageTriggered(const FilePath& fp);
101  void duplicateComponentTriggered(const FilePath& fp);
102  void duplicateDeviceTriggered(const FilePath& fp);
103  void removeElementTriggered(const FilePath& fp);
104 
105 private: // Methods
106  void updateMetadata() noexcept;
107  QString commitMetadata() noexcept;
108  bool isInterfaceBroken() const noexcept override { return false; }
109  bool runChecks(LibraryElementCheckMessageList& msgs) const override;
110  template <typename MessageType>
111  void fixMsg(const MessageType& msg);
112  template <typename MessageType>
113  bool fixMsgHelper(std::shared_ptr<const LibraryElementCheckMessage> msg,
114  bool applyFix);
115  bool processCheckMessage(
116  std::shared_ptr<const LibraryElementCheckMessage> msg,
117  bool applyFix) override;
118  void updateElementLists() noexcept;
119  template <typename ElementType>
120  void updateElementList(QListWidget& listWidget, const QIcon& icon) noexcept;
121  QHash<QListWidgetItem*, FilePath> getElementListItemFilePaths(
122  const QList<QListWidgetItem*>& items) const noexcept;
123  void updateElementListFilter(QListWidget& listWidget) noexcept;
124  void openContextMenuAtPos(const QPoint& pos) noexcept;
125  void newItem(QListWidget* list) noexcept;
126  void editItem(QListWidget* list, const FilePath& fp) noexcept;
127  void duplicateItem(QListWidget* list, const FilePath& fp) noexcept;
128  void removeItems(
129  const QHash<QListWidgetItem*, FilePath>& selectedItemPaths) noexcept;
130  void moveElementsToOtherLibrary(
131  const QHash<QListWidgetItem*, FilePath>& selectedItemPaths,
132  const FilePath& libFp, const QString& libName) noexcept;
133  QList<LibraryMenuItem> getLocalLibraries() const noexcept;
134 
135  // Event Handlers
136  void btnIconClicked() noexcept;
137  void lstDoubleClicked(const QModelIndex& index) noexcept;
138 
139 private: // Data
140  QScopedPointer<Ui::LibraryOverviewWidget> mUi;
141  QScopedPointer<LibraryListEditorWidget> mDependenciesEditorWidget;
142  QSharedPointer<Library> mLibrary;
143  QByteArray mIcon;
144  QString mCurrentFilter;
145 };
146 
147 /*******************************************************************************
148  * End of File
149  ******************************************************************************/
150 
151 } // namespace editor
152 } // namespace library
153 } // namespace librepcb
154 
155 #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:108
The Library class represents a library directory.
Definition: library.h:46
Definition: airwiresbuilder.cpp:32
QString name
Definition: libraryoverviewwidget.h:58
QSharedPointer< Library > mLibrary
Definition: libraryoverviewwidget.h:142
QScopedPointer< Ui::LibraryOverviewWidget > mUi
Definition: libraryoverviewwidget.h:140
QString mCurrentFilter
Definition: libraryoverviewwidget.h:144
QPixmap pixmap
Definition: libraryoverviewwidget.h:59
QByteArray mIcon
Definition: libraryoverviewwidget.h:143
This class represents absolute, well-formatted paths to files or directories.
Definition: filepath.h:127
QScopedPointer< LibraryListEditorWidget > mDependenciesEditorWidget
Definition: libraryoverviewwidget.h:141
FilePath filepath
Definition: libraryoverviewwidget.h:60
The EditorWidgetBase class.
Definition: editorwidgetbase.h:63