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

Adam Treat treat at kde.org
Thu Sep 14 02:06:36 CEST 2006


SVN commit 584016 by treat:

* Add newObject functionality to the linefit plugin.
* Save the output scalars.
* Connect some missing signals so that datamanager is updated
on 'new' or 'edit'.
* Fix a type in the dom snippet saving.
* Need to fix the signal connection between KstDataDialog's and
KstDoc... this should take place in the KstDataDialog ctor so that
all dialogs benefit.  In general, need to go over the API and make
it as simple as possible to produce plugins.




 M  +1 -0      libkstapp/kst.cpp  
 M  +9 -5      libkstapp/kstdoc.cpp  
 M  +2 -3      libkstmath/kstdataobject.cpp  
 M  +1 -1      libkstmath/kstdataobject.h  
 M  +68 -20    plugins/linefit/linefitdialog_i.cpp  
 M  +1 -2      plugins/linefit/linefitdialog_i.h  
 M  +33 -7     plugins/linefit/linefitplugin.cpp  
 M  +5 -5      plugins/linefit/linefitplugin.h  


--- branches/work/kst/pluginify/kst/src/libkstapp/kst.cpp #584015:584016
@@ -162,6 +162,7 @@
   _quickStartDialog = new KstQuickStartDialogI(this, 0 , true);
 #endif
 
+  //FIXME these should be in KstDataDialog constructor...
   connect(KstVectorDialogI::globalInstance(), SIGNAL(modified()), doc, SLOT(wasModified()));
   connect(KstCurveDialogI::globalInstance(), SIGNAL(modified()), doc, SLOT(wasModified()));
   connect(KstCsdDialogI::globalInstance(), SIGNAL(modified()), doc, SLOT(wasModified()));
--- branches/work/kst/pluginify/kst/src/libkstapp/kstdoc.cpp #584015:584016
@@ -382,12 +382,16 @@
       } else if (e.tagName() == "plugin") {
         const QString name = e.attribute("name");
         KstDataObjectPtr p;
-        if ( name.isEmpty() )
+        if (name.isEmpty()) {
           p = new KstPlugin(e);
-        else
-          p = KstDataObject::createPlugin(name, e);
-        KstWriteLocker dowl(&KST::dataObjectList.lock());
-        KST::dataObjectList.append(p);
+        } else {
+          if (p = KstDataObject::createPlugin(name))
+            p->load(e);
+        }
+        if (p) {
+          KstWriteLocker dowl(&KST::dataObjectList.lock());
+          KST::dataObjectList.append(p);
+        }
       } else if (e.tagName() == "curve") {
         KstDataObjectPtr p = new KstVCurve(e);
         KstWriteLocker dowl(&KST::dataObjectList.lock());
--- branches/work/kst/pluginify/kst/src/libkstmath/kstdataobject.cpp #584015:584016
@@ -142,7 +142,7 @@
         return 0;
 }
 
-KstDataObjectPtr KstDataObject::createPlugin( const QString &name, const QDomElement &e )
+KstDataObjectPtr KstDataObject::createPlugin( const QString &name )
 {
   KService::List sl = KServiceType::offers("Kst Data Object");
   for (KService::List::ConstIterator it = sl.begin(); it != sl.end(); ++it) {
@@ -150,8 +150,7 @@
       continue;
     }
     else if ( KstDataObjectPtr object = createPlugin( *it ) ) {
-        object->load( e );
-        return object;
+      return object;
     }
   }
   return 0;
--- branches/work/kst/pluginify/kst/src/libkstmath/kstdataobject.h #584015:584016
@@ -45,7 +45,7 @@
     /** Returns a list of object plugins found on the system. */
     static QStringList pluginList();
     static KstDataObjectPtr plugin( const QString &name );
-    static KstDataObjectPtr createPlugin( const QString &name, const QDomElement& e );
+    static KstDataObjectPtr createPlugin( const QString &name );
 
     virtual UpdateType update(int updateCounter = -1) = 0;
     virtual const QString& typeString() const { return _typeString; }
--- branches/work/kst/pluginify/kst/src/plugins/linefit/linefitdialog_i.cpp #584015:584016
@@ -42,9 +42,12 @@
 
 // application specific includes
 #include <kst.h>
+#include <kstdoc.h>
 #include <scalarselector.h>
 #include <stringselector.h>
 #include <vectorselector.h>
+#include <kstdefaultnames.h>
+#include <kstdataobjectcollection.h>
 
 const QString& LineFitDialogI::defaultTag = KGlobal::staticQString("<Auto Name>");
 
@@ -54,6 +57,14 @@
 : KstDataDialog(parent, name, modal, fl) {
   _w = new LineFitDialogWidget(_contents);
   setMultiple(false);
+
+  connect(_w->_xArray, SIGNAL(newVectorCreated(const QString&)), this, SIGNAL(modified()));
+  connect(_w->_xArray, SIGNAL(newVectorCreated(const QString&)), this, SIGNAL(modified()));
+
+  _w->_xArray->provideNoneVector(true);
+  _w->_xArray->provideNoneVector(true);
+
+  connect(this, SIGNAL(modified()), KstApp::inst()->document(), SLOT(wasModified())); //FIXME this should be in KstDataDialog constructor...
 }
 
 LineFitDialogI::~LineFitDialogI() {
@@ -69,7 +80,52 @@
 {
   //called upon clicking 'ok' in 'new' mode
   //return false if the specified objects can't be made, otherwise true
-  return false;
+
+  //Need to create a new object rather than use the one in KstDataObject pluginList
+  LineFitPtr lf = kst_cast<LineFit>(KstDataObject::createPlugin("Line Fit"));
+  Q_ASSERT(lf); //should never happen...
+
+  lf->writeLock();
+
+  QString tagName = _tagName->text();
+
+  if (tagName != defaultTag && KstData::self()->dataTagNameNotUnique(tagName, true, this)) {
+    _tagName->setFocus();
+    return false;
+  }
+
+  if (tagName == defaultTag) {
+    tagName = KST::suggestPluginName("linefit");
+  }
+  lf->setTagName(tagName);
+
+  lf->unlock();
+
+  // Save the vectors and scalars
+  if (!editSingleObject(lf) /*|| !lf->isValid()*/) {
+    KMessageBox::sorry(this, i18n("There is an error in the values you entered."));
+    return false;
+  }
+
+  lf->setXInterpolated(_w->_xInterpolated->text());
+  lf->setYInterpolated(_w->_yInterpolated->text());
+  lf->setA(_w->_a->text());
+  lf->setB(_w->_b->text());
+  lf->setChi2(_w->_chi2->text());
+
+  if (!lf /*|| !lf->isValid()*/) {
+    KMessageBox::sorry(this, i18n("There is an error in the linefit you entered."));
+    return false;
+  }
+
+  lf->setDirty();
+  KST::dataObjectList.lock().writeLock();
+  KST::dataObjectList.append(lf.data());
+  KST::dataObjectList.lock().unlock();
+  lf = 0L; // drop the reference
+  emit modified();
+
+  return true;
 }
 
 bool LineFitDialogI::editObject()
@@ -108,27 +164,18 @@
   lf->unlock();
 
   // Save the vectors and scalars
-  if (!saveInputs(lf)) {
-    KMessageBox::sorry(this, i18n("There is an error in the input you entered."));
+  if (!editSingleObject(lf) || !lf->isValid()) {
+    KMessageBox::sorry(this, i18n("There is an error in the values you entered."));
     return false;
   }
 
-  if (!saveOutputs(lf)) {
-    KMessageBox::sorry(this, i18n("There is an error in the output you entered."));
-    return false;
-  }
-
-  if (!lf->isValid()) {
-    KMessageBox::sorry(this, i18n("There is an error in the values you entered."));
-    return false;
-  }
   lf->setDirty();
 
   emit modified();
   return true;
 }
 
-bool LineFitDialogI::saveInputs(LineFitPtr lf)
+bool LineFitDialogI::editSingleObject(LineFitPtr lf)
 {
   KST::vectorList.lock().readLock();
 
@@ -150,13 +197,6 @@
   return true;
 }
 
-bool LineFitDialogI::saveOutputs(LineFitPtr lf)
-{
-  Q_UNUSED(lf);
-  //implement me
-  return true;
-}
-
 void LineFitDialogI::fillFieldsForEdit() {
   LineFitPtr lf = kst_cast<LineFit>(_dp);
   if (!lf) {
@@ -172,11 +212,19 @@
   _w->_yArray->setSelection( lf->yArrayTag() );
 
   _w->_xInterpolated->setText( lf->xInterpolatedTag() );
+  _w->_xInterpolated->setEnabled( false );
+
   _w->_yInterpolated->setText( lf->yInterpolatedTag() );
+  _w->_yInterpolated->setEnabled( false );
 
   _w->_a->setText( lf->aTag() );
+  _w->_a->setEnabled( false );
+
   _w->_b->setText( lf->bTag() );
+  _w->_b->setEnabled( false );
+
   _w->_chi2->setText( lf->chi2Tag() );
+  _w->_chi2->setEnabled( false );
 
   lf->unlock();
 
--- branches/work/kst/pluginify/kst/src/plugins/linefit/linefitdialog_i.h #584015:584016
@@ -49,8 +49,7 @@
     virtual void fillFieldsForNew();
 
   private:
-    bool saveInputs(LineFitPtr lf);
-    bool saveOutputs(LineFitPtr lf);
+    bool editSingleObject(LineFitPtr lf);
     static const QString& defaultTag;
     static QGuardedPtr<LineFitDialogI> _inst;
     LineFitDialogWidget *_w;
--- branches/work/kst/pluginify/kst/src/plugins/linefit/linefitplugin.cpp #584015:584016
@@ -48,7 +48,7 @@
 }
 
 bool LineFit::isValid() const {
-  return m_init;
+  return m_init; //FIXME this is very clearly wrong
 }
 
 KstObject::UpdateType LineFit::update(int updateCounter) {
@@ -296,12 +296,38 @@
   setDirty();
 }
 
-// void setXInterpolated(KstVectorPtr new_xInterpolated);
-// void setYInterpolated(KstVectorPtr new_yInterpolated);
-// void setA(KstScalarPtr new_a);
-// void setB(KstScalarPtr new_b);
-// void setChi2(KstScalarPtr new_chi2);
+void LineFit::setXInterpolated(const QString &name)
+{
+  KstVectorPtr v = new KstVector(name, 0, this, false);
+  _outputVectors.insert("X Interpolated", v);
+  KST::addVectorToList(v);
+}
 
+void LineFit::setYInterpolated(const QString &name)
+{
+  KstVectorPtr v = new KstVector(name, 0, this, false);
+  _outputVectors.insert("Y Interpolated", v);
+  KST::addVectorToList(v);
+}
+
+void LineFit::setA(const QString &name)
+{
+  KstScalarPtr sp = new KstScalar(name, this);
+  _outputScalars.insert("a", sp);
+}
+
+void LineFit::setB(const QString &name)
+{
+  KstScalarPtr sp = new KstScalar(name, this);
+  _outputScalars.insert("b", sp);
+}
+
+void LineFit::setChi2(const QString &name)
+{
+  KstScalarPtr sp = new KstScalar(name, this);
+  _outputScalars.insert("chi^2", sp);
+}
+
 QString LineFit::propertyString() const {
   return "linefit";
 }
@@ -357,7 +383,7 @@
 
 void LineFit::save(QTextStream& ts, const QString& indent) {
   QString l2 = indent + "  ";
-  ts << indent << "<plugin name=\"Line Fit\"" << endl;
+  ts << indent << "<plugin name=\"Line Fit\">" << endl;
   ts << l2 << "<tag>" << QStyleSheet::escape(tagName()) << "</tag>" << endl;
   for (KstVectorMap::Iterator i = _inputVectors.begin(); i != _inputVectors.end(); ++i) {
     ts << l2 << "<ivector name=\"" << QStyleSheet::escape(i.key()) << "\">"
--- branches/work/kst/pluginify/kst/src/plugins/linefit/linefitplugin.h #584015:584016
@@ -47,11 +47,11 @@
 
   void setXArray(KstVectorPtr new_xArray);
   void setYArray(KstVectorPtr new_yArray);
-  void setXInterpolated(KstVectorPtr new_xInterpolated);
-  void setYInterpolated(KstVectorPtr new_yInterpolated);
-  void setA(KstScalarPtr new_a);
-  void setB(KstScalarPtr new_b);
-  void setChi2(KstScalarPtr new_chi2);
+  void setXInterpolated(const QString &name);
+  void setYInterpolated(const QString &name);
+  void setA(const QString &name);
+  void setB(const QString &name);
+  void setChi2(const QString &name);
 
   //Pure virtual methods from KstDataObject
   virtual KstObject::UpdateType update(int updateCounter = -1);


More information about the Kst mailing list