[Kst] branches/work/kst/portto4/kst/src/libkstapp

Ted Kisner tskisner.public at gmail.com
Mon Jun 18 07:29:44 CEST 2007


SVN commit 676960 by tskisner:

Beggining of 2D rendering framework.  Each PlotItem has a list of renderers and each renderer has a list of basecurves.  Much still TODO before a working demo is available.

 M  +4 -1      CMakeLists.txt  
 A             axis.cpp   [License: GPL (v2+)]
 M  +7 -3      axis.h  
 M  +48 -4     plotitem.cpp  
 M  +19 -1     plotitem.h  
 A             plotrenderer2d.cpp   [License: GPL (v2+)]
 M  +49 -4     plotrenderer2d.h  
 A             render2dcartesian.cpp   [License: GPL (v2+)]
 A             render2dcartesian.h   [License: GPL (v2+)]


--- branches/work/kst/portto4/kst/src/libkstapp/CMakeLists.txt #676959:676960
@@ -1,4 +1,4 @@
-include_directories( ${CMAKE_BINARY_DIR}/kst ${CMAKE_SOURCE_DIR}/kst/src/extdate ${CMAKE_SOURCE_DIR}/kst/src/widgets ${CMAKE_BINARY_DIR}/kst/src/widgets ${CMAKE_SOURCE_DIR}/kst/src/libkst ${CMAKE_BINARY_DIR}/kst/src/libkst ${CMAKE_SOURCE_DIR}/kst/src/libkstmath ${KDE4_INCLUDE_DIR} ${QT_INCLUDES}  )
+include_directories( ${CMAKE_BINARY_DIR}/kst ${CMAKE_SOURCE_DIR}/kst/src/extdate ${CMAKE_SOURCE_DIR}/kst/src/widgets ${CMAKE_BINARY_DIR}/kst/src/widgets ${CMAKE_SOURCE_DIR}/kst/src/libkst ${CMAKE_BINARY_DIR}/kst/src/libkst ${CMAKE_SOURCE_DIR}/kst/src/libkstapp ${CMAKE_BINARY_DIR}/kst/src/libkstapp ${CMAKE_SOURCE_DIR}/kst/src/libkstmath ${KDE4_INCLUDE_DIR} ${QT_INCLUDES}  )
 
 set(kstapp_LIB_SRCS
    applicationsettings.cpp
@@ -30,6 +30,9 @@
    view.cpp
    viewitem.cpp
    viewitemdialog.cpp
+   axis.cpp
+   plotrenderer2d.cpp
+   render2dcartesian.cpp
    )
 
 kde4_add_ui_files(kstapp_LIB_SRCS
--- branches/work/kst/portto4/kst/src/libkstapp/axis.h #676959:676960
@@ -12,6 +12,8 @@
 #ifndef AXIS_H
 #define AXIS_H
 
+#include <QtGlobal>
+
 namespace Kst {
 
 // A representation of a plot axis.  This has nothing to do with the way the
@@ -19,10 +21,11 @@
 class Axis {
   public:
     Axis();
+    ~Axis();
 
     bool reversed;
     bool isLog;
-    double logBase;
+    qreal logBase;
 };
 
 
@@ -30,11 +33,12 @@
 class AxisStyle {
   public:
     AxisStyle();
+    ~AxisStyle();
 
     bool showMinorTicks;
     bool showMajorTicks;
-    double minorTickWidth;
-    double majorTickWidth;
+    qreal minorTickWidth;
+    qreal majorTickWidth;
 };
 
 }
--- branches/work/kst/portto4/kst/src/libkstapp/plotitem.cpp #676959:676960
@@ -9,17 +9,35 @@
  *                                                                         *
  ***************************************************************************/
 
+#include <QDebug>
+#include <QPainterPath>
+
 #include "plotitem.h"
 
-#include <QDebug>
-#include <QGraphicsItem>
-#include <QGraphicsScene>
+// FIXME temporary
+#include "kstsvector.h"
+#include "kstvcurve.h"
+#include "kstdatacollection.h"
+#include "kstdataobjectcollection.h"
+#include "render2dcartesian.h"
 
 namespace Kst {
 
 PlotItem::PlotItem(View *parent)
   : ViewItem(parent) {
-  setBrush(Qt::white);
+  _backgroundColor = Qt::transparent;
+  // FIXME: temporary test code
+  QColor temp = Qt::black;
+  _colorStack.push(temp);
+  
+  // FIXME: fake data for testing rendering
+  KstVectorPtr xTest = new KstSVector(0.0, 100.0, 10000, KstObjectTag::fromString("X vector"));
+  KstVectorPtr yTest = new KstSVector(-100.0, 100.0, 10000, KstObjectTag::fromString("Y vector"));
+  KstVCurvePtr renderTest = new KstVCurve(QString("rendertest"), xTest, yTest, NULL, NULL, NULL, NULL, QColor(Qt::red));
+  
+  Render2DCartesian carTest(QString("cartesiantest"));
+  carTest.sources.append(kst_cast<KstBaseCurve>(renderTest));
+  renderers.append(carTest);
 }
 
 
@@ -34,8 +52,34 @@
   CreateCommand::createItem();
 }
 
+void PlotItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
+  QPainterPath path;
+  setBrush(Qt::transparent);
+  //FIXME:  temporary test code
+  const qreal w = pen().widthF();
+  path.addEllipse(rect().adjusted(w, w, -w, -w));
+  painter->drawPath(path);
+  QPen p = pen();
+  setPen(Qt::NoPen);
+  ViewItem::paint(painter, option, widget);
+  setPen(p);
+  
+  //QFont testFont;
+  //QColor fg = Qt::black;
+  //QPen testPen(fg);
+  //path.addText(100, 100, testFont, tr("This is a test")); 
+  /*
+  for (KstBaseCurveList::Iterator i = _sources.begin(); i != _sources.end(); ++i) {
+    (*i)->paint(&path);
+  }
+  */
 }
 
+void PlotItem::paint(QPainter *painter) {
+}
+
+}
+
 #include "plotitem.moc"
 
 // vim: ts=2 sw=2 et
--- branches/work/kst/portto4/kst/src/libkstapp/plotitem.h #676959:676960
@@ -12,7 +12,14 @@
 #ifndef PLOTITEM_H
 #define PLOTITEM_H
 
+#include <QObject>
+#include <QColor>
+#include <QStack>
+#include <QGraphicsItem>
+
 #include "viewitem.h"
+#include "kstbasecurve.h"
+#include "plotrenderer2d.h"
 
 namespace Kst {
 
@@ -22,7 +29,18 @@
   public:
     PlotItem(View *parent);
     virtual ~PlotItem();
-
+    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
+    void paint(QPainter *painter);
+    
+    // List of renderers to use
+    QList<PlotRenderer2D> renderers;
+    
+  private:
+    
+    // Options common to the plot and all rendered data
+    QColor _backgroundColor;
+    QStack<QColor> _colorStack;
+    
 };
 
 class KST_EXPORT CreatePlotCommand : public CreateCommand
--- branches/work/kst/portto4/kst/src/libkstapp/plotrenderer2d.h #676959:676960
@@ -9,20 +9,65 @@
  *                                                                         *
  ***************************************************************************/
 
-#ifndef PLOTRENDER2D_H
-#define PLOTRENDER2D_H
+#ifndef PLOTRENDERER2D_H
+#define PLOTRENDERER2D_H
 
+#include <QPainterPath>
 #include "axis.h"
+#include "kstbasecurve.h"
 
 namespace Kst {
 
+enum RenderType2D { Cartesian, Polar, Sinusoidal };
+
 class PlotRenderer2D {
   public:
-    PlotRenderer2D();
+    PlotRenderer2D(const QString &name);
+    virtual ~PlotRenderer2D();
+    // Set data range in terms of projected coordinates
+    virtual void setRangeXY(const QRectF& range);
+    // Set data range in terms of native coordinates
+    virtual void setRangeUV(const QRectF& range);
+    // Get data range in terms of projected coordinates
+    virtual void rangeXY(QRectF *range);
+    // Get data range in terms of native coordinates
+    virtual void rangeUV(QRectF *range);
+    // Take a PainterPath in native coordinates and project
+    virtual void projectPath(QPainterPath *path);
+    // Project a single point
+    virtual void projectPoint(const QPointF& pold, QPointF *pnew);
+    // Inverse projection of a single point
+    virtual void projectPointInv(const QPointF& pold, QPointF *pnew);
+    
+    // Set and get the renderer type
+    void setType(RenderType2D type);
+    RenderType2D type();
+    
+    // The list of things to render
+    KstBaseCurveList sources;
 
-  private:
+  protected:
+    // Recompute auxilliary range information if the
+    // properties of the full plot have changed.
+    void refreshRange(); 
+    
+    // Range of plot in projected coordinates
+    QRectF _xyRange;
+    // Range of plot in native coordinates
+    QRectF _uvRange;
+    
+    // Axes 
     Axis _xAxis, _yAxis;
+    // Axis styles
     AxisStyle _xAxisStyle, _yAxisStyle;
+    
+  private:
+    // Name of the plot
+    QString _name;
+    
+    // Type of the plot
+    RenderType2D _type;
+    
 };
 
 }


More information about the Kst mailing list