Ejemplo n.º 1
0
void Data::collectVectors(KstVectorList& c) {
  if (_vector && !c.contains(_vector)) {
    c.append(_vector);
  }
}
Ejemplo n.º 2
0
int KST::vectorsToFile(const KstVectorList& vl, QFile *f, bool interpolate) {
  KstApp *app = KstApp::inst();
  int maxlen = -1;

  if (interpolate) { // code duplication is faster
    maxlen = 0;
    for (KstVectorList::ConstIterator v = vl.begin(); v != vl.end(); ++v) {
      (*v)->readLock();
      maxlen = KMAX(maxlen, (*v)->length());
    }
  } else {
    for (KstVectorList::ConstIterator v = vl.begin(); v != vl.end(); ++v) {
      (*v)->readLock();
      if (maxlen == -1) {
        maxlen = (*v)->length();
      } else {
        maxlen = KMIN(maxlen, (*v)->length());
      }
    }
  }

  QString saving = i18n("Saving vectors...");
  register int modval = QMAX(maxlen/100, 100);
  app->slotUpdateProgress(maxlen, 0, QString::null);

  bool first = true;
  QString ltxt = ";";
  for (KstVectorList::ConstIterator v = vl.begin(); v != vl.end(); ++v) {
    ltxt += ' ';
    ltxt += (*v)->tagName();
  }
  ltxt += '\n';

  f->writeBlock(ltxt.ascii(), ltxt.length());
  ltxt.fill('-');
  ltxt[0] = ';';
  ltxt[1] = ' ';
  ltxt[ltxt.length() - 1] = '\n';
  f->writeBlock(ltxt.ascii(), ltxt.length());
#if QT_VERSION >= 0x030200
  ltxt.reserve(vl.count()*17);
#endif
  for (int line = 0; line < maxlen; ++line) {
    ltxt.truncate(0);
    first = true;
    for (KstVectorList::ConstIterator v = vl.begin(); v != vl.end(); ++v) {
      if (!first) {
        ltxt += ' ';
      } else {
        first = false;
      }
      double val;
      if (interpolate) {  // might be faster to put this outside the for loops
        val = (*v)->interpolate(line, maxlen);
      } else {
        val = (*v)->value()[line];
      } 
      ltxt += QString::number(val, 'g', 15);
    }
    ltxt += "\n";
    f->writeBlock(ltxt.ascii(), ltxt.length());
    if (line % modval == 0) {
      app->slotUpdateProgress(maxlen, line, saving);
    }
  }

  for (KstVectorList::ConstIterator v = vl.begin(); v != vl.end(); ++v) {
    (*v)->readUnlock();
  }

  app->slotUpdateProgress(0, 0, QString::null);

  return 0;
}
Ejemplo n.º 3
0
bool KstVectorDialogI::editObject() {
  KstVectorList vcList = KST::vectorList;

  // if editing multiple objects, edit each one
  if (_editMultipleMode) {
    // get dirties first
    _fileNameDirty = !_w->FileName->url().isEmpty();
    _skipDirty = _w->_kstDataRange->Skip->text() != " ";
    _f0Dirty = !_w->_kstDataRange->F0->text().isEmpty();
    _nDirty = !_w->_kstDataRange->N->text().isEmpty();
    _NDirty = _w->_N->text() != " ";
    _xMinDirty = !_w->_xMin->text().isEmpty();
    _xMaxDirty = !_w->_xMax->text().isEmpty();

    // now edit the vectors
    bool didEdit = false;
    for (uint i = 0; i < _editMultipleWidget->_objectList->count(); i++) {
      if (_editMultipleWidget->_objectList->isSelected(i)) {
        // get the pointer to the object
        KstVectorList::Iterator vcIter = vcList.findTag(_editMultipleWidget->_objectList->text(i));
        if (vcIter == vcList.end()) {
          return false;
        }
        KstVectorPtr vcPtr = *vcIter;

        if (!editSingleObject(vcPtr)) {
          return false;
        }
        didEdit = true;
      }
    }
    if (!didEdit) {
      KMessageBox::sorry(this, i18n("Select one or more objects to edit."));
      return false;
    }
  } else {
    // verify that the curve name is unique
    QString tag_name = _tagName->text();
    _dp->writeLock();
    if (tag_name != _dp->tagName() && KstData::self()->dataTagNameNotUnique(tag_name)) {
      _dp->writeUnlock();
      _tagName->setFocus();
      return false;
    }

    _dp->setTagName(tag_name);
    _dp->writeUnlock();

    // then edit the object
    _fileNameDirty = true;
    _f0Dirty = true;
    _nDirty = true;
    _NDirty = true;
    _countFromEndDirty = true;
    _readToEndDirty = true;
    _doFilterDirty = true;
    _doSkipDirty = true;
    _skipDirty = true;
    _xMinDirty = true;
    _xMaxDirty = true;
    KstVectorPtr vp = kst_cast<KstVector>(_dp);
    if (!vp || !editSingleObject(vp)) {
      return false;
    }
  }
  emit modified();
  return true;
}