BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
PolygonPointView Class Reference

Description

This is a View of polygon point for PolygonMaskItem.

Definition at line 24 of file PolygonPointView.h.

Inheritance diagram for PolygonPointView:
[legend]
Collaboration diagram for PolygonPointView:
[legend]

Signals

void closePolygonRequest (bool)
 
void propertyChanged ()
 

Public Member Functions

 PolygonPointView (PolygonPointItem *item)
 
 ~PolygonPointView () override
 
virtual void addView (IShape2DView *childView, int row=0)
 
QRectF boundingRect () const override
 
SessionItemparameterizedItem () const override
 
void setSceneAdaptor (const ISceneAdaptor *adaptor)
 
int type () const override
 
void updateParameterizedItem (const QPointF &pos)
 

Protected Slots

virtual void onChangedX ()
 
virtual void onChangedY ()
 
void onPropertyChange () override
 
void update_view () override
 

Protected Member Functions

bool blockOnProperty () const
 
void disconnectFromItem (SessionItem *item)
 
qreal fromSceneX (qreal value) const
 convert scene coordinates to ColorMap plot coordinates More...
 
qreal fromSceneY (qreal value) const
 
void hoverEnterEvent (QGraphicsSceneHoverEvent *event) override
 
void hoverLeaveEvent (QGraphicsSceneHoverEvent *event) override
 
QPainterPath maskedShape () const
 Returns the shape with all masking already applied. More...
 
void mouseMoveEvent (QGraphicsSceneMouseEvent *event) override
 
void paint (QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) override
 
void setBlockOnProperty (bool value)
 
qreal toSceneX (qreal value) const
 
qreal toSceneY (qreal value) const
 

Protected Attributes

const ISceneAdaptorm_adaptor
 
bool m_block_on_property_change
 
QRectF m_bounding_rect
 

Private Member Functions

void onItemDestroyed () override
 
void onItemPropertyChange (const QString &propertyName)
 

Private Attributes

PolygonPointItemm_item
 
bool m_on_hover
 

Constructor & Destructor Documentation

◆ PolygonPointView()

PolygonPointView::PolygonPointView ( PolygonPointItem item)
explicit

Definition at line 20 of file PolygonPointView.cpp.

21  : IShape2DView(item)
22  , m_item(item)
23  , m_on_hover(false)
24 {
25  setFlag(QGraphicsItem::ItemIsMovable);
26  setFlag(QGraphicsItem::ItemSendsGeometryChanges);
27 }
IShape2DView(SessionItem *item)
PolygonPointItem * m_item

◆ ~PolygonPointView()

PolygonPointView::~PolygonPointView ( )
override

Definition at line 29 of file PolygonPointView.cpp.

30 {
32 }
void disconnectFromItem(SessionItem *item)

References IShape2DView::disconnectFromItem(), and m_item.

Here is the call graph for this function:

Member Function Documentation

◆ addView()

void IShape2DView::addView ( IShape2DView childView,
int  row = 0 
)
virtualinherited

Reimplemented in PolygonView.

Definition at line 129 of file IShape2DView.cpp.

130 {
131  if (!childItems().contains(childView))
132  childView->setParentItem(this);
133 }

Referenced by MaskGraphicsScene::updateViews().

◆ blockOnProperty()

bool IShape2DView::blockOnProperty ( ) const
protectedinherited

Definition at line 140 of file IShape2DView.cpp.

141 {
143 }
bool m_block_on_property_change
Definition: IShape2DView.h:69

References IShape2DView::m_block_on_property_change.

◆ boundingRect()

QRectF PolygonPointView::boundingRect ( ) const
override

Definition at line 34 of file PolygonPointView.cpp.

35 {
36  return QRectF(-4, -4, 8, 8);
37 }

Referenced by paint().

◆ closePolygonRequest

void PolygonPointView::closePolygonRequest ( bool  )
signal

◆ disconnectFromItem()

void IShape2DView::disconnectFromItem ( SessionItem item)
protectedinherited

Definition at line 145 of file IShape2DView.cpp.

146 {
147  if (item)
148  item->mapper()->unsubscribe(this);
149 }
void unsubscribe(const void *caller)
Cancels all subscriptions of given caller.
Definition: ModelMapper.cpp:78
ModelMapper * mapper()
Returns the current model mapper of this item. Creates new one if necessary.

References SessionItem::mapper(), and ModelMapper::unsubscribe().

Referenced by EllipseView::~EllipseView(), HorizontalLineView::~HorizontalLineView(), MaskAllView::~MaskAllView(), MaskContainerView::~MaskContainerView(), ~PolygonPointView(), PolygonView::~PolygonView(), RectangleView::~RectangleView(), and VerticalLineView::~VerticalLineView().

Here is the call graph for this function:

◆ fromSceneX()

qreal IShape2DView::fromSceneX ( qreal  value) const
protectedinherited

convert scene coordinates to ColorMap plot coordinates

Definition at line 119 of file IShape2DView.cpp.

120 {
121  return m_adaptor ? m_adaptor->fromSceneX(value) : value;
122 }
virtual qreal fromSceneX(qreal) const =0
convert scene x-coordinate to native mask coordinate
const ISceneAdaptor * m_adaptor
Definition: IShape2DView.h:67

References ISceneAdaptor::fromSceneX(), and IShape2DView::m_adaptor.

Referenced by EllipseView::mouseMoveEvent(), RectangleView::mouseMoveEvent(), EllipseView::onChangedX(), VerticalLineView::onChangedX(), RectangleView::onChangedX(), and updateParameterizedItem().

Here is the call graph for this function:

◆ fromSceneY()

qreal IShape2DView::fromSceneY ( qreal  value) const
protectedinherited

Definition at line 124 of file IShape2DView.cpp.

125 {
126  return m_adaptor ? m_adaptor->fromSceneY(value) : value;
127 }
virtual qreal fromSceneY(qreal) const =0
convert scene y-coordinate to native mask coordinate

References ISceneAdaptor::fromSceneY(), and IShape2DView::m_adaptor.

Referenced by EllipseView::mouseMoveEvent(), RectangleView::mouseMoveEvent(), EllipseView::onChangedY(), HorizontalLineView::onChangedY(), RectangleView::onChangedY(), and updateParameterizedItem().

Here is the call graph for this function:

◆ hoverEnterEvent()

void PolygonPointView::hoverEnterEvent ( QGraphicsSceneHoverEvent *  event)
overrideprotected

Definition at line 76 of file PolygonPointView.cpp.

77 {
78  m_on_hover = true;
80  IShape2DView::hoverEnterEvent(event);
81 }
void closePolygonRequest(bool)

References closePolygonRequest(), and m_on_hover.

◆ hoverLeaveEvent()

void PolygonPointView::hoverLeaveEvent ( QGraphicsSceneHoverEvent *  event)
overrideprotected

Definition at line 83 of file PolygonPointView.cpp.

84 {
85  m_on_hover = false;
87  IShape2DView::hoverLeaveEvent(event);
88 }

References closePolygonRequest(), and m_on_hover.

◆ maskedShape()

QPainterPath IShape2DView::maskedShape ( ) const
protectedinherited

Returns the shape with all masking already applied.

Definition at line 79 of file IShape2DView.cpp.

80 {
81  static const QSet<MaskEditorHelper::EViewTypes> relevantMaskTypes = {
84 
85  QPainterPath resultingShape = mapToScene(shape());
86  for (auto* item : scene()->items()) {
87  auto* const maskItem = dynamic_cast<IShape2DView*>(item);
88  if (!maskItem
89  || !relevantMaskTypes.contains((MaskEditorHelper::EViewTypes)maskItem->type()))
90  continue;
91 
92  const bool isMaskingItem = itemMaskValue(maskItem->parameterizedItem());
93  const bool isOnTop = maskItem->zValue() > zValue();
94  if (isMaskingItem || !isOnTop)
95  continue;
96 
97  const auto maskItemShape = maskItem->mapToScene(maskItem->shape());
98  if (!maskItemShape.intersects(resultingShape))
99  continue;
100 
101  // Item lays on top and is non-masking -> subtract the
102  // path of the item
103  resultingShape = resultingShape.subtracted(maskItemShape);
104  }
105 
106  return mapFromScene(resultingShape);
107 }
Main interface class for views representing MaskItems, Projections on graphics scene.
Definition: IShape2DView.h:27

References MaskEditorHelper::ELLIPSE, MaskEditorHelper::HORIZONTALLINE, MaskEditorHelper::POLYGON, MaskEditorHelper::RECTANGLE, and MaskEditorHelper::VERTICALLINE.

Referenced by IShape2DView::paint().

◆ mouseMoveEvent()

void PolygonPointView::mouseMoveEvent ( QGraphicsSceneMouseEvent *  event)
overrideprotected

Definition at line 71 of file PolygonPointView.cpp.

72 {
73  updateParameterizedItem(event->scenePos());
74 }
void updateParameterizedItem(const QPointF &pos)

References updateParameterizedItem().

Here is the call graph for this function:

◆ onChangedX

virtual void IShape2DView::onChangedX ( )
inlineprotectedvirtualslotinherited

Definition at line 44 of file IShape2DView.h.

44 {}

Referenced by IShape2DView::IShape2DView().

◆ onChangedY

virtual void IShape2DView::onChangedY ( )
inlineprotectedvirtualslotinherited

Definition at line 45 of file IShape2DView.h.

45 {}

Referenced by IShape2DView::IShape2DView().

◆ onItemDestroyed()

void PolygonPointView::onItemDestroyed ( )
overrideprivatevirtual

Implements IShape2DView.

Definition at line 90 of file PolygonPointView.cpp.

91 {
92  m_item = nullptr;
93 }

References m_item.

◆ onItemPropertyChange()

void IShape2DView::onItemPropertyChange ( const QString &  propertyName)
privateinherited

Definition at line 151 of file IShape2DView.cpp.

152 {
154  return;
155 
157 
158  bool schedule_update = false;
159  if (MaskItem::isMaskValuePropertyName(propertyName))
160  schedule_update = true;
161  else if (MaskItem::isIsVisiblePropertyName(propertyName)) {
162  bool visible = false;
163  if (auto* maskItem = dynamic_cast<MaskItem*>(parameterizedItem()))
164  visible = maskItem->isVisibleValue();
165  this->setVisible(visible);
166  schedule_update = true;
167  }
168 
170 
171  if (schedule_update)
172  update();
173 
175 }
virtual void onPropertyChange()
Definition: IShape2DView.h:46
virtual SessionItem * parameterizedItem() const =0
A base class for all mask items.
Definition: MaskItems.h:27
static bool isIsVisiblePropertyName(const QString &name)
Definition: MaskItems.cpp:105
static bool isMaskValuePropertyName(const QString &name)
Definition: MaskItems.cpp:90

References MaskItem::isIsVisiblePropertyName(), MaskItem::isMaskValuePropertyName(), IShape2DView::m_block_on_property_change, IShape2DView::onPropertyChange(), and IShape2DView::parameterizedItem().

Referenced by IShape2DView::IShape2DView().

Here is the call graph for this function:

◆ onPropertyChange

void PolygonPointView::onPropertyChange ( )
overrideprotectedslot

Definition at line 55 of file PolygonPointView.cpp.

56 {
57  emit propertyChanged();
58 }
void propertyChanged()

References propertyChanged().

◆ paint()

void PolygonPointView::paint ( QPainter *  painter,
const QStyleOptionGraphicsItem *  ,
QWidget *   
)
overrideprotected

Definition at line 60 of file PolygonPointView.cpp.

61 {
62  painter->setRenderHints(QPainter::Antialiasing);
64  if (acceptHoverEvents() && m_on_hover)
65  brush.setColor(Qt::red);
66  painter->setBrush(brush);
67  painter->setPen(MaskEditorHelper::getSelectionMarkerPen());
68  painter->drawEllipse(boundingRect());
69 }
static QPen getSelectionMarkerPen()
static QBrush getSelectionMarkerBrush()
QRectF boundingRect() const override

References boundingRect(), MaskEditorHelper::getSelectionMarkerBrush(), MaskEditorHelper::getSelectionMarkerPen(), and m_on_hover.

Here is the call graph for this function:

◆ parameterizedItem()

SessionItem * PolygonPointView::parameterizedItem ( ) const
overridevirtual

Implements IShape2DView.

Definition at line 39 of file PolygonPointView.cpp.

40 {
41  return m_item;
42 }

References m_item.

◆ propertyChanged

void PolygonPointView::propertyChanged ( )
signal

◆ setBlockOnProperty()

void IShape2DView::setBlockOnProperty ( bool  value)
protectedinherited

◆ setSceneAdaptor()

void IShape2DView::setSceneAdaptor ( const ISceneAdaptor adaptor)
inherited

Definition at line 55 of file IShape2DView.cpp.

56 {
57  ASSERT(adaptor);
58 
59  if (m_adaptor != adaptor) {
60  if (m_adaptor)
62 
63  m_adaptor = adaptor;
65  Qt::UniqueConnection);
66  update_view();
67  }
68 }
void update_request()
virtual void update_view()=0
update visual appearance of view (triggered by ISceneAdaptor)

References IShape2DView::m_adaptor, ISceneAdaptor::update_request(), and IShape2DView::update_view().

Referenced by MaskViewFactory::createMaskView().

Here is the call graph for this function:

◆ toSceneX()

qreal IShape2DView::toSceneX ( qreal  value) const
protectedinherited

Definition at line 109 of file IShape2DView.cpp.

110 {
111  return m_adaptor ? m_adaptor->toSceneX(value) : value;
112 }
virtual qreal toSceneX(qreal) const =0
convert native mask x-coordinate to scene coordinate

References IShape2DView::m_adaptor, and ISceneAdaptor::toSceneX().

Referenced by EllipseView::left(), RectangleView::left(), EllipseView::onPropertyChange(), VerticalLineView::onPropertyChange(), EllipseView::right(), RectangleView::right(), PolygonView::update_polygon(), EllipseView::update_position(), RectangleView::update_position(), and VerticalLineView::update_view().

Here is the call graph for this function:

◆ toSceneY()

qreal IShape2DView::toSceneY ( qreal  value) const
protectedinherited

Definition at line 114 of file IShape2DView.cpp.

115 {
116  return m_adaptor ? m_adaptor->toSceneY(value) : value;
117 }
virtual qreal toSceneY(qreal) const =0
convert native mask y-coordinate to scene coordinate

References IShape2DView::m_adaptor, and ISceneAdaptor::toSceneY().

Referenced by EllipseView::bottom(), RectangleView::bottom(), EllipseView::onPropertyChange(), HorizontalLineView::onPropertyChange(), EllipseView::top(), RectangleView::top(), PolygonView::update_polygon(), EllipseView::update_position(), RectangleView::update_position(), and HorizontalLineView::update_view().

Here is the call graph for this function:

◆ type()

int PolygonPointView::type ( ) const
inlineoverride

Definition at line 28 of file PolygonPointView.h.

References MaskEditorHelper::POLYGONPOINT.

◆ update_view

void PolygonPointView::update_view ( )
overrideprotectedslot

Definition at line 50 of file PolygonPointView.cpp.

51 {
52  update();
53 }

◆ updateParameterizedItem()

void PolygonPointView::updateParameterizedItem ( const QPointF &  pos)

Definition at line 44 of file PolygonPointView.cpp.

45 {
46  m_item->setPosX(fromSceneX(pos.x()));
47  m_item->setPosY(fromSceneY(pos.y()));
48 }
qreal fromSceneY(qreal value) const
qreal fromSceneX(qreal value) const
convert scene coordinates to ColorMap plot coordinates
void setPosY(double pos_y)
Definition: MaskItems.cpp:239
void setPosX(double pos_x)
Definition: MaskItems.cpp:229

References IShape2DView::fromSceneX(), IShape2DView::fromSceneY(), m_item, PolygonPointItem::setPosX(), and PolygonPointItem::setPosY().

Referenced by mouseMoveEvent().

Here is the call graph for this function:

Member Data Documentation

◆ m_adaptor

◆ m_block_on_property_change

bool IShape2DView::m_block_on_property_change
protectedinherited

◆ m_bounding_rect

◆ m_item

PolygonPointItem* PolygonPointView::m_item
private

◆ m_on_hover

bool PolygonPointView::m_on_hover
private

Definition at line 58 of file PolygonPointView.h.

Referenced by hoverEnterEvent(), hoverLeaveEvent(), and paint().


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