Beispiel #1
0
bool KstBasicDialogI::editObject() {
  //called upon clicking 'ok' in 'edit' mode
  //return false if the specified objects can't be editted, otherwise true

  KstBasicPluginPtr ptr = kst_cast<KstBasicPlugin>(_dp);
  Q_ASSERT(ptr); //should never happen...

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

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

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

  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;
  }

  ptr->setDirty();

  emit modified();
  return true;
}
Beispiel #2
0
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->outputVectorList();
  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->outputScalarList();
  QStringList::ConstIterator osI = os.begin();
  for (; osI != os.end(); ++osI) {
    if (QLineEdit *w = output(*osI)) {
      ptr->setOutputScalar(*osI, w->text());
    }
  }

  //ouput strings...
  QStringList ostr = ptr->outputStringList();
  QStringList::ConstIterator ostrI = ostr.begin();
  for (; ostrI != ostr.end(); ++ostrI) {
    if (QLineEdit *w = output(*ostrI)) {
      ptr->setOutputString(*ostrI, 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;
}