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 
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 
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 cutTriggered() noexcept;
134  void copyTriggered() noexcept;
135  void pasteTriggered() 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 duplicateComponentCategoryTriggered(const FilePath& fp) noexcept;
157  void duplicatePackageCategoryTriggered(const FilePath& fp) noexcept;
158  void duplicateSymbolTriggered(const FilePath& fp) noexcept;
159  void duplicatePackageTriggered(const FilePath& fp) noexcept;
160  void duplicateComponentTriggered(const FilePath& fp) noexcept;
161  void duplicateDeviceTriggered(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 duplicateLibraryElement(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:609
void duplicatePackageTriggered(const FilePath &fp) noexcept
Definition: libraryeditor.cpp:496
void abortCommandTriggered() noexcept
Definition: libraryeditor.cpp:411
void duplicateLibraryElement(NewElementWizardContext::ElementType type, const FilePath &fp)
Definition: libraryeditor.cpp:649
void duplicateDeviceTriggered(const FilePath &fp) noexcept
Definition: libraryeditor.cpp:504
The GraphicsLayer class represents a graphical layer used in schematics and boards.
Definition: graphicslayer.h:50
void saveTriggered() noexcept
Definition: libraryeditor.cpp:377
bool closeAndDestroy(bool askForSave) noexcept
Close the library editor (this will destroy this object!)
Definition: libraryeditor.cpp:324
void duplicateComponentTriggered(const FilePath &fp) noexcept
Definition: libraryeditor.cpp:500
void closeEvent(QCloseEvent *event) noexceptoverride
Definition: libraryeditor.cpp:711
The Workspace class represents a workspace with all its data (library, projects, settings, ...)
Definition: workspace.h:62
void editGridPropertiesTriggered() noexcept
Definition: libraryeditor.cpp:427
The LibraryEditor class.
Definition: libraryeditor.h:71
void newElementTriggered() noexcept
Definition: libraryeditor.cpp:368
The Library class represents a library directory.
Definition: library.h:46
QList< GraphicsLayer * > getAllLayers() const noexceptoverride
Definition: libraryeditor.h:97
void tabCloseRequested(int index) noexcept
Definition: libraryeditor.cpp:546
void duplicateSymbolTriggered(const FilePath &fp) noexcept
Definition: libraryeditor.cpp:492
The NewElementWizardContext class.
Definition: newelementwizardcontext.h:60
void newSymbolTriggered() noexcept
Definition: libraryeditor.cpp:439
QScopedPointer< Ui::LibraryEditor > mUi
Definition: libraryeditor.h:185
void copyTriggered() noexcept
Definition: libraryeditor.cpp:391
The IF_GraphicsLayerProvider class defines an interface for classes which provide layers...
Definition: graphicslayer.h:227
void zoomOutTriggered() noexcept
Definition: libraryeditor.cpp:419
void updateTabTitles() noexcept
Definition: libraryeditor.cpp:686
void editLibraryElementTriggered(const FilePath &fp, bool isNewElement) noexcept
Definition: libraryeditor.cpp:509
void editPackageCategoryTriggered(const FilePath &fp) noexcept
Definition: libraryeditor.cpp:460
void duplicatePackageCategoryTriggered(const FilePath &fp) noexcept
Definition: libraryeditor.cpp:486
void newComponentTriggered() noexcept
Definition: libraryeditor.cpp:447
The Point class is used to represent a point/coordinate/vector, for example (1.2mm; 5...
Definition: point.h:78
The ExclusiveActionGroup class groups multiple QAction's together.
Definition: exclusiveactiongroup.h:50
void addLayer(const QString &name, bool forceVisible=false) noexcept
Definition: libraryeditor.cpp:719
void editComponentCategoryTriggered(const FilePath &fp) noexcept
Definition: libraryeditor.cpp:455
bool closeTab(int index) noexcept
Definition: libraryeditor.cpp:557
void zoomInTriggered() noexcept
Definition: libraryeditor.cpp:415
void newComponentCategoryTriggered() noexcept
Definition: libraryeditor.cpp:431
QScopedPointer< UndoStackActionGroup > mUndoStackActionGroup
Definition: libraryeditor.h:186
Library * mLibrary
Definition: libraryeditor.h:190
void editDeviceTriggered(const FilePath &fp) noexcept
Definition: libraryeditor.cpp:476
void duplicateComponentCategoryTriggered(const FilePath &fp) noexcept
Definition: libraryeditor.cpp:480
workspace::Workspace & mWorkspace
Definition: libraryeditor.h:183
This class represents absolute, well-formatted paths to files or directories.
Definition: filepath.h:127
void cursorPositionChanged(const Point &pos) noexcept
Definition: libraryeditor.cpp:599
void newDeviceTriggered() noexcept
Definition: libraryeditor.cpp:451
LibraryEditor & operator=(const LibraryEditor &rhs)=delete
void pasteTriggered() noexcept
Definition: libraryeditor.cpp:395
const QString & getName() const noexcept
Definition: graphicslayer.h:157
void showElementInFileExplorerTriggered() noexcept
Definition: libraryeditor.cpp:381
void cutTriggered() noexcept
Definition: libraryeditor.cpp:387
The UndoStackActionGroup class groups an undo-QAction and redo-QAction together and optionally connec...
Definition: undostackactiongroup.h:44
EditorWidgetBase * mCurrentEditorWidget
Definition: libraryeditor.h:189
~LibraryEditor() noexcept
Definition: libraryeditor.cpp:308
void editComponentTriggered(const FilePath &fp) noexcept
Definition: libraryeditor.cpp:472
void newPackageTriggered() noexcept
Definition: libraryeditor.cpp:443
QScopedPointer< ExclusiveActionGroup > mToolsActionGroup
Definition: libraryeditor.h:187
void zoomAllTriggered() noexcept
Definition: libraryeditor.cpp:423
void editPackageTriggered(const FilePath &fp) noexcept
Definition: libraryeditor.cpp:468
void removeTriggered() noexcept
Definition: libraryeditor.cpp:407
GraphicsLayer * getLayer(const QString &name) const noexceptoverride
Definition: libraryeditor.h:85
void rotateCcwTriggered() noexcept
Definition: libraryeditor.cpp:403
void newPackageCategoryTriggered() noexcept
Definition: libraryeditor.cpp:435
QList< GraphicsLayer * > mLayers
Definition: libraryeditor.h:188
void closeTabIfOpen(const FilePath &fp) noexcept
Definition: libraryeditor.cpp:351
void currentTabChanged(int index) noexcept
Definition: libraryeditor.cpp:541
void editNewLibraryElement(NewElementWizardContext::ElementType type, const FilePath &fp)
Definition: libraryeditor.cpp:660
void newLibraryElement(NewElementWizardContext::ElementType type)
Definition: libraryeditor.cpp:638
void editSymbolTriggered(const FilePath &fp) noexcept
Definition: libraryeditor.cpp:464
The EditorWidgetBase class.
Definition: editorwidgetbase.h:62
void rotateCwTriggered() noexcept
Definition: libraryeditor.cpp:399
bool mIsOpenedReadOnly
Definition: libraryeditor.h:184