void KstMatrixDefaults::sync() { KstRMatrixList::iterator it; KstRMatrixList rmatrixList; KstRMatrixPtr rmatrix; KST::matrixList.lock().readLock(); rmatrixList = kstObjectSubList<KstMatrix,KstRMatrix>(KST::matrixList); KST::matrixList.lock().unlock(); // // find a non-stdin source... // for (it=rmatrixList.begin(); it!=rmatrixList.end(); ++it) { KstDataSourcePtr dsp; rmatrix = *it; rmatrix->readLock(); dsp = rmatrix->dataSource(); rmatrix->unlock(); if (dsp && !kst_cast<KstStdinSource>(dsp)) { break; } } if (it != rmatrixList.end()) { rmatrix->readLock(); _dataSource = rmatrix->filename(); _xStart = rmatrix->reqXStart(); _yStart = rmatrix->reqYStart(); _xNumSteps = rmatrix->reqXNumSteps(); _yNumSteps = rmatrix->reqYNumSteps(); _skip = rmatrix->skip(); _doAve = rmatrix->doAverage(); _doSkip = rmatrix->doSkip(); rmatrix->unlock(); } }
void KstDataManagerI::update() { if (!isShown()) { return; } QListViewItem *currentItem = DataView->selectedItem(); QPtrStack<QListViewItem> trash; KST::dataObjectList.lock().writeLock(); KST::vectorList.lock().writeLock(); KST::matrixList.lock().writeLock(); // garbage collect first for (QListViewItem *i = DataView->firstChild(); i; i = i->nextSibling()) { KstObjectItem *oi = static_cast<KstObjectItem*>(i); if (i->rtti() == RTTI_OBJ_OBJECT) { if (KST::dataObjectList.findTag(oi->tag().tag()) == KST::dataObjectList.end()) { trash.push(i); } } else if (i->rtti() == RTTI_OBJ_DATA_MATRIX || i->rtti() == RTTI_OBJ_MATRIX || i->rtti() == RTTI_OBJ_STATIC_MATRIX) { if (KST::matrixList.findTag(oi->tag().tag()) == KST::matrixList.end()) { trash.push(i); } } else { if (KST::vectorList.findTag(oi->tag().tag()) == KST::vectorList.end()) { trash.push(i); } } } trash.setAutoDelete(true); DataView->blockSignals(true); trash.clear(); DataView->blockSignals(false); // update the data objects for (KstDataObjectList::iterator it = KST::dataObjectList.begin(); it != KST::dataObjectList.end(); ++it) { KstReadLocker dol(*it); bool found = false; for (QListViewItem *i = DataView->firstChild(); i; i = i->nextSibling()) { KstObjectItem *oi = static_cast<KstObjectItem*>(i); if (oi->rtti() == RTTI_OBJ_OBJECT && oi->tag().tag() == (*it)->tag().tag()) { oi->update(); found = true; break; } } if (!found) { KstObjectItem *i = new KstObjectItem(DataView, *it, this); connect(i, SIGNAL(updated()), this, SLOT(doUpdates())); } } KST::dataObjectList.lock().unlock(); // update the data vectors KstRVectorList rvl = kstObjectSubList<KstVector,KstRVector>(KST::vectorList); for (KstRVectorList::iterator it = rvl.begin(); it != rvl.end(); ++it) { KstReadLocker vl(*it); bool found = false; for (QListViewItem *i = DataView->firstChild(); i; i = i->nextSibling()) { KstObjectItem *oi = static_cast<KstObjectItem*>(i); if (oi->rtti() == RTTI_OBJ_DATA_VECTOR && oi->tag().tag() == (*it)->tag().tag()) { oi->update(true, 1); found = true; break; } } if (!found) { KstObjectItem *i = new KstObjectItem(DataView, *it, this, 1); connect(i, SIGNAL(updated()), this, SLOT(doUpdates())); } } // update the static vectors KstSVectorList svl = kstObjectSubList<KstVector,KstSVector>(KST::vectorList); for (KstSVectorList::iterator it = svl.begin(); it != svl.end(); ++it) { KstReadLocker vl(*it); bool found = false; for (QListViewItem *i = DataView->firstChild(); i; i = i->nextSibling()) { KstObjectItem *oi = static_cast<KstObjectItem*>(i); if (oi->rtti() == RTTI_OBJ_STATIC_VECTOR && oi->tag().tag() == (*it)->tag().tag()) { oi->update(true, 1); found = true; break; } } if (!found) { KstObjectItem *i = new KstObjectItem(DataView, *it, this, 1); connect(i, SIGNAL(updated()), this, SLOT(doUpdates())); } } KST::vectorList.lock().unlock(); // update the data matrices KstRMatrixList rml = kstObjectSubList<KstMatrix,KstRMatrix>(KST::matrixList); for (KstRMatrixList::iterator it = rml.begin(); it != rml.end(); ++it) { KstReadLocker ml(*it); bool found = false; for (QListViewItem *i = DataView->firstChild(); i; i = i->nextSibling()) { KstObjectItem *oi = static_cast<KstObjectItem*>(i); if (oi->rtti() == RTTI_OBJ_DATA_MATRIX && oi->tag().tag() == (*it)->tag().tag()) { oi->update(true, 1); found = true; break; } } if (!found) { KstObjectItem *i = new KstObjectItem(DataView, *it, this, 1); connect(i, SIGNAL(updated()), this, SLOT(doUpdates())); } } // update the static matrices KstSMatrixList sml = kstObjectSubList<KstMatrix,KstSMatrix>(KST::matrixList); for (KstSMatrixList::iterator it = sml.begin(); it != sml.end(); ++it) { KstReadLocker ml(*it); bool found = false; for (QListViewItem *i = DataView->firstChild(); i; i = i->nextSibling()) { KstObjectItem *oi = static_cast<KstObjectItem*>(i); if (oi->rtti() == RTTI_OBJ_STATIC_MATRIX && oi->tag().tag() == (*it)->tag().tag()) { oi->update(true, 1); found = true; break; } } if (!found) { KstObjectItem *i = new KstObjectItem(DataView, *it, this, 1); connect(i, SIGNAL(updated()), this, SLOT(doUpdates())); } } KST::matrixList.lock().unlock(); // is this really necessary? I would think not... for (QListViewItem *i = DataView->firstChild(); i; i = i->nextSibling()) { if (i == currentItem) { DataView->setCurrentItem(i); DataView->setSelected(i, true); break; } } if (DataView->selectedItem()) { static_cast<KstObjectItem*>(DataView->currentItem())->updateButtons(); } else { Edit->setEnabled(false); Delete->setEnabled(false); } }