LibrePCB Developers Documentation
editorwidgetbase.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_EDITORWIDGETBASE_H
21#define LIBREPCB_EDITOR_EDITORWIDGETBASE_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
26#include "../dialogs/graphicsexportdialog.h"
27#include "../undostack.h"
28#include "../widgets/rulechecklistwidget.h"
29
32
33#include <QtCore>
34#include <QtWidgets>
35
36/*******************************************************************************
37 * Namespace / Forward Declarations
38 ******************************************************************************/
39namespace librepcb {
40
41class Angle;
42class Library;
43class LibraryBaseElement;
44class Point;
45class Workspace;
46
47namespace editor {
48
49class ExclusiveActionGroup;
50class IF_GraphicsLayerProvider;
51class StatusBar;
52class ToolBarProxy;
53class UndoStackActionGroup;
54
55/*******************************************************************************
56 * Class EditorWidgetBase
57 ******************************************************************************/
58
62class EditorWidgetBase : public QWidget, protected IF_RuleCheckHandler {
63 Q_OBJECT
64
65public:
66 // Types
67
68 struct Context {
74 };
75
76 enum Tool {
94 };
95
96 enum class Feature {
97 // Handled by editor widgets (constant).
98 Close,
99 Filter,
102 BackgroundImage,
103 ExportGraphics,
104 GenerateOutline,
105 GenerateCourtyard,
106 ReNumberPads,
107
108 // Handled by FSM states (dynamic).
109 SelectGraphics,
110 ImportGraphics,
111 Abort,
112 Cut,
113 Copy,
114 Paste,
115 Remove,
116 Move,
117 Rotate,
118 Mirror,
119 Flip,
120 MoveAlign,
121 SnapToGrid,
122 Properties,
123 };
124
125 // Constructors / Destructor
127 EditorWidgetBase(const EditorWidgetBase& other) = delete;
128 explicit EditorWidgetBase(const Context& context, const FilePath& fp,
129 QWidget* parent = nullptr);
130 virtual ~EditorWidgetBase() noexcept;
131
132 // Getters
133 const FilePath& getFilePath() const noexcept { return mFilePath; }
134 bool isDirty() const noexcept {
135 return mManualModificationsMade || (!mUndoStack->isClean());
136 }
137 virtual bool isBackgroundImageSet() const noexcept { return false; }
138 virtual QSet<Feature> getAvailableFeatures() const noexcept = 0;
139
140 // Setters
141 virtual void connectEditor(UndoStackActionGroup& undoStackActionGroup,
142 ExclusiveActionGroup& toolsActionGroup,
143 QToolBar& commandToolBar,
144 StatusBar& statusBar) noexcept;
145 virtual void disconnectEditor() noexcept;
146
147 // Operator Overloadings
148 EditorWidgetBase& operator=(const EditorWidgetBase& rhs) = delete;
149
150public slots:
151 virtual bool save() noexcept;
152 virtual bool selectAll() noexcept { return false; }
153 virtual bool cut() noexcept { return false; }
154 virtual bool copy() noexcept { return false; }
155 virtual bool paste() noexcept { return false; }
156 virtual bool move(Qt::ArrowType direction) noexcept {
157 Q_UNUSED(direction);
158 return false;
159 }
160 virtual bool rotate(const librepcb::Angle& rotation) noexcept {
161 Q_UNUSED(rotation);
162 return false;
163 }
164 virtual bool mirror(Qt::Orientation orientation) noexcept {
165 Q_UNUSED(orientation);
166 return false;
167 }
168 virtual bool flip(Qt::Orientation orientation) noexcept {
169 Q_UNUSED(orientation);
170 return false;
171 }
172 virtual bool moveAlign() noexcept { return false; }
173 virtual bool snapToGrid() noexcept { return false; }
174 virtual bool remove() noexcept { return false; }
175 virtual bool editProperties() noexcept { return false; }
176 virtual bool zoomIn() noexcept { return false; }
177 virtual bool zoomOut() noexcept { return false; }
178 virtual bool zoomAll() noexcept { return false; }
179 virtual bool toggle3D() noexcept { return false; }
180 virtual bool abortCommand() noexcept { return false; }
181 virtual bool processGenerateOutline() noexcept { return false; }
182 virtual bool processGenerateCourtyard() noexcept { return false; }
183 virtual bool importDxf() noexcept { return false; }
184 virtual bool exportImage() noexcept;
185 virtual bool exportPdf() noexcept;
186 virtual bool print() noexcept;
187 virtual bool editGridProperties() noexcept { return false; }
188 virtual bool increaseGridInterval() noexcept { return false; }
189 virtual bool decreaseGridInterval() noexcept { return false; }
190 virtual bool toggleBackgroundImage() noexcept { return false; }
191
192protected: // Methods
193 void setupInterfaceBrokenWarningWidget(QWidget& widget) noexcept;
194 void setupErrorNotificationWidget(QWidget& widget) noexcept;
195 virtual bool isInterfaceBroken() const noexcept = 0;
196 virtual bool toolChangeRequested(Tool newTool,
197 const QVariant& mode) noexcept {
198 Q_UNUSED(newTool);
199 Q_UNUSED(mode);
200 return false;
201 }
202 virtual bool runChecks(RuleCheckMessageList& msgs) const = 0;
204 std::shared_ptr<const RuleCheckMessage> msg,
205 bool approve) noexcept;
207 const QString& settingsKey) noexcept {
208 Q_UNUSED(output);
209 Q_UNUSED(settingsKey);
210 return false;
211 }
212 void undoStackStateModified() noexcept;
213 void setStatusBarMessage(const QString& message, int timeoutMs = -1) noexcept;
214 const QStringList& getLibLocaleOrder() const noexcept;
215 QString getWorkspaceSettingsUserName() noexcept;
216
217private slots:
218 void updateCheckMessages() noexcept;
219
220private: // Methods
231 static bool askForRestoringBackup(const FilePath& dir);
232 void toolRequested(int tool, const QVariant& mode) noexcept;
233 void undoStackCleanChanged(bool clean) noexcept;
234 void scheduleLibraryElementChecks() noexcept;
236 std::shared_ptr<const RuleCheckMessage> msg, bool applyFix) = 0;
238 std::shared_ptr<const RuleCheckMessage> msg) noexcept override;
240 std::shared_ptr<const RuleCheckMessage> msg) noexcept override;
242 std::shared_ptr<const RuleCheckMessage> msg) noexcept override;
244 std::shared_ptr<const RuleCheckMessage> msg) noexcept override;
246 std::shared_ptr<const RuleCheckMessage> msg) noexcept override;
247
248signals:
249 void dirtyChanged(bool dirty);
251 void interfaceBrokenChanged(bool broken);
252 void errorsAvailableChanged(bool hasErrors);
254 const QSet<librepcb::editor::EditorWidgetBase::Feature>& features);
255
256protected: // Data
260 QScopedPointer<UndoStack> mUndoStack;
268
269 // Memorized message approvals
272};
273
274inline QtCompat::Hash qHash(const EditorWidgetBase::Feature& feature,
275 QtCompat::Hash seed = 0) noexcept {
276 return ::qHash(static_cast<int>(feature), seed);
277}
278
279/*******************************************************************************
280 * End of File
281 ******************************************************************************/
282
283} // namespace editor
284} // namespace librepcb
285
286#endif
The Angle class is used to represent an angle (for example 12.75 degrees)
Definition: angle.h:78
This class represents absolute, well-formatted paths to files or directories.
Definition: filepath.h:129
The LibraryBaseElement class.
Definition: librarybaseelement.h:48
The Library class represents a library directory.
Definition: library.h:46
Qt compatibility helper class.
Definition: qtcompat.h:43
The RuleCheckMessage class.
Definition: rulecheckmessage.h:45
The SExpression class.
Definition: sexpression.h:69
Transactional librepcb::FileSystem implementation.
Definition: transactionalfilesystem.h:71
The Workspace class represents a workspace with all its data (library, projects, settings,...
Definition: workspace.h:54
The EditorWidgetBase class.
Definition: editorwidgetbase.h:62
void errorsAvailableChanged(bool hasErrors)
void setStatusBarMessage(const QString &message, int timeoutMs=-1) noexcept
Definition: editorwidgetbase.cpp:217
Context mContext
Definition: editorwidgetbase.h:257
virtual bool remove() noexcept
Definition: editorwidgetbase.h:174
virtual bool editProperties() noexcept
Definition: editorwidgetbase.h:175
virtual bool move(Qt::ArrowType direction) noexcept
Definition: editorwidgetbase.h:156
virtual bool save() noexcept
Definition: editorwidgetbase.cpp:122
void interfaceBrokenChanged(bool broken)
virtual bool increaseGridInterval() noexcept
Definition: editorwidgetbase.h:188
ExclusiveActionGroup * mToolsActionGroup
Definition: editorwidgetbase.h:262
virtual bool rotate(const librepcb::Angle &rotation) noexcept
Definition: editorwidgetbase.h:160
virtual bool runChecks(RuleCheckMessageList &msgs) const =0
virtual ~EditorWidgetBase() noexcept
Definition: editorwidgetbase.cpp:78
virtual void connectEditor(UndoStackActionGroup &undoStackActionGroup, ExclusiveActionGroup &toolsActionGroup, QToolBar &commandToolBar, StatusBar &statusBar) noexcept
Definition: editorwidgetbase.cpp:85
void toolRequested(int tool, const QVariant &mode) noexcept
Definition: editorwidgetbase.cpp:268
QSet< SExpression > mDisappearedApprovals
Definition: editorwidgetbase.h:271
void undoStackStateModified() noexcept
Definition: editorwidgetbase.cpp:206
static bool askForRestoringBackup(const FilePath &dir)
Ask the user whether to restore a backup of a library element.
Definition: editorwidgetbase.cpp:250
const QStringList & getLibLocaleOrder() const noexcept
Definition: editorwidgetbase.cpp:231
void setMessageApproved(LibraryBaseElement &element, std::shared_ptr< const RuleCheckMessage > msg, bool approve) noexcept
Definition: editorwidgetbase.cpp:190
void updateCheckMessages() noexcept
Definition: editorwidgetbase.cpp:287
virtual bool processGenerateCourtyard() noexcept
Definition: editorwidgetbase.h:182
virtual bool decreaseGridInterval() noexcept
Definition: editorwidgetbase.h:189
virtual void disconnectEditor() noexcept
Definition: editorwidgetbase.cpp:103
virtual bool paste() noexcept
Definition: editorwidgetbase.h:155
void elementEdited(const librepcb::FilePath &fp)
virtual bool abortCommand() noexcept
Definition: editorwidgetbase.h:180
void undoStackCleanChanged(bool clean) noexcept
Definition: editorwidgetbase.cpp:272
bool ruleCheckFixAvailable(std::shared_ptr< const RuleCheckMessage > msg) noexcept override
Definition: editorwidgetbase.cpp:313
bool mManualModificationsMade
Modifications bypassing the undo stack.
Definition: editorwidgetbase.h:265
QSet< SExpression > mSupportedApprovals
Definition: editorwidgetbase.h:270
virtual bool zoomAll() noexcept
Definition: editorwidgetbase.h:178
FilePath mFilePath
Definition: editorwidgetbase.h:258
void scheduleLibraryElementChecks() noexcept
Definition: editorwidgetbase.cpp:277
virtual bool flip(Qt::Orientation orientation) noexcept
Definition: editorwidgetbase.h:168
virtual bool exportImage() noexcept
Definition: editorwidgetbase.cpp:132
virtual bool copy() noexcept
Definition: editorwidgetbase.h:154
void setupErrorNotificationWidget(QWidget &widget) noexcept
Definition: editorwidgetbase.cpp:170
bool isDirty() const noexcept
Definition: editorwidgetbase.h:134
const FilePath & getFilePath() const noexcept
Definition: editorwidgetbase.h:133
EditorWidgetBase(const EditorWidgetBase &other)=delete
QString getWorkspaceSettingsUserName() noexcept
Definition: editorwidgetbase.cpp:235
virtual bool print() noexcept
Definition: editorwidgetbase.cpp:140
Tool
Definition: editorwidgetbase.h:76
@ MEASURE
Definition: editorwidgetbase.h:92
@ ADD_HOLES
Definition: editorwidgetbase.h:91
@ SELECT
Definition: editorwidgetbase.h:78
@ RENUMBER_PADS
Definition: editorwidgetbase.h:93
@ ADD_NAMES
Definition: editorwidgetbase.h:86
@ DRAW_LINE
Definition: editorwidgetbase.h:79
@ ADD_VALUES
Definition: editorwidgetbase.h:87
@ DRAW_POLYGON
Definition: editorwidgetbase.h:81
@ DRAW_ARC
Definition: editorwidgetbase.h:83
@ DRAW_RECT
Definition: editorwidgetbase.h:80
@ DRAW_TEXT
Definition: editorwidgetbase.h:84
@ ADD_THT_PADS
Definition: editorwidgetbase.h:89
@ NONE
Definition: editorwidgetbase.h:77
@ ADD_SMT_PADS
Definition: editorwidgetbase.h:90
@ DRAW_ZONE
Definition: editorwidgetbase.h:85
@ DRAW_CIRCLE
Definition: editorwidgetbase.h:82
@ ADD_PINS
Definition: editorwidgetbase.h:88
virtual bool editGridProperties() noexcept
Definition: editorwidgetbase.h:187
virtual bool toggleBackgroundImage() noexcept
Definition: editorwidgetbase.h:190
Feature
Definition: editorwidgetbase.h:96
virtual bool mirror(Qt::Orientation orientation) noexcept
Definition: editorwidgetbase.h:164
std::shared_ptr< TransactionalFileSystem > mFileSystem
Definition: editorwidgetbase.h:259
void ruleCheckDescriptionRequested(std::shared_ptr< const RuleCheckMessage > msg) noexcept override
Definition: editorwidgetbase.cpp:332
UndoStackActionGroup * mUndoStackActionGroup
Definition: editorwidgetbase.h:261
virtual bool isBackgroundImageSet() const noexcept
Definition: editorwidgetbase.h:137
virtual bool importDxf() noexcept
Definition: editorwidgetbase.h:183
virtual bool toggle3D() noexcept
Definition: editorwidgetbase.h:179
virtual bool processRuleCheckMessage(std::shared_ptr< const RuleCheckMessage > msg, bool applyFix)=0
void ruleCheckFixRequested(std::shared_ptr< const RuleCheckMessage > msg) noexcept override
Definition: editorwidgetbase.cpp:323
virtual bool zoomIn() noexcept
Definition: editorwidgetbase.h:176
void ruleCheckMessageDoubleClicked(std::shared_ptr< const RuleCheckMessage > msg) noexcept override
Definition: editorwidgetbase.cpp:344
QScopedPointer< ToolBarProxy > mCommandToolBarProxy
Definition: editorwidgetbase.h:264
QString mStatusBarMessage
Definition: editorwidgetbase.h:267
void availableFeaturesChanged(const QSet< librepcb::editor::EditorWidgetBase::Feature > &features)
virtual bool execGraphicsExportDialog(GraphicsExportDialog::Output output, const QString &settingsKey) noexcept
Definition: editorwidgetbase.h:206
virtual bool processGenerateOutline() noexcept
Definition: editorwidgetbase.h:181
virtual bool snapToGrid() noexcept
Definition: editorwidgetbase.h:173
virtual bool cut() noexcept
Definition: editorwidgetbase.h:153
virtual bool toolChangeRequested(Tool newTool, const QVariant &mode) noexcept
Definition: editorwidgetbase.h:196
QScopedPointer< UndoStack > mUndoStack
Definition: editorwidgetbase.h:260
StatusBar * mStatusBar
Definition: editorwidgetbase.h:263
virtual bool isInterfaceBroken() const noexcept=0
virtual bool exportPdf() noexcept
Definition: editorwidgetbase.cpp:136
virtual bool zoomOut() noexcept
Definition: editorwidgetbase.h:177
virtual bool selectAll() noexcept
Definition: editorwidgetbase.h:152
void ruleCheckMessageSelected(std::shared_ptr< const RuleCheckMessage > msg) noexcept override
Definition: editorwidgetbase.cpp:339
void setupInterfaceBrokenWarningWidget(QWidget &widget) noexcept
Definition: editorwidgetbase.cpp:148
virtual QSet< Feature > getAvailableFeatures() const noexcept=0
bool mIsInterfaceBroken
Definition: editorwidgetbase.h:266
virtual bool moveAlign() noexcept
Definition: editorwidgetbase.h:172
The ExclusiveActionGroup class groups multiple QAction's together.
Definition: exclusiveactiongroup.h:54
Output
Definition: graphicsexportdialog.h:83
The GraphicsView class.
Definition: graphicsview.h:51
The IF_GraphicsLayerProvider class defines an interface for classes which provide layers.
Definition: graphicslayer.h:111
Definition: rulechecklistwidget.h:44
OpenGL 3D viewer widget.
Definition: openglview.h:52
The StatusBar class extends QStatusBar for some commonly used fields.
Definition: statusbar.h:45
The ToolBarProxy class allows to map a list of QAction's to one QToolBar.
Definition: toolbarproxy.h:45
The UndoStackActionGroup class groups an undo-QAction and redo-QAction together and optionally connec...
Definition: undostackactiongroup.h:45
The UndoStack class holds UndoCommand objects and provides undo/redo commands.
Definition: undostack.h:106
QtCompat::Hash qHash(const EditorWidgetBase::Feature &feature, QtCompat::Hash seed=0) noexcept
Definition: editorwidgetbase.h:274
Definition: occmodel.cpp:77
QVector< std::shared_ptr< const RuleCheckMessage > > RuleCheckMessageList
Definition: rulecheckmessage.h:104
Definition: editorwidgetbase.h:68
bool readOnly
Definition: editorwidgetbase.h:72
bool elementIsNewlyCreated
Definition: editorwidgetbase.h:71
const IF_GraphicsLayerProvider & layerProvider
Definition: editorwidgetbase.h:70
const Library * library
Definition: editorwidgetbase.h:73
Workspace & workspace
Definition: editorwidgetbase.h:69