[Kst] extragear/graphics/kst/kst

George Staikos staikos at kde.org
Wed Jul 13 23:02:16 CEST 2005


SVN commit 434379 by staikos:

add rendering of vector indexing and fix parsing of embedded equations.


 M  +2 -1      labelparser.cpp  
 M  +23 -0     labelrenderer.cpp  


--- trunk/extragear/graphics/kst/kst/labelparser.cpp #434378:434379
@@ -340,6 +340,7 @@
           int vectorIndexEnd = -1;
           int bracketStack = 1;
           int pos = -1;
+          bool equation = txt[i + 1] == '=';
           for (uint searchPt = i + 1; bracketStack != 0 && searchPt < cnt; ++searchPt) {
             if (txt[searchPt] == ']') {
               if (--bracketStack == 0) {
@@ -350,7 +351,7 @@
               }
             } else if (txt[searchPt] == '[') {
               ++bracketStack;
-              if (!vector) {
+              if (!vector && !equation) {
                 vector = true;
                 vectorIndexStart = searchPt + 1;
               }
--- trunk/extragear/graphics/kst/kst/labelrenderer.cpp #434378:434379
@@ -91,6 +91,29 @@
         rc.p->drawText(rc.x, rc.y, txt);
       }
       rc.x += rc.fontWidth(txt);
+    } else if (fi->vector) {
+      QString txt;
+      KST::vectorList.lock().readLock();
+      KstVectorPtr vp = *KST::vectorList.findTag(fi->text);
+      KST::vectorList.lock().readUnlock();
+      if (vp) {
+        if (!fi->expression.isEmpty()) {
+          // Parse and evaluate as an equation
+          bool ok = false;
+          double idx = Equation::interpret(fi->expression.latin1(), &ok);
+          if (ok) {
+            vp->readLock();
+            txt = QString::number(vp->value()[int(idx)]);
+            vp->readUnlock();
+          } else {
+            txt = "NAN";
+          }
+        }
+      }
+      if (rc.p) {
+        rc.p->drawText(rc.x, rc.y, txt);
+      }
+      rc.x += rc.fontWidth(txt);
     } else if (fi->tab) {
       int tabWidth = rc.fontWidth("MMMMMMMM");
       rc.x += tabWidth - (rc.x - rc.xStart) % tabWidth;


More information about the Kst mailing list