LibrePCB Developers Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 public:
58  // Constructors / Destructor
59  LibraryOverviewWidget() = delete;
60  LibraryOverviewWidget(const LibraryOverviewWidget& other) = delete;
61  LibraryOverviewWidget(const Context& context, const FilePath& fp,
62  QWidget* parent = nullptr) noexcept;
63  ~LibraryOverviewWidget() noexcept;
64 
65  // Getters
66  Library& getLibrary() const noexcept { return *mLibrary; }
67 
68  // Operator Overloadings
70 
71 public slots:
72  bool save() noexcept override;
73  bool remove() noexcept override;
74 
75 signals:
78  void newSymbolTriggered();
79  void newPackageTriggered();
80  void newComponentTriggered();
81  void newDeviceTriggered();
83  void editPackageCategoryTriggered(const FilePath& fp);
84  void editSymbolTriggered(const FilePath& fp);
85  void editPackageTriggered(const FilePath& fp);
86  void editComponentTriggered(const FilePath& fp);
87  void editDeviceTriggered(const FilePath& fp);
90  void duplicateSymbolTriggered(const FilePath& fp);
91  void duplicatePackageTriggered(const FilePath& fp);
92  void duplicateComponentTriggered(const FilePath& fp);
93  void duplicateDeviceTriggered(const FilePath& fp);
94  void removeElementTriggered(const FilePath& fp);
95 
96 private: // Methods
97  void updateMetadata() noexcept;
98  QString commitMetadata() noexcept;
99  bool isInterfaceBroken() const noexcept override { return false; }
100  bool runChecks(LibraryElementCheckMessageList& msgs) const override;
101  template <typename MessageType>
102  void fixMsg(const MessageType& msg);
103  template <typename MessageType>
104  bool fixMsgHelper(std::shared_ptr<const LibraryElementCheckMessage> msg,
105  bool applyFix);
106  bool processCheckMessage(
107  std::shared_ptr<const LibraryElementCheckMessage> msg,
108  bool applyFix) override;
109  void updateElementLists() noexcept;
110  template <typename ElementType>
111  void updateElementList(QListWidget& listWidget, const QIcon& icon) noexcept;
112  QHash<QListWidgetItem*, FilePath> getElementListItemFilePaths(
113  const QList<QListWidgetItem*>& items) const noexcept;
114  void openContextMenuAtPos(const QPoint& pos) noexcept;
115  void newItem(QListWidget* list) noexcept;
116  void editItem(QListWidget* list, const FilePath& fp) noexcept;
117  void duplicateItem(QListWidget* list, const FilePath& fp) noexcept;
118  void removeItems(
119  const QHash<QListWidgetItem*, FilePath>& selectedItemPaths) noexcept;
120 
121  // Event Handlers
122  void btnIconClicked() noexcept;
123  void lstDoubleClicked(const QModelIndex& index) noexcept;
124 
125 private: // Data
126  QScopedPointer<Ui::LibraryOverviewWidget> mUi;
128  QSharedPointer<Library> mLibrary;
129  QByteArray mIcon;
130 };
131 
132 /*******************************************************************************
133  * End of File
134  ******************************************************************************/
135 
136 } // namespace editor
137 } // namespace library
138 } // namespace librepcb
139 
140 #endif // LIBREPCB_LIBRARY_EDITOR_LIBRARYOVERVIEWWIDGET_H
QVector< std::shared_ptr< const LibraryElementCheckMessage > > LibraryElementCheckMessageList
Definition: libraryelementcheckmessage.h:96
The LibraryOverviewWidget class.
Definition: libraryoverviewwidget.h:54
The Library class represents a library directory.
Definition: library.h:46
QSharedPointer< Library > mLibrary
Definition: libraryoverviewwidget.h:128
void removeItems(const QHash< QListWidgetItem *, FilePath > &selectedItemPaths) noexcept
Definition: libraryoverviewwidget.cpp:441
LibraryOverviewWidget & operator=(const LibraryOverviewWidget &rhs)=delete
QScopedPointer< Ui::LibraryOverviewWidget > mUi
Definition: libraryoverviewwidget.h:126
void updateElementLists() noexcept
Definition: libraryoverviewwidget.cpp:263
void duplicateItem(QListWidget *list, const FilePath &fp) noexcept
Definition: libraryoverviewwidget.cpp:403
Library & getLibrary() const noexcept
Definition: libraryoverviewwidget.h:66
void editItem(QListWidget *list, const FilePath &fp) noexcept
Definition: libraryoverviewwidget.cpp:422
The LibraryListEditorWidget class.
Definition: librarylisteditorwidget.h:54
void duplicateComponentCategoryTriggered(const FilePath &fp)
void duplicatePackageCategoryTriggered(const FilePath &fp)
QString commitMetadata() noexcept
Definition: libraryoverviewwidget.cpp:192
QByteArray mIcon
Definition: libraryoverviewwidget.h:129
void updateElementList(QListWidget &listWidget, const QIcon &icon) noexcept
Definition: libraryoverviewwidget.cpp:276
void editComponentCategoryTriggered(const FilePath &fp)
bool runChecks(LibraryElementCheckMessageList &msgs) const override
Definition: libraryoverviewwidget.cpp:224
void editPackageCategoryTriggered(const FilePath &fp)
void updateMetadata() noexcept
Definition: libraryoverviewwidget.cpp:171
void duplicatePackageTriggered(const FilePath &fp)
void lstDoubleClicked(const QModelIndex &index) noexcept
Definition: libraryoverviewwidget.cpp:500
bool fixMsgHelper(std::shared_ptr< const LibraryElementCheckMessage > msg, bool applyFix)
Definition: libraryoverviewwidget.cpp:245
void btnIconClicked() noexcept
Definition: libraryoverviewwidget.cpp:485
void newItem(QListWidget *list) noexcept
Definition: libraryoverviewwidget.cpp:385
bool save() noexceptoverride
Definition: libraryoverviewwidget.cpp:137
This class represents absolute, well-formatted paths to files or directories.
Definition: filepath.h:127
bool isInterfaceBroken() const noexceptoverride
Definition: libraryoverviewwidget.h:99
QScopedPointer< LibraryListEditorWidget > mDependenciesEditorWidget
Definition: libraryoverviewwidget.h:127
bool remove() noexceptoverride
Definition: libraryoverviewwidget.cpp:156
~LibraryOverviewWidget() noexcept
Definition: libraryoverviewwidget.cpp:130
void openContextMenuAtPos(const QPoint &pos) noexcept
Definition: libraryoverviewwidget.cpp:340
void duplicateComponentTriggered(const FilePath &fp)
QHash< QListWidgetItem *, FilePath > getElementListItemFilePaths(const QList< QListWidgetItem * > &items) const noexcept
Definition: libraryoverviewwidget.cpp:326
bool processCheckMessage(std::shared_ptr< const LibraryElementCheckMessage > msg, bool applyFix) override
Definition: libraryoverviewwidget.cpp:256
The EditorWidgetBase class.
Definition: editorwidgetbase.h:62