LibrePCB Developers Documentation
schematiceditorevent.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_PROJECT_SCHEMATICEDITOREVENT_H
21 #define LIBREPCB_PROJECT_SCHEMATICEDITOREVENT_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
26 #include <librepcb/common/uuid.h>
27 
28 #include <QtCore>
29 
30 /*******************************************************************************
31  * Namespace / Forward Declarations
32  ******************************************************************************/
33 namespace librepcb {
34 namespace project {
35 
36 class Project;
37 class Schematic;
38 
39 namespace editor {
40 
41 class SchematicEditor;
42 
43 namespace Ui {
44 class SchematicEditor;
45 }
46 
47 /*******************************************************************************
48  * Class SEE_Base
49  ******************************************************************************/
50 
54 class SEE_Base {
55 public:
57  enum EventType_t {
58  // Triggered Actions (SEE_Base objects, no additional parameters)
70  // Redirected QEvent's (SEE_RedirectedQEvent objects, with pointer to a
71  // QEvent)
72  GraphicsViewEvent,
73  // Special Events (with some additional parameters)
75  StartAddComponent,
76  SwitchToSchematicPage,
78  };
80 
81  // Constructors / Destructor
82  SEE_Base(EventType_t type);
83  virtual ~SEE_Base();
84 
85  // Getters
86  EventType_t getType() const noexcept { return mType; }
87  bool isAccepted() const noexcept { return mAccepted; }
88 
89  // Setters
90  virtual void setAccepted(bool accepted) noexcept { mAccepted = accepted; }
91 
92 protected:
94  bool mAccepted;
95 };
96 
97 /*******************************************************************************
98  * Class SEE_RedirectedQEvent
99  ******************************************************************************/
100 
104 class SEE_RedirectedQEvent final : public SEE_Base {
105 public:
106  // Constructors / Destructor
107  SEE_RedirectedQEvent(EventType_t type, QEvent* event)
108  : SEE_Base(type), mQEvent(event) {}
110 
111  // Getters
112  QEvent* getQEvent() const noexcept { return mQEvent; }
113 
114  // Setters
115  void setAccepted(bool accepted) noexcept {
116  mQEvent->setAccepted(accepted);
117  SEE_Base::setAccepted(accepted);
118  }
119 
120  // Static Methods
121 
129  static QEvent* getQEventFromSEE(const SEE_Base* see) noexcept {
130  const SEE_RedirectedQEvent* r =
131  dynamic_cast<const SEE_RedirectedQEvent*>(see);
132  return (r ? r->getQEvent() : nullptr);
133  }
134 
135 private:
136  QEvent* mQEvent;
137 };
138 
139 /*******************************************************************************
140  * Class SEE_StartAddComponent
141  ******************************************************************************/
142 
148 class SEE_StartAddComponent final : public SEE_Base {
149 public:
150  // Constructors / Destructor
152  SEE_StartAddComponent(const Uuid& cmp, const Uuid& symbVar);
154 
155  // Getters
156  const tl::optional<Uuid>& getComponentUuid() const noexcept {
157  return mComponentUuid;
158  }
159  const tl::optional<Uuid>& getSymbVarUuid() const noexcept {
160  return mSymbVarUuid;
161  }
162 
163 private:
164  tl::optional<Uuid> mComponentUuid;
165  tl::optional<Uuid> mSymbVarUuid;
166 };
167 
168 /*******************************************************************************
169  * Class SEE_SwitchToSchematicPage
170  ******************************************************************************/
171 
185 class SEE_SwitchToSchematicPage final : public SEE_Base {
186 public:
187  // Constructors / Destructor
188  SEE_SwitchToSchematicPage(unsigned int schematicIndex)
189  : SEE_Base(EventType_t::SwitchToSchematicPage),
190  mSchematicIndex(schematicIndex) {}
192 
193  // Getters
194  unsigned int getSchematicIndex() const noexcept { return mSchematicIndex; }
195 
196 private:
197  unsigned int mSchematicIndex;
198 };
199 
200 /*******************************************************************************
201  * End of File
202  ******************************************************************************/
203 
204 } // namespace editor
205 } // namespace project
206 } // namespace librepcb
207 
208 #endif // LIBREPCB_PROJECT_SCHEMATICEDITOREVENT_H
virtual void setAccepted(bool accepted) noexcept
Definition: schematiceditorevent.h:90
start command: draw wire
Definition: schematiceditorevent.h:61
The SEE_SwitchToSchematicPage class.
Definition: schematiceditorevent.h:185
EventType_t getType() const noexcept
Definition: schematiceditorevent.h:86
tl::optional< Uuid > mComponentUuid
Definition: schematiceditorevent.h:164
Definition: mainwindow.h:10
rotate the selected elements 90° CCW (r)
Definition: schematiceditorevent.h:66
Definition: alignment.cpp:30
copy the selected elements to clipboard (ctrl+c)
Definition: schematiceditorevent.h:63
abort the currently active command (esc)
Definition: schematiceditorevent.h:59
void setAccepted(bool accepted) noexcept
Definition: schematiceditorevent.h:115
The SEE_RedirectedQEvent class.
Definition: schematiceditorevent.h:104
QEvent * getQEvent() const noexcept
Definition: schematiceditorevent.h:112
paste the elements from the clipboard (ctrl+v)
Definition: schematiceditorevent.h:65
The SEE_Base (Schematic Editor Event Base) class.
Definition: schematiceditorevent.h:54
EventType_t mType
Definition: schematiceditorevent.h:93
unsigned int getSchematicIndex() const noexcept
Definition: schematiceditorevent.h:194
cut the selected elements (ctrl+x)
Definition: schematiceditorevent.h:64
bool isAccepted() const noexcept
Definition: schematiceditorevent.h:87
The SEE_StartAddComponent class.
Definition: schematiceditorevent.h:148
const tl::optional< Uuid > & getSymbVarUuid() const noexcept
Definition: schematiceditorevent.h:159
unsigned int mSchematicIndex
the requested schematic page index
Definition: schematiceditorevent.h:197
start command: select elements
Definition: schematiceditorevent.h:60
rotate the selected elements 90° CW (Shift+r)
Definition: schematiceditorevent.h:67
tl::optional< Uuid > mSymbVarUuid
Definition: schematiceditorevent.h:165
SEE_SwitchToSchematicPage(unsigned int schematicIndex)
Definition: schematiceditorevent.h:188
start command: add netlabel
Definition: schematiceditorevent.h:62
virtual ~SEE_SwitchToSchematicPage()
Definition: schematiceditorevent.h:191
const tl::optional< Uuid > & getComponentUuid() const noexcept
Definition: schematiceditorevent.h:156
remove the selected elements
Definition: schematiceditorevent.h:69
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:58
virtual ~SEE_RedirectedQEvent()
Definition: schematiceditorevent.h:109
mirror selected items (horizontally)
Definition: schematiceditorevent.h:68
SEE_RedirectedQEvent(EventType_t type, QEvent *event)
Definition: schematiceditorevent.h:107
EventType_t
FSM event types.
Definition: schematiceditorevent.h:57
QEvent * mQEvent
Definition: schematiceditorevent.h:136
bool mAccepted
Definition: schematiceditorevent.h:94
static QEvent * getQEventFromSEE(const SEE_Base *see) noexcept
Helper method to get the QEvent from a pointer to SEE_Base.
Definition: schematiceditorevent.h:129