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

Description

This is a view of VerticalLineItem mask.

Definition at line 25 of file LineViews.h.

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

Public Member Functions

 VerticalLineView (VerticalLineItem *item)
 
 ~VerticalLineView () override
 
virtual void addView (IShape2DView *childView, int row=0)
 
QRectF boundingRect () const override
 
SessionItemparameterizedItem () const override
 
void setSceneAdaptor (const ISceneAdaptor *adaptor)
 
QPainterPath shape () const override
 
int type () const override
 

Protected Slots

void onChangedX () override
 
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
 
QVariant itemChange (GraphicsItemChange change, const QVariant &value) override
 Allows item movement along x, prevent movement along y. More...
 
QPainterPath maskedShape () const
 Returns the shape with all masking already applied. More...
 
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

VerticalLineItemm_item
 

Constructor & Destructor Documentation

◆ VerticalLineView()

VerticalLineView::VerticalLineView ( VerticalLineItem item)
explicit

Definition at line 29 of file LineViews.cpp.

30  : IShape2DView(item)
31  , m_item(item)
32 {
33  setFlag(QGraphicsItem::ItemIsSelectable);
34  setFlag(QGraphicsItem::ItemIsMovable);
35  setFlag(QGraphicsItem::ItemSendsGeometryChanges);
36  setCursor(Qt::SizeHorCursor);
37 }
IShape2DView(SessionItem *item)
VerticalLineItem * m_item
Definition: LineViews.h:49

◆ ~VerticalLineView()

VerticalLineView::~VerticalLineView ( )
override

Definition at line 39 of file LineViews.cpp.

40 {
42 }
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 IShape2DView::boundingRect ( ) const
overrideinherited

Definition at line 50 of file IShape2DView.cpp.

51 {
52  return m_bounding_rect;
53 }
QRectF m_bounding_rect
Definition: IShape2DView.h:68

References IShape2DView::m_bounding_rect.

◆ 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::~PolygonPointView(), PolygonView::~PolygonView(), RectangleView::~RectangleView(), and ~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(), onChangedX(), RectangleView::onChangedX(), and PolygonPointView::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 PolygonPointView::updateParameterizedItem().

Here is the call graph for this function:

◆ itemChange()

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

Allows item movement along x, prevent movement along y.

Definition at line 98 of file LineViews.cpp.

100 {
101  if (isSelected() && change == ItemPositionChange && scene()) {
102  QPointF newPos = value.toPointF();
103  newPos.setY(y());
104  return newPos;
105  }
106  return QGraphicsItem::itemChange(change, value);
107 }

◆ 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().

◆ onChangedX

void VerticalLineView::onChangedX ( )
overrideprotectedslot

Definition at line 56 of file LineViews.cpp.

57 {
58  setBlockOnProperty(true);
59  m_item->setPosX(fromSceneX(this->x()));
60  setBlockOnProperty(false);
61 }
void setBlockOnProperty(bool value)
qreal fromSceneX(qreal value) const
convert scene coordinates to ColorMap plot coordinates
void setPosX(double pos_x)
Definition: MaskItems.cpp:336

References IShape2DView::fromSceneX(), m_item, IShape2DView::setBlockOnProperty(), and VerticalLineItem::setPosX().

Here is the call graph for this function:

◆ onChangedY

virtual void IShape2DView::onChangedY ( )
inlineprotectedvirtualslotinherited

Definition at line 45 of file IShape2DView.h.

45 {}

Referenced by IShape2DView::IShape2DView().

◆ onItemDestroyed()

void VerticalLineView::onItemDestroyed ( )
overrideprivatevirtual

Implements IShape2DView.

Definition at line 109 of file LineViews.cpp.

110 {
111  m_item = nullptr;
112 }

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 VerticalLineView::onPropertyChange ( )
overrideprotectedslot

Definition at line 63 of file LineViews.cpp.

64 {
65  setX(toSceneX(m_item->posX()));
66 }
qreal toSceneX(qreal value) const
DoubleDescriptor posX() const
Definition: MaskItems.cpp:331

References m_item, VerticalLineItem::posX(), and IShape2DView::toSceneX().

Here is the call graph for this function:

◆ paint()

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

Definition at line 79 of file LineViews.cpp.

80 {
81  bool mask_value = static_cast<VerticalLineItem*>(m_item)->maskValue();
82  painter->setBrush(MaskEditorHelper::getMaskBrush(mask_value));
83  painter->setPen(MaskEditorHelper::getMaskPen(mask_value));
84  painter->drawRect(
85  QRectF(-mask_visible_width / 2., 0.0, mask_visible_width, m_bounding_rect.height()));
86 
87  if (isSelected()) {
88  QPen pen;
89  pen.setStyle(Qt::DashLine);
90  painter->setPen(pen);
91  painter->setBrush(Qt::NoBrush);
92  painter->drawRect(
93  QRectF(-mask_visible_width / 2., 0.0, mask_visible_width, m_bounding_rect.height()));
94  }
95 }
static QBrush getMaskBrush(bool mask_value)
static QPen getMaskPen(bool mask_value)

References MaskEditorHelper::getMaskBrush(), MaskEditorHelper::getMaskPen(), IShape2DView::m_bounding_rect, and m_item.

Here is the call graph for this function:

◆ parameterizedItem()

SessionItem * VerticalLineView::parameterizedItem ( ) const
overridevirtual

Implements IShape2DView.

Definition at line 51 of file LineViews.cpp.

52 {
53  return m_item;
54 }

References m_item.

◆ 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:

◆ shape()

QPainterPath VerticalLineView::shape ( ) const
override

Definition at line 44 of file LineViews.cpp.

45 {
46  QPainterPath p;
47  p.addRect(QRectF(-mask_visible_width / 2., 0.0, mask_visible_width, m_bounding_rect.height()));
48  return p;
49 }

References IShape2DView::m_bounding_rect.

◆ 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(), onPropertyChange(), EllipseView::right(), RectangleView::right(), PolygonView::update_polygon(), EllipseView::update_position(), RectangleView::update_position(), and 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 VerticalLineView::type ( ) const
inlineoverride

Definition at line 29 of file LineViews.h.

References MaskEditorHelper::VERTICALLINE.

◆ update_view

void VerticalLineView::update_view ( )
overrideprotectedslot

Definition at line 68 of file LineViews.cpp.

69 {
70  QRectF plot_scene_rectangle = m_adaptor->viewportRectangle();
71 
72  setX(toSceneX(m_item->posX()));
73  setY(plot_scene_rectangle.top());
74 
75  m_bounding_rect = QRectF(-mask_width / 2., 0.0, mask_width, plot_scene_rectangle.height());
76  update();
77 }
virtual const QRectF & viewportRectangle() const
Returns viewport rectangle in scene coordinates.
Definition: ISceneAdaptor.h:39

References IShape2DView::m_adaptor, IShape2DView::m_bounding_rect, m_item, VerticalLineItem::posX(), IShape2DView::toSceneX(), and ISceneAdaptor::viewportRectangle().

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

VerticalLineItem* VerticalLineView::m_item
private

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