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

Adam Treat treat at kde.org
Fri Aug 3 05:04:47 CEST 2007


SVN commit 695832 by treat:

* No longer hard code the zoom box.  Now it
is calculated to display the first 100 points.


 M  +1 -1      libkstapp/plotitem.cpp  
 M  +38 -17    libkstapp/vectorcurverenderitem.cpp  
 M  +34 -19    libkstmath/kstvcurve.cpp  


--- branches/work/kst/portto4/kst/src/libkstapp/plotitem.cpp #695831:695832
@@ -31,7 +31,7 @@
 
   // FIXME fake data for testing rendering
   KstVectorPtr xTest = new KstSVector(0.0, 100.0, 10000, KstObjectTag::fromString("X vector"));
-  KstVectorPtr yTest = new KstSVector(0.0, 100.0, 10000, KstObjectTag::fromString("Y vector"));
+  KstVectorPtr yTest = new KstSVector(-100.0, 100.0, 10000, KstObjectTag::fromString("Y vector"));
 
   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"));
--- branches/work/kst/portto4/kst/src/libkstapp/vectorcurverenderitem.cpp #695831:695832
@@ -13,6 +13,9 @@
 
 #include <QDebug>
 
+//FIXME how many?
+static int DESIRED_NUMBER_OF_POINTS_FOR_INITIAL_VIEW = 100;
+
 namespace Kst {
 
 VectorCurveRenderItem::VectorCurveRenderItem(const QString &name)
@@ -26,28 +29,50 @@
 
 void VectorCurveRenderItem::paint(QPainter *painter) {
   foreach (KstRelationPtr relation, relationList()) {
+    //FIXME static_cast to kstvcurve and take advantage of extra api
+
     KstCurveRenderContext context;
     context.painter = painter;
     context.window = range().toRect(); //no idea if this should be floating point
 
-    //Everything that comes next is magic...  I took most from kst2dplot, hints
-    //from barth and trial and error...
+    //FIXME rename these methods in kstvcurve
+    QRectF vectorRect(relation->minX(),
+                      relation->minY(),
+                      relation->maxX(),
+                      relation->maxY());
 
-    //These are the region of the plot in vector coord
-    context.XMin = 0.0;
-    context.XMax = 0.1;
-    context.YMin = 0.0;
-    context.YMax = 0.1;
+    QTransform t;
+    qreal scaleFactor = 1.0 / (relation->sampleCount() / DESIRED_NUMBER_OF_POINTS_FOR_INITIAL_VIEW);
+    t.scale(scaleFactor, scaleFactor);
 
+    QRectF zoomRect = t.mapRect(vectorRect);
+    zoomRect.moveTopLeft(vectorRect.topLeft());
+
+    //FIXME this should no longer be called range...
+    QRectF plotRect = range();
+
+//     qDebug() << "============================================================>"
+//              << "vectorRect" << vectorRect
+//              << "zoombox" << zoomRect
+//              << "plotRect" << plotRect << endl;
+
+    //FIXME Completely refactor KstCurveRenderContext now that we know what these are
+
+    //Set what amounts to the zoombox...
+    context.XMin = zoomRect.left();
+    context.XMax = zoomRect.right();
+    context.YMin = zoomRect.top();
+    context.YMax = zoomRect.bottom();
+
     //These are the bounding box in regular QGV coord
-    context.Lx = range().left();
-    context.Hx = range().right();
-    context.Ly = range().top();
-    context.Hy = range().bottom();
+    context.Lx = plotRect.left();
+    context.Hx = plotRect.right();
+    context.Ly = plotRect.top();
+    context.Hy = plotRect.bottom();
 
     //To convert between the last two...
-    double m_X =  double(range().width()-1)/(context.XMax - context.XMin);
-    double m_Y = -double(range().height()-1)/(context.YMax - context.YMin);
+    double m_X =  double(plotRect.width()-1)/(context.XMax - context.XMin);
+    double m_Y = -double(plotRect.height()-1)/(context.YMax - context.YMin);
     double b_X = context.Lx - m_X * context.XMin;
     double b_Y = context.Ly - m_Y * context.YMax;
 
@@ -57,10 +82,6 @@
     context.b_Y = b_Y;
 
     painter->save();
-
-//     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 #695831:695832
@@ -34,7 +34,7 @@
 
 #include <time.h>
 
-// #define DEBUB_VECTOR_CURVE
+// #define DEBUG_VECTOR_CURVE
 
 #ifndef KDE_IS_LIKELY
 #if __GNUC__ - 0 >= 3
@@ -976,7 +976,7 @@
             QPolygon poly;
             poly.putPoints(0, index, points);
 #ifdef DEBUG_VECTOR_CURVE
-qDebug() << "976 drawPolyline" << poly << endl;
+qDebug() << __LINE__ << "drawPolyline" << poly << endl;
 #endif
             p->drawPolyline(poly);
           }
@@ -989,7 +989,7 @@
                 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;
+qDebug() << __LINE__ << "drawLine" << QLine(d2i(X2), d2i(minY), d2i(X2), d2i(maxY)) << endl;
 #endif
                 p->drawLine(d2i(X2), d2i(minY), d2i(X2), d2i(maxY));
               }
@@ -1042,37 +1042,37 @@
                     QPolygon poly;
                     poly.putPoints(0, index, points);
 #ifdef DEBUG_VECTOR_CURVE
-qDebug() << "1037 drawPolyline" << poly << endl;
+qDebug() << __LINE__ << "drawPolyline" << poly << endl;
 #endif
                     p->drawPolyline(poly);
                     index = 0;
                   }
                   if (KDE_ISUNLIKELY(minYi == maxYi)) {
 #ifdef DEBUG_VECTOR_CURVE
-qDebug() << "1042 index++" << index << endl;
+qDebug() << __LINE__ << "index++" << index << endl;
 #endif
                     points.setPoint(index++, X2i, maxYi);
                   } else if (KDE_ISUNLIKELY(Y2 == minY)) {
 #ifdef DEBUG_VECTOR_CURVE
-qDebug() << "1045 index++" << index << endl;
+qDebug() << __LINE__ << "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;
+qDebug() << __LINE__ << "index++" << index << endl;
 #endif
                     points.setPoint(index++, X2i, minYi);
                     points.setPoint(index++, X2i, maxYi);
                   } else {
 #ifdef DEBUG_VECTOR_CURVE
-qDebug() << "1053 index++" << index << endl;
+qDebug() << __LINE__ << "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;
+qDebug() << __LINE__ << "index++" << index << endl;
 #endif
                       points.setPoint(index++, X2i, Y2i);
                     }
@@ -1091,13 +1091,13 @@
                       QPolygon poly;
                       poly.putPoints(0, index, points);
 #ifdef DEBUG_VECTOR_CURVE
-qDebug() << "1069 drawPolyline" << poly << endl;
+qDebug() << __LINE__ << "drawPolyline" << poly << endl;
 #endif
                       p->drawPolyline(poly);
                       index = 0;
                     }
 #ifdef DEBUG_VECTOR_CURVE
-qDebug() << "1079 drawLine" << QLine(X2i, d2i(minY), X2i, d2i(maxY)) << endl;
+qDebug() << __LINE__ << "drawLine" << QLine(X2i, d2i(minY), X2i, d2i(maxY)) << endl;
 #endif
                     p->drawLine(X2i, d2i(minY), X2i, d2i(maxY));
                   }
@@ -1177,10 +1177,25 @@
                 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")
+bool xInBounds = (X1 >= Lx && X1 <= Hx && X2 >= Lx && X2 <= Hx);
+bool yInBounds = (Y1 >= Ly && Y1 <= Hy && Y2 >= Ly && Y2 <= Hy);
+
+if (!xInBounds)
+qDebug() << "x not in bounds"
+         << "X1:" << X1
+         << "X2:" << X2
+         << "Lx:" << Lx
+         << "Hx:" << Hx
          << endl;
+if (!yInBounds)
+qDebug() << "y not in bounds"
+         << "Y1:" << Y1
+         << "Y2:" << Y2
+         << "Ly:" << Ly
+         << "Hy:" << Hy
+         << endl;
 #endif
 
               if (X1 >= Lx && X1 <= Hx && X2 >= Lx && X2 <= Hx &&
@@ -1196,7 +1211,7 @@
 
                 if (KDE_ISUNLIKELY(index == 0)) {
 #ifdef DEBUG_VECTOR_CURVE
-qDebug() << "1063 index++" << index << endl;
+qDebug() << __LINE__ << "index++" << index << endl;
 #endif
                   points.setPoint(index++, X2i, Y2i);
                   points.setPoint(index++, X1i, Y1i);
@@ -1204,7 +1219,7 @@
                     lastPlottedY == Y2i &&
                     index < MAX_NUM_POLYLINES) {
 #ifdef DEBUG_VECTOR_CURVE
-qDebug() << "1069 index++" << index << endl;
+qDebug() << __LINE__ << "index++" << index << endl;
 #endif
                   points.setPoint(index++, X1i, Y1i);
                 } else {
@@ -1212,13 +1227,13 @@
                     QPolygon poly;
                     poly.putPoints(0, index, points);
 #ifdef DEBUG_VECTOR_CURVE
-qDebug() << "1168 drawPolyline" << poly << endl;
+qDebug() << __LINE__ << "drawPolyline" << poly << endl;
 #endif
                     p->drawPolyline(poly);
                   }
                   index = 0;
 #ifdef DEBUG_VECTOR_CURVE
-qDebug() << "1079 index++" << index << endl;
+qDebug() << __LINE__ << "index++" << index << endl;
 #endif
                   points.setPoint(index++, X2i, Y2i);
                   points.setPoint(index++, X1i, Y1i);
@@ -1236,7 +1251,7 @@
         QPolygon poly;
         poly.putPoints(0, index, points);
 #ifdef DEBUG_VECTOR_CURVE
-qDebug() << "1187 drawPolyline" << poly << endl;
+qDebug() << __LINE__ << "drawPolyline" << poly << endl;
 #endif
         p->drawPolyline(poly);
         index = 0;
@@ -1253,7 +1268,7 @@
           }
           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;
+qDebug() << __LINE__ << "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