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

Mike Fenton mike at staikos.net
Thu Dec 6 15:49:53 CET 2007


SVN commit 745600 by fenton:

Add Apply and EditMultiple Functionality to Histogram Dialog.
Fix logic error in EquationDialog.


 M  +1 -2      equationdialog.cpp  
 M  +124 -11   histogramdialog.cpp  
 M  +15 -0     histogramdialog.h  


--- branches/work/kst/portto4/kst/src/libkstapp/equationdialog.cpp #745599:745600
@@ -153,7 +153,7 @@
 
 
 bool EquationTab::doInterpolationDirty() const {
-  return _doInterpolation->checkState() == Qt::PartiallyChecked;
+  return _doInterpolation->checkState() != Qt::PartiallyChecked;
 }
 
 
@@ -190,7 +190,6 @@
   _xVectors->clearSelection();
   _equation->clear();
   _doInterpolation->setCheckState(Qt::PartiallyChecked);
-  _curveAppearance->clearValues();
 }
 
 
--- branches/work/kst/portto4/kst/src/libkstapp/histogramdialog.cpp #745599:745600
@@ -12,6 +12,7 @@
 #include "histogramdialog.h"
 
 #include "dialogpage.h"
+#include "editmultiplewidget.h"
 
 #include "histogram.h"
 
@@ -33,7 +34,7 @@
 namespace Kst {
 
 HistogramTab::HistogramTab(QWidget *parent)
-  : DataTab(parent) {
+  : DataTab(parent), _normalizationDirty(false) {
 
   setupUi(this);
   setTabTitle(tr("Histogram"));
@@ -42,6 +43,20 @@
   connect(_realTimeAutoBin, SIGNAL(clicked()), this, SLOT(updateButtons()));
   connect(_vector, SIGNAL(selectionChanged(QString)), this, SLOT(selectionChanged()));
 
+  connect(_vector, SIGNAL(selectionChanged(QString)), this, SIGNAL(modified()));
+  connect(_min, SIGNAL(textChanged(const QString &)), this, SIGNAL(modified()));
+  connect(_max, SIGNAL(textChanged(const QString &)), this, SIGNAL(modified()));
+  connect(_numberOfBins, SIGNAL(valueChanged(int)), this, SIGNAL(modified()));
+  connect(_realTimeAutoBin, SIGNAL(clicked()), this, SIGNAL(modified()));
+  connect(_normalizationIsNumber, SIGNAL(clicked()), this, SIGNAL(modified()));
+  connect(_normalizationIsFraction, SIGNAL(clicked()), this, SIGNAL(modified()));
+  connect(_normalizationIsPercent, SIGNAL(clicked()), this, SIGNAL(modified()));
+  connect(_normalizationMaximumOne, SIGNAL(clicked()), this, SIGNAL(modified()));
+  connect(_normalizationIsNumber, SIGNAL(clicked()), this, SLOT(normalizationChanged()));
+  connect(_normalizationIsFraction, SIGNAL(clicked()), this, SLOT(normalizationChanged()));
+  connect(_normalizationIsPercent, SIGNAL(clicked()), this, SLOT(normalizationChanged()));
+  connect(_normalizationMaximumOne, SIGNAL(clicked()), this, SLOT(normalizationChanged()));
+
   _curvePlacement->setExistingPlots(Data::self()->plotList());
   _curveAppearance->setShowLines(false);
   _curveAppearance->setShowPoints(false);
@@ -59,6 +74,16 @@
 }
 
 
+void HistogramTab::normalizationChanged() {
+  _normalizationDirty = true;
+}
+
+
+void HistogramTab::resetNormalizationDirty() {
+  _normalizationDirty = false;
+}
+
+
 void HistogramTab::selectionChanged() {
   emit vectorChanged();
 }
@@ -97,6 +122,11 @@
 }
 
 
+bool HistogramTab::vectorDirty() const {
+  return _vector->selectedVectorDirty();
+}
+
+
 void HistogramTab::setVector(const VectorPtr vector) {
   _vector->setSelectedVector(vector);
 }
@@ -107,6 +137,11 @@
 }
 
 
+bool HistogramTab::minDirty() const {
+  return !_min->text().isEmpty();
+}
+
+
 void HistogramTab::setMin(const double min) {
   _min->setText(QString::number(min));
 }
@@ -117,6 +152,11 @@
 }
 
 
+bool HistogramTab::maxDirty() const {
+  return !_max->text().isEmpty();
+}
+
+
 void HistogramTab::setMax(const double max) {
   _max->setText(QString::number(max));
 }
@@ -127,6 +167,11 @@
 }
 
 
+bool HistogramTab::binsDirty() const {
+  return !_numberOfBins->text().isEmpty();
+}
+
+
 void HistogramTab::setBins(const int bins) {
   _numberOfBins->setValue(bins);
 }
@@ -137,6 +182,11 @@
 }
 
 
+bool HistogramTab::realTimeAutoBinDirty() const {
+  return _realTimeAutoBin->checkState() != Qt::PartiallyChecked;
+}
+
+
 void HistogramTab::setRealTimeAutoBin(const bool autoBin) {
   _realTimeAutoBin->setChecked(autoBin);
 }
@@ -156,6 +206,11 @@
 }
 
 
+bool HistogramTab::normalizationTypeDirty() const {
+  return _normalizationDirty;
+}
+
+
 void HistogramTab::setNormalizationType(const Histogram::NormalizationType normalizationType) {
   switch (normalizationType) {
     case Histogram::Fraction:
@@ -171,6 +226,7 @@
       _normalizationIsPercent->setChecked(true);
       break;
   }
+  resetNormalizationDirty();
 }
 
 
@@ -197,6 +253,17 @@
 }
 
 
+void HistogramTab::clearTabValues() {
+  _vector->clearSelection();
+  _min->clear();
+  _max->clear();
+  _numberOfBins->clear();
+  _realTimeAutoBin->setCheckState(Qt::PartiallyChecked);
+  _normalizationIsNumber->setChecked(true);
+  resetNormalizationDirty();
+}
+
+
 HistogramDialog::HistogramDialog(ObjectPtr dataObject, QWidget *parent)
   : DataDialog(dataObject, parent) {
 
@@ -215,6 +282,10 @@
   }
 
   connect(_histogramTab, SIGNAL(vectorChanged()), this, SLOT(updateButtons()));
+  connect(this, SIGNAL(editMultipleMode()), this, SLOT(editMultipleMode()));
+  connect(this, SIGNAL(editSingleMode()), this, SLOT(editSingleMode()));
+
+  connect(_histogramTab, SIGNAL(modified()), this, SLOT(modified()));
   updateButtons();
 }
 
@@ -228,6 +299,16 @@
 }
 
 
+void HistogramDialog::editMultipleMode() {
+  _histogramTab->clearTabValues();
+}
+
+
+void HistogramDialog::editSingleMode() {
+   configureTab(dataObject());
+}
+
+
 void HistogramDialog::configureTab(ObjectPtr object) {
   if (!object) {
     _histogramTab->setRealTimeAutoBin(_dialogDefaults->value("histogram/realTimeAutoBin", false).toBool());
@@ -240,12 +321,20 @@
     _histogramTab->setRealTimeAutoBin(histogram->realTimeAutoBin());
     _histogramTab->setNormalizationType(histogram->normalizationType());
     _histogramTab->hideCurveOptions();
+    if (_editMultipleWidget) {
+      QStringList objectList;
+      HistogramList objects = _document->objectStore()->getObjects<Histogram>();
+      foreach(HistogramPtr object, objects) {
+        objectList.append(object->tag().displayString());
+      }
+      _editMultipleWidget->addObjects(objectList);
+    }
   }
 }
 
 
 void HistogramDialog::updateButtons() {
-  _buttonBox->button(QDialogButtonBox::Ok)->setEnabled(_histogramTab->vector());
+  _buttonBox->button(QDialogButtonBox::Ok)->setEnabled(_histogramTab->vector() || (editMode() == EditMultiple));
 }
 
 
@@ -334,18 +423,42 @@
 
 ObjectPtr HistogramDialog::editExistingDataObject() const {
   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());
+    if (editMode() == EditMultiple) {
+      QStringList objects = _editMultipleWidget->selectedObjects();
+      foreach (QString objectTag, objects) {
+        HistogramPtr histogram = kst_cast<Histogram>(_document->objectStore()->retrieveObject(ObjectTag::fromString(objectTag)));
+        if (histogram) {
+          VectorPtr vector = _histogramTab->vectorDirty() ? _histogramTab->vector() : histogram->vector();
+          const double min = _histogramTab->minDirty() ? _histogramTab->min() : histogram->xMin();
+          const double max = _histogramTab->maxDirty() ? _histogramTab->max() : histogram->xMax();
+          const int bins = _histogramTab->binsDirty() ? _histogramTab->bins() : histogram->numberOfBins();
+          Histogram::NormalizationType normalizationType = _histogramTab->normalizationTypeDirty() ? _histogramTab->normalizationType() : histogram->normalizationType();
+          const bool realTimeAutoBin = _histogramTab->realTimeAutoBinDirty() ?  _histogramTab->realTimeAutoBin() : histogram->realTimeAutoBin();
 
-    histogram->update(0);
-    histogram->unlock();
+          histogram->writeLock();
+          histogram->setVector(vector);
+          histogram->setXRange(min, max);
+          histogram->setNumberOfBins(bins);
+          histogram->setNormalizationType(normalizationType);
+          histogram->setRealTimeAutoBin(realTimeAutoBin);
 
-    setHistogramDefaults(histogram);
+          histogram->update(0);
+          histogram->unlock();
+        }
+      }
+    } else {
+      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();
+
+      setHistogramDefaults(histogram);
+    }
   }
   return dataObject();
 }
--- branches/work/kst/portto4/kst/src/libkstapp/histogramdialog.h #745599:745600
@@ -34,35 +34,48 @@
     void setObjectStore(ObjectStore *store);
 
     VectorPtr vector() const;
+    bool vectorDirty() const;
     void setVector(VectorPtr vector);
 
     double min() const;
+    bool minDirty() const;
     void setMin(const double min);
 
     double max() const;
+    bool maxDirty() const;
     void setMax(const double max);
 
     int bins() const;
+    bool binsDirty() const;
     void setBins(const int bins);
 
     bool realTimeAutoBin() const;
+    bool realTimeAutoBinDirty() const;
     void setRealTimeAutoBin(const bool autoBin);
 
     Histogram::NormalizationType normalizationType() const;
+    bool normalizationTypeDirty() const;
     void setNormalizationType(const Histogram::NormalizationType normalizationType);
 
     CurveAppearance* curveAppearance() const;
     CurvePlacement* curvePlacement() const;
 
     void hideCurveOptions();
+    void clearTabValues();
 
+    void resetNormalizationDirty();
+
   private Q_SLOTS:
     void generateAutoBin();
     void updateButtons();
     void selectionChanged();
+    void normalizationChanged();
 
   Q_SIGNALS:
     void vectorChanged();
+
+  private:
+    bool _normalizationDirty;
 };
 
 class KST_EXPORT HistogramDialog : public DataDialog {
@@ -80,6 +93,8 @@
 
   private Q_SLOTS:
     void updateButtons();
+    void editMultipleMode();
+    void editSingleMode();
 
   private:
     void configureTab(ObjectPtr object=0);


More information about the Kst mailing list