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

Mike Fenton mike at staikos.net
Fri Mar 27 21:06:44 CET 2009


SVN commit 945618 by fenton:

Fix Zoom over-redrawing bugs.
Add proper invalidation of labels when global changes occur.


 M  +131 -60   plotitem.cpp  
 M  +8 -4      plotitem.h  


--- branches/work/kst/portto4/kst/src/libkstapp/plotitem.cpp #945617:945618
@@ -51,9 +51,6 @@
 // Benchmark drawing
 // #define BENCHMARK 1
 
-// FIXME:no magic numbers in pixels
-static qreal BOTTOM_MARGIN = 0.0;
-static qreal LEFT_MARGIN = 0.0;
 static const int PLOT_MAXIMIZED_ZORDER = 1000;
 
 namespace Kst {
@@ -87,6 +84,7 @@
   _allowUpdates(true),
   _updateDelayed(false),
   _legend(0),
+  _axisLabelsDirty(true),
   _zoomMenu(0),
   _filterMenu(0),
   _fitMenu(0),
@@ -625,17 +623,29 @@
 
 
 void PlotItem::paintPlot(QPainter *painter) {
+  bool xLabelsUpdated = false;
+  bool yLabelsUpdated = false;
   if (xAxis()->ticksUpdated()) {
     xAxis()->validateDrawingRegion(painter);
     updateXAxisLines();
     updateXAxisLabels(painter);
+    xLabelsUpdated = true;
   }
   if (yAxis()->ticksUpdated()) {
     yAxis()->validateDrawingRegion(painter);
     updateYAxisLines();
     updateYAxisLabels(painter);
+    yLabelsUpdated = true;
   }
 
+  if (_axisLabelsDirty) {
+    if (!xLabelsUpdated) {
+      updateXAxisLabels(painter);
+    }
+    if (!yLabelsUpdated) {
+      updateYAxisLabels(painter);
+    }
+  }
 #ifdef BENCHMARK
   QTime bench_time, benchtmp;
   int b_1 = 0, b_2 = 0, b_3 = 0, b_4 = 0, b_5 = 0;
@@ -1104,26 +1114,34 @@
 
 
 void PlotItem::setLeftPadding(const qreal padding) {
-  _leftPadding = padding;
-  setPlotRectsDirty();
+  if (padding != _leftPadding) {
+    _leftPadding = padding;
+    setPlotRectsDirty();
+  }
 }
 
 
 void PlotItem::setBottomPadding(const qreal padding) {
-  _bottomPadding = padding;
-  setPlotRectsDirty();
+  if (padding != _bottomPadding) {
+    _bottomPadding = padding;
+    setPlotRectsDirty();
+  }
 }
 
 
 void PlotItem::setRightPadding(const qreal padding) {
-  _rightPadding = padding;
-  setPlotRectsDirty();
+  if (padding != _rightPadding) {
+    _rightPadding = padding;
+    setPlotRectsDirty();
+  }
 }
 
 
 void PlotItem::setTopPadding(const qreal padding) {
-  _topPadding = padding;
-  setPlotRectsDirty();
+  if (padding != _topPadding) {
+    _topPadding = padding;
+    setPlotRectsDirty();
+  }
 }
 
 
@@ -1341,9 +1359,11 @@
 
 
 void PlotItem::setRightLabelFont(const QFont &font) {
-  _rightLabelFont = font;
-  setPlotBordersDirty(true);
-  setRightLabelDirty();
+  if (font != _rightLabelFont) {
+    _rightLabelFont = font;
+    setPlotBordersDirty(true);
+    setRightLabelDirty();
+  }
 }
 
 
@@ -1353,9 +1373,11 @@
 
 
 void PlotItem::setTopLabelFont(const QFont &font) {
-  _topLabelFont = font;
-  setPlotBordersDirty(true);
-  setTopLabelDirty();
+  if (font != _topLabelFont) {
+    _topLabelFont = font;
+    setPlotBordersDirty(true);
+    setTopLabelDirty();
+  }
 }
 
 
@@ -1365,7 +1387,11 @@
 
 
 void PlotItem::setGlobalFont(const QFont &font) {
-  _globalFont = font;
+  if (font != _globalFont) {
+    _globalFont = font;
+    setPlotBordersDirty(true);
+    setLabelsDirty();
+  }
 }
 
 
@@ -1375,9 +1401,11 @@
 
 
 void PlotItem::setLeftLabelFont(const QFont &font) {
-  _leftLabelFont = font;
-  setPlotBordersDirty(true);
-  setLeftLabelDirty();
+  if (font != _leftLabelFont) {
+    _leftLabelFont = font;
+    setPlotBordersDirty(true);
+    setLeftLabelDirty();
+  }
 }
 
 
@@ -1387,9 +1415,11 @@
 
 
 void PlotItem::setBottomLabelFont(const QFont &font) {
-  _bottomLabelFont = font;
-  setPlotBordersDirty(true);
-  setBottomLabelDirty();
+  if (font != _bottomLabelFont) {
+    _bottomLabelFont = font;
+    setPlotBordersDirty(true);
+    setBottomLabelDirty();
+  }
 }
 
 
@@ -1399,8 +1429,11 @@
 
 
 void PlotItem::setNumberLabelFont(const QFont &font) {
-  _numberLabelFont = font;
-  setPlotBordersDirty(true);
+  if (font != _numberLabelFont) {
+    _numberLabelFont = font;
+    setPlotBordersDirty(true);
+    setAxisLabelsDirty();
+  }
 }
 
 
@@ -1410,9 +1443,11 @@
 
 
 void PlotItem::setRightLabelFontScale(const qreal scale) {
-  _rightLabelFontScale = scale;
-  setPlotBordersDirty(true);
-  setRightLabelDirty();
+  if (scale != _rightLabelFontScale) {
+    _rightLabelFontScale = scale;
+    setPlotBordersDirty(true);
+    setRightLabelDirty();
+  }
 }
 
 
@@ -1422,7 +1457,11 @@
 
 
 void PlotItem::setGlobalFontScale(const qreal scale) {
-  _globalFontScale = scale;
+  if (scale != _globalFontScale) {
+    _globalFontScale = scale;
+    setPlotBordersDirty(true);
+    setLabelsDirty();
+  }
 }
 
 
@@ -1432,9 +1471,11 @@
 
 
 void PlotItem::setLeftLabelFontScale(const qreal scale) {
-  _leftLabelFontScale = scale;
-  setPlotBordersDirty(true);
-  setLeftLabelDirty();
+  if (scale != _leftLabelFontScale) {
+    _leftLabelFontScale = scale;
+    setPlotBordersDirty(true);
+    setLeftLabelDirty();
+  }
 }
 
 
@@ -1444,9 +1485,11 @@
 
 
 void PlotItem::setTopLabelFontScale(const qreal scale) {
-  _topLabelFontScale = scale;
-  setPlotBordersDirty(true);
-  setTopLabelDirty();
+  if (scale != _topLabelFontScale) {
+    _topLabelFontScale = scale;
+    setPlotBordersDirty(true);
+    setTopLabelDirty();
+  }
 }
 
 
@@ -1456,9 +1499,11 @@
 
 
 void PlotItem::setBottomLabelFontScale(const qreal scale) {
-  _bottomLabelFontScale = scale;
-  setPlotBordersDirty(true);
-  setBottomLabelDirty();
+  if (scale != _bottomLabelFontScale) {
+    _bottomLabelFontScale = scale;
+    setPlotBordersDirty(true);
+    setBottomLabelDirty();
+  }
 }
 
 
@@ -1468,8 +1513,11 @@
 
 
 void PlotItem::setNumberLabelFontScale(const qreal scale) {
-  _numberLabelFontScale = scale;
-  setPlotBordersDirty(true);
+  if (scale != _numberLabelFontScale) {
+    _numberLabelFontScale = scale;
+    setPlotBordersDirty(true);
+    setAxisLabelsDirty();
+  }
 }
 
 
@@ -1479,7 +1527,10 @@
 
 
 void PlotItem::setGlobalFontColor(const QColor &color) {
-  _globalFontColor = color;
+  if (color != _globalFontColor) {
+    _globalFontColor = color;
+    setLabelsDirty();
+  }
 }
 
 
@@ -1489,8 +1540,10 @@
 
 
 void PlotItem::setLeftLabelFontColor(const QColor &color) {
-  _leftLabelFontColor = color;
-  setLeftLabelDirty();
+  if (color != _leftLabelFontColor) {
+    _leftLabelFontColor = color;
+    setLeftLabelDirty();
+  }
 }
 
 
@@ -1500,8 +1553,10 @@
 
 
 void PlotItem::setRightLabelFontColor(const QColor &color) {
-  _rightLabelFontColor = color;
-  setRightLabelDirty();
+  if (color != _rightLabelFontColor) {
+    _rightLabelFontColor = color;
+    setRightLabelDirty();
+  }
 }
 
 
@@ -1511,8 +1566,10 @@
 
 
 void PlotItem::setTopLabelFontColor(const QColor &color) {
-  _topLabelFontColor = color;
-  setTopLabelDirty();
+  if (color != _topLabelFontColor) {
+    _topLabelFontColor = color;
+    setTopLabelDirty();
+  }
 }
 
 
@@ -1522,8 +1579,10 @@
 
 
 void PlotItem::setBottomLabelFontColor(const QColor &color) {
-  _bottomLabelFontColor = color;
-  setBottomLabelDirty();
+  if (color != _bottomLabelFontColor) {
+    _bottomLabelFontColor = color;
+    setBottomLabelDirty();
+  }
 }
 
 
@@ -1533,7 +1592,10 @@
 
 
 void PlotItem::setNumberLabelFontColor(const QColor &color) {
-  _numberLabelFontColor = color;
+  if (color != _numberLabelFontColor) {
+    _numberLabelFontColor = color;
+    setAxisLabelsDirty();
+  }
 }
 
 
@@ -1547,6 +1609,9 @@
 
 
 void PlotItem::setLeftLabelOverride(const QString &label) {
+  if (label == leftLabelOverride()) {
+    return;
+  }
   if (label == leftLabel()) {
     _leftLabelOverride.clear();
   } else {
@@ -1567,6 +1632,9 @@
 
 
 void PlotItem::setBottomLabelOverride(const QString &label) {
+  if (label == bottomLabelOverride()) {
+    return;
+  }
   if (label == bottomLabel()) {
     _bottomLabelOverride.clear();
   } else {
@@ -1587,6 +1655,9 @@
 
 
 void PlotItem::setTopLabelOverride(const QString &label) {
+  if (label == topLabelOverride()) {
+    return;
+  }
   if (label == topLabel()) {
     _topLabelOverride.clear();
   } else {
@@ -1607,6 +1678,9 @@
 
 
 void PlotItem::setRightLabelOverride(const QString &label) {
+  if (label == rightLabelOverride()) {
+    return;
+  }
   if (label == rightLabel()) {
     _rightLabelOverride.clear();
   } else {
@@ -1753,7 +1827,7 @@
 
 
 qreal PlotItem::leftLabelMargin() const {
-  qreal m = qMax(LEFT_MARGIN, _calculatedLeftLabelMargin);
+  qreal m = _calculatedLeftLabelMargin;
 
   //No more than 1/4 the width of the plot
   if (width() < m * 4)
@@ -1798,7 +1872,7 @@
 
 
 qreal PlotItem::bottomLabelMargin() const {
-  qreal m = qMax(BOTTOM_MARGIN, _calculatedBottomLabelMargin);
+  qreal m = _calculatedBottomLabelMargin;
 
   //No more than 1/4 the height of the plot
   if (height() < m * 4)
@@ -2369,11 +2443,8 @@
 
 
 void PlotItem::setShowLegend(const bool show) {
-  _showLegend = show;
-  if (show) {
-    legend()->setVisible(true);
-  } else {
-    legend()->setVisible(false);
+  if (show != _showLegend) {
+    legend()->setVisible(show);
   }
 }
 
@@ -2393,9 +2464,9 @@
 
     _projectionRect = rect;
     setPlotBordersDirty(true);
+    emit updateAxes();
+    update(); //slow, but need to update everything...
   }
-  emit updateAxes();
-  update(); //slow, but need to update everything...
 }
 
 
--- branches/work/kst/portto4/kst/src/libkstapp/plotitem.h #945617:945618
@@ -106,15 +106,16 @@
     SharedAxisBoxItem* sharedAxisBox();
     void setSharedAxisBox(SharedAxisBoxItem* parent);
 
-    qreal leftMarginSize() const;
     void setLeftPadding(const qreal);
-    qreal bottomMarginSize() const;
     void setBottomPadding(const qreal);
-    qreal rightMarginSize() const;
     void setRightPadding(const qreal);
-    qreal topMarginSize() const;
     void setTopPadding(const qreal);
 
+    qreal leftMarginSize() const;
+    qreal bottomMarginSize() const;
+    qreal rightMarginSize() const;
+    qreal topMarginSize() const;
+
     QString leftLabel() const;
     QString bottomLabel() const;
     QString rightLabel() const;
@@ -305,6 +306,8 @@
     void setBottomLabelDirty() { _bottomLabel.dirty = true; }
     void setLabelsDirty() { _leftLabel.dirty = true; _rightLabel.dirty = true; _topLabel.dirty = true; _bottomLabel.dirty = true; }
 
+    void setAxisLabelsDirty() { _axisLabelsDirty = true; }
+
   private:
     void createActions();
     void createZoomMenu();
@@ -463,6 +466,7 @@
 
     LegendItem* _legend;
 
+    bool _axisLabelsDirty;
     DrawnLabel _leftLabel;
     DrawnLabel _rightLabel;
     DrawnLabel _topLabel;


More information about the Kst mailing list