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 
58  Q_OBJECT
59 
60 public:
61  // Constructors / Destructor
62  LibraryOverviewWidget() = delete;
63  LibraryOverviewWidget(const LibraryOverviewWidget& other) = delete;
64  LibraryOverviewWidget(const Context& context, const FilePath& fp,
65  QWidget* parent = nullptr) noexcept;
66  ~LibraryOverviewWidget() noexcept;
67 
68  // Getters
69  Library& getLibrary() const noexcept { return *mLibrary; }
70 
71  // Operator Overloadings
73 
74 public slots:
75  bool save() noexcept override;
76  bool remove() noexcept override;
77 
78 signals:
81  void newSymbolTriggered();
82  void newPackageTriggered();
83  void newComponentTriggered();
84  void newDeviceTriggered();
86  void editPackageCategoryTriggered(const FilePath& fp);
87  void editSymbolTriggered(const FilePath& fp);
88  void editPackageTriggered(const FilePath& fp);
89  void editComponentTriggered(const FilePath& fp);
90  void editDeviceTriggered(const FilePath& fp);
92  void copyPackageCategoryTriggered(const FilePath& fp);
93  void copySymbolTriggered(const FilePath& fp);
94  void copyPackageTriggered(const FilePath& fp);
95  void copyComponentTriggered(const FilePath& fp);
96  void copyDeviceTriggered(const FilePath& fp);
97  void removeElementTriggered(const FilePath& fp);
98 
99 private: // Methods
100  void updateMetadata() noexcept;
101  QString commitMetadata() noexcept;
102  bool isInterfaceBroken() const noexcept override { return false; }
103  bool runChecks(LibraryElementCheckMessageList& msgs) const override;
104  template <typename MessageType>
105  void fixMsg(const MessageType& msg);
106  template <typename MessageType>
107  bool fixMsgHelper(std::shared_ptr<const LibraryElementCheckMessage> msg,
108  bool applyFix);
109  bool processCheckMessage(
110  std::shared_ptr<const LibraryElementCheckMessage> msg,
111  bool applyFix) override;
112  void updateElementLists() noexcept;
113  template <typename ElementType>
114  void updateElementList(QListWidget& listWidget, const QIcon& icon) noexcept;
115  QHash<QListWidgetItem*, FilePath> getElementListItemFilePaths(
116  const QList<QListWidgetItem*>& items) const noexcept;
117  void openContextMenuAtPos(const QPoint& pos) noexcept;
118  void newItem(QListWidget* list) noexcept;
119  void editItem(QListWidget* list, const FilePath& fp) noexcept;
120  void copyItem(QListWidget* list, const FilePath& fp) noexcept;
121  void removeItems(
122  const QHash<QListWidgetItem*, FilePath>& selectedItemPaths) noexcept;
123 
124  // Event Handlers
125  void btnIconClicked() noexcept;
126  void lstDoubleClicked(const QModelIndex& index) noexcept;
127 
128 private: // Data
129  QScopedPointer<Ui::LibraryOverviewWidget> mUi;
131  QSharedPointer<Library> mLibrary;
132  QByteArray mIcon;
133 };
134 
135 /*******************************************************************************
136  * End of File
137  ******************************************************************************/
138 
139 } // namespace editor
140 } // namespace library
141 } // namespace librepcb
142 
143 #endif // LIBREPCB_LIBRARY_EDITOR_LIBRARYOVERVIEWWIDGET_H
QVector< std::shared_ptr< const LibraryElementCheckMessage > > LibraryElementCheckMessageList
Definition: libraryelementcheckmessage.h:96
The LibraryOverviewWidget class.
Definition: libraryoverviewwidget.h:57
void copyComponentCategoryTriggered(const FilePath &fp)
The Library class represents a library directory.
Definition: library.h:49
QSharedPointer< Library > mLibrary
Definition: libraryoverviewwidget.h:131
void removeItems(const QHash< QListWidgetItem *, FilePath > &selectedItemPaths) noexcept
Definition: libraryoverviewwidget.cpp:440
LibraryOverviewWidget & operator=(const LibraryOverviewWidget &rhs)=delete
QScopedPointer< Ui::LibraryOverviewWidget > mUi
Definition: libraryoverviewwidget.h:129
void updateElementLists() noexcept
Definition: libraryoverviewwidget.cpp:263
Library & getLibrary() const noexcept
Definition: libraryoverviewwidget.h:69
void editItem(QListWidget *list, const FilePath &fp) noexcept
Definition: libraryoverviewwidget.cpp:421
The LibraryListEditorWidget class.
Definition: librarylisteditorwidget.h:57
void copyItem(QListWidget *list, const FilePath &fp) noexcept
Definition: libraryoverviewwidget.cpp:402
QString commitMetadata() noexcept
Definition: libraryoverviewwidget.cpp:192
QByteArray mIcon
Definition: libraryoverviewwidget.h:132
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 lstDoubleClicked(const QModelIndex &index) noexcept
Definition: libraryoverviewwidget.cpp:499
bool fixMsgHelper(std::shared_ptr< const LibraryElementCheckMessage > msg, bool applyFix)
Definition: libraryoverviewwidget.cpp:245
void btnIconClicked() noexcept
Definition: libraryoverviewwidget.cpp:484
void newItem(QListWidget *list) noexcept
Definition: libraryoverviewwidget.cpp:384
bool save() noexceptoverride
Definition: libraryoverviewwidget.cpp:137
This class represents absolute, well-formatted paths to files or directories.
Definition: filepath.h:130
bool isInterfaceBroken() const noexceptoverride
Definition: libraryoverviewwidget.h:102
void copyPackageCategoryTriggered(const FilePath &fp)
QScopedPointer< LibraryListEditorWidget > mDependenciesEditorWidget
Definition: libraryoverviewwidget.h:130
bool remove() noexceptoverride
Definition: libraryoverviewwidget.cpp:156
~LibraryOverviewWidget() noexcept
Definition: libraryoverviewwidget.cpp:130
void openContextMenuAtPos(const QPoint &pos) noexcept
Definition: libraryoverviewwidget.cpp:340
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:65