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  ******************************************************************************/
30 
31 #include <QtCore>
32 #include <QtWidgets>
33 
34 #include <memory>
35 
36 /*******************************************************************************
37  * Namespace / Forward Declarations
38  ******************************************************************************/
39 namespace librepcb {
40 
41 class UndoStackActionGroup;
42 class ExclusiveActionGroup;
43 
44 namespace workspace {
45 class Workspace;
46 }
47 
48 namespace library {
49 
50 class Library;
51 
52 namespace editor {
53 
54 class EditorWidgetBase;
55 class LibraryOverviewWidget;
56 
57 namespace Ui {
58 class LibraryEditor;
59 }
60 
61 /*******************************************************************************
62  * Class LibraryEditor
63  ******************************************************************************/
64 
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, QSharedPointer<Library> lib);
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 
124  bool closeAndDestroy(bool askForSave) noexcept;
125 
126  // Operator Overloadings
127  LibraryEditor& operator=(const LibraryEditor& rhs) = delete;
128 
129 private: // GUI Event Handlers
130  void newElementTriggered() noexcept;
131  void saveTriggered() noexcept;
132  void showElementInFileExplorerTriggered() noexcept;
133  void rotateCwTriggered() noexcept;
134  void rotateCcwTriggered() noexcept;
135  void removeTriggered() noexcept;
136  void abortCommandTriggered() noexcept;
137  void zoomInTriggered() noexcept;
138  void zoomOutTriggered() noexcept;
139  void zoomAllTriggered() noexcept;
140  void editGridPropertiesTriggered() noexcept;
141  void editComponentCategoryTriggered(const FilePath& fp) noexcept;
142  void editPackageCategoryTriggered(const FilePath& fp) noexcept;
143  void editSymbolTriggered(const FilePath& fp) noexcept;
144  void editPackageTriggered(const FilePath& fp) noexcept;
145  void editComponentTriggered(const FilePath& fp) noexcept;
146  void editDeviceTriggered(const FilePath& fp) noexcept;
147  void closeTabIfOpen(const FilePath& fp) noexcept;
148  template <typename ElementType, typename EditWidgetType>
149  void editLibraryElementTriggered(const FilePath& fp,
150  bool isNewElement) noexcept;
151  void currentTabChanged(int index) noexcept;
152  void tabCloseRequested(int index) noexcept;
153  bool closeTab(int index) noexcept;
154  void cursorPositionChanged(const Point& pos) noexcept;
155 
156 private: // Methods
158  void updateTabTitles() noexcept;
159  void closeEvent(QCloseEvent* event) noexcept override;
160  void addLayer(const QString& name, bool forceVisible = false) noexcept;
161 
162 private: // Data
163  workspace::Workspace& mWorkspace;
164  QSharedPointer<Library> mLibrary;
165  QScopedPointer<Ui::LibraryEditor> mUi;
171 };
172 
173 /*******************************************************************************
174  * End of File
175  ******************************************************************************/
176 
177 } // namespace editor
178 } // namespace library
179 } // namespace librepcb
180 
181 #endif // LIBREPCB_LIBRARY_LIBRARYEDITOR_H
void setActiveEditorWidget(EditorWidgetBase *widget)
Definition: libraryeditor.cpp:545
void abortCommandTriggered() noexcept
Definition: libraryeditor.cpp:398
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:300
void closeEvent(QCloseEvent *event) noexceptoverride
Definition: libraryeditor.cpp:586
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 editLibraryElementTriggered(const FilePath &fp, bool isNewElement) noexcept
Definition: libraryeditor.cpp:446
The LibraryEditor class.
Definition: libraryeditor.h:71
void newElementTriggered() noexcept
Definition: libraryeditor.cpp:344
The Library class represents a library directory.
Definition: library.h:49
QList< GraphicsLayer * > getAllLayers() const noexceptoverride
Definition: libraryeditor.h:97
void tabCloseRequested(int index) noexcept
Definition: libraryeditor.cpp:482
QScopedPointer< Ui::LibraryEditor > mUi
Definition: libraryeditor.h:165
QSharedPointer< Library > mLibrary
Definition: libraryeditor.h:164
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:569
void editPackageCategoryTriggered(const FilePath &fp) noexcept
Definition: libraryeditor.cpp:424
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:594
void editComponentCategoryTriggered(const FilePath &fp) noexcept
Definition: libraryeditor.cpp:418
bool closeTab(int index) noexcept
Definition: libraryeditor.cpp:493
void zoomInTriggered() noexcept
Definition: libraryeditor.cpp:402
QScopedPointer< UndoStackActionGroup > mUndoStackActionGroup
Definition: libraryeditor.h:166
void editDeviceTriggered(const FilePath &fp) noexcept
Definition: libraryeditor.cpp:441
workspace::Workspace & mWorkspace
Definition: libraryeditor.h:163
This class represents absolute, well-formatted paths to files or directories.
Definition: filepath.h:130
void cursorPositionChanged(const Point &pos) noexcept
Definition: libraryeditor.cpp:535
LibraryEditor & operator=(const LibraryEditor &rhs)=delete
const QString & getName() const noexcept
Definition: graphicslayer.h:150
void showElementInFileExplorerTriggered() noexcept
Definition: libraryeditor.cpp:380
The UndoStackActionGroup class groups an undo-QAction and redo-QAction together and optionally connec...
Definition: undostackactiongroup.h:47
EditorWidgetBase * mCurrentEditorWidget
Definition: libraryeditor.h:169
~LibraryEditor() noexcept
Definition: libraryeditor.cpp:285
void editComponentTriggered(const FilePath &fp) noexcept
Definition: libraryeditor.cpp:437
QScopedPointer< ExclusiveActionGroup > mToolsActionGroup
Definition: libraryeditor.h:167
DirectoryLock mLock
Definition: libraryeditor.h:170
void zoomAllTriggered() noexcept
Definition: libraryeditor.cpp:410
void editPackageTriggered(const FilePath &fp) noexcept
Definition: libraryeditor.cpp:433
void removeTriggered() noexcept
Definition: libraryeditor.cpp:394
GraphicsLayer * getLayer(const QString &name) const noexceptoverride
Definition: libraryeditor.h:85
void rotateCcwTriggered() noexcept
Definition: libraryeditor.cpp:390
QList< GraphicsLayer * > mLayers
Definition: libraryeditor.h:168
void closeTabIfOpen(const FilePath &fp) noexcept
Definition: libraryeditor.cpp:327
void currentTabChanged(int index) noexcept
Definition: libraryeditor.cpp:477
void editSymbolTriggered(const FilePath &fp) noexcept
Definition: libraryeditor.cpp:429
This class can be used to implement file-based directory locks.
Definition: directorylock.h:162
The EditorWidgetBase class.
Definition: editorwidgetbase.h:66
void rotateCwTriggered() noexcept
Definition: libraryeditor.cpp:386