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

Description

Main interface class for views representing MaskItems, Projections on graphics scene.

Definition at line 27 of file IShape2DView.h.

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

Public Member Functions

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 ()
 
virtual void update_view ()=0
 update visual appearance of view (triggered by ISceneAdaptor) More...
 

Protected Member Functions

 IShape2DView (SessionItem *item)
 
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
 
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

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

Constructor & Destructor Documentation

◆ IShape2DView()

IShape2DView::IShape2DView ( SessionItem item)
explicitprotected

Definition at line 35 of file IShape2DView.cpp.

36  : m_adaptor(nullptr)
38 {
39  connect(this, &IShape2DView::xChanged, this, &IShape2DView::onChangedX);
40  connect(this, &IShape2DView::yChanged, this, &IShape2DView::onChangedY);
41 
42  if (item) {
43  item->mapper()->setOnPropertyChange(
44  [this](const QString& name) { onItemPropertyChange(name); }, this);
45 
46  item->mapper()->setOnItemDestroy([this](SessionItem*) { onItemDestroyed(); }, this);
47  }
48 }
virtual void onItemDestroyed()=0
virtual void onChangedX()
Definition: IShape2DView.h:44
const ISceneAdaptor * m_adaptor
Definition: IShape2DView.h:67
void onItemPropertyChange(const QString &propertyName)
virtual void onChangedY()
Definition: IShape2DView.h:45
bool m_block_on_property_change
Definition: IShape2DView.h:69
void setOnItemDestroy(std::function< void(SessionItem *)> f, const void *caller=nullptr)
Definition: ModelMapper.cpp:67
void setOnPropertyChange(std::function< void(QString)> f, const void *caller=nullptr)
Definition: ModelMapper.cpp:39
Base class for a GUI data item.
Definition: SessionItem.h:204
ModelMapper * mapper()
Returns the current model mapper of this item. Creates new one if necessary.
QString const & name(EShape k)
Definition: particles.cpp:20

References SessionItem::mapper(), GUI::RealSpace::Particles::name(), onChangedX(), onChangedY(), onItemDestroyed(), onItemPropertyChange(), ModelMapper::setOnItemDestroy(), and ModelMapper::setOnPropertyChange().

Here is the call graph for this function:

Member Function Documentation

◆ addView()

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

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
protected

Definition at line 140 of file IShape2DView.cpp.

141 {
143 }

References m_block_on_property_change.

◆ boundingRect()

QRectF IShape2DView::boundingRect ( ) const
override

Definition at line 50 of file IShape2DView.cpp.

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

References m_bounding_rect.

◆ disconnectFromItem()

void IShape2DView::disconnectFromItem ( SessionItem item)
protected

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

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
protected

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

References ISceneAdaptor::fromSceneX(), and 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
protected

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

◆ maskedShape()

QPainterPath IShape2DView::maskedShape ( ) const
protected

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

◆ onChangedX

virtual void IShape2DView::onChangedX ( )
inlineprotectedvirtualslot

Definition at line 44 of file IShape2DView.h.

44 {}

Referenced by IShape2DView().

◆ onChangedY

virtual void IShape2DView::onChangedY ( )
inlineprotectedvirtualslot

Definition at line 45 of file IShape2DView.h.

45 {}

Referenced by IShape2DView().

◆ onItemDestroyed()

virtual void IShape2DView::onItemDestroyed ( )
privatepure virtual

◆ onItemPropertyChange()

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

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(), m_block_on_property_change, onPropertyChange(), and parameterizedItem().

Referenced by IShape2DView().

Here is the call graph for this function:

◆ onPropertyChange

virtual void IShape2DView::onPropertyChange ( )
inlineprotectedvirtualslot

Definition at line 46 of file IShape2DView.h.

46 {}

Referenced by onItemPropertyChange().

◆ paint()

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

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(), maskedShape(), and parameterizedItem().

Referenced by PolygonView::paint().

Here is the call graph for this function:

◆ parameterizedItem()

◆ setBlockOnProperty()

void IShape2DView::setBlockOnProperty ( bool  value)
protected

◆ setSceneAdaptor()

void IShape2DView::setSceneAdaptor ( const ISceneAdaptor adaptor)

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 m_adaptor, ISceneAdaptor::update_request(), and update_view().

Referenced by MaskViewFactory::createMaskView().

Here is the call graph for this function:

◆ toSceneX()

qreal IShape2DView::toSceneX ( qreal  value) const
protected

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 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
protected

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

Definition at line 31 of file IShape2DView.h.

References MaskEditorHelper::IMASKVIEW.

◆ update_view

virtual void IShape2DView::update_view ( )
protectedpure virtualslot

update visual appearance of view (triggered by ISceneAdaptor)

Implemented in RectangleBaseView.

Referenced by setSceneAdaptor().

Member Data Documentation

◆ m_adaptor

◆ m_block_on_property_change

bool IShape2DView::m_block_on_property_change
protected

Definition at line 69 of file IShape2DView.h.

Referenced by blockOnProperty(), onItemPropertyChange(), and setBlockOnProperty().

◆ m_bounding_rect


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