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_EDITOR_LIBRARYEDITOR_H
21#define LIBREPCB_EDITOR_LIBRARYEDITOR_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
26#include "../graphics/graphicslayer.h"
27#include "editorwidgetbase.h"
29
31
32#include <QtCore>
33#include <QtWidgets>
34
35#include <memory>
36
37/*******************************************************************************
38 * Namespace / Forward Declarations
39 ******************************************************************************/
40namespace librepcb {
41
42class Library;
43class TransactionalFileSystem;
44class Workspace;
45
46namespace editor {
47
48class ExclusiveActionGroup;
49class LibraryOverviewWidget;
50class SearchToolBar;
51class StandardEditorCommandHandler;
52class UndoStackActionGroup;
53
54namespace Ui {
55class LibraryEditor;
56}
57
58/*******************************************************************************
59 * Class LibraryEditor
60 ******************************************************************************/
61
65class LibraryEditor final : public QMainWindow,
67 Q_OBJECT
68
69public:
70 // Constructors / Destructor
71 LibraryEditor() = delete;
72 LibraryEditor(const LibraryEditor& other) = delete;
73 LibraryEditor(Workspace& ws, const FilePath& libFp, bool readOnly);
74 ~LibraryEditor() noexcept;
75
79 std::shared_ptr<GraphicsLayer> getLayer(
80 const QString& name) const noexcept override {
81 foreach (const std::shared_ptr<GraphicsLayer>& layer, mLayers) {
82 if (layer->getName() == name) {
83 return layer;
84 }
85 }
86 return nullptr;
87 }
88
92 QList<std::shared_ptr<GraphicsLayer>> getAllLayers() const noexcept override {
93 return mLayers;
94 }
95
119 bool closeAndDestroy(bool askForSave) noexcept;
120
121 // Operator Overloadings
122 LibraryEditor& operator=(const LibraryEditor& rhs) = delete;
123
124private: // GUI Event Handlers
125 void newComponentCategoryTriggered() noexcept;
126 void newPackageCategoryTriggered() noexcept;
127 void newSymbolTriggered() noexcept;
128 void newPackageTriggered() noexcept;
129 void newComponentTriggered() noexcept;
130 void newDeviceTriggered() noexcept;
131 void editComponentCategoryTriggered(const FilePath& fp) noexcept;
132 void editPackageCategoryTriggered(const FilePath& fp) noexcept;
133 void editSymbolTriggered(const FilePath& fp) noexcept;
134 void editPackageTriggered(const FilePath& fp) noexcept;
135 void editComponentTriggered(const FilePath& fp) noexcept;
136 void editDeviceTriggered(const FilePath& fp) noexcept;
137 void duplicateComponentCategoryTriggered(const FilePath& fp) noexcept;
138 void duplicatePackageCategoryTriggered(const FilePath& fp) noexcept;
139 void duplicateSymbolTriggered(const FilePath& fp) noexcept;
140 void duplicatePackageTriggered(const FilePath& fp) noexcept;
141 void duplicateComponentTriggered(const FilePath& fp) noexcept;
142 void duplicateDeviceTriggered(const FilePath& fp) noexcept;
143 void closeTabIfOpen(const FilePath& fp) noexcept;
144 template <typename EditWidgetType>
146 bool isNewElement) noexcept;
147 void currentTabChanged(int index) noexcept;
148 void tabCloseRequested(int index) noexcept;
149 bool closeTab(int index) noexcept;
150
151private: // Methods
152 void createActions() noexcept;
153 void createToolBars() noexcept;
154 void createMenus() noexcept;
155 EditorWidgetBase::Context createContext(bool isNewElement) noexcept;
157 const QSet<EditorWidgetBase::Feature>& features) noexcept;
159 void newLibraryElement(NewElementWizardContext::ElementType type);
161 const FilePath& fp);
162 void editNewLibraryElement(NewElementWizardContext::ElementType type,
163 const FilePath& fp);
164 void updateTabTitles() noexcept;
165 void tabCountChanged() noexcept;
166 void keyPressEvent(QKeyEvent* event) noexcept override;
167 void closeEvent(QCloseEvent* event) noexcept override;
168 bool closeAllTabs(bool withNonClosable, bool askForSave) noexcept;
169 void addLayer(const QString& name) noexcept;
170
171private: // Data
174 QScopedPointer<Ui::LibraryEditor> mUi;
176 QList<std::shared_ptr<GraphicsLayer>> mLayers;
179
180 // Actions
181 QScopedPointer<QAction> mActionAboutLibrePcb;
182 QScopedPointer<QAction> mActionAboutQt;
183 QScopedPointer<QAction> mActionOnlineDocumentation;
184 QScopedPointer<QAction> mActionKeyboardShortcutsReference;
185 QScopedPointer<QAction> mActionWebsite;
186 QScopedPointer<QAction> mActionSave;
187 QScopedPointer<QAction> mActionSaveAll;
188 QScopedPointer<QAction> mActionCloseTab;
189 QScopedPointer<QAction> mActionCloseAllTabs;
190 QScopedPointer<QAction> mActionCloseWindow;
191 QScopedPointer<QAction> mActionQuit;
192 QScopedPointer<QAction> mActionFileManager;
193 QScopedPointer<QAction> mActionRescanLibraries;
194 QScopedPointer<QAction> mActionImportDxf;
195 QScopedPointer<QAction> mActionImportEagleLibrary;
196 QScopedPointer<QAction> mActionExportImage;
197 QScopedPointer<QAction> mActionExportPdf;
198 QScopedPointer<QAction> mActionPrint;
199 QScopedPointer<QAction> mActionNewElement;
200 QScopedPointer<QAction> mActionNextPage;
201 QScopedPointer<QAction> mActionPreviousPage;
202 QScopedPointer<QAction> mActionFind;
203 QScopedPointer<QAction> mActionSelectAll;
204 QScopedPointer<QAction> mActionGridProperties;
205 QScopedPointer<QAction> mActionGridIncrease;
206 QScopedPointer<QAction> mActionGridDecrease;
207 QScopedPointer<QAction> mActionToggleBgImage;
208 QScopedPointer<QAction> mActionZoomFit;
209 QScopedPointer<QAction> mActionZoomIn;
210 QScopedPointer<QAction> mActionZoomOut;
211 QScopedPointer<QAction> mActionToggle3D;
212 QScopedPointer<QAction> mActionUndo;
213 QScopedPointer<QAction> mActionRedo;
214 QScopedPointer<QAction> mActionCut;
215 QScopedPointer<QAction> mActionCopy;
216 QScopedPointer<QAction> mActionPaste;
217 QScopedPointer<QAction> mActionMoveLeft;
218 QScopedPointer<QAction> mActionMoveRight;
219 QScopedPointer<QAction> mActionMoveUp;
220 QScopedPointer<QAction> mActionMoveDown;
221 QScopedPointer<QAction> mActionRotateCcw;
222 QScopedPointer<QAction> mActionRotateCw;
223 QScopedPointer<QAction> mActionMirrorHorizontal;
224 QScopedPointer<QAction> mActionMirrorVertical;
225 QScopedPointer<QAction> mActionFlipHorizontal;
226 QScopedPointer<QAction> mActionFlipVertical;
227 QScopedPointer<QAction> mActionMoveAlign;
228 QScopedPointer<QAction> mActionSnapToGrid;
229 QScopedPointer<QAction> mActionProperties;
230 QScopedPointer<QAction> mActionRemove;
231 QScopedPointer<QAction> mActionHelperTools;
232 QScopedPointer<QAction> mActionGenerateOutline;
233 QScopedPointer<QAction> mActionGenerateCourtyard;
234 QScopedPointer<QAction> mActionAbort;
235 QScopedPointer<QAction> mActionToolSelect;
236 QScopedPointer<QAction> mActionToolLine;
237 QScopedPointer<QAction> mActionToolRect;
238 QScopedPointer<QAction> mActionToolPolygon;
239 QScopedPointer<QAction> mActionToolCircle;
240 QScopedPointer<QAction> mActionToolArc;
241 QScopedPointer<QAction> mActionToolText;
242 QScopedPointer<QAction> mActionToolName;
243 QScopedPointer<QAction> mActionToolValue;
244 QScopedPointer<QAction> mActionToolPin;
245 QScopedPointer<QAction> mActionToolSmtPadStandard;
246 QScopedPointer<QAction> mActionToolThtPad;
247 QScopedPointer<QAction> mActionToolSpecialPadThermal;
248 QScopedPointer<QAction> mActionToolSpecialPadBga;
249 QScopedPointer<QAction> mActionToolSpecialPadEdgeConnector;
250 QScopedPointer<QAction> mActionToolSpecialPadTest;
251 QScopedPointer<QAction> mActionToolSpecialPadLocalFiducial;
252 QScopedPointer<QAction> mActionToolSpecialPadGlobalFiducial;
253 QScopedPointer<QAction> mActionToolZone;
254 QScopedPointer<QAction> mActionToolHole;
255 QScopedPointer<QAction> mActionToolMeasure;
256 QScopedPointer<QAction> mActionReNumberPads;
257
258 // Action groups
261
262 // Toolbars
263 QScopedPointer<QToolBar> mToolBarFile;
264 QScopedPointer<QToolBar> mToolBarEdit;
265 QScopedPointer<QToolBar> mToolBarView;
267 QScopedPointer<QToolBar> mToolBarCommand;
268 QScopedPointer<QToolBar> mToolBarTools;
269};
270
271/*******************************************************************************
272 * End of File
273 ******************************************************************************/
274
275} // namespace editor
276} // namespace librepcb
277
278#endif
This class represents absolute, well-formatted paths to files or directories.
Definition: filepath.h:129
The Library class represents a library directory.
Definition: library.h:46
The Workspace class represents a workspace with all its data (library, projects, settings,...
Definition: workspace.h:54
The EditorWidgetBase class.
Definition: editorwidgetbase.h:62
The ExclusiveActionGroup class groups multiple QAction's together.
Definition: exclusiveactiongroup.h:54
The GraphicsLayer class represents a graphical layer used in schematics and boards.
Definition: graphicslayer.h:53
The IF_GraphicsLayerProvider class defines an interface for classes which provide layers.
Definition: graphicslayer.h:111
The LibraryEditor class.
Definition: libraryeditor.h:66
QScopedPointer< QAction > mActionGenerateOutline
Definition: libraryeditor.h:232
EditorWidgetBase * mCurrentEditorWidget
Definition: libraryeditor.h:177
void setAvailableFeatures(const QSet< EditorWidgetBase::Feature > &features) noexcept
Definition: libraryeditor.cpp:991
EditorWidgetBase::Context createContext(bool isNewElement) noexcept
Definition: libraryeditor.cpp:984
QScopedPointer< QAction > mActionZoomFit
Definition: libraryeditor.h:208
void duplicatePackageTriggered(const FilePath &fp) noexcept
Definition: libraryeditor.cpp:365
QScopedPointer< QAction > mActionExportImage
Definition: libraryeditor.h:196
QScopedPointer< QAction > mActionToolSpecialPadEdgeConnector
Definition: libraryeditor.h:249
void duplicateLibraryElement(NewElementWizardContext::ElementType type, const FilePath &fp)
Definition: libraryeditor.cpp:1075
QScopedPointer< QAction > mActionSave
Definition: libraryeditor.h:186
QScopedPointer< UndoStackActionGroup > mUndoStackActionGroup
Definition: libraryeditor.h:259
QScopedPointer< QAction > mActionCut
Definition: libraryeditor.h:214
void closeTabIfOpen(const FilePath &fp) noexcept
Definition: libraryeditor.cpp:282
void newDeviceTriggered() noexcept
Definition: libraryeditor.cpp:320
QScopedPointer< QAction > mActionMoveAlign
Definition: libraryeditor.h:227
~LibraryEditor() noexcept
Definition: libraryeditor.cpp:253
QScopedPointer< QAction > mActionZoomIn
Definition: libraryeditor.h:209
QScopedPointer< QAction > mActionCopy
Definition: libraryeditor.h:215
QScopedPointer< QAction > mActionToolRect
Definition: libraryeditor.h:237
QScopedPointer< QAction > mActionKeyboardShortcutsReference
Definition: libraryeditor.h:184
void addLayer(const QString &name) noexcept
Definition: libraryeditor.cpp:1185
QScopedPointer< QAction > mActionMirrorHorizontal
Definition: libraryeditor.h:223
void newLibraryElement(NewElementWizardContext::ElementType type)
Definition: libraryeditor.cpp:1064
QScopedPointer< QAction > mActionQuit
Definition: libraryeditor.h:191
QScopedPointer< ExclusiveActionGroup > mToolsActionGroup
Definition: libraryeditor.h:260
QScopedPointer< QAction > mActionToolHole
Definition: libraryeditor.h:254
QScopedPointer< QAction > mActionMoveDown
Definition: libraryeditor.h:220
QScopedPointer< QAction > mActionGridIncrease
Definition: libraryeditor.h:205
QScopedPointer< QAction > mActionHelperTools
Definition: libraryeditor.h:231
void duplicateComponentTriggered(const FilePath &fp) noexcept
Definition: libraryeditor.cpp:369
QScopedPointer< QAction > mActionToolValue
Definition: libraryeditor.h:243
QScopedPointer< QAction > mActionCloseTab
Definition: libraryeditor.h:188
QScopedPointer< QAction > mActionCloseAllTabs
Definition: libraryeditor.h:189
QScopedPointer< QAction > mActionGridProperties
Definition: libraryeditor.h:204
void setActiveEditorWidget(EditorWidgetBase *widget)
Definition: libraryeditor.cpp:1039
void newPackageCategoryTriggered() noexcept
Definition: libraryeditor.cpp:304
QScopedPointer< QAction > mActionReNumberPads
Definition: libraryeditor.h:256
bool closeAllTabs(bool withNonClosable, bool askForSave) noexcept
Definition: libraryeditor.cpp:1163
QList< std::shared_ptr< GraphicsLayer > > mLayers
Definition: libraryeditor.h:176
QScopedPointer< QAction > mActionToolSpecialPadTest
Definition: libraryeditor.h:250
QScopedPointer< QAction > mActionAbort
Definition: libraryeditor.h:234
QScopedPointer< QToolBar > mToolBarEdit
Definition: libraryeditor.h:264
QScopedPointer< QAction > mActionRotateCcw
Definition: libraryeditor.h:221
void createMenus() noexcept
Definition: libraryeditor.cpp:875
QScopedPointer< QAction > mActionToolArc
Definition: libraryeditor.h:240
QScopedPointer< QAction > mActionRescanLibraries
Definition: libraryeditor.h:193
QScopedPointer< QAction > mActionAboutLibrePcb
Definition: libraryeditor.h:181
void editNewLibraryElement(NewElementWizardContext::ElementType type, const FilePath &fp)
Definition: libraryeditor.cpp:1086
bool mIsOpenedReadOnly
Definition: libraryeditor.h:173
bool closeTab(int index) noexcept
Definition: libraryeditor.cpp:425
QScopedPointer< QAction > mActionSelectAll
Definition: libraryeditor.h:203
std::shared_ptr< GraphicsLayer > getLayer(const QString &name) const noexcept override
Definition: libraryeditor.h:79
QScopedPointer< QToolBar > mToolBarTools
Definition: libraryeditor.h:268
QScopedPointer< QAction > mActionMoveUp
Definition: libraryeditor.h:219
QScopedPointer< QToolBar > mToolBarFile
Definition: libraryeditor.h:263
void updateTabTitles() noexcept
Definition: libraryeditor.cpp:1112
QScopedPointer< QAction > mActionPreviousPage
Definition: libraryeditor.h:201
QScopedPointer< QAction > mActionImportDxf
Definition: libraryeditor.h:194
void createToolBars() noexcept
Definition: libraryeditor.cpp:766
QScopedPointer< QAction > mActionCloseWindow
Definition: libraryeditor.h:190
void duplicateSymbolTriggered(const FilePath &fp) noexcept
Definition: libraryeditor.cpp:361
void currentTabChanged(int index) noexcept
Definition: libraryeditor.cpp:410
QScopedPointer< QAction > mActionToolSelect
Definition: libraryeditor.h:235
QList< std::shared_ptr< GraphicsLayer > > getAllLayers() const noexcept override
Definition: libraryeditor.h:92
QScopedPointer< QAction > mActionWebsite
Definition: libraryeditor.h:185
QScopedPointer< QAction > mActionToolSpecialPadGlobalFiducial
Definition: libraryeditor.h:252
void editDeviceTriggered(const FilePath &fp) noexcept
Definition: libraryeditor.cpp:345
QScopedPointer< QAction > mActionUndo
Definition: libraryeditor.h:212
QScopedPointer< QAction > mActionRotateCw
Definition: libraryeditor.h:222
QScopedPointer< SearchToolBar > mToolBarSearch
Definition: libraryeditor.h:266
QScopedPointer< QAction > mActionToolLine
Definition: libraryeditor.h:236
QScopedPointer< QAction > mActionFlipVertical
Definition: libraryeditor.h:226
QScopedPointer< QAction > mActionMoveLeft
Definition: libraryeditor.h:217
QScopedPointer< QToolBar > mToolBarCommand
Definition: libraryeditor.h:267
QScopedPointer< QAction > mActionProperties
Definition: libraryeditor.h:229
bool closeAndDestroy(bool askForSave) noexcept
Close the library editor (this will destroy this object!)
Definition: libraryeditor.cpp:263
QScopedPointer< StandardEditorCommandHandler > mStandardCommandHandler
Definition: libraryeditor.h:175
QScopedPointer< QAction > mActionSaveAll
Definition: libraryeditor.h:187
void editComponentCategoryTriggered(const FilePath &fp) noexcept
Definition: libraryeditor.cpp:324
QScopedPointer< QAction > mActionToolCircle
Definition: libraryeditor.h:239
QScopedPointer< QAction > mActionExportPdf
Definition: libraryeditor.h:197
void tabCountChanged() noexcept
Definition: libraryeditor.cpp:1138
QScopedPointer< QAction > mActionToggleBgImage
Definition: libraryeditor.h:207
QScopedPointer< QToolBar > mToolBarView
Definition: libraryeditor.h:265
void editComponentTriggered(const FilePath &fp) noexcept
Definition: libraryeditor.cpp:341
Library * mLibrary
Definition: libraryeditor.h:178
QScopedPointer< QAction > mActionToolSmtPadStandard
Definition: libraryeditor.h:245
void newComponentCategoryTriggered() noexcept
Definition: libraryeditor.cpp:300
QScopedPointer< QAction > mActionToolSpecialPadThermal
Definition: libraryeditor.h:247
QScopedPointer< QAction > mActionToolName
Definition: libraryeditor.h:242
QScopedPointer< QAction > mActionToolPolygon
Definition: libraryeditor.h:238
void newSymbolTriggered() noexcept
Definition: libraryeditor.cpp:308
void editPackageCategoryTriggered(const FilePath &fp) noexcept
Definition: libraryeditor.cpp:329
Workspace & mWorkspace
Definition: libraryeditor.h:172
QScopedPointer< QAction > mActionGenerateCourtyard
Definition: libraryeditor.h:233
QScopedPointer< QAction > mActionOnlineDocumentation
Definition: libraryeditor.h:183
QScopedPointer< QAction > mActionFileManager
Definition: libraryeditor.h:192
void newComponentTriggered() noexcept
Definition: libraryeditor.cpp:316
QScopedPointer< QAction > mActionFind
Definition: libraryeditor.h:202
void editSymbolTriggered(const FilePath &fp) noexcept
Definition: libraryeditor.cpp:333
QScopedPointer< Ui::LibraryEditor > mUi
Definition: libraryeditor.h:174
QScopedPointer< QAction > mActionMoveRight
Definition: libraryeditor.h:218
void keyPressEvent(QKeyEvent *event) noexcept override
Definition: libraryeditor.cpp:1142
QScopedPointer< QAction > mActionImportEagleLibrary
Definition: libraryeditor.h:195
void duplicateComponentCategoryTriggered(const FilePath &fp) noexcept
Definition: libraryeditor.cpp:349
void newPackageTriggered() noexcept
Definition: libraryeditor.cpp:312
void closeEvent(QCloseEvent *event) noexcept override
Definition: libraryeditor.cpp:1155
void duplicateDeviceTriggered(const FilePath &fp) noexcept
Definition: libraryeditor.cpp:373
LibraryEditor(const LibraryEditor &other)=delete
QScopedPointer< QAction > mActionPaste
Definition: libraryeditor.h:216
void duplicatePackageCategoryTriggered(const FilePath &fp) noexcept
Definition: libraryeditor.cpp:355
void createActions() noexcept
Definition: libraryeditor.cpp:477
QScopedPointer< QAction > mActionPrint
Definition: libraryeditor.h:198
QScopedPointer< QAction > mActionGridDecrease
Definition: libraryeditor.h:206
void editPackageTriggered(const FilePath &fp) noexcept
Definition: libraryeditor.cpp:337
QScopedPointer< QAction > mActionNextPage
Definition: libraryeditor.h:200
QScopedPointer< QAction > mActionRedo
Definition: libraryeditor.h:213
LibraryEditor & operator=(const LibraryEditor &rhs)=delete
QScopedPointer< QAction > mActionToolThtPad
Definition: libraryeditor.h:246
void tabCloseRequested(int index) noexcept
Definition: libraryeditor.cpp:415
QScopedPointer< QAction > mActionAboutQt
Definition: libraryeditor.h:182
QScopedPointer< QAction > mActionMirrorVertical
Definition: libraryeditor.h:224
QScopedPointer< QAction > mActionToolMeasure
Definition: libraryeditor.h:255
QScopedPointer< QAction > mActionRemove
Definition: libraryeditor.h:230
QScopedPointer< QAction > mActionFlipHorizontal
Definition: libraryeditor.h:225
QScopedPointer< QAction > mActionToolSpecialPadLocalFiducial
Definition: libraryeditor.h:251
QScopedPointer< QAction > mActionToolSpecialPadBga
Definition: libraryeditor.h:248
QScopedPointer< QAction > mActionToolZone
Definition: libraryeditor.h:253
QScopedPointer< QAction > mActionZoomOut
Definition: libraryeditor.h:210
QScopedPointer< QAction > mActionToggle3D
Definition: libraryeditor.h:211
void editLibraryElementTriggered(const FilePath &fp, bool isNewElement) noexcept
Definition: libraryeditor.cpp:378
QScopedPointer< QAction > mActionToolText
Definition: libraryeditor.h:241
QScopedPointer< QAction > mActionToolPin
Definition: libraryeditor.h:244
QScopedPointer< QAction > mActionNewElement
Definition: libraryeditor.h:199
QScopedPointer< QAction > mActionSnapToGrid
Definition: libraryeditor.h:228
The NewElementWizardContext class.
Definition: newelementwizardcontext.h:58
The SearchToolBar class.
Definition: searchtoolbar.h:44
Helper to handle some of the librepcb::editor::EditorCommand actions.
Definition: standardeditorcommandhandler.h:48
The UndoStackActionGroup class groups an undo-QAction and redo-QAction together and optionally connec...
Definition: undostackactiongroup.h:45
Definition: occmodel.cpp:77