LibrePCB Developers Documentation
Loading...
Searching...
No Matches
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
31
32#include <QtCore>
33#include <QtWidgets>
34
35/*******************************************************************************
36 * Namespace / Forward Declarations
37 ******************************************************************************/
38namespace librepcb {
39
40class Angle;
41class Library;
42class LibraryBaseElement;
43class Point;
44class Workspace;
45
46namespace editor {
47
48class ExclusiveActionGroup;
49class IF_GraphicsLayerProvider;
50class StatusBar;
51class ToolBarProxy;
52class UndoStackActionGroup;
53
54/*******************************************************************************
55 * Class EditorWidgetBase
56 ******************************************************************************/
57
61class EditorWidgetBase : public QWidget, protected IF_RuleCheckHandler {
62 Q_OBJECT
63
64public:
65 // Types
66
74
94
95 enum class Feature {
96 // Handled by editor widgets (constant).
97 Close,
98 Filter,
106
107 // Handled by FSM states (dynamic).
110 Abort,
111 Cut,
112 Copy,
113 Paste,
114 Remove,
115 Move,
116 Rotate,
117 Mirror,
118 Flip,
119 MoveAlign,
122 };
123
124 // Constructors / Destructor
126 EditorWidgetBase(const EditorWidgetBase& other) = delete;
127 explicit EditorWidgetBase(const Context& context, const FilePath& fp,
128 QWidget* parent = nullptr);
129 virtual ~EditorWidgetBase() noexcept;
130
131 // Getters
132 const FilePath& getFilePath() const noexcept { return mFilePath; }
133 bool isDirty() const noexcept {
134 return mManualModificationsMade || (!mUndoStack->isClean());
135 }
136 virtual bool isBackgroundImageSet() const noexcept { return false; }
137 virtual QSet<Feature> getAvailableFeatures() const noexcept = 0;
138
139 // Setters
140 virtual void connectEditor(UndoStackActionGroup& undoStackActionGroup,
141 ExclusiveActionGroup& toolsActionGroup,
142 QToolBar& commandToolBar,
143 StatusBar& statusBar) noexcept;
144 virtual void disconnectEditor() noexcept;
145
146 // Operator Overloadings
147 EditorWidgetBase& operator=(const EditorWidgetBase& rhs) = delete;
148
149public slots:
150 virtual bool save() noexcept;
151 virtual bool selectAll() noexcept { return false; }
152 virtual bool cut() noexcept { return false; }
153 virtual bool copy() noexcept { return false; }
154 virtual bool paste() noexcept { return false; }
155 virtual bool move(Qt::ArrowType direction) noexcept {
156 Q_UNUSED(direction);
157 return false;
158 }
159 virtual bool rotate(const librepcb::Angle& rotation) noexcept {
160 Q_UNUSED(rotation);
161 return false;
162 }
163 virtual bool mirror(Qt::Orientation orientation) noexcept {
164 Q_UNUSED(orientation);
165 return false;
166 }
167 virtual bool flip(Qt::Orientation orientation) noexcept {
168 Q_UNUSED(orientation);
169 return false;
170 }
171 virtual bool moveAlign() noexcept { return false; }
172 virtual bool snapToGrid() noexcept { return false; }
173 virtual bool remove() noexcept { return false; }
174 virtual bool editProperties() noexcept { return false; }
175 virtual bool zoomIn() noexcept { return false; }
176 virtual bool zoomOut() noexcept { return false; }
177 virtual bool zoomAll() noexcept { return false; }
178 virtual bool toggle3D() noexcept { return false; }
179 virtual bool abortCommand() noexcept { return false; }
180 virtual bool processGenerateOutline() noexcept { return false; }
181 virtual bool processGenerateCourtyard() noexcept { return false; }
182 virtual bool importDxf() noexcept { return false; }
183 virtual bool exportImage() noexcept;
184 virtual bool exportPdf() noexcept;
185 virtual bool print() noexcept;
186 virtual bool editGridProperties() noexcept { return false; }
187 virtual bool increaseGridInterval() noexcept { return false; }
188 virtual bool decreaseGridInterval() noexcept { return false; }
189 virtual bool toggleBackgroundImage() noexcept { return false; }
190
191protected: // Methods
192 void setupInterfaceBrokenWarningWidget(QWidget& widget) noexcept;
193 void setupErrorNotificationWidget(QWidget& widget) noexcept;
194 virtual bool isInterfaceBroken() const noexcept = 0;
195 virtual bool toolChangeRequested(Tool newTool,
196 const QVariant& mode) noexcept {
197 Q_UNUSED(newTool);
198 Q_UNUSED(mode);
199 return false;
200 }
201 virtual bool runChecks(RuleCheckMessageList& msgs) const = 0;
203 std::shared_ptr<const RuleCheckMessage> msg,
204 bool approve) noexcept;
206 const QString& settingsKey) noexcept {
207 Q_UNUSED(output);
208 Q_UNUSED(settingsKey);
209 return false;
210 }
211 void undoStackStateModified() noexcept;
212 void setStatusBarMessage(const QString& message, int timeoutMs = -1) noexcept;
213 const QStringList& getLibLocaleOrder() const noexcept;
214 QString getWorkspaceSettingsUserName() noexcept;
215
216private slots:
217 void updateCheckMessages() noexcept;
218
219private: // Methods
230 static bool askForRestoringBackup(const FilePath& dir);
231 void toolRequested(int tool, const QVariant& mode) noexcept;
232 void undoStackCleanChanged(bool clean) noexcept;
233 void scheduleLibraryElementChecks() noexcept;
235 std::shared_ptr<const RuleCheckMessage> msg, bool applyFix) = 0;
237 std::shared_ptr<const RuleCheckMessage> msg) noexcept override;
239 std::shared_ptr<const RuleCheckMessage> msg) noexcept override;
241 std::shared_ptr<const RuleCheckMessage> msg) noexcept override;
243 std::shared_ptr<const RuleCheckMessage> msg) noexcept override;
245 std::shared_ptr<const RuleCheckMessage> msg) noexcept override;
246
247signals:
248 void dirtyChanged(bool dirty);
250 void interfaceBrokenChanged(bool broken);
251 void errorsAvailableChanged(bool hasErrors);
253 const QSet<librepcb::editor::EditorWidgetBase::Feature>& features);
254
255protected: // Data
259 QScopedPointer<UndoStack> mUndoStack;
267
268 // Memorized message approvals
271};
272
273inline std::size_t qHash(const EditorWidgetBase::Feature& feature,
274 std::size_t seed = 0) noexcept {
275 return ::qHash(static_cast<int>(feature), seed);
276}
277
278/*******************************************************************************
279 * End of File
280 ******************************************************************************/
281
282} // namespace editor
283} // namespace librepcb
284
285#endif
The Angle class is used to represent an angle (for example 12.75 degrees)
Definition angle.h:76
This class represents absolute, well-formatted paths to files or directories.
Definition filepath.h:127
The LibraryBaseElement class.
Definition librarybaseelement.h:48
The Library class represents a library directory.
Definition library.h:46
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:61
void errorsAvailableChanged(bool hasErrors)
void setStatusBarMessage(const QString &message, int timeoutMs=-1) noexcept
Definition editorwidgetbase.cpp:217
Context mContext
Definition editorwidgetbase.h:256
virtual bool remove() noexcept
Definition editorwidgetbase.h:173
virtual bool editProperties() noexcept
Definition editorwidgetbase.h:174
virtual bool move(Qt::ArrowType direction) noexcept
Definition editorwidgetbase.h:155
virtual bool save() noexcept
Definition editorwidgetbase.cpp:122
void interfaceBrokenChanged(bool broken)
virtual bool increaseGridInterval() noexcept
Definition editorwidgetbase.h:187
ExclusiveActionGroup * mToolsActionGroup
Definition editorwidgetbase.h:261
virtual bool rotate(const librepcb::Angle &rotation) noexcept
Definition editorwidgetbase.h:159
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:270
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:181
virtual bool decreaseGridInterval() noexcept
Definition editorwidgetbase.h:188
virtual void disconnectEditor() noexcept
Definition editorwidgetbase.cpp:103
virtual bool paste() noexcept
Definition editorwidgetbase.h:154
void elementEdited(const librepcb::FilePath &fp)
virtual bool abortCommand() noexcept
Definition editorwidgetbase.h:179
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:264
QSet< SExpression > mSupportedApprovals
Definition editorwidgetbase.h:269
virtual bool zoomAll() noexcept
Definition editorwidgetbase.h:177
FilePath mFilePath
Definition editorwidgetbase.h:257
void scheduleLibraryElementChecks() noexcept
Definition editorwidgetbase.cpp:277
virtual bool flip(Qt::Orientation orientation) noexcept
Definition editorwidgetbase.h:167
virtual bool exportImage() noexcept
Definition editorwidgetbase.cpp:132
virtual bool copy() noexcept
Definition editorwidgetbase.h:153
void setupErrorNotificationWidget(QWidget &widget) noexcept
Definition editorwidgetbase.cpp:170
bool isDirty() const noexcept
Definition editorwidgetbase.h:133
const FilePath & getFilePath() const noexcept
Definition editorwidgetbase.h:132
EditorWidgetBase(const EditorWidgetBase &other)=delete
QString getWorkspaceSettingsUserName() noexcept
Definition editorwidgetbase.cpp:235
virtual bool print() noexcept
Definition editorwidgetbase.cpp:140
Tool
Definition editorwidgetbase.h:75
@ MEASURE
Definition editorwidgetbase.h:91
@ ADD_HOLES
Definition editorwidgetbase.h:90
@ SELECT
Definition editorwidgetbase.h:77
@ RENUMBER_PADS
Definition editorwidgetbase.h:92
@ ADD_NAMES
Definition editorwidgetbase.h:85
@ DRAW_LINE
Definition editorwidgetbase.h:78
@ ADD_VALUES
Definition editorwidgetbase.h:86
@ DRAW_POLYGON
Definition editorwidgetbase.h:80
@ DRAW_ARC
Definition editorwidgetbase.h:82
@ DRAW_RECT
Definition editorwidgetbase.h:79
@ DRAW_TEXT
Definition editorwidgetbase.h:83
@ ADD_THT_PADS
Definition editorwidgetbase.h:88
@ NONE
Definition editorwidgetbase.h:76
@ ADD_SMT_PADS
Definition editorwidgetbase.h:89
@ DRAW_ZONE
Definition editorwidgetbase.h:84
@ DRAW_CIRCLE
Definition editorwidgetbase.h:81
@ ADD_PINS
Definition editorwidgetbase.h:87
virtual bool editGridProperties() noexcept
Definition editorwidgetbase.h:186
virtual bool toggleBackgroundImage() noexcept
Definition editorwidgetbase.h:189
Feature
Definition editorwidgetbase.h:95
virtual bool mirror(Qt::Orientation orientation) noexcept
Definition editorwidgetbase.h:163
std::shared_ptr< TransactionalFileSystem > mFileSystem
Definition editorwidgetbase.h:258
void ruleCheckDescriptionRequested(std::shared_ptr< const RuleCheckMessage > msg) noexcept override
Definition editorwidgetbase.cpp:332
UndoStackActionGroup * mUndoStackActionGroup
Definition editorwidgetbase.h:260
virtual bool isBackgroundImageSet() const noexcept
Definition editorwidgetbase.h:136
virtual bool importDxf() noexcept
Definition editorwidgetbase.h:182
virtual bool toggle3D() noexcept
Definition editorwidgetbase.h:178
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:175
void ruleCheckMessageDoubleClicked(std::shared_ptr< const RuleCheckMessage > msg) noexcept override
Definition editorwidgetbase.cpp:344
QScopedPointer< ToolBarProxy > mCommandToolBarProxy
Definition editorwidgetbase.h:263
QString mStatusBarMessage
Definition editorwidgetbase.h:266
void availableFeaturesChanged(const QSet< librepcb::editor::EditorWidgetBase::Feature > &features)
virtual bool execGraphicsExportDialog(GraphicsExportDialog::Output output, const QString &settingsKey) noexcept
Definition editorwidgetbase.h:205
virtual bool processGenerateOutline() noexcept
Definition editorwidgetbase.h:180
virtual bool snapToGrid() noexcept
Definition editorwidgetbase.h:172
virtual bool cut() noexcept
Definition editorwidgetbase.h:152
virtual bool toolChangeRequested(Tool newTool, const QVariant &mode) noexcept
Definition editorwidgetbase.h:195
QScopedPointer< UndoStack > mUndoStack
Definition editorwidgetbase.h:259
StatusBar * mStatusBar
Definition editorwidgetbase.h:262
virtual bool isInterfaceBroken() const noexcept=0
virtual bool exportPdf() noexcept
Definition editorwidgetbase.cpp:136
virtual bool zoomOut() noexcept
Definition editorwidgetbase.h:176
virtual bool selectAll() noexcept
Definition editorwidgetbase.h:151
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:265
virtual bool moveAlign() noexcept
Definition editorwidgetbase.h:171
The ExclusiveActionGroup class groups multiple QAction's together.
Definition exclusiveactiongroup.h:54
Output
Definition graphicsexportdialog.h:83
The IF_GraphicsLayerProvider class defines an interface for classes which provide layers.
Definition graphicslayer.h:111
Definition rulechecklistwidget.h:44
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
std::size_t qHash(const EditorWidgetBase::Feature &feature, std::size_t seed=0) noexcept
Definition editorwidgetbase.h:273
Definition occmodel.cpp:76
QVector< std::shared_ptr< const RuleCheckMessage > > RuleCheckMessageList
Definition rulecheckmessage.h:104
Definition uuid.h:186
Definition editorwidgetbase.h:67
bool readOnly
Definition editorwidgetbase.h:71
bool elementIsNewlyCreated
Definition editorwidgetbase.h:70
const IF_GraphicsLayerProvider & layerProvider
Definition editorwidgetbase.h:69
const Library * library
Definition editorwidgetbase.h:72
Workspace & workspace
Definition editorwidgetbase.h:68