[Kst] branches/work/kst/1.5/kst/src

Andrew Walker arwalker at sumusltd.com
Sat Sep 15 00:44:59 CEST 2007


SVN commit 712628 by arwalker:

allow user to set point style from javaScript and remove confusion between line style and point style

 M  +27 -1     extensions/js/bind_curve.cpp  
 M  +15 -2     extensions/js/bind_curve.h  
 M  +4 -4      libkstapp/kstcurvedialog_i.cpp  
 M  +3 -3      libkstapp/kstcurvedifferentiate_i.cpp  
 M  +4 -4      libkstapp/kstdatawizard_i.cpp  
 M  +3 -3      libkstapp/ksteqdialog_i.cpp  
 M  +2 -3      libkstapp/kstfilterdialog_i.cpp  
 M  +1 -1      libkstapp/kstfitdialog_i.cpp  
 M  +1 -1      libkstapp/ksthsdialog_i.cpp  
 M  +1 -1      libkstapp/kstpsddialog_i.cpp  
 M  +1 -1      libkstapp/kstvvdialog_i.cpp  
 M  +19 -10    libkstmath/kstvcurve.cpp  
 M  +15 -19    libkstmath/kstvcurve.h  


--- branches/work/kst/1.5/kst/src/extensions/js/bind_curve.cpp #712627:712628
@@ -176,6 +176,7 @@
   { "hasLines", &KstBindCurve::setHasLines, &KstBindCurve::hasLines },
   { "hasBars", &KstBindCurve::setHasBars, &KstBindCurve::hasBars },
   { "lineWidth", &KstBindCurve::setLineWidth, &KstBindCurve::lineWidth },
+  { "pointStyle", &KstBindCurve::setPointStyle, &KstBindCurve::pointStyle },
   { "lineStyle", &KstBindCurve::setLineStyle, &KstBindCurve::lineStyle },
   { "barStyle", &KstBindCurve::setBarStyle, &KstBindCurve::barStyle },
   { "pointDensity", &KstBindCurve::setPointDensity, &KstBindCurve::pointDensity },
@@ -763,6 +764,32 @@
 }
 
 
+void KstBindCurve::setPointStyle(KJS::ExecState *exec, const KJS::Value& value) {
+  unsigned i = 0;
+  if (value.type() != KJS::NumberType || !value.toUInt32(i)) {
+    KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError);
+    exec->setException(eobj);
+    return;
+  }
+  KstVCurvePtr d = makeCurve(_d);
+  if (d) {
+    KstWriteLocker wl(d);
+    d->setPointStyle(i);
+  }
+}
+
+
+KJS::Value KstBindCurve::pointStyle(KJS::ExecState *exec) const {
+  Q_UNUSED(exec)
+  KstVCurvePtr d = makeCurve(_d);
+  if (d) {
+    KstReadLocker rl(d);
+    return KJS::Number(d->pointStyle());
+  }
+  return KJS::Number(0);
+}
+
+
 void KstBindCurve::setLineStyle(KJS::ExecState *exec, const KJS::Value& value) {
   unsigned i = 0;
   if (value.type() != KJS::NumberType || !value.toUInt32(i)) {
@@ -850,4 +877,3 @@
 
 #undef makeCurve
 
-// vim: ts=2 sw=2 et
--- branches/work/kst/1.5/kst/src/extensions/js/bind_curve.h #712627:712628
@@ -180,8 +180,8 @@
     */
     void setLineWidth(KJS::ExecState *exec, const KJS::Value& value);
     KJS::Value lineWidth(KJS::ExecState *exec) const;
-    /* @property number lineStyle
-       @description Sets the line style for this curve when lines are drawn.
+    /* @property number pointStyle
+       @description Sets the point style for this curve when points are drawn.
                     <ul>
                     <li>0 - Cross</li>
                     <li>1 - Hollow box</li>
@@ -196,8 +196,21 @@
                     <li>10 - Filled triangle</li>
                     <li>11 - Hollow diamond</li>
                     <li>12 - Filled diamond</li>
+                    <li>13 - Point</li>
                     </ul>
     */
+    void setPointStyle(KJS::ExecState *exec, const KJS::Value& value);
+    KJS::Value pointStyle(KJS::ExecState *exec) const;
+    /* @property number lineStyle
+       @description Sets the line style for this curve when lines are drawn.
+                    <ul>
+                    <li>0 - Soild</li>
+                    <li>1 - Dash</li>
+                    <li>2 - Dot</li>
+                    <li>3 - Dash Dot</li>
+                    <li>4 - Dash Dot Dot</li>
+                    </ul>
+    */
     void setLineStyle(KJS::ExecState *exec, const KJS::Value& value);
     KJS::Value lineStyle(KJS::ExecState *exec) const;
     /* @property number barStyle
--- branches/work/kst/1.5/kst/src/libkstapp/kstcurvedialog_i.cpp #712627:712628
@@ -157,7 +157,7 @@
 
   _w->_curveAppearance->setValue(cp->hasLines(), cp->hasPoints(),
       cp->hasBars(), cp->color(),
-      cp->pointType, cp->lineWidth(),
+      cp->pointStyle(), cp->lineWidth(),
       cp->lineStyle(), cp->barStyle(), cp->pointDensity());
 
   _w->_checkBoxIgnoreAutoscale->setChecked(cp->ignoreAutoScale());
@@ -295,13 +295,13 @@
   } else {
     curve->setLegendText(legend_text);
   }
-  
+
   curve->setHasPoints(_w->_curveAppearance->showPoints());
   curve->setHasLines(_w->_curveAppearance->showLines());
   curve->setHasBars(_w->_curveAppearance->showBars());
   curve->setLineWidth(_w->_curveAppearance->lineWidth());
   curve->setLineStyle(_w->_curveAppearance->lineStyle());
-  curve->pointType = _w->_curveAppearance->pointType();
+  curve->setPointStyle(_w->_curveAppearance->pointType());
   curve->setBarStyle(_w->_curveAppearance->barStyle());
   curve->setPointDensity(_w->_curveAppearance->pointDensity());
   curve->setIgnoreAutoScale(_w->_checkBoxIgnoreAutoscale->isChecked());
@@ -421,7 +421,7 @@
   }
 
   if (_comboDirty) {
-    cvPtr->pointType = _w->_curveAppearance->pointType();
+    cvPtr->setPointStyle(_w->_curveAppearance->pointType());
   }
 
   if (_barStyleDirty) {
--- branches/work/kst/1.5/kst/src/libkstapp/kstcurvedifferentiate_i.cpp #712627:712628
@@ -267,7 +267,7 @@
           (*i)->setColor(KstColorSequence::entry(_lineColorSeq.current()));
         }
         if (_pointStyleOrder > -1) {
-          (*i)->pointType = _pointStyleSeq.current();
+          (*i)->setPointStyle(_pointStyleSeq.current());
           (*i)->setHasPoints(true);
           (*i)->setPointDensity(_pointDensity);
         }
@@ -278,7 +278,7 @@
           (*i)->setLineWidth(_lineWidthSeq.current());
         }
 
-        (_seqVect[0])->next();        
+        (_seqVect[0])->next();
       }
     }
   }
@@ -356,4 +356,4 @@
 }
 
 #include "kstcurvedifferentiate_i.moc"
-// vim: ts=2 sw=2 et
+
--- branches/work/kst/1.5/kst/src/libkstapp/kstdatawizard_i.cpp #712627:712628
@@ -1052,14 +1052,14 @@
         c->setLineWidth(KstSettings::globalSettings()->defaultLineWeight);
         if (_drawBoth->isChecked()) {
           c->setHasPoints(true);
-          c->pointType = pointType++ % KSTPOINT_MAXTYPE;
+          c->setPointStyle(pointType++ % KSTPOINT_MAXTYPE);
           c->setHasLines(true);
         } else if (_drawLines->isChecked()) {
           c->setHasPoints(false);
           c->setHasLines(true);
         } else {
           c->setHasPoints(true);
-          c->pointType = pointType++ % KSTPOINT_MAXTYPE;
+          c->setPointStyle(pointType++ % KSTPOINT_MAXTYPE);
           c->setHasLines(false);
         }
         KST::dataObjectList.lock().writeLock();
@@ -1140,14 +1140,14 @@
           c->setLineWidth(KstSettings::globalSettings()->defaultLineWeight);
           if (_drawBoth->isChecked()) {
             c->setHasPoints(true);
-            c->pointType = pointType++ % KSTPOINT_MAXTYPE;
+            c->setPointStyle(pointType++ % KSTPOINT_MAXTYPE);
             c->setHasLines(true);
           } else if (_drawLines->isChecked()) {
             c->setHasPoints(false);
             c->setHasLines(true);
           } else {
             c->setHasPoints(true);
-            c->pointType = pointType++ % KSTPOINT_MAXTYPE;
+            c->setPointStyle(pointType++ % KSTPOINT_MAXTYPE);
             c->setHasLines(false);
           }
           KST::dataObjectList.lock().writeLock();
--- branches/work/kst/1.5/kst/src/libkstapp/ksteqdialog_i.cpp #712627:712628
@@ -207,10 +207,10 @@
   vc->setHasBars(_w->_curveAppearance->showBars());
   vc->setLineWidth(_w->_curveAppearance->lineWidth());
   vc->setLineStyle(_w->_curveAppearance->lineStyle());
-  vc->pointType = _w->_curveAppearance->pointType();
+  vc->setPointStyle(_w->_curveAppearance->pointType());
   vc->setPointDensity(_w->_curveAppearance->pointDensity());
   vc->setBarStyle(_w->_curveAppearance->barStyle());
-  
+
   QString legend_text = _legendText->text();
   if (legend_text == defaultTag) {
     vc->setLegendText(QString(""));
@@ -453,4 +453,4 @@
 }
 
 #include "ksteqdialog_i.moc"
-// vim: ts=2 sw=2 et
+
--- branches/work/kst/1.5/kst/src/libkstapp/kstfilterdialog_i.cpp #712627:712628
@@ -210,7 +210,7 @@
   fit->setHasBars(_w->_curveAppearance->showBars());
   fit->setLineWidth(_w->_curveAppearance->lineWidth());
   fit->setLineStyle(_w->_curveAppearance->lineStyle());
-  fit->pointType = _w->_curveAppearance->pointType();
+  fit->setPointStyle(_w->_curveAppearance->pointType());
   fit->setBarStyle(_w->_curveAppearance->barStyle());
   fit->setPointDensity(_w->_curveAppearance->pointDensity());
 
@@ -225,6 +225,7 @@
   KST::dataObjectList.lock().writeLock();
   KST::dataObjectList.append(fit.data());
   KST::dataObjectList.lock().unlock();
+
   return true;
 }
 
@@ -411,7 +412,5 @@
   }
 }
 
-
 #include "kstfilterdialog_i.moc"
 
-// vim: ts=2 sw=2 et
--- branches/work/kst/1.5/kst/src/libkstapp/kstfitdialog_i.cpp #712627:712628
@@ -146,7 +146,7 @@
   fit->setHasBars(_w->_curveAppearance->showBars());
   fit->setLineWidth(_w->_curveAppearance->lineWidth());
   fit->setLineStyle(_w->_curveAppearance->lineStyle());
-  fit->pointType = _w->_curveAppearance->pointType();
+  fit->setPointStyle(_w->_curveAppearance->pointType());
   fit->setBarStyle(_w->_curveAppearance->barStyle());
   fit->setPointDensity(_w->_curveAppearance->pointDensity());
 
--- branches/work/kst/1.5/kst/src/libkstapp/ksthsdialog_i.cpp #712627:712628
@@ -229,7 +229,7 @@
   vc->setHasPoints(_w->_curveAppearance->showPoints());
   vc->setHasLines(_w->_curveAppearance->showLines());
   vc->setHasBars(_w->_curveAppearance->showBars());
-  vc->pointType = _w->_curveAppearance->pointType();
+  vc->setPointStyle(_w->_curveAppearance->pointType());
   vc->setLineWidth(_w->_curveAppearance->lineWidth());
   vc->setLineStyle(_w->_curveAppearance->lineStyle());
   vc->setBarStyle(_w->_curveAppearance->barStyle());
--- branches/work/kst/1.5/kst/src/libkstapp/kstpsddialog_i.cpp #712627:712628
@@ -193,7 +193,7 @@
     vc->setHasPoints(_w->_curveAppearance->showPoints());
     vc->setHasLines(_w->_curveAppearance->showLines());
     vc->setHasBars(_w->_curveAppearance->showBars());
-    vc->pointType = _w->_curveAppearance->pointType();
+    vc->setPointStyle(_w->_curveAppearance->pointType());
     vc->setLineWidth(_w->_curveAppearance->lineWidth());
     vc->setLineStyle(_w->_curveAppearance->lineStyle());
     vc->setBarStyle(_w->_curveAppearance->barStyle());
--- branches/work/kst/1.5/kst/src/libkstapp/kstvvdialog_i.cpp #712627:712628
@@ -304,7 +304,7 @@
   vc->setHasPoints(_w->_curveAppearance->showPoints());
   vc->setHasLines(_w->_curveAppearance->showLines());
   vc->setHasBars(_w->_curveAppearance->showBars());
-  vc->pointType = _w->_curveAppearance->pointType();
+  vc->setPointStyle(_w->_curveAppearance->pointType());
   vc->setLineWidth(_w->_curveAppearance->lineWidth());
   vc->setLineStyle(_w->_curveAppearance->lineStyle());
   vc->setBarStyle(_w->_curveAppearance->barStyle());
--- branches/work/kst/1.5/kst/src/libkstmath/kstvcurve.cpp #712627:712628
@@ -152,7 +152,7 @@
       } else if (e.tagName() == "hasBars") {
         HasBars = e.text() != "0";
       } else if (e.tagName() == "pointType") {
-        pointType = e.text().toInt();
+        PointStyle = e.text().toInt();
       } else if (e.tagName() == "lineWidth") {
         LineWidth = e.text().toInt();
       } else if (e.tagName() == "lineStyle") {
@@ -514,7 +514,7 @@
   if (HasPoints) {
     ts << l2 << "<hasPoints/>" << endl;
   }
-  ts << l2 << "<pointType>" << pointType << "</pointType>" << endl;
+  ts << l2 << "<pointType>" << PointStyle << "</pointType>" << endl;
   ts << l2 << "<pointDensity>" << PointDensity << "</pointDensity>" << endl;
   if (HasBars) {
     ts << l2 << "<hasBars/>" << endl;
@@ -818,6 +818,16 @@
 }
 
 
+void KstVCurve::setPointStyle(int in_PointStyle) {
+  if (in_PointStyle >= 0 && (unsigned int)in_PointStyle <KSTPOINT_MAXTYPE)
+  {
+    PointStyle = in_PointStyle;
+    setDirty();
+    emit modifiedLegendEntry();
+  }
+}
+
+
 void KstVCurve::setColor(const QColor& new_c) {
   setDirty();
   Color = new_c;
@@ -1379,7 +1389,7 @@
           pt.setX(d2i(m_X * rX + b_X));
           pt.setY(d2i(m_Y * rY + b_Y));
           if (rgn.contains(pt)) {
-            KstCurvePointSymbol::draw(pointType, p, pt.x(), pt.y(), width);
+            KstCurvePointSymbol::draw(PointStyle, p, pt.x(), pt.y(), width);
             rgn -= QRegion(pt.x()-(size/2), pt.y()-(size/2), size, size, QRegion::Ellipse);
           }
         }
@@ -1397,7 +1407,7 @@
           X1 = m_X * rX + b_X;
           Y1 = m_Y * rY + b_Y;
           if (X1 >= Lx && X1 <= Hx && Y1 >= Ly && Y1 <= Hy) {
-            KstCurvePointSymbol::draw(pointType, p, d2i(X1), d2i(Y1), width);
+            KstCurvePointSymbol::draw(PointStyle, p, d2i(X1), d2i(Y1), width);
           }
         }
       }
@@ -1719,13 +1729,13 @@
 
 void KstVCurve::paintLegendSymbol(KstPainter *p, const QRect& bound) {
   int width;
-  
+
   if (lineWidth() == 0) {
     width = p->lineWidthAdjustmentFactor();
-  } else {  
+  } else {
     width = lineWidth() * p->lineWidthAdjustmentFactor();
   }
-  
+
   p->save();
   if (hasLines()) {
     // draw a line from left to right centered vertically
@@ -1736,7 +1746,7 @@
   if (hasPoints()) {
     // draw a point in the middle
     p->setPen(QPen(color(), width));
-    KstCurvePointSymbol::draw(pointType, p, bound.left() + bound.width()/2, bound.top() + bound.height()/2, width, 600);
+    KstCurvePointSymbol::draw(PointStyle, p, bound.left() + bound.width()/2, bound.top() + bound.height()/2, width, 600);
   }
   p->restore();
 }
@@ -1746,10 +1756,9 @@
   return (_interp);
 }
 
+
 void KstVCurve::setInterp(KstVCurve::InterpType itype) {
   _interp = itype;
   setDirty();
 }
 
-
-// vim: ts=2 sw=2 et
--- branches/work/kst/1.5/kst/src/libkstmath/kstvcurve.h #712627:712628
@@ -105,7 +105,7 @@
     KstVectorPtr yErrorVector() const;
     KstVectorPtr xMinusErrorVector() const;
     KstVectorPtr yMinusErrorVector() const;
-    
+
     virtual bool hasPoints()    const { return HasPoints; }
     virtual bool hasLines()     const { return HasLines; }
     virtual bool hasBars()      const { return HasBars; }
@@ -116,44 +116,39 @@
     virtual void setLineStyle(int in_LineStyle);
     virtual void setBarStyle( int in_BarStyle);
     virtual void setPointDensity(int in_PointDensity);
-    
+    virtual void setPointStyle(int in_PointStyle);
+
     virtual int lineWidth()     const { return LineWidth; }
     virtual int lineStyle()     const { return LineStyle; }
     virtual int barStyle()      const { return BarStyle; }
     virtual int pointDensity()  const { return PointDensity; }
+    virtual int pointStyle()    const { return PointStyle; }
 
     virtual QColor color() const { return Color; }
     virtual void setColor(const QColor& new_c);
-    
-    
+
     void pushColor(const QColor& c) { _colorStack.push(color()); setColor(c); }
     void popColor() { setColor(_colorStack.pop()); }
     void pushLineWidth(int w) { _widthStack.push(lineWidth()); setLineWidth(w); }
     void popLineWidth() { setLineWidth(_widthStack.pop()); }
     void pushLineStyle(int s) { _lineStyleStack.push(lineStyle()); setLineStyle(s); }
     void popLineStyle() { setLineStyle(_lineStyleStack.pop()); }
-    void pushPointStyle(int s) { _pointStyleStack.push(pointType); pointType = s; }
-    void popPointStyle() { pointType = _pointStyleStack.pop(); }
+    void pushPointStyle(int s) { _pointStyleStack.push(pointStyle()); setPointStyle(s); }
+    void popPointStyle() { setPointStyle(_pointStyleStack.pop()); }
     void pushHasPoints(bool h) { _hasPointsStack.push(hasPoints()); setHasPoints(h); }
     void popHasPoints() { setHasPoints(_hasPointsStack.pop()); }
     void pushHasLines(bool h) { _hasLinesStack.push(hasLines()); setHasLines(h); }
     void popHasLines() { setHasLines(_hasLinesStack.pop()); }
     void pushPointDensity(int d) { _pointDensityStack.push(pointDensity()); setPointDensity(d); }
     void popPointDensity() { setPointDensity(_pointDensityStack.pop()); } 
-    
-    int pointType;
-    
+
     virtual KstDataObjectPtr makeDuplicate(KstDataObjectDataObjectMap& duplicatedMap);
-    
-    // render this vcurve
     virtual void paint(const KstCurveRenderContext& context);
-    
-    // render the legend symbol for this curve
     virtual void paintLegendSymbol(KstPainter *p, const QRect& bound);
-    
+
     // see KstBaseCurve::distanceToPoint
     virtual double distanceToPoint(double xpos, double dx, double ypos) const;
-    
+
     // see KstBaseCurve::providerDataObject
     virtual KstDataObjectPtr providerDataObject() const;
 
@@ -161,16 +156,17 @@
     inline void commonConstructor(const QString& in_tag, const QColor& in_color);
 
     double MeanY;
-    
+
     int BarStyle;
     int LineWidth;
     int LineStyle;
     int PointDensity;
-    
+    int PointStyle;
+
     bool HasPoints;
     bool HasLines;
     bool HasBars;
-    
+
     QColor Color;
     QValueStack<int> _widthStack;
     QValueStack<QColor> _colorStack;
@@ -186,4 +182,4 @@
 typedef KstObjectList<KstVCurvePtr> KstVCurveList;
 
 #endif
-// vim: ts=2 sw=2 et
+


More information about the Kst mailing list