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

Adam Treat treat at kde.org
Tue Sep 19 02:04:36 CEST 2006


SVN commit 586196 by treat:

* Implement saving and editing of input/output
in the dialog and basic plugin.  Fills out more



 M  +89 -6     libkstapp/kstbasicdialog_i.cpp  
 M  +1 -3      libkstapp/kstbasicdialog_i.h  
 M  +50 -1     libkstmath/kstbasicplugin.cpp  
 M  +7 -0      libkstmath/kstbasicplugin.h  


--- branches/work/kst/pluginify/kst/src/libkstapp/kstbasicdialog_i.cpp #586195:586196
@@ -21,6 +21,8 @@
 #include <qlineedit.h>
 
 // include files for KDE
+#include <klocale.h>
+#include <kmessagebox.h>
 
 #include "kstbasicdialog_i.h"
 #include "basicdialogwidget.h"
@@ -50,7 +52,6 @@
 : KstDataDialog(parent, name, modal, fl) {
   setMultiple(false);
   _w = new BasicDialogWidget(_contents);
-  connect( this, SIGNAL(pluginChanged()), this, SLOT(init()));
   connect(this, SIGNAL(modified()), KstApp::inst()->document(), SLOT(wasModified())); //FIXME this should be in KstDataDialog constructor...
 
   _pluginName = QString::null;
@@ -61,11 +62,10 @@
 KstBasicDialogI::~KstBasicDialogI() {
 }
 
-
 void KstBasicDialogI::init() {
 
   KstBasicPluginPtr ptr;
-  if (_newDialog)
+  if (!_newDialog)
     ptr = kst_cast<KstBasicPlugin>(_dp);
   else
     ptr = kst_cast<KstBasicPlugin>(
@@ -216,6 +216,74 @@
 bool KstBasicDialogI::newObject() {
   //called upon clicking 'ok' in 'new' mode
   //return false if the specified objects can't be made, otherwise true
+
+  //Need to create a new object rather than use the one in KstDataObject pluginList
+  KstBasicPluginPtr ptr = kst_cast<KstBasicPlugin>(
+      KstDataObject::createPlugin(_pluginName));
+  Q_ASSERT(ptr); //should never happen...
+
+  ptr->writeLock();
+
+  QString tagName = _tagName->text();
+
+  if (tagName != defaultTag && KstData::self()->dataTagNameNotUnique(tagName, true, this)) {
+    _tagName->setFocus();
+    return false;
+  }
+
+  if (tagName == defaultTag) {
+    tagName = KST::suggestPluginName(ptr->propertyString());
+  }
+  ptr->setTagName(tagName);
+
+  ptr->unlock();
+
+  // Save the vectors and scalars
+  if (!editSingleObject(ptr) || !ptr->isValid()) {
+    KMessageBox::sorry(this, i18n("There is an error in the values you entered."));
+    return false;
+  }
+
+  //set the outputs
+  //output vectors...
+  QStringList ov = ptr->outputVectors();
+  QStringList::ConstIterator ovI = ov.begin();
+  for (; ovI != ov.end(); ++ovI) {
+    if (QLineEdit *w = output(*ovI)) {
+      ptr->setOutputVector(*ovI, w->text());
+    }
+  }
+
+  //output scalars...
+  QStringList os = ptr->outputScalars();
+  QStringList::ConstIterator osI = os.begin();
+  for (; osI != os.end(); ++osI) {
+    if (QLineEdit *w = output(*osI)) {
+      ptr->setOutputScalar(*ovI, w->text());
+    }
+  }
+
+  //ouput strings...
+  QStringList ostr = ptr->outputStrings();
+  QStringList::ConstIterator ostrI = ostr.begin();
+  for (; ostrI != ostr.end(); ++ostrI) {
+    if (QLineEdit *w = output(*ostrI)) {
+      ptr->setOutputString(*ovI, w->text());
+    }
+  }
+
+  if (!ptr || !ptr->isValid()) {
+    KMessageBox::sorry(this, i18n("There is an error in the plugin you entered."));
+    return false;
+  }
+
+  ptr->setDirty();
+  KST::dataObjectList.lock().writeLock();
+  KST::dataObjectList.append(ptr.data());
+  KST::dataObjectList.lock().unlock();
+  ptr = 0L; // drop the reference
+  emit modified();
+
   return true;
 }
 
@@ -228,12 +296,27 @@
 
 
 void KstBasicDialogI::showNew(const QString &field) {
-  _pluginName = field;
-  emit pluginChanged();
-  KstDataDialog::showNew(field);
+  if (_pluginName != field) {
+    _pluginName = field;
+    KstDataDialog::showNew(field);
+    init();
+  } else {
+    KstDataDialog::showNew(field);
+  }
 }
 
 
+void KstBasicDialogI::showEdit(const QString &field) {
+  if (_pluginName != field) {
+    _pluginName = field;
+    KstDataDialog::showEdit(field);
+    init();
+  } else {
+    KstDataDialog::showEdit(field);
+  }
+}
+
+
 bool KstBasicDialogI::editSingleObject(KstBasicPluginPtr ptr) {
   Q_UNUSED(ptr)
   return true;
--- branches/work/kst/pluginify/kst/src/libkstapp/kstbasicdialog_i.h #586195:586196
@@ -43,10 +43,8 @@
     virtual bool newObject();
     virtual bool editObject();
     virtual void showNew(const QString &field);
+    virtual void showEdit(const QString &field);
 
-  signals:
-    void pluginChanged();
-
   protected:
     virtual void fillFieldsForEdit();
     virtual void fillFieldsForNew();
--- branches/work/kst/pluginify/kst/src/libkstmath/kstbasicplugin.cpp #586195:586196
@@ -51,7 +51,7 @@
 
 
 void KstBasicPlugin::showEditDialog() {
-  KstDialogs::self()->showBasicPluginDialog(tagName());
+  KstDialogs::self()->showBasicPluginDialog(tagName(), true);
 }
 
 
@@ -109,6 +109,55 @@
 }
 
 
+void KstBasicPlugin::setInputVector(const QString &type, KstVectorPtr ptr) {
+  if (ptr) {
+    _inputVectors[type] = ptr;
+  } else {
+    _inputVectors.remove(type);
+  }
+  setDirty();
+}
+
+
+void KstBasicPlugin::setInputScalar(const QString &type, KstScalarPtr ptr) {
+  if (ptr) {
+    _inputScalars[type] = ptr;
+  } else {
+    _inputScalars.remove(type);
+  }
+  setDirty();
+}
+
+
+void KstBasicPlugin::setInputString(const QString &type, KstStringPtr ptr) {
+  if (ptr) {
+    _inputStrings[type] = ptr;
+  } else {
+    _inputStrings.remove(type);
+  }
+  setDirty();
+}
+
+
+void KstBasicPlugin::setOutputVector(const QString &type, const QString &name) {
+  KstVectorPtr v = new KstVector(name, 0, this, false);
+  _outputVectors.insert(type, v);
+  KST::addVectorToList(v);
+}
+
+
+void KstBasicPlugin::setOutputScalar(const QString &type, const QString &name) {
+  KstScalarPtr s = new KstScalar(name, this);
+  _outputScalars.insert(type, s);
+}
+
+
+void KstBasicPlugin::setOutputString(const QString &type, const QString &name) {
+  KstStringPtr s = new KstString(name, this);
+  _outputStrings.insert(type, s);
+}
+
+
 KstObject::UpdateType KstBasicPlugin::update(int updateCounter) {
   bool force = dirty();
   setDirty(false);
--- branches/work/kst/pluginify/kst/src/libkstmath/kstbasicplugin.h #586195:586196
@@ -66,6 +66,13 @@
   KstScalarPtr outputScalar(const QString& name) const;
   KstStringPtr outputString(const QString& name) const;
 
+  void setInputVector(const QString &type, KstVectorPtr ptr);
+  void setInputScalar(const QString &type, KstScalarPtr ptr);
+  void setInputString(const QString &type, KstStringPtr ptr);
+  void setOutputVector(const QString &type, const QString &name);
+  void setOutputScalar(const QString &type, const QString &name);
+  void setOutputString(const QString &type, const QString &name);
+
   //Pure virtual methods inherited from KstDataObject
   //We do this one ourselves for benefit of all plugins...
   KstObject::UpdateType update(int updateCounter = -1);


More information about the Kst mailing list