LibrePCB Developers Documentation
libraryeditor.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_LIBRARYEDITOR_H
21 #define LIBREPCB_LIBRARY_LIBRARYEDITOR_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
27 
32 
33 #include <QtCore>
34 #include <QtWidgets>
35 
36 #include <memory>
37 
38 /*******************************************************************************
39  * Namespace / Forward Declarations
40  ******************************************************************************/
41 namespace librepcb {
42 
43 class UndoStackActionGroup;
44 class ExclusiveActionGroup;
45 class TransactionalFileSystem;
46 
47 namespace workspace {
48 class Workspace;
49 }
50 
51 namespace library {
52 
53 class Library;
54 
55 namespace editor {
56 
57 class EditorWidgetBase;
58 class LibraryOverviewWidget;
59 
60 namespace Ui {
61 class LibraryEditor;
62 }
63 
64 /*******************************************************************************
65  * Class LibraryEditor
66  ******************************************************************************/
67 
71 class LibraryEditor final : public QMainWindow,
73  Q_OBJECT
74 
75 public:
76  // Constructors / Destructor
77  LibraryEditor() = delete;
78  LibraryEditor(const LibraryEditor& other) = delete;
79  LibraryEditor(workspace::Workspace& ws, const FilePath& libFp, bool readOnly);
80  ~LibraryEditor() noexcept;
81 
85  GraphicsLayer* getLayer(const QString& name) const noexcept override {
86  foreach (GraphicsLayer* layer, mLayers) {
87  if (layer->getName() == name) {
88  return layer;
89  }
90  }
91  return nullptr;
92  }
93 
97  QList<GraphicsLayer*> getAllLayers() const noexcept override {
98  return mLayers;
99  }
100 
125  bool closeAndDestroy(bool askForSave) noexcept;
126 
127  // Operator Overloadings
128  LibraryEditor& operator=(const LibraryEditor& rhs) = delete;
129 
130 private: // GUI Event Handlers
131  void newElementTriggered() noexcept;
132  void saveTriggered() noexcept;
133  void showElementInFileExplorerTriggered() noexcept;
134  void selectAllTriggered() noexcept;
135  void cutTriggered() noexcept;
136  void copyTriggered() noexcept;
137  void pasteTriggered() noexcept;
138  void rotateCwTriggered() noexcept;
139  void rotateCcwTriggered() noexcept;
140  void mirrorTriggered() noexcept;
141  void flipTriggered() noexcept;
142  void removeTriggered() noexcept;
143  void abortCommandTriggered() noexcept;
144  void zoomInTriggered() noexcept;
145  void zoomOutTriggered() noexcept;
146  void zoomAllTriggered() noexcept;
147  void editGridPropertiesTriggered() noexcept;
148  void newComponentCategoryTriggered() noexcept;
149  void newPackageCategoryTriggered() noexcept;
150  void newSymbolTriggered() noexcept;
151  void newPackageTriggered() noexcept;
152  void newComponentTriggered() noexcept;
153  void newDeviceTriggered() noexcept;
154  void editComponentCategoryTriggered(const FilePath& fp) noexcept;
155  void editPackageCategoryTriggered(const FilePath& fp) noexcept;
156  void editSymbolTriggered(const FilePath& fp) noexcept;
157  void editPackageTriggered(const FilePath& fp) noexcept;
158  void editComponentTriggered(const FilePath& fp) noexcept;
159  void editDeviceTriggered(const FilePath& fp) noexcept;
160  void duplicateComponentCategoryTriggered(const FilePath& fp) noexcept;
161  void duplicatePackageCategoryTriggered(const FilePath& fp) noexcept;
162  void duplicateSymbolTriggered(const FilePath& fp) noexcept;
163  void duplicatePackageTriggered(const FilePath& fp) noexcept;
164  void duplicateComponentTriggered(const FilePath& fp) noexcept;
165  void duplicateDeviceTriggered(const FilePath& fp) noexcept;
166  void closeTabIfOpen(const FilePath& fp) noexcept;
167  template <typename EditWidgetType>
168  void editLibraryElementTriggered(const FilePath& fp,
169  bool isNewElement) noexcept;
170  void currentTabChanged(int index) noexcept;
171  void tabCloseRequested(int index) noexcept;
172  bool closeTab(int index) noexcept;
173 
174 private: // Methods
175  void setActiveEditorWidget(EditorWidgetBase* widget);
176  void newLibraryElement(NewElementWizardContext::ElementType type);
177  void duplicateLibraryElement(NewElementWizardContext::ElementType type,
178  const FilePath& fp);
179  void editNewLibraryElement(NewElementWizardContext::ElementType type,
180  const FilePath& fp);
181  void updateTabTitles() noexcept;
182  void closeEvent(QCloseEvent* event) noexcept override;
183  void addLayer(const QString& name, bool forceVisible = false) noexcept;
184 
185 private: // Data
188  QScopedPointer<Ui::LibraryEditor> mUi;
189  QScopedPointer<UndoStackActionGroup> mUndoStackActionGroup;
190  QScopedPointer<ExclusiveActionGroup> mToolsActionGroup;
191  QList<GraphicsLayer*> mLayers;
194 };
195 
196 /*******************************************************************************
197  * End of File
198  ******************************************************************************/
199 
200 } // namespace editor
201 } // namespace library
202 } // namespace librepcb
203 
204 #endif // LIBREPCB_LIBRARY_LIBRARYEDITOR_H
The GraphicsLayer class represents a graphical layer used in schematics and boards.
Definition: graphicslayer.h:50
The Workspace class represents a workspace with all its data (library, projects, settings, ...)
Definition: workspace.h:62
The LibraryEditor class.
Definition: libraryeditor.h:71
Definition: mainwindow.h:10
The Library class represents a library directory.
Definition: library.h:46
Definition: airwiresbuilder.cpp:32
QScopedPointer< Ui::LibraryEditor > mUi
Definition: libraryeditor.h:188
The IF_GraphicsLayerProvider class defines an interface for classes which provide layers...
Definition: graphicslayer.h:225
GraphicsLayer * getLayer(const QString &name) const noexcept override
Definition: libraryeditor.h:85
ElementType
Definition: newelementwizardcontext.h:79
QScopedPointer< UndoStackActionGroup > mUndoStackActionGroup
Definition: libraryeditor.h:189
Library * mLibrary
Definition: libraryeditor.h:193
workspace::Workspace & mWorkspace
Definition: libraryeditor.h:186
This class represents absolute, well-formatted paths to files or directories.
Definition: filepath.h:127
const QString & getName() const noexcept
Definition: graphicslayer.h:157
EditorWidgetBase * mCurrentEditorWidget
Definition: libraryeditor.h:192
QScopedPointer< ExclusiveActionGroup > mToolsActionGroup
Definition: libraryeditor.h:190
QList< GraphicsLayer * > getAllLayers() const noexcept override
Definition: libraryeditor.h:97
QList< GraphicsLayer * > mLayers
Definition: libraryeditor.h:191
The EditorWidgetBase class.
Definition: editorwidgetbase.h:63
bool mIsOpenedReadOnly
Definition: libraryeditor.h:187