void KstDataManagerI::delete_I() { QListViewItem *qi = DataView->selectedItems().at(0); KstObjectItem *koi = static_cast<KstObjectItem*>(qi); if (qi->rtti() == RTTI_OBJ_OBJECT) { doc->removeDataObject(koi->tagName()); } else if (qi->rtti() == RTTI_OBJ_DATA_VECTOR) { KST::vectorList.removeTag(koi->tagName()); doUpdates(); } }
void KstDataManagerI::delete_I() { QListViewItem *qi = DataView->selectedItems().at(0); KstObjectItem *koi = static_cast<KstObjectItem*>(qi); if (koi->removable()) { if (qi->rtti() == RTTI_OBJ_OBJECT) { doc->removeDataObject(koi->tagName()); } else if (qi->rtti() == RTTI_OBJ_DATA_VECTOR) { KST::vectorList.lock().writeLock(); KST::vectorList.removeTag(koi->tagName()); KST::vectorList.lock().unlock(); doUpdates(); } else if (qi->rtti() == RTTI_OBJ_STATIC_VECTOR) { KST::vectorList.lock().writeLock(); KST::vectorList.removeTag(koi->tagName()); KST::vectorList.lock().unlock(); doUpdates(); } else if (qi->rtti() == RTTI_OBJ_DATA_MATRIX) { KST::matrixList.lock().writeLock(); KST::matrixList.removeTag(koi->tagName()); KST::matrixList.lock().unlock(); } else if (qi->rtti() == RTTI_OBJ_STATIC_MATRIX) { KST::matrixList.lock().writeLock(); KST::matrixList.removeTag(koi->tagName()); KST::matrixList.lock().unlock(); } update(); } else { // Don't prompt for base curves KstBaseCurvePtr bc = kst_cast<KstBaseCurve>(koi->dataObject()); if (bc || KMessageBox::warningYesNo(this, i18n("There are other objects in memory that depend on %1. Do you wish to delete them too?").arg(koi->tagName())) == KMessageBox::Yes) { if (qi->rtti() == RTTI_OBJ_OBJECT) { koi->dataObject()->deleteDependents(); doc->removeDataObject(koi->tagName()); } else if (qi->rtti() == RTTI_OBJ_DATA_VECTOR) { KstRVectorPtr x = kst_cast<KstRVector>(*KST::vectorList.findTag(koi->tagName())); if (x) { x->deleteDependents(); x = 0L; KST::vectorList.lock().writeLock(); KST::vectorList.removeTag(koi->tagName()); KST::vectorList.lock().unlock(); doUpdates(); } else { KMessageBox::sorry(this, i18n("Unknown error deleting data vector.")); } } else if (qi->rtti() == RTTI_OBJ_STATIC_VECTOR) { KstSVectorPtr x = kst_cast<KstSVector>(*KST::vectorList.findTag(koi->tagName())); if (x) { x->deleteDependents(); x = 0L; KST::vectorList.lock().writeLock(); KST::vectorList.removeTag(koi->tagName()); KST::vectorList.lock().unlock(); doUpdates(); } else { KMessageBox::sorry(this, i18n("Unknown error deleting static vector.")); } } else if (qi->rtti() == RTTI_OBJ_DATA_MATRIX) { KstRMatrixPtr x = kst_cast<KstRMatrix>(*KST::matrixList.findTag(koi->tagName())); if (x) { x->deleteDependents(); x = 0L; KST::matrixList.lock().writeLock(); KST::matrixList.removeTag(koi->tagName()); KST::matrixList.lock().unlock(); doUpdates(); } else { KMessageBox::sorry(this, i18n("Unknown error deleting data matrix.")); } } else if (qi->rtti() == RTTI_OBJ_STATIC_MATRIX) { KstSMatrixPtr x = kst_cast<KstSMatrix>(*KST::matrixList.findTag(koi->tagName())); if (x) { x->deleteDependents(); x = 0L; KST::matrixList.lock().writeLock(); KST::matrixList.removeTag(koi->tagName()); KST::matrixList.lock().unlock(); doUpdates(); } else { KMessageBox::sorry(this, i18n("Unknown error deleting static matrix.")); } } KstApp::inst()->paintAll(KstPainter::P_PLOT); update(); } else { KMessageBox::sorry(this, i18n("Cannot delete objects with dependencies.")); } } }
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->tagName()) == 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->tagName()) == KST::matrixList.end()) { trash.push(i); } } else { if (KST::vectorList.findTag(oi->tagName()) == 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) { 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->tagName() == (*it)->tagName()) { oi->update(); found = true; break; } } if (!found) { KstObjectItem *i = new KstObjectItem(DataView, *it, this); connect(i, SIGNAL(updated()), this, SLOT(doUpdates())); } } KST::matrixList.lock().unlock(); KST::vectorList.lock().unlock(); 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) { 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->tagName() == (*it)->tagName()) { 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) { 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->tagName() == (*it)->tagName()) { 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 data matrices KstRMatrixList rml = kstObjectSubList<KstMatrix,KstRMatrix>(KST::matrixList); for (KstRMatrixList::iterator it = rml.begin(); it != rml.end(); ++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->tagName() == (*it)->tagName()) { 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) { 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->tagName() == (*it)->tagName()) { oi->update(true, 1); found = true; break; } } if (!found) { KstObjectItem *i = new KstObjectItem(DataView, *it, this, 1); connect(i, SIGNAL(updated()), this, SLOT(doUpdates())); } } // 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); } }
void KstObjectItem::update(bool recursive, int localUseCount) { switch (_rtti) { case RTTI_OBJ_DATA_VECTOR: { KstRVectorPtr x = kst_cast<KstRVector>(*KST::vectorList.findTag(_name)); 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: { KstSVectorPtr x = kst_cast<KstSVector>(*KST::vectorList.findTag(_name)); 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: { KstVectorPtr x = *KST::vectorList.findTag(_name); 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: { KstDataObjectPtr x = *KST::dataObjectList.findTag(_name); 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->tagName()) == 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()->tagName(); for (QListViewItem *i = firstChild(); i; i = i->nextSibling()) { KstObjectItem *oi = static_cast<KstObjectItem*>(i); if (oi->tagName() == 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()->tagName(); for (QListViewItem *i = firstChild(); i; i = i->nextSibling()) { KstObjectItem *oi = static_cast<KstObjectItem*>(i); if (oi->tagName() == 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: { KstRMatrixPtr x = kst_cast<KstRMatrix>(*KST::matrixList.findTag(_name)); 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: { KstSMatrixPtr x = kst_cast<KstSMatrix>(*KST::matrixList.findTag(_name)); 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: { KstMatrixPtr x = *KST::matrixList.findTag(_name); 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); } }
void KstObjectItem::update(bool recursive) { switch (_rtti) { case RTTI_OBJ_DATA_VECTOR: { KstVectorPtr px = *KST::vectorList.findTag(_name); assert(px.data()); assert(dynamic_cast<KstRVector*>(px.data())); KstRVectorPtr x = static_cast<KstRVector*>(px.data()); setText(2, QString::number(x->getUsage() - 3)); // caller has a ptr setText(3, QString::number(x->sampleCount())); setText(4, i18n("%3: %4 [%1..%2]").arg(x->reqStartFrame()) .arg(x->reqStartFrame() + x->reqNumFrames()) .arg(x->getFilename()) .arg(x->getField())); _removable = x->getUsage() == 3; break; } case RTTI_OBJ_VECTOR: { KstVectorPtr x = *KST::vectorList.findTag(_name); assert(x.data()); setText(2, QString::number(x->getUsage() - 2)); //caller also points setText(3, QString::number(x->sampleCount())); setText(4, i18n("[%1..%2]").arg(x->min()).arg(x->max())); _removable = false; break; } case RTTI_OBJ_OBJECT: { KstDataObjectPtr x = *KST::dataObjectList.findTag(_name); assert(x.data()); setText(1, x->typeString()); setText(2, QString::number(x->getUsage() - 1)); // our pointer setText(3, QString::number(x->sampleCount())); setText(4, x->propertyString()); if (recursive) { QPtrStack<QListViewItem> trash; for (QListViewItem *i = firstChild(); i; i = i->nextSibling()) { KstObjectItem *oi = static_cast<KstObjectItem*>(i); if (x->outputVectors().findTag(oi->tagName()) == x->outputVectors().end()) { trash.push(i); } } trash.setAutoDelete(true); trash.clear(); for (KstVectorMap::Iterator p = x->outputVectors().begin(); p != x->outputVectors().end(); ++p) { bool found = false; for (QListViewItem *i = firstChild(); i; i = i->nextSibling()) { KstObjectItem *oi = static_cast<KstObjectItem*>(i); if (oi->tagName() == p.data()->tagName()) { oi->update(); found = true; break; } } if (!found) { new KstObjectItem(this, p.data(), _dm); } } } _removable = x->getUsage() == 1; break; } default: assert(0); } }
void KstDataManagerI::update() { if (!isShown()) { return; } QPtrStack<QListViewItem> trash; // 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->tagName()) == KST::dataObjectList.end()) { trash.push(i); } } else { if (KST::vectorList.findTag(oi->tagName()) == KST::vectorList.end()) { trash.push(i); } } } trash.setAutoDelete(true); trash.clear(); for (KstDataObjectList::iterator it = KST::dataObjectList.begin(); it != KST::dataObjectList.end(); ++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->tagName() == (*it)->tagName()) { oi->update(); found = true; break; } } if (!found) { KstObjectItem *i = new KstObjectItem(DataView, *it, this); connect(i, SIGNAL(updated()), this, SLOT(doUpdates())); } } KstRVectorList rvl = kstObjectSubList<KstVector,KstRVector>(KST::vectorList); for (KstRVectorList::iterator it = rvl.begin(); it != rvl.end(); ++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->tagName() == (*it)->tagName()) { oi->update(); found = true; break; } } if (!found) { KstObjectItem *i = new KstObjectItem(DataView, *it, this); connect(i, SIGNAL(updated()), this, SLOT(doUpdates())); } } if (DataView->selectedItem()) { static_cast<KstObjectItem*>(DataView->currentItem())->updateButtons(); } else { Edit->setEnabled(false); Delete->setEnabled(false); } }