BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
RectangleBaseView Class Referenceabstract

Description

Base view for all rectangular-like masks.

Definition at line 24 of file RectangleBaseView.h.

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

Public Member Functions

 RectangleBaseView (SessionItem *item)
 
virtual void addView (IShape2DView *childView, int row=0)
 
QRectF boundingRect () const override
 
virtual SessionItemparameterizedItem () const =0
 
void setSceneAdaptor (const ISceneAdaptor *adaptor)
 
int type () const override
 

Protected Slots

virtual void onChangedX ()
 
virtual void onChangedY ()
 
virtual void onPropertyChange ()
 

Protected Member Functions

bool blockOnProperty () const
 
virtual qreal bottom () const =0
 
void create_size_handle_elements ()
 
void disconnectFromItem (SessionItem *item)
 
qreal fromSceneX (qreal value) const
 convert scene coordinates to ColorMap plot coordinates More...
 
qreal fromSceneY (qreal value) const
 
qreal height () const
 
QVariant itemChange (GraphicsItemChange change, const QVariant &value) override
 Track if item selected/deselected and show/hide size handles. More...
 
virtual qreal left () const =0
 
virtual QRectF mask_rectangle ()=0
 
QPainterPath maskedShape () const
 Returns the shape with all masking already applied. More...
 
void mouseReleaseEvent (QGraphicsSceneMouseEvent *event) override
 
void paint (QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) override
 
virtual qreal right () const =0
 
void setBlockOnProperty (bool value)
 
virtual qreal top () const =0
 
qreal toSceneX (qreal value) const
 
qreal toSceneY (qreal value) const
 
virtual void update_bounding_rect ()
 updates view's bounding rectangle using item properties More...
 
virtual void update_position ()=0
 
void update_view () override
 update visual appearance of view (triggered by ISceneAdaptor) More...
 
qreal width () const
 Returns width of the rectangle. More...
 

Protected Attributes

SizeHandleElementm_activeHandleElement
 
const ISceneAdaptorm_adaptor
 
bool m_block_on_property_change
 
QRectF m_bounding_rect
 
QRectF m_mask_rect
 mask rectangle in scene coordinates More...
 
QMap< SizeHandleElement::EHandleLocation, SizeHandleElement * > m_resize_handles
 coordinates of corner opposite to the grip corner at the moment it first clicked in scene coordinates More...
 
QPointF m_resize_opposite_origin
 

Private Slots

void onSizeHandleElementRequest (bool going_to_resize)
 triggered by SizeHandleElement More...
 

Private Member Functions

virtual void onItemDestroyed ()=0
 
void onItemPropertyChange (const QString &propertyName)
 

Constructor & Destructor Documentation

◆ RectangleBaseView()

RectangleBaseView::RectangleBaseView ( SessionItem item)
explicit

Definition at line 23 of file RectangleBaseView.cpp.

24  : IShape2DView(item)
25  , m_activeHandleElement(nullptr)
26 {
27  setFlag(QGraphicsItem::ItemIsSelectable);
28  setFlag(QGraphicsItem::ItemIsMovable);
29  setFlag(QGraphicsItem::ItemSendsGeometryChanges);
30  setAcceptHoverEvents(true);
32 }
IShape2DView(SessionItem *item)
SizeHandleElement * m_activeHandleElement

References create_size_handle_elements().

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.

◆ bottom()

virtual qreal RectangleBaseView::bottom ( ) const
protectedpure virtual

Implemented in RectangleView, and EllipseView.

Referenced by height().

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

◆ create_size_handle_elements()

void RectangleBaseView::create_size_handle_elements ( )
protected

Definition at line 103 of file RectangleBaseView.cpp.

104 {
105  QList<SizeHandleElement::EHandleLocation> points;
110 
111  for (SizeHandleElement::EHandleLocation point_type : points) {
112  auto* el = new SizeHandleElement(point_type, this);
113  connect(el, &SizeHandleElement::resize_request, this,
115  el->setVisible(false);
116  m_resize_handles[point_type] = el;
117  }
118 }
void onSizeHandleElementRequest(bool going_to_resize)
triggered by SizeHandleElement
QMap< SizeHandleElement::EHandleLocation, SizeHandleElement * > m_resize_handles
coordinates of corner opposite to the grip corner at the moment it first clicked in scene coordinates
Size handle on top of RectangleView represented as small circle or small rectangle....
void resize_request(bool going_to_resize)

References SizeHandleElement::BOTTOMLEFT, SizeHandleElement::BOTTOMMIDLE, SizeHandleElement::BOTTOMRIGHT, m_resize_handles, SizeHandleElement::MIDDLELEFT, SizeHandleElement::MIDDLERIGHT, onSizeHandleElementRequest(), SizeHandleElement::resize_request(), SizeHandleElement::TOPLEFT, SizeHandleElement::TOPMIDDLE, and SizeHandleElement::TOPRIGHT.

Referenced by RectangleBaseView().

Here is the call graph for this function:

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

Here is the call graph for this function:

◆ height()

qreal RectangleBaseView::height ( ) const
protected

Definition at line 98 of file RectangleBaseView.cpp.

99 {
100  return bottom() - top();
101 }
virtual qreal top() const =0
virtual qreal bottom() const =0

References bottom(), and top().

Referenced by EllipseView::mask_rectangle(), RectangleView::mask_rectangle(), and EllipseView::mouseMoveEvent().

Here is the call graph for this function:

◆ itemChange()

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

Track if item selected/deselected and show/hide size handles.

Definition at line 51 of file RectangleBaseView.cpp.

53 {
54  if (change == QGraphicsItem::ItemSelectedChange) {
55  for (auto it = m_resize_handles.begin(); it != m_resize_handles.end(); ++it)
56  it.value()->setVisible(!this->isSelected());
57  }
58  return value;
59 }

References m_resize_handles.

◆ left()

virtual qreal RectangleBaseView::left ( ) const
protectedpure virtual

Implemented in RectangleView, and EllipseView.

Referenced by width().

◆ mask_rectangle()

virtual QRectF RectangleBaseView::mask_rectangle ( )
protectedpure virtual

Implemented in RectangleView, and EllipseView.

Referenced by update_bounding_rect().

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

◆ mouseReleaseEvent()

void RectangleBaseView::mouseReleaseEvent ( QGraphicsSceneMouseEvent *  event)
overrideprotected

Definition at line 61 of file RectangleBaseView.cpp.

62 {
64  IShape2DView::mouseReleaseEvent(event);
65 }

References onSizeHandleElementRequest().

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

virtual void IShape2DView::onItemDestroyed ( )
privatepure virtualinherited

◆ 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

virtual void IShape2DView::onPropertyChange ( )
inlineprotectedvirtualslotinherited

Definition at line 46 of file IShape2DView.h.

46 {}

Referenced by IShape2DView::onItemPropertyChange().

◆ onSizeHandleElementRequest

void RectangleBaseView::onSizeHandleElementRequest ( bool  going_to_resize)
privateslot

triggered by SizeHandleElement

Definition at line 35 of file RectangleBaseView.cpp.

36 {
37  if (going_to_resize) {
38  setFlag(QGraphicsItem::ItemIsMovable, false);
39  m_activeHandleElement = qobject_cast<SizeHandleElement*>(sender());
40  ASSERT(m_activeHandleElement);
41  SizeHandleElement::EHandleLocation oposite_corner =
43  m_resize_opposite_origin = m_resize_handles[oposite_corner]->scenePos();
44  } else {
45  setFlag(QGraphicsItem::ItemIsMovable, true);
46  m_activeHandleElement = nullptr;
47  }
48 }
QPointF m_resize_opposite_origin
EHandleLocation getOppositeHandleLocation() const

References SizeHandleElement::getOppositeHandleLocation(), m_activeHandleElement, m_resize_handles, and m_resize_opposite_origin.

Referenced by create_size_handle_elements(), and mouseReleaseEvent().

Here is the call graph for this function:

◆ paint()

void IShape2DView::paint ( QPainter *  painter,
const QStyleOptionGraphicsItem *  ,
QWidget *   
)
overrideprotectedinherited

Definition at line 70 of file IShape2DView.cpp.

71 {
72  const bool isMasked = itemMaskValue(parameterizedItem());
73  painter->setBrush(MaskEditorHelper::getMaskBrush(isMasked));
74  painter->setPen(MaskEditorHelper::getMaskPen(isMasked));
75  painter->setRenderHints(QPainter::Antialiasing);
76  painter->drawPath(maskedShape());
77 }
QPainterPath maskedShape() const
Returns the shape with all masking already applied.
static QBrush getMaskBrush(bool mask_value)
static QPen getMaskPen(bool mask_value)

References MaskEditorHelper::getMaskBrush(), MaskEditorHelper::getMaskPen(), IShape2DView::maskedShape(), and IShape2DView::parameterizedItem().

Referenced by PolygonView::paint().

Here is the call graph for this function:

◆ parameterizedItem()

◆ right()

virtual qreal RectangleBaseView::right ( ) const
protectedpure virtual

Implemented in RectangleView, and EllipseView.

Referenced by width().

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

◆ top()

virtual qreal RectangleBaseView::top ( ) const
protectedpure virtual

Implemented in RectangleView, and EllipseView.

Referenced by height().

◆ 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 RectangleBaseView::type ( ) const
inlineoverride

Definition at line 28 of file RectangleBaseView.h.

References MaskEditorHelper::RECTANGLEBASE.

Referenced by update_bounding_rect().

◆ update_bounding_rect()

void RectangleBaseView::update_bounding_rect ( )
protectedvirtual

updates view's bounding rectangle using item properties

Definition at line 76 of file RectangleBaseView.cpp.

77 {
78  if (parameterizedItem()) {
81  m_bounding_rect = m_mask_rect.marginsAdded(
82  QMarginsF(bbox_margins, bbox_margins, bbox_margins, bbox_margins));
83  }
84  for (QMap<SizeHandleElement::EHandleLocation, SizeHandleElement*>::iterator it =
85  m_resize_handles.begin();
86  it != m_resize_handles.end(); ++it) {
87  it.value()->updateHandleElementPosition(m_mask_rect);
88  }
89 }
virtual QRectF mask_rectangle()=0
QRectF m_mask_rect
mask rectangle in scene coordinates
int type() const override

References IShape2DView::m_bounding_rect, m_mask_rect, m_resize_handles, mask_rectangle(), IShape2DView::parameterizedItem(), MaskEditorHelper::REGIONOFINTEREST, and type().

Referenced by update_view().

Here is the call graph for this function:

◆ update_position()

virtual void RectangleBaseView::update_position ( )
protectedpure virtual

Implemented in RectangleView, and EllipseView.

Referenced by update_view().

◆ update_view()

void RectangleBaseView::update_view ( )
overrideprotectedvirtual

update visual appearance of view (triggered by ISceneAdaptor)

Implements IShape2DView.

Definition at line 67 of file RectangleBaseView.cpp.

68 {
69  prepareGeometryChange();
72 }
virtual void update_position()=0
virtual void update_bounding_rect()
updates view's bounding rectangle using item properties

References update_bounding_rect(), and update_position().

Referenced by RectangleView::mouseMoveEvent(), EllipseView::onPropertyChange(), RectangleView::onPropertyChange(), and RegionOfInterestView::update_view().

Here is the call graph for this function:

◆ width()

qreal RectangleBaseView::width ( ) const
protected

Returns width of the rectangle.

Definition at line 93 of file RectangleBaseView.cpp.

94 {
95  return right() - left();
96 }
virtual qreal right() const =0
virtual qreal left() const =0

References left(), and right().

Referenced by EllipseView::mask_rectangle(), RectangleView::mask_rectangle(), and EllipseView::mouseMoveEvent().

Here is the call graph for this function:

Member Data Documentation

◆ m_activeHandleElement

SizeHandleElement* RectangleBaseView::m_activeHandleElement
protected

◆ m_adaptor

◆ m_block_on_property_change

bool IShape2DView::m_block_on_property_change
protectedinherited

◆ m_bounding_rect

◆ m_mask_rect

QRectF RectangleBaseView::m_mask_rect
protected

◆ m_resize_handles

QMap<SizeHandleElement::EHandleLocation, SizeHandleElement*> RectangleBaseView::m_resize_handles
protected

coordinates of corner opposite to the grip corner at the moment it first clicked in scene coordinates

Definition at line 53 of file RectangleBaseView.h.

Referenced by create_size_handle_elements(), itemChange(), onSizeHandleElementRequest(), and update_bounding_rect().

◆ m_resize_opposite_origin

QPointF RectangleBaseView::m_resize_opposite_origin
protected

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