[Kst] kdeextragear-2/kst

George Staikos staikos at kde.org
Fri Jun 18 00:53:44 CEST 2004


CVS commit by staikos: 

After another marathon of debugging, get X-axis border adjustments working
inward as well as outward.  Unfortunately it's also O(n^2) which somewhat
irritates me.


  M +0 -1      devel-docs/newviewtodo.txt   1.33
  M +41 -6     kst/kst2dplot.cpp   1.96
  M +3 -1      kst/kst2dplot.h   1.37


--- kdeextragear-2/kst/devel-docs/newviewtodo.txt  #1.32:1.33
@@ -40,5 +40,4 @@
 ---------
 - Frame # in status bar  <--- this isn't working in the old code either?!
-- X-left offset will never adjust inward again  (George)
 
 

--- kdeextragear-2/kst/kst/kst2dplot.cpp  #1.95:1.96
@@ -227,4 +227,5 @@ void Kst2DPlot::commonConstructor(const 
 
   _xLeft = -99999999;
+  _neededBorder = 0;
   _hasFocus = false;
   _copy_x = _copy_y = KST::NOPOINT;
@@ -776,4 +777,6 @@ double Kst2DPlot::getXBorder(QPainter& p
              YTick, Yorg, p);
 
+  _neededBorder = xleft_bdr_px;
+
   return xleft_bdr_px;
 }
@@ -966,7 +969,35 @@ void Kst2DPlot::triggerBorderAdjustments
   }
 
+#if 0
+  // DO NEVER DO THIS - causes reentrancy in the painter which is:
+  // 1) broken
+  // 2) bad
+  // 3) extremely time consuming to trace down
   for (QValueList<KstViewWindow*>::Iterator i = updateViews.begin(); i != updateViews.end(); ++i) {
     (*i)->view()->widget()->paint();
   }
+#endif
+}
+
+
+double Kst2DPlot::neededBorder() const {
+  return _neededBorder;
+}
+
+
+void Kst2DPlot::possiblyShrinkXBorders() {
+  kdDebug() << "Possibly shrink X borders - " << tagName() << endl;
+  double maxBorder = -99999999;
+  Kst2DPlotList pl = globalPlotList();
+  for (Kst2DPlotList::Iterator i = pl.begin(); i != pl.end(); ++i) {
+    double pmb = (*i)->neededBorder();
+    maxBorder = maxBorder > pmb ? maxBorder : pmb;
+  }
+
+  PlotDisplayManager *dm = PlotDisplayManager::self();
+  if (maxBorder < dm->xOffset) {
+    dm->xOffset = maxBorder;
+    triggerBorderAdjustments(maxBorder);
+  }
 }
 
@@ -974,4 +1005,5 @@ void Kst2DPlot::triggerBorderAdjustments
 void Kst2DPlot::paint(QPainter& p) {
   setpixrect(_geom.x(), _geom.y());
+  double old = neededBorder();
   double tmp = getXBorder(p);
   PlotDisplayManager *dm = PlotDisplayManager::self();
@@ -985,4 +1017,7 @@ void Kst2DPlot::paint(QPainter& p) {
     triggerBorderAdjustments(_xLeft);
   } else if (tmp < dm->xOffset) {
+    if (tmp != old) {
+      possiblyShrinkXBorders();
+    }
     _xLeft = dm->xOffset;
     draw();
@@ -991,6 +1026,4 @@ void Kst2DPlot::paint(QPainter& p) {
       _xLeft = tmp;
       draw();
-    } else {
-      _xLeft = tmp;
     }
   }
@@ -1005,13 +1038,15 @@ void Kst2DPlot::draw() {
   _buffer.buffer().fill(backgroundColor());
   QPainter p(&_buffer.buffer());
+  double old = neededBorder();
   double tmp = getXBorder(p);
   PlotDisplayManager *dm = PlotDisplayManager::self();
-  if (tmp > dm->xOffset) {
+  if (tmp > dm->xOffset) { // stretch out all the plots
     dm->xOffset = _xLeft = tmp;
     // Danger: recusion --  triggerBorderAdjustments(x);
-  } else if (tmp < dm->xOffset) {
+  } else if (tmp < dm->xOffset) {  // someone else is possibly bigger
+    if (tmp != old) {           // if we changed, try shrinking
+      possiblyShrinkXBorders();
+    }
     _xLeft = dm->xOffset;
-  } else {
-    _xLeft = tmp;
   }
   paint(p, dm->xOffset);

--- kdeextragear-2/kst/kst/kst2dplot.h  #1.36:1.37
@@ -170,4 +170,5 @@ public:
   void setHasFocus(bool hasFocus);
   void removeFocus(QPainter& p);
+  double neededBorder() const;
 
 public slots:
@@ -204,4 +205,5 @@ protected:
 
 private:
+  void possiblyShrinkXBorders();
   void triggerBorderAdjustments(double x);
   void updateTieBox(QPainter&);
@@ -231,5 +233,5 @@ private:
   double XMin, XMax, YMin, YMax;
   double _copy_x, _copy_y;
-  double _xLeft;
+  double _xLeft, _neededBorder;
 
   bool _xLog : 1, _yLog : 1;





More information about the Kst mailing list