[Kst] extragear/graphics/kst/kst

Andrew Walker arwalker at sumusltd.com
Tue Dec 20 21:56:15 CET 2005


SVN commit 490115 by arwalker:

if there are no curves to plot for a legend then display a blank legend of reasonable size. We do not want to hide the legend as then there would be no way for the user to edit the legend contents

 M  +26 -21    kstviewlegend.cpp  


--- trunk/extragear/graphics/kst/kst/kstviewlegend.cpp #490114:490115
@@ -214,32 +214,37 @@
   _ascent = 0;
   _textHeight = 0;
 
-  for (KstBaseCurveList::Iterator it = _curves.begin(); it != _curves.end(); it++) {
-    if ((*it)->parsedLegendTag()) {
-      RenderContext rc(_fontName, _absFontSize, 0L);
-      renderLabel(rc, (*it)->parsedLegendTag()->chunk);
-      if (_vertical) {
-        if (rc.xMax>_textWidth) {
-          _textWidth = rc.xMax;
+  RenderContext rc(_fontName, _absFontSize, 0L);
+  if (_curves.count() == 0) {
+    _ascent = rc.fontAscent();
+    _textWidth  = _ascent;
+    _textHeight = _ascent;
+  } else {
+    for (KstBaseCurveList::Iterator it = _curves.begin(); it != _curves.end(); it++) {
+      if ((*it)->parsedLegendTag()) {
+        renderLabel(rc, (*it)->parsedLegendTag()->chunk);
+        if (_vertical) {
+          if (rc.xMax>_textWidth) {
+            _textWidth = rc.xMax;
+          }
+        } else {
+          if (rc.fontHeight() > _textHeight) {
+            _textHeight = rc.fontHeight();
+          }
+          _textWidth += rc.xMax;
         }
+        (*it)->setLegendLabelSize(QSize(rc.xMax, rc.fontHeight()));
       } else {
-        if (rc.fontHeight() > _textHeight) {
-          _textHeight = rc.fontHeight();
-        }
-        _textWidth += rc.xMax;
+        (*it)->setLegendLabelSize(QSize(0,0));
       }
-      (*it)->setLegendLabelSize(QSize(rc.xMax, rc.fontHeight()));
+    }
+    _ascent = rc.fontAscent();
+    if (_vertical) {
+      _textHeight = _curves.count()*rc.fontHeight() + (_curves.count()-1)*_ascent/4;
     } else {
-      (*it)->setLegendLabelSize(QSize(0,0));
+      _textWidth += _curves.count()*_ascent;
     }
   }
-  RenderContext rc(_fontName, _absFontSize, 0L);
-  _ascent = rc.fontAscent();
-  if (_vertical) {
-    _textHeight = _curves.count()*rc.fontHeight() + (_curves.count()-1)*_ascent/4;
-  } else {
-    _textWidth += _curves.count()*_ascent;
-  }
 }
 
 
@@ -248,7 +253,7 @@
     p.save();
     adjustSizeForText(p.window());
     p.setViewport(geometry());
-    p.setWindow(0,0,geometry().width(), geometry().height());
+    p.setWindow(0, 0, geometry().width(), geometry().height());
     drawToPainter(p);
     //setDirty();
     p.restore();


More information about the Kst mailing list