Changeset 8334:ecfac1bd8c5b in orange


Ignore:
Timestamp:
06/27/11 21:28:21 (3 years ago)
Author:
Noughmad <Noughmad@…>
Branch:
default
Convert:
db122d7108c8092d72469584c5d82a575a802488
Message:

Move PlotItem and Graph classes to C++

Location:
source/orangegraph
Files:
6 added
4 edited

Legend:

Unmodified
Added
Removed
  • source/orangegraph/curve.cpp

    r8332 r8334  
    55#include <QtGui/QPen> 
    66 
    7 Curve::Curve(QGraphicsItem* parent): QGraphicsObject(parent) 
    8 { 
    9   m_continuous = false; 
    10   m_lineItem = 0; 
    11 } 
    12    
    13 Curve::Curve(const Data& data, QGraphicsItem* parent) : QGraphicsObject(parent) 
    14 { 
    15   m_continuous = false; 
    16   m_lineItem = 0; 
    17   setData(data); 
     7Curve::Curve(QList< double > xData, QList< double > yData, QGraphicsItem* parent, QGraphicsScene* scene): PlotItem(xData, yData, parent, scene) 
     8{ 
     9    m_continuous = false; 
     10    m_lineItem = 0; 
     11    setData(xData, yData); 
    1812} 
    1913 
     
    2216 
    2317} 
    24  
    25 void Curve::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) 
    26 { 
    27  
    28 } 
    29  
    30 QRectF Curve::boundingRect() const 
    31 { 
    32     return QRectF(); 
    33 } 
    34  
    3518 
    3619void Curve::updateNumberOfItems() 
     
    193176} 
    194177 
    195 void Curve::setData(const Data& data) 
    196 { 
    197   if (data.size() != m_data.size()) 
    198   { 
    199     m_needsUpdate |= UpdateNumberOfItems; 
    200   } 
    201   m_data = data; 
    202   m_needsUpdate |= UpdatePosition; 
    203   updateBounds(); 
    204   checkForUpdate(); 
    205 } 
    206  
    207178void Curve::setData(const QList< qreal > xData, const QList< qreal > yData) 
    208179{ 
  • source/orangegraph/curve.h

    r8330 r8334  
    22#define CURVE_H 
    33 
    4 #include <QtGui/QGraphicsObject> 
     4#include "plotitem.h" 
    55 
    6  
    7    
    86struct DataPoint 
    97{ 
     
    1412typedef QList< DataPoint > Data; 
    1513 
    16 class Curve : public QGraphicsObject 
     14class Curve : public PlotItem 
    1715{ 
    18   Q_OBJECT 
    19   Q_ENUMS(Symbol) 
    20   /** 
    21    * @brief the curve's color 
    22    *  
    23    * Contains this curve's color.  
    24    * If the curve is continuous, the line is drawn with this color. Otherwise, the points are drawn and filled with this color. 
    25    **/ 
    26   Q_PROPERTY(QColor color READ color WRITE setColor) 
    27   Q_PROPERTY(int pointSize READ pointSize WRITE setPointSize) 
    28   Q_PROPERTY(int symbol READ symbol WRITE setSymbol) 
    29   Q_PROPERTY(bool continuous READ isContinuous WRITE setContinuous) 
    30   Q_PROPERTY(Data data READ data WRITE setData) 
    31   Q_PROPERTY(QTransform graphTransform READ transform WRITE setTransform) 
    32   /** 
    33    * @brief Update the curve immediately after every change 
    34    *  
    35    * If this property is set to true, every change to the curve will result in an immediate update.  
    36    * If it is false, you must explicitely call update() or updateAll() before the changes become visible.  
    37    * The default is true 
    38    **/ 
    39   Q_PROPERTY(bool autoUpdate READ autoUpdate WRITE setAutoUpdate) 
    4016   
    4117public: 
     
    6541  }; 
    6642   
    67   Curve(QGraphicsItem* parent = 0); 
    68    
    6943  /** 
    7044   * @brief Default constructor 
     
    7246   * Constructs a Curve from a series of data points 
    7347   * 
    74    * @param data A list of data points, i.e. pairs of coordinates (x,y) 
    75    * @param parent parent QGraphicsItem, passed to QGraphicsObject's constructor 
     48   * @param xData A list of x coordinates of data points 
     49   * @param yData A list of y coordinates of data points 
     50   * @param parent parent item 
     51   * @param scene if this is not 0, the Curve is automatically added to it 
    7652   **/ 
    77   Curve(const Data& data, QGraphicsItem* parent = 0); 
    78      
     53  Curve(QList< double > xData, QList< double > yData, QGraphicsItem* parent = 0, QGraphicsScene* scene = 0); 
     54 
    7955  /** 
    8056   * Default destructor 
     
    8258   **/ 
    8359  virtual ~Curve(); 
    84  
    85   virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0); 
    86   virtual QRectF boundingRect() const; 
    8760     
    8861  /** 
     
    131104   
    132105  Data data() const; 
    133   void setData(const Data& data); 
    134106  void setData(const QList<qreal> xData, const QList<qreal> yData); 
    135107   
  • source/orangegraph/curve.sip

    r8330 r8334  
    1111typedef QList<DataPoint> Data; 
    1212 
    13 class Curve : QGraphicsObject { 
     13class Curve : PlotItem { 
    1414 
    1515%TypeHeaderCode 
    1616#include "curve.h" 
    17 %End 
    18  
    19 %TypeCode 
    20 // Create a Data object from a list of tuples 
    21 static Data dataFromTupleList(PyObject* l) 
    22 { 
    23   Data data; 
    24   int n = PyList_GET_SIZE(l); 
    25   DataPoint p; 
    26   for (SIP_SSIZE_T i = 0; i < PyList_GET_SIZE(l); ++i) 
    27   { 
    28     if (PyArg_ParseTuple(PyList_GET_ITEM(l,i), "dd", &p.x, &p.y)) 
    29     { 
    30       data.append(p); 
    31     } 
    32   } 
    33   return data; 
    34 } 
    3517%End 
    3618 
     
    5739  }; 
    5840 
    59   Curve(QGraphicsItem* parent /TransferThis/ = 0); 
    60   Curve(SIP_PYLIST data, QGraphicsItem* parent /TransferThis/ = 0) [(Data, QGraphicsItem*)]; 
    61 %MethodCode 
    62   sipCpp = new sipCurve(dataFromTupleList(a0), a1); 
    63 %End 
    64  
     41  Curve(QList< double > xData, QList< double > yData, QGraphicsItem* parent /TransferThis/ = 0, QGraphicsScene* scene = 0); 
    6542  virtual ~Curve(); 
    66  
    6743 
    6844  virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0); 
     
    8763   
    8864  Data data() const; 
    89   void setData(SIP_PYLIST data); 
    90 %MethodCode 
    91   sipCpp->setData(dataFromTupleList(a0)); 
    92 %End 
    93  
    9465  void setData(const QList<qreal>& xData, const QList<qreal>& yData); 
    9566 
  • source/orangegraph/orangegraph.sip

    r8328 r8334  
    33%Import QtGui/QtGuimod.sip 
    44 
    5 %Include owgraph.sip 
     5%Include plotitem.sip 
    66%Include curve.sip 
     7%Include graph.sip 
Note: See TracChangeset for help on using the changeset viewer.