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

Mike Fenton mike at staikos.net
Mon Oct 22 15:49:10 CEST 2007


SVN commit 728125 by fenton:

Add creation of Images and addition of Kst Grayscale palette.


 M  +112 -4    libkstapp/imagedialog.cpp  
 M  +13 -1     libkstapp/imagedialog.h  
 M  +19 -8     libkstmath/palette.cpp  
 M  +1 -1      libkstmath/palette.h  


--- branches/work/kst/portto4/kst/src/libkstapp/imagedialog.cpp #728124:728125
@@ -56,6 +56,55 @@
 }
 
 
+bool ImageTab::realTimeAutoThreshold() const {
+  return _realTimeAutoThreshold->isChecked();
+}
+
+
+bool ImageTab::colorOnly() const {
+  return _colorOnly->isChecked();
+}
+
+
+bool ImageTab::contourOnly() const {
+  return _contourOnly->isChecked();
+}
+
+
+bool ImageTab::colorAndContour() const {
+  return _colorAndContour->isChecked();
+}
+
+
+MatrixPtr ImageTab::matrix() const {
+  return _matrix->selectedMatrix();
+}
+
+
+double ImageTab::lowerZ() const {
+  return _lowerZ->text().toDouble();
+}
+
+
+double ImageTab::upperZ() const {
+  return _upperZ->text().toDouble();
+}
+
+
+int ImageTab::numberOfContourLines() const {
+  return _numContourLines->value();
+}
+
+
+int ImageTab::contourWeight() const {
+  return _contourWeight->value();
+}
+
+
+QColor ImageTab::contourColor() const {
+  return _contourColor->color();
+}
+
 void ImageTab::realTimeAutoThresholdToggled(const bool checked) {
   _lowerZ->setEnabled(!checked);
   _upperZ->setEnabled(!checked);
@@ -79,8 +128,8 @@
   else
     setWindowTitle(tr("New Image"));
 
-  _ImageTab = new ImageTab(this);
-  addDataTab(_ImageTab);
+  _imageTab = new ImageTab(this);
+  addDataTab(_imageTab);
 
   //FIXME need to do validation to enable/disable ok button...
 }
@@ -96,8 +145,67 @@
 
 
 ObjectPtr ImageDialog::createNewDataObject() const {
-  qDebug() << "createNewDataObject" << endl;
-  return 0;
+
+  ImagePtr image;
+
+  if (_imageTab->colorOnly()) {
+    image = new Image(tagName(),
+                                    _imageTab->matrix(),
+                                    _imageTab->lowerZ(),
+                                    _imageTab->upperZ(),
+                                    _imageTab->realTimeAutoThreshold(),
+                                    Palette(_imageTab->colorPalette()->selectedPalette()).paletteData());
+  } else if (_imageTab->contourOnly()) {
+    image = new Image(tagName(),
+                                    _imageTab->matrix(),
+                                    _imageTab->numberOfContourLines(),
+                                    _imageTab->contourColor(),
+                                    _imageTab->contourWeight());
+  } else {
+    image = new Image(tagName(),
+                                    _imageTab->matrix(),
+                                    _imageTab->lowerZ(),
+                                    _imageTab->upperZ(),
+                                    _imageTab->realTimeAutoThreshold(),
+                                    Palette(_imageTab->colorPalette()->selectedPalette()).paletteData(),
+                                    _imageTab->numberOfContourLines(),
+                                    _imageTab->contourColor(),
+                                    _imageTab->contourWeight());
+  }
+
+  image->writeLock();
+  image->update(0);
+  image->unlock();
+
+  PlotItem *plotItem = 0;
+  switch (_imageTab->curvePlacement()->place()) {
+  case CurvePlacement::NoPlot:
+    break;
+  case CurvePlacement::ExistingPlot:
+    {
+      plotItem = static_cast<PlotItem*>(_imageTab->curvePlacement()->existingPlot());
+      break;
+    }
+  case CurvePlacement::NewPlot:
+    {
+      CreatePlotForCurve *cmd = new CreatePlotForCurve(
+        _imageTab->curvePlacement()->createLayout(),
+        _imageTab->curvePlacement()->appendToLayout());
+      cmd->createItem();
+
+      plotItem = static_cast<PlotItem*>(cmd->item());
+      break;
+    }
+  default:
+    break;
+  }
+
+  PlotRenderItem *renderItem = plotItem->renderItem(PlotRenderItem::Cartesian);
+  //TODO  Adam, is this the correct way to draw an image?  It runs very slow.
+  renderItem->addRelation(kst_cast<Relation>(image));
+  plotItem->update();
+
+  return ObjectPtr(image.data());
 }
 
 
--- branches/work/kst/portto4/kst/src/libkstapp/imagedialog.h #728124:728125
@@ -34,6 +34,18 @@
     CurvePlacement* curvePlacement() const;
     ColorPalette* colorPalette() const;
 
+    bool realTimeAutoThreshold() const;
+    bool colorOnly() const;
+    bool contourOnly() const;
+    bool colorAndContour() const;
+    double lowerZ() const;
+    double upperZ() const;
+    int numberOfContourLines() const;
+    int contourWeight() const;
+    QColor contourColor() const;
+
+    MatrixPtr matrix() const;
+
   private Q_SLOTS:
     void realTimeAutoThresholdToggled(const bool checked);
     void updateEnabled(const bool checked);
@@ -52,7 +64,7 @@
     virtual ObjectPtr editExistingDataObject() const;
 
   private:
-    ImageTab *_ImageTab;
+    ImageTab *_imageTab;
 };
 
 }
--- branches/work/kst/portto4/kst/src/libkstmath/palette.cpp #728124:728125
@@ -32,6 +32,7 @@
 static const int KstColorsCount = sizeof(KstColors) / sizeof(char*);
 
 static const QString KstColorsName = "Kst Colors";
+static const QString KstGrayscaleName = "Kst Grayscale";
 
 
 QStringList Palette::getPaletteList() { 
@@ -39,6 +40,7 @@
 
   //TODO Populate a shared list of colors to return here.
   paletteList.append(KstColorsName);
+  paletteList.append(KstGrayscaleName);
 
   return paletteList;
 }
@@ -49,9 +51,7 @@
 
 
 Palette::Palette(const QString &paletteName) {
-  Q_UNUSED(paletteName);
-  // Use PaletteName to construct a palette by name when palette list exists.
-  createPalette();
+  createPalette(paletteName);
 }
 
 
@@ -63,7 +63,7 @@
   return _paletteName;
 }
 
-
+  
 int Palette::colorCount() const {
   return _count;
 }
@@ -77,13 +77,24 @@
 }
 
 
-void Palette::createPalette() {
+void Palette::createPalette(const QString &paletteName) {
   //TODO Get Palette details from a palette name parameter when a shared list exists.
   _palette.clear();
-  _paletteName = KstColorsName;
+  if (paletteName.isEmpty()) {
+    _paletteName = KstColorsName;
+  } else {
+    //TODO when a proper shared list exists, validate that the palette exists.
+    _paletteName = paletteName;
+  }
 
-  for (int i = 0; i < KstColorsCount; i++) {
-    _palette.insert(i, QColor(KstColors[i]));
+  if (_paletteName == KstColorsName) {
+    for (int i = 0; i < KstColorsCount; i++) {
+      _palette.insert(i, QColor(KstColors[i]));
+    }
+  } else {
+    for (int i = 0; i < 255; i++) {
+      _palette.insert(i, QColor(i, i, i));
+    }
   }
   _count = _palette.count();
 }
--- branches/work/kst/portto4/kst/src/libkstmath/palette.h #728124:728125
@@ -35,7 +35,7 @@
     PaletteData paletteData() const;
 
   private:
-    void createPalette();
+    void createPalette(const QString &paletteName = QString());
 
     PaletteData _palette;
     QString _paletteName;


More information about the Kst mailing list