[Kst] kdeextragear-2/kst/kst

Barth Netterfield netterfield at astro.utoronto.ca
Thu Aug 12 16:40:50 CEST 2004


CVS commit by netterfield: 

Fix for Bug 87016: attempting to fit a curve to a histogram crashes kst

Fits to histograms now work.

Histograms export slave vectors 

CCMAIL: 87016-done at bugs.kde.org


  M +36 -0     ksthistogram.cpp   1.26
  M +7 -0      ksthistogram.h   1.18
  M +18 -15    ksthsdialog_i.cpp   1.61


--- kdeextragear-2/kst/kst/ksthistogram.cpp  #1.25:1.26
@@ -31,4 +31,6 @@
 #include <klocale.h>
 
+static const QString BINS = "B";
+static const QString HIST = "H";
 KstHistogram::KstHistogram(const QString &in_tag, KstVectorPtr in_V,
                            double xmin_in, double xmax_in,
@@ -137,8 +139,23 @@ void KstHistogram::commonConstructor(con
   Color = in_color;
 
+  KstVectorPtr iv = new KstVector(in_tag+"-bins", NBins);
+  KST::addVectorToList(iv);
+  _bVector = _outputVectors.insert(BINS, iv);
+
+  iv = new KstVector(in_tag+"-sv", NBins);
+  KST::addVectorToList(iv);
+  _hVector = _outputVectors.insert(HIST, iv);
+
   update();
 }
 
 KstHistogram::~KstHistogram() {
+  _bVector = _outputVectors.end();
+  _hVector = _outputVectors.end();
+  KST::vectorList.lock().writeLock();
+  KST::vectorList.remove(_outputVectors[BINS]);
+  KST::vectorList.remove(_outputVectors[HIST]);
+  KST::vectorList.lock().writeUnlock();
+
   delete[] Bins;
 }
@@ -213,4 +230,15 @@ KstObject::UpdateType KstHistogram::upda
   else MinPosX = 1.0;
 
+  double *bins =  (*_bVector)->value();
+  double *hist =  (*_hVector)->value();
+
+  for ( i_bin = 0; i_bin<NBins; i_bin++ ) {
+    bins[i_bin] = ( double( i_bin )+ 0.5 )*W + MinX;
+    hist[i_bin] = Bins[i_bin]*Normalization;
+  }
+
+  (*_bVector)->update(update_counter);
+  (*_hVector)->update(update_counter);
+
   return (UPDATE);
 }
@@ -254,4 +282,8 @@ void KstHistogram::setNBins(int in_n_bin
   Bins = new unsigned long[in_n_bins];
   W = (MaxX - MinX)/(double)NBins;
+
+  (*_bVector)->resize(NBins);
+  (*_hVector)->resize(NBins);
+
 }
 
@@ -368,3 +400,7 @@ void KstHistogram::AutoBin(KstVectorPtr 
 }
 
+bool KstHistogram::slaveVectorsUsed() const {
+  return true;
+}
+
 // vim: ts=2 sw=2 et

--- kdeextragear-2/kst/kst/ksthistogram.h  #1.17:1.18
@@ -77,4 +77,9 @@ public:
   virtual void _showDialog();
 
+  virtual bool slaveVectorsUsed() const;
+
+  virtual QString getXVTag() const {return (*_bVector)->tagName();}
+  virtual QString getYVTag() const {return (*_hVector)->tagName();}
+
 private:
   KstVectorPtr V;
@@ -93,4 +98,6 @@ private:
 
   KstHsNormType NormMode;
+
+  KstVectorMap::Iterator _bVector, _hVector;
 };
 

--- kdeextragear-2/kst/kst/ksthsdialog_i.cpp  #1.60:1.61
@@ -203,7 +203,9 @@ bool KstHsDialogI::new_I() {
 
   KstHistogramPtr hs;
-  { // make sure this iterator falls out of scope
-    KstReadLocker ml(&KST::vectorList.lock());
-    KstVectorList::Iterator i = KST::vectorList.findTag(_vector->selectedVector());
+
+  KST::vectorList.lock().readLock();
+  KstVectorList::Iterator i =
+    KST::vectorList.findTag(_vector->selectedVector());
+  KST::vectorList.lock().readUnlock();
     if (i == KST::vectorList.end()) {
       kdFatal() << "Bug in kst: the Vector field in plotDialog (Hs) refers to "
@@ -211,4 +213,5 @@ bool KstHsDialogI::new_I() {
     }
 
+  ( *i )->readLock();
     hs = new KstHistogram(tag_name, *i, new_min, new_max,
                           new_n_bins, new_norm_mode,
@@ -219,5 +222,4 @@ bool KstHsDialogI::new_I() {
     hs->setLineStyle(_curveAppearance->lineStyle());
     hs->Point.setType(_curveAppearance->pointType());
-  }
 
   if (hs) {
@@ -254,4 +256,5 @@ bool KstHsDialogI::new_I() {
       }
     }
+    ( *i )->readUnlock();
 
     KST::dataObjectList.lock().writeLock();





More information about the Kst mailing list