QElectroTech 0.100.0-dev
Loading...
Searching...
No Matches
Public Types | Public Slots | Signals | Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Friends | List of all members
ElementScene Class Reference

The ElementScene class This class is the canvas allowing the visual edition of an electrical element. It displays the various primitives composing the drawing of the element, the border due to its fixed size and its hotspot. More...

#include <elementscene.h>

Inherits QGraphicsScene.

Collaboration diagram for ElementScene:
Collaboration graph

Public Types

enum  Behavior { Normal , PasteArea , AddPart }
 
enum  ItemOption {
  SortByZValue = 1 , IncludeTerminals = 2 , IncludeHelperItems = 4 , Selected = 8 ,
  NonSelected = 16 , SelectedOrNot = 24
}
 

Public Slots

void slot_select (const ElementContent &)
 ElementScene::slot_select Select the item in content, every others items in the scene are deselected.
 
void slot_selectAll ()
 ElementScene::slot_selectAll Select all items.
 
void slot_deselectAll ()
 ElementScene::slot_deselectAll deselect all item.
 
void slot_invertSelection ()
 ElementScene::slot_invertSelection Inverse Selection.
 
void slot_delete ()
 ElementScene::slot_delete Delete selected items.
 
void slot_editNames ()
 ElementScene::slot_editNames Launch a dialog for edit the names of the edited element.
 
void slot_editAuthorInformations ()
 ElementScene::slot_editAuthorInformations Starts a dialog to edit the additional information of this element. Concretely, this free field is intended to receive information on the author of the element, its license, etc.
 
void slot_editProperties ()
 ElementScene::slot_editProperties Open dialog to edit the element properties.
 
void managePrimitivesGroups ()
 ElementScene::managePrimitivesGroups Ensure the decorator is adequately shown, hidden or updated so it always represents the current selection.
 
void stackAction (ElementEditionCommand *)
 ElementScene::stackAction Push the provided command on the undo stack.
 

Signals

void partsAdded ()
 Signal emitted after one or several parts were added.
 
void partsRemoved ()
 Signal emitted after one or several parts were removed.
 
void partsZValueChanged ()
 Signal emitted when the zValue of one or several parts change.
 
void pasteAreaDefined (const QRectF &)
 Signal emitted when users have defined the copy/paste area.
 
void needZoomFit ()
 Signal emitted when need zoomFit.
 
void elementInfoChanged ()
 

Public Member Functions

 ElementScene (QETElementEditor *, QObject *=nullptr)
 ElementScene::ElementScene constructor.
 
 ~ElementScene () override
 ElementScene::~ElementScene.
 
ElementData elementData ()
 ElementScene::elementData.
 
void setElementData (ElementData data)
 
void setEventInterface (ESEventInterface *event_interface)
 ElementScene::setEventInterface Set a new event interface.
 
void clearEventInterface ()
 ElementScene::clearEventInterface Clear the current event interface.
 
void setBehavior (ElementScene::Behavior)
 ElementScene::setBehavior Modify the current behavior of this scene.
 
ElementScene::Behavior behavior () const
 
QPointF snapToGrid (QPointF point)
 ElementScene::snapToGrid Rounds the coordinates of the point passed as a parameter so that this point is aligned with the grid.
 
virtual int xGrid () const
 ElementScene::xGrid.
 
virtual int yGrid () const
 ElementScene::yGrid.
 
virtual void setGrid (int, int)
 ElementScene::setGrid.
 
virtual const QDomDocument toXml (bool=true)
 ElementScene::toXml Export this element as a xml file.
 
virtual QRectF boundingRectFromXml (const QDomDocument &)
 ElementScene::boundingRectFromXml.
 
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, the imported elements are positioned in such a way that the upper left corner of the smallest rectangle that can surround them all (the bounding rect) either at this position.
 
virtual void reset ()
 ElementScene::reset Remove all QGraphicsItems in the scene and clear the undo stack.
 
virtual QList< CustomElementPart * > primitives () const
 ElementScene::primitives.
 
virtual QList< QGraphicsItem * > zItems (ItemOptions options=ItemOptions(SortByZValue|IncludeTerminals|SelectedOrNot)) const
 ElementScene::zItems.
 
virtual ElementContent selectedContent () const
 ElementScene::selectedContent.
 
virtual void getPasteArea (const QRectF &)
 ElementScene::getPasteArea.
 
QRectF elementSceneGeometricRect () const
 ElementScene::elementSceneGeometricRect.
 
bool containsTerminals () const
 ElementScene::containsTerminals.
 
QUndoStack & undoStack ()
 ElementScene::undoStack.
 
QGIManagerqgiManager ()
 ElementScene::qgiManager.
 
bool wasCopiedFromThisElement (const QString &)
 ElementScene::wasCopiedFromThisElement.
 
void cut ()
 ElementScene::cut Handles the fact of cutting the selection = exporting it in XML to the clipboard then deleting it.
 
void copy ()
 ElementScene::copy Handles the fact of copying the selection = exporting it as XML to the clipboard.
 
QETElementEditoreditor () const
 ElementScene::editor.
 
void addItems (QVector< QGraphicsItem * > items)
 ElementScene::addItems Add items to the scene and emit partsAdded. Prefer always use this method instead of QGraphicsScene::addItem even if you want to add one item, for gain the signal emission.
 
void removeItems (QVector< QGraphicsItem * > items)
 ElementScene::removeItems Remove items from the scene and emit partsRemoved. Prefer always use this method instead of QGraphicsScene::removeItem even if you want to remove one item, for gain the signal emission.
 

Static Public Member Functions

static bool clipboardMayContainElement ()
 ElementScene::clipboardMayContainElement.
 

Protected Member Functions

void mouseMoveEvent (QGraphicsSceneMouseEvent *) override
 ElementScene::mouseMoveEvent.
 
void mousePressEvent (QGraphicsSceneMouseEvent *) override
 ElementScene::mousePressEvent.
 
void mouseReleaseEvent (QGraphicsSceneMouseEvent *) override
 ElementScene::mouseReleaseEvent.
 
void mouseDoubleClickEvent (QGraphicsSceneMouseEvent *event) override
 ElementScene::mouseDoubleClickEvent.
 
void keyPressEvent (QKeyEvent *event) override
 ElementScene::keyPressEvent manage key press event.
 
void contextMenuEvent (QGraphicsSceneContextMenuEvent *event) override
 ElementScene::contextMenuEvent Display the context menu event, only if behavior are Normal.
 
void drawForeground (QPainter *, const QRectF &) override
 ElementScene::drawForeground Draws the background of the editor, ie the hotspot indicator.
 

Private Member Functions

 ElementScene (const ElementScene &)
 
QRectF elementContentBoundingRect (const ElementContent &) const
 ElementScene::elementContentBoundingRect.
 
ElementContent loadContent (const QDomDocument &)
 ElementScene::loadContent Create and load the content describe in the xml document.
 
ElementContent addContent (const ElementContent &)
 ElementScene::addContent Add content content to this element.
 
ElementContent addContentAtPos (const ElementContent &, const QPointF &)
 ElementScene::addContentAtPos Add content content to this element.
 
void addPrimitive (QGraphicsItem *)
 ElementScene::addPrimitive Add a primitive to the scene by wrapping it within an ElementPrimitiveDecorator group.
 
void initPasteArea ()
 ElementScene::initPasteArea Initializes the paste area.
 
void centerElementToOrigine ()
 ElementScene::centerElementToOrigine try to center better is possible the element to the scene (the calcul isn't optimal but work good)
 

Static Private Member Functions

static bool zValueLessThan (QGraphicsItem *, QGraphicsItem *)
 ElementScene::zValueLessThan.
 

Private Attributes

ElementData m_element_data
 
QGIManager m_qgi_manager
 ElementData. Actually in transition with old data storage.
 
QUndoStack m_undo_stack
 
ESEventInterfacem_event_interface = nullptr
 
Behavior m_behavior
 
QETElementEditorm_element_editor = nullptr
 
QGraphicsRectItem * m_paste_area
 
QRectF m_defined_paste_area
 
QString m_last_copied
 
ElementPrimitiveDecoratorm_decorator = nullptr
 Decorator item displayed when at least one item is selected.
 
int m_x_grid
 
int m_y_grid
 
QPointer< CustomElementGraphicPartm_single_selected_item
 
QMutex * m_decorator_lock
 

Friends

class ChangePropertiesCommand
 

Detailed Description

The ElementScene class This class is the canvas allowing the visual edition of an electrical element. It displays the various primitives composing the drawing of the element, the border due to its fixed size and its hotspot.

For add and remove item prefer use custom method addItems and removeItems instead of addItem and removeItem, because these methods emit signal partAdded and partRemoved.

Member Enumeration Documentation

◆ Behavior

Enumerator
Normal 
PasteArea 
AddPart 

◆ ItemOption

Enumerator
SortByZValue 
IncludeTerminals 
IncludeHelperItems 
Selected 
NonSelected 
SelectedOrNot 

Constructor & Destructor Documentation

◆ ElementScene() [1/2]

ElementScene::ElementScene ( QETElementEditor editor,
QObject *  parent = nullptr 
)

ElementScene::ElementScene constructor.

Parameters
editor: Element editor concerned
parent: Widget parent
Here is the call graph for this function:

◆ ~ElementScene()

ElementScene::~ElementScene ( )
override

ElementScene::~ElementScene.

Here is the call graph for this function:

◆ ElementScene() [2/2]

ElementScene::ElementScene ( const ElementScene )
private

Member Function Documentation

◆ addContent()

ElementContent ElementScene::addContent ( const ElementContent content)
private

ElementScene::addContent Add content content to this element.

Parameters
content: content (= list of parts) to load
Returns
Content adds
Here is the call graph for this function:
Here is the caller graph for this function:

◆ addContentAtPos()

ElementContent ElementScene::addContentAtPos ( const ElementContent content,
const QPointF &  pos 
)
private

ElementScene::addContentAtPos Add content content to this element.

Parameters
content: content (= list of parts) to load
pos: Position of the upper left corner of the content after being added
Returns
Content adds
Here is the call graph for this function:
Here is the caller graph for this function:

◆ addItems()

void ElementScene::addItems ( QVector< QGraphicsItem * >  items)

ElementScene::addItems Add items to the scene and emit partsAdded. Prefer always use this method instead of QGraphicsScene::addItem even if you want to add one item, for gain the signal emission.

Parameters
items
Here is the call graph for this function:

◆ addPrimitive()

void ElementScene::addPrimitive ( QGraphicsItem *  primitive)
private

ElementScene::addPrimitive Add a primitive to the scene by wrapping it within an ElementPrimitiveDecorator group.

Parameters
primitive
Here is the caller graph for this function:

◆ behavior()

ElementScene::Behavior ElementScene::behavior ( ) const

◆ boundingRectFromXml()

QRectF ElementScene::boundingRectFromXml ( const QDomDocument &  xml_document)
virtual

ElementScene::boundingRectFromXml.

Parameters
xml_document: an XML document describing an element
Returns
the boundingRect of the element's content
Here is the call graph for this function:

◆ centerElementToOrigine()

void ElementScene::centerElementToOrigine ( )
private

ElementScene::centerElementToOrigine try to center better is possible the element to the scene (the calcul isn't optimal but work good)

Here is the call graph for this function:
Here is the caller graph for this function:

◆ clearEventInterface()

void ElementScene::clearEventInterface ( )

ElementScene::clearEventInterface Clear the current event interface.

◆ clipboardMayContainElement()

bool ElementScene::clipboardMayContainElement ( )
static

ElementScene::clipboardMayContainElement.

Returns
true if the clipboard appears to contain an element
Here is the caller graph for this function:

◆ containsTerminals()

bool ElementScene::containsTerminals ( ) const

ElementScene::containsTerminals.

Returns
true if the element has at least one terminal, false if it has none.

◆ contextMenuEvent()

void ElementScene::contextMenuEvent ( QGraphicsSceneContextMenuEvent *  event)
overrideprotected

ElementScene::contextMenuEvent Display the context menu event, only if behavior are Normal.

Parameters
event

◆ copy()

void ElementScene::copy ( )

ElementScene::copy Handles the fact of copying the selection = exporting it as XML to the clipboard.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cut()

void ElementScene::cut ( )

ElementScene::cut Handles the fact of cutting the selection = exporting it in XML to the clipboard then deleting it.

Here is the call graph for this function:

◆ drawForeground()

void ElementScene::drawForeground ( QPainter *  p,
const QRectF &   
)
overrideprotected

ElementScene::drawForeground Draws the background of the editor, ie the hotspot indicator.

Parameters
p: The QPainter to use for drawing

◆ editor()

QETElementEditor * ElementScene::editor ( ) const

ElementScene::editor.

Returns
Here is the caller graph for this function:

◆ elementContentBoundingRect()

QRectF ElementScene::elementContentBoundingRect ( const ElementContent content) const
private

ElementScene::elementContentBoundingRect.

Parameters
content: Content (= parts) of an element
Returns
the boundingRect of these parts, expressed in the coordinates of the scene
Here is the caller graph for this function:

◆ elementData()

ElementData ElementScene::elementData ( )

ElementScene::elementData.

Returns
the elementdata using by the scene
Here is the caller graph for this function:

◆ elementInfoChanged

void ElementScene::elementInfoChanged ( )
signal
Here is the caller graph for this function:

◆ elementSceneGeometricRect()

QRectF ElementScene::elementSceneGeometricRect ( ) const

ElementScene::elementSceneGeometricRect.

Returns
the minimum, margin-less rectangle the element can fit into, in scene coordinates. It is different from itemsBoundingRect() because it is not supposed to imply any margin.
Here is the caller graph for this function:

◆ fromXml()

void ElementScene::fromXml ( const QDomDocument &  xml_document,
const QPointF &  position = QPointF(),
bool  consider_informations = true,
ElementContent content_ptr = nullptr 
)
virtual

ElementScene::fromXml Imports the element described in an XML document. If a position is specified, the imported elements are positioned in such a way that the upper left corner of the smallest rectangle that can surround them all (the bounding rect) either at this position.

Parameters
xml_document: an XML document describing the element
position: The position of the imported parts
consider_informations: If true, additional information (dimensions, hotspot, etc.) will be taken into account
content_ptr: if this pointer to an ElementContent is different from 0, it will be filled with the content added to the element by the fromXml
Here is the call graph for this function:

◆ getPasteArea()

void ElementScene::getPasteArea ( const QRectF &  to_paste)
virtual

ElementScene::getPasteArea.

Parameters
to_paste: Rectangle enclosing the parts to be glued
Returns
the rectangle where you will have to glue these parts

◆ initPasteArea()

void ElementScene::initPasteArea ( )
private

ElementScene::initPasteArea Initializes the paste area.

Here is the caller graph for this function:

◆ keyPressEvent()

void ElementScene::keyPressEvent ( QKeyEvent *  event)
overrideprotected

ElementScene::keyPressEvent manage key press event.

Parameters
event
Here is the call graph for this function:
Here is the caller graph for this function:

◆ loadContent()

ElementContent ElementScene::loadContent ( const QDomDocument &  xml_document)
private

ElementScene::loadContent Create and load the content describe in the xml document.

Parameters
xml_document: xml dom document to analyze
Returns
the loaded content
Here is the call graph for this function:
Here is the caller graph for this function:

◆ managePrimitivesGroups

void ElementScene::managePrimitivesGroups ( )
slot

ElementScene::managePrimitivesGroups Ensure the decorator is adequately shown, hidden or updated so it always represents the current selection.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mouseDoubleClickEvent()

void ElementScene::mouseDoubleClickEvent ( QGraphicsSceneMouseEvent *  event)
overrideprotected

ElementScene::mouseDoubleClickEvent.

Parameters
event
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mouseMoveEvent()

void ElementScene::mouseMoveEvent ( QGraphicsSceneMouseEvent *  e)
overrideprotected

ElementScene::mouseMoveEvent.

Parameters
e
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mousePressEvent()

void ElementScene::mousePressEvent ( QGraphicsSceneMouseEvent *  e)
overrideprotected

ElementScene::mousePressEvent.

Parameters
e
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mouseReleaseEvent()

void ElementScene::mouseReleaseEvent ( QGraphicsSceneMouseEvent *  e)
overrideprotected

ElementScene::mouseReleaseEvent.

Parameters
e
Here is the call graph for this function:
Here is the caller graph for this function:

◆ needZoomFit

void ElementScene::needZoomFit ( )
signal

Signal emitted when need zoomFit.

Here is the caller graph for this function:

◆ partsAdded

void ElementScene::partsAdded ( )
signal

Signal emitted after one or several parts were added.

Here is the caller graph for this function:

◆ partsRemoved

void ElementScene::partsRemoved ( )
signal

Signal emitted after one or several parts were removed.

Here is the caller graph for this function:

◆ partsZValueChanged

void ElementScene::partsZValueChanged ( )
signal

Signal emitted when the zValue of one or several parts change.

Here is the caller graph for this function:

◆ pasteAreaDefined

void ElementScene::pasteAreaDefined ( const QRectF &  )
signal

Signal emitted when users have defined the copy/paste area.

Here is the caller graph for this function:

◆ primitives()

QList< CustomElementPart * > ElementScene::primitives ( ) const
virtual

ElementScene::primitives.

Returns
the list of primitives currently present on the scene.

◆ qgiManager()

QGIManager & ElementScene::qgiManager ( )

ElementScene::qgiManager.

Returns
the QGraphicsItem manager of this item editor
Here is the caller graph for this function:

◆ removeItems()

void ElementScene::removeItems ( QVector< QGraphicsItem * >  items)

ElementScene::removeItems Remove items from the scene and emit partsRemoved. Prefer always use this method instead of QGraphicsScene::removeItem even if you want to remove one item, for gain the signal emission.

Parameters
items
Here is the call graph for this function:

◆ reset()

void ElementScene::reset ( )
virtual

ElementScene::reset Remove all QGraphicsItems in the scene and clear the undo stack.

Here is the call graph for this function:

◆ selectedContent()

ElementContent ElementScene::selectedContent ( ) const
virtual

ElementScene::selectedContent.

Returns
the selected graphic parts
Here is the call graph for this function:

◆ setBehavior()

void ElementScene::setBehavior ( ElementScene::Behavior  b)

ElementScene::setBehavior Modify the current behavior of this scene.

Parameters
b
Here is the caller graph for this function:

◆ setElementData()

void ElementScene::setElementData ( ElementData  data)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setEventInterface()

void ElementScene::setEventInterface ( ESEventInterface event_interface)

ElementScene::setEventInterface Set a new event interface.

Parameters
event_interface
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setGrid()

void ElementScene::setGrid ( int  x_g,
int  y_g 
)
virtual

ElementScene::setGrid.

Parameters
x_g: Horizontal grid size
y_g: Vertical grid size
Here is the caller graph for this function:

◆ slot_delete

void ElementScene::slot_delete ( )
slot

ElementScene::slot_delete Delete selected items.

Here is the caller graph for this function:

◆ slot_deselectAll

void ElementScene::slot_deselectAll ( )
slot

ElementScene::slot_deselectAll deselect all item.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ slot_editAuthorInformations

void ElementScene::slot_editAuthorInformations ( )
slot

ElementScene::slot_editAuthorInformations Starts a dialog to edit the additional information of this element. Concretely, this free field is intended to receive information on the author of the element, its license, etc.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ slot_editNames

void ElementScene::slot_editNames ( )
slot

ElementScene::slot_editNames Launch a dialog for edit the names of the edited element.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ slot_editProperties

void ElementScene::slot_editProperties ( )
slot

ElementScene::slot_editProperties Open dialog to edit the element properties.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ slot_invertSelection

void ElementScene::slot_invertSelection ( )
slot

ElementScene::slot_invertSelection Inverse Selection.

Here is the caller graph for this function:

◆ slot_select

void ElementScene::slot_select ( const ElementContent content)
slot

ElementScene::slot_select Select the item in content, every others items in the scene are deselected.

Parameters
content
Here is the caller graph for this function:

◆ slot_selectAll

void ElementScene::slot_selectAll ( )
slot

ElementScene::slot_selectAll Select all items.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ snapToGrid()

QPointF ElementScene::snapToGrid ( QPointF  point)

ElementScene::snapToGrid Rounds the coordinates of the point passed as a parameter so that this point is aligned with the grid.

Parameters
point: a reference to a QPointF. This object will be modified.
Returns
point
Here is the caller graph for this function:

◆ stackAction

void ElementScene::stackAction ( ElementEditionCommand command)
slot

ElementScene::stackAction Push the provided command on the undo stack.

Parameters
command
Here is the call graph for this function:
Here is the caller graph for this function:

◆ toXml()

const QDomDocument ElementScene::toXml ( bool  all_parts = true)
virtual

ElementScene::toXml Export this element as a xml file.

Parameters
all_parts: (true by default) if true, export the entire element in xml, if false, only export the selected parts.
Returns
an xml document that describe the element.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ undoStack()

QUndoStack & ElementScene::undoStack ( )

ElementScene::undoStack.

Returns
the undo stack of this element editor
Here is the caller graph for this function:

◆ wasCopiedFromThisElement()

bool ElementScene::wasCopiedFromThisElement ( const QString &  clipboard_content)

ElementScene::wasCopiedFromThisElement.

Parameters
clipboard_content: character string, probably coming from the clipboard.
Returns
true if clipboard_content has been copied from this element.

◆ xGrid()

int ElementScene::xGrid ( ) const
virtual

ElementScene::xGrid.

Returns
the horizontal size of the grid

◆ yGrid()

int ElementScene::yGrid ( ) const
virtual

ElementScene::yGrid.

Returns
vertical grid size

◆ zItems()

QList< QGraphicsItem * > ElementScene::zItems ( ItemOptions  options = ItemOptions(SortByZValue  | IncludeTerminals  | SelectedOrNot)) const
virtual

ElementScene::zItems.

Parameters
options
Returns
the parts of the element ordered by increasing zValue
Here is the call graph for this function:
Here is the caller graph for this function:

◆ zValueLessThan()

bool ElementScene::zValueLessThan ( QGraphicsItem *  item1,
QGraphicsItem *  item2 
)
staticprivate

ElementScene::zValueLessThan.

Parameters
item1: QGraphicsItem
item2: QGraphicsItem
Returns
true if item1's zValue() is less than item2's.
Here is the caller graph for this function:

Friends And Related Symbol Documentation

◆ ChangePropertiesCommand

friend class ChangePropertiesCommand
friend

Member Data Documentation

◆ m_behavior

Behavior ElementScene::m_behavior
private

◆ m_decorator

ElementPrimitiveDecorator* ElementScene::m_decorator = nullptr
private

Decorator item displayed when at least one item is selected.

◆ m_decorator_lock

QMutex* ElementScene::m_decorator_lock
private

◆ m_defined_paste_area

QRectF ElementScene::m_defined_paste_area
private

◆ m_element_data

ElementData ElementScene::m_element_data
private

◆ m_element_editor

QETElementEditor* ElementScene::m_element_editor = nullptr
private

◆ m_event_interface

ESEventInterface* ElementScene::m_event_interface = nullptr
private

◆ m_last_copied

QString ElementScene::m_last_copied
private

◆ m_paste_area

QGraphicsRectItem* ElementScene::m_paste_area
private

◆ m_qgi_manager

QGIManager ElementScene::m_qgi_manager
private

ElementData. Actually in transition with old data storage.

◆ m_single_selected_item

QPointer<CustomElementGraphicPart> ElementScene::m_single_selected_item
private

◆ m_undo_stack

QUndoStack ElementScene::m_undo_stack
private

◆ m_x_grid

int ElementScene::m_x_grid
private

◆ m_y_grid

int ElementScene::m_y_grid
private

The documentation for this class was generated from the following files: