LibrePCB Developers Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
74 class LibraryEditor final : public QMainWindow,
76  Q_OBJECT
77 
78 public:
79  // Constructors / Destructor
80  LibraryEditor() = delete;
81  LibraryEditor(const LibraryEditor& other) = delete;
82  LibraryEditor(workspace::Workspace& ws, const FilePath& libFp, bool readOnly);
83  ~LibraryEditor() noexcept;
84 
88  GraphicsLayer* getLayer(const QString& name) const noexcept override {
89  foreach (GraphicsLayer* layer, mLayers) {
90  if (layer->getName() == name) {
91  return layer;
92  }
93  }
94  return nullptr;
95  }
96 
100  QList<GraphicsLayer*> getAllLayers() const noexcept override {
101  return mLayers;
102  }
103 
127  bool closeAndDestroy(bool askForSave) noexcept;
128 
129  // Operator Overloadings
130  LibraryEditor& operator=(const LibraryEditor& rhs) = delete;
131 
132 private: // GUI Event Handlers
133  void newElementTriggered() noexcept;
134  void saveTriggered() noexcept;
135  void showElementInFileExplorerTriggered() noexcept;
136  void rotateCwTriggered() noexcept;
137  void rotateCcwTriggered() noexcept;
138  void removeTriggered() noexcept;
139  void abortCommandTriggered() noexcept;
140  void zoomInTriggered() noexcept;
141  void zoomOutTriggered() noexcept;
142  void zoomAllTriggered() noexcept;
143  void editGridPropertiesTriggered() noexcept;
144  void newComponentCategoryTriggered() noexcept;
145  void newPackageCategoryTriggered() noexcept;
146  void newSymbolTriggered() noexcept;
147  void newPackageTriggered() noexcept;
148  void newComponentTriggered() noexcept;
149  void newDeviceTriggered() noexcept;
150  void editComponentCategoryTriggered(const FilePath& fp) noexcept;
151  void editPackageCategoryTriggered(const FilePath& fp) noexcept;
152  void editSymbolTriggered(const FilePath& fp) noexcept;
153  void editPackageTriggered(const FilePath& fp) noexcept;
154  void editComponentTriggered(const FilePath& fp) noexcept;
155  void editDeviceTriggered(const FilePath& fp) noexcept;
156  void copyComponentCategoryTriggered(const FilePath& fp) noexcept;
157  void copyPackageCategoryTriggered(const FilePath& fp) noexcept;
158  void copySymbolTriggered(const FilePath& fp) noexcept;
159  void copyPackageTriggered(const FilePath& fp) noexcept;
160  void copyComponentTriggered(const FilePath& fp) noexcept;
161  void copyDeviceTriggered(const FilePath& fp) noexcept;
162  void closeTabIfOpen(const FilePath& fp) noexcept;
163  template <typename EditWidgetType>
164  void editLibraryElementTriggered(const FilePath& fp,
165  bool isNewElement) noexcept;
166  void currentTabChanged(int index) noexcept;
167  void tabCloseRequested(int index) noexcept;
168  bool closeTab(int index) noexcept;
169  void cursorPositionChanged(const Point& pos) noexcept;
170 
171 private: // Methods
173  void newLibraryElement(NewElementWizardContext::ElementType type);
174  void copyLibraryElement(NewElementWizardContext::ElementType type,
175  const FilePath& fp);
176  void editNewLibraryElement(NewElementWizardContext::ElementType type,
177  const FilePath& fp);
178  void updateTabTitles() noexcept;
179  void closeEvent(QCloseEvent* event) noexcept override;
180  void addLayer(const QString& name, bool forceVisible = false) noexcept;
181 
182 private: // Data
183  workspace::Workspace& mWorkspace;
185  QScopedPointer<Ui::LibraryEditor> mUi;
191 };
192 
193 /*******************************************************************************
194  * End of File
195  ******************************************************************************/
196 
197 } // namespace editor
198 } // namespace library
199 } // namespace librepcb
200 
201 #endif // LIBREPCB_LIBRARY_LIBRARYEDITOR_H
void setActiveEditorWidget(EditorWidgetBase *widget)
Definition: libraryeditor.cpp:594
void abortCommandTriggered() noexcept
Definition: libraryeditor.cpp:398
void copyComponentCategoryTriggered(const FilePath &fp) noexcept
Definition: libraryeditor.cpp:467
void copySymbolTriggered(const FilePath &fp) noexcept
Definition: libraryeditor.cpp:477
The GraphicsLayer class represents a graphical layer used in schematics and boards.
Definition: graphicslayer.h:54
void saveTriggered() noexcept
Definition: libraryeditor.cpp:376
bool closeAndDestroy(bool askForSave) noexcept
Close the library editor (this will destroy this object!)
Definition: libraryeditor.cpp:323
void closeEvent(QCloseEvent *event) noexceptoverride
Definition: libraryeditor.cpp:696
The Workspace class represents a workspace with all its data (library, projects, settings, ...)
Definition: workspace.h:65
void editGridPropertiesTriggered() noexcept
Definition: libraryeditor.cpp:414
void copyPackageCategoryTriggered(const FilePath &fp) noexcept
Definition: libraryeditor.cpp:473
The LibraryEditor class.
Definition: libraryeditor.h:74
void newElementTriggered() noexcept
Definition: libraryeditor.cpp:367
The Library class represents a library directory.
Definition: library.h:49
QList< GraphicsLayer * > getAllLayers() const noexceptoverride
Definition: libraryeditor.h:100
void tabCloseRequested(int index) noexcept
Definition: libraryeditor.cpp:531
The NewElementWizardContext class.
Definition: newelementwizardcontext.h:63
void newSymbolTriggered() noexcept
Definition: libraryeditor.cpp:426
QScopedPointer< Ui::LibraryEditor > mUi
Definition: libraryeditor.h:185
The IF_GraphicsLayerProvider class defines an interface for classes which provide layers...
Definition: graphicslayer.h:250
void zoomOutTriggered() noexcept
Definition: libraryeditor.cpp:406
void updateTabTitles() noexcept
Definition: libraryeditor.cpp:671
void editLibraryElementTriggered(const FilePath &fp, bool isNewElement) noexcept
Definition: libraryeditor.cpp:494
void editPackageCategoryTriggered(const FilePath &fp) noexcept
Definition: libraryeditor.cpp:447
void newComponentTriggered() noexcept
Definition: libraryeditor.cpp:434
void copyPackageTriggered(const FilePath &fp) noexcept
Definition: libraryeditor.cpp:481
The Point class is used to represent a point/coordinate/vector, for example (1.2mm; 5...
Definition: point.h:81
The ExclusiveActionGroup class groups multiple QAction's together.
Definition: exclusiveactiongroup.h:53
void addLayer(const QString &name, bool forceVisible=false) noexcept
Definition: libraryeditor.cpp:704
void editComponentCategoryTriggered(const FilePath &fp) noexcept
Definition: libraryeditor.cpp:442
bool closeTab(int index) noexcept
Definition: libraryeditor.cpp:542
void zoomInTriggered() noexcept
Definition: libraryeditor.cpp:402
void newComponentCategoryTriggered() noexcept
Definition: libraryeditor.cpp:418
QScopedPointer< UndoStackActionGroup > mUndoStackActionGroup
Definition: libraryeditor.h:186
Library * mLibrary
Definition: libraryeditor.h:190
void editDeviceTriggered(const FilePath &fp) noexcept
Definition: libraryeditor.cpp:463
workspace::Workspace & mWorkspace
Definition: libraryeditor.h:183
This class represents absolute, well-formatted paths to files or directories.
Definition: filepath.h:130
void cursorPositionChanged(const Point &pos) noexcept
Definition: libraryeditor.cpp:584
void newDeviceTriggered() noexcept
Definition: libraryeditor.cpp:438
LibraryEditor & operator=(const LibraryEditor &rhs)=delete
const QString & getName() const noexcept
Definition: graphicslayer.h:150
void showElementInFileExplorerTriggered() noexcept
Definition: libraryeditor.cpp:380
void copyComponentTriggered(const FilePath &fp) noexcept
Definition: libraryeditor.cpp:485
The UndoStackActionGroup class groups an undo-QAction and redo-QAction together and optionally connec...
Definition: undostackactiongroup.h:47
EditorWidgetBase * mCurrentEditorWidget
Definition: libraryeditor.h:189
~LibraryEditor() noexcept
Definition: libraryeditor.cpp:307
void editComponentTriggered(const FilePath &fp) noexcept
Definition: libraryeditor.cpp:459
void newPackageTriggered() noexcept
Definition: libraryeditor.cpp:430
QScopedPointer< ExclusiveActionGroup > mToolsActionGroup
Definition: libraryeditor.h:187
void zoomAllTriggered() noexcept
Definition: libraryeditor.cpp:410
void editPackageTriggered(const FilePath &fp) noexcept
Definition: libraryeditor.cpp:455
void removeTriggered() noexcept
Definition: libraryeditor.cpp:394
void copyLibraryElement(NewElementWizardContext::ElementType type, const FilePath &fp)
Definition: libraryeditor.cpp:634
GraphicsLayer * getLayer(const QString &name) const noexceptoverride
Definition: libraryeditor.h:88
void rotateCcwTriggered() noexcept
Definition: libraryeditor.cpp:390
void newPackageCategoryTriggered() noexcept
Definition: libraryeditor.cpp:422
QList< GraphicsLayer * > mLayers
Definition: libraryeditor.h:188
void closeTabIfOpen(const FilePath &fp) noexcept
Definition: libraryeditor.cpp:350
void currentTabChanged(int index) noexcept
Definition: libraryeditor.cpp:526
void editNewLibraryElement(NewElementWizardContext::ElementType type, const FilePath &fp)
Definition: libraryeditor.cpp:645
void newLibraryElement(NewElementWizardContext::ElementType type)
Definition: libraryeditor.cpp:623
void copyDeviceTriggered(const FilePath &fp) noexcept
Definition: libraryeditor.cpp:489
void editSymbolTriggered(const FilePath &fp) noexcept
Definition: libraryeditor.cpp:451
The EditorWidgetBase class.
Definition: editorwidgetbase.h:65
void rotateCwTriggered() noexcept
Definition: libraryeditor.cpp:386
bool mIsOpenedReadOnly
Definition: libraryeditor.h:184