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()));
}
Example #2
0
void KstObjectItem::showMetadata() {
  if (_rtti == RTTI_OBJ_DATA_VECTOR) {
    DataSourceMetaDataDialog *dlg = new DataSourceMetaDataDialog(_dm, 0, false, WDestructiveClose);
    KstReadLocker vl(&KST::vectorList.lock());
    KstVectorList::Iterator m = KST::vectorList.findTag(_tag);
    KstRVectorPtr r = kst_cast<KstRVector>(*m);
    KstDataSourcePtr dsp;
    if (r) {
      r->readLock();
      dsp = r->dataSource();
      r->unlock();
    }
    dlg->setDataSource(dsp);
    dlg->show();
  } else if (_rtti == RTTI_OBJ_DATA_MATRIX) {
    DataSourceMetaDataDialog *dlg = new DataSourceMetaDataDialog(_dm, 0, false, WDestructiveClose);
    KstReadLocker ml(&KST::matrixList.lock());
    KstMatrixList::Iterator m = KST::matrixList.findTag(_tag);
    KstRMatrixPtr r = kst_cast<KstRMatrix>(*m);
    KstDataSourcePtr dsp;
    if (r) {
      r->readLock();
      dsp = r->dataSource();
      r->unlock();
    }
    dlg->setDataSource(dsp);
    dlg->show();
  }
}
Example #3
0
void KstObjectItem::reload() {
  if (_rtti == RTTI_OBJ_DATA_VECTOR) {
    KstReadLocker ml(&KST::vectorList.lock());
    KstVectorList::Iterator v = KST::vectorList.findTag(_tag);
    if (v != KST::vectorList.end()) {
      KstRVectorPtr r = kst_cast<KstRVector>(*v);
      if (r) {
        r->writeLock();
        r->reload();
        r->unlock();
      }
    }
  } else if (_rtti == RTTI_OBJ_DATA_MATRIX) {
    KstReadLocker ml(&KST::matrixList.lock());
    KstMatrixList::Iterator m = KST::matrixList.findTag(_tag);
    if (m != KST::matrixList.end()) {
      KstRMatrixPtr r = kst_cast<KstRMatrix>(*m);
      if (r) {
        r->writeLock();
        r->reload();
        r->unlock();
      }
    }
  }
}
bool KstChangeNptsDialogI::updateChangeNptsDialog() {
  QStringList qsl;
  int inserted = 0;

  for (uint i_vector = 0; i_vector < CurveList->count(); i_vector++) {
    if (CurveList->isSelected(i_vector)) {
      qsl.append(CurveList->text(i_vector));
    }
  }
  CurveList->clear();

  KstRVectorList rvl = kstObjectSubList<KstVector,KstRVector>(KST::vectorList);
  // insert vectors into ChangeNptsCurveList
  CurveList->blockSignals(true); // avoid deadlock
  for (KstRVectorList::ConstIterator i = rvl.begin(); i != rvl.end(); ++i) {
    KstRVectorPtr vector = *i;
    vector->readLock();
    QString tag = vector->tag().displayString();
    CurveList->insertItem(tag, -1);
    if (qsl.contains(tag)) {
      CurveList->setSelected(inserted, true);
    }
    ++inserted;
    vector->unlock();
  }
  CurveList->blockSignals(false);

  return !qsl.isEmpty();
}
void KstChangeNptsDialogI::updateDefaults(int index) {
  KstRVectorList rvl = kstObjectSubList<KstVector,KstRVector>(KST::vectorList);
  if (rvl.isEmpty() || index >= (int)rvl.count() || index < 0) {
    return;
  }

  KstRVectorPtr vector = rvl[index];
  vector->readLock();

  disconnect(_kstDataRange, SIGNAL(changed()), this, SLOT(modifiedRange()));

  _kstDataRange->_startUnits->setCurrentItem(0);
  _kstDataRange->_rangeUnits->setCurrentItem(0);

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

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

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

  connect(_kstDataRange, SIGNAL(changed()), this, SLOT(modifiedRange()));

  vector->unlock();
}
Example #6
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;
}
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 #8
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;
}
Example #10
0
void KstObjectItem::update(bool recursive, int localUseCount) {
  switch (_rtti) {
    case RTTI_OBJ_DATA_VECTOR:
    {
      KST::vectorList.lock().readLock();
      KstRVectorPtr x = kst_cast<KstRVector>(*KST::vectorList.findTag(_tag));
      KST::vectorList.lock().unlock();
      if (x) {
        x->readLock();
        // getUsage: subtract 1 for KstRVectorPtr x
        bool inUse = (x->getUsage() - 1 - localUseCount) > 0;
        if (inUse != _inUse) {
          _inUse = inUse;
          setPixmap(2, inUse ? _dm->yesPixmap() : QPixmap());
        }
        QString field;
        if (inUse) {
          field = QString::number(x->length());
        } else {
          field = "-";
        }
        if (text(3) != field) {
          setText(3, field);
        }
        field = i18n("%3: %4 [%1..%2]").arg(x->reqStartFrame())
            .arg(x->reqStartFrame() + x->reqNumFrames())
            .arg(x->filename())
            .arg(x->field());
        if (text(4) != field) {
          setText(4, field);
        }
        _removable = x->getUsage() == 2;
        x->unlock();
      }
      // Hmmm what happens if this if() fails??  We become inconsistent?
      break;
    }
    case RTTI_OBJ_STATIC_VECTOR:
    {
      KST::vectorList.lock().readLock();
      KstSVectorPtr x = kst_cast<KstSVector>(*KST::vectorList.findTag(_tag));
      KST::vectorList.lock().unlock();
      if (x) {
        x->readLock();
        // getUsage: subtract 1 for KstRVectorPtr x
        bool inUse = (x->getUsage() - 1 - localUseCount) > 0;
        if (inUse != _inUse) {
          _inUse = inUse;
          setPixmap(2, inUse ? _dm->yesPixmap() : QPixmap());
        }
        QString field;
        if (inUse) {
          field = QString::number(x->length());
        } else {
          field = "-";
        }
        if (text(3) != field) {
          setText(3, field);
        }
        field = i18n("%1 to %2").arg(x->min()).arg(x->max());
        if (text(4) != field) {
          setText(4, field);
        }
        _removable = x->getUsage() == 2;
        x->unlock();
      }
      // Hmmm what happens if this if() fails??  We become inconsistent?
      break;
    }
    case RTTI_OBJ_VECTOR:
    {
      KST::vectorList.lock().readLock();
      KstVectorPtr x = *KST::vectorList.findTag(_tag);
      KST::vectorList.lock().unlock();
      if (x) {
        x->readLock();
        // getUsage:
        //  subtract 1 for KstVectorPtr x
        bool inUse = (x->getUsage() - 1 - localUseCount) > 0;
        if (inUse != _inUse) {
          _inUse = inUse;
          setPixmap(2, inUse ? _dm->yesPixmap() : QPixmap());
        }
        QString field = QString::number(x->length());
        if (text(3) != field) {
          setText(3, field);
        }
        field = i18n("[%1..%2]").arg(x->min()).arg(x->max());
        if (text(4) != field) {
          setText(4, field);
        }
        x->unlock();
        _removable = false;
      }
      break;
    }
    case RTTI_OBJ_OBJECT:
    {
      KST::dataObjectList.lock().readLock();
      KstDataObjectPtr x = *KST::dataObjectList.findTag(_tag.tag());
      KST::dataObjectList.lock().unlock();
      if (x) {
        x->readLock();
        QString field = x->typeString();
        if (text(1) != field) {
          setText(1, field);
        }
        // getUsage:
        //  subtract 1 for KstDataObjectPtr x
        bool inUse = (x->getUsage() - 1 - localUseCount) > 0;
        if (inUse != _inUse) {
          _inUse = inUse;
          setPixmap(2, inUse ? _dm->yesPixmap() : QPixmap());
        }
        if (x->sampleCount() > 0) {
          field = QString::number(x->sampleCount());
          if (text(3) != field) {
            setText(3, field);
          }
        } else {
          if (text(3) != "-") {
            setText(3, "-");
          }          
        }
        field = x->propertyString();
        if (text(4) != field) {
          setText(4, field);
        }
        if (recursive) {
          QPtrStack<QListViewItem> trash;
          KstVectorMap vl = x->outputVectors();
          KstVectorMap::Iterator vlEnd = vl.end();

          for (QListViewItem *i = firstChild(); i; i = i->nextSibling()) {
            KstObjectItem *oi = static_cast<KstObjectItem*>(i);
            if (vl.findTag(oi->tag().tag()) == vlEnd) {
              trash.push(i);
            }
          }
          trash.setAutoDelete(true);
          trash.clear();

          // get the output vectors
          for (KstVectorMap::Iterator p = vl.begin(); p != vlEnd; ++p) {
            bool found = false;
            QString tn = p.data()->tag().tag();
            for (QListViewItem *i = firstChild(); i; i = i->nextSibling()) {
              KstObjectItem *oi = static_cast<KstObjectItem*>(i);
              if (oi->tag().tag() == tn) {
                oi->update();
                found = true;
                break;
              }
            }
            if (!found) {
              KstObjectItem *item = new KstObjectItem(this, p.data(), _dm);
              connect(item, SIGNAL(updated()), this, SIGNAL(updated()));
            }
          }
          
          KstMatrixMap ml = x->outputMatrices();
          KstMatrixMap::Iterator mlEnd = ml.end();
          // also get the output matrices
          for (KstMatrixMap::Iterator p = ml.begin(); p != mlEnd; ++p) {
            bool found = false;
            QString tn = p.data()->tag().tag();
            for (QListViewItem *i = firstChild(); i; i = i->nextSibling()) {
              KstObjectItem *oi = static_cast<KstObjectItem*>(i);
              if (oi->tag().tag() == tn) {
                oi->update();
                found = true;
                break;
              }
            }
            if (!found) {
              KstObjectItem *item = new KstObjectItem(this, p.data(), _dm);
              connect(item, SIGNAL(updated()), this, SIGNAL(updated()));
            }
          }
        }
        _removable = x->getUsage() == 1;
        x->unlock();
      }
      break;
    }
    case RTTI_OBJ_DATA_MATRIX:
    {
      KST::matrixList.lock().readLock();
      KstRMatrixPtr x = kst_cast<KstRMatrix>(*KST::matrixList.findTag(_tag));
      KST::matrixList.lock().unlock();
      if (x) {
        x->readLock();
          // getUsage: subtract 1 for KstRMatrixPtr x
        bool inUse = (x->getUsage() - 1 - localUseCount) > 0;
        if (inUse != _inUse) {
          _inUse = inUse;
          setPixmap(2, inUse ? _dm->yesPixmap() : QPixmap());
        }
        QString field = QString::number(x->sampleCount());
        if (text(3) != field) {
          setText(3, field);
        }
        field = i18n("%1: %2 (%3 by %4)").arg(x->filename()).arg(x->field())
                .arg(x->xNumSteps())
                .arg(x->yNumSteps()); 
        if (text(4) != field) {
          setText(4, field);
        }
        _removable = x->getUsage() == 2;
        x->unlock();
      } 
      break;
    }
    case RTTI_OBJ_STATIC_MATRIX:
    {
      KST::matrixList.lock().readLock();
      KstSMatrixPtr x = kst_cast<KstSMatrix>(*KST::matrixList.findTag(_tag));
      KST::matrixList.lock().unlock();
      if (x) {
        x->readLock();
          // getUsage: subtract 1 for KstRMatrixPtr x
        bool inUse = (x->getUsage() - 1 - localUseCount) > 0;
        if (inUse != _inUse) {
          _inUse = inUse;
          setPixmap(2, inUse ? _dm->yesPixmap() : QPixmap());
        }
        QString field = QString::number(x->sampleCount());
        if (text(3) != field) {
          setText(3, field);
        }
        field = i18n("%1 to %2").arg(x->gradZMin()).arg(x->gradZMax());
        if (text(4) != field) {
          setText(4, field);
        }
        _removable = x->getUsage() == 2;
        x->unlock();
      }
      break;
    }
    case RTTI_OBJ_MATRIX:
    {
      KST::matrixList.lock().readLock();
      KstMatrixPtr x = *KST::matrixList.findTag(_tag);
      KST::matrixList.lock().unlock();
      if (x) {
        x->readLock();
          // getUsage:
          //  subtract 1 for KstVectorPtr x
        bool inUse = (x->getUsage() - 1 - localUseCount) > 0;
        if (inUse != _inUse) {
          _inUse = inUse;
          setPixmap(2, inUse ? _dm->yesPixmap() : QPixmap());
        }
        QString field = QString::number(x->sampleCount());
        if (text(3) != field) {
          setText(3, field);
        }
        field = i18n("[%1..%2]").arg(x->minValue()).arg(x->maxValue());
        if (text(4) != field) {
          setText(4, field);
        }
        x->unlock();
        _removable = false;
      }
      break;
    }
    default:
      assert(0);
  }
}
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;
}
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();
}