LibrePCB Developers Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 IF_GraphicsLayerProvider;
44 
45 namespace workspace {
46 class Workspace;
47 }
48 
49 namespace library {
50 
51 class LibraryBaseElement;
52 
53 namespace editor {
54 
55 /*******************************************************************************
56  * Class EditorWidgetBase
57  ******************************************************************************/
58 
62 class EditorWidgetBase : public QWidget,
64  Q_OBJECT
65 
66 public:
67  // Types
68 
69  struct Context {
73  bool readOnly;
74  };
75 
76  enum Tool {
90  };
91 
92  // Constructors / Destructor
93  EditorWidgetBase() = delete;
94  EditorWidgetBase(const EditorWidgetBase& other) = delete;
95  explicit EditorWidgetBase(const Context& context, const FilePath& fp,
96  QWidget* parent = nullptr);
97  virtual ~EditorWidgetBase() noexcept;
98 
99  // Getters
100  const FilePath& getFilePath() const noexcept { return mFilePath; }
101  bool isDirty() const noexcept { return !mUndoStack->isClean(); }
102  virtual bool hasGraphicalEditor() const noexcept { return false; }
103  virtual bool supportsFlip() const noexcept { return false; }
104 
105  // Setters
106  virtual void setUndoStackActionGroup(UndoStackActionGroup* group) noexcept;
107  virtual void setToolsActionGroup(ExclusiveActionGroup* group) noexcept;
108  virtual void setCommandToolBar(QToolBar* toolbar) noexcept;
109 
110  // Operator Overloadings
111  EditorWidgetBase& operator=(const EditorWidgetBase& rhs) = delete;
112 
113 public slots:
114  virtual bool save() noexcept;
115  virtual bool cut() noexcept { return false; }
116  virtual bool copy() noexcept { return false; }
117  virtual bool paste() noexcept { return false; }
118  virtual bool rotateCw() noexcept { return false; }
119  virtual bool rotateCcw() noexcept { return false; }
120  virtual bool mirror() noexcept { return false; }
121  virtual bool flip() noexcept { return false; }
122  virtual bool remove() noexcept { return false; }
123  virtual bool zoomIn() noexcept { return false; }
124  virtual bool zoomOut() noexcept { return false; }
125  virtual bool zoomAll() noexcept { return false; }
126  virtual bool abortCommand() noexcept { return false; }
127  virtual bool editGridProperties() noexcept { return false; }
128 
129 protected: // Methods
130  void setupInterfaceBrokenWarningWidget(QWidget& widget) noexcept;
131  void setupErrorNotificationWidget(QWidget& widget) noexcept;
132  virtual bool isInterfaceBroken() const noexcept = 0;
133  virtual bool toolChangeRequested(Tool newTool) noexcept {
134  Q_UNUSED(newTool);
135  return false;
136  }
137  virtual bool runChecks(LibraryElementCheckMessageList& msgs) const = 0;
138  void undoStackStateModified() noexcept;
139  const QStringList& getLibLocaleOrder() const noexcept;
140  QString getWorkspaceSettingsUserName() noexcept;
141 
142 private slots:
143  void updateCheckMessages() noexcept;
144 
145 private: // Methods
146  void toolActionGroupChangeTriggered(const QVariant& newTool) noexcept;
147  void undoStackCleanChanged(bool clean) noexcept;
148  void scheduleLibraryElementChecks() noexcept;
149  virtual bool processCheckMessage(
150  std::shared_ptr<const LibraryElementCheckMessage> msg, bool applyFix) = 0;
152  std::shared_ptr<const LibraryElementCheckMessage> msg) noexcept override;
154  std::shared_ptr<const LibraryElementCheckMessage> msg) noexcept override;
156  std::shared_ptr<const LibraryElementCheckMessage> msg) noexcept override;
157 
158 signals:
159  void dirtyChanged(bool dirty);
160  void elementEdited(const FilePath& fp);
161  void interfaceBrokenChanged(bool broken);
162  void errorsAvailableChanged(bool hasErrors);
163  void cursorPositionChanged(const Point& pos);
164 
165 protected: // Data
169  QScopedPointer<UndoStack> mUndoStack;
174 };
175 
176 /*******************************************************************************
177  * End of File
178  ******************************************************************************/
179 
180 } // namespace editor
181 } // namespace library
182 } // namespace librepcb
183 
184 #endif // LIBREPCB_LIBRARY_EDITOR_EDITORWIDGETBASE_H
virtual bool zoomOut() noexcept
Definition: editorwidgetbase.h:124
virtual bool zoomIn() noexcept
Definition: editorwidgetbase.h:123
virtual bool rotateCw() noexcept
Definition: editorwidgetbase.h:118
bool elementIsNewlyCreated
Definition: editorwidgetbase.h:72
virtual bool mirror() noexcept
Definition: editorwidgetbase.h:120
bool isDirty() const noexcept
Definition: editorwidgetbase.h:101
void setupInterfaceBrokenWarningWidget(QWidget &widget) noexcept
Definition: editorwidgetbase.cpp:127
QVector< std::shared_ptr< const LibraryElementCheckMessage > > LibraryElementCheckMessageList
Definition: libraryelementcheckmessage.h:96
virtual bool zoomAll() noexcept
Definition: editorwidgetbase.h:125
The LibraryElementCheckMessage class.
Definition: libraryelementcheckmessage.h:44
const IF_GraphicsLayerProvider & layerProvider
Definition: editorwidgetbase.h:71
The Workspace class represents a workspace with all its data (library, projects, settings, ...)
Definition: workspace.h:62
virtual void setUndoStackActionGroup(UndoStackActionGroup *group) noexcept
Definition: editorwidgetbase.cpp:76
virtual bool save() noexcept
Definition: editorwidgetbase.cpp:114
void undoStackStateModified() noexcept
Definition: editorwidgetbase.cpp:169
Special FileSystem implementation for libraries and projects.
Definition: transactionalfilesystem.h:63
UndoStackActionGroup * mUndoStackActionGroup
Definition: editorwidgetbase.h:170
virtual bool processCheckMessage(std::shared_ptr< const LibraryElementCheckMessage > msg, bool applyFix)=0
virtual bool rotateCcw() noexcept
Definition: editorwidgetbase.h:119
const FilePath & getFilePath() const noexcept
Definition: editorwidgetbase.h:100
QScopedPointer< ToolBarProxy > mCommandToolBarProxy
Definition: editorwidgetbase.h:172
void libraryElementCheckDescriptionRequested(std::shared_ptr< const LibraryElementCheckMessage > msg) noexceptoverride
Definition: editorwidgetbase.cpp:262
void toolActionGroupChangeTriggered(const QVariant &newTool) noexcept
Definition: editorwidgetbase.cpp:199
The IF_GraphicsLayerProvider class defines an interface for classes which provide layers...
Definition: graphicslayer.h:227
The UndoStack class holds UndoCommand objects and provides undo/redo commands.
Definition: undostack.h:107
virtual ~EditorWidgetBase() noexcept
Definition: editorwidgetbase.cpp:69
virtual bool isInterfaceBroken() const noexcept=0
void libraryElementCheckFixRequested(std::shared_ptr< const LibraryElementCheckMessage > msg) noexceptoverride
Definition: editorwidgetbase.cpp:253
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's together.
Definition: exclusiveactiongroup.h:50
virtual bool cut() noexcept
Definition: editorwidgetbase.h:115
virtual bool editGridProperties() noexcept
Definition: editorwidgetbase.h:127
EditorWidgetBase & operator=(const EditorWidgetBase &rhs)=delete
Definition: libraryelementchecklistwidget.h:44
Context mContext
Definition: editorwidgetbase.h:166
virtual bool runChecks(LibraryElementCheckMessageList &msgs) const =0
Tool
Definition: editorwidgetbase.h:76
const QStringList & getLibLocaleOrder() const noexcept
Definition: editorwidgetbase.cpp:180
Definition: editorwidgetbase.h:77
void setupErrorNotificationWidget(QWidget &widget) noexcept
Definition: editorwidgetbase.cpp:149
This class represents absolute, well-formatted paths to files or directories.
Definition: filepath.h:127
QString getWorkspaceSettingsUserName() noexcept
Definition: editorwidgetbase.cpp:184
void scheduleLibraryElementChecks() noexcept
Definition: editorwidgetbase.cpp:209
virtual bool copy() noexcept
Definition: editorwidgetbase.h:116
virtual bool supportsFlip() const noexcept
Definition: editorwidgetbase.h:103
virtual void setToolsActionGroup(ExclusiveActionGroup *group) noexcept
Definition: editorwidgetbase.cpp:85
bool readOnly
Definition: editorwidgetbase.h:73
FilePath mFilePath
Definition: editorwidgetbase.h:167
void undoStackCleanChanged(bool clean) noexcept
Definition: editorwidgetbase.cpp:204
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:168
ExclusiveActionGroup * mToolsActionGroup
Definition: editorwidgetbase.h:171
QScopedPointer< UndoStack > mUndoStack
Definition: editorwidgetbase.h:169
void cursorPositionChanged(const Point &pos)
virtual bool toolChangeRequested(Tool newTool) noexcept
Definition: editorwidgetbase.h:133
virtual bool hasGraphicalEditor() const noexcept
Definition: editorwidgetbase.h:102
virtual bool flip() noexcept
Definition: editorwidgetbase.h:121
bool libraryElementCheckFixAvailable(std::shared_ptr< const LibraryElementCheckMessage > msg) noexceptoverride
Definition: editorwidgetbase.cpp:244
bool mIsInterfaceBroken
Definition: editorwidgetbase.h:173
workspace::Workspace & workspace
Definition: editorwidgetbase.h:70
void updateCheckMessages() noexcept
Definition: editorwidgetbase.cpp:223
virtual void setCommandToolBar(QToolBar *toolbar) noexcept
Definition: editorwidgetbase.cpp:106
virtual bool abortCommand() noexcept
Definition: editorwidgetbase.h:126
The ToolBarProxy class allows to map a list of QAction's to one QToolBar.
Definition: toolbarproxy.h:44
virtual bool paste() noexcept
Definition: editorwidgetbase.h:117
The EditorWidgetBase class.
Definition: editorwidgetbase.h:62