Arrow
*PhysGraphicsView
::createVector(QPointF StartPt,
QPointF EndPt, PhysParticle
*pStartItem, PhysParticle
*pEndItem
) { Arrow *pArrow = new Arrow(StartPt, EndPt);
pArrow ->startItem(pStartItem);
if (pStartItem) {
pStartItem ->addArrow(pArrow);
pArrow ->startItem(pStartItem);
}
if (pStartItem != pEndItem && pEndItem) {
pEndItem ->addArrow(pArrow);
pArrow ->endItem(pEndItem); // <---- this causes it to crash
}
pArrow ->setColor(m_LineColor);
pArrow ->setZValue(-1000.0);
m_pScene ->addItem(pArrow);
pArrow ->updatePosition();
return pArrow;
}
// partial class definition for Arrow:
public:
enum { Type = PhysBaseItem::VectorType };
int type() const { return Type; }
void setColor
(const QColor &color
) { m_Color
= color;
} PhysParticle *startItem() const { return m_pStartItem; }
PhysParticle *endItem() const { return m_pEndItem; }
void startItem(PhysParticle *pStartItem) { m_pStartItem = pStartItem; }
void endItem(PhysParticle *pEndItem) { m_pEndItem = pEndItem; }
private:
PhysParticle *m_pStartItem, *m_pEndItem;
Arrow *PhysGraphicsView::createVector(QPointF StartPt, QPointF EndPt, PhysParticle *pStartItem, PhysParticle *pEndItem) {
Arrow *pArrow = new Arrow(StartPt, EndPt);
pArrow ->startItem(pStartItem);
if (pStartItem) {
pStartItem ->addArrow(pArrow);
pArrow ->startItem(pStartItem);
}
if (pStartItem != pEndItem && pEndItem) {
pEndItem ->addArrow(pArrow);
pArrow ->endItem(pEndItem); // <---- this causes it to crash
}
pArrow ->setColor(m_LineColor);
pArrow ->setZValue(-1000.0);
m_pScene ->addItem(pArrow);
pArrow ->updatePosition();
return pArrow;
}
// partial class definition for Arrow:
class Arrow : public QGraphicsLineItem, PhysBaseItem {
public:
enum { Type = PhysBaseItem::VectorType };
Arrow(PhysParticle *, PhysParticle *, QGraphicsItem * = NULL);
Arrow(QPointF, QPointF, QGraphicsItem * = NULL);
Arrow(QPointF, QPointF, PhysParticle *, PhysParticle *, QGraphicsItem * = NULL);
int type() const { return Type; }
QRectF boundingRect() const;
void setColor(const QColor &color) { m_Color = color; }
PhysParticle *startItem() const { return m_pStartItem; }
PhysParticle *endItem() const { return m_pEndItem; }
void startItem(PhysParticle *pStartItem) { m_pStartItem = pStartItem; }
void endItem(PhysParticle *pEndItem) { m_pEndItem = pEndItem; }
private:
PhysParticle *m_pStartItem, *m_pEndItem;
To copy to clipboard, switch view to plain text mode
Bookmarks