Changeset 8491:7afbcc22c41f in orange


Ignore:
Timestamp:
07/27/11 22:01:03 (3 years ago)
Author:
Noughmad <Noughmad@…>
Branch:
default
Convert:
22cd783be9014475275b32e1a19682182e7f836a
Message:

Add a PointsCollection class to speed up querying for selected points, at the cost of greater memory consumption

Files:
2 added
9 edited

Legend:

Unmodified
Added
Removed
  • orange/OrangeWidgets/plot/owplot.py

    r8486 r8491  
    527527             
    528528    def update_zoom(self): 
    529       #  self.setViewportUpdateMode(QGraphicsView.NoViewportUpdate) 
    530529        self.zoom_transform = self.transform_for_zoom(self._zoom_factor, self._zoom_point, self.graph_area) 
    531530        self.zoom_rect = self.zoom_transform.mapRect(self.graph_area) 
     
    547546        """ 
    548547        self.update_axes(zoom_only=True) 
    549          
    550         self.setViewportUpdateMode(QGraphicsView.FullViewportUpdate) 
    551548        self.update() 
    552549         
  • source/orangeplot/CMakeLists.txt

    r8423 r8491  
    1414 
    1515#### orangeplot sources #### 
    16 set(orangeplot_SRCS plotitem.cpp point.cpp curve.cpp unconnectedlinescurve.cpp plot.cpp networkcurve.cpp) 
     16set(orangeplot_SRCS  
     17    plotitem.cpp  
     18    point.cpp  
     19    pointscollection.cpp 
     20    curve.cpp  
     21    unconnectedlinescurve.cpp  
     22    networkcurve.cpp 
     23    plot.cpp  
     24) 
    1725qt4_automoc(${orangeplot_SRCS}) 
    1826 
  • source/orangeplot/curve.cpp

    r8447 r8491  
    99#include "point.h" 
    1010 
    11 Curve::Curve(const QList< double >& x_data, const QList< double >& y_data, QGraphicsItem* parent, QGraphicsScene* scene): PlotItem(parent, scene) 
     11Curve::Curve(const QList< double >& x_data, const QList< double >& y_data, QGraphicsItem* parent, QGraphicsScene* scene): PlotItem(parent, scene), PointsCollection() 
    1212{ 
    1313    m_style = NoCurve; 
     
    1919} 
    2020 
    21 Curve::Curve(QGraphicsItem* parent, QGraphicsScene* scene): PlotItem(parent, scene) 
     21Curve::Curve(QGraphicsItem* parent, QGraphicsScene* scene): PlotItem(parent, scene), PointsCollection() 
    2222{ 
    2323    m_style = NoCurve; 
     
    5353   
    5454  Q_ASSERT(m_pointItems.size() == m_data.size()); 
     55  set_points(m_pointItems); 
    5556} 
    5657 
     
    149150    m_data.append(p); 
    150151  } 
     152  set_data_points(x_data, y_data); 
    151153  set_data_rect(rect_from_data(x_data, y_data)); 
    152154  m_needsUpdate |= UpdatePosition; 
  • source/orangeplot/curve.h

    r8447 r8491  
    99 
    1010#include <QtCore/QtConcurrentMap> 
     11#include "pointscollection.h" 
    1112 
    1213struct DataPoint 
     
    7980typedef QList< DataPoint > Data; 
    8081 
    81 class Curve : public PlotItem 
     82class Curve : public PlotItem, public PointsCollection 
    8283{ 
    8384   
     
    161162  double max_y_value() const; 
    162163  double min_y_value() const; 
    163      
     164 
    164165  enum UpdateFlag 
    165166  { 
  • source/orangeplot/networkcurve.cpp

    r8488 r8491  
    436436    qDeleteAll(m_nodes); 
    437437    m_nodes = nodes; 
     438    foreach (NodeItem* node, nodes) 
     439    { 
     440        add_point(node); 
     441    } 
    438442} 
    439443 
  • source/orangeplot/plot.cpp

    r8479 r8491  
    44 
    55#include <QtCore/QDebug> 
     6#include "pointscollection.h" 
    67 
    78template <class Area> 
     
    166167    for (int i = 0; i < n; ++i) 
    167168    { 
    168         const QPointF coords = QPointF(x_data[i], y_data[i]) * transform; 
    169         bool found_point = false; 
    170         foreach (QGraphicsItem* item, scene()->items(coords)) 
    171         { 
    172             if (item->pos() != coords) 
    173             { 
    174                 continue; 
    175             } 
    176             const Point* point = qgraphicsitem_cast<Point*>(item); 
    177             found_point = (point && point->is_selected()); 
    178             if (found_point) 
    179             { 
    180                 break; 
    181             } 
    182         } 
    183         selected << found_point; 
    184     } 
    185     qDebug() << "Found" << selected.count(1) << "selected points out of" << selected.size(); 
     169        selected << (selected_point_at(QPointF(x_data[i], y_data[i]) * transform) ? 1 : 0); 
     170    } 
    186171    return selected; 
    187172} 
    188173 
     174Point* Plot::selected_point_at(const QPointF& pos) 
     175{ 
     176    foreach (PlotItem* item, plot_items()) 
     177    { 
     178        const PointsCollection* collection = dynamic_cast<PointsCollection*>(item); 
     179        if (collection && collection->contains(pos) && collection->point_at(pos)->is_selected()) 
     180        { 
     181            return collection->point_at(pos); 
     182        } 
     183    } 
     184    return 0; 
     185} 
     186 
    189187Point* Plot::point_at(const QPointF& pos) 
    190188{ 
    191189    Point* point; 
    192     foreach (QGraphicsItem* item, scene()->items(pos)) 
    193     { 
    194         if (point = qgraphicsitem_cast<Point*>(item)) 
    195         { 
    196             return point; 
     190    foreach (PlotItem* item, plot_items()) 
     191    { 
     192        const PointsCollection* collection = dynamic_cast<PointsCollection*>(item); 
     193        if (collection && collection->contains(pos)) 
     194        { 
     195            return collection->point_at(pos); 
    197196        } 
    198197    } 
  • source/orangeplot/plot.h

    r8479 r8491  
    4545     
    4646    Point* point_at(const QPointF& pos); 
     47    Point* selected_point_at(const QPointF& pos); 
    4748     
    4849protected: 
  • source/orangeplot/point.cpp

    r8480 r8491  
    316316    pixmap_cache.clear(); 
    317317} 
    318  
    319  
    320  
    321  
  • source/orangeplot/point.h

    r8480 r8491  
    115115     
    116116    static void clear_cache(); 
    117          
     117 
    118118private: 
    119119    static QPainterPath trianglePath(double d, double rot); 
Note: See TracChangeset for help on using the changeset viewer.