QElectroTech 0.100.0-dev
Loading...
Searching...
No Matches
elementscene.h
Go to the documentation of this file.
1/*
2 Copyright 2006-2024 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 "../NameList/nameslist.h"
21#include "../diagramcontext.h"
22#include "../qgimanager.h"
23#include "elementcontent.h"
24#include "../properties/elementdata.h"
25
26#include <QtWidgets>
27#include <QtXml>
28
34class QKeyEvent;
45class ElementScene : public QGraphicsScene
46{
48 Q_OBJECT
49
50 // enum
51 public:
61 Q_DECLARE_FLAGS(ItemOptions, ItemOption)
62
63 // constructors, destructor
64 public:
65 ElementScene(QETElementEditor *, QObject * = nullptr);
66 ~ElementScene() override;
67
68 private:
70
71 // attributes
72 private:
75 QUndoStack m_undo_stack;
76
80
81 QGraphicsRectItem *m_paste_area;
83
85
88
91
92 QPointer<CustomElementGraphicPart> m_single_selected_item;
93
94 // methods
95 public:
97 void setElementData(ElementData data);
98
99 void setEventInterface (ESEventInterface *event_interface);
100 void clearEventInterface();
101
104
105 QPointF snapToGrid(QPointF point);
106 virtual int xGrid() const;
107 virtual int yGrid() const;
108 virtual void setGrid(int, int);
109
110 virtual const QDomDocument toXml(bool = true);
111 virtual QRectF boundingRectFromXml(const QDomDocument &);
112 virtual void fromXml(const QDomDocument &,
113 const QPointF & = QPointF(),
114 bool = true,
115 ElementContent * = nullptr);
116 virtual void reset();
117 virtual QList<CustomElementPart *> primitives() const;
118 virtual QList<QGraphicsItem *>
119 zItems(ItemOptions options = ItemOptions(SortByZValue
121 | SelectedOrNot)) const;
122 virtual ElementContent selectedContent() const;
123 virtual void getPasteArea(const QRectF &);
124 QRectF elementSceneGeometricRect () const;
125 bool containsTerminals() const;
126 QUndoStack &undoStack();
128 static bool clipboardMayContainElement();
129 bool wasCopiedFromThisElement(const QString &);
130 void cut();
131 void copy();
132 QETElementEditor* editor() const;
133 void addItems(QVector<QGraphicsItem *> items);
134 void removeItems(QVector<QGraphicsItem *> items);
135
136 protected:
137 void mouseMoveEvent (QGraphicsSceneMouseEvent *) override;
138 void mousePressEvent (QGraphicsSceneMouseEvent *) override;
139 void mouseReleaseEvent (QGraphicsSceneMouseEvent *) override;
140 void mouseDoubleClickEvent (QGraphicsSceneMouseEvent *event) override;
141 void keyPressEvent (QKeyEvent *event) override;
142 void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override;
143 void drawForeground(QPainter *, const QRectF &) override;
144
145 private:
146 QRectF elementContentBoundingRect(const ElementContent &) const;
147 ElementContent loadContent(const QDomDocument &);
149 ElementContent addContentAtPos(const ElementContent &, const QPointF &);
150 void addPrimitive(QGraphicsItem *);
151 void initPasteArea();
152 static bool zValueLessThan(QGraphicsItem *, QGraphicsItem *);
155
156 public slots:
157 void slot_select(const ElementContent &);
158 void slot_selectAll();
159 void slot_deselectAll();
161 void slot_delete();
162 void slot_editNames();
164 void slot_editProperties();
167
168 signals:
176 void pasteAreaDefined(const QRectF &);
180};
181
182Q_DECLARE_OPERATORS_FOR_FLAGS(ElementScene::ItemOptions)
183
184#endif
The CustomElementGraphicPart class This class is the base for all home-made primitive like line,...
Definition customelementgraphicpart.h:36
The CustomElementPart class This abstract class represents a primitive of the visual representation o...
Definition customelementpart.h:40
Definition eseventinterface.h:30
The ElementData class WARNING This class inherit from PropertiesInterface but only fromXml is actuall...
Definition elementdata.h:32
The ElementEditionCommand class ElementEditionCommand is the base class for all commands classes invo...
Definition editorcommands.h:47
Definition elementprimitivedecorator.h:42
The ElementScene class This class is the canvas allowing the visual edition of an electrical element....
Definition elementscene.h:46
QUndoStack m_undo_stack
Definition elementscene.h:75
void mouseMoveEvent(QGraphicsSceneMouseEvent *) override
ElementScene::mouseMoveEvent.
Definition elementscene.cpp:116
QGIManager m_qgi_manager
ElementData. Actually in transition with old data storage.
Definition elementscene.h:74
QUndoStack & undoStack()
ElementScene::undoStack.
Definition elementscene.cpp:633
ElementPrimitiveDecorator * m_decorator
Decorator item displayed when at least one item is selected.
Definition elementscene.h:87
~ElementScene() override
ElementScene::~ElementScene.
Definition elementscene.cpp:98
void elementInfoChanged()
virtual const QDomDocument toXml(bool=true)
ElementScene::toXml Export this element as a xml file.
Definition elementscene.cpp:413
void slot_deselectAll()
ElementScene::slot_deselectAll deselect all item.
Definition elementscene.cpp:811
ElementScene::Behavior behavior() const
Definition elementscene.cpp:367
QRectF elementContentBoundingRect(const ElementContent &) const
ElementScene::elementContentBoundingRect.
Definition elementscene.cpp:1120
Behavior m_behavior
Definition elementscene.h:78
void slot_editAuthorInformations()
ElementScene::slot_editAuthorInformations Starts a dialog to edit the additional information of this ...
Definition elementscene.cpp:857
QRectF m_defined_paste_area
Definition elementscene.h:82
void keyPressEvent(QKeyEvent *event) override
ElementScene::keyPressEvent manage key press event.
Definition elementscene.cpp:213
ElementContent loadContent(const QDomDocument &)
ElementScene::loadContent Create and load the content describe in the xml document.
Definition elementscene.cpp:1139
virtual ElementContent selectedContent() const
ElementScene::selectedContent.
Definition elementscene.cpp:1055
void pasteAreaDefined(const QRectF &)
Signal emitted when users have defined the copy/paste area.
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override
ElementScene::mouseDoubleClickEvent.
Definition elementscene.cpp:193
void drawForeground(QPainter *, const QRectF &) override
ElementScene::drawForeground Draws the background of the editor, ie the hotspot indicator.
Definition elementscene.cpp:308
virtual void fromXml(const QDomDocument &, const QPointF &=QPointF(), bool=true, ElementContent *=nullptr)
ElementScene::fromXml Imports the element described in an XML document. If a position is specified,...
Definition elementscene.cpp:555
bool containsTerminals() const
ElementScene::containsTerminals.
Definition elementscene.cpp:616
void needZoomFit()
Signal emitted when need zoomFit.
void initPasteArea()
ElementScene::initPasteArea Initializes the paste area.
Definition elementscene.cpp:1273
QString m_last_copied
Definition elementscene.h:84
QETElementEditor * editor() const
ElementScene::editor.
Definition elementscene.cpp:719
void setElementData(ElementData data)
Definition elementscene.cpp:85
void partsZValueChanged()
Signal emitted when the zValue of one or several parts change.
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override
ElementScene::contextMenuEvent Display the context menu event, only if behavior are Normal.
Definition elementscene.cpp:291
QPointF snapToGrid(QPointF point)
ElementScene::snapToGrid Rounds the coordinates of the point passed as a parameter so that this point...
Definition elementscene.cpp:1301
static bool zValueLessThan(QGraphicsItem *, QGraphicsItem *)
ElementScene::zValueLessThan.
Definition elementscene.cpp:1314
virtual QList< QGraphicsItem * > zItems(ItemOptions options=ItemOptions(SortByZValue|IncludeTerminals|SelectedOrNot)) const
ElementScene::zItems.
Definition elementscene.cpp:981
void stackAction(ElementEditionCommand *)
ElementScene::stackAction Push the provided command on the undo stack.
Definition elementscene.cpp:1402
QGIManager & qgiManager()
ElementScene::qgiManager.
Definition elementscene.cpp:643
ESEventInterface * m_event_interface
Definition elementscene.h:77
QPointer< CustomElementGraphicPart > m_single_selected_item
Definition elementscene.h:92
virtual int yGrid() const
ElementScene::yGrid.
Definition elementscene.cpp:387
void addPrimitive(QGraphicsItem *)
ElementScene::addPrimitive Add a primitive to the scene by wrapping it within an ElementPrimitiveDeco...
Definition elementscene.cpp:1262
virtual void reset()
ElementScene::reset Remove all QGraphicsItems in the scene and clear the undo stack.
Definition elementscene.cpp:1087
bool wasCopiedFromThisElement(const QString &)
ElementScene::wasCopiedFromThisElement.
Definition elementscene.cpp:670
void centerElementToOrigine()
ElementScene::centerElementToOrigine try to center better is possible the element to the scene (the c...
Definition elementscene.cpp:1324
int m_y_grid
Definition elementscene.h:90
void addItems(QVector< QGraphicsItem * > items)
ElementScene::addItems Add items to the scene and emit partsAdded. Prefer always use this method inst...
Definition elementscene.cpp:731
void slot_editNames()
ElementScene::slot_editNames Launch a dialog for edit the names of the edited element.
Definition elementscene.cpp:931
void setEventInterface(ESEventInterface *event_interface)
ElementScene::setEventInterface Set a new event interface.
Definition elementscene.cpp:331
virtual void setGrid(int, int)
ElementScene::setGrid.
Definition elementscene.cpp:399
void slot_selectAll()
ElementScene::slot_selectAll Select all items.
Definition elementscene.cpp:802
int m_x_grid
Definition elementscene.h:89
ElementData m_element_data
Definition elementscene.h:73
void slot_delete()
ElementScene::slot_delete Delete selected items.
Definition elementscene.cpp:835
virtual QRectF boundingRectFromXml(const QDomDocument &)
ElementScene::boundingRectFromXml.
Definition elementscene.cpp:513
Behavior
Definition elementscene.h:52
@ AddPart
Definition elementscene.h:52
@ PasteArea
Definition elementscene.h:52
@ Normal
Definition elementscene.h:52
friend class ChangePropertiesCommand
Definition elementscene.h:47
void mousePressEvent(QGraphicsSceneMouseEvent *) override
ElementScene::mousePressEvent.
Definition elementscene.cpp:147
void setBehavior(ElementScene::Behavior)
ElementScene::setBehavior Modify the current behavior of this scene.
Definition elementscene.cpp:362
void clearEventInterface()
ElementScene::clearEventInterface Clear the current event interface.
Definition elementscene.cpp:347
void mouseReleaseEvent(QGraphicsSceneMouseEvent *) override
ElementScene::mouseReleaseEvent.
Definition elementscene.cpp:166
ElementScene(const ElementScene &)
virtual void getPasteArea(const QRectF &)
ElementScene::getPasteArea.
Definition elementscene.cpp:1072
void slot_select(const ElementContent &)
ElementScene::slot_select Select the item in content, every others items in the scene are deselected.
Definition elementscene.cpp:772
void removeItems(QVector< QGraphicsItem * > items)
ElementScene::removeItems Remove items from the scene and emit partsRemoved. Prefer always use this m...
Definition elementscene.cpp:747
void slot_invertSelection()
ElementScene::slot_invertSelection Inverse Selection.
Definition elementscene.cpp:821
void partsRemoved()
Signal emitted after one or several parts were removed.
void copy()
ElementScene::copy Handles the fact of copying the selection = exporting it as XML to the clipboard.
Definition elementscene.cpp:697
ElementContent addContent(const ElementContent &)
ElementScene::addContent Add content content to this element.
Definition elementscene.cpp:1211
QMutex * m_decorator_lock
Definition elementscene.h:153
ElementContent addContentAtPos(const ElementContent &, const QPointF &)
ElementScene::addContentAtPos Add content content to this element.
Definition elementscene.cpp:1232
virtual int xGrid() const
ElementScene::xGrid.
Definition elementscene.cpp:377
ItemOption
Definition elementscene.h:53
@ SelectedOrNot
Definition elementscene.h:59
@ NonSelected
Definition elementscene.h:58
@ SortByZValue
Definition elementscene.h:54
@ IncludeTerminals
Definition elementscene.h:55
@ Selected
Definition elementscene.h:57
@ IncludeHelperItems
Definition elementscene.h:56
void partsAdded()
Signal emitted after one or several parts were added.
QETElementEditor * m_element_editor
Definition elementscene.h:79
static bool clipboardMayContainElement()
ElementScene::clipboardMayContainElement.
Definition elementscene.cpp:653
virtual QList< CustomElementPart * > primitives() const
ElementScene::primitives.
Definition elementscene.cpp:962
QGraphicsRectItem * m_paste_area
Definition elementscene.h:81
ElementData elementData()
ElementScene::elementData.
Definition elementscene.cpp:81
void managePrimitivesGroups()
ElementScene::managePrimitivesGroups Ensure the decorator is adequately shown, hidden or updated so i...
Definition elementscene.cpp:1352
QRectF elementSceneGeometricRect() const
ElementScene::elementSceneGeometricRect.
Definition elementscene.cpp:595
void cut()
ElementScene::cut Handles the fact of cutting the selection = exporting it in XML to the clipboard th...
Definition elementscene.cpp:682
void slot_editProperties()
ElementScene::slot_editProperties Open dialog to edit the element properties.
Definition elementscene.cpp:914
Definition qetelementeditor.h:39
Definition qgimanager.h:30
QList< QGraphicsItem * > ElementContent
Definition elementcontent.h:30