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 {
93 };
94
95 enum class Feature {
96 // Handled by editor widgets (constant).
97 Close,
98 Filter,
101 ExportGraphics,
102 GenerateOutline,
103 GenerateCourtyard,
104
105 // Handled by FSM states (dynamic).
106 SelectGraphics,
107 ImportGraphics,
108 Abort,
109 Cut,
110 Copy,
111 Paste,
112 Remove,
113 Move,
114 Rotate,
115 Mirror,
116 Flip,
117 SnapToGrid,
118 Properties,
119 };
120
121 // Constructors / Destructor
123 EditorWidgetBase(const EditorWidgetBase& other) = delete;
124 explicit EditorWidgetBase(const Context& context, const FilePath& fp,
125 QWidget* parent = nullptr);
126 virtual ~EditorWidgetBase() noexcept;
127
128 // Getters
129 const FilePath& getFilePath() const noexcept { return mFilePath; }
130 bool isDirty() const noexcept {
131 return mManualModificationsMade || (!mUndoStack->isClean());
132 }
133 virtual QSet<Feature> getAvailableFeatures() const noexcept = 0;
134
135 // Setters
136 virtual void connectEditor(UndoStackActionGroup& undoStackActionGroup,
137 ExclusiveActionGroup& toolsActionGroup,
138 QToolBar& commandToolBar,
139 StatusBar& statusBar) noexcept;
140 virtual void disconnectEditor() noexcept;
141
142 // Operator Overloadings
143 EditorWidgetBase& operator=(const EditorWidgetBase& rhs) = delete;
144
145public slots:
146 virtual bool save() noexcept;
147 virtual bool selectAll() noexcept { return false; }
148 virtual bool cut() noexcept { return false; }
149 virtual bool copy() noexcept { return false; }
150 virtual bool paste() noexcept { return false; }
151 virtual bool move(Qt::ArrowType direction) noexcept {
152 Q_UNUSED(direction);
153 return false;
154 }
155 virtual bool rotate(const librepcb::Angle& rotation) noexcept {
156 Q_UNUSED(rotation);
157 return false;
158 }
159 virtual bool mirror(Qt::Orientation orientation) noexcept {
160 Q_UNUSED(orientation);
161 return false;
162 }
163 virtual bool flip(Qt::Orientation orientation) noexcept {
164 Q_UNUSED(orientation);
165 return false;
166 }
167 virtual bool snapToGrid() noexcept { return false; }
168 virtual bool remove() noexcept { return false; }
169 virtual bool editProperties() noexcept { return false; }
170 virtual bool zoomIn() noexcept { return false; }
171 virtual bool zoomOut() noexcept { return false; }
172 virtual bool zoomAll() noexcept { return false; }
173 virtual bool toggle3D() noexcept { return false; }
174 virtual bool abortCommand() noexcept { return false; }
175 virtual bool processGenerateOutline() noexcept { return false; }
176 virtual bool processGenerateCourtyard() noexcept { return false; }
177 virtual bool importDxf() noexcept { return false; }
178 virtual bool exportImage() noexcept;
179 virtual bool exportPdf() noexcept;
180 virtual bool print() noexcept;
181 virtual bool editGridProperties() noexcept { return false; }
182 virtual bool increaseGridInterval() noexcept { return false; }
183 virtual bool decreaseGridInterval() noexcept { return false; }
184
185protected: // Methods
186 void setupInterfaceBrokenWarningWidget(QWidget& widget) noexcept;
187 void setupErrorNotificationWidget(QWidget& widget) noexcept;
188 virtual bool isInterfaceBroken() const noexcept = 0;
189 virtual bool toolChangeRequested(Tool newTool,
190 const QVariant& mode) noexcept {
191 Q_UNUSED(newTool);
192 Q_UNUSED(mode);
193 return false;
194 }
195 virtual bool runChecks(RuleCheckMessageList& msgs) const = 0;
197 std::shared_ptr<const RuleCheckMessage> msg,
198 bool approve) noexcept;
200 const QString& settingsKey) noexcept {
201 Q_UNUSED(output);
202 Q_UNUSED(settingsKey);
203 return false;
204 }
205 void undoStackStateModified() noexcept;
206 void setStatusBarMessage(const QString& message, int timeoutMs = -1) noexcept;
207 const QStringList& getLibLocaleOrder() const noexcept;
208 QString getWorkspaceSettingsUserName() noexcept;
209
210private slots:
211 void updateCheckMessages() noexcept;
212
213private: // Methods
224 static bool askForRestoringBackup(const FilePath& dir);
225 void toolRequested(int tool, const QVariant& mode) noexcept;
226 void undoStackCleanChanged(bool clean) noexcept;
227 void scheduleLibraryElementChecks() noexcept;
229 std::shared_ptr<const RuleCheckMessage> msg, bool applyFix) = 0;
231 std::shared_ptr<const RuleCheckMessage> msg) noexcept override;
233 std::shared_ptr<const RuleCheckMessage> msg) noexcept override;
235 std::shared_ptr<const RuleCheckMessage> msg) noexcept override;
237 std::shared_ptr<const RuleCheckMessage> msg) noexcept override;
239 std::shared_ptr<const RuleCheckMessage> msg) noexcept override;
240
241signals:
242 void dirtyChanged(bool dirty);
244 void interfaceBrokenChanged(bool broken);
245 void errorsAvailableChanged(bool hasErrors);
247 const QSet<librepcb::editor::EditorWidgetBase::Feature>& features);
248
249protected: // Data
253 QScopedPointer<UndoStack> mUndoStack;
261
262 // Memorized message approvals
265};
266
267inline QtCompat::Hash qHash(const EditorWidgetBase::Feature& feature,
268 QtCompat::Hash seed = 0) noexcept {
269 return ::qHash(static_cast<int>(feature), seed);
270}
271
272/*******************************************************************************
273 * End of File
274 ******************************************************************************/
275
276} // namespace editor
277} // namespace librepcb
278
279#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:250
virtual bool remove() noexcept
Definition: editorwidgetbase.h:168
virtual bool editProperties() noexcept
Definition: editorwidgetbase.h:169
virtual bool move(Qt::ArrowType direction) noexcept
Definition: editorwidgetbase.h:151
virtual bool save() noexcept
Definition: editorwidgetbase.cpp:122
void interfaceBrokenChanged(bool broken)
virtual bool increaseGridInterval() noexcept
Definition: editorwidgetbase.h:182
ExclusiveActionGroup * mToolsActionGroup
Definition: editorwidgetbase.h:255
virtual bool rotate(const librepcb::Angle &rotation) noexcept
Definition: editorwidgetbase.h:155
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:264
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:176
virtual bool decreaseGridInterval() noexcept
Definition: editorwidgetbase.h:183
virtual void disconnectEditor() noexcept
Definition: editorwidgetbase.cpp:103
virtual bool paste() noexcept
Definition: editorwidgetbase.h:150
void elementEdited(const librepcb::FilePath &fp)
virtual bool abortCommand() noexcept
Definition: editorwidgetbase.h:174
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:258
QSet< SExpression > mSupportedApprovals
Definition: editorwidgetbase.h:263
virtual bool zoomAll() noexcept
Definition: editorwidgetbase.h:172
FilePath mFilePath
Definition: editorwidgetbase.h:251
void scheduleLibraryElementChecks() noexcept
Definition: editorwidgetbase.cpp:277
virtual bool flip(Qt::Orientation orientation) noexcept
Definition: editorwidgetbase.h:163
virtual bool exportImage() noexcept
Definition: editorwidgetbase.cpp:132
virtual bool copy() noexcept
Definition: editorwidgetbase.h:149
void setupErrorNotificationWidget(QWidget &widget) noexcept
Definition: editorwidgetbase.cpp:170
bool isDirty() const noexcept
Definition: editorwidgetbase.h:130
const FilePath & getFilePath() const noexcept
Definition: editorwidgetbase.h:129
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
@ 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:181
Feature
Definition: editorwidgetbase.h:95
virtual bool mirror(Qt::Orientation orientation) noexcept
Definition: editorwidgetbase.h:159
std::shared_ptr< TransactionalFileSystem > mFileSystem
Definition: editorwidgetbase.h:252
void ruleCheckDescriptionRequested(std::shared_ptr< const RuleCheckMessage > msg) noexcept override
Definition: editorwidgetbase.cpp:332
UndoStackActionGroup * mUndoStackActionGroup
Definition: editorwidgetbase.h:254
virtual bool importDxf() noexcept
Definition: editorwidgetbase.h:177
virtual bool toggle3D() noexcept
Definition: editorwidgetbase.h:173
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:170
void ruleCheckMessageDoubleClicked(std::shared_ptr< const RuleCheckMessage > msg) noexcept override
Definition: editorwidgetbase.cpp:344
QScopedPointer< ToolBarProxy > mCommandToolBarProxy
Definition: editorwidgetbase.h:257
QString mStatusBarMessage
Definition: editorwidgetbase.h:260
void availableFeaturesChanged(const QSet< librepcb::editor::EditorWidgetBase::Feature > &features)
virtual bool execGraphicsExportDialog(GraphicsExportDialog::Output output, const QString &settingsKey) noexcept
Definition: editorwidgetbase.h:199
virtual bool processGenerateOutline() noexcept
Definition: editorwidgetbase.h:175
virtual bool snapToGrid() noexcept
Definition: editorwidgetbase.h:167
virtual bool cut() noexcept
Definition: editorwidgetbase.h:148
virtual bool toolChangeRequested(Tool newTool, const QVariant &mode) noexcept
Definition: editorwidgetbase.h:189
QScopedPointer< UndoStack > mUndoStack
Definition: editorwidgetbase.h:253
StatusBar * mStatusBar
Definition: editorwidgetbase.h:256
virtual bool isInterfaceBroken() const noexcept=0
virtual bool exportPdf() noexcept
Definition: editorwidgetbase.cpp:136
virtual bool zoomOut() noexcept
Definition: editorwidgetbase.h:171
virtual bool selectAll() noexcept
Definition: editorwidgetbase.h:147
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:259
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:267
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