COPASI API  4.16.103
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
CQConnectionGraphicsItem Class Reference

#include <CQConnectionGraphicsItem.h>

Inheritance diagram for CQConnectionGraphicsItem:
Inheritance graph
[legend]
Collaboration diagram for CQConnectionGraphicsItem:
Collaboration graph
[legend]

Public Member Functions

 CQConnectionGraphicsItem (const CLGlyphWithCurve *glyph, const CLRenderResolver *resolver=NULL)
 
virtual ~CQConnectionGraphicsItem ()
 
- Public Member Functions inherited from CQCopasiGraphicsItem
 CQCopasiGraphicsItem (const CLRenderResolver *resolver, const CLStyle *style)
 
const CLRenderResolvergetResolver () const
 
const CLStylegetStyle () const
 
void setResolver (const CLRenderResolver *resolver)
 
void setStyle (const CLStyle *style)
 
virtual ~CQCopasiGraphicsItem ()
 

Static Public Member Functions

static QSharedPointer
< QPainterPath > 
getPath (const CLCurve &curve)
 

Protected Member Functions

virtual QVariant itemChange (GraphicsItemChange change, const QVariant &value)
 
void mouseReleaseEvent (QGraphicsSceneMouseEvent *event)
 
virtual void paint (QPainter *painter, const QStyleOptionGraphicsItem *option=new QStyleOptionGraphicsItem(), QWidget *widget=0)
 

Protected Attributes

bool mWasMoved
 
- Protected Attributes inherited from CQCopasiGraphicsItem
const CLRenderResolvermpResolver
 
const CLStylempStyle
 

Detailed Description

Definition at line 18 of file CQConnectionGraphicsItem.h.

Constructor & Destructor Documentation

CQConnectionGraphicsItem::CQConnectionGraphicsItem ( const CLGlyphWithCurve glyph,
const CLRenderResolver resolver = NULL 
)

Definition at line 82 of file CQConnectionGraphicsItem.cpp.

References CQRenderConverter::applyStyle(), CCopasiVector< T >::begin(), COPASI_LAYOUT_KEY, CCopasiVector< T >::end(), CQRenderConverter::fillGroupFromStyle(), CLGraphicalObject::getBoundingBox(), CLGlyphWithCurve::getCurve(), CLStyle::getGroup(), CLGraphicalObject::getKey(), CLReactionGlyph::getListOfMetabReferenceGlyphs(), CLGeneralGlyph::getListOfReferenceGlyphs(), CLCurve::getNumCurveSegments(), getPath(), CQCopasiGraphicsItem::mpStyle, and CLRenderResolver::resolveStyle().

83  : CQCopasiGraphicsItem(resolver, resolver != NULL ? resolver->resolveStyle(curveGlyph) : NULL)
84  , mWasMoved(false)
85 {
86  setFlag(QGraphicsItem::ItemIsMovable);
87  setFlag(QGraphicsItem::ItemSendsGeometryChanges);
88  setData(COPASI_LAYOUT_KEY, QString(curveGlyph->getKey().c_str()));
89 
90  QSharedPointer<QPainterPath> path = getPath(curveGlyph->getCurve());
91  QGraphicsPathItem* item;
92  QGraphicsItemGroup* itemGroup;
93 
94  if (curveGlyph->getCurve().getNumCurveSegments() > 0)
95  {
96  item = new QGraphicsPathItem(*path);
97  itemGroup = new QGraphicsItemGroup();
98  itemGroup->addToGroup(item);
99 
100  if (mpStyle != NULL)
101  CQRenderConverter::applyStyle(item, &curveGlyph->getBoundingBox(), mpStyle->getGroup(), resolver, itemGroup);
102 
103  addToGroup(itemGroup);
104  }
105 
106  const CLReactionGlyph* reaction = dynamic_cast<const CLReactionGlyph*>(curveGlyph);
107 
108  if (reaction != NULL)
109  {
111 
112  for (CCopasiVector<CLMetabReferenceGlyph>::const_iterator it = list.begin(); it != list.end(); ++it)
113  {
114  const CLMetabReferenceGlyph* metab = *it;
115  const CLStyle *style = resolver->resolveStyle(metab);
116 
117  if (metab->getCurve().getNumCurveSegments() > 0)
118  {
119  path = getPath(metab->getCurve());
120  item = new QGraphicsPathItem(*path);
121  itemGroup = new QGraphicsItemGroup();
122  itemGroup->addToGroup(item);
123  CQRenderConverter::applyStyle(item, &metab->getBoundingBox(), style == NULL ?
124  mpStyle == NULL ? NULL : mpStyle->getGroup()
125  : style->getGroup(), resolver, itemGroup);
126  addToGroup(itemGroup);
127  }
128  }
129  }
130 
131  const CLGeneralGlyph* general = dynamic_cast<const CLGeneralGlyph*>(curveGlyph);
132 
133  if (general != NULL)
134  {
136 
137  for (CCopasiVector<CLReferenceGlyph>::const_iterator it = list.begin(); it != list.end(); ++it)
138  {
139  const CLReferenceGlyph* glyph = *it;
140  const CLStyle *style = resolver->resolveStyle(glyph);
141 
142  if (glyph ->getCurve().getNumCurveSegments() > 0)
143  {
144  path = getPath(glyph ->getCurve());
145  item = new QGraphicsPathItem(*path);
146  itemGroup = new QGraphicsItemGroup();
147  itemGroup->addToGroup(item);
148  CQRenderConverter::applyStyle(item, &glyph ->getBoundingBox(), style == NULL ?
149  mpStyle == NULL ? NULL : mpStyle->getGroup()
150  : style->getGroup(), resolver, itemGroup);
151  addToGroup(itemGroup);
152  }
153  }
154  }
155 
156  // add decorations on reactions
157  itemGroup = new QGraphicsItemGroup();
158  CQRenderConverter::fillGroupFromStyle(itemGroup, &curveGlyph->getBoundingBox(), mpStyle, resolver);
159 
160  if (itemGroup->childItems().size() > 0)
161  addToGroup(itemGroup);
162  else
163  delete itemGroup;
164 }
#define COPASI_LAYOUT_KEY
const CLBoundingBox & getBoundingBox() const
static QSharedPointer< QPainterPath > getPath(const CLCurve &curve)
const CLStyle * resolveStyle(const CLGraphicalObject *pObject) const
iterator begin()
static void fillGroupFromStyle(QGraphicsItemGroup *group, const CLBoundingBox *bounds, const CLStyle *style, const CLRenderResolver *resolver)
iterator end()
const CLGroup * getGroup() const
Definition: CLStyle.cpp:91
static void applyStyle(QGraphicsTextItem *item, const CLBoundingBox *bounds, const CLGroup *style, const CLRenderResolver *resolver)
const CCopasiVector< CLReferenceGlyph > & getListOfReferenceGlyphs() const
CQCopasiGraphicsItem(const CLRenderResolver *resolver, const CLStyle *style)
const CCopasiVector< CLMetabReferenceGlyph > & getListOfMetabReferenceGlyphs() const
const CLCurve & getCurve() const
size_t getNumCurveSegments() const
Definition: CLCurve.h:168
CQConnectionGraphicsItem::~CQConnectionGraphicsItem ( )
virtual

Definition at line 166 of file CQConnectionGraphicsItem.cpp.

167 {
168 }

Member Function Documentation

QSharedPointer< QPainterPath > CQConnectionGraphicsItem::getPath ( const CLCurve curve)
static

Definition at line 16 of file CQConnectionGraphicsItem.cpp.

References CLLineSegment::getBase1(), CLLineSegment::getBase2(), CLLineSegment::getEnd(), CLCurve::getNumCurveSegments(), CLCurve::getSegmentAt(), CLLineSegment::getStart(), CLPoint::getX(), CLPoint::getY(), and CLLineSegment::isBezier().

Referenced by CQConnectionGraphicsItem().

17 {
18  QSharedPointer<QPainterPath> result = QSharedPointer<QPainterPath>(new QPainterPath());
19 
20  for (size_t i = 0; i < curve.getNumCurveSegments(); ++i)
21  {
22  const CLLineSegment* segment = curve.getSegmentAt(i);
23  QPainterPath path = QPainterPath(
24  QPointF(
25  segment->getStart().getX(),
26  segment->getStart().getY()));
27 
28  if (segment->isBezier())
29  {
30  path.cubicTo(
31  segment->getBase1().getX(), segment->getBase1().getY(),
32  segment->getBase2().getX(), segment->getBase2().getY(),
33  segment->getEnd().getX(), segment->getEnd().getY()
34  );
35  }
36  else
37  {
38  path.lineTo(segment->getEnd().getX(), segment->getEnd().getY());
39  }
40 
41  result->addPath(path);
42  }
43 
44  return result;
45 }
const CLPoint & getBase1() const
Definition: CLCurve.h:82
const CLPoint & getBase2() const
Definition: CLCurve.h:83
const CLPoint & getEnd() const
Definition: CLCurve.h:75
const C_FLOAT64 & getX() const
Definition: CLBase.h:83
const C_FLOAT64 & getY() const
Definition: CLBase.h:84
bool isBezier() const
Definition: CLCurve.h:90
const CLLineSegment * getSegmentAt(size_t i) const
Definition: CLCurve.h:156
size_t getNumCurveSegments() const
Definition: CLCurve.h:168
const CLPoint & getStart() const
Definition: CLCurve.h:74
QVariant CQConnectionGraphicsItem::itemChange ( GraphicsItemChange  change,
const QVariant &  value 
)
protectedvirtual

Definition at line 70 of file CQConnectionGraphicsItem.cpp.

References mWasMoved.

71 {
72  CQLayoutScene * currentScene = dynamic_cast<CQLayoutScene *>(scene());
73 
74  if (change == ItemPositionHasChanged && currentScene)
75  {
76  mWasMoved = true;
77  }
78 
79  return QGraphicsItem::itemChange(change, value);
80 }
void CQConnectionGraphicsItem::mouseReleaseEvent ( QGraphicsSceneMouseEvent *  event)
protected

Definition at line 54 of file CQConnectionGraphicsItem.cpp.

References COPASI_LAYOUT_KEY, mWasMoved, and CQLayoutScene::updatePosition().

55 {
56  CQLayoutScene * currentScene = dynamic_cast<CQLayoutScene *>(scene());
57 
58  if (mWasMoved && currentScene)
59  {
60  QPointF currentPos = pos();
61  currentScene->updatePosition(data(COPASI_LAYOUT_KEY).toString(), currentPos);
62  mWasMoved = false;
63  }
64  else
65  {
66  QGraphicsItem::mouseReleaseEvent(event);
67  }
68 }
#define COPASI_LAYOUT_KEY
void updatePosition(const QString &key, const QPointF &newPos)
void CQConnectionGraphicsItem::paint ( QPainter *  painter,
const QStyleOptionGraphicsItem *  option = new QStyleOptionGraphicsItem(),
QWidget *  widget = 0 
)
protectedvirtual

Definition at line 47 of file CQConnectionGraphicsItem.cpp.

48 {
49  painter->save();
50  QGraphicsItemGroup::paint(painter, option, widget);
51  painter->restore();
52 }

Member Data Documentation

bool CQConnectionGraphicsItem::mWasMoved
protected

Definition at line 31 of file CQConnectionGraphicsItem.h.

Referenced by itemChange(), and mouseReleaseEvent().


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