Exemplo n.º 1
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;
}
bool KstFilterDialogI::newObject() {
  QString tagName = _tagName->text();

  if (KstData::self()->dataTagNameNotUnique(tagName, true, this)) {
    _tagName->setFocus();
    return false;
  } else {
    int pitem = _w->PluginCombo->currentItem();

    if (pitem >= 0 && _w->PluginCombo->count() > 0) {
      KstSharedPtr<Plugin> pPtr = PluginCollection::self()->plugin(_pluginList[pitem]);

      if (pPtr) {
        KstCPluginPtr plugin = new KstCPlugin;
        KstWriteLocker pl(plugin);
        plugin->setDirty();
        if (saveInputs(plugin, pPtr)) {
          if (tagName == plugin_defaultTag) {
            tagName = KST::suggestPluginName(_pluginList[pitem], KstObjectTag::fromString(_yvector));
          }

          plugin->setTagName(KstObjectTag(tagName, KstObjectTag::globalTagContext)); // FIXME: tag context always global?

          plugin->setPlugin(pPtr);

          if (saveOutputs(plugin, pPtr)) {
            if (plugin->isValid()) {
              if (!createCurve(plugin)) {
                KMessageBox::sorry(this, i18n("There is an error in the plugin you entered."));
                return false;
              } else {
                KST::dataObjectList.lock().writeLock();
                KST::dataObjectList.append(plugin.data());
                KST::dataObjectList.lock().unlock();
              }
            } else {
              KMessageBox::sorry(this, i18n("There is an error in the plugin you entered."));
              return false;
            }
          } else {
            KMessageBox::sorry(this, i18n("There is an error in the outputs you entered."));
            return false;
          }
        } else {
          KMessageBox::sorry(this, i18n("There is an error in the inputs you entered."));
          return false;
        }
      }
    }
    emit modified();
  }
  return true;
}
bool KstPluginDialogI::newObject() {
    QString tagName = _tagName->text();

    if (tagName != plugin_defaultTag && KstData::self()->dataTagNameNotUnique(tagName, true, this)) {
        _tagName->setFocus();
        return false;
    }
    KstCPluginPtr plugin;
    int pitem = _w->PluginCombo->currentItem();
    if (pitem >= 0 && _w->PluginCombo->count() > 0) {
        KstSharedPtr<Plugin> pPtr = PluginCollection::self()->plugin(_pluginList[pitem]);
        if (pPtr) {
            plugin = new KstCPlugin;
            KstWriteLocker pl(plugin);

            // set the tag name before any dependents are created
            if (tagName == plugin_defaultTag) {
                tagName = KST::suggestPluginName(_pluginList[pitem]);
            }
            plugin->setTagName(KstObjectTag(tagName, KstObjectTag::globalTagContext));

            if (!saveInputs(plugin, pPtr)) {
                KMessageBox::sorry(this, i18n("There is an error in the inputs you entered."));
                plugin = 0L;
                return false;
            }

            plugin->setPlugin(pPtr);

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

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

    plugin->setDirty();
    KST::dataObjectList.lock().writeLock();
    KST::dataObjectList.append(plugin.data());
    KST::dataObjectList.lock().unlock();
    plugin = 0L;
    emit modified();

    return true;
}
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->tag(), true);
  QColor color = KstApp::inst()->chooseColorDlg()->getColorForCurve(KstVectorPtr(xVector), KstVectorPtr(yVector));
  if (!color.isValid()) {
    color = _w->_curveAppearance->color();
  }
  KstVCurvePtr fit = new KstVCurve(c_name, KstVectorPtr(xVector), KstVectorPtr(yVector), KstVectorPtr(0L), KstVectorPtr(0L), KstVectorPtr(0L), KstVectorPtr(0L), 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->setPointStyle(_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;
}