Changeset 8680:59826618a121 in orange


Ignore:
Timestamp:
08/12/11 19:45:08 (3 years ago)
Author:
Noughmad <Noughmad@…>
Branch:
default
Convert:
c63984274dd6c65651fb1ffe5186555a8fff1f96
Message:

Make points in Curve, NetworkCurve and MultiCurve animated.

Files:
20 edited

Legend:

Unmodified
Added
Removed
  • orange/OrangeWidgets/Prototypes/OWScatterPlotGraphQt.py

    r8674 r8680  
    5757    # update shown data. Set labels, coloring by className .... 
    5858    def updateData(self, xAttr, yAttr, colorAttr, shapeAttr = "", sizeShapeAttr = "", labelAttr = None, **args): 
    59         self.clear() 
    60         qDebug('Updating with data %s and subset %s' % (self.rawData, self.rawSubsetData)) 
     59        self.legend().clear() 
    6160        self.tooltipData = [] 
    6261        self.potentialsClassifier = None 
  • source/orangeqt/CMakeLists.txt

    r8673 r8680  
    5050endif() 
    5151 
    52 message(${ORANGE_LIB_DIR}) 
     52get_target_property(PYTHON_LIB_LOCATION python_module_orangeqt LOCATION) 
    5353 
    54 get_target_property(PYTHON_LIB_LOCATION python_module_orangeqt LOCATION) 
    5554add_custom_command( 
    5655   TARGET python_module_orangeqt 
  • source/orangeqt/curve.cpp

    r8669 r8680  
    2525#include <QtCore/qmath.h> 
    2626#include <QtCore/QtConcurrentRun> 
     27#include <QtCore/QFutureWatcher> 
     28 
    2729#include "point.h" 
    2830#include "plot.h" 
    29  
    30 Curve::Curve(const QList< double >& x_data, const QList< double >& y_data, QGraphicsItem* parent, QGraphicsScene* scene): PlotItem(parent, scene) 
     31#include <QtCore/QParallelAnimationGroup> 
     32 
     33Curve::Curve(const QList< double >& x_data, const QList< double >& y_data, QGraphicsItem* parent): PlotItem(parent) 
    3134{ 
    3235    // Don't make any calls to update_properties() until the constructor is finished 
     
    3942    m_needsUpdate = UpdateAll; 
    4043    set_data(x_data, y_data); 
     44    QObject::connect(&m_watcher, SIGNAL(finished()), SLOT(pointMapFinished())); 
    4145     
    4246    m_autoUpdate = true; 
    4347} 
    4448 
    45 Curve::Curve(QGraphicsItem* parent, QGraphicsScene* scene): PlotItem(parent, scene) 
     49Curve::Curve(QGraphicsItem* parent): PlotItem(parent) 
    4650{ 
    4751    m_autoUpdate = true; 
     
    4953    m_lineItem = 0; 
    5054    m_needsUpdate = 0; 
     55    QObject::connect(&m_watcher, SIGNAL(finished()), SLOT(pointMapFinished())); 
    5156} 
    5257 
     
    125130    for (int i = 0; i < n; ++i) 
    126131    { 
     132         
    127133      m_pointItems[i]->set_coordinates(m_data[i]); 
    128134    } 
    129135    register_points(); 
    130     update_items(m_pointItems, PointPosUpdater(m_graphTransform), UpdatePosition); 
     136    update_items(m_pointItems, AnimatedPointPosUpdater(m_graphTransform), UpdatePosition); 
    131137  }  
    132138   
     
    402408void Curve::set_points(const QList< Point* >& points) 
    403409{ 
     410    if (points == m_pointItems) 
     411    { 
     412        return; 
     413    } 
    404414    m_pointItems = points; 
    405415    register_points(); 
     
    411421} 
    412422 
    413  
    414  
    415  
    416  
     423void Curve::update_point_positions() 
     424{ 
     425    if (m_watcher.future().isRunning()) 
     426    { 
     427        m_watcher.future().cancel(); 
     428        m_watcher.future().waitForFinished(); 
     429    } 
     430    if (plot() && plot()->use_animations) 
     431    { 
     432        m_watcher.setFuture(QtConcurrent::mapped(m_pointItems, PointPosMapper(m_graphTransform))); 
     433    } 
     434    else 
     435    { 
     436        update_items(m_pointItems, PointPosUpdater(m_graphTransform), UpdatePosition); 
     437    } 
     438} 
     439 
     440void Curve::pointMapFinished() 
     441{ 
     442    QParallelAnimationGroup* group = new QParallelAnimationGroup; 
     443    int n = m_pointItems.size(); 
     444    for (int i = 0; i < n; ++i) 
     445    { 
     446        QPropertyAnimation* a = new QPropertyAnimation(m_pointItems[i], "pos"); 
     447        a->setEndValue(m_watcher.resultAt(i)); 
     448        group->addAnimation(a); 
     449    } 
     450    group->start(QAbstractAnimation::DeleteWhenStopped); 
     451} 
     452 
     453 
     454 
     455#include "curve.moc" 
     456 
  • source/orangeqt/curve.h

    r8669 r8680  
    2525#include <QtGui/QPen> 
    2626#include <QtGui/QBrush> 
    27  
    2827#include <QtCore/QtConcurrentMap> 
     28#include <QtCore/QFutureWatcher> 
     29 
     30struct PointPosMapper{ 
     31  PointPosMapper(const QTransform& t) : t(t) {} 
     32  typedef QPointF result_type; 
     33  result_type operator()(Point* p) 
     34  { 
     35      return t.map(p->coordinates()); 
     36  } 
     37   
     38private: 
     39    QTransform t; 
     40}; 
     41 
    2942 
    3043struct ZoomUpdater 
     
    96109class Curve : public PlotItem 
    97110{ 
     111    Q_OBJECT 
    98112   
    99113public: 
     
    115129   * @param y_data A list of y coordinates of data points 
    116130   * @param parent parent item 
    117    * @param scene if this is not 0, the Curve is automatically added to it 
    118131   **/ 
    119   Curve(const QList< double >& x_data, const QList< double >& y_data, QGraphicsItem* parent = 0, QGraphicsScene* scene = 0); 
    120   explicit Curve(QGraphicsItem* parent = 0, QGraphicsScene* scene = 0); 
     132  Curve(const QList< double >& x_data, const QList< double >& y_data, QGraphicsItem* parent = 0); 
     133  explicit Curve(QGraphicsItem* parent = 0); 
    121134  /** 
    122135   * Default destructor 
     
    198211  void update_items(const Sequence& sequence, Updater updater, Curve::UpdateFlag flag); 
    199212   
     213  void update_point_positions(); 
     214   
    200215  void set_points(const QList<Point*>& points); 
    201216  QList<Point*> points(); 
     
    210225  void updateNumberOfItems(); 
    211226  void changeContinuous(); 
     227   
     228private slots: 
     229    void pointMapFinished(); 
    212230   
    213231private: 
     
    229247  QTransform m_zoom_transform; 
    230248  QMap<UpdateFlag, QFuture<void> > m_currentUpdate; 
     249  QFutureWatcher<QPointF> m_watcher; 
     250   
    231251}; 
    232252 
  • source/orangeqt/curve.sip

    r8669 r8680  
    3434  }; 
    3535 
    36   Curve(const QList< double >& x_data, const QList< double >& y_data, QGraphicsItem* parent /TransferThis/ = 0, QGraphicsScene* scene /TransferThis/ = 0); 
    37   Curve(QGraphicsItem* parent /TransferThis/ = 0, QGraphicsScene* scene /TransferThis/ = 0); 
     36  Curve(const QList< double >& x_data, const QList< double >& y_data, QGraphicsItem* parent /TransferThis/ = 0); 
     37  Curve(QGraphicsItem* parent /TransferThis/ = 0); 
    3838  virtual ~Curve(); 
    3939 
     
    9696  void set_points(const QList<Point*>& points); 
    9797  QList<Point*> points(); 
     98 
     99  void update_point_positions(); 
    98100   
    99101protected: 
  • source/orangeqt/multicurve.cpp

    r8669 r8680  
    1919 
    2020#include "multicurve.h" 
     21#include "plot.h" 
    2122 
    2223MultiCurve::MultiCurve(const QList< double >& x_data, const QList< double >& y_data): Curve() 
     
    130131     
    131132    register_points(); 
    132      
    133     update_items(points(), PointPosUpdater(graph_transform()), UpdatePosition);     
     133    update_point_positions(); 
    134134    update_items(points(), ZoomUpdater(point_transform()), UpdateZoom); 
    135135} 
  • source/orangeqt/networkcurve.cpp

    r8671 r8680  
    2828 
    2929#include <QtCore/QTime> 
     30#include <QtCore/QParallelAnimationGroup> 
    3031 
    3132/************/ 
     
    7273    p.y = m_y; 
    7374    Point::set_coordinates(p); 
    74      
    75     setPos(QPointF(m_x, m_y) * m_graph_transform); 
    7675} 
    7776 
     
    307306/****************/ 
    308307 
    309 NetworkCurve::NetworkCurve(QGraphicsItem* parent, QGraphicsScene* scene): Curve(parent, scene) 
     308NetworkCurve::NetworkCurve(QGraphicsItem* parent): Curve(parent) 
    310309{ 
    311310     m_min_node_size = 5; 
     
    325324{ 
    326325    const QTransform t = graph_transform(); 
    327     update_items(m_nodes, NodeUpdater(t, point_transform()), UpdatePosition); 
     326    update_point_positions(); 
    328327    update_items(m_edges, EdgeUpdater(t), UpdatePen); 
    329328} 
     
    10681067void NetworkCurve::register_points() 
    10691068{ 
    1070     Plot* p = plot(); 
    1071     if (p) 
    1072     { 
    1073         p->remove_all_points(this); 
    1074         foreach (NodeItem* node, m_nodes) 
    1075         { 
    1076             p->add_point(node, this); 
    1077         } 
    1078     } 
     1069    QList<Point*> list; 
     1070    foreach (NodeItem* node, m_nodes) 
     1071    { 
     1072        list << node; 
     1073    } 
     1074    set_points(list); 
    10791075} 
    10801076 
  • source/orangeqt/networkcurve.h

    r8671 r8680  
    222222    typedef QMap<int, NodeItem*> Nodes; 
    223223 
    224     explicit NetworkCurve(QGraphicsItem* parent = 0, QGraphicsScene* scene = 0); 
     224    explicit NetworkCurve(QGraphicsItem* parent = 0); 
    225225    virtual ~NetworkCurve(); 
    226226 
  • source/orangeqt/networkcurve.sip

    r8669 r8680  
    8181    typedef QMap<int, NodeItem*> Nodes; 
    8282 
    83     NetworkCurve(QGraphicsItem* parent /TransferThis/ = 0, QGraphicsScene* scene /TransferThis/ = 0); 
     83    NetworkCurve(QGraphicsItem* parent /TransferThis/ = 0); 
    8484    virtual ~NetworkCurve(); 
    8585     
  • source/orangeqt/plot.h

    r8669 r8680  
    9898    void marked_to_selected(); 
    9999     
     100    bool use_animations; 
     101     
    100102Q_SIGNALS: 
    101103    void selection_changed(); 
  • source/orangeqt/plot.sip

    r8669 r8680  
    8282    void remove_point(Point* point, PlotItem* parent); 
    8383    void remove_all_points(PlotItem* parent); 
     84     
     85    bool use_animations; 
    8486 
    8587Q_SIGNALS: 
  • source/orangeqt/plotitem.cpp

    r8669 r8680  
    2626const int yLeft = 0; 
    2727 
    28 PlotItem::PlotItem(QGraphicsItem* parent, QGraphicsScene* scene): QGraphicsItem(parent, scene),  
     28PlotItem::PlotItem(QGraphicsItem* parent): QGraphicsObject(parent),  
    2929    m_plot(0) 
    3030{ 
     
    174174} 
    175175 
     176#include "plotitem.moc" 
  • source/orangeqt/plotitem.h

    r8669 r8680  
    2020#define PLOTITEM_H 
    2121 
    22 #include <QtGui/QGraphicsItem> 
     22#include <QtGui/QGraphicsObject> 
    2323 
    2424class Plot; 
    2525 
    26 class PlotItem : public QGraphicsItem 
     26class PlotItem : public QGraphicsObject 
    2727{ 
    28  
     28    Q_OBJECT 
    2929public: 
    30     explicit PlotItem(QGraphicsItem* parent = 0, QGraphicsScene* scene = 0); 
     30    explicit PlotItem(QGraphicsItem* parent = 0); 
    3131    virtual ~PlotItem(); 
    3232     
  • source/orangeqt/plotitem.sip

    r8669 r8680  
    1 class PlotItem : QGraphicsItem { 
     1class PlotItem : QGraphicsObject { 
    22 
    33%TypeHeaderCode 
     
    66 
    77public: 
    8     PlotItem(QGraphicsItem* parent /TransferThis/ = 0, QGraphicsScene* scene /TransferThis/ = 0); 
     8    PlotItem(QGraphicsItem* parent /TransferThis/ = 0); 
    99    virtual ~PlotItem(); 
    1010     
  • source/orangeqt/point.cpp

    r8678 r8680  
    5656} 
    5757 
     58DataPoint::operator QPointF() 
     59{ 
     60    return QPointF(x, y); 
     61} 
     62 
     63 
    5864Point::Point(int symbol, QColor color, int size, QGraphicsItem* parent): QGraphicsObject(parent), 
    5965 m_symbol(symbol), 
     
    6571} 
    6672 
    67 Point::Point(QGraphicsItem* parent, QGraphicsScene* scene): QGraphicsObject(parent) 
     73Point::Point(QGraphicsItem* parent): QGraphicsObject(parent) 
    6874{ 
    6975    m_symbol = Ellipse; 
     
    320326    return QRectF(-size/2, -size/2, size, size); 
    321327} 
    322 void Point::set_state(Point::State state) { 
     328 
     329void Point::set_state(Point::State state)  
     330{ 
    323331    m_state = state; 
    324332} 
    325 Point::State Point::state() const { 
     333 
     334Point::State Point::state() const  
     335{ 
    326336    return m_state; 
    327337} 
     338 
    328339void Point::set_state_flag(Point::StateFlag flag, bool on) { 
    329340    if (on) 
     
    397408} 
    398409 
     410#include "point.moc" 
  • source/orangeqt/point.h

    r8678 r8680  
    2222#include <QtGui/QGraphicsObject> 
    2323#include <QtCore/QDebug> 
     24#include <QtCore/QPropertyAnimation> 
    2425 
    2526 
     
    2829  double x; 
    2930  double y; 
     31   
     32  operator QPointF(); 
    3033}; 
    3134 
     
    98101    } 
    99102     
    100     explicit Point(QGraphicsItem* parent = 0, QGraphicsScene* scene = 0); 
     103    explicit Point(QGraphicsItem* parent = 0); 
    101104    Point(int symbol, QColor color, int size, QGraphicsItem* parent = 0); 
    102105    virtual ~Point(); 
     
    181184}; 
    182185 
     186struct AnimatedPointPosUpdater 
     187{ 
     188    AnimatedPointPosUpdater(const QTransform& t) : t(t) {} 
     189    void operator()(Point* point) 
     190    { 
     191        QPointF endPos = t.map(point->coordinates()); 
     192        if (endPos == point->pos()) 
     193        { 
     194            return; 
     195        } 
     196        QPropertyAnimation* animation = new QPropertyAnimation(point, "pos", point); 
     197        qDebug() << animation->startValue() << point->property("pos"); 
     198        animation->setEndValue(endPos); 
     199        animation->setDuration(100); 
     200        animation->start(QPropertyAnimation::DeleteWhenStopped); 
     201    } 
     202private: 
     203    QTransform t; 
     204}; 
     205 
    183206#endif // POINT_H 
  • source/orangeqt/point.sip

    r8669 r8680  
    2525}; 
    2626 
    27 class Point : QGraphicsItem 
     27class Point : QGraphicsObject 
    2828{ 
    2929     
     
    6868    typedef QFlags<Point::StateFlag> State; 
    6969   
    70     Point(QGraphicsItem* parent /TransferThis/ = 0, QGraphicsScene* scene /TransferThis/ = 0); 
     70    Point(QGraphicsItem* parent /TransferThis/ = 0); 
    7171    Point(int symbol, QColor color, int size, QGraphicsItem* parent /TransferThis/ = 0); 
    7272    virtual ~Point(); 
  • source/orangeqt/unconnectedlinescurve.cpp

    r8669 r8680  
    2121#include <QtCore/QDebug> 
    2222 
    23 UnconnectedLinesCurve::UnconnectedLinesCurve(const QList< double >& x_data, const QList< double >& y_data, QGraphicsItem* parent, QGraphicsScene* scene): Curve(parent, scene) 
     23UnconnectedLinesCurve::UnconnectedLinesCurve(const QList< double >& x_data, const QList< double >& y_data, QGraphicsItem* parent): Curve(parent) 
    2424{ 
    2525    m_path_item = new QGraphicsPathItem(this); 
  • source/orangeqt/unconnectedlinescurve.h

    r8669 r8680  
    2626 
    2727public: 
    28     UnconnectedLinesCurve(const QList< double >& x_data, const QList< double >& y_data, QGraphicsItem* parent = 0, QGraphicsScene* scene = 0); 
     28    UnconnectedLinesCurve(const QList< double >& x_data, const QList< double >& y_data, QGraphicsItem* parent = 0); 
    2929    virtual ~UnconnectedLinesCurve(); 
    3030     
  • source/orangeqt/unconnectedlinescurve.sip

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