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

Andrew Walker arwalker at sumusltd.com
Wed Sep 26 23:57:48 CEST 2007


SVN commit 717448 by arwalker:

BUG:145435 added mechanism to specify default values for input scalars. Added a default value to the bin plugin as an example

 M  +9 -8      libkstapp/kstbasicdialog_i.cpp  
 M  +1 -1      libkstapp/kstbasicdialog_i.h  
 M  +49 -25    libkstmath/kstbasicplugin.cpp  
 M  +4 -0      libkstmath/kstbasicplugin.h  
 M  +11 -11    plugins/bin/bin.cpp  


--- branches/work/kst/1.6/kst/src/libkstapp/kstbasicdialog_i.cpp #717447:717448
@@ -99,21 +99,21 @@
   QStringList iv = ptr->inputVectorList();
   QStringList::ConstIterator ivI = iv.begin();
   for (; ivI != iv.end(); ++ivI) {
-      createInputVector(*ivI, ++cnt);
+    createInputVector(*ivI, ++cnt);
   }
 
   //Now, the inputScalars...
   QStringList is = ptr->inputScalarList();
   QStringList::ConstIterator isI = is.begin();
   for (; isI != is.end(); ++isI) {
-      createInputScalar(*isI, ++cnt);
+    createInputScalar(*isI, ++cnt, ptr->defaultScalarValue(*isI));
   }
 
   //Finally, the inputStrings...
   QStringList istr = ptr->inputStringList();
   QStringList::ConstIterator istrI = istr.begin();
   for (; istrI != istr.end(); ++istrI) {
-      createInputString(*istrI, ++cnt);
+    createInputString(*istrI, ++cnt);
   }
 
   //create sep
@@ -154,8 +154,7 @@
 
   VectorSelector *widget = new VectorSelector(_w->_frame,
                                               name.latin1());
-  connect(widget, SIGNAL(newVectorCreated(const QString&)),
-          this, SIGNAL(modified()));
+  connect(widget, SIGNAL(newVectorCreated(const QString&)), this, SIGNAL(modified()));
 
   _grid->addWidget(label, row, 0);
   label->show();
@@ -164,14 +163,16 @@
 }
 
 
-void KstBasicDialogI::createInputScalar(const QString &name, int row) {
+void KstBasicDialogI::createInputScalar(const QString &name, int row, double value) {
   QLabel *label = new QLabel(name + ":", _w->_frame);
 
   ScalarSelector *widget = new ScalarSelector(_w->_frame,
                                               name.latin1());
-  connect(widget, SIGNAL(newScalarCreated()),
-          this, SIGNAL(modified()));
+  connect(widget, SIGNAL(newScalarCreated()), this, SIGNAL(modified()));
   widget->allowDirectEntry(true);
+  if (widget->_scalar->lineEdit()) {
+    widget->_scalar->lineEdit()->setText(QString::number(value));
+  }
 
   _grid->addWidget(label, row, 0);
   label->show();
--- branches/work/kst/1.6/kst/src/libkstapp/kstbasicdialog_i.h #717447:717448
@@ -57,7 +57,7 @@
     bool editSingleObject(KstBasicPluginPtr ptr);
 
     void createInputVector(const QString &name, int row);
-    void createInputScalar(const QString &name, int row);
+    void createInputScalar(const QString &name, int row, double value);
     void createInputString(const QString &name, int row);
     void createOutputWidget(const QString &name, int row);
 
--- branches/work/kst/1.6/kst/src/libkstmath/kstbasicplugin.cpp #717447:717448
@@ -96,55 +96,61 @@
 
 KstVectorPtr KstBasicPlugin::inputVector(const QString& vector) const {
   KstVectorMap::ConstIterator i = _inputVectors.find(vector);
-  if (i != _inputVectors.end())
+  if (i != _inputVectors.end()) {
     return *i;
-  else
+  } else {
     return 0;
+  }
 }
 
 
 KstScalarPtr KstBasicPlugin::inputScalar(const QString& scalar) const {
   KstScalarMap::ConstIterator i = _inputScalars.find(scalar);
-  if (i != _inputScalars.end())
+  if (i != _inputScalars.end()) {
     return *i;
-  else
+  } else {
     return 0;
+  }
 }
 
 
 KstStringPtr KstBasicPlugin::inputString(const QString& string) const {
   KstStringMap::ConstIterator i = _inputStrings.find(string);
-  if (i != _inputStrings.end())
+  if (i != _inputStrings.end()) {
     return *i;
-  else
+  } else {
     return 0;
+  }
 }
 
 
 KstVectorPtr KstBasicPlugin::outputVector(const QString& vector) const {
   KstVectorMap::ConstIterator i = _outputVectors.find(vector);
-  if (i != _outputVectors.end())
+  if (i != _outputVectors.end()) {
     return *i;
-  else
+  } else {
     return 0;
+  }
 }
 
 
 KstScalarPtr KstBasicPlugin::outputScalar(const QString& scalar) const {
   KstScalarMap::ConstIterator i = _outputScalars.find(scalar);
-  if (i != _outputScalars.end())
+  if (i != _outputScalars.end()) {
     return *i;
-  else
+  } else {
     return 0;
+  }
 }
 
 
 KstStringPtr KstBasicPlugin::outputString(const QString& string) const {
   KstStringMap::ConstIterator i = _outputStrings.find(string);
-  if (i != _outputStrings.end())
+  if (i != _outputStrings.end()) {
     return *i;
-  else
+  } else {
     return 0;
+  }
 }
 
 
@@ -217,8 +223,9 @@
   }
 
   //Make sure we have all the necessary inputs
-  if (!inputsExist())
+  if (!inputsExist()) {
     return setLastUpdateResult(NO_CHANGE);
+  }
 
   writeLockInputsAndOutputs();
 
@@ -313,8 +320,10 @@
 }
 
 
-QString KstBasicPlugin::parameterName(int /*index*/) const {
-    return QString::null;
+QString KstBasicPlugin::parameterName(int index) const {
+  Q_UNUSED(index)
+
+  return QString::null;
 }
 
 
@@ -345,6 +354,7 @@
 
 void KstBasicPlugin::save(QTextStream& ts, const QString& indent) {
   QString l2 = indent + "  ";
+
   //The plugin name _must_ be the same as the entry in the .desktop file
   ts << indent << "<plugin name=\"" << propertyString() << "\">" << endl;
   ts << l2 << "<tag>" << QStyleSheet::escape(tagName()) << "</tag>" << endl;
@@ -391,25 +401,29 @@
   QStringList iv = inputVectorList();
   QStringList::ConstIterator ivI = iv.begin();
   for (; ivI != iv.end(); ++ivI) {
-    if (!inputVector(*ivI))
+    if (!inputVector(*ivI)) {
       return false;
+    }
   }
 
   //Now, check the inputScalars...
   QStringList is = inputScalarList();
   QStringList::ConstIterator isI = is.begin();
   for (; isI != is.end(); ++isI) {
-    if (!inputScalar(*isI))
+    if (!inputScalar(*isI)) {
       return false;
+    }
   }
 
   //Finally, check the inputStrings...
   QStringList istr = inputStringList();
   QStringList::ConstIterator istrI = istr.begin();
   for (; istrI != istr.end(); ++istrI) {
-    if (!inputString(*istrI))
+    if (!inputString(*istrI)) {
       return false;
+    }
   }
+
   return true;
 }
 
@@ -422,8 +436,7 @@
   QStringList::ConstIterator ivI = iv.begin();
   for (; ivI != iv.end(); ++ivI) {
     Q_ASSERT(inputVector(*ivI)->myLockStatus() == KstRWLock::WRITELOCKED);
-    depUpdated =
-        UPDATE == inputVector(*ivI)->update(updateCounter) || depUpdated;
+    depUpdated = UPDATE == inputVector(*ivI)->update(updateCounter) || depUpdated;
   }
 
   //Now, update the inputScalars...
@@ -431,8 +444,7 @@
   QStringList::ConstIterator isI = is.begin();
   for (; isI != is.end(); ++isI) {
     Q_ASSERT(inputScalar(*isI)->myLockStatus() == KstRWLock::WRITELOCKED);
-    depUpdated =
-        UPDATE == inputScalar(*isI)->update(updateCounter) || depUpdated;
+    depUpdated = UPDATE == inputScalar(*isI)->update(updateCounter) || depUpdated;
   }
 
   //Finally, update the inputStrings...
@@ -440,9 +452,9 @@
   QStringList::ConstIterator istrI = istr.begin();
   for (; istrI != istr.end(); ++istrI) {
     Q_ASSERT(inputString(*istrI)->myLockStatus() == KstRWLock::WRITELOCKED);
-    depUpdated =
-        UPDATE == inputString(*istrI)->update(updateCounter) || depUpdated;
+    depUpdated = UPDATE == inputString(*istrI)->update(updateCounter) || depUpdated;
   }
+
   return depUpdated;
 }
 
@@ -482,4 +494,16 @@
   }
 }
 
-// vim: ts=2 sw=2 et
+double KstBasicPlugin::defaultScalarValue(const QString& name) const {
+  double value = 0.0;
+
+  QMap<QString, double>::ConstIterator it;
+
+  it = _inputScalarDefaults.find(name);
+  if (it != _inputScalarDefaults.end()) {
+    value = *it;
+  }
+
+  return value;
+}
+
--- branches/work/kst/1.6/kst/src/libkstmath/kstbasicplugin.h #717447:717448
@@ -67,6 +67,8 @@
     KstScalarPtr outputScalar(const QString& name) const;
     KstStringPtr outputString(const QString& name) const;
 
+    double defaultScalarValue(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);
@@ -89,6 +91,8 @@
 
   protected:
     virtual QString parameterName(int index) const;
+
+    QMap<QString, double> _inputScalarDefaults;
     bool _isFit;
 
   private:
--- branches/work/kst/1.6/kst/src/plugins/bin/bin.cpp #717447:717448
@@ -32,6 +32,7 @@
 
 Bin::Bin( QObject */*parent*/, const char */*name*/, const QStringList &/*args*/ )
     : KstBasicPlugin() {
+  _inputScalarDefaults.insert(SIZE, 10.0);
 }
 
 
@@ -50,7 +51,7 @@
 
   //Make sure there is at least 1 element in the input vector
   //Make sure the bin size is at least 1
-  if (input->length() < 1 || size->value() < 1) {
+  if (input->length() < 1 || size->value() < 1.0) {
     return -1;
   }
 
@@ -58,16 +59,15 @@
   bins->resize(int(input->length() / size->value()), false);
 
   //now bin the data
-  for (int i=0; i<bins->length(); i++)
-  {
-      bins->value()[i]=0;
-      //add up the elements for this bin
-      for (int j=0; j<size->value(); j++)
-      {
-          bins->value()[i]+=input->value()[int(i*size->value()+j)];
-      }
-      //find the mean
-      bins->value()[i]/=size->value();
+  for (int i=0; i<bins->length(); i++) {
+    bins->value()[i] = 0.0;
+
+    //add up the elements for this bin
+    for (int j=0; j<size->value(); j++) {
+      bins->value()[i] += input->value()[int(i*size->value()+j)];
+    }
+    //find the mean
+    bins->value()[i] /= size->value();
   }
   return true;
 }


More information about the Kst mailing list