示例#1
0
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();
    QMap<QString,QString> data = s->metaData();
    s->readUnlock();
    for (QMap<QString,QString>::ConstIterator i = data.begin(); i != data.end(); ++i) {
      array.put(exec, KJS::Identifier(i.key().latin1()), KJS::String(i.data()));
    }
  }
  return array;
}
示例#2
0
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->readUnlock();
  for (QStringList::ConstIterator i = l.begin(); i != l.end(); ++i) {
    rc.append(KJS::String(*i));
  }

  return KJS::Object(exec->interpreter()->builtinArray().construct(exec, rc));
}
示例#3
0
void KstVectorDialogI::updateCompletion() {
  QString current_text = Field->currentText();
  Field->clear();

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

  delete _configWidget; // FIXME: very inefficient!!!!
  _configWidget = 0L;
  QStringList list;
  if (ds) {
    ds->readLock();
    list = ds->fieldList();
    Field->setEditable(!ds->fieldListIsComplete());
    _configWidget = ds->configWidget();
    ds->readUnlock();
  } else {
    QString type;
    bool complete = false;
    list = KstDataSource::fieldListForSource(FileName->url(), QString::null, &type, &complete);
    Field->setEditable(!complete);
    if (!list.isEmpty() && !type.isEmpty()) {
      _configWidget = KstDataSource::configWidgetForSource(FileName->url(), type);
    }
  }

  _configure->setEnabled(_configWidget);

  _fieldCompletion = Field->completionObject();

  Field->insertStringList(list);
  if (_fieldCompletion) {
    _fieldCompletion->clear();
    _fieldCompletion->insertItems(list);
  }
  if (!current_text.isEmpty() && (list.contains(current_text) || Field->editable())) {
    Field->setCurrentText(current_text);
  }
  _kstDataRange->setAllowTime(ds && ds->supportsTimeConversions());
}
示例#4
0
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().writeUnlock();
          KMessageBox::sorry(this, i18n("The file could not be loaded."));
          return false;
        }
        if (file->isEmpty()) {
          KST::dataSourceList.lock().writeUnlock();
          KMessageBox::sorry(this, i18n("The file does not contain data."));
          return false;
        }
        KST::dataSourceList.append(file);
      } else {
        file = *it;
      }
      KST::dataSourceList.lock().writeUnlock();
    }
    file->readLock();
    if (!file->isValidField(_w->Field->currentText())) {
      file->readUnlock();
      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->readUnlock();
        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->readUnlock();

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

    KST::addVectorToList(KstVectorPtr(vector));

    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, tagname);
    KST::addVectorToList(KstVectorPtr(svector));
    emit vectorCreated(KstVectorPtr(svector));
    svector = 0L;
    emit modified();
  }

  return true;
}
示例#5
0
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());

  /* fill the fields */
  _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->readUnlock();
    } else {
      QStringList list = KstDataSource::fieldListForSource(_w->FileName->url());
      _w->Field->insertStringList(list);
      if (_fieldCompletion) {
        _fieldCompletion->insertItems(list);
      }
    }
    KST::dataSourceList.lock().readUnlock();
  }
  _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->readUnlock();
}
示例#6
0
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().readUnlock();

  delete _configWidget;
  _configWidget = 0L;
  QStringList list;
  if (ds) {
    ds->readLock();
    list = ds->fieldList();
    _w->Field->setEditable(!ds->fieldListIsComplete());
    _configWidget = ds->configWidget();
    ds->readUnlock();
    _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);
}
示例#7
0
bool KstVectorDialogI::edit_I() {
  KstDataSourcePtr file;

  KstRVectorList vectorList = kstObjectSubList<KstVector,KstRVector>(KST::vectorList);

  /* verify that the vector name is unique */
  DP->readLock();
  if (_tagName->text() != DP->tagName() && KST::vectorTagNameNotUnique(_tagName->text())) {
    DP->readUnlock();
    return false;
  }
  DP->readUnlock();

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

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

  int f0, n;
  if (_kstDataRange->isTime()) {
    file->readLock();
    f0 = file->sampleForTime(_kstDataRange->f0Value());
    n = file->sampleForTime(_kstDataRange->nValue());
    file->readUnlock();
  } else {
    f0 = _kstDataRange->f0Value();
    n = _kstDataRange->nValue();
  }
  /* change the vector */
  DP->writeLock();
  DP->change(file, Field->currentText(),
             _tagName->text(),
             (_kstDataRange->CountFromEnd->isChecked() ?  -1 : f0),
             (_kstDataRange->ReadToEnd->isChecked() ?  -1 : n),
             _kstDataRange->Skip->value(),
             _kstDataRange->DoSkip->isChecked(),
             _kstDataRange->DoFilter->isChecked());
  DP->writeUnlock();

  vectorList.clear();
  emit modified();
  return true;
}
示例#8
0
bool KstVectorDialogI::new_I() {
  KstDataSourcePtr file;
  KstRVectorList vectorList = kstObjectSubList<KstVector,KstRVector>(KST::vectorList);
  QString tag_name = _tagName->text();

  tag_name.replace("<New_Vector>", Field->currentText());

  KST::vectorList.lock().readLock();
  int i_c = KST::vectorList.count() + 1;
  KST::vectorList.lock().readUnlock();
  while (KST::vectorTagNameNotUnique(tag_name, false)) {
    tag_name.sprintf("V%d-", i_c);
    tag_name += Field->currentText();
    i_c++;
  }
  vectorList.clear();

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

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

  int f0, n;
  if (_kstDataRange->isTime()) {
    file->readLock();
    f0 = file->sampleForTime(_kstDataRange->f0Value());
    n = file->sampleForTime(_kstDataRange->nValue());
    file->readUnlock();
  } else {
    f0 = _kstDataRange->f0Value();
    n = _kstDataRange->nValue();
  }
  /* create the vector */
  KstRVectorPtr vector = new KstRVector(
    file, Field->currentText(),
    tag_name,
    (_kstDataRange->CountFromEnd->isChecked() ? -1 : f0),
    (_kstDataRange->ReadToEnd->isChecked() ? -1 : n),
    _kstDataRange->Skip->value(),
    _kstDataRange->DoSkip->isChecked(),
    _kstDataRange->DoFilter->isChecked());

  KST::addVectorToList(KstVectorPtr(vector));

  emit vectorCreated(KstVectorPtr(vector));
  vector = 0L;
  emit modified();

  return true;
}
示例#9
0
void KstVectorDialogI::_fillFieldsForEdit() {
  if (DP == 0L) {
    return; // shouldn't be needed
  }

  DP->readLock();

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

  /* fill the fields */
  Field->clear();
  if (_fieldCompletion) {
    _fieldCompletion->clear();
  }
  {
    KstDataSourcePtr tf;
    KST::dataSourceList.lock().readLock();
    KstDataSourceList::Iterator it = KST::dataSourceList.findFileName(DP->filename());
    if (it != KST::dataSourceList.end()) {
      tf = *it;
      tf->readLock();
      Field->insertStringList(tf->fieldList());
      if (_fieldCompletion) {
        _fieldCompletion->insertItems(tf->fieldList());
      }
      tf->readUnlock();
    } else {
      QStringList list = KstDataSource::fieldListForSource(FileName->url());
      Field->insertStringList(list);
      if (_fieldCompletion) {
        _fieldCompletion->insertItems(list);
      }
    }
    KST::dataSourceList.lock().readUnlock();
  }
  Field->setCurrentText(DP->field());

  /* select the proper file */
  FileName->setURL(DP->filename());

  /* fill the vector range entries */
  if (DP->countFromEOF()) {
    _kstDataRange->CountFromEnd->setChecked(true);
  } else {
    _kstDataRange->CountFromEnd->setChecked(false);
  }
  _kstDataRange->setF0Value(DP->reqStartFrame());

  /* fill number of frames entries */
  if (DP->readToEOF()) {
    _kstDataRange->ReadToEnd->setChecked(true);
  } else {
    _kstDataRange->ReadToEnd->setChecked(false);
  }
  _kstDataRange->setNValue(DP->reqNumFrames());

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

  DP->readUnlock();
}