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

Mike Fenton mike at staikos.net
Thu Oct 2 17:00:05 CEST 2008


SVN commit 866992 by fenton:

Updates to BasicPlugin Interfaces
1) Add Validation check to prevent invalid object creation.
2) Add Scalar Creation based on Parameter Vectors.


 M  +9 -0      libkstapp/filterfitdialog.cpp  
 M  +8 -6      libkstmath/basicplugin.cpp  
 M  +4 -3      libkstmath/basicplugin.h  
 M  +1 -0      plugins/fits/fits.pro  
 M  +12 -0     plugins/fits/gradient_unweighted/fitgradient_unweighted.cpp  
 M  +2 -0      plugins/fits/gradient_unweighted/fitgradient_unweighted.h  
 M  +12 -0     plugins/fits/gradient_weighted/fitgradient_weighted.cpp  
 M  +2 -0      plugins/fits/gradient_weighted/fitgradient_weighted.h  
 M  +15 -0     plugins/fits/linear_unweighted/fitlinear_unweighted.cpp  
 M  +2 -0      plugins/fits/linear_unweighted/fitlinear_unweighted.h  
 M  +18 -3     plugins/fits/linear_weighted/fitlinear_weighted.cpp  
 M  +3 -0      plugins/fits/linear_weighted/fitlinear_weighted.h  


--- branches/work/kst/portto4/kst/src/libkstapp/filterfitdialog.cpp #866991:866992
@@ -19,6 +19,8 @@
 #include "objectstore.h"
 #include "curve.h"
 
+#include <QMessageBox>
+
 namespace Kst {
 
 FilterFitTab::FilterFitTab(QString& pluginName, QWidget *parent)
@@ -166,6 +168,13 @@
   BasicPluginPtr dataObject = kst_cast<BasicPlugin>(DataObject::createPlugin(_pluginName, _document->objectStore(), _filterFitTab->configWidget()));
   Q_ASSERT(dataObject);
 
+  if (!dataObject->isValid()) {
+    _document->objectStore()->removeObject(dataObject);
+    QMessageBox::warning(this, tr("Kst"), tr("Unable to create Plugin Object using provided parameters."));
+
+    return 0;
+  }
+
   if (_plotItem) {
     CurvePtr curve = _document->objectStore()->createObject<Curve>();
 
--- branches/work/kst/portto4/kst/src/libkstmath/basicplugin.cpp #866991:866992
@@ -24,6 +24,7 @@
 #include "dialoglauncher.h"
 #include "datacollection.h"
 #include "objectstore.h"
+#include "dataobjectplugin.h"
 
 namespace Kst {
 
@@ -31,7 +32,7 @@
 const QString BasicPlugin::staticTypeTag = I18N_NOOP("plugin");
 
 BasicPlugin::BasicPlugin(ObjectStore *store)
-: DataObject(store), _isFit(false) {
+: DataObject(store) {
   _typeString = i18n("Plugin");
   _type = "Plugin";
 
@@ -240,7 +241,7 @@
   //Perform update on the outputs
   updateOutput();
 
-  createFitScalars();
+  createScalars();
 
   unlockInputsAndOutputs();
 
@@ -249,12 +250,12 @@
 
 
 // FIXME: BasicPlugin should not know about fit scalars!!
-void BasicPlugin::createFitScalars() {
+void BasicPlugin::createScalars() {
   // Assumes that this is called with a write lock in place on this object
   Q_ASSERT(myLockStatus() == KstRWLock::WRITELOCKED);
 
-  if (_isFit && _outputVectors.contains("Parameters")) {
-    VectorPtr vectorParam = _outputVectors["Parameters"];
+  if (_outputVectors.contains("Parameters Vector")) {
+    VectorPtr vectorParam = _outputVectors["Parameters Vector"];
     if (vectorParam) {
       QString paramName;
       int i = 0;
@@ -268,8 +269,9 @@
         if (!_outputScalars.contains(paramName)) {
           ScalarPtr s = store()->createObject<Scalar>();
           s->setProvider(this);
-          //FIXME: set slaveName
+          s->setSlaveName(paramName);
           s->setValue(scalarValue);
+          s->writeLock();
           _outputScalars.insert(paramName, s);
         } else {
           _outputScalars[paramName]->setValue(scalarValue);
--- branches/work/kst/portto4/kst/src/libkstmath/basicplugin.h #866991:866992
@@ -51,6 +51,9 @@
 
     virtual QString descriptionTip() const;
 
+    // Validator of plugin data.  Expensive, only use to verify successful creation.
+    bool isValid() { return algorithm(); }
+
   public slots:
     //Pure virtual slots from DataObject
     //Each plugin can provide an implementation or use the default
@@ -88,9 +91,7 @@
     virtual void save(QXmlStreamWriter &s);
     virtual void saveProperties(QXmlStreamWriter &s);
 
-    bool isFit() const { return _isFit; }
-    // FIXME: remove this
-    void createFitScalars();
+    void createScalars();
     QString label(int precision) const;
 
   protected:
--- branches/work/kst/portto4/kst/src/plugins/fits/fits.pro #866991:866992
@@ -6,3 +6,4 @@
     gradient_unweighted \
     linear_weighted \
     linear_unweighted
+
--- branches/work/kst/portto4/kst/src/plugins/fits/gradient_unweighted/fitgradient_unweighted.cpp #866991:866992
@@ -257,6 +257,18 @@
 }
 
 
+QString FitGradientUnweightedSource::parameterName(int index) const {
+  QString parameter;
+  switch (index) {
+    case 0:
+      parameter = "Gradient";
+      break;
+  }
+
+  return parameter;
+}
+
+
 // Name used to identify the plugin.  Used when loading the plugin.
 QString FitGradientUnweightedPlugin::pluginName() const { return "Gradient Fit"; }
 QString FitGradientUnweightedPlugin::pluginDescription() const { return "Generates a gradient fit for a set of data."; }
--- branches/work/kst/portto4/kst/src/plugins/fits/gradient_unweighted/fitgradient_unweighted.h #866991:866992
@@ -44,6 +44,8 @@
     FitGradientUnweightedSource(Kst::ObjectStore *store);
     ~FitGradientUnweightedSource();
 
+    virtual QString parameterName(int index) const;
+
   friend class Kst::ObjectStore;
 
 
--- branches/work/kst/portto4/kst/src/plugins/fits/gradient_weighted/fitgradient_weighted.cpp #866991:866992
@@ -279,6 +279,18 @@
 }
 
 
+QString FitGradientWeightedSource::parameterName(int index) const {
+  QString parameter;
+  switch (index) {
+    case 0:
+      parameter = "Gradient";
+      break;
+  }
+
+  return parameter;
+}
+
+
 // Name used to identify the plugin.  Used when loading the plugin.
 QString FitGradientWeightedPlugin::pluginName() const { return "Gradient Weighted Fit"; }
 QString FitGradientWeightedPlugin::pluginDescription() const { return "Generates a gradient weighted fit for a set of data."; }
--- branches/work/kst/portto4/kst/src/plugins/fits/gradient_weighted/fitgradient_weighted.h #866991:866992
@@ -45,6 +45,8 @@
     FitGradientWeightedSource(Kst::ObjectStore *store);
     ~FitGradientWeightedSource();
 
+    virtual QString parameterName(int index) const;
+
   friend class Kst::ObjectStore;
 
 
--- branches/work/kst/portto4/kst/src/plugins/fits/linear_unweighted/fitlinear_unweighted.cpp #866991:866992
@@ -261,6 +261,21 @@
 }
 
 
+QString FitLinearUnweightedSource::parameterName(int index) const {
+  QString parameter;
+  switch (index) {
+    case 0:
+      parameter = "Intercept";
+      break;
+    case 1:
+      parameter = "Gradient";
+      break;
+  }
+
+  return parameter;
+}
+
+
 // Name used to identify the plugin.  Used when loading the plugin.
 QString FitLinearUnweightedPlugin::pluginName() const { return "Linear Fit"; }
 QString FitLinearUnweightedPlugin::pluginDescription() const { return "Generates a linear fit for a set of data."; }
--- branches/work/kst/portto4/kst/src/plugins/fits/linear_unweighted/fitlinear_unweighted.h #866991:866992
@@ -44,6 +44,8 @@
     FitLinearUnweightedSource(Kst::ObjectStore *store);
     ~FitLinearUnweightedSource();
 
+    virtual QString parameterName(int index) const;
+
   friend class Kst::ObjectStore;
 
 
--- branches/work/kst/portto4/kst/src/plugins/fits/linear_weighted/fitlinear_weighted.cpp #866991:866992
@@ -183,7 +183,7 @@
 
   int i = 0;
   int iLength;
-  int iReturn = -1;
+  bool bReturn = false;
   double* pInputs[3];
   double c0 = 0.0;
   double c1 = 0.0;
@@ -212,13 +212,13 @@
       outputVectorYCovariance->value()[2] = cov11;
 
       outputScalar->setValue(dSumSq / ( (double)iLength - 2.0 ));
-      iReturn = 0;
+      bReturn = true;
     }
   }
 
   postcursor( true, pInputs );
 
-  return iReturn;
+  return bReturn;
 }
 
 
@@ -283,6 +283,21 @@
 }
 
 
+QString FitLinearWeightedSource::parameterName(int index) const {
+  QString parameter;
+  switch (index) {
+    case 0:
+      parameter = "Intercept";
+      break;
+    case 1:
+      parameter = "Gradient";
+      break;
+  }
+
+  return parameter;
+}
+
+
 // Name used to identify the plugin.  Used when loading the plugin.
 QString FitLinearWeightedPlugin::pluginName() const { return "Linear Weighted Fit"; }
 QString FitLinearWeightedPlugin::pluginDescription() const { return "Generates a linear weighted fit for a set of data."; }
--- branches/work/kst/portto4/kst/src/plugins/fits/linear_weighted/fitlinear_weighted.h #866991:866992
@@ -41,10 +41,13 @@
 
     virtual void saveProperties(QXmlStreamWriter &s);
 
+
   protected:
     FitLinearWeightedSource(Kst::ObjectStore *store);
     ~FitLinearWeightedSource();
 
+    virtual QString parameterName(int index) const;
+
   friend class Kst::ObjectStore;
 
 


More information about the Kst mailing list