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 
32 
33 #include <QtCore>
34 #include <QtWidgets>
35 
36 /*******************************************************************************
37  * Namespace / Forward Declarations
38  ******************************************************************************/
39 namespace librepcb {
40 
41 class ExclusiveActionGroup;
42 class UndoStackActionGroup;
43 class ToolBarProxy;
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 
66 class EditorWidgetBase : public QWidget,
68  Q_OBJECT
69 
70 public:
71  // Types
72 
73  struct Context {
77  };
78 
79  enum Tool {
93  };
94 
95  // Constructors / Destructor
96  EditorWidgetBase() = delete;
97  EditorWidgetBase(const EditorWidgetBase& other) = delete;
98  explicit EditorWidgetBase(const Context& context, const FilePath& fp,
99  QWidget* parent = nullptr);
100  virtual ~EditorWidgetBase() noexcept;
101 
102  // Getters
103  const FilePath& getFilePath() const noexcept { return mFilePath; }
104  bool isDirty() const noexcept { return !mUndoStack->isClean(); }
105  virtual bool hasGraphicalEditor() const noexcept { return false; }
106 
107  // Setters
108  virtual void setUndoStackActionGroup(UndoStackActionGroup* group) noexcept;
109  virtual void setToolsActionGroup(ExclusiveActionGroup* group) noexcept;
110  virtual void setCommandToolBar(QToolBar* toolbar) noexcept;
111 
112  // Operator Overloadings
113  EditorWidgetBase& operator=(const EditorWidgetBase& rhs) = delete;
114 
115 public slots:
116  virtual bool save() noexcept;
117  virtual bool rotateCw() noexcept { return false; }
118  virtual bool rotateCcw() noexcept { return false; }
119  virtual bool remove() noexcept { return false; }
120  virtual bool zoomIn() noexcept { return false; }
121  virtual bool zoomOut() noexcept { return false; }
122  virtual bool zoomAll() noexcept { return false; }
123  virtual bool abortCommand() noexcept { return false; }
124  virtual bool editGridProperties() noexcept { return false; }
125 
126 protected: // Methods
127  void setupInterfaceBrokenWarningWidget(QWidget& widget) noexcept;
128  void setupErrorNotificationWidget(QWidget& widget) noexcept;
129  virtual bool isInterfaceBroken() const noexcept = 0;
130  virtual bool toolChangeRequested(Tool newTool) noexcept {
131  Q_UNUSED(newTool);
132  return false;
133  }
134  virtual bool runChecks(LibraryElementCheckMessageList& msgs) const = 0;
135  void undoStackStateModified() noexcept;
136  const QStringList& getLibLocaleOrder() const noexcept;
137  QString getWorkspaceSettingsUserName() noexcept;
138 
139 private slots:
140  void updateCheckMessages() noexcept;
141 
142 private: // Methods
143  void toolActionGroupChangeTriggered(const QVariant& newTool) noexcept;
144  void undoStackCleanChanged(bool clean) noexcept;
145  void scheduleLibraryElementChecks() noexcept;
146  virtual bool processCheckMessage(
147  std::shared_ptr<const LibraryElementCheckMessage> msg, bool applyFix) = 0;
149  std::shared_ptr<const LibraryElementCheckMessage> msg) noexcept override;
151  std::shared_ptr<const LibraryElementCheckMessage> msg) noexcept override;
153  std::shared_ptr<const LibraryElementCheckMessage> msg) noexcept override;
154 
155 signals:
156  void dirtyChanged(bool dirty);
157  void elementEdited(const FilePath& fp);
158  void interfaceBrokenChanged(bool broken);
159  void errorsAvailableChanged(bool hasErrors);
160  void cursorPositionChanged(const Point& pos);
161 
162 protected: // Data
165  QScopedPointer<UndoStack> mUndoStack;
170 };
171 
172 /*******************************************************************************
173  * End of File
174  ******************************************************************************/
175 
176 } // namespace editor
177 } // namespace library
178 } // namespace librepcb
179 
180 #endif // LIBREPCB_LIBRARY_EDITOR_EDITORWIDGETBASE_H
virtual bool zoomOut() noexcept
Definition: editorwidgetbase.h:121
virtual bool zoomIn() noexcept
Definition: editorwidgetbase.h:120
virtual bool rotateCw() noexcept
Definition: editorwidgetbase.h:117
bool elementIsNewlyCreated
Definition: editorwidgetbase.h:76
bool isDirty() const noexcept
Definition: editorwidgetbase.h:104
void setupInterfaceBrokenWarningWidget(QWidget &widget) noexcept
Definition: editorwidgetbase.cpp:124
QVector< std::shared_ptr< const LibraryElementCheckMessage > > LibraryElementCheckMessageList
Definition: libraryelementcheckmessage.h:96
virtual bool zoomAll() noexcept
Definition: editorwidgetbase.h:122
The LibraryElementCheckMessage class.
Definition: libraryelementcheckmessage.h:44
const IF_GraphicsLayerProvider & layerProvider
Definition: editorwidgetbase.h:75
The Workspace class represents a workspace with all its data (library, projects, settings, ...)
Definition: workspace.h:65
virtual void setUndoStackActionGroup(UndoStackActionGroup *group) noexcept
Definition: editorwidgetbase.cpp:73
virtual bool save() noexcept
Definition: editorwidgetbase.cpp:111
void undoStackStateModified() noexcept
Definition: editorwidgetbase.cpp:166
UndoStackActionGroup * mUndoStackActionGroup
Definition: editorwidgetbase.h:166
virtual bool processCheckMessage(std::shared_ptr< const LibraryElementCheckMessage > msg, bool applyFix)=0
virtual bool rotateCcw() noexcept
Definition: editorwidgetbase.h:118
const FilePath & getFilePath() const noexcept
Definition: editorwidgetbase.h:103
QScopedPointer< ToolBarProxy > mCommandToolBarProxy
Definition: editorwidgetbase.h:168
void libraryElementCheckDescriptionRequested(std::shared_ptr< const LibraryElementCheckMessage > msg) noexceptoverride
Definition: editorwidgetbase.cpp:259
void toolActionGroupChangeTriggered(const QVariant &newTool) noexcept
Definition: editorwidgetbase.cpp:196
The IF_GraphicsLayerProvider class defines an interface for classes which provide layers...
Definition: graphicslayer.h:250
The UndoStack class holds UndoCommand objects and provides undo/redo commands.
Definition: undostack.h:120
virtual ~EditorWidgetBase() noexcept
Definition: editorwidgetbase.cpp:66
virtual bool isInterfaceBroken() const noexcept=0
void libraryElementCheckFixRequested(std::shared_ptr< const LibraryElementCheckMessage > msg) noexceptoverride
Definition: editorwidgetbase.cpp:250
The Point class is used to represent a point/coordinate/vector, for example (1.2mm; 5...
Definition: point.h:81
The ExclusiveActionGroup class groups multiple QAction's together.
Definition: exclusiveactiongroup.h:53
virtual bool editGridProperties() noexcept
Definition: editorwidgetbase.h:124
EditorWidgetBase & operator=(const EditorWidgetBase &rhs)=delete
Definition: libraryelementchecklistwidget.h:44
Context mContext
Definition: editorwidgetbase.h:163
virtual bool runChecks(LibraryElementCheckMessageList &msgs) const =0
Tool
Definition: editorwidgetbase.h:79
const QStringList & getLibLocaleOrder() const noexcept
Definition: editorwidgetbase.cpp:177
Definition: editorwidgetbase.h:80
void setupErrorNotificationWidget(QWidget &widget) noexcept
Definition: editorwidgetbase.cpp:146
This class represents absolute, well-formatted paths to files or directories.
Definition: filepath.h:130
QString getWorkspaceSettingsUserName() noexcept
Definition: editorwidgetbase.cpp:181
void scheduleLibraryElementChecks() noexcept
Definition: editorwidgetbase.cpp:206
virtual void setToolsActionGroup(ExclusiveActionGroup *group) noexcept
Definition: editorwidgetbase.cpp:82
FilePath mFilePath
Definition: editorwidgetbase.h:164
void undoStackCleanChanged(bool clean) noexcept
Definition: editorwidgetbase.cpp:201
The UndoStackActionGroup class groups an undo-QAction and redo-QAction together and optionally connec...
Definition: undostackactiongroup.h:47
ExclusiveActionGroup * mToolsActionGroup
Definition: editorwidgetbase.h:167
QScopedPointer< UndoStack > mUndoStack
Definition: editorwidgetbase.h:165
void cursorPositionChanged(const Point &pos)
virtual bool toolChangeRequested(Tool newTool) noexcept
Definition: editorwidgetbase.h:130
virtual bool hasGraphicalEditor() const noexcept
Definition: editorwidgetbase.h:105
bool libraryElementCheckFixAvailable(std::shared_ptr< const LibraryElementCheckMessage > msg) noexceptoverride
Definition: editorwidgetbase.cpp:241
bool mIsInterfaceBroken
Definition: editorwidgetbase.h:169
workspace::Workspace & workspace
Definition: editorwidgetbase.h:74
void updateCheckMessages() noexcept
Definition: editorwidgetbase.cpp:220
virtual void setCommandToolBar(QToolBar *toolbar) noexcept
Definition: editorwidgetbase.cpp:103
virtual bool abortCommand() noexcept
Definition: editorwidgetbase.h:123
The ToolBarProxy class allows to map a list of QAction's to one QToolBar.
Definition: toolbarproxy.h:47
The EditorWidgetBase class.
Definition: editorwidgetbase.h:66