QElectroTech  0.70
elementscene.h
Go to the documentation of this file.
1 /*
2  Copyright 2006-2019 The QElectroTech Team
3  This file is part of QElectroTech.
4 
5  QElectroTech is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 2 of the License, or
8  (at your option) any later version.
9 
10  QElectroTech is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
17 */
18 #ifndef ELEMENT_SCENE_H
19 #define ELEMENT_SCENE_H
20 #include <QtWidgets>
21 #include <QtXml>
22 #include "qgimanager.h"
23 #include "elementcontent.h"
24 #include "diagramcontext.h"
25 #include "nameslist.h"
26 
27 class CustomElementPart;
30 class QETElementEditor;
31 class ESEventInterface;
32 class QKeyEvent;
38 class ElementScene : public QGraphicsScene
39 {
41  Q_OBJECT
42 
43  // enum
44  public:
46  enum ItemOption {
50  Selected = 8,
53  };
54  Q_DECLARE_FLAGS(ItemOptions, ItemOption)
55 
56  // constructors, destructor
57  public:
58  ElementScene(QETElementEditor *, QObject * = nullptr);
59  ~ElementScene() override;
60 
61  private:
62  ElementScene(const ElementScene &);
63 
64  // attributes
65  private:
67  QString m_informations;
68  QString m_elmt_type;
72  QUndoStack m_undo_stack;
73 
77 
78  QGraphicsRectItem *m_paste_area;
80 
81  QString m_last_copied;
82 
85 
86  int m_x_grid,
87  m_y_grid;
88 
89  // methods
90  public:
91  void setEventInterface (ESEventInterface *event_interface);
92  void clearEventInterface();
95  QPointF snapToGrid(QPointF point);
96  void setNames(const NamesList &);
97  NamesList names() const;
98  QString informations() const;
99  void setInformations(const QString &);
100  QString elementType () const {return m_elmt_type;}
103  virtual int xGrid() const;
104  virtual int yGrid() const;
105  virtual void setGrid(int, int);
106  virtual const QDomDocument toXml(bool = true);
107  virtual QRectF boundingRectFromXml(const QDomDocument &);
108  virtual void fromXml(const QDomDocument &, const QPointF & = QPointF(), bool = true, ElementContent * = nullptr);
109  virtual void reset();
110  virtual QList<CustomElementPart *> primitives() const;
111  virtual QList<QGraphicsItem *> zItems(ItemOptions options = ItemOptions(SortByZValue | IncludeTerminals | SelectedOrNot)) const;
112  virtual ElementContent selectedContent() const;
113  virtual void getPasteArea(const QRectF &);
114  QRectF elementSceneGeometricRect () const;
115  bool containsTerminals() const;
116  QUndoStack &undoStack();
118  static bool clipboardMayContainElement();
119  bool wasCopiedFromThisElement(const QString &);
120  void cut();
121  void copy();
122  QETElementEditor* editor() const;
123  void setElementInfo(const DiagramContext& dc);
124 
125  protected:
126  void mouseMoveEvent (QGraphicsSceneMouseEvent *) override;
127  void mousePressEvent (QGraphicsSceneMouseEvent *) override;
128  void mouseReleaseEvent (QGraphicsSceneMouseEvent *) override;
129  void mouseDoubleClickEvent (QGraphicsSceneMouseEvent *event) override;
130  void keyPressEvent (QKeyEvent *event) override;
131  void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override;
132 
133  void drawForeground(QPainter *, const QRectF &) override;
134 
135  private:
136  QRectF elementContentBoundingRect(const ElementContent &) const;
137  bool applyInformations(const QDomDocument &);
138  ElementContent loadContent(const QDomDocument &);
140  ElementContent addContentAtPos(const ElementContent &, const QPointF &);
141  void addPrimitive(QGraphicsItem *);
142  void initPasteArea();
143  static bool zValueLessThan(QGraphicsItem *, QGraphicsItem *);
145  void centerElementToOrigine();
146 
147  public slots:
148  void slot_select(const ElementContent &);
149  void slot_selectAll();
150  void slot_deselectAll();
151  void slot_invertSelection();
152  void slot_delete();
153  void slot_editNames();
155  void slot_editProperties();
156  void managePrimitivesGroups();
158 
159  signals:
161  void partsAdded();
163  void partsRemoved();
165  void partsZValueChanged();
167  void pasteAreaDefined(const QRectF &);
169  void needZoomFit();
170  void elementInfoChanged();
171 };
172 
173 Q_DECLARE_OPERATORS_FOR_FLAGS(ElementScene::ItemOptions)
174 
175 
176 
179 inline void ElementScene::setNames(const NamesList &nameslist) {
180  m_names_list = nameslist;
181 }
182 
187  return(m_names_list);
188 }
189 
193 inline QString ElementScene::informations() const {
194  return(m_informations);
195 }
196 
200 inline void ElementScene::setInformations(const QString &infos) {
201  m_informations = infos;
202 }
203 
204 #endif
void setEventInterface(ESEventInterface *event_interface)
ElementScene::setEventInterface Set a new event interface.
virtual void fromXml(const QDomDocument &, const QPointF &=QPointF(), bool=true, ElementContent *=nullptr)
void mousePressEvent(QGraphicsSceneMouseEvent *) override
ElementScene::mousePressEvent.
void drawForeground(QPainter *, const QRectF &) override
DiagramContext m_elmt_kindInfo
element type
Definition: elementscene.h:69
void slot_deselectAll()
ElementScene::slot_deselectAll deselect all item.
void elementInfoChanged()
NamesList m_names_list
Definition: elementscene.h:66
void setBehavior(ElementScene::Behavior)
ElementScene::setBehavior Modifie the current behavior of this scene.
void slot_editAuthorInformations()
QMutex * m_decorator_lock
Definition: elementscene.h:144
void partsRemoved()
Signal emitted after one or several parts were removed.
virtual QRectF boundingRectFromXml(const QDomDocument &)
void slot_selectAll()
ElementScene::slot_selectAll Select all items.
QGIManager m_qgi_manager
element kind info
Definition: elementscene.h:71
void slot_editProperties()
ElementScene::slot_editProperties Open dialog to edit the element properties.
QString informations() const
Definition: elementscene.h:193
bool wasCopiedFromThisElement(const QString &)
Behavior m_behavior
Definition: elementscene.h:75
void stackAction(ElementEditionCommand *)
void mouseReleaseEvent(QGraphicsSceneMouseEvent *) override
ElementScene::mouseReleaseEvent.
static bool zValueLessThan(QGraphicsItem *, QGraphicsItem *)
ElementContent loadContent(const QDomDocument &)
ElementScene::loadContent.
QString m_informations
List of localized names.
Definition: elementscene.h:67
virtual const QDomDocument toXml(bool=true)
ElementScene::toXml Export this element as a xml file.
virtual void setGrid(int, int)
void addPrimitive(QGraphicsItem *)
void partsZValueChanged()
Signal emitted when the zValue of one or several parts change.
void slot_select(const ElementContent &)
ElementScene::slot_select Select the item in content, every others items in the scene are deselected...
QGIManager & qgiManager()
QRectF elementContentBoundingRect(const ElementContent &) const
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override
ElementScene::mouseDoubleClickEvent.
~ElementScene() override
ElementScene::~ElementScene.
ESEventInterface * m_event_interface
Definition: elementscene.h:74
void pasteAreaDefined(const QRectF &)
Signal emitted when users have defined the copy/paste area.
QETElementEditor * editor() const
void managePrimitivesGroups()
ElementScene::managePrimitivesGroups Ensure the decorator is adequately shown, hidden or updated so i...
QUndoStack & undoStack()
void needZoomFit()
Signal emitted when need zoomFit.
The ElementEditionCommand class ElementEditionCommand is the base class for all commands classes invo...
QString m_last_copied
Definition: elementscene.h:81
DiagramContext elementKindInfo() const
Definition: elementscene.h:101
void partsAdded()
Signal emitted after one or several parts were added.
ElementScene(QETElementEditor *, QObject *=nullptr)
void setNames(const NamesList &)
Definition: elementscene.h:179
virtual void reset()
ElementScene::reset Remove all QGraphicsItems in the scene and clear the undo stack.
static bool clipboardMayContainElement()
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override
ElementScene::contextMenuEvent Display the context menu event, only if behavior are Normal...
void keyPressEvent(QKeyEvent *event) override
ElementScene::keyPressEvent manage key press event.
virtual int yGrid() const
bool containsTerminals() const
void clearEventInterface()
ElementScene::clearEventInterface Clear the current event interface.
bool applyInformations(const QDomDocument &)
virtual ElementContent selectedContent() const
virtual QList< CustomElementPart * > primitives() const
QString m_elmt_type
Extra informations.
Definition: elementscene.h:68
NamesList names() const
Definition: elementscene.h:186
void mouseMoveEvent(QGraphicsSceneMouseEvent *) override
ElementScene::mouseMoveEvent.
void slot_delete()
DiagramContext m_elmt_information
Definition: elementscene.h:69
DiagramContext elementInformation() const
Definition: elementscene.h:102
virtual QList< QGraphicsItem * > zItems(ItemOptions options=ItemOptions(SortByZValue|IncludeTerminals|SelectedOrNot)) const
QRectF m_defined_paste_area
Definition: elementscene.h:79
void centerElementToOrigine()
ElementScene::centerElementToOrigine try to center better is possible the element to the scene (the c...
virtual void getPasteArea(const QRectF &)
QString elementType() const
Definition: elementscene.h:100
QETElementEditor * m_element_editor
Definition: elementscene.h:76
ElementContent addContentAtPos(const ElementContent &, const QPointF &)
virtual int xGrid() const
QList< QGraphicsItem * > ElementContent
void initPasteArea()
void setInformations(const QString &)
Definition: elementscene.h:200
QPointF snapToGrid(QPointF point)
ElementPrimitiveDecorator * m_decorator
Decorator item displayed when at least one item is selected.
Definition: elementscene.h:84
QRectF elementSceneGeometricRect() const
void slot_editNames()
ElementScene::slot_editNames Launch a dialog for edit the names of the edited element.
ElementScene::Behavior behavior() const
void setElementInfo(const DiagramContext &dc)
QGraphicsRectItem * m_paste_area
Definition: elementscene.h:78
ElementContent addContent(const ElementContent &)
QUndoStack m_undo_stack
Definition: elementscene.h:72
void slot_invertSelection()