ObjectPtr BasicPluginDialog::createNewDataObject() {
  BasicPluginPtr dataObject = kst_cast<BasicPlugin>(DataObject::createPlugin(_pluginName, _document->objectStore(), _basicPluginTab->configWidget()));

  _basicPluginTab->configWidget()->save();

  if (!dataObject->isValid()) {
    _document->objectStore()->removeObject(dataObject);
    QString msg(tr("Unable to create Plugin Object using provided parameters.\n\n"));
    msg += dataObject->errorMessage();
    QMessageBox::warning(this, tr("Kst"), msg);

    return 0;
  }

  return dataObject;
}
DataObjectPtr BasicPlugin::makeDuplicate() const {
#if 0
  BasicPluginPtr plugin = kst_cast<BasicPlugin>(DataObject::createPlugin(propertyString()));

  // use same inputs
  for (VectorMap::ConstIterator iter = _inputVectors.begin(); iter != _inputVectors.end(); ++iter) {
    plugin->inputVectors().insert(iter.key(), iter.value());
  }
  for (ScalarMap::ConstIterator iter = _inputScalars.begin(); iter != _inputScalars.end(); ++iter) {
    plugin->inputScalars().insert(iter.key(), iter.value());
  }
  for (StringMap::ConstIterator iter = _inputStrings.begin(); iter != _inputStrings.end(); ++iter) {
    plugin->inputStrings().insert(iter.key(), iter.value());
  }

  // create new outputs
  for (VectorMap::ConstIterator iter = outputVectors().begin(); iter != outputVectors().end(); ++iter) {
    KstWriteLocker blockVectorUpdates(&vectorList.lock());
    VectorPtr v = new Vector(ObjectTag(iter.value()->tag().tag() + "'", iter.value()->tag().context()), 0, plugin.data()); // FIXME: unique tag generation
    plugin->outputVectors().insert(iter.key(), v);
  }
  for (ScalarMap::ConstIterator iter = outputScalars().begin(); iter != outputScalars().end(); ++iter) {
    ScalarPtr s = new Scalar(ObjectTag(iter.value()->tag().tag() + "'", iter.value()->tag().context()), plugin.data()); // FIXME: unique tag generation
    plugin->outputScalars().insert(iter.key(), s);
  }
  for (StringMap::ConstIterator iter = outputStrings().begin(); iter != outputStrings().end(); ++iter) {
    StringPtr s = new String(ObjectTag(iter.value()->tag().tag() + "'", iter.value()->tag().context()), plugin.data()); // FIXME: unique tag generation
    plugin->outputStrings().insert(iter.key(), s);
  }

  // set the same plugin
  plugin->setTagName(ObjectTag(tag().tag() + "'", tag().context())); // FIXME: unique tag generation method
  map.insert(this, DataObjectPtr(plugin));
  return DataObjectPtr(plugin);
#endif
  // FIXME: implement this
  return 0L;
}
DataObjectPtr BasicPluginFactory::generateObject(ObjectStore *store, QXmlStreamReader& xml) {
  Q_ASSERT(store);

  DataObjectConfigWidget* configWidget;
  QString pluginName;
  BasicPluginPtr dataObject;
  bool validTag;

  while (!xml.atEnd()) {
    const QString n = xml.name().toString();
    if (xml.isStartElement()) {
      if (n == BasicPlugin::staticTypeTag) {
        QXmlStreamAttributes attrs = xml.attributes();
        pluginName = attrs.value("type").toString();
        Object::processShortNameIndexAttributes(attrs);

        configWidget = DataObject::pluginWidget(pluginName);
        if (configWidget) {
          if (!configWidget->configurePropertiesFromXml(store, attrs) ) {
            Debug::self()->log(QObject::tr("Error unable to create data object from plugin"), Debug::Warning);
            return 0;
          } else {
            if (xml.isEndElement() && n == BasicPlugin::staticTypeTag) {
              break;
            }
          }
        } else {
          Debug::self()->log(QObject::tr("Error unable to find plugin for data object"), Debug::Warning);
          return 0;
        }

        dataObject = kst_cast<BasicPlugin>(DataObject::createPlugin(pluginName, store, configWidget, false));

        QString expectedEnd;
        while (!(xml.isEndElement() && (xml.name().toString() == BasicPlugin::staticTypeTag))) {
          if (xml.isStartElement() && xml.name().toString() == "inputvector") {
            expectedEnd = xml.name().toString();
            attrs = xml.attributes();
            QString type = attrs.value("type").toString();
            QString tagName = attrs.value("tag").toString();
            VectorPtr vector = kst_cast<Vector>(store->retrieveObject(tagName));
            if (vector) {
              dataObject->setInputVector(type, vector);
            }
          } else if (xml.isStartElement() && xml.name().toString() == "inputscalar") {
            expectedEnd = xml.name().toString();
            attrs = xml.attributes();
            QString type = attrs.value("type").toString();
            QString tagName = attrs.value("tag").toString();
            ScalarPtr scalar = kst_cast<Scalar>(store->retrieveObject(tagName));
            if (scalar) {
              dataObject->setInputScalar(type, scalar);
            }
          } else if (xml.isStartElement() && xml.name().toString() == "inputstring") {
            expectedEnd = xml.name().toString();
            attrs = xml.attributes();
            QString type = attrs.value("type").toString();
            QString tagName = attrs.value("tag").toString();
            StringPtr string = kst_cast<String>(store->retrieveObject(tagName));
            if (string) {
              dataObject->setInputString(type, string);
            }
          } else if (xml.isStartElement() && xml.name().toString() == "outputvector") {
            expectedEnd = xml.name().toString();
            attrs = xml.attributes();
            QString type = attrs.value("type").toString();
            QString tagName = attrs.value("tag").toString();
            dataObject->setOutputVector(type, tagName);
          } else if (xml.isStartElement() && xml.name().toString() == "outputscalar") {
            expectedEnd = xml.name().toString();
            attrs = xml.attributes();
            QString type = attrs.value("type").toString();
            QString tagName = attrs.value("tag").toString();
            dataObject->setOutputScalar(type, tagName);
          } else if (xml.isStartElement() && xml.name().toString() == "outputstring") {
            expectedEnd = xml.name().toString();
            attrs = xml.attributes();
            QString type = attrs.value("type").toString();
            QString tagName = attrs.value("tag").toString();
            dataObject->setOutputString(type, tagName);
          } else if (xml.isEndElement()) {
            if (xml.name().toString() != expectedEnd) {
              validTag = false;
              break;
            }
          }
          xml.readNext();
        }
      } else {
        return 0;
      }
    }
    if (xml.isEndElement()) {
      if (n == BasicPlugin::staticTypeTag) {
        break;
      } else {
        Debug::self()->log(QObject::tr("Error creating Plugin Object from Kst file."), Debug::Warning);
        return 0;
      }
    }
    xml.readNext();
  }

  if (xml.hasError()) {
    return 0;
  }

  dataObject->writeLock();
  dataObject->registerChange();
  dataObject->unlock();

  return dataObject;
}
Ejemplo n.º 4
0
ObjectPtr FilterFitDialog::createNewDataObject() {
    BasicPluginPtr dataObject = kst_cast<BasicPlugin>(DataObject::createPlugin(_filterFitTab->pluginName(), _document->objectStore(), _filterFitTab->configWidget()));
    Q_ASSERT(dataObject);

    if (!dataObject->isValid()) {
        _document->objectStore()->removeObject(dataObject);
        QString msg(tr("Unable to create Plugin Object using provided parameters.\n\n"));
        msg += dataObject->errorMessage();
        QMessageBox::warning(this, tr("Kst"), msg);

        return 0;
    }

    if(editMode()==New) {
        PlotItem *plotItem = 0;
        switch (_filterFitTab->curvePlacement()->place()) {
        case CurvePlacement::NoPlot:
            break;
        case CurvePlacement::ExistingPlot:
        {
            plotItem = static_cast<PlotItem*>(_filterFitTab->curvePlacement()->existingPlot());
            break;
        }
        case CurvePlacement::NewPlotNewTab:
            _document->createView();
        // fall through to case NewPlot.
        case CurvePlacement::NewPlot:
        {
            CreatePlotForCurve *cmd = new CreatePlotForCurve();
            cmd->createItem();

            plotItem = static_cast<PlotItem*>(cmd->item());
            if (_filterFitTab->curvePlacement()->scaleFonts()) {
                plotItem->view()->resetPlotFontSizes(plotItem);
                plotItem->view()->configurePlotFontDefaults(plotItem); // copy plots already in window
            }
            plotItem->view()->appendToLayout(_filterFitTab->curvePlacement()->layout(), plotItem,
                                             _filterFitTab->curvePlacement()->gridColumns());
            if (_filterFitTab->curvePlacement()->layout() == CurvePlacement::Custom) {
                plotItem->createCustomLayout(_filterFitTab->curvePlacement()->gridColumns());
            }
            break;
        }
        default:
            break;
        }

        if (plotItem) {
            CurvePtr curve = _document->objectStore()->createObject<Curve>();
            Q_ASSERT(curve);

            if (!_vectorX) {
                setVectorX(dataObject->inputVectors().value(dataObject->inputVectorList().first()));
            }
            Q_ASSERT(_vectorX);
            curve->setXVector(_vectorX);

            VectorPtr yVector = dataObject->outputVectors().value(dataObject->outputVectorList().first());
            Q_ASSERT(yVector);
            curve->setYVector(yVector);

            curve->setColor(_filterFitTab->curveAppearance()->color());
            curve->setHasPoints(_filterFitTab->curveAppearance()->showPoints());
            curve->setHasLines(_filterFitTab->curveAppearance()->showLines());
            curve->setHasBars(_filterFitTab->curveAppearance()->showBars());
            curve->setLineWidth(_filterFitTab->curveAppearance()->lineWidth());
            curve->setPointSize(_filterFitTab->curveAppearance()->pointSize());
            curve->setLineStyle(_filterFitTab->curveAppearance()->lineStyle());
            curve->setPointType(_filterFitTab->curveAppearance()->pointType());
            curve->setPointDensity(_filterFitTab->curveAppearance()->pointDensity());
            curve->setBarFillColor(_filterFitTab->curveAppearance()->barFillColor());

            curve->writeLock();
            curve->registerChange();
            curve->unlock();

            _filterFitTab->curveAppearance()->setWidgetDefaults();

            PlotRenderItem *renderItem = plotItem->renderItem(PlotRenderItem::Cartesian);
            renderItem->addRelation(kst_cast<Relation>(curve));

            dataObject->writeLock();
            dataObject->internalUpdate();
            dataObject->unlock();

            if (dataObject->hasParameterVector()) {
                CreateLabelCommand *cmd = new CreateLabelCommand;
                QString *tmpstring = new QString(dataObject->parameterVectorToString());

                cmd->createItem(tmpstring);
            }
            plotItem->update();

        }
    }

    _filterFitTab->configWidget()->save();

    return dataObject;
}