LibrePCB Developers Documentation
Loading...
Searching...
No Matches
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
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> mActionImportKiCadLibrary;
197 QScopedPointer<QAction> mActionExportImage;
198 QScopedPointer<QAction> mActionExportPdf;
199 QScopedPointer<QAction> mActionPrint;
200 QScopedPointer<QAction> mActionNewElement;
201 QScopedPointer<QAction> mActionNextPage;
202 QScopedPointer<QAction> mActionPreviousPage;
203 QScopedPointer<QAction> mActionFind;
204 QScopedPointer<QAction> mActionSelectAll;
205 QScopedPointer<QAction> mActionGridProperties;
206 QScopedPointer<QAction> mActionGridIncrease;
207 QScopedPointer<QAction> mActionGridDecrease;
208 QScopedPointer<QAction> mActionToggleBgImage;
209 QScopedPointer<QAction> mActionZoomFit;
210 QScopedPointer<QAction> mActionZoomIn;
211 QScopedPointer<QAction> mActionZoomOut;
212 QScopedPointer<QAction> mActionToggle3D;
213 QScopedPointer<QAction> mActionUndo;
214 QScopedPointer<QAction> mActionRedo;
215 QScopedPointer<QAction> mActionCut;
216 QScopedPointer<QAction> mActionCopy;
217 QScopedPointer<QAction> mActionPaste;
218 QScopedPointer<QAction> mActionMoveLeft;
219 QScopedPointer<QAction> mActionMoveRight;
220 QScopedPointer<QAction> mActionMoveUp;
221 QScopedPointer<QAction> mActionMoveDown;
222 QScopedPointer<QAction> mActionRotateCcw;
223 QScopedPointer<QAction> mActionRotateCw;
224 QScopedPointer<QAction> mActionMirrorHorizontal;
225 QScopedPointer<QAction> mActionMirrorVertical;
226 QScopedPointer<QAction> mActionFlipHorizontal;
227 QScopedPointer<QAction> mActionFlipVertical;
228 QScopedPointer<QAction> mActionMoveAlign;
229 QScopedPointer<QAction> mActionSnapToGrid;
230 QScopedPointer<QAction> mActionProperties;
231 QScopedPointer<QAction> mActionRemove;
232 QScopedPointer<QAction> mActionHelperTools;
233 QScopedPointer<QAction> mActionGenerateOutline;
234 QScopedPointer<QAction> mActionGenerateCourtyard;
235 QScopedPointer<QAction> mActionAbort;
236 QScopedPointer<QAction> mActionToolSelect;
237 QScopedPointer<QAction> mActionToolLine;
238 QScopedPointer<QAction> mActionToolRect;
239 QScopedPointer<QAction> mActionToolPolygon;
240 QScopedPointer<QAction> mActionToolCircle;
241 QScopedPointer<QAction> mActionToolArc;
242 QScopedPointer<QAction> mActionToolText;
243 QScopedPointer<QAction> mActionToolName;
244 QScopedPointer<QAction> mActionToolValue;
245 QScopedPointer<QAction> mActionToolPin;
246 QScopedPointer<QAction> mActionToolSmtPadStandard;
247 QScopedPointer<QAction> mActionToolThtPad;
248 QScopedPointer<QAction> mActionToolSpecialPadThermal;
249 QScopedPointer<QAction> mActionToolSpecialPadBga;
250 QScopedPointer<QAction> mActionToolSpecialPadEdgeConnector;
251 QScopedPointer<QAction> mActionToolSpecialPadTest;
252 QScopedPointer<QAction> mActionToolSpecialPadLocalFiducial;
253 QScopedPointer<QAction> mActionToolSpecialPadGlobalFiducial;
254 QScopedPointer<QAction> mActionToolZone;
255 QScopedPointer<QAction> mActionToolHole;
256 QScopedPointer<QAction> mActionToolMeasure;
257 QScopedPointer<QAction> mActionReNumberPads;
258
259 // Action groups
262
263 // Toolbars
264 QScopedPointer<QToolBar> mToolBarFile;
265 QScopedPointer<QToolBar> mToolBarEdit;
266 QScopedPointer<QToolBar> mToolBarView;
268 QScopedPointer<QToolBar> mToolBarCommand;
269 QScopedPointer<QToolBar> mToolBarTools;
270};
271
272/*******************************************************************************
273 * End of File
274 ******************************************************************************/
275
276} // namespace editor
277} // namespace librepcb
278
279#endif
This class represents absolute, well-formatted paths to files or directories.
Definition filepath.h:127
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:61
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:233
EditorWidgetBase * mCurrentEditorWidget
Definition libraryeditor.h:177
void setAvailableFeatures(const QSet< EditorWidgetBase::Feature > &features) noexcept
Definition libraryeditor.cpp:998
EditorWidgetBase::Context createContext(bool isNewElement) noexcept
Definition libraryeditor.cpp:991
QScopedPointer< QAction > mActionZoomFit
Definition libraryeditor.h:209
void duplicatePackageTriggered(const FilePath &fp) noexcept
Definition libraryeditor.cpp:364
QScopedPointer< QAction > mActionExportImage
Definition libraryeditor.h:197
QScopedPointer< QAction > mActionToolSpecialPadEdgeConnector
Definition libraryeditor.h:250
void duplicateLibraryElement(NewElementWizardContext::ElementType type, const FilePath &fp)
Definition libraryeditor.cpp:1082
QScopedPointer< QAction > mActionSave
Definition libraryeditor.h:186
QScopedPointer< UndoStackActionGroup > mUndoStackActionGroup
Definition libraryeditor.h:260
QScopedPointer< QAction > mActionCut
Definition libraryeditor.h:215
void closeTabIfOpen(const FilePath &fp) noexcept
Definition libraryeditor.cpp:281
void newDeviceTriggered() noexcept
Definition libraryeditor.cpp:319
QScopedPointer< QAction > mActionMoveAlign
Definition libraryeditor.h:228
~LibraryEditor() noexcept
Definition libraryeditor.cpp:252
QScopedPointer< QAction > mActionZoomIn
Definition libraryeditor.h:210
QScopedPointer< QAction > mActionCopy
Definition libraryeditor.h:216
QScopedPointer< QAction > mActionToolRect
Definition libraryeditor.h:238
QScopedPointer< QAction > mActionKeyboardShortcutsReference
Definition libraryeditor.h:184
void addLayer(const QString &name) noexcept
Definition libraryeditor.cpp:1192
QScopedPointer< QAction > mActionMirrorHorizontal
Definition libraryeditor.h:224
void newLibraryElement(NewElementWizardContext::ElementType type)
Definition libraryeditor.cpp:1071
QScopedPointer< QAction > mActionQuit
Definition libraryeditor.h:191
QScopedPointer< ExclusiveActionGroup > mToolsActionGroup
Definition libraryeditor.h:261
QScopedPointer< QAction > mActionToolHole
Definition libraryeditor.h:255
QScopedPointer< QAction > mActionMoveDown
Definition libraryeditor.h:221
QScopedPointer< QAction > mActionGridIncrease
Definition libraryeditor.h:206
QScopedPointer< QAction > mActionHelperTools
Definition libraryeditor.h:232
void duplicateComponentTriggered(const FilePath &fp) noexcept
Definition libraryeditor.cpp:368
QScopedPointer< QAction > mActionToolValue
Definition libraryeditor.h:244
QScopedPointer< QAction > mActionCloseTab
Definition libraryeditor.h:188
QScopedPointer< QAction > mActionCloseAllTabs
Definition libraryeditor.h:189
QScopedPointer< QAction > mActionGridProperties
Definition libraryeditor.h:205
void setActiveEditorWidget(EditorWidgetBase *widget)
Definition libraryeditor.cpp:1046
void newPackageCategoryTriggered() noexcept
Definition libraryeditor.cpp:303
QScopedPointer< QAction > mActionReNumberPads
Definition libraryeditor.h:257
bool closeAllTabs(bool withNonClosable, bool askForSave) noexcept
Definition libraryeditor.cpp:1170
QList< std::shared_ptr< GraphicsLayer > > mLayers
Definition libraryeditor.h:176
QScopedPointer< QAction > mActionToolSpecialPadTest
Definition libraryeditor.h:251
QScopedPointer< QAction > mActionAbort
Definition libraryeditor.h:235
QScopedPointer< QToolBar > mToolBarEdit
Definition libraryeditor.h:265
QScopedPointer< QAction > mActionRotateCcw
Definition libraryeditor.h:222
void createMenus() noexcept
Definition libraryeditor.cpp:881
QScopedPointer< QAction > mActionToolArc
Definition libraryeditor.h:241
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:1093
bool mIsOpenedReadOnly
Definition libraryeditor.h:173
bool closeTab(int index) noexcept
Definition libraryeditor.cpp:424
QScopedPointer< QAction > mActionSelectAll
Definition libraryeditor.h:204
std::shared_ptr< GraphicsLayer > getLayer(const QString &name) const noexcept override
Definition libraryeditor.h:79
QScopedPointer< QToolBar > mToolBarTools
Definition libraryeditor.h:269
QScopedPointer< QAction > mActionMoveUp
Definition libraryeditor.h:220
QScopedPointer< QToolBar > mToolBarFile
Definition libraryeditor.h:264
void updateTabTitles() noexcept
Definition libraryeditor.cpp:1119
QScopedPointer< QAction > mActionPreviousPage
Definition libraryeditor.h:202
QScopedPointer< QAction > mActionImportDxf
Definition libraryeditor.h:194
void createToolBars() noexcept
Definition libraryeditor.cpp:772
QScopedPointer< QAction > mActionCloseWindow
Definition libraryeditor.h:190
void duplicateSymbolTriggered(const FilePath &fp) noexcept
Definition libraryeditor.cpp:360
void currentTabChanged(int index) noexcept
Definition libraryeditor.cpp:409
QScopedPointer< QAction > mActionToolSelect
Definition libraryeditor.h:236
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:253
void editDeviceTriggered(const FilePath &fp) noexcept
Definition libraryeditor.cpp:344
QScopedPointer< QAction > mActionUndo
Definition libraryeditor.h:213
QScopedPointer< QAction > mActionRotateCw
Definition libraryeditor.h:223
QScopedPointer< SearchToolBar > mToolBarSearch
Definition libraryeditor.h:267
QScopedPointer< QAction > mActionToolLine
Definition libraryeditor.h:237
QScopedPointer< QAction > mActionFlipVertical
Definition libraryeditor.h:227
QScopedPointer< QAction > mActionMoveLeft
Definition libraryeditor.h:218
QScopedPointer< QToolBar > mToolBarCommand
Definition libraryeditor.h:268
QScopedPointer< QAction > mActionProperties
Definition libraryeditor.h:230
bool closeAndDestroy(bool askForSave) noexcept
Close the library editor (this will destroy this object!)
Definition libraryeditor.cpp:262
QScopedPointer< StandardEditorCommandHandler > mStandardCommandHandler
Definition libraryeditor.h:175
QScopedPointer< QAction > mActionSaveAll
Definition libraryeditor.h:187
void editComponentCategoryTriggered(const FilePath &fp) noexcept
Definition libraryeditor.cpp:323
QScopedPointer< QAction > mActionToolCircle
Definition libraryeditor.h:240
QScopedPointer< QAction > mActionExportPdf
Definition libraryeditor.h:198
void tabCountChanged() noexcept
Definition libraryeditor.cpp:1145
QScopedPointer< QAction > mActionToggleBgImage
Definition libraryeditor.h:208
QScopedPointer< QToolBar > mToolBarView
Definition libraryeditor.h:266
void editComponentTriggered(const FilePath &fp) noexcept
Definition libraryeditor.cpp:340
Library * mLibrary
Definition libraryeditor.h:178
QScopedPointer< QAction > mActionToolSmtPadStandard
Definition libraryeditor.h:246
void newComponentCategoryTriggered() noexcept
Definition libraryeditor.cpp:299
QScopedPointer< QAction > mActionToolSpecialPadThermal
Definition libraryeditor.h:248
QScopedPointer< QAction > mActionToolName
Definition libraryeditor.h:243
QScopedPointer< QAction > mActionToolPolygon
Definition libraryeditor.h:239
void newSymbolTriggered() noexcept
Definition libraryeditor.cpp:307
void editPackageCategoryTriggered(const FilePath &fp) noexcept
Definition libraryeditor.cpp:328
QScopedPointer< QAction > mActionImportKiCadLibrary
Definition libraryeditor.h:196
Workspace & mWorkspace
Definition libraryeditor.h:172
QScopedPointer< QAction > mActionGenerateCourtyard
Definition libraryeditor.h:234
QScopedPointer< QAction > mActionOnlineDocumentation
Definition libraryeditor.h:183
QScopedPointer< QAction > mActionFileManager
Definition libraryeditor.h:192
void newComponentTriggered() noexcept
Definition libraryeditor.cpp:315
QScopedPointer< QAction > mActionFind
Definition libraryeditor.h:203
void editSymbolTriggered(const FilePath &fp) noexcept
Definition libraryeditor.cpp:332
QScopedPointer< Ui::LibraryEditor > mUi
Definition libraryeditor.h:174
QScopedPointer< QAction > mActionMoveRight
Definition libraryeditor.h:219
void keyPressEvent(QKeyEvent *event) noexcept override
Definition libraryeditor.cpp:1149
QScopedPointer< QAction > mActionImportEagleLibrary
Definition libraryeditor.h:195
void duplicateComponentCategoryTriggered(const FilePath &fp) noexcept
Definition libraryeditor.cpp:348
void newPackageTriggered() noexcept
Definition libraryeditor.cpp:311
void closeEvent(QCloseEvent *event) noexcept override
Definition libraryeditor.cpp:1162
void duplicateDeviceTriggered(const FilePath &fp) noexcept
Definition libraryeditor.cpp:372
LibraryEditor(const LibraryEditor &other)=delete
QScopedPointer< QAction > mActionPaste
Definition libraryeditor.h:217
void duplicatePackageCategoryTriggered(const FilePath &fp) noexcept
Definition libraryeditor.cpp:354
void createActions() noexcept
Definition libraryeditor.cpp:476
QScopedPointer< QAction > mActionPrint
Definition libraryeditor.h:199
QScopedPointer< QAction > mActionGridDecrease
Definition libraryeditor.h:207
void editPackageTriggered(const FilePath &fp) noexcept
Definition libraryeditor.cpp:336
QScopedPointer< QAction > mActionNextPage
Definition libraryeditor.h:201
QScopedPointer< QAction > mActionRedo
Definition libraryeditor.h:214
LibraryEditor & operator=(const LibraryEditor &rhs)=delete
QScopedPointer< QAction > mActionToolThtPad
Definition libraryeditor.h:247
void tabCloseRequested(int index) noexcept
Definition libraryeditor.cpp:414
QScopedPointer< QAction > mActionAboutQt
Definition libraryeditor.h:182
QScopedPointer< QAction > mActionMirrorVertical
Definition libraryeditor.h:225
QScopedPointer< QAction > mActionToolMeasure
Definition libraryeditor.h:256
QScopedPointer< QAction > mActionRemove
Definition libraryeditor.h:231
QScopedPointer< QAction > mActionFlipHorizontal
Definition libraryeditor.h:226
QScopedPointer< QAction > mActionToolSpecialPadLocalFiducial
Definition libraryeditor.h:252
QScopedPointer< QAction > mActionToolSpecialPadBga
Definition libraryeditor.h:249
QScopedPointer< QAction > mActionToolZone
Definition libraryeditor.h:254
QScopedPointer< QAction > mActionZoomOut
Definition libraryeditor.h:211
QScopedPointer< QAction > mActionToggle3D
Definition libraryeditor.h:212
void editLibraryElementTriggered(const FilePath &fp, bool isNewElement) noexcept
Definition libraryeditor.cpp:377
QScopedPointer< QAction > mActionToolText
Definition libraryeditor.h:242
QScopedPointer< QAction > mActionToolPin
Definition libraryeditor.h:245
QScopedPointer< QAction > mActionNewElement
Definition libraryeditor.h:200
QScopedPointer< QAction > mActionSnapToGrid
Definition libraryeditor.h:229
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:76
Definition uuid.h:186