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_LIBRARY_EDITOR_EDITORWIDGETBASE_H
21 #define LIBREPCB_LIBRARY_EDITOR_EDITORWIDGETBASE_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
26 #include "../common/libraryelementchecklistwidget.h"
27 
31 
32 #include <QtCore>
33 #include <QtWidgets>
34 
35 /*******************************************************************************
36  * Namespace / Forward Declarations
37  ******************************************************************************/
38 namespace librepcb {
39 
40 class ExclusiveActionGroup;
41 class UndoStackActionGroup;
42 class ToolBarProxy;
43 class StatusBar;
44 class IF_GraphicsLayerProvider;
45 
46 namespace workspace {
47 class Workspace;
48 }
49 
50 namespace library {
51 
52 class LibraryBaseElement;
53 
54 namespace editor {
55 
56 /*******************************************************************************
57  * Class EditorWidgetBase
58  ******************************************************************************/
59 
63 class EditorWidgetBase : public QWidget,
65  Q_OBJECT
66 
67 public:
68  // Types
69 
70  struct Context {
74  bool readOnly;
75  };
76 
77  enum Tool {
91  };
92 
93  // Constructors / Destructor
94  EditorWidgetBase() = delete;
95  EditorWidgetBase(const EditorWidgetBase& other) = delete;
96  explicit EditorWidgetBase(const Context& context, const FilePath& fp,
97  QWidget* parent = nullptr);
98  virtual ~EditorWidgetBase() noexcept;
99 
100  // Getters
101  const FilePath& getFilePath() const noexcept { return mFilePath; }
102  bool isDirty() const noexcept { return !mUndoStack->isClean(); }
103  virtual bool hasGraphicalEditor() const noexcept { return false; }
104  virtual bool supportsFlip() const noexcept { return false; }
105 
106  // Setters
107  virtual void setUndoStackActionGroup(UndoStackActionGroup* group) noexcept;
108  virtual void setToolsActionGroup(ExclusiveActionGroup* group) noexcept;
109  virtual void setCommandToolBar(QToolBar* toolbar) noexcept;
110  virtual void setStatusBar(StatusBar* statusbar) noexcept;
111 
112  // Operator Overloadings
113  EditorWidgetBase& operator=(const EditorWidgetBase& rhs) = delete;
114 
115 public slots:
116  virtual bool save() noexcept;
117  virtual bool selectAll() noexcept { return false; }
118  virtual bool cut() noexcept { return false; }
119  virtual bool copy() noexcept { return false; }
120  virtual bool paste() noexcept { return false; }
121  virtual bool rotateCw() noexcept { return false; }
122  virtual bool rotateCcw() noexcept { return false; }
123  virtual bool mirror() noexcept { return false; }
124  virtual bool flip() noexcept { return false; }
125  virtual bool remove() noexcept { return false; }
126  virtual bool zoomIn() noexcept { return false; }
127  virtual bool zoomOut() noexcept { return false; }
128  virtual bool zoomAll() noexcept { return false; }
129  virtual bool abortCommand() noexcept { return false; }
130  virtual bool editGridProperties() noexcept { return false; }
131 
132 protected: // Methods
133  void setupInterfaceBrokenWarningWidget(QWidget& widget) noexcept;
134  void setupErrorNotificationWidget(QWidget& widget) noexcept;
135  virtual bool isInterfaceBroken() const noexcept = 0;
136  virtual bool toolChangeRequested(Tool newTool) noexcept {
137  Q_UNUSED(newTool);
138  return false;
139  }
140  virtual bool runChecks(LibraryElementCheckMessageList& msgs) const = 0;
141  void undoStackStateModified() noexcept;
142  const QStringList& getLibLocaleOrder() const noexcept;
143  QString getWorkspaceSettingsUserName() noexcept;
144 
145 private slots:
146  void updateCheckMessages() noexcept;
147 
148 private: // Methods
159  static bool askForRestoringBackup(const FilePath& dir);
160  void toolActionGroupChangeTriggered(const QVariant& newTool) noexcept;
161  void undoStackCleanChanged(bool clean) noexcept;
162  void scheduleLibraryElementChecks() noexcept;
163  virtual bool processCheckMessage(
164  std::shared_ptr<const LibraryElementCheckMessage> msg, bool applyFix) = 0;
165  bool libraryElementCheckFixAvailable(
166  std::shared_ptr<const LibraryElementCheckMessage> msg) noexcept override;
167  void libraryElementCheckFixRequested(
168  std::shared_ptr<const LibraryElementCheckMessage> msg) noexcept override;
169  void libraryElementCheckDescriptionRequested(
170  std::shared_ptr<const LibraryElementCheckMessage> msg) noexcept override;
171 
172 signals:
173  void dirtyChanged(bool dirty);
174  void elementEdited(const FilePath& fp);
175  void interfaceBrokenChanged(bool broken);
176  void errorsAvailableChanged(bool hasErrors);
177  void cursorPositionChanged(const Point& pos);
178 
179 protected: // Data
182  std::shared_ptr<TransactionalFileSystem> mFileSystem;
183  QScopedPointer<UndoStack> mUndoStack;
187  QScopedPointer<ToolBarProxy> mCommandToolBarProxy;
189 };
190 
191 /*******************************************************************************
192  * End of File
193  ******************************************************************************/
194 
195 } // namespace editor
196 } // namespace library
197 } // namespace librepcb
198 
199 #endif // LIBREPCB_LIBRARY_EDITOR_EDITORWIDGETBASE_H
virtual bool zoomOut() noexcept
Definition: editorwidgetbase.h:127
virtual bool zoomIn() noexcept
Definition: editorwidgetbase.h:126
virtual bool rotateCw() noexcept
Definition: editorwidgetbase.h:121
bool elementIsNewlyCreated
Definition: editorwidgetbase.h:73
virtual bool mirror() noexcept
Definition: editorwidgetbase.h:123
bool isDirty() const noexcept
Definition: editorwidgetbase.h:102
QVector< std::shared_ptr< const LibraryElementCheckMessage > > LibraryElementCheckMessageList
Definition: libraryelementcheckmessage.h:96
virtual bool zoomAll() noexcept
Definition: editorwidgetbase.h:128
const IF_GraphicsLayerProvider & layerProvider
Definition: editorwidgetbase.h:72
The Workspace class represents a workspace with all its data (library, projects, settings, ...)
Definition: workspace.h:62
StatusBar * mStatusBar
Definition: editorwidgetbase.h:186
UndoStackActionGroup * mUndoStackActionGroup
Definition: editorwidgetbase.h:184
Definition: airwiresbuilder.cpp:32
virtual bool rotateCcw() noexcept
Definition: editorwidgetbase.h:122
QScopedPointer< ToolBarProxy > mCommandToolBarProxy
Definition: editorwidgetbase.h:187
The IF_GraphicsLayerProvider class defines an interface for classes which provide layers...
Definition: graphicslayer.h:227
The Point class is used to represent a point/coordinate/vector, for example (1.2mm; 5...
Definition: point.h:78
The ExclusiveActionGroup class groups multiple QAction&#39;s together.
Definition: exclusiveactiongroup.h:50
virtual bool cut() noexcept
Definition: editorwidgetbase.h:118
virtual bool editGridProperties() noexcept
Definition: editorwidgetbase.h:130
Definition: libraryelementchecklistwidget.h:44
Context mContext
Definition: editorwidgetbase.h:180
Tool
Definition: editorwidgetbase.h:77
Definition: editorwidgetbase.h:78
virtual bool selectAll() noexcept
Definition: editorwidgetbase.h:117
This class represents absolute, well-formatted paths to files or directories.
Definition: filepath.h:127
virtual bool copy() noexcept
Definition: editorwidgetbase.h:119
virtual bool supportsFlip() const noexcept
Definition: editorwidgetbase.h:104
The StatusBar class extends QStatusBar for some commonly used fields.
Definition: statusbar.h:44
bool readOnly
Definition: editorwidgetbase.h:74
FilePath mFilePath
Definition: editorwidgetbase.h:181
The UndoStackActionGroup class groups an undo-QAction and redo-QAction together and optionally connec...
Definition: undostackactiongroup.h:44
std::shared_ptr< TransactionalFileSystem > mFileSystem
Definition: editorwidgetbase.h:182
ExclusiveActionGroup * mToolsActionGroup
Definition: editorwidgetbase.h:185
QScopedPointer< UndoStack > mUndoStack
Definition: editorwidgetbase.h:183
virtual bool toolChangeRequested(Tool newTool) noexcept
Definition: editorwidgetbase.h:136
virtual bool hasGraphicalEditor() const noexcept
Definition: editorwidgetbase.h:103
virtual bool flip() noexcept
Definition: editorwidgetbase.h:124
bool mIsInterfaceBroken
Definition: editorwidgetbase.h:188
workspace::Workspace & workspace
Definition: editorwidgetbase.h:71
virtual bool abortCommand() noexcept
Definition: editorwidgetbase.h:129
virtual bool paste() noexcept
Definition: editorwidgetbase.h:120
The EditorWidgetBase class.
Definition: editorwidgetbase.h:63