[Kst] kdeextragear-2/kst/kst

Andrew Walker arwalker at sumusltd.com
Thu Dec 9 01:56:08 CET 2004


CVS commit by arwalker: 

Make bars simpler and more efficient to draw.


  M +34 -33    kst2dplot.cpp   1.304


--- kdeextragear-2/kst/kst/kst2dplot.cpp  #1.303:1.304
@@ -5315,6 +5315,11 @@ void Kst2DPlot::plotCurves(QPainter& p,
         bool has_right = true;
         bool visible = true;
-        double drX, rX2=0;
+        double drX, rX2=0.0;
         int x0, y0, w, h;
+
+        if (c->barStyle() == 1) { // filled
+          p.setPen(QPen(_foregroundColor));
+        }
+
         drX = (c->maxX() - c->minX())/double(c->sampleCount());
         for (i_pt = i0; i_pt <= iN; i_pt++) {
@@ -5329,6 +5334,6 @@ void Kst2DPlot::plotCurves(QPainter& p,
             c->point(i_pt, rX, rY);
           }
-          rX-=drX/2.0;
-          rX2=rX+drX;
+          rX -= drX/2.0;
+          rX2 = rX + drX;
           if (_xLog) {
             rX = logX(rX);
@@ -5341,12 +5346,12 @@ void Kst2DPlot::plotCurves(QPainter& p,
           X1 = m_X * rX + b_X;
           X2 = m_X * rX2 + b_X;
-          if ((X1>Hx) || (X2<Lx)) {
+          if (X1 > Hx || X2 < Lx) {
             visible = false;
           } else {
-            if (X1<Lx) {
+            if (X1 < Lx) {
               has_left = false;
               X1 = Lx;
             }
-            if (X2>Hx) {
+            if (X2 > Hx) {
               has_right = false;
               X2 = Hx;
@@ -5354,18 +5359,22 @@ void Kst2DPlot::plotCurves(QPainter& p,
           }
 
-          // determine where the top visible of the bar is and whether
-          // to draw the top line.
+          //
+          // determine where the top of the bar is and whether
+          // to draw the top line
+          //
           Y1 = m_Y * rY + b_Y;
-          if (Y1<Ly) {
+          if (Y1 < Ly) {
             Y1 = Ly;
             has_top = false;
           }
-          if (Y1>Hy) {
+          if (Y1 > Hy) {
             Y1 = Hy;
             has_top = false;
           }
 
-          // determine where the bottom visible of the bar are is,
-          // and whether to draw the bottom line
+          //
+          // determine where the bottom of the bar is and whether
+          // to draw the bottom line
+          //
           if (_yLog) {
             Y2 = Hy;
@@ -5373,9 +5382,9 @@ void Kst2DPlot::plotCurves(QPainter& p,
           } else {
             Y2 = b_Y;
-            if (Y2<Ly) {
+            if (Y2 < Ly) {
               Y2 = Ly;
               has_bot = false;
             }
-            if (Y2>Hy) {
+            if (Y2 > Hy) {
               Y2 = Hy;
               has_bot = false;
@@ -5383,10 +5392,14 @@ void Kst2DPlot::plotCurves(QPainter& p,
           }
 
-          if ((Y1==Ly) && (Y2==Ly)) visible = false;
-          if ((Y1==Hy) && (Y2==Hy)) visible = false;
+          if (Y1==Ly && Y2==Ly) {
+            visible = false;
+          }
+          else if (Y1==Hy && Y2==Hy) {
+            visible = false;
+          }
 
           if (visible) {
             if (c->barStyle() == 1) { // filled
-              p.setPen(QPen(_foregroundColor));
+              p.fillRect(d2i(X1), d2i(Y1), d2i(X2)-d2i(X1), d2i(Y2)-d2i(Y1), c->color());
             }
             if (has_top) {
@@ -5402,21 +5415,8 @@ void Kst2DPlot::plotCurves(QPainter& p,
               p.drawLine(d2i(X2), d2i(Y1), d2i(X2), d2i(Y2));
             }
-            if (c->barStyle() == 1) { // filled
-              x0 = d2i(X1);
-              if (has_left) x0++;
-              y0 = d2i(Y1);
-              if (has_top) y0++;
-              w = d2i(X2)-d2i(X1)-1;
-              if (!has_left) w++;
-              if (!has_right) w++;
-              h = abs(d2i(Y2)-d2i(Y1))-1;
-              if (!has_top) h++;
-              if (!has_bot) h++;
-              if ((w>0) && (h>0)) {
-                p.fillRect(x0, y0, w, h, c->color());
-              }
-              p.setPen(QPen(c->color()));
             }
           }
+        if (c->barStyle() == 1) { // filled
+          p.setPen(QPen(c->color()));
         }
       }





More information about the Kst mailing list