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

Adam Treat treat at kde.org
Fri Aug 3 03:14:32 CEST 2007


SVN commit 695814 by treat:

And... we're drawing plots :)

I'm leaving in the debugging code until I have a chance
to go through it and document/refactor the kstvcurve drawing
code.

The plots are still fully transformable via QGV.  Rotating plots ;)

I'm still hardcoding the zoom box to this particular vector, but at
least we're drawing this one good...  more later.



 M  +9 -7      libkstapp/plotitem.cpp  
 M  +6 -8      libkstapp/vectorcurverenderitem.cpp  
 M  +61 -0     libkstmath/kstvcurve.cpp  


--- branches/work/kst/portto4/kst/src/libkstapp/plotitem.cpp #695813:695814
@@ -31,9 +31,12 @@
 
   // 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"));
+  KstVectorPtr yTest = new KstSVector(0.0, 100.0, 10000, KstObjectTag::fromString("Y vector"));
 
-  KstVCurvePtr renderTest = new KstVCurve(QString("rendertest"), xTest, yTest, xTest, yTest, xTest, yTest, QColor(Qt::red));
+  KstVectorPtr errorX = new KstSVector(0.0, 0.0, 0, KstObjectTag::fromString("X error"));
+  KstVectorPtr errorY = new KstSVector(0.0, 0.0, 0, KstObjectTag::fromString("y error"));
+
+  KstVCurvePtr renderTest = new KstVCurve(QString("rendertest"), xTest, yTest, errorX, errorY, errorX, errorY, QColor(Qt::red));
   renderTest->writeLock();
   renderTest->update(0);
   renderTest->unlock();
@@ -63,15 +66,14 @@
 void PlotItem::paint(QPainter *painter) {
   ViewItem::paint(painter);
 
-  painter->translate(rect().x(), rect().y() + rect().height());
-
-  QRectF range = boundingRect();
-  range = painter->transform().mapRect(range);
+  QRectF range = rect();
+  range = range.normalized();
+  painter->translate(range.x(), range.y());
   range.moveTopLeft(QPoint(0,0));
 
   foreach (PlotRenderItem *renderer, _renderers) {
 
-    renderer->setRange(range); //FIXME no idea if this is the idea...
+    renderer->setRange(range);
     renderer->paint(painter);
   }
 }
--- branches/work/kst/portto4/kst/src/libkstapp/vectorcurverenderitem.cpp #695813:695814
@@ -30,8 +30,6 @@
     context.painter = painter;
     context.window = range().toRect(); //no idea if this should be floating point
 
-    qDebug() << range() << endl;
-
     //Everything that comes next is magic...  I took most from kst2dplot, hints
     //from barth and trial and error...
 
@@ -42,9 +40,9 @@
     context.YMax = 0.1;
 
     //These are the bounding box in regular QGV coord
-    context.Lx = 0;
+    context.Lx = range().left();
     context.Hx = range().right();
-    context.Ly = 0;
+    context.Ly = range().top();
     context.Hy = range().bottom();
 
     //To convert between the last two...
@@ -59,10 +57,10 @@
     context.b_Y = b_Y;
 
     painter->save();
-    QTransform t;
-    t.scale(1, -1); //i guess this is dependent upon the Y vector range
-    painter->setTransform(t, true);
-    painter->translate(0, int(-1.0 * context.Hy - context.Ly));
+
+//     qDebug() << "origin of plot:" << QPoint(context.Lx, context.Hy) << endl;
+//     qDebug() << "origin of relation:" << QPoint(relation->minX(), relation->minY()) << endl;
+
     relation->paint(context);
     painter->restore();
   }
--- branches/work/kst/portto4/kst/src/libkstmath/kstvcurve.cpp #695813:695814
@@ -34,6 +34,8 @@
 
 #include <time.h>
 
+// #define DEBUB_VECTOR_CURVE
+
 #ifndef KDE_IS_LIKELY
 #if __GNUC__ - 0 >= 3
 # define KDE_ISLIKELY( x )    __builtin_expect(!!(x),1)
@@ -973,6 +975,9 @@
           if (index > 0) {
             QPolygon poly;
             poly.putPoints(0, index, points);
+#ifdef DEBUG_VECTOR_CURVE
+qDebug() << "976 drawPolyline" << poly << endl;
+#endif
             p->drawPolyline(poly);
           }
           index = 0;
@@ -983,6 +988,9 @@
               if (minY < Ly && maxY >= Ly)
                 minY = Ly;
               if (minY >= Ly && minY <= Hy && maxY >= Ly && maxY <= Hy) {
+#ifdef DEBUG_VECTOR_CURVE
+qDebug() << "987 drawLine" << QLine(d2i(X2), d2i(minY), d2i(X2), d2i(maxY)) << endl;
+#endif
                 p->drawLine(d2i(X2), d2i(minY), d2i(X2), d2i(maxY));
               }
             }
@@ -1033,21 +1041,39 @@
                   if (index >= MAX_NUM_POLYLINES-2) {
                     QPolygon poly;
                     poly.putPoints(0, index, points);
+#ifdef DEBUG_VECTOR_CURVE
+qDebug() << "1037 drawPolyline" << poly << endl;
+#endif
                     p->drawPolyline(poly);
                     index = 0;
                   }
                   if (KDE_ISUNLIKELY(minYi == maxYi)) {
+#ifdef DEBUG_VECTOR_CURVE
+qDebug() << "1042 index++" << index << endl;
+#endif
                     points.setPoint(index++, X2i, maxYi);
                   } else if (KDE_ISUNLIKELY(Y2 == minY)) {
+#ifdef DEBUG_VECTOR_CURVE
+qDebug() << "1045 index++" << index << endl;
+#endif
                     points.setPoint(index++, X2i, maxYi);
                     points.setPoint(index++, X2i, minYi);
                   } else if (KDE_ISUNLIKELY(Y2 == maxY)) {
+#ifdef DEBUG_VECTOR_CURVE
+qDebug() << "1049 index++" << index << endl;
+#endif
                     points.setPoint(index++, X2i, minYi);
                     points.setPoint(index++, X2i, maxYi);
                   } else {
+#ifdef DEBUG_VECTOR_CURVE
+qDebug() << "1053 index++" << index << endl;
+#endif
                     points.setPoint(index++, X2i, minYi);
                     points.setPoint(index++, X2i, maxYi);
                     if (KDE_ISLIKELY(Y2 >= Ly && Y2 <= Hy)) {
+#ifdef DEBUG_VECTOR_CURVE
+qDebug() << "1057 index++" << index << endl;
+#endif
                       points.setPoint(index++, X2i, Y2i);
                     }
                   }
@@ -1064,9 +1090,15 @@
                     if (index > 0) {
                       QPolygon poly;
                       poly.putPoints(0, index, points);
+#ifdef DEBUG_VECTOR_CURVE
+qDebug() << "1069 drawPolyline" << poly << endl;
+#endif
                       p->drawPolyline(poly);
                       index = 0;
                     }
+#ifdef DEBUG_VECTOR_CURVE
+qDebug() << "1079 drawLine" << QLine(X2i, d2i(minY), X2i, d2i(maxY)) << endl;
+#endif
                     p->drawLine(X2i, d2i(minY), X2i, d2i(maxY));
                   }
                 }
@@ -1075,6 +1107,7 @@
             }
 
             if (KDE_ISLIKELY(!((X1 < Lx && X2 < Lx) || (X1 > Hx && X2 > Hx)))) {
+
               // trim the line to be within the plot...
               if (KDE_ISUNLIKELY(isinf(X1))) {
                 Y1 = Y2;
@@ -1144,6 +1177,12 @@
                 Y1 = Hy;
               }
 
+#ifdef DEBUG_VECTOR_CURVE
+qDebug() << "x in bounds" << ((X1 >= Lx && X1 <= Hx && X2 >= Lx && X2 <= Hx) ? "true" : "false")
+         << "y in bounds" << ((Y1 >= Ly && Y1 <= Hy && Y2 >= Ly && Y2 <= Hy) ? "true" : "false")
+         << endl;
+#endif
+
               if (X1 >= Lx && X1 <= Hx && X2 >= Lx && X2 <= Hx &&
                   Y1 >= Ly && Y1 <= Hy && Y2 >= Ly && Y2 <= Hy) {
                 int X1i = d2i(X1);
@@ -1151,20 +1190,36 @@
                 int X2i = d2i(X2);
                 int Y2i = d2i(Y2);
 
+#ifdef DEBUG_VECTOR_CURVE
+qDebug() << "MY POINTS ARE GOOD!!" << index << endl;
+#endif
+
                 if (KDE_ISUNLIKELY(index == 0)) {
+#ifdef DEBUG_VECTOR_CURVE
+qDebug() << "1063 index++" << index << endl;
+#endif
                   points.setPoint(index++, X2i, Y2i);
                   points.setPoint(index++, X1i, Y1i);
                 } else if (lastPlottedX == X2i &&
                     lastPlottedY == Y2i &&
                     index < MAX_NUM_POLYLINES) {
+#ifdef DEBUG_VECTOR_CURVE
+qDebug() << "1069 index++" << index << endl;
+#endif
                   points.setPoint(index++, X1i, Y1i);
                 } else {
                   if (KDE_ISLIKELY(index > 1)) {
                     QPolygon poly;
                     poly.putPoints(0, index, points);
+#ifdef DEBUG_VECTOR_CURVE
+qDebug() << "1168 drawPolyline" << poly << endl;
+#endif
                     p->drawPolyline(poly);
                   }
                   index = 0;
+#ifdef DEBUG_VECTOR_CURVE
+qDebug() << "1079 index++" << index << endl;
+#endif
                   points.setPoint(index++, X2i, Y2i);
                   points.setPoint(index++, X1i, Y1i);
                 }
@@ -1180,6 +1235,9 @@
       if (index > 1) {
         QPolygon poly;
         poly.putPoints(0, index, points);
+#ifdef DEBUG_VECTOR_CURVE
+qDebug() << "1187 drawPolyline" << poly << endl;
+#endif
         p->drawPolyline(poly);
         index = 0;
       }
@@ -1194,6 +1252,9 @@
             minY = Ly;
           }
           if (minY >= Ly && minY <= Hy && maxY >= Ly && maxY <= Hy) {
+#ifdef DEBUG_VECTOR_CURVE
+qDebug() << "1212 drawLine" << QLine(d2i(X2), d2i(minY), d2i(X2), d2i(maxY)) << endl;
+#endif
             p->drawLine(d2i(X2), d2i(minY), d2i(X2), d2i(maxY));
           }
         }


More information about the Kst mailing list