Example #1
0
QString KstIfaceImpl::loadMatrix(const QString& name, const QString& file, const QString& field,
                                int xStart, int yStart, int xNumSteps, int yNumSteps, 
                                int skipFrames, bool boxcarFilter) {
  KstDataSourcePtr src;
  /* generate or find the kstfile */
  KST::dataSourceList.lock().writeLock();
  KstDataSourceList::Iterator it = KST::dataSourceList.findReusableFileName(file);

  if (it == KST::dataSourceList.end()) {
    src = KstDataSource::loadSource(file);
    if (!src || !src->isValid()) {
      KST::dataSourceList.lock().unlock();
      return QString::null;
    }
    if (src->isEmpty()) {
      KST::dataSourceList.lock().unlock();
      return QString::null;
    }
    KST::dataSourceList.append(src);
  } else {
    src = *it;
  }
  src->writeLock();
  KST::dataSourceList.lock().unlock();

  // make sure field is valid
  if (!src->isValidMatrix(field)) {
    src->unlock();
    return QString::null;  
  }
  
  // make sure name is unique, else generate a unique one
  KST::matrixList.lock().readLock();
 
  QString matrixName;
  if (name.isEmpty()) {
    matrixName = "M" + QString::number(KST::matrixList.count() + 1); 
  } else {
    matrixName = name;  
  }

  while (KstData::self()->matrixTagNameNotUnique(matrixName, false)) {
    matrixName = "M" + QString::number(KST::matrixList.count() + 1);
  }
  KST::matrixList.lock().unlock();

  KstMatrixPtr p = new KstRMatrix(src, field, matrixName, xStart, yStart, xNumSteps, yNumSteps, 
                                  boxcarFilter, skipFrames > 0, skipFrames);
  KST::addMatrixToList(p);

  src->unlock();

  if (p) {
    _doc->forceUpdate();
    _doc->setModified();
    return p->tagName();
  }

  return QString::null;
}
Example #2
0
void KstChangeFileDialog::sourceChanged(const QString& text)
{
  delete _configWidget;
  _configWidget = 0L;
  _configureSource->setEnabled(false);
  _file = QString::null;
  if (!text.isEmpty() && text != "stdin" && text != "-") {
    KUrl url;
    QString txt = _dataFile->completionObject()->replacedPath(text);
    if (QFile::exists(txt) && QFileInfo(txt).isRelative()) {
      url.setPath(txt);
    } else {
      url = KUrl::fromPathOrURL(txt);
    }

    if (!url.isLocalFile() && url.protocol() != "file" && !url.protocol().isEmpty()) {
      _fileType->setText(QString::null);
      return;
    }

    if (!url.isValid()) {
      _fileType->setText(QString::null);
      return;
    }

    QString file = txt;

    KstDataSourcePtr ds = *KST::dataSourceList.findReusableFileName(file);
    QStringList fl;
    QString fileType;

    if (ds) {
      ds->readLock();
      fl = ds->fieldList();
      fileType = ds->fileType();
      ds->unlock();
      ds = 0L;
    } else {
      bool complete = false;
      fl = KstDataSource::fieldListForSource(file, QString::null, &fileType, &complete);
    }

    if (!fl.isEmpty() && !fileType.isEmpty()) {
      if (ds) {
        ds->writeLock();
        _configWidget = ds->configWidget();
        ds->unlock();
      } else {
        _configWidget = KstDataSource::configWidgetForSource(file, fileType);
      }
    }

    _configureSource->setEnabled(_configWidget);
    _file = file;
    _fileType->setText(fileType.isEmpty() ? QString::null : tr("Data source of type: %1").arg(fileType));
  } else {
    _fileType->setText(QString::null);
  }
}
void KstChangeNptsDialogI::applyNptsChange() {
  KstRVectorList rvl = kstObjectSubList<KstVector,KstRVector>(KST::vectorList);
  for (uint i = 0; i < CurveList->count(); ++i) {
    if (CurveList->isSelected(i)) {
      KstRVectorPtr vector = *(rvl.findTag(CurveList->text(i)));
      if (vector) {
        int f0, n;

        vector->readLock();
        KstDataSourcePtr ds = vector->dataSource();
        if (_kstDataRange->isStartRelativeTime() && ds) {
          ds->readLock();
          f0 = ds->sampleForTime(_kstDataRange->f0Value());
          ds->unlock();
        } else if (_kstDataRange->isStartAbsoluteTime() && ds) {
          ds->readLock();
          f0 = ds->sampleForTime(_kstDataRange->f0DateTimeValue());
          ds->unlock();
        } else {
          f0 = int(_kstDataRange->f0Value());
        }

        if (_kstDataRange->isRangeRelativeTime() && ds) {
          ds->readLock();
          double nValStored = _kstDataRange->nValue();
          if (_kstDataRange->CountFromEnd->isChecked()) {
            int frameCount = ds->frameCount(vector->field());
            double msCount = ds->relativeTimeForSample(frameCount - 1);
            n = frameCount - 1 - ds->sampleForTime(msCount - nValStored);
          } else {
            double fTime = ds->relativeTimeForSample(f0);
            n = ds->sampleForTime(fTime + nValStored) - ds->sampleForTime(fTime);
          }
          ds->unlock();
        } else {
          n = int(_kstDataRange->nValue());
        }
        vector->unlock();

        vector->writeLock();
        vector->changeFrames(
          (_kstDataRange->CountFromEnd->isChecked() ? -1 : f0),
          (_kstDataRange->ReadToEnd->isChecked() ? -1 : n),
          _kstDataRange->Skip->value(),
          _kstDataRange->DoSkip->isChecked(),
          _kstDataRange->DoFilter->isChecked());
        vector->unlock();
      }
    }
  }

  _modifiedRange = false;

  // avoid re-entering the dialog
  QTimer::singleShot(0, this, SLOT(emitDocChanged()));
}
KJS::Value KstBindDataSource::frameCount(KJS::ExecState *exec, const KJS::List& args) {
  QString field;

  if (args.size() == 1) {
    if (args[0].type() != KJS::StringType) {
      KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError);
      exec->setException(eobj);
      return KJS::Number(0);
    }
    field = args[0].toString(exec).qstring();
  } else if (args.size() != 0) {
    KJS::Object eobj = KJS::Error::create(exec, KJS::SyntaxError, "Requires at most one argument.");
    exec->setException(eobj);
    return KJS::Number(0);
  }

  KstDataSourcePtr s = makeSource(_d);
  if (!s) {
    KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
    exec->setException(eobj);
    return KJS::Number(0);
  }

  s->writeLock();
  int rc = s->frameCount(field);
  s->unlock();

  return KJS::Number(rc);
}
KJS::Value KstBindDataSource::isValidField(KJS::ExecState *exec, const KJS::List& args) {
  if (args.size() != 1) {
    KJS::Object eobj = KJS::Error::create(exec, KJS::SyntaxError, "Requires exactly one argument.");
    exec->setException(eobj);
    return KJS::Boolean(false);
  }

  if (args[0].type() != KJS::StringType) {
    KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError);
    exec->setException(eobj);
    return KJS::Boolean(false);
  }

  KstDataSourcePtr s = makeSource(_d);
  if (!s) {
    KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
    exec->setException(eobj);
    return KJS::Boolean(false);
  }

  s->writeLock();
  bool rc = s->isValidField(args[0].toString(exec).qstring());
  s->unlock();

  return KJS::Boolean(rc);
}
KJS::Value KstBindDataSource::samplesPerFrame(KJS::ExecState *exec, const KJS::List& args) {
  if (args.size() != 1) {
    KJS::Object eobj = KJS::Error::create(exec, KJS::SyntaxError, "Requires exactly one argument.");
    exec->setException(eobj);
    return KJS::Number(0);
  }

  if (args[0].type() != KJS::StringType) {
    KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError);
    exec->setException(eobj);
    return KJS::Number(0);
  }

  KstDataSourcePtr s = makeSource(_d);
  if (!s) {
    KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
    exec->setException(eobj);
    return KJS::Number(0);
  }

  s->writeLock();
  int rc = s->samplesPerFrame(args[0].toString(exec).qstring());
  s->unlock();

  return KJS::Number(rc);
}
Example #7
0
bool KstIfaceImpl::changeDataFile(const QString& vector, const QString& fileName, bool update) {
  KST::vectorList.lock().readLock();
  KstRVectorPtr rvp = kst_cast<KstRVector>(*KST::vectorList.findTag(vector));
  KST::vectorList.lock().unlock();
  if (!rvp) {
    return false;
  }

  KST::dataSourceList.lock().writeLock();
  KstDataSourceList::Iterator it = KST::dataSourceList.findReusableFileName(fileName);
  KstDataSourcePtr file;
  QString invalidSources;

  if (it == KST::dataSourceList.end()) {
    file = KstDataSource::loadSource(fileName);
    if (!file || !file->isValid() || file->isEmpty()) {
      KST::dataSourceList.lock().unlock();
      return false;
    }
    KST::dataSourceList.append(file);
  } else {
    file = *it;
  }

  KST::dataSourceList.lock().unlock();

  rvp->writeLock();
  file->writeLock();

  if (!file->isValidField(vector)) {
    file->unlock();
    rvp->unlock();
    return false;
  }

  rvp->changeFile(file);
  
  file->unlock();
  bool rc = rvp->isValid();
  rvp->unlock();

  if (update) {
    KstApp::inst()->forceUpdate();
  }

  return rc;
}
KJS::Value KstBindDataSource::metaData(KJS::ExecState *exec) const {
  KJS::Object array(exec->interpreter()->builtinArray().construct(exec, 0));
  KstDataSourcePtr s = makeSource(_d);
  if (s) {
    s->readLock();
    QDict<KstString> data = s->metaData();
    s->unlock();
    for (QDictIterator<KstString> i(data); i.current(); ++i) {
      array.put(exec, KJS::Identifier(i.currentKey().latin1()), KJS::String(i.current() ? i.current()->value() : QString::null));
    }
  }
  return array;
}
KJS::Value KstBindDataSource::fieldList(KJS::ExecState *exec, const KJS::List& args) {
  Q_UNUSED(args)
  KJS::List rc;
  KstDataSourcePtr s = makeSource(_d);
  if (!s) {
    KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
    exec->setException(eobj);
    return KJS::Object(exec->interpreter()->builtinArray().construct(exec, rc));
  }
  s->readLock();
  QStringList l = s->fieldList();
  s->unlock();
  for (QStringList::ConstIterator i = l.begin(); i != l.end(); ++i) {
    rc.append(KJS::String(*i));
  }

  return KJS::Object(exec->interpreter()->builtinArray().construct(exec, rc));
}
Example #10
0
const QString& KstIfaceImpl::loadVector(const QString& file, const QString& field) {
  KstDataSourcePtr src;
  /* generate or find the kstfile */
  KST::dataSourceList.lock().writeLock();
  KstDataSourceList::Iterator it = KST::dataSourceList.findReusableFileName(file);

  if (it == KST::dataSourceList.end()) {
    src = KstDataSource::loadSource(file);
    if (!src || !src->isValid()) {
      KST::dataSourceList.lock().unlock();
      return QString::null;
    }
    if (src->isEmpty()) {
      KST::dataSourceList.lock().unlock();
      return QString::null;
    }
    KST::dataSourceList.append(src);
  } else {
    src = *it;
  }
  src->writeLock();
  KST::dataSourceList.lock().unlock();

  KST::vectorList.lock().readLock();
  QString vname = "V" + QString::number(KST::vectorList.count() + 1);

  while (KstData::self()->vectorTagNameNotUnique(vname, false)) {
    vname = "V" + QString::number(KST::vectorList.count() + 1);
  }
  KST::vectorList.lock().unlock();

  KstVectorPtr p = new KstRVector(src, field, vname, 0, -1, 0, false, false);
  KST::addVectorToList(p);

  src->unlock();

  if (p) {
    _doc->forceUpdate();
    _doc->setModified();
    return p->tagName();
  }

  return QString::null;
}
void KstChangeNptsDialogI::updateTimeCombo() {
  KstRVectorList rvl = kstObjectSubList<KstVector,KstRVector>(KST::vectorList);
  uint cnt = CurveList->count();
  bool supportsTime = true;
  for (uint i = 0; i < cnt; ++i) {
    if (CurveList->isSelected(i)) {
      KstRVectorPtr vector = *(rvl.findTag(CurveList->text(i)));
      if (vector) {
        vector->readLock();
        KstDataSourcePtr ds = vector->dataSource();
        vector->unlock();
        if (ds) {
          ds->readLock();
          supportsTime = ds->supportsTimeConversions();
          ds->unlock();
          if (!supportsTime) {
            break;
          }
        }
      }
    }
  }
  _kstDataRange->setAllowTime(supportsTime);
}
Example #12
0
bool UpdateThread::doUpdates(bool force, bool *gotData) {
  KstObject::UpdateType U = KstObject::NO_CHANGE;

  _updatedCurves.clear(); // HACK

  if (gotData) {
    *gotData = false;
  }
  
#if UPDATEDEBUG > 0
  if (force) {
    qDebug() << "Forced update!" << endl;
  }
#endif

  _updateCounter++;
  if (_updateCounter < 1) {
    _updateCounter = 1; // check for wrap around
  }

#if UPDATEDEBUG > 2
  qDebug() << "UPDATE: counter=" << _updateCounter << endl;
#endif

  {
    // Must make a copy to avoid deadlock
    KstBaseCurveList cl;
    KstDataObjectList dol;
    kstObjectSplitList<KstDataObject, KstBaseCurve>(KST::dataObjectList, cl, dol);
    qSort(cl); 
    qSort(dol); 

    // Update all curves
    for (uint i = 0; i < cl.count(); ++i) {
      KstBaseCurvePtr bcp = cl[i];
      bcp->writeLock();
      assert(bcp.data());
#if UPDATEDEBUG > 1
      qDebug() << "updating curve: " << (void*)bcp << " - " << bcp->tagName() << endl;
#endif
      KstObject::UpdateType ut = bcp->update(_updateCounter);
      bcp->unlock();

      if (ut == KstObject::UPDATE) { // HACK
        _updatedCurves.append(bcp);
      }

      if (U != KstObject::UPDATE) {
        U = ut;
        if (U == KstObject::UPDATE) {
#if UPDATEDEBUG > 0
          qDebug() << "Curve " << bcp->tagName() << " said UPDATE" << endl;
#endif
        }
      }

      if (_done || (_paused && !force)) {
#if UPDATEDEBUG > 1
        qDebug() << "5 Returning from scan with U=" << (int)U << endl;
#endif
        return U == KstObject::UPDATE;
      }
    }

    // Update all data objects
    for (uint i = 0; i < dol.count(); ++i) {
      KstDataObjectPtr dp = dol[i];
      dp->writeLock();
      assert(dp.data());
#if UPDATEDEBUG > 1
      qDebug() << "updating data object: " << (void*)dp << " - " << dp->tagName() << endl;
#endif
      dp->update(_updateCounter);
      dp->unlock();

      if (_done || (_paused && !force)) {
#if UPDATEDEBUG > 1
        qDebug() << "5 Returning from scan with U=" << (int)U << endl;
#endif
        return U == KstObject::UPDATE;
      }
    }
  }

  // Update the files
  if (!_paused) { // don't update even if paused && force
    KST::dataSourceList.lock().readLock();
    unsigned cnt = KST::dataSourceList.count();
    for (uint i = 0; i < cnt; ++i) {
      KstDataSourcePtr dsp = KST::dataSourceList[i];

      dsp->writeLock();
      dsp->update(_updateCounter);
      dsp->unlock();

      if (_done) {
        KST::dataSourceList.lock().unlock();
        return false;
      }
    }
    KST::dataSourceList.lock().unlock();
  }

  if (KstScalar::scalarsDirty()) {
    KstScalar::clearScalarsDirty(); // Must do this first and take a risk of
                                    // falling slightly behind
    KST::scalarList.lock().readLock();
    KstScalarList sl = Q3DeepCopy<KstScalarList>(KST::scalarList.list()); // avoid deadlock on exit
    KST::scalarList.lock().unlock();
    for (KstScalarList::ConstIterator i = sl.begin(); i != sl.end(); ++i) {
      KstScalarPtr sp = *i;

      sp->writeLock();
      KstObject::UpdateType ut = sp->update(_updateCounter);
      sp->unlock();

      if (ut == KstObject::UPDATE) {
        U = KstObject::UPDATE;
      }

      if (_done) {
        return false;
      }
    }
  }

  if (U == KstObject::UPDATE) {
    qDebug() << "Update plots" << endl;
    if (gotData) { // FIXME: do we need to consider all the other exit points?
      *gotData = true;
    }
  }

#if UPDATEDEBUG > 1
  qDebug() << "6 Returning from scan with U=" << (int)U << endl;
#endif
  return U == KstObject::UPDATE;
}
Example #13
0
bool KstChangeFileDialog::applyFileChange() {
  KstDataSourcePtr file;
  KST::dataSourceList.lock().writeLock();
  KstDataSourceList::Iterator it = KST::dataSourceList.findReusableFileName(_dataFile->url());
  QString invalidSources;
  int invalid = 0;

  if (it == KST::dataSourceList.end()) {
    file = KstDataSource::loadSource(_dataFile->url());
    if (!file || !file->isValid()) {
      KST::dataSourceList.lock().unlock();
      QMessageBox::warning(this, tr("Kst"), tr("The file could not be loaded."));
      return false;
    }
    if (file->isEmpty()) {
      KST::dataSourceList.lock().unlock();
      QMessageBox::warning(this, tr("Kst"), tr("The file does not contain data."));
      return false;
    }
    KST::dataSourceList.append(file);
  } else {
    file = *it;
  }
  KST::dataSourceList.lock().unlock();

  KstApp *app = KstApp::inst();
  KstRVectorList rvl = kstObjectSubList<KstVector,KstRVector>(KST::vectorList);
  KstRMatrixList rml = kstObjectSubList<KstMatrix,KstRMatrix>(KST::matrixList);
  int selected = 0;
  int handled = 0;

  int count = (int)ChangeFileCurveList->count();
  for (int i = 0; i < count; i++) {
    if (ChangeFileCurveList->isSelected(i)) {
      ++selected;
    }
  }

  // a map to keep track of which objects have been duplicated, and mapping
  // old object -> new object
  KstDataObjectDataObjectMap duplicatedMap;
  QMap<KstVectorPtr, KstVectorPtr> duplicatedVectors;
  QMap<KstMatrixPtr, KstMatrixPtr> duplicatedMatrices;

  KstDataSourceList oldSources;

  // go through the vectors
  for (int i = 0; i < (int)rvl.count(); i++) {
    if (ChangeFileCurveList->isSelected(i)) {
      KstRVectorPtr vector = rvl[i];
      vector->writeLock();
      file->readLock();
      bool valid = file->isValidField(vector->field());
      file->unlock();
      if (!valid) {
        if (invalid > 0) {
          invalidSources = tr("%1, %2").arg(invalidSources).arg(vector->field());
        } else {
          invalidSources = vector->field();
        }
        ++invalid;
      } else {
        if (_duplicateSelected->isChecked()) {
          // block vector updates until vector is setup properly
          KST::vectorList.lock().writeLock();

          // create a new vector
          KstRVectorPtr newVector = vector->makeDuplicate();
          if (!oldSources.contains(newVector->dataSource())) {
            oldSources << newVector->dataSource();
          }
          newVector->changeFile(file);

          KST::vectorList.lock().unlock();

          // duplicate dependents
          if (_duplicateDependents->isChecked()) {
            duplicatedVectors.insert(KstVectorPtr(vector), KstVectorPtr(newVector));
            KST::duplicateDependents(KstVectorPtr(vector), duplicatedMap, duplicatedVectors);
          }
        } else {
          if (!oldSources.contains(vector->dataSource())) {
            oldSources << vector->dataSource();
          }
          vector->changeFile(file);
        }
      }
      vector->unlock();
      app->slotUpdateProgress(selected, ++handled, tr("Updating vectors..."));
    }
  }

  // go through the matrices
  for (int i = (int)rvl.count(); i < (int)ChangeFileCurveList->count(); i++) {
    if (ChangeFileCurveList->isSelected(i)) {
      KstRMatrixPtr matrix = rml[i-rvl.count()];
      matrix->writeLock();
      file->readLock();
      bool valid = file->isValidMatrix(matrix->field());
      file->unlock();
      if (!valid) {
        if (invalid > 0) {
          invalidSources = tr("%1, %2").arg(invalidSources).arg(matrix->field());
        } else {
          invalidSources = matrix->field();
        }
        ++invalid;
      } else {
        if (_duplicateSelected->isChecked()) {
          // block matrix updates until matrix is setup properly
          KST::matrixList.lock().writeLock();

          // create a new matrix
          KstRMatrixPtr newMatrix = matrix->makeDuplicate();
          if (!oldSources.contains(newMatrix->dataSource())) {
            oldSources << newMatrix->dataSource();
          }
          newMatrix->changeFile(file);

          KST::matrixList.lock().unlock();

          // duplicate dependents
          if (_duplicateDependents->isChecked()) {
            duplicatedMatrices.insert(KstMatrixPtr(matrix), KstMatrixPtr(newMatrix));
            KST::duplicateDependents(KstMatrixPtr(matrix), duplicatedMap, duplicatedMatrices);
          }
        } else {
          if (!oldSources.contains(matrix->dataSource())) {
            oldSources << matrix->dataSource();
          }
          matrix->changeFile(file);
        }
      }
      matrix->unlock();
      app->slotUpdateProgress(selected, ++handled, tr("Updating matrices..."));
    }
  }

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

  // now add any curves and images to plots if they were duplicated
  if (_duplicateSelected->isChecked() && _duplicateDependents->isChecked()) { 
    KstApp *app = KstApp::inst();
    QList<QMdiSubWindow*> windows;
    QList<QMdiSubWindow*>::const_iterator i;
  
    windows = app->subWindowList( CreationOrder );

    for (i = windows.constBegin(); i != windows.constEnd(); ++i)
      KstViewWindow *viewWindow = dynamic_cast<KstViewWindow*>(*i);
      if (viewWindow) {
        KstTopLevelViewPtr view = kst_cast<KstTopLevelView>(viewWindow->view());
        if (view) {
          Kst2DPlotList plots = view->findChildrenType<Kst2DPlot>(true);

          for (Kst2DPlotList::Iterator plotIter = plots.begin(); plotIter != plots.end(); ++plotIter) {
            for (KstDataObjectDataObjectMap::ConstIterator iter = duplicatedMap.begin(); iter != duplicatedMap.end(); ++iter) {
              if (KstBaseCurvePtr curve = kst_cast<KstBaseCurve>(iter.data())) {
                if ((*plotIter)->Curves.contains(kst_cast<KstBaseCurve>(iter.key())) && !(*plotIter)->Curves.contains(kst_cast<KstBaseCurve>(curve))) {
                  (*plotIter)->addCurve(curve);
                }
              }
            }
          }
        }
      }
    }
  }
bool KstChangeFileDialogI::applyFileChange() {
  KstDataSourcePtr file;
  KST::dataSourceList.lock().writeLock();
  KstDataSourceList::Iterator it = KST::dataSourceList.findReusableFileName(_dataFile->url());
  QString invalidSources;
  int invalid = 0;

  if (it == KST::dataSourceList.end()) {
    file = KstDataSource::loadSource(_dataFile->url());
    if (!file || !file->isValid()) {
      KST::dataSourceList.lock().unlock();
      KMessageBox::sorry(this, i18n("The file could not be loaded."));
      return false;
    }
    if (file->isEmpty()) {
      KST::dataSourceList.lock().unlock();
      KMessageBox::sorry(this, i18n("The file does not contain data."));
      return false;
    }
    KST::dataSourceList.append(file);
  } else {
    file = *it;
  }
  KST::dataSourceList.lock().unlock();

  KstApp *app = KstApp::inst();
  KstRVectorList rvl = kstObjectSubList<KstVector,KstRVector>(KST::vectorList);
  KstRMatrixList rml = kstObjectSubList<KstMatrix,KstRMatrix>(KST::matrixList);
  int selected = 0;
  int handled = 0;

  int count = (int)ChangeFileCurveList->count();
  for (int i = 0; i < count; i++) {
    if (ChangeFileCurveList->isSelected(i)) {
      ++selected;
    }
  }

  // a map to keep track of which objects have been duplicated, and mapping
  // old object -> new object
  KstDataObjectDataObjectMap duplicatedMap;
  QMap<KstVectorPtr, KstVectorPtr> duplicatedVectors;
  QMap<KstMatrixPtr, KstMatrixPtr> duplicatedMatrices;

  KstDataSourceList oldSources;
  
  // go through the vectors
  for (int i = 0; i < (int)rvl.count(); i++) {
    if (ChangeFileCurveList->isSelected(i)) {
      KstRVectorPtr vector = rvl[i];
      vector->writeLock();
      file->readLock();
      bool valid = file->isValidField(vector->field());
      file->unlock();
      if (!valid) {
        if (invalid > 0) {
          // FIXME: invalid list construction for i18n
          invalidSources = i18n("%1, %2").arg(invalidSources).arg(vector->field());
        } else {
          invalidSources = vector->field();
        }
        ++invalid;
      } else {
        if (_duplicateSelected->isChecked()) {
          // block vector updates until vector is setup properly
          KST::vectorList.lock().writeLock();

          // create a new vector
          KstRVectorPtr newVector = vector->makeDuplicate();
          if (!oldSources.contains(newVector->dataSource())) {
            oldSources << newVector->dataSource();
          }
          newVector->changeFile(file);

          KST::vectorList.lock().unlock();

          // duplicate dependents
          if (_duplicateDependents->isChecked()) {
            duplicatedVectors.insert(KstVectorPtr(vector), KstVectorPtr(newVector));
            KST::duplicateDependents(KstVectorPtr(vector), duplicatedMap, duplicatedVectors);
          }
        } else {
          if (!oldSources.contains(vector->dataSource())) {
            oldSources << vector->dataSource();
          }
          vector->changeFile(file);
        }
      }
      vector->unlock();
      app->slotUpdateProgress(selected, ++handled, i18n("Updating vectors..."));
    }
  }
  
  // go through the matrices
  for (int i = (int)rvl.count(); i < (int)ChangeFileCurveList->count(); i++) {
    if (ChangeFileCurveList->isSelected(i)) {
      KstRMatrixPtr matrix = rml[i-rvl.count()];
      matrix->writeLock();
      file->readLock();
      bool valid = file->isValidMatrix(matrix->field());
      file->unlock();
      if (!valid) {
        if (invalid > 0) {
          // FIXME: invalid list construction for i18n
          invalidSources = i18n("%1, %2").arg(invalidSources).arg(matrix->field());
        } else {
          invalidSources = matrix->field();
        }
        ++invalid;
      } else {
        if (_duplicateSelected->isChecked()) {
          // block matrix updates until matrix is setup properly
          KST::matrixList.lock().writeLock();

          // create a new matrix
          KstRMatrixPtr newMatrix = matrix->makeDuplicate();
          if (!oldSources.contains(newMatrix->dataSource())) {
            oldSources << newMatrix->dataSource();
          }
          newMatrix->changeFile(file);

          KST::matrixList.lock().unlock();

          // duplicate dependents
          if (_duplicateDependents->isChecked()) {
            duplicatedMatrices.insert(KstMatrixPtr(matrix), KstMatrixPtr(newMatrix));
            KST::duplicateDependents(KstMatrixPtr(matrix), duplicatedMap, duplicatedMatrices);
          }
        } else {
          if (!oldSources.contains(matrix->dataSource())) {
            oldSources << matrix->dataSource();
          }
          matrix->changeFile(file);
        }
      }
      matrix->unlock();
      app->slotUpdateProgress(selected, ++handled, i18n("Updating matrices..."));
    }
  }

  app->slotUpdateProgress(0, 0, QString::null);
  file = 0L;
  
  // now add any curves and images to plots if they were duplicated
  if (_duplicateSelected->isChecked() && _duplicateDependents->isChecked()) { 
    KstApp *app = KstApp::inst();
    KMdiIterator<KMdiChildView*> *it = app->createIterator();
    while (it->currentItem()) {
      KstViewWindow *w = dynamic_cast<KstViewWindow*>(it->currentItem());
      if (w) {
        KstTopLevelViewPtr view = kst_cast<KstTopLevelView>(w->view());
        if (view) {
          Kst2DPlotList plots = view->findChildrenType<Kst2DPlot>(true);
          for (Kst2DPlotList::Iterator plotIter = plots.begin(); plotIter != plots.end(); ++plotIter) {
            for (KstDataObjectDataObjectMap::ConstIterator iter = duplicatedMap.begin(); iter != duplicatedMap.end(); ++iter) {
              if (KstBaseCurvePtr curve = kst_cast<KstBaseCurve>(iter.data())) {
                if ((*plotIter)->Curves.contains(kst_cast<KstBaseCurve>(iter.key())) && !(*plotIter)->Curves.contains(kst_cast<KstBaseCurve>(curve))) {
                  (*plotIter)->addCurve(curve);
                }
              } 
            }
  
          }     
        }
      }
      it->next();
    }
    app->deleteIterator(it);
  }

  // clean up unused data sources
//  kstdDebug() << "cleaning up data sources" << endl;
  KST::dataSourceList.lock().writeLock();
  for (KstDataSourceList::Iterator it = oldSources.begin(); it != oldSources.end(); ++it) {
//    kstdDebug() << "DATA SOURCE: " << (*it)->tag().displayString() << " (" << (void*)(*it) << ") USAGE: " << (*it)->getUsage() << endl;
    if ((*it)->getUsage() == 1) {
//      kstdDebug() << "    -> REMOVED" << endl;
      KST::dataSourceList.remove((*it).data());
    }
  }
  KST::dataSourceList.lock().unlock();
  
  if (!invalidSources.isEmpty()) {
    if (invalid == 1) {
      KMessageBox::sorry(this, i18n("The following field is not defined for the requested file:\n%1").arg(invalidSources));
    } else {
      KMessageBox::sorry(this, i18n("The following fields are not defined for the requested file:\n%1").arg(invalidSources));
    }
  }

  emit docChanged();

  // force an update in case we're in paused mode
  KstApp::inst()->forceUpdate();
  return true;
}
bool KstVectorDialogI::editSingleObjectRV(KstVectorPtr vcPtr) {
  KstRVectorPtr rvp = kst_cast<KstRVector>(vcPtr);

  KstDataSourcePtr file;
  if (_fileNameDirty) {
    // if there is not an active KstFile, create one
    KST::dataSourceList.lock().writeLock();
    KstDataSourceList::Iterator it = KST::dataSourceList.findReusableFileName(_w->FileName->url());

    if (it == KST::dataSourceList.end()) {
      file = KstDataSource::loadSource(_w->FileName->url());
      if (!file || !file->isValid()) {
        KST::dataSourceList.lock().unlock();
        KMessageBox::sorry(this, i18n("The file could not be opened."));
        return false;
      }
      if (file->isEmpty()) {
        KST::dataSourceList.lock().unlock();
        KMessageBox::sorry(this, i18n("The file does not contain data."));
        return false;
      }
      KST::dataSourceList.append(file);
    } else {
      file = *it;
    }
    KST::dataSourceList.lock().unlock();
  } else {
    KstRVectorList vcList = kstObjectSubList<KstVector,KstRVector>(KST::vectorList);
    for (uint i = 0; i < _editMultipleWidget->_objectList->count(); i++) {
      if (_editMultipleWidget->_objectList->isSelected(i)) {
        // get the pointer to the object
        KstRVectorList::Iterator vcIter = vcList.findTag(_editMultipleWidget->_objectList->text(i));
        if (vcIter == vcList.end()) {
          return false;
        }

        KstRVectorPtr rvp = *vcIter;
        rvp->readLock();
        file = rvp->dataSource();
        rvp->unlock();
      }
    }
  }

  file->writeLock();
  if (rvp) {
    QString pField;
    if (_fileNameDirty) {
      pField = _w->Field->currentText();
      if (!file->isValidField(pField)) {
        KMessageBox::sorry(this, i18n("The requested field is not defined for the requested file."));
        file->unlock();
        return false;
      }
    } else {
      pField = rvp->field();
    }

    int f0 = 0, n = 0;
    if (_f0Dirty) {
      if (_w->_kstDataRange->isStartRelativeTime()) {
        f0 = file->sampleForTime(_w->_kstDataRange->f0Value());
      } else if (_w->_kstDataRange->isStartAbsoluteTime()) {
        bool ok = false;
        f0 = file->sampleForTime(_w->_kstDataRange->f0DateTimeValue(), &ok);
        if (!ok) {
          file->unlock();
          KMessageBox::sorry(this, i18n("The requested field or file could not use the specified date."));
          return false;
        }
      } else {
        f0 = int(_w->_kstDataRange->f0Value());
      }
    }
    if (_nDirty) {
      if (_w->_kstDataRange->isRangeRelativeTime()) {
        double nValStored = _w->_kstDataRange->nValue();
        if (_w->_kstDataRange->CountFromEnd->isChecked()) {
          int frameCount = file->frameCount(_w->Field->currentText());
          double msCount = file->relativeTimeForSample(frameCount - 1);
          n = frameCount - 1 - file->sampleForTime(msCount - nValStored);
        } else {
          double fTime = file->relativeTimeForSample(f0);
          n = file->sampleForTime(fTime + nValStored) - file->sampleForTime(fTime);
        }
      } else {
        n = int(_w->_kstDataRange->nValue());
      }
    }
    // use existing requested start and number of frames if not dirty
    rvp->readLock();
    if (!_f0Dirty) {
      f0 = rvp->reqStartFrame();
    }
    if (!_nDirty) {
      n = rvp->reqNumFrames();
    }
    // other parameters for multiple edit
    bool pCountFromEnd, pReadToEnd, pDoSkip, pDoFilter;
    int pSkip;

    if (_countFromEndDirty) {
      pCountFromEnd = _w->_kstDataRange->CountFromEnd->isChecked();
    } else {
      pCountFromEnd = rvp->countFromEOF();
    }

    if (_readToEndDirty) {
      pReadToEnd = _w->_kstDataRange->ReadToEnd->isChecked();
    } else {
      pReadToEnd = rvp->readToEOF();
    }

    if (_skipDirty) {
      pSkip = _w->_kstDataRange->Skip->value();
    } else {
      pSkip = rvp->skip();
    }

    if (_doSkipDirty) {
      pDoSkip = _w->_kstDataRange->DoSkip->isChecked();
    } else {
      pDoSkip = rvp->doSkip();
    }

    if (_doFilterDirty) {
      pDoFilter = _w->_kstDataRange->DoFilter->isChecked();
    } else {
      pDoFilter = rvp->doAve();
    }

    rvp->unlock();

    // change the vector
    rvp->writeLock();
    rvp->change(file, pField, rvp->tag(), pCountFromEnd ?  -1 : f0, pReadToEnd ?  -1 : n, pSkip, pDoSkip, pDoFilter);
    rvp->unlock();
  } else {
    KstSVectorPtr svp = kst_cast<KstSVector>(_dp);
    if (!svp) {
      file->unlock();
      return true; // shouldn't be needed
    }
    double x0 = _w->_xMin->text().toDouble();
    double x1 = _w->_xMax->text().toDouble();
    int n = _w->_N->value();

    svp->writeLock();
    svp->changeRange(x0, x1, n);
    svp->setTagName(KstObjectTag(_tagName->text(), svp->tag().context())); // FIXME: doesn't verify uniqueness, doesn't allow changing tag context
    svp->unlock();
  }
  file->unlock();
  return true;
}
bool KstVectorDialogI::newObject() {
  KstDataSourcePtr file;
  QString tag_name = _tagName->text();

  if (_w->_readFromSource->isChecked()) {
    tag_name.replace(defaultTag, _w->Field->currentText());
    tag_name = KST::suggestVectorName(tag_name);

    // if there is not an active DataSource, create one
    {
      KST::dataSourceList.lock().writeLock();
      KstDataSourceList::Iterator it = KST::dataSourceList.findReusableFileName(_w->FileName->url());

      if (it == KST::dataSourceList.end()) {
        file = KstDataSource::loadSource(_w->FileName->url());
        if (!file || !file->isValid()) {
          KST::dataSourceList.lock().unlock();
          KMessageBox::sorry(this, i18n("The file could not be loaded."));
          return false;
        }
        if (file->isEmpty()) {
          KST::dataSourceList.lock().unlock();
          KMessageBox::sorry(this, i18n("The file does not contain data."));
          return false;
        }
        KST::dataSourceList.append(file);
      } else {
        file = *it;
      }
      KST::dataSourceList.lock().unlock();
    }
    file->readLock();
    if (!file->isValidField(_w->Field->currentText())) {
      file->unlock();
      KMessageBox::sorry(this, i18n("The requested field is not defined for the requested file."));
      return false;
    }

    int f0, n;
    if (_w->_kstDataRange->isStartRelativeTime()) {
      f0 = file->sampleForTime(_w->_kstDataRange->f0Value());
    } else if (_w->_kstDataRange->isStartAbsoluteTime()) {
      bool ok = false;
      f0 = file->sampleForTime(_w->_kstDataRange->f0DateTimeValue(), &ok);
      if (!ok) {
        file->unlock();
        KMessageBox::sorry(this, i18n("The requested field or file could not use the specified date."));
        return false;
      }
    } else {
      f0 = int(_w->_kstDataRange->f0Value());
    }

    if (_w->_kstDataRange->isRangeRelativeTime()) {
      double nValStored = _w->_kstDataRange->nValue();
      if (_w->_kstDataRange->CountFromEnd->isChecked()) {
        int frameCount = file->frameCount(_w->Field->currentText());
        double msCount = file->relativeTimeForSample(frameCount - 1);
        n = frameCount - 1 - file->sampleForTime(msCount - nValStored);
      } else {
        double fTime = file->relativeTimeForSample(f0);
        n = file->sampleForTime(fTime + nValStored) - file->sampleForTime(fTime);
      }
    } else {
      n = int(_w->_kstDataRange->nValue());
    }
    file->unlock();

    // create the vector
    KstRVectorPtr vector = new KstRVector(
        file, _w->Field->currentText(),
        KstObjectTag(tag_name, file->tag(), false),
        _w->_kstDataRange->CountFromEnd->isChecked() ? -1 : f0,
        _w->_kstDataRange->ReadToEnd->isChecked() ? -1 : n,
        _w->_kstDataRange->Skip->value(),
        _w->_kstDataRange->DoSkip->isChecked(),
        _w->_kstDataRange->DoFilter->isChecked());

    emit vectorCreated(KstVectorPtr(vector));
    vector = 0L;
    emit modified();
  } else {
    double x0 = _w->_xMin->text().toDouble();
    double x1 = _w->_xMax->text().toDouble();
    int n = _w->_N->value();
    QString tagname = _tagName->text();
    if (tagname == defaultTag) {
      tagname = KST::suggestVectorName(QString("(%1..%2)").arg(x0).arg(x1));
    }

    KstSVectorPtr svector = new KstSVector(x0, x1, n, KstObjectTag(tagname, KstObjectTag::globalTagContext));
    emit vectorCreated(KstVectorPtr(svector));
    svector = 0L;
    emit modified();
  }

  return true;
}
void KstVectorDialogI::fillFieldsForRVEdit() {
  KstRVectorPtr rvp = kst_cast<KstRVector>(_dp);
  rvp->readLock();

  _w->_readFromSource->setChecked(true);
  _w->_rvectorGroup->show();
  _w->_kstDataRange->show();
  _w->_kstDataRange->setEnabled(true);
  _w->_svectorGroup->hide();
  _w->_svectorGroup->setEnabled(false);
  _w->sourceGroup->hide();

  _tagName->setText(rvp->tagName());

  _w->Field->clear();
  if (_fieldCompletion) {
    _fieldCompletion->clear();
  }

  {
    KstDataSourcePtr tf;
    KST::dataSourceList.lock().readLock();
    KstDataSourceList::Iterator it = KST::dataSourceList.findReusableFileName(rvp->filename());
    if (it != KST::dataSourceList.end()) {
      tf = *it;
      tf->readLock();
      _w->Field->insertStringList(tf->fieldList());
      if (_fieldCompletion) {
        _fieldCompletion->insertItems(tf->fieldList());
      }
      tf->unlock();
    } else {
      QStringList list = KstDataSource::fieldListForSource(_w->FileName->url());
      _w->Field->insertStringList(list);
      if (_fieldCompletion) {
        _fieldCompletion->insertItems(list);
      }
    }
    KST::dataSourceList.lock().unlock();
  }

  _w->Field->setEnabled(_w->Field->count() > 0);
  _ok->setEnabled(_w->Field->isEnabled());
  _w->Field->setCurrentText(rvp->field());

  // select the proper file
  _w->FileName->setURL(rvp->filename());

  // fill the vector range entries
  _w->_kstDataRange->CountFromEnd->setChecked(rvp->countFromEOF());
  _w->_kstDataRange->setF0Value(rvp->reqStartFrame());

  // fill number of frames entries
  _w->_kstDataRange->ReadToEnd->setChecked(rvp->readToEOF());
  _w->_kstDataRange->setNValue(rvp->reqNumFrames());

  // fill in frames to skip box
  _w->_kstDataRange->Skip->setValue(rvp->skip());
  _w->_kstDataRange->DoSkip->setChecked(rvp->doSkip());
  _w->_kstDataRange->DoFilter->setChecked(rvp->doAve());
  _w->_kstDataRange->updateEnables();

  rvp->unlock();
}
Example #18
0
bool KstMatrixDialog::editSingleRMatrix(KstRMatrixPtr rmp) {
  KstDataSourcePtr file;
  QString pField;
  bool doSkip, doAve;
  int xStart;
  int yStart;
  int xNumSteps;
  int yNumSteps;
  int skip;

  if (_fileNameDirty) {
    KstDataSourceList::iterator it;

    //
    // if there is not an active KstFile, create one...
    //

    KST::dataSourceList.lock().writeLock();
// xxx    it = KST::dataSourceList.findReusableFileName(_w->_fileName->url());

    if (it == KST::dataSourceList.end()) {
// xxx      file = KstDataSource::loadSource(_w->_fileName->url());
      if (!file || !file->isValid()) {
        KST::dataSourceList.lock().unlock();
        QMessageBox::warning(this, QObject::tr("Kst"), QObject::tr("The file could not be opened."));

        return false;
      }

      if (file->isEmpty()) {
        KST::dataSourceList.lock().unlock();
        QMessageBox::warning(this, QObject::tr("Kst"), QObject::tr("The file does not contain data."));

        return false;
      }
      KST::dataSourceList.append(file);
    } else {
      file = *it;
    }
    KST::dataSourceList.lock().unlock();

    pField = _w->_field->currentText();
    if (!file->isValidMatrix(pField)) {
      QMessageBox::warning(this, QObject::tr("Kst"), QObject::tr("The requested field is not defined for the requested file."));
      file->unlock();

      return false;
    }
  } else {
    rmp->readLock();
    file = rmp->dataSource();
    pField = rmp->field();
    rmp->unlock();
  }

  rmp->readLock();

  if (_xStartDirty || _xStartCountFromEndDirty) {
    xStart = _w->_xStartCountFromEnd->isChecked() ? -1 : _w->_xStart->value();
  } else {
    xStart = rmp->reqXStart();
  }

  if (_yStartDirty || _yStartCountFromEndDirty) {
    yStart = _w->_yStartCountFromEnd->isChecked() ? -1 : _w->_yStart->value();
  } else {
    yStart = rmp->reqYStart();
  }

  if (_xNumStepsDirty || _xNumStepsReadToEndDirty) {
    xNumSteps = _w->_xNumStepsReadToEnd->isChecked() ? -1 : _w->_xNumSteps->value();
  } else {
    xNumSteps = rmp->reqXNumSteps();
  }

  if (_yNumStepsDirty || _yNumStepsReadToEndDirty) {
    yNumSteps = _w->_yNumStepsReadToEnd->isChecked() ? -1 : _w->_yNumSteps->value();
  } else {
    yNumSteps = rmp->reqYNumSteps();
  }

  if (_doSkipDirty) {
    doSkip = _w->_doSkip->isChecked();
  } else {
    doSkip = rmp->doSkip();
  }

  if (_doAveDirty) {
    doAve = _w->_doAve->isChecked();
  } else {
    doAve = rmp->doAverage();
  }

  if (_skipDirty) {
    skip = _w->_skip->value();
  } else {
    skip = rmp->skip();
  }

  rmp->unlock();

  rmp->writeLock();
  rmp->change(file, pField, KstObjectTag(rmp->tag().tag(), rmp->tag().context()), xStart, yStart, xNumSteps, yNumSteps, doAve, doSkip, skip);
  rmp->unlock();

  return true;
}
Example #19
0
void KstMatrixDialog::fillFieldsForRMatrixEdit() {
  KstRMatrixPtr rmp;

  //
  // first hide/show the correct widgets...
  //

  _w->_readFromSource->setChecked(true);
  _w->_generateGradient->setChecked(false);
  _w->_dataSourceGroup->show();
  _w->_dataRangeGroup->show();
  _w->_gradientGroup->hide();
  _w->_scalingGroup->hide();

  rmp = kst_cast<KstRMatrix>(_dp);
  if (rmp) {
    rmp->readLock();
  
    //
    // fill in the list of fields...
    //

    _w->_field->clear();
/* xxx
    if (_fieldCompletion) {
      _fieldCompletion->clear();
    }
*/
    //
    // scope for iterator...
    //

    {
      KstDataSourcePtr tf;
      KstDataSourceList::iterator it;

      KST::dataSourceList.lock().readLock();
      it = KST::dataSourceList.findReusableFileName(rmp->filename());
      if (it != KST::dataSourceList.end()) {
        tf = *it;
        tf->readLock();
        _w->_field->insertItems(0, tf->matrixList());
/* xxx
        if (_fieldCompletion) {
          _fieldCompletion->insertItems(tf->matrixList());
        }
*/
        tf->unlock();
      } else {
        QStringList list;

// xxx        list = KstDataSource::matrixListForSource(_w->_fileName->url());
        _w->_field->insertItems(0, list);
/* xxx
        if (_fieldCompletion) {
          _fieldCompletion->insertItems(list);
        }
*/
      }
      KST::dataSourceList.lock().unlock();
    }

    _w->_field->setEnabled(_w->_field->count() > 0);
    _ok->setEnabled(_w->_field->isEnabled());
    _w->_field->setItemText(_w->_field->currentIndex(), rmp->field());
  
    //
    // fill in the other parameters...
    //

// xxx    _w->_fileName->setURL(rmp->filename());
  
    _w->_xStart->setValue(rmp->reqXStart());
    _w->_yStart->setValue(rmp->reqYStart());
    _w->_xNumSteps->setValue(rmp->reqXNumSteps());
    _w->_yNumSteps->setValue(rmp->reqYNumSteps());
  
    _w->_xStartCountFromEnd->setChecked(rmp->xCountFromEnd());
    _w->_yStartCountFromEnd->setChecked(rmp->yCountFromEnd());
    _w->_xNumStepsReadToEnd->setChecked(rmp->xReadToEnd());
    _w->_yNumStepsReadToEnd->setChecked(rmp->yReadToEnd());
  
    _w->_doSkip->setChecked(rmp->doSkip());
    _w->_skip->setValue(rmp->skip());
    _w->_doAve->setChecked(rmp->doAverage());
  
    rmp->unlock();
  }
}
Example #20
0
bool KstMatrixDialog::new_IRMatrix() {
  KstDataSourcePtr file;
  KstRMatrixPtr matrix;
  KstDataSourceList::iterator it;
  QString pField;
  QString tagName;
  bool doSkip;
  bool doAve;
  int xStart = _w->_xStartCountFromEnd->isChecked() ? -1 : _w->_xStart->value();
  int yStart = _w->_yStartCountFromEnd->isChecked() ? -1 : _w->_yStart->value();
  int xNumSteps = _w->_xNumStepsReadToEnd->isChecked() ? -1 : _w->_xNumSteps->value();
  int yNumSteps = _w->_yNumStepsReadToEnd->isChecked() ? -1 : _w->_yNumSteps->value();
  int skip;

  //
  // create a unique name...
  //

  tagName = (_tagName->text() == "<New_Matrix>") ? KST::suggestMatrixName(_w->_field->currentText()) : _tagName->text();
  if (KstData::self()->matrixTagNameNotUnique(tagName)) {
    _tagName->setFocus();

    return false;
  }

  //
  // if there is not an active KstFile, create one...
  //

  KST::dataSourceList.lock().writeLock();
// xxx  it = KST::dataSourceList.findReusableFileName(_w->_fileName->url());

  if (it == KST::dataSourceList.end()) {
// xxx    file = KstDataSource::loadSource(_w->_fileName->url());
    if (!file || !file->isValid()) {
      KST::dataSourceList.lock().unlock();
      QMessageBox::warning(this, QObject::tr("Kst"), QObject::tr("The file could not be opened."));

      return false;
    }

    if (file->isEmpty()) {
      KST::dataSourceList.lock().unlock();
      QMessageBox::warning(this, QObject::tr("Kst"), QObject::tr("The file does not contain data."));

      return false;
    }
    KST::dataSourceList.append(file);
  } else {
    file = *it;
  }
  KST::dataSourceList.lock().unlock();

  pField = _w->_field->currentText();

  if (!file->isValidMatrix(pField)) {
    QMessageBox::warning(this, QObject::tr("Kst"), QObject::tr("The requested matrix is not defined for the requested file."));
    file->unlock();

    return false;
  }

  doSkip = _w->_doSkip->isChecked();
  doAve = _w->_doAve->isChecked();
  skip = _w->_skip->value();

  matrix = new KstRMatrix(file, pField, KstObjectTag(tagName, file->tag(), false),
                          xStart, yStart, xNumSteps, yNumSteps, doAve, doSkip, skip);

  emit matrixCreated(KstMatrixPtr(matrix));

  matrix = 0L; // drop the reference

  emit modified();

  return true;
}
void KstVectorDialogI::updateCompletion() {
  QString current_text = _w->Field->currentText();
  _w->Field->clear();

  // update filename list and ll axes combo boxes
  KST::dataSourceList.lock().readLock();
  KstDataSourcePtr ds = *KST::dataSourceList.findReusableFileName(_w->FileName->url());
  KST::dataSourceList.lock().unlock();

  delete _configWidget;
  _configWidget = 0L;
  QStringList list;
  if (ds) {
    ds->readLock();
    list = ds->fieldList();
    _w->Field->setEditable(!ds->fieldListIsComplete());
    _configWidget = ds->configWidget();
    ds->unlock();
    _w->Field->setEnabled(true);
    _w->_connect->hide();
    _w->_kstDataRange->setAllowTime(ds->supportsTimeConversions());
  } else {
    QString type;
    bool complete = false;
    QString u = _w->FileName->url();
    KURL url;
    if (QFile::exists(u) && QFileInfo(u).isRelative()) {
      url.setPath(u);
    } else {
      url = KURL::fromPathOrURL(u);
    }

    if (!_inTest && !url.isLocalFile() && url.protocol() != "file" && !url.protocol().isEmpty()) {
      _w->_connect->show();
    } else if (url.isValid()) {
      list = KstDataSource::fieldListForSource(u, QString::null, &type, &complete);
      if (!_inTest || (_inTest && !list.isEmpty())) {
        _w->_connect->hide();
      }
    }
    _w->Field->setEditable(!complete);
    _w->Field->setEnabled(!list.isEmpty());
    if (!list.isEmpty() && !type.isEmpty()) {
      _configWidget = KstDataSource::configWidgetForSource(u, type);
    }
    _w->_kstDataRange->setAllowTime(KstDataSource::supportsTime(u, type));
  }

  _w->_configure->setEnabled(_configWidget);

  _fieldCompletion = _w->Field->completionObject();

  _w->Field->insertStringList(list);
  if (_fieldCompletion) {
    _fieldCompletion->clear();
    _fieldCompletion->insertItems(list);
  }
  if (!current_text.isEmpty() && (list.contains(current_text) || _w->Field->editable())) {
    _w->Field->setCurrentText(current_text);
  }
  _ok->setEnabled(_w->Field->isEnabled() || _editMultipleMode);
}
Example #22
0
void KstMatrixDialog::updateCompletion() {
  KstDataSourcePtr ds;
  QString current_text = _w->_field->currentText();
  QStringList list;

  _w->_field->clear();

  //
  // update filename list and ll axes combo boxes...
  //

  KST::dataSourceList.lock().readLock();
// xxx  ds = *KST::dataSourceList.findReusableFileName(_w->_fileName->url());
  KST::dataSourceList.lock().unlock();

  delete _configWidget;
  _configWidget = 0L;

  if (ds) {
    ds->readLock();
    list = ds->matrixList();
    _w->_field->setEditable(!ds->fieldListIsComplete());
    _configWidget = ds->configWidget();
    ds->unlock();
    _w->_field->setEnabled(true);
    _w->_connect->hide();
  //  _kstDataRange->setAllowTime(ds->supportsTimeConversions());
  } else {
    bool complete = false;
    QString u;
    QString type;

/* xxx
    u = _w->_fileName->url();
    
    if (QFile::exists(u) && QFileInfo(u).isRelative()) {
      url.setPath(u);
    } else {
      url = QUrl(u);
    }

    if (!_inTest && !url.scheme()=="file" && url.scheme() != "file" && !url.isRelative()) {
      _w->_connect->show();
    } else if (url.isValid()) {
      list = KstDataSource::matrixListForSource(u, QString::null, &type, &complete);

      //
      // pretend we're getting the full field list...
      //

      if (list.isEmpty()) {
        QStringList fullList = KstDataSource::fieldListForSource(u, QString::null, &type, &complete);
      }

      if (!_inTest || (_inTest && !list.isEmpty())) {
        _w->_connect->hide();
      }
    }
*/
    _w->_field->setEditable(!complete);
    _w->_field->setEnabled(!list.isEmpty());
    if (!type.isEmpty()) {
      _configWidget = KstDataSource::configWidgetForSource(u, type);
    }
//    _kstDataRange->setAllowTime(KstDataSource::supportsTime(u, type));
  }

  _w->_configure->setEnabled(_configWidget);

// xxx  _fieldCompletion = _w->_field->completionObject();

  _w->_field->insertItems(0, list);
/* xxx
  if (_fieldCompletion) {
    _fieldCompletion->clear();
    _fieldCompletion->insertItems(list);
  }
*/

  if (!current_text.isEmpty() && (list.contains(current_text) || _w->_field->isEditable())) {
    _w->_field->setItemText(_w->_field->currentIndex(), current_text);
  }

  _ok->setEnabled(_w->_field->isEnabled() || _editMultipleMode);
}
Example #23
0
bool KstMatrixDialogI::new_IRMatrix() {
  //check the parameters
  int xStart = _w->_xStartCountFromEnd->isChecked() ? -1 : _w->_xStart->value();
  int yStart = _w->_yStartCountFromEnd->isChecked() ? -1 : _w->_yStart->value();
  int xNumSteps = _w->_xNumStepsReadToEnd->isChecked() ? -1 : _w->_xNumSteps->value();
  int yNumSteps = _w->_yNumStepsReadToEnd->isChecked() ? -1 : _w->_yNumSteps->value();

  //create a unique name
  QString tag_name = (_tagName->text() == "<New_Matrix>") ? KST::suggestMatrixName(_w->_field->currentText()) : _tagName->text();
  if (KstData::self()->matrixTagNameNotUnique(tag_name)) {
    _tagName->setFocus();
    return false;
  }

  // get the data source and matrix field from datasource
  KstDataSourcePtr file;
  QString pField;

  /* if there is not an active KstFile, create one */
  KST::dataSourceList.lock().writeLock();
  KstDataSourceList::Iterator it = KST::dataSourceList.findReusableFileName(_w->_fileName->url());

  if (it == KST::dataSourceList.end()) {
    file = KstDataSource::loadSource(_w->_fileName->url());
    if (!file || !file->isValid()) {
      KST::dataSourceList.lock().unlock();
      KMessageBox::sorry(this, i18n("The file could not be opened."));
      return false;
    }
    if (file->isEmpty()) {
      KST::dataSourceList.lock().unlock();
      KMessageBox::sorry(this, i18n("The file does not contain data."));
      return false;
    }
    KST::dataSourceList.append(file);
  } else {
    file = *it;
  }
  KST::dataSourceList.lock().unlock();

  pField = _w->_field->currentText();
  if (!file->isValidMatrix(pField)) {
    KMessageBox::sorry(this, i18n("The requested matrix is not defined for the requested file."));
    file->unlock();
    return false;
  }

  // skipping parameters
  bool doSkip = _w->_doSkip->isChecked();
  bool doAve = _w->_doAve->isChecked();
  int skip = _w->_skip->value();

  KstRMatrixPtr matrix = new KstRMatrix(file, pField, tag_name,
                                        xStart, yStart, xNumSteps, yNumSteps,
                                        doAve, doSkip, skip);

  KST::addMatrixToList(KstMatrixPtr(matrix));
  emit matrixCreated(KstMatrixPtr(matrix));
  matrix = 0L; // drop the reference
  emit modified();

  return true;
}