[Kst] extragear/graphics/kst/kst

George Staikos staikos at kde.org
Tue Dec 20 22:40:06 CET 2005


SVN commit 490138 by staikos:

Don't crash due to failed parsing of labels.
BUG: 118748


 M  +33 -14    kstplotlabel.cpp  
 M  +15 -11    kstviewlabel.cpp  


--- trunk/extragear/graphics/kst/kst/kstplotlabel.cpp #490137:490138
@@ -80,6 +80,7 @@
     _txt = text;
     reparse();
     computeTextSize();
+    //setDirty(true);
   }
 }
 
@@ -90,14 +91,20 @@
 
 
 void KstPlotLabel::setRotation(float rotation) {
-  _rotation = rotation;
-  _sinr = fabs(sin(_rotation * M_PI / 180.0));
-  _cosr = fabs(cos(_rotation * M_PI / 180.0));
+  if (_rotation != rotation) {
+    _rotation = rotation;
+    _sinr = fabs(sin(_rotation * M_PI / 180.0));
+    _cosr = fabs(cos(_rotation * M_PI / 180.0));
+    //setDirty(true);
+  }
 }
 
 
 void KstPlotLabel::setJustification(KstLJustifyType justify) {
-  _justify = justify;
+  if (_justify != justify) {
+    _justify = justify;
+    //setDirty(true);
+  }
 }
 
 
@@ -110,6 +117,7 @@
   if (_fontName != fontName) {
     _fontName = fontName;
     computeTextSize();
+    //setDirty(true);
   }
 }
 
@@ -123,12 +131,16 @@
   if (_interpret != interpreted) {
     _interpret = interpreted;
     reparse();
+    //setDirty(true);
   }
 }
 
 
 void KstPlotLabel::setDoScalarReplacement(bool replace) {
-  _replace = replace;
+  if (_replace != replace) {
+    _replace = replace;
+    //setDirty(true);
+  }
 }
 
 
@@ -145,18 +157,22 @@
   p.translate(tx, ty);
   p.rotate(_rotation);
 
-  renderLabel(rc, lp->chunk);
+  if (lp && lp->chunk) {
+    renderLabel(rc, lp->chunk);
+  }
 }
 
 
 void KstPlotLabel::computeTextSize() {
-  RenderContext rc(_fontName, _absFontSize, 0L);
-  rc.setSubstituteScalars(_replace);
-  renderLabel(rc, _parsed->chunk);
-  _textWidth = rc.x;
-  _ascent = rc.ascent;
-  _textHeight = 1 + rc.ascent + rc.descent;
-  _lineSpacing = QFontMetrics(QFont(_fontName, _absFontSize)).lineSpacing();
+  if (_parsed && _parsed->chunk) {
+    RenderContext rc(_fontName, _absFontSize, 0L);
+    rc.setSubstituteScalars(_replace);
+    renderLabel(rc, _parsed->chunk);
+    _textWidth = rc.x;
+    _ascent = rc.ascent;
+    _textHeight = 1 + rc.ascent + rc.descent;
+    _lineSpacing = QFontMetrics(QFont(_fontName, _absFontSize)).lineSpacing();
+  }
 }
 
 
@@ -166,7 +182,10 @@
 
 
 void KstPlotLabel::setFontSize(int size) {
-  _fontSize = size;
+  if (_fontSize != size) {
+    _fontSize = size;
+    //setDirty(true);
+  }
 }
 
 
--- trunk/extragear/graphics/kst/kst/kstviewlabel.cpp #490137:490138
@@ -292,7 +292,9 @@
   QTime t;
   t.start();
 #endif
-  renderLabel(rc, lp->chunk);
+  if (lp && lp->chunk) {
+    renderLabel(rc, lp->chunk);
+  }
 #ifdef BENCHMARK
   kstdDebug() << "render took: " << t.elapsed() << endl;
   t.start();
@@ -305,20 +307,22 @@
 
 
 void KstViewLabel::computeTextSize(Label::Parsed *lp) {
-  RenderContext rc(_fontName, _absFontSize, 0L);
-  rc.setSubstituteScalars(_replace);
-  rc.precision = _dataPrecision;
+  if (lp && lp->chunk) {
+    RenderContext rc(_fontName, _absFontSize, 0L);
+    rc.setSubstituteScalars(_replace);
+    rc.precision = _dataPrecision;
 #ifdef BENCHMARK
-  QTime t;
-  t.start();
+    QTime t;
+    t.start();
 #endif
-  renderLabel(rc, lp->chunk);
+    renderLabel(rc, lp->chunk);
 #ifdef BENCHMARK
-  kstdDebug() << "compute (false render) took: " << t.elapsed() << endl;
+    kstdDebug() << "compute (false render) took: " << t.elapsed() << endl;
 #endif
-  _textWidth = rc.xMax;
-  _ascent = rc.ascent;
-  _textHeight = 1 + rc.ascent + rc.descent;
+    _textWidth = rc.xMax;
+    _ascent = rc.ascent;
+    _textHeight = 1 + rc.ascent + rc.descent;
+  }
 }
 
 


More information about the Kst mailing list