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 mirrorTriggered() noexcept;
139  void flipTriggered() noexcept;
140  void removeTriggered() noexcept;
141  void abortCommandTriggered() noexcept;
142  void zoomInTriggered() noexcept;
143  void zoomOutTriggered() noexcept;
144  void zoomAllTriggered() noexcept;
145  void editGridPropertiesTriggered() noexcept;
146  void newComponentCategoryTriggered() noexcept;
147  void newPackageCategoryTriggered() noexcept;
148  void newSymbolTriggered() noexcept;
149  void newPackageTriggered() noexcept;
150  void newComponentTriggered() noexcept;
151  void newDeviceTriggered() noexcept;
152  void editComponentCategoryTriggered(const FilePath& fp) noexcept;
153  void editPackageCategoryTriggered(const FilePath& fp) noexcept;
154  void editSymbolTriggered(const FilePath& fp) noexcept;
155  void editPackageTriggered(const FilePath& fp) noexcept;
156  void editComponentTriggered(const FilePath& fp) noexcept;
157  void editDeviceTriggered(const FilePath& fp) noexcept;
158  void duplicateComponentCategoryTriggered(const FilePath& fp) noexcept;
159  void duplicatePackageCategoryTriggered(const FilePath& fp) noexcept;
160  void duplicateSymbolTriggered(const FilePath& fp) noexcept;
161  void duplicatePackageTriggered(const FilePath& fp) noexcept;
162  void duplicateComponentTriggered(const FilePath& fp) noexcept;
163  void duplicateDeviceTriggered(const FilePath& fp) noexcept;
164  void closeTabIfOpen(const FilePath& fp) noexcept;
165  template <typename EditWidgetType>
166  void editLibraryElementTriggered(const FilePath& fp,
167  bool isNewElement) noexcept;
168  void currentTabChanged(int index) noexcept;
169  void tabCloseRequested(int index) noexcept;
170  bool closeTab(int index) noexcept;
171  void cursorPositionChanged(const Point& pos) noexcept;
172 
173 private: // Methods
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
185  workspace::Workspace& mWorkspace;
187  QScopedPointer<Ui::LibraryEditor> mUi;
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
void setActiveEditorWidget(EditorWidgetBase *widget)
Definition: libraryeditor.cpp:630
void duplicatePackageTriggered(const FilePath &fp) noexcept
Definition: libraryeditor.cpp:508
void abortCommandTriggered() noexcept
Definition: libraryeditor.cpp:423
void duplicateLibraryElement(NewElementWizardContext::ElementType type, const FilePath &fp)
Definition: libraryeditor.cpp:673
void duplicateDeviceTriggered(const FilePath &fp) noexcept
Definition: libraryeditor.cpp:516
The GraphicsLayer class represents a graphical layer used in schematics and boards.
Definition: graphicslayer.h:50
void saveTriggered() noexcept
Definition: libraryeditor.cpp:381
bool closeAndDestroy(bool askForSave) noexcept
Close the library editor (this will destroy this object!)
Definition: libraryeditor.cpp:328
void duplicateComponentTriggered(const FilePath &fp) noexcept
Definition: libraryeditor.cpp:512
void closeEvent(QCloseEvent *event) noexceptoverride
Definition: libraryeditor.cpp:735
The Workspace class represents a workspace with all its data (library, projects, settings, ...)
Definition: workspace.h:62
void editGridPropertiesTriggered() noexcept
Definition: libraryeditor.cpp:439
The LibraryEditor class.
Definition: libraryeditor.h:71
void newElementTriggered() noexcept
Definition: libraryeditor.cpp:372
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:558
void duplicateSymbolTriggered(const FilePath &fp) noexcept
Definition: libraryeditor.cpp:504
The NewElementWizardContext class.
Definition: newelementwizardcontext.h:60
void newSymbolTriggered() noexcept
Definition: libraryeditor.cpp:451
QScopedPointer< Ui::LibraryEditor > mUi
Definition: libraryeditor.h:187
void copyTriggered() noexcept
Definition: libraryeditor.cpp:395
The IF_GraphicsLayerProvider class defines an interface for classes which provide layers...
Definition: graphicslayer.h:227
void zoomOutTriggered() noexcept
Definition: libraryeditor.cpp:431
void updateTabTitles() noexcept
Definition: libraryeditor.cpp:710
void flipTriggered() noexcept
Definition: libraryeditor.cpp:415
void editLibraryElementTriggered(const FilePath &fp, bool isNewElement) noexcept
Definition: libraryeditor.cpp:521
void editPackageCategoryTriggered(const FilePath &fp) noexcept
Definition: libraryeditor.cpp:472
void duplicatePackageCategoryTriggered(const FilePath &fp) noexcept
Definition: libraryeditor.cpp:498
void newComponentTriggered() noexcept
Definition: libraryeditor.cpp:459
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:743
void editComponentCategoryTriggered(const FilePath &fp) noexcept
Definition: libraryeditor.cpp:467
bool closeTab(int index) noexcept
Definition: libraryeditor.cpp:569
void zoomInTriggered() noexcept
Definition: libraryeditor.cpp:427
void newComponentCategoryTriggered() noexcept
Definition: libraryeditor.cpp:443
QScopedPointer< UndoStackActionGroup > mUndoStackActionGroup
Definition: libraryeditor.h:188
void mirrorTriggered() noexcept
Definition: libraryeditor.cpp:411
Library * mLibrary
Definition: libraryeditor.h:192
void editDeviceTriggered(const FilePath &fp) noexcept
Definition: libraryeditor.cpp:488
void duplicateComponentCategoryTriggered(const FilePath &fp) noexcept
Definition: libraryeditor.cpp:492
workspace::Workspace & mWorkspace
Definition: libraryeditor.h:185
This class represents absolute, well-formatted paths to files or directories.
Definition: filepath.h:127
void cursorPositionChanged(const Point &pos) noexcept
Definition: libraryeditor.cpp:620
void newDeviceTriggered() noexcept
Definition: libraryeditor.cpp:463
LibraryEditor & operator=(const LibraryEditor &rhs)=delete
void pasteTriggered() noexcept
Definition: libraryeditor.cpp:399
const QString & getName() const noexcept
Definition: graphicslayer.h:157
void showElementInFileExplorerTriggered() noexcept
Definition: libraryeditor.cpp:385
void cutTriggered() noexcept
Definition: libraryeditor.cpp:391
The UndoStackActionGroup class groups an undo-QAction and redo-QAction together and optionally connec...
Definition: undostackactiongroup.h:44
EditorWidgetBase * mCurrentEditorWidget
Definition: libraryeditor.h:191
~LibraryEditor() noexcept
Definition: libraryeditor.cpp:312
void editComponentTriggered(const FilePath &fp) noexcept
Definition: libraryeditor.cpp:484
void newPackageTriggered() noexcept
Definition: libraryeditor.cpp:455
QScopedPointer< ExclusiveActionGroup > mToolsActionGroup
Definition: libraryeditor.h:189
void zoomAllTriggered() noexcept
Definition: libraryeditor.cpp:435
void editPackageTriggered(const FilePath &fp) noexcept
Definition: libraryeditor.cpp:480
void removeTriggered() noexcept
Definition: libraryeditor.cpp:419
GraphicsLayer * getLayer(const QString &name) const noexceptoverride
Definition: libraryeditor.h:85
void rotateCcwTriggered() noexcept
Definition: libraryeditor.cpp:407
void newPackageCategoryTriggered() noexcept
Definition: libraryeditor.cpp:447
QList< GraphicsLayer * > mLayers
Definition: libraryeditor.h:190
void closeTabIfOpen(const FilePath &fp) noexcept
Definition: libraryeditor.cpp:355
void currentTabChanged(int index) noexcept
Definition: libraryeditor.cpp:553
void editNewLibraryElement(NewElementWizardContext::ElementType type, const FilePath &fp)
Definition: libraryeditor.cpp:684
void newLibraryElement(NewElementWizardContext::ElementType type)
Definition: libraryeditor.cpp:662
void editSymbolTriggered(const FilePath &fp) noexcept
Definition: libraryeditor.cpp:476
The EditorWidgetBase class.
Definition: editorwidgetbase.h:62
void rotateCwTriggered() noexcept
Definition: libraryeditor.cpp:403
bool mIsOpenedReadOnly
Definition: libraryeditor.h:186