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

Mike Fenton mike at staikos.net
Thu Oct 18 21:53:20 CEST 2007


SVN commit 726750 by fenton:

Add accessor functions to FFTOptions and PSD creation from
PowerSpectrumDialog.


 M  +76 -4     libkstapp/powerspectrumdialog.cpp  
 M  +3 -1      libkstapp/powerspectrumdialog.h  
 M  +76 -23    widgets/fftoptions.cpp  
 M  +14 -0     widgets/fftoptions.h  
 M  +28 -28    widgets/fftoptions.ui  


--- branches/work/kst/portto4/kst/src/libkstapp/powerspectrumdialog.cpp #726749:726750
@@ -57,6 +57,11 @@
 }
 
 
+FFTOptions* PowerSpectrumTab::FFTOptionsWidget() const {
+  return _FFTOptions;
+}
+
+
 PowerSpectrumDialog::PowerSpectrumDialog(ObjectPtr dataObject, QWidget *parent)
   : DataDialog(dataObject, parent) {
 
@@ -65,8 +70,8 @@
   else
     setWindowTitle(tr("New Power Spectrum"));
 
-  _PowerSpectrumTab = new PowerSpectrumTab(this);
-  addDataTab(_PowerSpectrumTab);
+  _powerSpectrumTab = new PowerSpectrumTab(this);
+  addDataTab(_powerSpectrumTab);
 
   //FIXME need to do validation to enable/disable ok button...
 }
@@ -82,8 +87,75 @@
 
 
 ObjectPtr PowerSpectrumDialog::createNewDataObject() const {
-  qDebug() << "createNewDataObject" << endl;
-  return 0;
+ //FIXME Eli, how should I construct this tag??
+  PSDPtr powerspectrum = new PSD(tagName(),
+                                     _powerSpectrumTab->vector(),
+                                     _powerSpectrumTab->FFTOptionsWidget()->sampleRate(),
+                                     _powerSpectrumTab->FFTOptionsWidget()->interleavedAverage(),
+                                     _powerSpectrumTab->FFTOptionsWidget()->FFTLength(),
+                                     _powerSpectrumTab->FFTOptionsWidget()->apodize(),
+                                     _powerSpectrumTab->FFTOptionsWidget()->removeMean(),
+                                     _powerSpectrumTab->FFTOptionsWidget()->vectorUnits(),
+                                     _powerSpectrumTab->FFTOptionsWidget()->rateUnits(),
+                                     _powerSpectrumTab->FFTOptionsWidget()->apodizeFunction(),
+                                     _powerSpectrumTab->FFTOptionsWidget()->sigma(),
+                                     _powerSpectrumTab->FFTOptionsWidget()->output());
+  powerspectrum->setInterpolateHoles(_powerSpectrumTab->FFTOptionsWidget()->interpolateOverHoles());
+
+  powerspectrum->writeLock();
+  powerspectrum->update(0);
+  powerspectrum->unlock();
+
+  //FIXME this should be a command...
+  //FIXME need some smart placement...
+
+  CurvePtr curve = new Curve(suggestCurveName(powerspectrum->tag(), true),
+                                     powerspectrum->vX(),
+                                     powerspectrum->vY(),
+                                     0L, 0L, 0L, 0L,
+                                     _powerSpectrumTab->curveAppearance()->color());
+
+  curve->setHasPoints(_powerSpectrumTab->curveAppearance()->showPoints());
+  curve->setHasLines(_powerSpectrumTab->curveAppearance()->showLines());
+  curve->setHasBars(_powerSpectrumTab->curveAppearance()->showBars());
+  curve->setLineWidth(_powerSpectrumTab->curveAppearance()->lineWidth());
+  curve->setLineStyle(_powerSpectrumTab->curveAppearance()->lineStyle());
+  curve->pointType = _powerSpectrumTab->curveAppearance()->pointType();
+  curve->setPointDensity(_powerSpectrumTab->curveAppearance()->pointDensity());
+  curve->setBarStyle(_powerSpectrumTab->curveAppearance()->barStyle());
+
+  curve->writeLock();
+  curve->update(0);
+  curve->unlock();
+
+  PlotItem *plotItem = 0;
+  switch (_powerSpectrumTab->curvePlacement()->place()) {
+  case CurvePlacement::NoPlot:
+    break;
+  case CurvePlacement::ExistingPlot:
+    {
+      plotItem = static_cast<PlotItem*>(_powerSpectrumTab->curvePlacement()->existingPlot());
+      break;
+    }
+  case CurvePlacement::NewPlot:
+    {
+      CreatePlotForCurve *cmd = new CreatePlotForCurve(
+        _powerSpectrumTab->curvePlacement()->createLayout(),
+        _powerSpectrumTab->curvePlacement()->appendToLayout());
+      cmd->createItem();
+
+      plotItem = static_cast<PlotItem*>(cmd->item());
+      break;
+    }
+  default:
+    break;
+  }
+
+  PlotRenderItem *renderItem = plotItem->renderItem(PlotRenderItem::Cartesian);
+  renderItem->addRelation(kst_cast<Relation>(curve));
+  plotItem->update();
+
+  return ObjectPtr(powerspectrum.data());
 }
 
 
--- branches/work/kst/portto4/kst/src/libkstapp/powerspectrumdialog.h #726749:726750
@@ -34,7 +34,9 @@
     VectorPtr vector() const;
     CurveAppearance* curveAppearance() const;
     CurvePlacement* curvePlacement() const;
+    FFTOptions* FFTOptionsWidget() const;
 
+
   private Q_SLOTS:
   private:
 };
@@ -51,7 +53,7 @@
     virtual ObjectPtr editExistingDataObject() const;
 
   private:
-    PowerSpectrumTab *_PowerSpectrumTab;
+    PowerSpectrumTab *_powerSpectrumTab;
 };
 
 }
--- branches/work/kst/portto4/kst/src/widgets/fftoptions.cpp #726749:726750
@@ -20,13 +20,13 @@
     : QWidget(parent) {
   setupUi(this);
 
-  connect(Interleaved, SIGNAL(clicked()), this, SLOT(clickedInterleaved()));
+  connect(_interleavedAverage, SIGNAL(clicked()), this, SLOT(clickedInterleaved()));
 
-  connect(Apodize, SIGNAL(clicked()), this, SLOT(clickedApodize()));
+  connect(_apodize, SIGNAL(clicked()), this, SLOT(clickedApodize()));
 
-  connect(ApodizeFxn, SIGNAL(activated(int)), this, SLOT(changedApodizeFxn()));
+  connect(_apodizeFunction, SIGNAL(activated(int)), this, SLOT(changedApodizeFxn()));
 
-  connect(Apodize, SIGNAL(clicked()), this, SLOT(changedApodizeFxn()));
+  connect(_apodize, SIGNAL(clicked()), this, SLOT(changedApodizeFxn()));
 }
 
 
@@ -41,16 +41,16 @@
 void FFTOptions::update() {
   objectDefaults.sync();
 
-  FFTLen->setValue(objectDefaults.fftLen());
-  SampRate->setText(QString::number(objectDefaults.psdFreq()));
-  VectorUnits->setText(objectDefaults.vUnits());
-  RateUnits->setText(objectDefaults.rUnits());
-  Apodize->setChecked(objectDefaults.apodize());
-  RemoveMean->setChecked(objectDefaults.removeMean());
-  Interleaved->setChecked(objectDefaults.psdAverage());
-  ApodizeFxn->setCurrentIndex(objectDefaults.apodizeFxn());
-  Output->setCurrentIndex(objectDefaults.output());
-  InterpolateHoles->setChecked(objectDefaults.interpolateHoles());
+  _FFTLength->setValue(objectDefaults.fftLen());
+  _sampleRate->setText(QString::number(objectDefaults.psdFreq()));
+  _vectorUnits->setText(objectDefaults.vUnits());
+  _rateUnits->setText(objectDefaults.rUnits());
+  _apodize->setChecked(objectDefaults.apodize());
+  _removeMean->setChecked(objectDefaults.removeMean());
+  _interleavedAverage->setChecked(objectDefaults.psdAverage());
+  _apodizeFunction->setCurrentIndex(objectDefaults.apodizeFxn());
+  _output->setCurrentIndex(objectDefaults.output());
+  _interpolateOverHoles->setChecked(objectDefaults.interpolateHoles());
 
   clickedInterleaved();
   clickedApodize();
@@ -58,22 +58,75 @@
 }
 
 
+double FFTOptions::sampleRate() const {
+  return _sampleRate->text().toDouble();
+}
+
+
+double FFTOptions::sigma() const {
+  return _sigma->value();
+}
+
+bool FFTOptions::interleavedAverage() const {
+  return _interleavedAverage->isChecked();
+}
+
+
+bool FFTOptions::apodize() const {
+  return _apodize->isChecked();
+}
+
+
+bool FFTOptions::removeMean() const {
+  return _removeMean->isChecked();
+}
+
+
+bool FFTOptions::interpolateOverHoles() const {
+  return _interpolateOverHoles->isChecked();
+}
+
+int FFTOptions::FFTLength() const {
+  return _FFTLength->value();
+}
+
+
+QString FFTOptions::vectorUnits() const {
+  return _vectorUnits->text();
+}
+
+
+QString FFTOptions::rateUnits() const {
+  return _rateUnits->text();
+}
+
+
+ApodizeFunction FFTOptions::apodizeFunction() const {
+  return (ApodizeFunction)_apodizeFunction->currentIndex();
+}
+
+
+PSDType FFTOptions::output() const {
+  return (PSDType)_output->currentIndex();
+}
+
+
 void FFTOptions::changedApodizeFxn() {
   int gaussianIndex = 5;
-  if (ApodizeFxn->itemText(0).isEmpty()) {
+  if (_apodizeFunction->itemText(0).isEmpty()) {
     ++gaussianIndex;
   }
-  Sigma->setEnabled(ApodizeFxn->currentIndex() == gaussianIndex && Apodize->isChecked());
+  _sigma->setEnabled(_apodizeFunction->currentIndex() == gaussianIndex && _apodize->isChecked());
 }
 
 
 void FFTOptions::clickedInterleaved() {
-  FFTLen->setEnabled(Interleaved->isChecked());
+  _FFTLength->setEnabled(_interleavedAverage->isChecked());
 }
 
 
 void FFTOptions::clickedApodize() {
-  ApodizeFxn->setEnabled(Apodize->isChecked());
+  _apodizeFunction->setEnabled(_apodize->isChecked());
 }
 
 
@@ -84,17 +137,17 @@
 
 
 bool FFTOptions::checkValues() {
-  double new_freq = SampRate->text().toDouble();
-  int new_len = FFTLen->text().toInt();
+  double new_freq = _sampleRate->text().toDouble();
+  int new_len = _FFTLength->text().toInt();
   return checkGivenValues(new_freq, new_len);
 }
 
 
-bool FFTOptions::checkGivenValues(double sampRate, int FFTLen) {
-  if (sampRate <= 0) {
+bool FFTOptions::checkGivenValues(double sampleRate, int FFTLength) {
+  if (sampleRate <= 0) {
     return false;
   }
-  if (FFTLen < 2) {
+  if (FFTLength < 2) {
     return false;
   }
   return true;
--- branches/work/kst/portto4/kst/src/widgets/fftoptions.h #726749:726750
@@ -15,6 +15,8 @@
 #include <QWidget>
 #include "ui_fftoptions.h"
 
+#include "psd.h"
+
 #include "kst_export.h"
 
 namespace Kst {
@@ -26,6 +28,18 @@
   FFTOptions(QWidget *parent = 0);
   ~FFTOptions();
 
+  double sampleRate() const;
+  double sigma() const;
+  bool interleavedAverage() const;
+  int FFTLength() const;
+  bool apodize() const;
+  bool removeMean() const;
+  QString vectorUnits() const;
+  QString rateUnits() const;
+  ApodizeFunction apodizeFunction() const;
+  PSDType output() const;
+  bool interpolateOverHoles() const;
+
   void update();
 
 public slots:
--- branches/work/kst/portto4/kst/src/widgets/fftoptions.ui #726749:726750
@@ -6,7 +6,7 @@
     <x>0</x>
     <y>0</y>
     <width>488</width>
-    <height>162</height>
+    <height>188</height>
    </rect>
   </property>
   <property name="sizePolicy" >
@@ -76,7 +76,7 @@
          <number>0</number>
         </property>
         <item row="0" column="2" >
-         <widget class="QComboBox" name="ApodizeFxn" >
+         <widget class="QComboBox" name="_apodizeFunction" >
           <property name="sizePolicy" >
            <sizepolicy vsizetype="Fixed" hsizetype="MinimumExpanding" >
             <horstretch>0</horstretch>
@@ -139,12 +139,12 @@
            <bool>false</bool>
           </property>
           <property name="buddy" >
-           <cstring>Sigma</cstring>
+           <cstring>_sigma</cstring>
           </property>
          </widget>
         </item>
         <item row="0" column="4" >
-         <widget class="QDoubleSpinBox" name="Sigma" >
+         <widget class="QDoubleSpinBox" name="_sigma" >
           <property name="enabled" >
            <bool>false</bool>
           </property>
@@ -154,7 +154,7 @@
          </widget>
         </item>
         <item row="0" column="0" >
-         <widget class="QCheckBox" name="Apodize" >
+         <widget class="QCheckBox" name="_apodize" >
           <property name="sizePolicy" >
            <sizepolicy vsizetype="Fixed" hsizetype="Minimum" >
             <horstretch>0</horstretch>
@@ -181,7 +181,7 @@
            <bool>false</bool>
           </property>
           <property name="buddy" >
-           <cstring>ApodizeFxn</cstring>
+           <cstring>_apodizeFunction</cstring>
           </property>
          </widget>
         </item>
@@ -202,7 +202,7 @@
          <number>0</number>
         </property>
         <item row="0" column="1" >
-         <widget class="QCheckBox" name="Interleaved" >
+         <widget class="QCheckBox" name="_interleavedAverage" >
           <property name="text" >
            <string>&amp;Interleaved average</string>
           </property>
@@ -229,12 +229,12 @@
            <bool>false</bool>
           </property>
           <property name="buddy" >
-           <cstring>FFTLen</cstring>
+           <cstring>_FFTLength</cstring>
           </property>
          </widget>
         </item>
         <item row="0" column="3" >
-         <widget class="QSpinBox" name="FFTLen" >
+         <widget class="QSpinBox" name="_FFTLength" >
           <property name="sizePolicy" >
            <sizepolicy vsizetype="Fixed" hsizetype="MinimumExpanding" >
             <horstretch>0</horstretch>
@@ -256,7 +256,7 @@
          </widget>
         </item>
         <item row="0" column="0" >
-         <widget class="QCheckBox" name="RemoveMean" >
+         <widget class="QCheckBox" name="_removeMean" >
           <property name="text" >
            <string>Remo&amp;ve mean</string>
           </property>
@@ -266,7 +266,7 @@
          </widget>
         </item>
         <item row="1" column="0" >
-         <widget class="QCheckBox" name="InterpolateHoles" >
+         <widget class="QCheckBox" name="_interpolateOverHoles" >
           <property name="text" >
            <string>Interpolate Over &amp;Holes</string>
           </property>
@@ -309,12 +309,12 @@
            <bool>false</bool>
           </property>
           <property name="buddy" >
-           <cstring>SampRate</cstring>
+           <cstring>_sampleRate</cstring>
           </property>
          </widget>
         </item>
         <item>
-         <widget class="QLineEdit" name="SampRate" >
+         <widget class="QLineEdit" name="_sampleRate" >
           <property name="sizePolicy" >
            <sizepolicy vsizetype="Fixed" hsizetype="Expanding" >
             <horstretch>0</horstretch>
@@ -350,12 +350,12 @@
            <bool>false</bool>
           </property>
           <property name="buddy" >
-           <cstring>VectorUnits</cstring>
+           <cstring>_vectorUnits</cstring>
           </property>
          </widget>
         </item>
         <item>
-         <widget class="QLineEdit" name="VectorUnits" >
+         <widget class="QLineEdit" name="_vectorUnits" >
           <property name="sizePolicy" >
            <sizepolicy vsizetype="Fixed" hsizetype="Expanding" >
             <horstretch>0</horstretch>
@@ -388,12 +388,12 @@
            <bool>false</bool>
           </property>
           <property name="buddy" >
-           <cstring>RateUnits</cstring>
+           <cstring>_rateUnits</cstring>
           </property>
          </widget>
         </item>
         <item>
-         <widget class="QLineEdit" name="RateUnits" >
+         <widget class="QLineEdit" name="_rateUnits" >
           <property name="sizePolicy" >
            <sizepolicy vsizetype="Fixed" hsizetype="Expanding" >
             <horstretch>0</horstretch>
@@ -435,7 +435,7 @@
          </widget>
         </item>
         <item>
-         <widget class="QComboBox" name="Output" >
+         <widget class="QComboBox" name="_output" >
           <property name="sizePolicy" >
            <sizepolicy vsizetype="Fixed" hsizetype="MinimumExpanding" >
             <horstretch>0</horstretch>
@@ -474,16 +474,16 @@
  <layoutdefault spacing="6" margin="11" />
  <pixmapfunction>qPixmapFromMimeSource</pixmapfunction>
  <tabstops>
-  <tabstop>Apodize</tabstop>
-  <tabstop>ApodizeFxn</tabstop>
-  <tabstop>Sigma</tabstop>
-  <tabstop>RemoveMean</tabstop>
-  <tabstop>Interleaved</tabstop>
-  <tabstop>FFTLen</tabstop>
-  <tabstop>InterpolateHoles</tabstop>
-  <tabstop>SampRate</tabstop>
-  <tabstop>VectorUnits</tabstop>
-  <tabstop>RateUnits</tabstop>
+  <tabstop>_apodize</tabstop>
+  <tabstop>_apodizeFunction</tabstop>
+  <tabstop>_sigma</tabstop>
+  <tabstop>_removeMean</tabstop>
+  <tabstop>_interleavedAverage</tabstop>
+  <tabstop>_FFTLength</tabstop>
+  <tabstop>_interpolateOverHoles</tabstop>
+  <tabstop>_sampleRate</tabstop>
+  <tabstop>_vectorUnits</tabstop>
+  <tabstop>_rateUnits</tabstop>
  </tabstops>
  <resources/>
  <connections/>


More information about the Kst mailing list