Changeset 8705:ac7fd26be663 in orange


Ignore:
Timestamp:
08/14/11 15:46:22 (3 years ago)
Author:
Noughmad <Noughmad@…>
Branch:
default
Convert:
a5fb3d45717577400689b65a54b5207ee45dfecb
Message:

Make EdgeItem always draw a line between its two nodes, instead of storing a line and updating it.

Location:
source/orangeqt
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • source/orangeqt/networkcurve.cpp

    r8700 r8705  
    177177/************/ 
    178178 
    179 EdgeItem::EdgeItem(NodeItem* u, NodeItem* v, QGraphicsItem* parent, QGraphicsScene* scene): QGraphicsLineItem(parent, scene), 
     179EdgeItem::EdgeItem(NodeItem* u, NodeItem* v, QGraphicsItem* parent, QGraphicsScene* scene): QAbstractGraphicsShapeItem(parent, scene), 
    180180m_u(0), m_v(0) 
    181181{ 
     
    205205{ 
    206206    painter->setRenderHint(QPainter::Antialiasing, false); 
    207     QGraphicsLineItem::paint(painter, option, widget); 
    208  
     207        painter->setPen(pen()); 
     208        QLineF _line; 
     209        if (m_u && m_v) 
     210        { 
     211            _line.setPoints(m_u->pos(), m_v->pos()); 
     212            painter->drawLine(_line); 
     213        } 
     214         
    209215    if (!m_label.isEmpty()) 
    210216    { 
     
    215221        if(!on_marked_only || (on_marked_only && is_marked)) 
    216222        { 
    217             QLineF _line = line(); 
    218223            double x = (_line.x1() + _line.x2()) / 2; 
    219224            double y = (_line.y1() + _line.y2()) / 2; 
     
    231236} 
    232237 
     238QRectF EdgeItem::boundingRect() const 
     239{ 
     240    return QRectF(m_u->pos(), m_v->pos()); 
     241} 
     242 
     243QPainterPath EdgeItem::shape() const 
     244{ 
     245    QPainterPath path; 
     246    path.moveTo(m_u->pos()); 
     247    path.lineTo(m_v->pos()); 
     248    return path; 
     249} 
    233250 
    234251void EdgeItem::set_u(NodeItem* item) 
     
    349366    const QTransform t = graph_transform(); 
    350367    update_point_positions(); 
    351     update_items(m_edges, EdgeUpdater(t), UpdatePen); 
    352368} 
    353369 
  • source/orangeqt/networkcurve.h

    r8697 r8705  
    133133}; 
    134134 
    135 class EdgeItem : public QGraphicsLineItem 
     135class EdgeItem : public QAbstractGraphicsShapeItem 
    136136{ 
    137137public: 
     
    147147 
    148148    virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0); 
     149    virtual QRectF boundingRect() const; 
     150    virtual QPainterPath shape() const; 
    149151 
    150152    void set_u(NodeItem* item); 
     
    176178}; 
    177179 
    178 class EdgeUpdater 
    179 { 
    180 public: 
    181     EdgeUpdater(const QTransform& t) : m_t(t) {} 
    182     void operator()(EdgeItem* item) 
    183     { 
    184         NodeItem *u = item->u(); 
    185         NodeItem *v = item->v(); 
    186  
    187         if (u && v) 
    188         { 
    189             item->setLine(QLineF(u->x(), u->y(), v->x(), v->y()) * m_t); 
    190         } 
    191     } 
    192 private: 
    193     QTransform m_t; 
    194 }; 
    195  
    196180class NetworkCurve : public Curve 
    197181{ 
  • source/orangeqt/networkcurve.sip

    r8697 r8705  
    3434}; 
    3535 
    36 class EdgeItem : QGraphicsLineItem 
     36class EdgeItem : QAbstractGraphicsShapeItem 
    3737{ 
    3838public: 
     
    4848     
    4949    virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0); 
     50    virtual QRectF boundingRect() const; 
     51    virtual QPainterPath shape() const; 
    5052     
    5153    void set_u(NodeItem* item); 
Note: See TracChangeset for help on using the changeset viewer.