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 cutTriggered() noexcept;
135  void copyTriggered() noexcept;
136  void pasteTriggered() noexcept;
137  void rotateCwTriggered() noexcept;
138  void rotateCcwTriggered() noexcept;
139  void mirrorTriggered() noexcept;
140  void flipTriggered() noexcept;
141  void removeTriggered() noexcept;
142  void abortCommandTriggered() noexcept;
143  void zoomInTriggered() noexcept;
144  void zoomOutTriggered() noexcept;
145  void zoomAllTriggered() noexcept;
146  void editGridPropertiesTriggered() noexcept;
147  void newComponentCategoryTriggered() noexcept;
148  void newPackageCategoryTriggered() noexcept;
149  void newSymbolTriggered() noexcept;
150  void newPackageTriggered() noexcept;
151  void newComponentTriggered() noexcept;
152  void newDeviceTriggered() noexcept;
153  void editComponentCategoryTriggered(const FilePath& fp) noexcept;
154  void editPackageCategoryTriggered(const FilePath& fp) noexcept;
155  void editSymbolTriggered(const FilePath& fp) noexcept;
156  void editPackageTriggered(const FilePath& fp) noexcept;
157  void editComponentTriggered(const FilePath& fp) noexcept;
158  void editDeviceTriggered(const FilePath& fp) noexcept;
159  void duplicateComponentCategoryTriggered(const FilePath& fp) noexcept;
160  void duplicatePackageCategoryTriggered(const FilePath& fp) noexcept;
161  void duplicateSymbolTriggered(const FilePath& fp) noexcept;
162  void duplicatePackageTriggered(const FilePath& fp) noexcept;
163  void duplicateComponentTriggered(const FilePath& fp) noexcept;
164  void duplicateDeviceTriggered(const FilePath& fp) noexcept;
165  void closeTabIfOpen(const FilePath& fp) noexcept;
166  template <typename EditWidgetType>
167  void editLibraryElementTriggered(const FilePath& fp,
168  bool isNewElement) noexcept;
169  void currentTabChanged(int index) noexcept;
170  void tabCloseRequested(int index) noexcept;
171  bool closeTab(int index) noexcept;
172 
173 private: // Methods
174  void setActiveEditorWidget(EditorWidgetBase* widget);
175  void newLibraryElement(NewElementWizardContext::ElementType type);
176  void duplicateLibraryElement(NewElementWizardContext::ElementType type,
177  const FilePath& fp);
178  void editNewLibraryElement(NewElementWizardContext::ElementType type,
179  const FilePath& fp);
180  void updateTabTitles() noexcept;
181  void closeEvent(QCloseEvent* event) noexcept override;
182  void addLayer(const QString& name, bool forceVisible = false) noexcept;
183 
184 private: // Data
187  QScopedPointer<Ui::LibraryEditor> mUi;
188  QScopedPointer<UndoStackActionGroup> mUndoStackActionGroup;
189  QScopedPointer<ExclusiveActionGroup> mToolsActionGroup;
190  QList<GraphicsLayer*> mLayers;
193 };
194 
195 /*******************************************************************************
196  * End of File
197  ******************************************************************************/
198 
199 } // namespace editor
200 } // namespace library
201 } // namespace librepcb
202 
203 #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:187
The IF_GraphicsLayerProvider class defines an interface for classes which provide layers...
Definition: graphicslayer.h:227
GraphicsLayer * getLayer(const QString &name) const noexcept override
Definition: libraryeditor.h:85
ElementType
Definition: newelementwizardcontext.h:79
QScopedPointer< UndoStackActionGroup > mUndoStackActionGroup
Definition: libraryeditor.h:188
Library * mLibrary
Definition: libraryeditor.h:192
workspace::Workspace & mWorkspace
Definition: libraryeditor.h:185
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:191
QScopedPointer< ExclusiveActionGroup > mToolsActionGroup
Definition: libraryeditor.h:189
QList< GraphicsLayer * > getAllLayers() const noexcept override
Definition: libraryeditor.h:97
QList< GraphicsLayer * > mLayers
Definition: libraryeditor.h:190
The EditorWidgetBase class.
Definition: editorwidgetbase.h:63
bool mIsOpenedReadOnly
Definition: libraryeditor.h:186