Bug 142702

Summary: Cross power spectrum has useless default names for output vectors
Product: [Applications] kst Reporter: Andrew Walker <arwalker>
Component: generalAssignee: kst
Status: RESOLVED FIXED    
Severity: wishlist    
Priority: NOR    
Version: 1.x   
Target Milestone: ---   
Platform: unspecified   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:
Attachments: proposed fix

Description Andrew Walker 2007-03-08 20:57:10 UTC
Version:           HEAD (using KDE KDE 3.5.1)
OS:                Linux

If the user does not override the default names of the output vectors for the Cross Power Spectrum then the vectors generated are called:

"Anonymous Vector 1"
"Anonymous Vector 2"
"Anonymous Vector 3" 

This is not helpful. The default output vector names should be more meaningful.
Comment 1 Netterfield 2007-03-27 03:31:32 UTC
Created attachment 20106 [details]
proposed fix

-fix the default tag names
-fix the math (the calculation was wrong)
-fix a possible dangling lock
Comment 2 George Staikos 2007-03-27 15:11:40 UTC
Looks fine for 1.4.

--
George Staikos
KDE Developer				http://www.kde.org/
Staikos Computing Services Inc.		http://www.staikos.net/
Comment 3 Andrew Walker 2007-03-27 19:56:54 UTC
This fixes the problem with the default tag names, but does NOT
fix the problem with asserts described in #142701.
Comment 4 Netterfield 2007-03-27 20:06:08 UTC
Correct.

On Tuesday 27 March 2007 1:56:55 pm Andrew Walker wrote:
> ------- This fixes the problem with the default tag names, but does NOT
> fix the problem with asserts described in #142701.

Comment 5 Netterfield 2007-03-28 17:44:40 UTC
SVN commit 647523 by netterfield:

BUG: 142702
Fixes default names, fixes the math, and fixes a possible dangling lock
in a corner case.

approved by George.


 M  +22 -4     crosspowerspectrum.cpp  
 M  +7 -7      crossspectrumdialog_i.cpp  


--- trunk/extragear/graphics/kst/src/plugins/crossspectrum/crosspowerspectrum.cpp #647522:647523
@@ -196,22 +196,40 @@
 
 
 void CrossPowerSpectrum::setReal(const QString &name) {
+  QString tname;
+  if (name.isEmpty()) {
+    tname = i18n("the real part of a complex number", "real");
+  } else {
+    tname = name;
+  }
   KstWriteLocker blockVectorUpdates(&KST::vectorList.lock());
-  KstVectorPtr v = new KstVector(KstObjectTag(name, tag()), 0, this, false);
+  KstVectorPtr v = new KstVector(KstObjectTag(tname, tag()), 0, this, false);
   _outputVectors.insert(REAL, v);
 }
 
 
 void CrossPowerSpectrum::setImaginary(const QString &name) {
+  QString tname;
+  if (name.isEmpty()) {
+    tname = i18n("the imaginary part of a complex number", "imaginary");
+  } else {
+    tname = name;
+  }
   KstWriteLocker blockVectorUpdates(&KST::vectorList.lock());
-  KstVectorPtr v = new KstVector(KstObjectTag(name, tag()), 0, this, false);
+  KstVectorPtr v = new KstVector(KstObjectTag(tname, tag()), 0, this, false);
   _outputVectors.insert(IMAGINARY, v);
 }
 
 
 void CrossPowerSpectrum::setFrequency(const QString &name) {
+  QString tname;
+  if (name.isEmpty()) {
+    tname = i18n("frequency");
+  } else {
+    tname = name;
+  }
   KstWriteLocker blockVectorUpdates(&KST::vectorList.lock());
-  KstVectorPtr v = new KstVector(KstObjectTag(name, tag()), 0, this, false);
+  KstVectorPtr v = new KstVector(KstObjectTag(tname, tag()), 0, this, false);
   _outputVectors.insert(FREQUENCY, v);
 }
 
@@ -357,7 +375,7 @@
     real->value()[0] += ( a[0]*b[0] );
     real->value()[xps_len-1] += ( a[1]*b[1] );
     for (i_samp=1; i_samp<xps_len-1; i_samp++) {
-      real->value()[i_samp]+= ( a[i_samp*2] * b[i_samp*2] -
+      real->value()[i_samp]+= ( a[i_samp*2] * b[i_samp*2] +
                                    a[i_samp*2+1] * b[i_samp*2+1] );
       imaginary->value()[i_samp]+= ( -a[i_samp*2] * b[i_samp*2+1] +
                                    a[i_samp*2+1] * b[i_samp*2] );
--- trunk/extragear/graphics/kst/src/plugins/crossspectrum/crossspectrumdialog_i.cpp #647522:647523
@@ -80,12 +80,6 @@
   //called upon clicking 'ok' in 'new' mode
   //return false if the specified objects can't be made, otherwise true
 
-  //Need to create a new object rather than use the one in KstDataObject pluginList
-  CrossPowerSpectrumPtr cps = kst_cast<CrossPowerSpectrum>(KstDataObject::createPlugin("Cross Power Spectrum"));
-  Q_ASSERT(cps); //should never happen...
-
-  cps->writeLock();
-
   QString tagName = _tagName->text();
 
   if (tagName != defaultTag && KstData::self()->dataTagNameNotUnique(tagName, true, this)) {
@@ -93,6 +87,12 @@
     return false;
   }
 
+  //Need to create a new object rather than use the one in KstDataObject pluginList
+  CrossPowerSpectrumPtr cps = kst_cast<CrossPowerSpectrum>(KstDataObject::createPlugin("Cross Power Spectrum"));
+  Q_ASSERT(cps); //should never happen...
+
+  cps->writeLock();
+
   if (tagName == defaultTag) {
     tagName = KST::suggestPluginName("crosspowerspectrum");
   }
@@ -111,7 +111,7 @@
   cps->setFrequency(_w->_frequency->text());
 
   if (!cps || !cps->isValid()) {
-    KMessageBox::sorry(this, i18n("There is an error in the linefit you entered."));
+    KMessageBox::sorry(this, i18n("There is an error in the crosspowerspectrum you entered."));
     return false;
   }