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 
65 class EditorWidgetBase : public QWidget,
67  Q_OBJECT
68 
69 public:
70  // Types
71 
72  struct Context {
76  bool readOnly;
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
166  QScopedPointer<UndoStack> mUndoStack;
171 };
172 
173 /*******************************************************************************
174  * End of File
175  ******************************************************************************/
176 
177 } // namespace editor
178 } // namespace library
179 } // namespace librepcb
180 
181 #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:75
bool isDirty() const noexcept
Definition: editorwidgetbase.h:104
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:122
The LibraryElementCheckMessage class.
Definition: libraryelementcheckmessage.h:44
const IF_GraphicsLayerProvider & layerProvider
Definition: editorwidgetbase.h:74
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: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:167
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:169
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:250
The UndoStack class holds UndoCommand objects and provides undo/redo commands.
Definition: undostack.h:120
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: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:180
Definition: editorwidgetbase.h:80
void setupErrorNotificationWidget(QWidget &widget) noexcept
Definition: editorwidgetbase.cpp:149
This class represents absolute, well-formatted paths to files or directories.
Definition: filepath.h:130
QString getWorkspaceSettingsUserName() noexcept
Definition: editorwidgetbase.cpp:184
void scheduleLibraryElementChecks() noexcept
Definition: editorwidgetbase.cpp:209
virtual void setToolsActionGroup(ExclusiveActionGroup *group) noexcept
Definition: editorwidgetbase.cpp:85
bool readOnly
Definition: editorwidgetbase.h:76
FilePath mFilePath
Definition: editorwidgetbase.h:164
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:47
std::shared_ptr< TransactionalFileSystem > mFileSystem
Definition: editorwidgetbase.h:165
ExclusiveActionGroup * mToolsActionGroup
Definition: editorwidgetbase.h:168
QScopedPointer< UndoStack > mUndoStack
Definition: editorwidgetbase.h:166
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:244
bool mIsInterfaceBroken
Definition: editorwidgetbase.h:170
workspace::Workspace & workspace
Definition: editorwidgetbase.h:73
void updateCheckMessages() noexcept
Definition: editorwidgetbase.cpp:223
virtual void setCommandToolBar(QToolBar *toolbar) noexcept
Definition: editorwidgetbase.cpp:106
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:65