Example #1
0
void KstViewFitsDialog::fillComboBox(const QString& str) {
  KstCPluginList::iterator it;
  KstCPluginList fits;
  QString fitName = str;
  bool changed = false;
  uint i;

  _comboBoxFits->clear();
  fits = kstObjectSubList<KstDataObject,KstCPlugin>(KST::dataObjectList);

  for (it = fits.begin(); it != fits.end(); ++it) {
    KstCPluginPtr fit;

    fit = *it;
    fit->readLock();

    if (fit->plugin()->data()._isFit) {
      _comboBoxFits->insertItem(0, fit->tagName());
      if (fitName == fit->tagName() || fitName.isEmpty()) {
        _comboBoxFits->setCurrentIndex(_comboBoxFits->count() - 1);
        if (fitName.isEmpty()) {
          fitName = fit->tagName();
        }
        changed = true;
        fitChanged(fitName);
      }
    }

    fit->unlock();
  }

  if (!changed) {
    fitChanged(_comboBoxFits->currentText());
  }
}
void KstPluginDialogI::fillFieldsForEdit() {
    KstCPluginPtr pp = kst_cast<KstCPlugin>(_dp);
    if (!pp) {
        return;
    }
    pp->readLock();
    if (!pp->plugin()) { // plugin() can be null if the kst file is invalid
        pp->unlock();
        return;
    }
    const QString pluginName(pp->tagName());
    const QString pluginObjectName(pp->plugin()->data()._name);
    const int usage = pp->getUsage();
    KstSharedPtr<Plugin> plug = pp->plugin();
    pp->unlock();

    _tagName->setText(pluginName);
    updatePluginList();

    int i = _pluginList.findIndex(pluginObjectName);
    _w->PluginCombo->setCurrentItem(i);
    pluginChanged(_w->PluginCombo->currentItem());

    fillVectorScalarCombos(plug);
    _w->PluginCombo->setEnabled(usage < 3);

    fixupLayout();
}
Example #3
0
bool KstPluginDialogI::editObject() {
  KstCPluginPtr pp = kst_cast<KstCPlugin>(_dp);
  if (!pp) { // something is dreadfully wrong - this should never happen
    return false;
  }

  pp->writeLock();
  if (_tagName->text() != pp->tagName() && KstData::self()->dataTagNameNotUnique(_tagName->text())) {
    _tagName->setFocus();
    pp->unlock();
    return false;
  }

  pp->setTagName(_tagName->text());

  int pitem = _w->PluginCombo->currentItem();
  KstSharedPtr<Plugin> pPtr = PluginCollection::self()->plugin(_pluginList[pitem]);

  // Must unlock before clear()
  for (KstVectorMap::Iterator i = pp->inputVectors().begin(); i != pp->inputVectors().end(); ++i) {
    (*i)->unlock();
  }
  for (KstScalarMap::Iterator i = pp->inputScalars().begin(); i != pp->inputScalars().end(); ++i) {
    (*i)->unlock();
  }
  for (KstStringMap::Iterator i = pp->inputStrings().begin(); i != pp->inputStrings().end(); ++i) {
    (*i)->unlock();
  }
  pp->inputVectors().clear();
  pp->inputScalars().clear();
  pp->inputStrings().clear();

  // Save the vectors and scalars
  if (!saveInputs(pp, pPtr)) {
    KMessageBox::sorry(this, i18n("There is an error in the plugin you entered."));
    pp->unlock();
    return false;
  }

  if (pitem >= 0 && _w->PluginCombo->count() > 0) {
    pp->setPlugin(pPtr);
  }

  if (!saveOutputs(pp, pPtr)) {
    KMessageBox::sorry(this, i18n("There is an error in the plugin you entered."));
    pp->unlock();
    return false;
  }

  if (!pp->isValid()) {
    KMessageBox::sorry(this, i18n("There is an error in the plugin you entered."));
    pp->unlock();
    return false;
  }
  pp->setDirty();
  pp->unlock();

  emit modified();
  return true;
}
bool KstPluginDialogI::editObject() {
    KstCPluginPtr pp = kst_cast<KstCPlugin>(_dp);
    if (!pp) { // something is dreadfully wrong - this should never happen
        return false;
    }

    KstWriteLocker pl(pp);

    if (_tagName->text() != pp->tagName() && KstData::self()->dataTagNameNotUnique(_tagName->text())) {
        _tagName->setFocus();
        return false;
    }

    pp->setTagName(KstObjectTag(_tagName->text(), KstObjectTag::globalTagContext));  // FIXME: tag context always global?

    int pitem = _w->PluginCombo->currentItem();
    KstSharedPtr<Plugin> pPtr = PluginCollection::self()->plugin(_pluginList[pitem]);

    pp->setRecursed(false);
    pp->inputVectors().clear();
    pp->inputScalars().clear();
    pp->inputStrings().clear();

    // Save the vectors and scalars
    if (!saveInputs(pp, pPtr)) {
        KMessageBox::sorry(this, i18n("There is an error in the inputs you entered."));
        return false;
    }

    if (pitem >= 0 && _w->PluginCombo->count() > 0) {
        pp->setPlugin(pPtr);
    }

    if (!saveOutputs(pp, pPtr)) {
        KMessageBox::sorry(this, i18n("There is an error in the outputs you entered."));
        return false;
    }

    if (!pp->isValid()) {
        KMessageBox::sorry(this, i18n("There is an error in the plugin you entered."));
        return false;
    }

    pp->setRecursed(false);
    if (pp->recursion()) {
        pp->setRecursed(true);
        KMessageBox::sorry(this, i18n("There is a recursion resulting from the plugin you entered."));
        return false;
    }

    pp->setDirty();

    emit modified();

    return true;
}
Example #5
0
bool KstFilterDialogI::createCurve(KstCPluginPtr plugin) {
  KstVectorPtr xVector;
  KstVectorPtr yVector;

  KST::vectorList.lock().readLock();
  KstVectorList::Iterator it = KST::vectorList.findTag(_xvector);
  if (it != KST::vectorList.end()) {
    xVector = *it;
  }
  KST::vectorList.lock().unlock();

  if (plugin->outputVectors().contains(plugin->plugin()->data()._filterOutputVector)) {
    yVector = plugin->outputVectors()[plugin->plugin()->data()._filterOutputVector];
  }

  if (!xVector || !yVector) {
    return false;
  }
  plugin->setDirty();
  QString c_name = KST::suggestCurveName(plugin->tagName(), true);
  KstVCurvePtr fit = new KstVCurve(c_name, KstVectorPtr(xVector), KstVectorPtr(yVector), KstVectorPtr(0L), KstVectorPtr(0L), KstVectorPtr(0L), KstVectorPtr(0L), _w->_curveAppearance->color());

  fit->setHasPoints(_w->_curveAppearance->showPoints());
  fit->setHasLines(_w->_curveAppearance->showLines());
  fit->setHasBars(_w->_curveAppearance->showBars());
  fit->setLineWidth(_w->_curveAppearance->lineWidth());
  fit->setLineStyle(_w->_curveAppearance->lineStyle());
  fit->pointType = _w->_curveAppearance->pointType();
  fit->setBarStyle(_w->_curveAppearance->barStyle());
  fit->setPointDensity(_w->_curveAppearance->pointDensity());

  KstViewWindow *w = dynamic_cast<KstViewWindow*>(KstApp::inst()->findWindow(_window));
  if (w && w->view()->findChild(_plotName)) {
    Kst2DPlotPtr plot = kst_cast<Kst2DPlot>(w->view()->findChild(_plotName));
    if (plot) {
      plot->addCurve(fit.data());
    }
  }

  KST::dataObjectList.lock().writeLock();
  KST::dataObjectList.append(fit.data());
  KST::dataObjectList.lock().unlock();
  return true;
}
Example #6
0
bool KstPluginDialogI::saveOutputs(KstCPluginPtr plugin, KstSharedPtr<Plugin> p) {
  const QValueList<Plugin::Data::IOValue>& otable = p->data()._outputs;

  for (QValueList<Plugin::Data::IOValue>::ConstIterator it = otable.begin(); it != otable.end(); ++it) {
    QObject *field = _w->_pluginInputOutputFrame->child((*it)._name.latin1(), "QLineEdit");
    if (!field) {
      continue; // Some are unsupported
    }

    QLineEdit *li = static_cast<QLineEdit*>(field);

    if (li->text().isEmpty()) {
      QString tagName = _tagName->text();
      if (tagName==plugin_defaultTag) {
        tagName = plugin->tagName();
      }
      li->setText(tagName + "-" + (*it)._name);
    }

    QString nt = li->text();
    if ((*it)._type == Plugin::Data::IOValue::TableType) {
      if (!KstData::self()->vectorTagNameNotUnique(nt, false)) {
        // Implicitly creates it if it doesn't exist
        KstVectorPtr v = plugin->outputVectors()[(*it)._name];
        if (!v) {
          v = new KstVector(nt, 0, plugin.data());
          v->writeLock();
          plugin->outputVectors().insert((*it)._name, v);
          KST::addVectorToList(v);
        }
      } else if (plugin->outputVectors()[(*it)._name]->tagName() != nt) {
        while (KstData::self()->vectorTagNameNotUnique(nt, false)) {
          nt += "'";
        }
        KstVectorPtr v;
        if (plugin->outputVectors().contains((*it)._name)) {
          v = plugin->outputVectors()[(*it)._name];
        } else {
          v = new KstVector(nt, 0, plugin.data());
          v->writeLock();
          plugin->outputVectors().insert((*it)._name, v);
          KST::addVectorToList(v);
        }
      }
    } else if ((*it)._type == Plugin::Data::IOValue::StringType) {
      if (!KstData::self()->vectorTagNameNotUnique(nt, false)) {
        KstStringPtr s;
        if (plugin->outputStrings().contains((*it)._name)) {
          s = plugin->outputStrings()[(*it)._name];
        } else {
          s = new KstString(nt, plugin.data());
          s->writeLock();
          plugin->outputStrings().insert((*it)._name, s);
        }
      } else if (plugin->outputStrings()[(*it)._name]->tagName() != nt) {
        while (KstData::self()->vectorTagNameNotUnique(nt, false)) {
          nt += "'";
        }
        KstStringPtr s;
        if (plugin->outputStrings().contains((*it)._name)) {
          s = plugin->outputStrings()[(*it)._name];
        } else {
          s = new KstString(nt, plugin.data());
          s->writeLock();
          plugin->outputStrings().insert((*it)._name, s);
        }
      }
    } else if ((*it)._type == Plugin::Data::IOValue::PidType) {
      // Nothing
    } else if ((*it)._type == Plugin::Data::IOValue::FloatType) {
      if (!KstData::self()->vectorTagNameNotUnique(nt, false)) {
        KstScalarPtr s;
        if (plugin->outputScalars().contains((*it)._name)) {
          s = plugin->outputScalars()[(*it)._name];
        } else {
          s = new KstScalar(nt, plugin.data());
          s->writeLock();
          plugin->outputScalars().insert((*it)._name, s);
        }
      } else if (plugin->outputScalars()[(*it)._name]->tagName() != nt) {
        while (KstData::self()->vectorTagNameNotUnique(nt, false)) {
          nt += "'";
        }
        KstScalarPtr s;
        if (plugin->outputScalars().contains((*it)._name)) {
          s = plugin->outputScalars()[(*it)._name];
        } else {
          s = new KstScalar(nt, plugin.data());
          s->writeLock();
          plugin->outputScalars().insert((*it)._name, s);
        }
      }
    }
  }

  return true;
}