Changeset 8695:57256d6efd56 in orange


Ignore:
Timestamp:
08/14/11 10:03:47 (3 years ago)
Author:
Noughmad <Noughmad@…>
Branch:
default
Convert:
1999c80ce209acc769806d4bec44b7795d4fd687
Message:

Asynchronous calculations in UnconnectedLinesCurve

Location:
source/orangeqt
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • source/orangeqt/Makefile

    r8680 r8695  
    77all: 
    88    mkdir -p $(ORANGEPLOT_BUILD_DIR) 
    9     cd $(ORANGEPLOT_BUILD_DIR); cmake -DCMAKE_BUILD_TYPE=Release -DORANGE_LIB_DIR=$(abspath $(OLD)) .. 
     9    cd $(ORANGEPLOT_BUILD_DIR); cmake -DCMAKE_BUILD_TYPE=Debug -DORANGE_LIB_DIR=$(abspath $(OLD)) .. 
    1010    if ! $(MAKE) $@ -C $(ORANGEPLOT_BUILD_DIR); then exit 1; fi; 
    1111 
  • source/orangeqt/curve.cpp

    r8694 r8695  
    7474    return; 
    7575  } 
    76   int n = m_data.size(); 
    77   int m = m_pointItems.size(); 
    78   if (m > n) 
    79   { 
    80       qDebug() << "Deleting" << (m-n) << "points"; 
    81     qDeleteAll(m_pointItems.constBegin() + n, m_pointItems.constEnd()); 
    82     m_pointItems.erase(m_pointItems.begin() + n, m_pointItems.end()); 
    83   } 
    84   else if (m < n) 
    85   {   
    86     qDebug() << "Creating" << (n-m) << "points"; 
    87     m_pointItems.reserve(n); 
    88     Plot* p = plot(); 
    89     int delta = n - m; 
    90     if (p && delta > 500) 
    91     { 
    92         int update_every = qMax(5, delta / 100); 
    93         p->start_progress(); 
    94         for (int i = 0; i < delta; ++i) 
    95         { 
    96             m_pointItems << new Point(m_symbol, m_color, m_pointSize, this); 
    97          
    98             if (i % update_every == 0) 
    99             { 
    100                 qApp->processEvents(); 
    101                 p->set_progress(i, delta); 
    102             } 
    103         } 
    104         p->end_progress(); 
    105         qApp->processEvents(); 
    106     } 
    107     else 
    108     { 
    109       for (int i = 0; i < delta; ++i) 
    110       { 
    111         m_pointItems << new Point(m_symbol, m_color, m_pointSize, this); 
    112       } 
    113     } 
    114   } 
     76  resize_item_list<Point>(m_pointItems, m_data.size()); 
    11577  Q_ASSERT(m_pointItems.size() == m_data.size()); 
    11678} 
     
    11880void Curve::update_properties() 
    11981{ 
     82  cancelAllUpdates(); 
    12083  set_continuous(m_style != Curve::NoCurve); 
    12184   
     
    158121  if (m_needsUpdate & UpdatePosition) 
    159122  { 
    160     cancelAllUpdates(); 
    161123    update_point_coordinates(); 
    162124  }  
     
    482444        return; 
    483445    } 
    484     QParallelAnimationGroup* group = new QParallelAnimationGroup; 
     446    QParallelAnimationGroup* group = new QParallelAnimationGroup(this); 
    485447    int n = m_pointItems.size(); 
    486448    for (int i = 0; i < n; ++i) 
    487449    { 
    488         QPropertyAnimation* a = new QPropertyAnimation(m_pointItems[i], "pos"); 
     450        QPropertyAnimation* a = new QPropertyAnimation(m_pointItems[i], "pos", m_pointItems[i]); 
    489451        a->setEndValue(m_pos_watcher.resultAt(i)); 
    490452        group->addAnimation(a); 
     
    497459    return plot() && plot()->animate_points; 
    498460} 
     461 
    499462void Curve::update_point_properties_same(const QByteArray& property, const QVariant& value) { 
    500463    int n = m_pointItems.size(); 
  • source/orangeqt/curve.h

    r8694 r8695  
    205205   
    206206  void update_point_properties_same(const QByteArray& property, const QVariant& value); 
     207   
     208  template <class T> 
     209  void resize_item_list(QList< T* >& list, int size); 
    207210 
    208211  void set_points(const QList<Point*>& points); 
     
    316319} 
    317320 
     321template <class T> 
     322void Curve::resize_item_list(QList< T* >& list, int size) 
     323{ 
     324    int n = list.size();   
     325    if (n > size) 
     326  { 
     327    qDeleteAll(list.constBegin() + size, list.constEnd()); 
     328    list.erase(list.begin() + size, list.end()); 
     329  } 
     330  else if (n < size) 
     331  {   
     332    list.reserve(size); 
     333    for (int i = 0; i < (size-n); ++i) 
     334    { 
     335      list << new T(this); 
     336    } 
     337  } 
     338} 
     339 
     340 
    318341Q_DECLARE_OPERATORS_FOR_FLAGS(Curve::UpdateFlags) 
    319342 
  • source/orangeqt/plotitem.cpp

    r8680 r8695  
    2929    m_plot(0) 
    3030{ 
     31    // Most items have no paint() method, the drawing is done by their children 
     32    setFlag(ItemHasNoContents, true); 
     33     
    3134    set_axes(xBottom, yLeft); 
    3235    set_auto_scale(true); 
     
    133136void PlotItem::move_item(QGraphicsObject* item, const QPointF& pos, bool animate, int duration) 
    134137{ 
    135     QPropertyAnimation* a = new QPropertyAnimation(); 
    136     a->setTargetObject(item); 
    137     a->setPropertyName("pos"); 
    138     a->setStartValue(item->pos()); 
     138    QPropertyAnimation* a = new QPropertyAnimation(item, "pos", item); 
    139139    a->setEndValue(pos); 
    140140    a->setDuration(duration); 
  • source/orangeqt/point.cpp

    r8694 r8695  
    5656} 
    5757 
    58 DataPoint::operator QPointF() 
     58DataPoint::operator QPointF() const 
    5959{ 
    6060    return QPointF(x, y); 
  • source/orangeqt/point.h

    r8694 r8695  
    2929  double y; 
    3030   
    31   operator QPointF(); 
     31  operator QPointF() const; 
    3232}; 
    3333 
  • source/orangeqt/unconnectedlinescurve.cpp

    r8680 r8695  
    2121#include <QtCore/QDebug> 
    2222 
    23 UnconnectedLinesCurve::UnconnectedLinesCurve(const QList< double >& x_data, const QList< double >& y_data, QGraphicsItem* parent): Curve(parent) 
     23struct PointMapper 
     24{ 
     25    typedef QPointF result_type; 
     26    PointMapper(const QTransform& t) : t(t) {} 
     27     
     28    QPointF operator()(const DataPoint& p) 
     29    { 
     30        return t.map(p); 
     31    } 
     32     
     33    QTransform t; 
     34}; 
     35 
     36struct PathReducer 
     37{ 
     38    PathReducer() : closed(true) {} 
     39    void operator()(QPainterPath& path, const QPointF point) 
     40    { 
     41        if (closed) 
     42        { 
     43            path.moveTo(point); 
     44        } 
     45        else 
     46        { 
     47            path.lineTo(point); 
     48        } 
     49        closed = !closed; 
     50    } 
     51     
     52    bool closed; 
     53}; 
     54 
     55UnconnectedLinesCurve::UnconnectedLinesCurve(QGraphicsItem* parent): Curve(parent) 
    2456{ 
    2557    m_path_item = new QGraphicsPathItem(this); 
    26     set_data(x_data, y_data); 
     58    m_path_watcher = new QFutureWatcher<QPainterPath>(this); 
     59    connect(m_path_watcher, SIGNAL(finished()), SLOT(path_calculated())); 
     60    setFlag(ItemHasNoContents); 
    2761} 
    2862 
     
    3771    if (needs_update() & UpdatePosition) 
    3872    { 
    39         const Data d = data(); 
    40         const int n = d.size(); 
    41         QPainterPath path; 
    42         for (int i = 0; i < n; ++i) 
    43         { 
    44             path.moveTo(d[i].x, d[i].y); 
    45             ++i; 
    46             path.lineTo(d[i].x, d[i].y); 
    47         } 
    48         m_path_item->setPath(graph_transform().map(path)); 
     73        m_path_watcher->setFuture(QtConcurrent::mappedReduced<QPainterPath>(data(), PointMapper(graph_transform()), PathReducer(), QtConcurrent::OrderedReduce | QtConcurrent::SequentialReduce)); 
    4974    } 
    5075    if (needs_update() & UpdatePen) 
     
    5681    set_updated(Curve::UpdateAll); 
    5782} 
     83 
     84void UnconnectedLinesCurve::path_calculated() 
     85{ 
     86    m_path_item->setPath(m_path_watcher->result()); 
     87} 
     88 
     89#include "unconnectedlinescurve.moc" 
  • source/orangeqt/unconnectedlinescurve.h

    r8680 r8695  
    2424class UnconnectedLinesCurve : public Curve 
    2525{ 
    26  
     26    Q_OBJECT 
     27     
    2728public: 
    28     UnconnectedLinesCurve(const QList< double >& x_data, const QList< double >& y_data, QGraphicsItem* parent = 0); 
     29    UnconnectedLinesCurve(QGraphicsItem* parent = 0); 
    2930    virtual ~UnconnectedLinesCurve(); 
    3031     
    31     virtual void update_properties(); 
     32    virtual void update_properties();     
    3233     
    33 private: 
    34      QGraphicsPathItem* m_path_item; 
     34private:     
     35    QGraphicsPathItem* m_path_item; 
     36    QFutureWatcher< QPainterPath >* m_path_watcher; 
     37     
     38public slots: 
     39    void path_calculated(); 
    3540}; 
    3641 
  • source/orangeqt/unconnectedlinescurve.sip

    r8680 r8695  
    66 
    77public: 
    8     UnconnectedLinesCurve(const QList< double >& x_data, const QList< double >& y_data, QGraphicsItem* parent /TransferThis/ = 0); 
     8    UnconnectedLinesCurve(QGraphicsItem* parent /TransferThis/ = 0); 
    99    virtual ~UnconnectedLinesCurve(); 
    1010     
Note: See TracChangeset for help on using the changeset viewer.