QElectroTech 0.200.1-dev
Loading...
Searching...
No Matches
elementscene.h
Go to the documentation of this file.
1/*
2 Copyright 2006-2026 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
21#include "../diagramcontext.h"
22#include "../qgimanager.h"
23#include "elementcontent.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 bool m_hotspot_visible = true;
95
96 // methods
97 public:
99 void setElementData(ElementData data);
100
101 void setEventInterface (ESEventInterface *event_interface);
102 void clearEventInterface();
103
106
107 QPointF snapToGrid(QPointF point);
108 virtual int xGrid() const;
109 virtual int yGrid() const;
110 virtual void setGrid(int, int);
111
112 virtual const QDomDocument toXml(bool = true);
113 virtual QRectF boundingRectFromXml(const QDomDocument &);
114 virtual void fromXml(const QDomDocument &,
115 const QPointF & = QPointF(),
116 bool = true,
117 ElementContent * = nullptr);
118 virtual void reset();
119 virtual QList<CustomElementPart *> primitives() const;
120 virtual QList<QGraphicsItem *>
121 zItems(ItemOptions options = ItemOptions(SortByZValue
123 | SelectedOrNot)) const;
124 virtual ElementContent selectedContent() const;
125 virtual void getPasteArea(const QRectF &);
126 QRectF elementSceneGeometricRect () const;
127 bool containsTerminals() const;
128 QUndoStack &undoStack();
130 static bool clipboardMayContainElement();
131 bool wasCopiedFromThisElement(const QString &);
132 void cut();
133 void copy();
134 QETElementEditor* editor() const;
135 void addItems(QVector<QGraphicsItem *> items);
136 void removeItems(QVector<QGraphicsItem *> items);
137
143 void setHotspotVisible(bool visible) {m_hotspot_visible = visible;}
144 bool hotspotVisible() const {return m_hotspot_visible;}
145
146 protected:
147 void mouseMoveEvent (QGraphicsSceneMouseEvent *) override;
148 void mousePressEvent (QGraphicsSceneMouseEvent *) override;
149 void mouseReleaseEvent (QGraphicsSceneMouseEvent *) override;
150 void mouseDoubleClickEvent (QGraphicsSceneMouseEvent *event) override;
151 void keyPressEvent (QKeyEvent *event) override;
152 void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override;
153 void drawForeground(QPainter *, const QRectF &) override;
154
155 private:
156 QRectF elementContentBoundingRect(const ElementContent &) const;
157 ElementContent loadContent(const QDomDocument &);
159 ElementContent addContentAtPos(const ElementContent &, const QPointF &);
160 void addPrimitive(QGraphicsItem *);
161 void initPasteArea();
162 static bool zValueLessThan(QGraphicsItem *, QGraphicsItem *);
165
166 public slots:
167 void slot_select(const ElementContent &);
168 void slot_selectAll();
169 void slot_deselectAll();
171 void slot_delete();
172 void slot_editNames();
174 void slot_editProperties();
177
178 signals:
186 void pasteAreaDefined(const QRectF &);
193 void mouseMoved(const QPointF &pos);
194};
195
196Q_DECLARE_OPERATORS_FOR_FLAGS(ElementScene::ItemOptions)
197
198#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:36
The ElementEditionCommand class ElementEditionCommand is the base class for all commands classes invo...
Definition editorcommands.h:47
Definition elementprimitivedecorator.h:42
QUndoStack m_undo_stack
Definition elementscene.h:75
void mouseMoveEvent(QGraphicsSceneMouseEvent *) override
ElementScene::mouseMoveEvent.
Definition elementscene.cpp:120
QGIManager m_qgi_manager
ElementData. Actually in transition with old data storage.
Definition elementscene.h:74
QUndoStack & undoStack()
ElementScene::undoStack.
Definition elementscene.cpp:646
ElementPrimitiveDecorator * m_decorator
Decorator item displayed when at least one item is selected.
Definition elementscene.h:87
~ElementScene() override
ElementScene::~ElementScene.
Definition elementscene.cpp:100
void elementInfoChanged()
virtual const QDomDocument toXml(bool=true)
ElementScene::toXml Export this element as a xml file.
Definition elementscene.cpp:424
void slot_deselectAll()
ElementScene::slot_deselectAll deselect all item.
Definition elementscene.cpp:824
ElementScene(QETElementEditor *, QObject *=nullptr)
ElementScene::ElementScene constructor.
Definition elementscene.cpp:54
ElementScene::Behavior behavior() const
Definition elementscene.cpp:378
QRectF elementContentBoundingRect(const ElementContent &) const
ElementScene::elementContentBoundingRect.
Definition elementscene.cpp:1165
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:870
QRectF m_defined_paste_area
Definition elementscene.h:82
void keyPressEvent(QKeyEvent *event) override
ElementScene::keyPressEvent manage key press event.
Definition elementscene.cpp:220
ElementContent loadContent(const QDomDocument &)
ElementScene::loadContent Create and load the content describe in the xml document.
Definition elementscene.cpp:1184
virtual ElementContent selectedContent() const
ElementScene::selectedContent.
Definition elementscene.cpp:1100
void pasteAreaDefined(const QRectF &)
Signal emitted when users have defined the copy/paste area.
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override
ElementScene::mouseDoubleClickEvent.
Definition elementscene.cpp:200
void drawForeground(QPainter *, const QRectF &) override
ElementScene::drawForeground Draws the background of the editor, ie the hotspot indicator.
Definition elementscene.cpp:315
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:567
bool containsTerminals() const
ElementScene::containsTerminals.
Definition elementscene.cpp:629
void needZoomFit()
Signal emitted when need zoomFit.
void initPasteArea()
ElementScene::initPasteArea Initializes the paste area.
Definition elementscene.cpp:1319
QString m_last_copied
Definition elementscene.h:84
QETElementEditor * editor() const
ElementScene::editor.
Definition elementscene.cpp:732
void setElementData(ElementData data)
Definition elementscene.cpp:84
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:298
QPointF snapToGrid(QPointF point)
ElementScene::snapToGrid Rounds the coordinates of the point passed as a parameter so that this point...
Definition elementscene.cpp:1347
static bool zValueLessThan(QGraphicsItem *, QGraphicsItem *)
ElementScene::zValueLessThan.
Definition elementscene.cpp:1360
virtual QList< QGraphicsItem * > zItems(ItemOptions options=ItemOptions(SortByZValue|IncludeTerminals|SelectedOrNot)) const
ElementScene::zItems.
Definition elementscene.cpp:1026
void stackAction(ElementEditionCommand *)
ElementScene::stackAction Push the provided command on the undo stack.
Definition elementscene.cpp:1438
QGIManager & qgiManager()
ElementScene::qgiManager.
Definition elementscene.cpp:656
ESEventInterface * m_event_interface
Definition elementscene.h:77
bool m_hotspot_visible
Definition elementscene.h:94
QPointer< CustomElementGraphicPart > m_single_selected_item
Definition elementscene.h:92
virtual int yGrid() const
ElementScene::yGrid.
Definition elementscene.cpp:398
void addPrimitive(QGraphicsItem *)
ElementScene::addPrimitive Add a primitive to the scene by wrapping it within an ElementPrimitiveDeco...
Definition elementscene.cpp:1308
virtual void reset()
ElementScene::reset Remove all QGraphicsItems in the scene and clear the undo stack.
Definition elementscene.cpp:1132
bool wasCopiedFromThisElement(const QString &)
ElementScene::wasCopiedFromThisElement.
Definition elementscene.cpp:683
bool hotspotVisible() const
Definition elementscene.h:144
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:744
void slot_editNames()
ElementScene::slot_editNames Launch a dialog for edit the names of the edited element.
Definition elementscene.cpp:976
void setEventInterface(ESEventInterface *event_interface)
ElementScene::setEventInterface Set a new event interface.
Definition elementscene.cpp:342
virtual void setGrid(int, int)
ElementScene::setGrid.
Definition elementscene.cpp:410
void slot_selectAll()
ElementScene::slot_selectAll Select all items.
Definition elementscene.cpp:815
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:848
virtual QRectF boundingRectFromXml(const QDomDocument &)
ElementScene::boundingRectFromXml.
Definition elementscene.cpp:525
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:154
void setBehavior(ElementScene::Behavior)
ElementScene::setBehavior Modify the current behavior of this scene.
Definition elementscene.cpp:373
void clearEventInterface()
ElementScene::clearEventInterface Clear the current event interface.
Definition elementscene.cpp:358
void mouseReleaseEvent(QGraphicsSceneMouseEvent *) override
ElementScene::mouseReleaseEvent.
Definition elementscene.cpp:173
ElementScene(const ElementScene &)
virtual void getPasteArea(const QRectF &)
ElementScene::getPasteArea.
Definition elementscene.cpp:1117
void slot_select(const ElementContent &)
ElementScene::slot_select Select the item in content, every others items in the scene are deselected.
Definition elementscene.cpp:785
void mouseMoved(const QPointF &pos)
Signal emitted with the current cursor position (scene coordinates) on every mouse move.
void removeItems(QVector< QGraphicsItem * > items)
ElementScene::removeItems Remove items from the scene and emit partsRemoved. Prefer always use this m...
Definition elementscene.cpp:760
void slot_invertSelection()
ElementScene::slot_invertSelection Inverse Selection.
Definition elementscene.cpp:834
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:710
ElementContent addContent(const ElementContent &)
ElementScene::addContent Add content content to this element.
Definition elementscene.cpp:1257
QMutex * m_decorator_lock
Definition elementscene.h:163
ElementContent addContentAtPos(const ElementContent &, const QPointF &)
ElementScene::addContentAtPos Add content content to this element.
Definition elementscene.cpp:1278
virtual int xGrid() const
ElementScene::xGrid.
Definition elementscene.cpp:388
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.
void setHotspotVisible(bool visible)
Definition elementscene.h:143
QETElementEditor * m_element_editor
Definition elementscene.h:79
void elementTypeChanged()
Signal emitted when the element type changes.
static bool clipboardMayContainElement()
ElementScene::clipboardMayContainElement.
Definition elementscene.cpp:666
void centerElementToOrigin()
ElementScene::centerElementToOrigin try to center better is possible the element to the scene.
Definition elementscene.cpp:1369
virtual QList< CustomElementPart * > primitives() const
ElementScene::primitives.
Definition elementscene.cpp:1007
QGraphicsRectItem * m_paste_area
Definition elementscene.h:81
ElementData elementData()
ElementScene::elementData.
Definition elementscene.cpp:80
void managePrimitivesGroups()
ElementScene::managePrimitivesGroups Ensure the decorator is adequately shown, hidden or updated so i...
Definition elementscene.cpp:1390
QRectF elementSceneGeometricRect() const
ElementScene::elementSceneGeometricRect.
Definition elementscene.cpp:607
void cut()
ElementScene::cut Handles the fact of cutting the selection = exporting it in XML to the clipboard th...
Definition elementscene.cpp:695
void slot_editProperties()
ElementScene::slot_editProperties Open dialog to edit the element properties.
Definition elementscene.cpp:927
Definition qetelementeditor.h:39
Definition qgimanager.h:30
QList< QGraphicsItem * > ElementContent
Definition elementcontent.h:30