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

Description

This is a view of HorizontalLineItem mask.

Definition at line 55 of file LineViews.h.

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

Public Member Functions

 HorizontalLineView (HorizontalLineItem *item)
 
 ~HorizontalLineView () 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

virtual void onChangedX ()
 
void onChangedY () override
 
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 y, prevent movement along x. 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

HorizontalLineItemm_item
 

Constructor & Destructor Documentation

◆ HorizontalLineView()

HorizontalLineView::HorizontalLineView ( HorizontalLineItem item)
explicit

Definition at line 116 of file LineViews.cpp.

117  : IShape2DView(item)
118  , m_item(item)
119 {
120  setFlag(QGraphicsItem::ItemIsSelectable);
121  setFlag(QGraphicsItem::ItemIsMovable);
122  setFlag(QGraphicsItem::ItemSendsGeometryChanges);
123  setCursor(Qt::SizeVerCursor);
124 }
HorizontalLineItem * m_item
Definition: LineViews.h:79
IShape2DView(SessionItem *item)

◆ ~HorizontalLineView()

HorizontalLineView::~HorizontalLineView ( )
override

Definition at line 126 of file LineViews.cpp.

127 {
129 }
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(), MaskAllView::~MaskAllView(), MaskContainerView::~MaskContainerView(), PolygonPointView::~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 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(), onChangedY(), RectangleView::onChangedY(), and PolygonPointView::updateParameterizedItem().

Here is the call graph for this function:

◆ itemChange()

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

Allows item movement along y, prevent movement along x.

Definition at line 186 of file LineViews.cpp.

188 {
189  if (isSelected() && change == ItemPositionChange && scene()) {
190  QPointF newPos = value.toPointF();
191  newPos.setX(x());
192  return newPos;
193  }
194  return QGraphicsItem::itemChange(change, value);
195 }

◆ 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

virtual void IShape2DView::onChangedX ( )
inlineprotectedvirtualslotinherited

Definition at line 44 of file IShape2DView.h.

44 {}

Referenced by IShape2DView::IShape2DView().

◆ onChangedY

void HorizontalLineView::onChangedY ( )
overrideprotectedslot

Definition at line 144 of file LineViews.cpp.

145 {
146  setBlockOnProperty(true);
147  m_item->setPosY(fromSceneY(this->y()));
148  setBlockOnProperty(false);
149 }
void setPosY(double pos_y)
Definition: MaskItems.cpp:369
qreal fromSceneY(qreal value) const
void setBlockOnProperty(bool value)

References IShape2DView::fromSceneY(), m_item, IShape2DView::setBlockOnProperty(), and HorizontalLineItem::setPosY().

Here is the call graph for this function:

◆ onItemDestroyed()

void HorizontalLineView::onItemDestroyed ( )
overrideprivatevirtual

Implements IShape2DView.

Definition at line 197 of file LineViews.cpp.

198 {
199  m_item = nullptr;
200 }

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

Definition at line 151 of file LineViews.cpp.

152 {
153  setY(toSceneY(m_item->posY()));
154 }
DoubleDescriptor posY() const
Definition: MaskItems.cpp:364
qreal toSceneY(qreal value) const

References m_item, HorizontalLineItem::posY(), and IShape2DView::toSceneY().

Here is the call graph for this function:

◆ paint()

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

Definition at line 167 of file LineViews.cpp.

168 {
169  bool mask_value = static_cast<HorizontalLineItem*>(m_item)->maskValue();
170  painter->setBrush(MaskEditorHelper::getMaskBrush(mask_value));
171  painter->setPen(MaskEditorHelper::getMaskPen(mask_value));
172  painter->drawRect(
173  QRectF(0.0, -mask_visible_width / 2., m_bounding_rect.width(), mask_visible_width));
174 
175  if (isSelected()) {
176  QPen pen;
177  pen.setStyle(Qt::DashLine);
178  painter->setPen(pen);
179  painter->setBrush(Qt::NoBrush);
180  painter->drawRect(
181  QRectF(0.0, -mask_visible_width / 2., m_bounding_rect.width(), mask_visible_width));
182  }
183 }
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 * HorizontalLineView::parameterizedItem ( ) const
overridevirtual

Implements IShape2DView.

Definition at line 139 of file LineViews.cpp.

140 {
141  return m_item;
142 }

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 HorizontalLineView::shape ( ) const
override

Definition at line 131 of file LineViews.cpp.

132 {
133  QPainterPath path;
134  path.addRect(
135  QRectF(0.0, -mask_visible_width / 2., m_bounding_rect.width(), mask_visible_width));
136  return path;
137 }

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(), 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(), onPropertyChange(), EllipseView::top(), RectangleView::top(), PolygonView::update_polygon(), EllipseView::update_position(), RectangleView::update_position(), and update_view().

Here is the call graph for this function:

◆ type()

int HorizontalLineView::type ( ) const
inlineoverride

Definition at line 59 of file LineViews.h.

References MaskEditorHelper::HORIZONTALLINE.

◆ update_view

void HorizontalLineView::update_view ( )
overrideprotectedslot

Definition at line 156 of file LineViews.cpp.

157 {
158  QRectF plot_scene_rectangle = m_adaptor->viewportRectangle();
159 
160  setX(plot_scene_rectangle.left());
161  setY(toSceneY(m_item->posY()));
162 
163  m_bounding_rect = QRectF(0.0, -mask_width / 2., plot_scene_rectangle.width(), mask_width);
164  update();
165 }
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, HorizontalLineItem::posY(), IShape2DView::toSceneY(), 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

HorizontalLineItem* HorizontalLineView::m_item
private

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