Bug 87017

Summary: attempting to fit a curve to a psd crashes kst
Product: [Applications] kst Reporter: Netterfield <netterfield>
Component: generalAssignee: kst
Status: RESOLVED FIXED    
Severity: normal    
Priority: NOR    
Version: 1.x   
Target Milestone: ---   
Platform: unspecified   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:

Description Netterfield 2004-08-12 05:26:27 UTC
Version:           0.99-devel (using KDE 3.2 BRANCH >= 20040204, Mandrake Linux Cooker i586 - Cooker)
Compiler:          gcc version 3.3.2 (Mandrake Linux 10.0 3.3.2-6mdk)
OS:                Linux (i686) release 2.6.3-7mdk

Create a PSD and plot it. 
 
 select plot->rmb->fit->[histogramname] 
 select a fit (eg, fit linear) then <OK> 
 
 Kst crashes. 
 
 Correct behavior: kst doesn't crash - but instead fits a line to the psd.
Comment 1 Netterfield 2004-08-12 16:04:25 UTC
CVS commit by netterfield: 

Fix for 
Bug 87017: attempting to fit a curve to a psd crashes kst

work toward fixing
Bug 87016: attempting to fit a curve to a histogram crashes kst

BaseCurves now have getXVTag() etc which returns i18n("<None>") if
	they are not defined
The fit dialog now grabs BaseCurves not VCurves, and verifies that
	getXVTag and getYVTag are not <None>.
PSD's now return the proper things in get[XY}VTag().
The PSD's x vector is now the same lenght as the YV as a temp workaround for
Bug 87018 (fit problems)

CCMAIL: 87017-done@bugs.kde.org
CCMAIL: 87016@bugs.kde.org


  M +7 -2      kstbasecurve.h   1.19
  M +5 -2      kstfitdialog_i.cpp   1.32
  M +6 -7      kstpsdcurve.cpp   1.35
  M +3 -0      kstpsdcurve.h   1.21


--- kdeextragear-2/kst/kst/kstbasecurve.h  #1.18:1.19
@@ -23,4 +23,5 @@
 #include <qstring.h>
 #include <qcolor.h>
+#include <klocale.h>
 
 /**A class for handling curves for kst
@@ -29,5 +30,5 @@
  */
 
-typedef enum {KST_VCURVE, KST_PSDCURVE, KST_EQUATIONCURVE, KST_HISTOGRAM, KST_FITCURVE} KstCurveType;
+typedef enum {KST_VCURVE, KST_PSDCURVE, KST_EQUATIONCURVE, KST_HISTOGRAM} KstCurveType;
 
 class KstBaseCurve: public KstDataObject {
@@ -91,4 +92,8 @@ public:
   virtual int samplesPerFrame() const { return 1; }
   
+  virtual QString getXVTag() const {return i18n("<None>");}
+  virtual QString getYVTag() const {return i18n("<None>");}
+  virtual QString getYETag() const {return i18n("<None>");}
+  virtual QString getXETag() const {return i18n("<None>");}
   KstPoint Point;
 

--- kdeextragear-2/kst/kst/kstfitdialog_i.cpp  #1.31:1.32
@@ -121,6 +121,6 @@ void KstFitDialogI::show_setCurve(const 
                                   const QString& strWindow) {
 
-  KstVCurvePtr  curve;
-  KstVCurveList curves = kstObjectSubList<KstDataObject, KstVCurve>(KST::dataObjectList);
+  KstBaseCurvePtr  curve;
+  KstBaseCurveList curves = kstObjectSubList<KstDataObject, KstBaseCurve>(KST::dataObjectList);
   KstPluginList c = kstObjectSubList<KstDataObject, KstPlugin>(KST::dataObjectList);
   QString new_label;
@@ -136,4 +136,7 @@ void KstFitDialogI::show_setCurve(const 
   }
 
+  if ( _xvector==i18n("<None>") ) return;
+  if ( _yvector==i18n("<None>") ) return;
+
    _tagName->setText(newFitPluginString);
 

--- kdeextragear-2/kst/kst/kstpsdcurve.cpp  #1.34:1.35
@@ -10,5 +10,5 @@
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
- *   it under the terms of the GNU General Public License as published by  *
+ *   it under the terms of the GNU Geeral Public License as published by  *
  *   the Free Software Foundation; either version 2 of the License, or     *
  *   (at your option) any later version.                                   *
@@ -167,5 +167,5 @@ void KstPSDCurve::commonConstructor(cons
   last_n_new = 0;
 
-  KstVectorPtr iv = new KstVector(in_tag+"-freq", 2);
+  KstVectorPtr iv = new KstVector(in_tag+"-freq", PSDLen);
   KST::addVectorToList(iv);
   _fVector = _outputVectors.insert(FVECTOR, iv);
@@ -221,5 +221,5 @@ KstObject::UpdateType KstPSDCurve::updat
   KstVectorPtr iv = _inputVectors[INVECTOR];
 
-  double *psd;
+  double *psd,  *f;
 
   if (KstObject::checkUpdateCounter(update_counter))
@@ -245,7 +245,9 @@ KstObject::UpdateType KstPSDCurve::updat
 
   psd = (*_sVector)->value();
+  f = (*_fVector)->value();
 
   for (i_samp = 0; i_samp < PSDLen; i_samp++) {
     psd[i_samp] = 0;
+    f[i_samp] = i_samp*0.5*Freq/( PSDLen-1 );
   }
 
@@ -336,8 +338,4 @@ KstObject::UpdateType KstPSDCurve::updat
   MeanX = MaxX/2.0;
 
-  double *f = (*_fVector)->value();
-  f[0] = 0;
-  f[1] = Freq/2.0;
-
   (*_sVector)->update(update_counter);
   (*_fVector)->update(update_counter);
@@ -424,4 +422,5 @@ void KstPSDCurve::_adjustLengths() {
     PSDLen = psdlen;
     (*_sVector)->resize(PSDLen);
+    (*_fVector)->resize(PSDLen);
 
     ALen = PSDLen*2;

--- kdeextragear-2/kst/kst/kstpsdcurve.h  #1.20:1.21
@@ -74,4 +74,7 @@ public:
   virtual void _showDialog();
 
+  virtual QString getXVTag() const {return (*_fVector)->tagName();}
+  virtual QString getYVTag() const {return (*_sVector)->tagName();}
+
 private:
   double Freq;