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

Mike Fenton mike at staikos.net
Thu Nov 15 16:30:41 CET 2007


SVN commit 737131 by fenton:

Add Edit support for Histogram's.


 M  +6 -4      libkstapp/datamanager.cpp  
 M  +87 -2     libkstapp/histogramdialog.cpp  
 M  +20 -2     libkstapp/histogramdialog.h  
 M  +5 -0      libkstmath/histogram.cpp  
 M  +2 -0      libkstmath/histogram.h  


--- branches/work/kst/portto4/kst/src/libkstapp/datamanager.cpp #737130:737131
@@ -23,7 +23,9 @@
 #include "curve.h"
 #include "equation.h"
 #include "vector.h"
+#include "histogram.h"
 
+
 #include <QHeaderView>
 #include <QToolBar>
 #include <QMenu>
@@ -146,11 +148,11 @@
   if (_currentObject) {
     if (CurvePtr curve = kst_cast<Curve>(_currentObject)) {
       DialogLauncher::self()->showCurveDialog(curve);
-    }
-    if (EquationPtr equation = kst_cast<Equation>(_currentObject)) {
+    } else if (EquationPtr equation = kst_cast<Equation>(_currentObject)) {
       DialogLauncher::self()->showEquationDialog(equation);
-    }
-    if (VectorPtr vector = kst_cast<Vector>(_currentObject)) {
+    } else if (HistogramPtr histogram = kst_cast<Histogram>(_currentObject)) {
+      DialogLauncher::self()->showHistogramDialog(histogram);
+    } else if (VectorPtr vector = kst_cast<Vector>(_currentObject)) {
       DialogLauncher::self()->showVectorDialog(vector);
     }
   }
--- branches/work/kst/portto4/kst/src/libkstapp/histogramdialog.cpp #737130:737131
@@ -96,21 +96,51 @@
 }
 
 
+void HistogramTab::setVector(const VectorPtr vector) {
+  _vector->setSelectedVector(vector);
+}
+
+
 double HistogramTab::min() const {
   return _min->text().toDouble();
 }
 
 
+void HistogramTab::setMin(const double min) {
+  _min->setText(QString::number(min));
+}
+
+
 double HistogramTab::max() const {
   return _max->text().toDouble();
 }
 
 
+void HistogramTab::setMax(const double max) {
+  _max->setText(QString::number(max));
+}
+
+
 int HistogramTab::bins() const {
   return _numberOfBins->text().toInt();
 }
 
 
+void HistogramTab::setBins(const int bins) {
+  _numberOfBins->setValue(bins);
+}
+
+
+bool HistogramTab::realTimeAutoBin() const {
+  return _realTimeAutoBin->isChecked();
+}
+
+
+void HistogramTab::setRealTimeAutoBin(const bool autoBin) {
+  _realTimeAutoBin->setChecked(autoBin);
+}
+
+
 Histogram::NormalizationType HistogramTab::normalizationType() const {
   Histogram::NormalizationType normalization = Histogram::Number;
 
@@ -124,6 +154,26 @@
   return normalization;
 }
 
+
+void HistogramTab::setNormalizationType(const Histogram::NormalizationType normalizationType) {
+  switch (normalizationType) {
+    case Histogram::Fraction:
+      _normalizationIsFraction->setChecked(true);
+      break;
+    case Histogram::MaximumOne:
+      _normalizationMaximumOne->setChecked(true);
+      break;
+    case Histogram::Number:
+      _normalizationIsNumber->setChecked(true);
+      break;
+    case Histogram::Percent:
+      _normalizationIsPercent->setChecked(true);
+      break;
+  }
+}
+
+
+
 CurveAppearance* HistogramTab::curveAppearance() const {
   return _curveAppearance;
 }
@@ -139,6 +189,13 @@
 }
 
 
+void HistogramTab::hideCurveOptions() {
+  _curvePlacement->setVisible(false);
+  _curveAppearance->setVisible(false);
+  setMaximumHeight(235);
+}
+
+
 HistogramDialog::HistogramDialog(ObjectPtr dataObject, QWidget *parent)
   : DataDialog(dataObject, parent) {
 
@@ -150,6 +207,10 @@
   _histogramTab = new HistogramTab(this);
   addDataTab(_histogramTab);
 
+  if (editMode() == Edit) {
+    configureTab(dataObject);
+  }
+
   connect(_histogramTab, SIGNAL(vectorChanged()), this, SLOT(updateButtons()));
   updateButtons();
 }
@@ -164,6 +225,19 @@
 }
 
 
+void HistogramDialog::configureTab(ObjectPtr object) {
+  if (HistogramPtr histogram = kst_cast<Histogram>(object)) {
+    _histogramTab->setVector(histogram->vector());
+    _histogramTab->setMin(histogram->xMin());
+    _histogramTab->setMax(histogram->xMax());
+    _histogramTab->setBins(histogram->numberOfBins());
+    _histogramTab->setRealTimeAutoBin(histogram->realTimeAutoBin());
+    _histogramTab->setNormalizationType(histogram->normalizationType());
+    _histogramTab->hideCurveOptions();
+  }
+}
+
+
 void HistogramDialog::updateButtons() {
   _buttonBox->button(QDialogButtonBox::Ok)->setEnabled(_histogramTab->vector());
 }
@@ -178,6 +252,7 @@
   histogram->setXRange(_histogramTab->min(), _histogramTab->max());
   histogram->setNumberOfBins(_histogramTab->bins());
   histogram->setNormalizationType(_histogramTab->normalizationType());
+  histogram->setRealTimeAutoBin(_histogramTab->realTimeAutoBin());
 
   histogram->writeLock();
   histogram->update(0);
@@ -245,8 +320,18 @@
 
 
 ObjectPtr HistogramDialog::editExistingDataObject() const {
-  qDebug() << "editExistingDataObject" << endl;
-  return 0;
+  if (HistogramPtr histogram = kst_cast<Histogram>(dataObject())) {
+    histogram->writeLock();
+    histogram->setVector(_histogramTab->vector());
+    histogram->setXRange(_histogramTab->min(), _histogramTab->max());
+    histogram->setNumberOfBins(_histogramTab->bins());
+    histogram->setNormalizationType(_histogramTab->normalizationType());
+    histogram->setRealTimeAutoBin(_histogramTab->realTimeAutoBin());
+
+    histogram->update(0);
+    histogram->unlock();
+  }
+  return dataObject();
 }
 
 }
--- branches/work/kst/portto4/kst/src/libkstapp/histogramdialog.h #737130:737131
@@ -34,14 +34,30 @@
     void setObjectStore(ObjectStore *store);
 
     VectorPtr vector() const;
-    CurveAppearance* curveAppearance() const;
-    CurvePlacement* curvePlacement() const;
+    void setVector(VectorPtr vector);
 
     double min() const;
+    void setMin(const double min);
+
     double max() const;
+    void setMax(const double max);
+
     int bins() const;
+    void setBins(const int bins);
+
+    bool realTimeAutoBin() const;
+    void setRealTimeAutoBin(const bool autoBin);
+
     Histogram::NormalizationType normalizationType() const;
+    void setNormalizationType(const Histogram::NormalizationType normalizationType);
 
+    CurveAppearance* curveAppearance() const;
+    CurvePlacement* curvePlacement() const;
+
+
+
+    void hideCurveOptions();
+
   private Q_SLOTS:
     void generateAutoBin();
     void updateButtons();
@@ -66,6 +82,8 @@
     void updateButtons();
 
   private:
+    void configureTab(ObjectPtr curve);
+
     HistogramTab *_histogramTab;
 };
 
--- branches/work/kst/portto4/kst/src/libkstmath/histogram.cpp #737130:737131
@@ -333,6 +333,11 @@
 }
 
 
+VectorPtr Histogram::vector() const {
+  return _inputVectors[RAWVECTOR];
+}
+
+
 QString Histogram::yLabel() const {
   switch (_NormalizationMode) {
     case Number:
--- branches/work/kst/portto4/kst/src/libkstmath/histogram.h #737130:737131
@@ -52,6 +52,7 @@
     QString vTag() const;
 
     void setVector(VectorPtr);
+    VectorPtr vector() const;
 
     virtual QString yLabel() const;
     virtual QString xLabel() const;
@@ -65,6 +66,7 @@
     bool isNormalizationMaximumOne() const { return _NormalizationMode == MaximumOne; }
     void setIsNormNormalizationMaximumOne() { _NormalizationMode = MaximumOne; }
     void setNormalizationType(NormalizationType normType) { _NormalizationMode = normType; }
+    NormalizationType normalizationType() const { return _NormalizationMode; }
 
     static void AutoBin(const VectorPtr, int *n, double *max, double *min);
 


More information about the Kst mailing list