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

Mike Fenton mike at staikos.net
Fri Nov 16 15:37:08 CET 2007


SVN commit 737559 by fenton:

Add Edit support for ImageDialog.
Update ImageDialog to include proper calculations for Min/Max and Smart Thresholds.


 M  +3 -1      libkstapp/datamanager.cpp  
 M  +178 -16   libkstapp/imagedialog.cpp  
 M  +34 -2     libkstapp/imagedialog.h  
 M  +16 -7     libkstapp/imagetab.ui  
 M  +5 -1      widgets/colorpalette.cpp  
 M  +1 -0      widgets/colorpalette.h  


--- branches/work/kst/portto4/kst/src/libkstapp/datamanager.cpp #737558:737559
@@ -26,8 +26,8 @@
 #include "histogram.h"
 #include "psd.h"
 #include "eventmonitorentry.h"
+#include "image.h"
 
-
 #include <QHeaderView>
 #include <QToolBar>
 #include <QMenu>
@@ -158,6 +158,8 @@
       DialogLauncher::self()->showPowerSpectrumDialog(psd);
     } else if (EventMonitorEntryPtr eventMonitorEntry = kst_cast<EventMonitorEntry>(_currentObject)) {
       DialogLauncher::self()->showEventMonitorDialog(eventMonitorEntry);
+    } else if (ImagePtr image = kst_cast<Image>(_currentObject)) {
+      DialogLauncher::self()->showImageDialog(image);
     } else if (VectorPtr vector = kst_cast<Vector>(_currentObject)) {
       DialogLauncher::self()->showVectorDialog(vector);
     }
--- branches/work/kst/portto4/kst/src/libkstapp/imagedialog.cpp #737558:737559
@@ -41,6 +41,8 @@
   connect(_colorOnly, SIGNAL(toggled(const bool&)), this, SLOT(updateEnabled(const bool&)));
   connect(_colorAndContour, SIGNAL(toggled(const bool&)), this, SLOT(updateEnabled(const bool&)));
   connect(_contourOnly, SIGNAL(toggled(const bool&)), this, SLOT(updateEnabled(const bool&)));
+  connect(_autoThreshold, SIGNAL(clicked()), this, SLOT(calculateAutoThreshold()));
+  connect(_smartThreshold, SIGNAL(clicked()), this, SLOT(calculateSmartThreshold()));
 
   connect(_matrix, SIGNAL(selectionChanged()), this, SLOT(selectionChanged()));
 }
@@ -51,6 +53,8 @@
 
 
 void ImageTab::selectionChanged() {
+  _autoThreshold->setEnabled(_matrix->selectedMatrix() && !realTimeAutoThreshold());
+  _smartThreshold->setEnabled(_matrix->selectedMatrix() && !realTimeAutoThreshold());
   emit optionsChanged();
 }
 
@@ -70,58 +74,120 @@
 }
 
 
+void ImageTab::setRealTimeAutoThreshold(const bool realTimeAutoThreshold) {
+  _realTimeAutoThreshold->setChecked(realTimeAutoThreshold);
+}
+
+
 bool ImageTab::colorOnly() const {
   return _colorOnly->isChecked();
 }
 
 
+void ImageTab::setColorOnly(const bool colorOnly) {
+  _colorOnly->setChecked(colorOnly);
+}
+
+
 bool ImageTab::contourOnly() const {
   return _contourOnly->isChecked();
 }
 
 
+void ImageTab::setContourOnly(const bool contourOnly) {
+  _contourOnly->setChecked(contourOnly);
+}
+
+
 bool ImageTab::colorAndContour() const {
   return _colorAndContour->isChecked();
 }
 
 
+void ImageTab::setColorAndContour(const bool colorAndContour) {
+  _colorAndContour->setChecked(colorAndContour);
+}
+
+
+bool ImageTab::useVariableLineWeight() const {
+  return _useVariableWeight->isChecked();
+}
+
+
+void ImageTab::setUseVariableLineWeight(const bool useVariableLineWeight) {
+  _useVariableWeight->setChecked(useVariableLineWeight);
+}
+
+
 MatrixPtr ImageTab::matrix() const {
   return _matrix->selectedMatrix();
 }
 
 
-double ImageTab::lowerZ() const {
-  return _lowerZ->text().toDouble();
+void ImageTab::setMatrix(const MatrixPtr matrix) {
+  _matrix->setSelectedMatrix(matrix);
 }
 
 
-double ImageTab::upperZ() const {
-  return _upperZ->text().toDouble();
+double ImageTab::lowerThreshold() const {
+  return _lowerThreshold->text().toDouble();
 }
 
 
+void ImageTab::setLowerThreshold(const double lowerThreshold) {
+  _lowerThreshold->setText(QString::number(lowerThreshold));
+}
+
+
+double ImageTab::upperThreshold() const {
+  return _upperThreshold->text().toDouble();
+}
+
+
+void ImageTab::setUpperThreshold(const double upperThreshold) {
+  _upperThreshold->setText(QString::number(upperThreshold));
+}
+
+
 int ImageTab::numberOfContourLines() const {
   return _numContourLines->value();
 }
 
 
+void ImageTab::setNumberOfContourLines(const int numberOfContourLines) {
+  _numContourLines->setValue(numberOfContourLines);
+}
+
+
 int ImageTab::contourWeight() const {
   return _contourWeight->value();
 }
 
 
+void ImageTab::setContourWeight(const int contourWeight) {
+  _contourWeight->setValue(contourWeight);
+}
+
+
 QColor ImageTab::contourColor() const {
   return _contourColor->color();
 }
 
+
+void ImageTab::setContourColor(const QColor contourColor) {
+  _contourColor->setColor(contourColor);
+}
+
+
 void ImageTab::realTimeAutoThresholdToggled(const bool checked) {
-  _lowerZ->setEnabled(!checked);
-  _upperZ->setEnabled(!checked);
-  _autoThreshold->setEnabled(!checked);
-  _smartThreshold->setEnabled(!checked);
+  _lowerThreshold->setEnabled(!checked);
+  _upperThreshold->setEnabled(!checked);
   _smartThresholdValue->setEnabled(!checked);
+  _autoThreshold->setEnabled(_matrix->selectedMatrix() && !checked);
+  _smartThreshold->setEnabled(_matrix->selectedMatrix() && !checked);
 }
 
+
 void ImageTab::updateEnabled(const bool checked) {
   Q_UNUSED(checked);
   _colorMapGroup->setEnabled(_colorOnly->isChecked() || _colorAndContour->isChecked());
@@ -129,11 +195,43 @@
 }
 
 
+void ImageTab::calculateAutoThreshold() {
+  MatrixPtr matrix = _matrix->selectedMatrix();
+  if (matrix) {
+    matrix->readLock();
+    _lowerThreshold->setText(QString::number(matrix->minValue()));
+    _upperThreshold->setText(QString::number(matrix->maxValue()));
+    matrix->unlock();
+  }
+}
+
+
+void ImageTab::calculateSmartThreshold() {
+  MatrixPtr matrix = _matrix->selectedMatrix();
+  if (matrix) {
+    matrix->readLock();
+    double per = _smartThresholdValue->text().toDouble()/100.0;
+
+    matrix->calcNoSpikeRange(per);
+    _lowerThreshold->setText(QString::number(matrix->minValueNoSpike()));
+    _upperThreshold->setText(QString::number(matrix->maxValueNoSpike()));
+    matrix->unlock();
+  }
+}
+
+
 void ImageTab::setObjectStore(ObjectStore *store) {
   _matrix->setObjectStore(store);
+  _store = store;
 }
 
 
+void ImageTab::hidePlacementOptions() {
+  _curvePlacement->setVisible(false);
+  setMaximumHeight(335);
+}
+
+
 ImageDialog::ImageDialog(ObjectPtr dataObject, QWidget *parent)
   : DataDialog(dataObject, parent) {
 
@@ -145,6 +243,10 @@
   _imageTab = new ImageTab(this);
   addDataTab(_imageTab);
 
+  if (editMode() == Edit) {
+    configureTab(dataObject);
+  }
+
   connect(_imageTab, SIGNAL(optionsChanged()), this, SLOT(updateButtons()));
   updateButtons();
 }
@@ -164,6 +266,40 @@
 }
 
 
+void ImageDialog::configureTab(ObjectPtr object) {
+  if (ImagePtr image = kst_cast<Image>(object)) {
+    _imageTab->setMatrix(image->matrix());
+
+    if (image->hasContourMap() && image->hasColorMap()) {
+      _imageTab->setColorAndContour(true);
+      _imageTab->setNumberOfContourLines(image->numContourLines());
+      _imageTab->setContourColor(image->contourColor());
+      _imageTab->setContourWeight(image->contourWeight());
+      _imageTab->setLowerThreshold(image->lowerThreshold());
+      _imageTab->setUpperThreshold(image->upperThreshold());
+      _imageTab->setRealTimeAutoThreshold(image->autoThreshold());
+      _imageTab->colorPalette()->setPalette(image->paletteName());
+      _imageTab->setUseVariableLineWeight(image->contourWeight() == -1);
+
+    } else if (image->hasContourMap()) {
+      _imageTab->setContourOnly(true);
+      _imageTab->setNumberOfContourLines(image->numContourLines());
+      _imageTab->setContourColor(image->contourColor());
+      _imageTab->setContourWeight(image->contourWeight());
+      _imageTab->setUseVariableLineWeight(image->contourWeight() == -1);
+    } else {
+      _imageTab->setColorOnly(true);
+      _imageTab->setLowerThreshold(image->lowerThreshold());
+      _imageTab->setUpperThreshold(image->upperThreshold());
+      _imageTab->setRealTimeAutoThreshold(image->autoThreshold());
+      _imageTab->colorPalette()->setPalette(image->paletteName());
+    }
+
+    _imageTab->hidePlacementOptions();
+  }
+}
+
+
 ObjectPtr ImageDialog::createNewDataObject() const {
 
   Q_ASSERT(_document && _document->objectStore());
@@ -172,24 +308,24 @@
 
   if (_imageTab->colorOnly()) {
     image->changeToColorOnly(_imageTab->matrix(),
-        _imageTab->lowerZ(),
-        _imageTab->upperZ(),
+        _imageTab->lowerThreshold(),
+        _imageTab->upperThreshold(),
         _imageTab->realTimeAutoThreshold(),
         _imageTab->colorPalette()->selectedPalette());
   } else if (_imageTab->contourOnly()) {
     image->changeToContourOnly(_imageTab->matrix(),
         _imageTab->numberOfContourLines(),
         _imageTab->contourColor(),
-        _imageTab->contourWeight());
+        _imageTab->useVariableLineWeight() ? -1 : _imageTab->contourWeight());
   } else {
     image->changeToColorAndContour(_imageTab->matrix(),
-        _imageTab->lowerZ(),
-        _imageTab->upperZ(),
+        _imageTab->lowerThreshold(),
+        _imageTab->upperThreshold(),
         _imageTab->realTimeAutoThreshold(),
         _imageTab->colorPalette()->selectedPalette(),
         _imageTab->numberOfContourLines(),
         _imageTab->contourColor(),
-        _imageTab->contourWeight());
+        _imageTab->useVariableLineWeight() ? -1 : _imageTab->contourWeight());
   }
 
   image->writeLock();
@@ -229,8 +365,34 @@
 
 
 ObjectPtr ImageDialog::editExistingDataObject() const {
-  qDebug() << "editExistingDataObject" << endl;
-  return 0;
+  if (ImagePtr image = kst_cast<Image>(dataObject())) {
+    image->writeLock();
+    if (_imageTab->colorOnly()) {
+      image->changeToColorOnly(_imageTab->matrix(),
+          _imageTab->lowerThreshold(),
+          _imageTab->upperThreshold(),
+          _imageTab->realTimeAutoThreshold(),
+          _imageTab->colorPalette()->selectedPalette());
+    } else if (_imageTab->contourOnly()) {
+      image->changeToContourOnly(_imageTab->matrix(),
+          _imageTab->numberOfContourLines(),
+          _imageTab->contourColor(),
+          _imageTab->useVariableLineWeight() ? -1 : _imageTab->contourWeight());
+    } else {
+      image->changeToColorAndContour(_imageTab->matrix(),
+          _imageTab->lowerThreshold(),
+          _imageTab->upperThreshold(),
+          _imageTab->realTimeAutoThreshold(),
+          _imageTab->colorPalette()->selectedPalette(),
+          _imageTab->numberOfContourLines(),
+          _imageTab->contourColor(),
+          _imageTab->useVariableLineWeight() ? -1 : _imageTab->contourWeight());
+    }
+
+    image->update(0);
+    image->unlock();
+  }
+  return dataObject();
 }
 
 }
--- branches/work/kst/portto4/kst/src/libkstapp/imagedialog.h #737558:737559
@@ -25,6 +25,8 @@
 
 namespace Kst {
 
+  class ObjectStore;
+
 class KST_EXPORT ImageTab : public DataTab, Ui::ImageTab {
   Q_OBJECT
   public:
@@ -37,24 +39,52 @@
     void setObjectStore(ObjectStore *store);
 
     bool realTimeAutoThreshold() const;
+    void setRealTimeAutoThreshold(const bool realTimeAutoThreshold);
+
     bool colorOnly() const;
+    void setColorOnly(const bool colorOnly);
+
     bool contourOnly() const;
+    void setContourOnly(const bool contourOnly);
+
     bool colorAndContour() const;
-    double lowerZ() const;
-    double upperZ() const;
+    void setColorAndContour(const bool colorAndContour);
+
+    double lowerThreshold() const;
+    void setLowerThreshold(const double lowerThreshold);
+
+    double upperThreshold() const;
+    void setUpperThreshold(const double upperThreshold);
+
     int numberOfContourLines() const;
+    void setNumberOfContourLines(const int numberOfContourLines);
+
     int contourWeight() const;
+    void setContourWeight(const int contourWeight);
+
     QColor contourColor() const;
+    void setContourColor(const QColor contourColor);
 
     MatrixPtr matrix() const;
+    void setMatrix(const MatrixPtr matrix);
 
+    bool useVariableLineWeight() const;
+    void setUseVariableLineWeight(const bool useVariableLineWeight);
+
+    void hidePlacementOptions();
+
   private Q_SLOTS:
     void realTimeAutoThresholdToggled(const bool checked);
     void updateEnabled(const bool checked);
     void selectionChanged();
+    void calculateAutoThreshold();
+    void calculateSmartThreshold();
 
   Q_SIGNALS:
     void optionsChanged();
+
+  private:
+    ObjectStore* _store;
 };
 
 class KST_EXPORT ImageDialog : public DataDialog {
@@ -72,6 +102,8 @@
     void updateButtons();
 
   private:
+    void configureTab(ObjectPtr object);
+
     ImageTab *_imageTab;
 };
 
--- branches/work/kst/portto4/kst/src/libkstapp/imagetab.ui #737558:737559
@@ -196,12 +196,12 @@
            <bool>false</bool>
           </property>
           <property name="buddy" >
-           <cstring>_upperZ</cstring>
+           <cstring>_upperThreshold</cstring>
           </property>
          </widget>
         </item>
         <item>
-         <widget class="QLineEdit" name="_upperZ" >
+         <widget class="QLineEdit" name="_upperThreshold" >
           <property name="enabled" >
            <bool>false</bool>
           </property>
@@ -238,12 +238,12 @@
            <bool>false</bool>
           </property>
           <property name="buddy" >
-           <cstring>_lowerZ</cstring>
+           <cstring>_lowerThreshold</cstring>
           </property>
          </widget>
         </item>
         <item>
-         <widget class="QLineEdit" name="_lowerZ" >
+         <widget class="QLineEdit" name="_lowerThreshold" >
           <property name="enabled" >
            <bool>false</bool>
           </property>
@@ -304,10 +304,19 @@
          </widget>
         </item>
         <item>
-         <widget class="QLineEdit" name="_smartThresholdValue" >
+         <widget class="QDoubleSpinBox" name="_smartThresholdValue" >
           <property name="enabled" >
            <bool>false</bool>
           </property>
+          <property name="decimals" >
+           <number>1</number>
+          </property>
+          <property name="maximum" >
+           <double>45.000000000000000</double>
+          </property>
+          <property name="value" >
+           <double>0.500000000000000</double>
+          </property>
          </widget>
         </item>
        </layout>
@@ -587,8 +596,8 @@
  <tabstops>
   <tabstop>_matrix</tabstop>
   <tabstop>_colorOnly</tabstop>
-  <tabstop>_lowerZ</tabstop>
-  <tabstop>_upperZ</tabstop>
+  <tabstop>_lowerThreshold</tabstop>
+  <tabstop>_upperThreshold</tabstop>
   <tabstop>_autoThreshold</tabstop>
   <tabstop>_realTimeAutoThreshold</tabstop>
   <tabstop>_numContourLines</tabstop>
--- branches/work/kst/portto4/kst/src/widgets/colorpalette.cpp #737558:737559
@@ -69,12 +69,16 @@
 }
 
 
-
 QString ColorPalette::selectedPalette() {
    return _palette->currentText();
 }
 
 
+void ColorPalette::setPalette(const QString palette) {
+   _palette->setCurrentIndex(_palette->findText(palette));
+}
+
+
 void ColorPalette::refresh( const QString & palette ) {
   _palette->clear();
 
--- branches/work/kst/portto4/kst/src/widgets/colorpalette.h #737558:737559
@@ -29,6 +29,7 @@
   QString selectedPalette();
   void refresh(const QString &palette = QString());
   int currentPaletteIndex();
+  void setPalette(const QString palette);
 
 public slots:
   void updatePalette(const QString &palette = QString());


More information about the Kst mailing list