QElectroTech  0.70
Public Types | Signals | Public Member Functions | Protected Member Functions | Properties | Private Member Functions | Private Attributes | List of all members
PartPolygon Class Reference

The PartPolygon class This class represents a polygon primitive which may be used to compose the drawing of an electrical element within the element editor. More...

#include <partpolygon.h>

Public Types

enum  { Type = UserType + 1105 }
 
- Public Types inherited from CustomElementGraphicPart
enum  LineStyle { NormalStyle, DashedStyle, DottedStyle, DashdottedStyle }
 
enum  LineWeight {
  NoneWeight, ThinWeight, NormalWeight, UltraWeight,
  BigWeight
}
 
enum  Filling {
  NoneFilling, BlackFilling, WhiteFilling, GreenFilling,
  RedFilling, BlueFilling, GrayFilling, BrunFilling,
  YellowFilling, CyanFilling, MagentaFilling, LightgrayFilling,
  OrangeFilling, PurpleFilling, HorFilling, VerFilling,
  BdiagFilling, FdiagFilling
}
 
enum  Color {
  BlackColor, WhiteColor, GreenColor, RedColor,
  BlueColor, GrayColor, BrunColor, YellowColor,
  CyanColor, MagentaColor, LightgrayColor, OrangeColor,
  PurpleColor, NoneColor
}
 

Signals

void closedChange ()
 
void polygonChanged ()
 

Public Member Functions

 PartPolygon (QETElementEditor *editor, QGraphicsItem *parent=nullptr)
 PartPolygon::PartPolygon Constructor. More...
 
 ~PartPolygon () override
 PartPolygon::~PartPolygon. More...
 
int type () const override
 
void paint (QPainter *, const QStyleOptionGraphicsItem *, QWidget *) override
 PartPolygon::paint Draw this polygon. More...
 
QString name () const override
 
QString xmlName () const override
 
void fromXml (const QDomElement &) override
 PartPolygon::fromXml Import the properties of this polygon from a xml element. More...
 
const QDomElement toXml (QDomDocument &) const override
 PartPolygon::toXml Export this polygin in xml. More...
 
QPainterPath shape () const override
 PartPolygon::shape. More...
 
QPainterPath shadowShape () const override
 
QRectF boundingRect () const override
 PartPolygon::boundingRect. More...
 
bool isUseless () const override
 PartPolygon::isUseless. More...
 
QRectF sceneGeometricRect () const override
 PartPolygon::sceneGeometricRect. More...
 
void startUserTransformation (const QRectF &) override
 PartPolygon::startUserTransformation Start the user-induced transformation, provided this primitive is contained within the initial_selection_rect bounding rectangle. More...
 
void handleUserTransformation (const QRectF &, const QRectF &) override
 PartPolygon::handleUserTransformation Handle the user-induced transformation from initial_selection_rect to new_selection_rect. More...
 
QET::ScalingMethod preferredScalingMethod () const override
 PartPolygon::preferredScalingMethod This method is called by the decorator when it needs to determine the best way to interactively scale a primitive. It is typically called when only a single primitive is being scaled. More...
 
QPolygonF polygon () const
 
void setPolygon (const QPolygonF &polygon)
 PartPolygon::setPolygon Sets the item's polygon to be the given polygon. More...
 
void addPoint (const QPointF &point)
 PartPolygon::addPoint Add new point to polygon. More...
 
void setLastPoint (const QPointF &point)
 PartPolygon::setLastPoint Set the last point of polygon to . More...
 
void removeLastPoint ()
 PartPolygon::removeLastPoint Remove the last point of polygon. More...
 
bool isClosed () const
 
void setClosed (bool close)
 
- Public Member Functions inherited from CustomElementGraphicPart
 CustomElementGraphicPart (QETElementEditor *editor, QGraphicsItem *parent=nullptr)
 CustomElementGraphicPart::CustomElementGraphicPart Default constructor. By default, item is selectable, send geometry change (Qt > 4.6), accept mouse left button and accept hover event. More...
 
 ~CustomElementGraphicPart () override
 CustomElementGraphicPart::~CustomElementGraphicPart Destructor. More...
 
LineStyle lineStyle () const
 
void setLineStyle (const LineStyle ls)
 CustomElementGraphicPart::setLineStyle Set line style to ls. More...
 
LineWeight lineWeight () const
 
void setLineWeight (const LineWeight lw)
 CustomElementGraphicPart::setLineWeight Set line weight to lw. More...
 
qreal penWeight () const
 CustomElementGraphicPart::penWeight. More...
 
Filling filling () const
 
void setFilling (const Filling f)
 CustomElementGraphicPart::setFilling Set filling to f. More...
 
Color color () const
 
void setColor (const Color c)
 CustomElementGraphicPart::setColor Set color to c. More...
 
bool antialiased () const
 
void setAntialiased (const bool b)
 CustomElementGraphicPart::setAntialiased Set antialias to b. More...
 
void setProperty (const char *name, const QVariant &value) override
 
QVariant property (const char *name) const override
 
- Public Member Functions inherited from CustomElementPart
 CustomElementPart (QETElementEditor *editor)
 
virtual ~CustomElementPart ()
 Destructor. More...
 
virtual QETElementEditorelementEditor () const
 
virtual void updateCurrentPartEditor () const
 
virtual ElementSceneelementScene () const
 
virtual QUndoStack & undoStack () const
 
virtual QGraphicsItem * toItem ()
 

Protected Member Functions

QVariant itemChange (GraphicsItemChange change, const QVariant &value) override
 PartPolygon::itemChange. More...
 
bool sceneEventFilter (QGraphicsItem *watched, QEvent *event) override
 PartPolygon::sceneEventFilter. More...
 
void contextMenuEvent (QGraphicsSceneContextMenuEvent *event) override
 
- Protected Member Functions inherited from CustomElementGraphicPart
void stylesToXml (QDomElement &) const
 CustomElementGraphicPart::stylesToXml Write the curent style to xml element. The style are stored like this: name-of-style:value;name-of-style:value Each style separate by ; and name-style/value are separate by : More...
 
void stylesFromXml (const QDomElement &)
 CustomElementGraphicPart::stylesFromXml Read the style used by this, from a xml element. More...
 
void resetStyles ()
 CustomElementGraphicPart::resetStyles Reset the curent style to default, same style of default constructor. More...
 
void applyStylesToQPainter (QPainter &) const
 CustomElementGraphicPart::applyStylesToQPainter Apply the current style to the QPainter. More...
 
void drawShadowShape (QPainter *painter)
 CustomElementGraphicPart::drawShadowShape Draw a transparent blue shadow arround the shape of this item. The QPainterPathStroker used to draw shadows have a width of SHADOWS_HEIGHT Be carefull if penWeight of this item is to 0 the outline of strock is bigger of 0.5. More...
 
QVariant itemChange (GraphicsItemChange change, const QVariant &value) override
 CustomElementGraphicPart::itemChange Reimplemented from QGraphicsObject. If the item position change call updateCurrentPartEditor() the change is always send to QGraphicsObject. More...
 
void hoverEnterEvent (QGraphicsSceneHoverEvent *event) override
 CustomElementGraphicPart::hoverEnterEvent Reimplemented from QGraphicsObject. Set m_hovered to true. More...
 
void hoverLeaveEvent (QGraphicsSceneHoverEvent *event) override
 CustomElementGraphicPart::hoverLeaveEvent Reimplemented from QGraphicsObject. Set m_hovered to false. More...
 
void mousePressEvent (QGraphicsSceneMouseEvent *event) override
 
void mouseMoveEvent (QGraphicsSceneMouseEvent *event) override
 
void mouseReleaseEvent (QGraphicsSceneMouseEvent *event) override
 
- Protected Member Functions inherited from CustomElementPart
QList< QPointF > mapPoints (const QRectF &, const QRectF &, const QList< QPointF > &)
 

Properties

bool closed
 
QPolygonF polygon
 PartPolygon::polygon. More...
 
- Properties inherited from CustomElementGraphicPart
LineStyle line_style
 
LineWeight line_weight
 
Filling filling
 
Color color
 
bool antialias
 

Private Member Functions

 PartPolygon (const PartPolygon &)
 
void adjusteHandlerPos ()
 PartPolygon::adjusteHandlerPos. More...
 
void handlerMousePressEvent (QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event)
 PartPolygon::handlerMousePressEvent. More...
 
void handlerMouseMoveEvent (QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event)
 PartPolygon::handlerMouseMoveEvent. More...
 
void handlerMouseReleaseEvent (QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event)
 PartPolygon::handlerMouseReleaseEvent. More...
 
void sceneSelectionChanged ()
 PartPolygon::sceneSelectionChanged When the scene selection change, if there are several primitive selected, we remove the handler of this item. More...
 
void addHandler ()
 PartPolygon::addHandler Add handlers for this item. More...
 
void removeHandler ()
 PartPolygon::removeHandler Remove the handlers of this item. More...
 
void insertPoint ()
 PartPolygon::insertPoint Insert a point in this polygone. More...
 
void removePoint ()
 PartPolygon::removePoint remove a point on this polygon. More...
 

Private Attributes

bool m_closed
 
QList< QPointF > saved_points_
 
QPolygonF m_polygon
 
QPropertyUndoCommandm_undo_command
 
int m_vector_index = -1
 
QVector< QetGraphicsHandlerItem * > m_handler_vector
 
QAction * m_insert_point
 
QAction * m_remove_point
 
QPointF m_context_menu_pos
 

Additional Inherited Members

- Static Public Member Functions inherited from CustomElementGraphicPart
static void drawCross (const QPointF &center, QPainter *painter)
 CustomElementGraphicPart::drawCross Draw a cross at pos center. More...
 
- Protected Attributes inherited from CustomElementGraphicPart
bool m_hovered
 

Detailed Description

The PartPolygon class This class represents a polygon primitive which may be used to compose the drawing of an electrical element within the element editor.

Definition at line 33 of file partpolygon.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
Type 

Definition at line 54 of file partpolygon.h.

Constructor & Destructor Documentation

◆ PartPolygon() [1/2]

PartPolygon::PartPolygon ( QETElementEditor editor,
QGraphicsItem *  parent = nullptr 
)

PartPolygon::PartPolygon Constructor.

Parameters
editor: editor of this item
parent: parent item

Definition at line 33 of file partpolygon.cpp.

References QET::Icons::Add, insertPoint(), m_insert_point, m_remove_point, QET::Icons::Remove, removePoint(), and QET::Icons::tr.

◆ ~PartPolygon()

PartPolygon::~PartPolygon ( )
override

PartPolygon::~PartPolygon.

Definition at line 49 of file partpolygon.cpp.

References m_undo_command, and removeHandler().

◆ PartPolygon() [2/2]

PartPolygon::PartPolygon ( const PartPolygon )
private

Member Function Documentation

◆ addHandler()

void PartPolygon::addHandler ( )
private

◆ addPoint()

void PartPolygon::addPoint ( const QPointF &  point)

PartPolygon::addPoint Add new point to polygon.

Parameters
point

Definition at line 219 of file partpolygon.cpp.

References m_polygon.

◆ adjusteHandlerPos()

void PartPolygon::adjusteHandlerPos ( )
private

◆ boundingRect()

QRectF PartPolygon::boundingRect ( ) const
override

PartPolygon::boundingRect.

Returns
the bounding rect of this item

Definition at line 568 of file partpolygon.cpp.

References m_polygon, CustomElementGraphicPart::penWeight(), and SHADOWS_HEIGHT.

Referenced by sceneGeometricRect().

◆ closedChange

void PartPolygon::closedChange ( )
signal

◆ contextMenuEvent()

void PartPolygon::contextMenuEvent ( QGraphicsSceneContextMenuEvent *  event)
overrideprotected

◆ fromXml()

void PartPolygon::fromXml ( const QDomElement &  qde)
overridevirtual

PartPolygon::fromXml Import the properties of this polygon from a xml element.

Parameters
qde: Xml document to use

Implements CustomElementPart.

Definition at line 85 of file partpolygon.cpp.

References QET::attributeIsAReal(), m_closed, m_polygon, and CustomElementGraphicPart::stylesFromXml().

◆ handlerMouseMoveEvent()

void PartPolygon::handlerMouseMoveEvent ( QetGraphicsHandlerItem qghi,
QGraphicsSceneMouseEvent *  event 
)
private

◆ handlerMousePressEvent()

void PartPolygon::handlerMousePressEvent ( QetGraphicsHandlerItem qghi,
QGraphicsSceneMouseEvent *  event 
)
private

PartPolygon::handlerMousePressEvent.

Parameters
qghi
event

Definition at line 391 of file partpolygon.cpp.

References m_polygon, m_undo_command, and QET::Icons::tr.

Referenced by sceneEventFilter().

◆ handlerMouseReleaseEvent()

void PartPolygon::handlerMouseReleaseEvent ( QetGraphicsHandlerItem qghi,
QGraphicsSceneMouseEvent *  event 
)
private

◆ handleUserTransformation()

void PartPolygon::handleUserTransformation ( const QRectF &  initial_selection_rect,
const QRectF &  new_selection_rect 
)
overridevirtual

PartPolygon::handleUserTransformation Handle the user-induced transformation from initial_selection_rect to new_selection_rect.

Parameters
initial_selection_rect
new_selection_rect

Implements CustomElementPart.

Definition at line 175 of file partpolygon.cpp.

References m_polygon, CustomElementPart::mapPoints(), and saved_points_.

◆ insertPoint()

void PartPolygon::insertPoint ( )
private

◆ isClosed()

bool PartPolygon::isClosed ( ) const
inline

Definition at line 84 of file partpolygon.h.

References m_closed.

Referenced by PolygonEditor::updatePolygonClosedState().

◆ isUseless()

bool PartPolygon::isUseless ( ) const
overridevirtual

PartPolygon::isUseless.

Returns
true if this part is irrelevant and does not deserve to be Retained / registered. A polygon is relevant when he have 2 differents points

Implements CustomElementPart.

Definition at line 136 of file partpolygon.cpp.

References m_polygon.

◆ itemChange()

QVariant PartPolygon::itemChange ( GraphicsItemChange  change,
const QVariant &  value 
)
overrideprotected

PartPolygon::itemChange.

Parameters
change
value
Returns

Definition at line 266 of file partpolygon.cpp.

References addHandler(), adjusteHandlerPos(), removeHandler(), and sceneSelectionChanged().

◆ name()

QString PartPolygon::name ( ) const
inlineoverridevirtual
Returns
the name of the primitive

Implements CustomElementPart.

Definition at line 62 of file partpolygon.h.

References QET::Icons::tr.

◆ paint()

void PartPolygon::paint ( QPainter *  painter,
const QStyleOptionGraphicsItem *  options,
QWidget *  widget 
)
override

◆ polygon()

QPolygonF PartPolygon::polygon ( ) const

Referenced by removePoint(), and setPolygon().

◆ polygonChanged

void PartPolygon::polygonChanged ( )
signal

◆ preferredScalingMethod()

QET::ScalingMethod PartPolygon::preferredScalingMethod ( ) const
overridevirtual

PartPolygon::preferredScalingMethod This method is called by the decorator when it needs to determine the best way to interactively scale a primitive. It is typically called when only a single primitive is being scaled.

Returns
: This reimplementation systematically returns QET::RoundScaleRatios.

Reimplemented from CustomElementPart.

Definition at line 188 of file partpolygon.cpp.

References QET::RoundScaleRatios.

◆ removeHandler()

void PartPolygon::removeHandler ( )
private

PartPolygon::removeHandler Remove the handlers of this item.

Definition at line 472 of file partpolygon.cpp.

References m_handler_vector.

Referenced by itemChange(), sceneSelectionChanged(), and ~PartPolygon().

◆ removeLastPoint()

void PartPolygon::removeLastPoint ( )

PartPolygon::removeLastPoint Remove the last point of polygon.

Definition at line 243 of file partpolygon.cpp.

References m_polygon.

Referenced by ESEventAddPolygon::mouseDoubleClickEvent().

◆ removePoint()

void PartPolygon::removePoint ( )
private

◆ sceneEventFilter()

bool PartPolygon::sceneEventFilter ( QGraphicsItem *  watched,
QEvent *  event 
)
overrideprotected

◆ sceneGeometricRect()

QRectF PartPolygon::sceneGeometricRect ( ) const
overridevirtual

PartPolygon::sceneGeometricRect.

Returns
the minimum, margin-less rectangle this part can fit into, in scene coordinates. It is different from boundingRect() because it is not supposed to imply any margin, and it is different from shape because it is a regular rectangle, not a complex shape.

Implements CustomElementPart.

Definition at line 153 of file partpolygon.cpp.

References boundingRect(), and m_polygon.

◆ sceneSelectionChanged()

void PartPolygon::sceneSelectionChanged ( )
private

PartPolygon::sceneSelectionChanged When the scene selection change, if there are several primitive selected, we remove the handler of this item.

Definition at line 440 of file partpolygon.cpp.

References addHandler(), and removeHandler().

Referenced by itemChange().

◆ setClosed()

void PartPolygon::setClosed ( bool  close)

Definition at line 252 of file partpolygon.cpp.

References closedChange(), and m_closed.

Referenced by ESEventAddPolygon::mouseDoubleClickEvent().

◆ setLastPoint()

void PartPolygon::setLastPoint ( const QPointF &  point)

PartPolygon::setLastPoint Set the last point of polygon to .

Parameters
point

Definition at line 230 of file partpolygon.cpp.

References m_polygon.

◆ setPolygon()

void PartPolygon::setPolygon ( const QPolygonF &  polygon)

PartPolygon::setPolygon Sets the item's polygon to be the given polygon.

Parameters
polygon

Definition at line 205 of file partpolygon.cpp.

References adjusteHandlerPos(), m_polygon, polygon(), and polygonChanged().

◆ shadowShape()

QPainterPath PartPolygon::shadowShape ( ) const
overridevirtual

◆ shape()

QPainterPath PartPolygon::shape ( ) const
override

PartPolygon::shape.

Returns
the shape of this item

Definition at line 535 of file partpolygon.cpp.

References m_closed, CustomElementGraphicPart::m_hovered, m_polygon, CustomElementGraphicPart::penWeight(), and SHADOWS_HEIGHT.

Referenced by shadowShape().

◆ startUserTransformation()

void PartPolygon::startUserTransformation ( const QRectF &  initial_selection_rect)
overridevirtual

PartPolygon::startUserTransformation Start the user-induced transformation, provided this primitive is contained within the initial_selection_rect bounding rectangle.

Parameters
initial_selection_rect

Implements CustomElementPart.

Definition at line 163 of file partpolygon.cpp.

References m_polygon, and saved_points_.

◆ toXml()

const QDomElement PartPolygon::toXml ( QDomDocument &  xml_document) const
overridevirtual

PartPolygon::toXml Export this polygin in xml.

Parameters
xml_document: Xml document to use for create the xml element
Returns
an xml element that describe this polygon

Implements CustomElementPart.

Definition at line 116 of file partpolygon.cpp.

References m_closed, m_polygon, and CustomElementGraphicPart::stylesToXml().

◆ type()

int PartPolygon::type ( ) const
inlineoverride

Enable the use of qgraphicsitem_cast to safely cast a QGraphicsItem into a PartPolygon.

Returns
the QGraphicsItem type

Definition at line 59 of file partpolygon.h.

References Type.

◆ xmlName()

QString PartPolygon::xmlName ( ) const
inlineoverridevirtual
Returns
the name that will be used as XML tag when exporting the primitive

Implements CustomElementPart.

Definition at line 63 of file partpolygon.h.

Member Data Documentation

◆ m_closed

bool PartPolygon::m_closed
private

Definition at line 105 of file partpolygon.h.

Referenced by fromXml(), insertPoint(), isClosed(), paint(), setClosed(), shadowShape(), shape(), and toXml().

◆ m_context_menu_pos

QPointF PartPolygon::m_context_menu_pos
private

Definition at line 113 of file partpolygon.h.

Referenced by contextMenuEvent(), insertPoint(), and removePoint().

◆ m_handler_vector

QVector<QetGraphicsHandlerItem *> PartPolygon::m_handler_vector
private

◆ m_insert_point

QAction* PartPolygon::m_insert_point
private

Definition at line 111 of file partpolygon.h.

Referenced by contextMenuEvent(), and PartPolygon().

◆ m_polygon

QPolygonF PartPolygon::m_polygon
private

◆ m_remove_point

QAction * PartPolygon::m_remove_point
private

Definition at line 111 of file partpolygon.h.

Referenced by contextMenuEvent(), and PartPolygon().

◆ m_undo_command

QPropertyUndoCommand* PartPolygon::m_undo_command
private

Definition at line 108 of file partpolygon.h.

Referenced by handlerMousePressEvent(), handlerMouseReleaseEvent(), and ~PartPolygon().

◆ m_vector_index

int PartPolygon::m_vector_index = -1
private

◆ saved_points_

QList<QPointF> PartPolygon::saved_points_
private

Definition at line 106 of file partpolygon.h.

Referenced by handleUserTransformation(), and startUserTransformation().

Property Documentation

◆ closed

bool PartPolygon::closed
readwrite

Definition at line 37 of file partpolygon.h.

◆ polygon

QPolygonF PartPolygon::polygon
readwrite

PartPolygon::polygon.

Returns
the item's polygon, or an empty polygon if no polygon has been set.

Definition at line 38 of file partpolygon.h.

Referenced by ESEventAddPolygon::mouseDoubleClickEvent(), and PolygonEditor::updatePolygonPoints().


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