void KstDataManagerI::edit_I() { QListViewItem *qi; if (DataView->selectedItems().count() > 0) { qi = DataView->selectedItems().at(0); } else { KMessageBox::sorry(this, i18n("A data item must be selected to edit.")); return; } if (qi->rtti() == RTTI_OBJ_DATA_VECTOR) { emit editDataVector(qi->text(0)); } if (qi->rtti() == RTTI_OBJ_STATIC_VECTOR) { emit editStaticVector(qi->text(0)); } if (qi->rtti() == RTTI_OBJ_OBJECT) { static_cast<KstObjectItem*>(qi)->dataObject()->showDialog(); } if (qi->rtti() == RTTI_OBJ_DATA_MATRIX) { emit editDataMatrix(qi->text(0)); } if (qi->rtti() == RTTI_OBJ_STATIC_MATRIX) { emit editStaticMatrix(qi->text(0)); } }
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(); } }
qsamplerInstrumentGroup *qsamplerInstrumentGroup::groupItem (void) const { QListViewItem *pParent = QListViewItem::parent(); while (pParent && pParent->rtti() != qsamplerInstrumentList::Group) pParent = pParent->parent(); return static_cast<qsamplerInstrumentGroup *> (pParent); }
void KstDataManagerI::edit_I() { QListViewItem *qi = 0; if (!DataView->selectedItems().isEmpty()) { qi = DataView->selectedItems().at(0); } else { // This error message is odd to say the least. //KMessageBox::sorry(this, i18n("A data item must be selected to edit.")); return; } switch (qi->rtti()) { case RTTI_OBJ_DATA_VECTOR: emit editDataVector(qi->text(0)); break; case RTTI_OBJ_STATIC_VECTOR: emit editStaticVector(qi->text(0)); break; case RTTI_OBJ_OBJECT: static_cast<KstObjectItem*>(qi)->dataObject()->showDialog(true); break; case RTTI_OBJ_DATA_MATRIX: emit editDataMatrix(qi->text(0)); break; case RTTI_OBJ_STATIC_MATRIX: emit editStaticMatrix(qi->text(0)); break; default: break; } }
void FolderListView::startDrag() { QListViewItem *item = currentItem(); if (!item) return; if (item == firstChild() && item->listView()->rootIsDecorated()) return;//it's the project folder so we don't want the user to move it QPoint orig = viewportToContents( viewport()->mapFromGlobal( QCursor::pos() ) ); QPixmap pix; if (item->rtti() == FolderListItem::ListItemType) pix = QPixmap( folder_closed_xpm ); else pix = *item->pixmap (0); QIconDrag *drag = new QIconDrag(viewport()); drag->setPixmap(pix, QPoint(pix.width()/2, pix.height()/2 ) ); QPtrList<QListViewItem> lst; for (item = firstChild(); item; item = item->itemBelow()) { if (item->isSelected()) lst.append(item); } emit dragItems(lst); drag->drag(); }
// In-place selection slot. void qsamplerInstrumentList::selectionChangedSlot (void) { qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); QListViewItem *pListItem = QListView::selectedItem(); bool bEnabled = (pMainForm && pMainForm->client()); m_pNewItemAction->setEnabled(bEnabled); bEnabled = (bEnabled && pListItem != NULL); m_pEditItemAction->setEnabled(bEnabled && pListItem->rtti() == Item); m_pRenameAction->setEnabled(bEnabled); m_pDeleteAction->setEnabled(bEnabled); }
void FolderListView::contentsDropEvent( QDropEvent *e ) { QListViewItem *dest = itemAt( contentsToViewport(e->pos()) ); if ( dest && dest->rtti() == FolderListItem::ListItemType) { emit dropItems(dest); e->accept(); } else e->ignore(); }
// Remove current group/item. void qsamplerInstrumentList::deleteSlot (void) { QListViewItem *pListItem = QListView::selectedItem(); if (pListItem == NULL) return; qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); if (pMainForm == NULL) return; // Prompt user if this is for real... qsamplerOptions *pOptions = pMainForm->options(); if (pOptions && pOptions->bConfirmRemove) { if (QMessageBox::warning(this, QSAMPLER_TITLE ": " + tr("Warning"), tr("Delete %1:\n\n" "%2\n\n" "Are you sure?") .arg(pListItem->rtti() == Item ? tr("instrument") : tr("group")) .arg(pListItem->text(0)), tr("OK"), tr("Cancel")) > 0) return; } // Unmap instrument entry... if (pListItem->rtti() == Item) { qsamplerInstrumentItem *pItem = static_cast<qsamplerInstrumentItem *> (pListItem); if (pItem && pItem->instrument()) { pItem->instrument()->unmapInstrument(); emit instrumentsChanged(); } } // Do it for real... delete pListItem; selectionChangedSlot(); }
// Find a group item, given its name. qsamplerInstrumentGroup *qsamplerInstrumentList::findGroup ( const QString& sName ) const { // Iterate all over the place to search for the group. QListViewItemIterator iter((QListView *) this); while (iter.current()) { QListViewItem *pItem = iter.current(); if (pItem->rtti() == Group && pItem->text(0) == sName) return static_cast<qsamplerInstrumentGroup *> (pItem); ++iter; } // Not found. return NULL; }
void VariableTree::clear() { QListViewItem *sibling = firstChild(); while (sibling != 0) { QListViewItem * current = sibling; sibling = sibling->nextSibling(); if (current->rtti() != RTTI_WATCH_ROOT) { delete current; } } globalRoot_ = 0; selectedFrame_ = 0; return; }
// Edit current item below the current one. void qsamplerInstrumentList::editItemSlot (void) { QListViewItem *pListItem = QListView::selectedItem(); if (pListItem == NULL) return; if (pListItem->rtti() == Item) { qsamplerInstrument *pInstrument = NULL; qsamplerInstrumentItem *pItem = static_cast<qsamplerInstrumentItem *> (pListItem); if (pItem) pInstrument = pItem->instrument(); if (pInstrument) { // Save current key values... qsamplerInstrument oldInstrument(*pInstrument); // Do the edit dance... qsamplerInstrumentForm form(this); form.setup(pInstrument); if (form.exec()) { // Commit... pInstrument->mapInstrument(); // Check whether we changed instrument key... if (oldInstrument.map() == pInstrument->map() && oldInstrument.bank() == pInstrument->bank() && oldInstrument.prog() == pInstrument->prog()) { // just update tree item... pItem->update(); } else { // Unmap old instance... oldInstrument.unmapInstrument(); // Change item tree, whether applicable... if (m_iMidiMap < 0 || m_iMidiMap == pInstrument->map()) { // Add new brand item into view... addItem(pInstrument, groupItem(pListItem)); } else { // Just remove/hide old one. delete pItem; } } // Notify we've changes... emit instrumentsChanged(); } } } selectionChangedSlot(); }
VarFrameRoot *VariableTree::findFrame(int frameNo, int threadNo) const { // frames only exist on the top level so we only need to // check the siblings QListViewItem *sibling = firstChild(); while (sibling != 0) { if ( sibling->rtti() == RTTI_VAR_FRAME_ROOT && ((VarFrameRoot*) sibling)->frameNo() == frameNo && ((VarFrameRoot*) sibling)->threadNo() == threadNo ) { return (VarFrameRoot*) sibling; } sibling = sibling->nextSibling(); } return 0; }
void VariableTree::prune() { QListViewItem *child = firstChild(); while (child != 0) { QListViewItem *nextChild = child->nextSibling(); // Only prune var frames, not the watch or global root if (child->rtti() == RTTI_VAR_FRAME_ROOT) { if (((VarFrameRoot*) child)->isActive()) { if (child->isOpen()) { ((VarFrameRoot*) child)->prune(); } } else { delete child; } } child = nextChild; } }
bool VariableTree::schedule() { QListViewItem * child = firstChild(); VarFrameRoot * frame = 0; while (child != 0) { if (child->rtti() == RTTI_VAR_FRAME_ROOT) { frame = (VarFrameRoot *) child; Q_ASSERT( !frame->isWaitingForData() ); if (frame->needsVariables()) { if (QApplication::overrideCursor() == 0) { QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); } // Tell the controller to fetch the variable values emit selectFrame(frame->frameNo(), frame->threadNo()); return true; } } child = child->nextSibling(); } frame = findFrame(1, currentThread_); Q_ASSERT( frame != 0 ); Q_ASSERT( !frame->needsVariables() ); // All over, nothing left to fetch. // Return to frame 1, and prune the inactive items // from the variable tree.. QApplication::restoreOverrideCursor(); emit selectFrame(1, currentThread_); prune(); return false; }
// Find a file item, given its name. qsamplerInstrumentItem *qsamplerInstrumentList::findItem ( qsamplerInstrument *pInstrument ) const { if (pInstrument == NULL) return NULL; // Iterate all over the place to search for the group. QListViewItemIterator iter((QListView *) this); while (iter.current()) { QListViewItem *pListItem = iter.current(); if (pListItem->rtti() == Item) { qsamplerInstrumentItem *pItem = static_cast<qsamplerInstrumentItem *> (pListItem); if (pItem && pItem->instrument() && pItem->instrument()->map() == pInstrument->map() && pItem->instrument()->bank() == pInstrument->bank() && pItem->instrument()->prog() == pInstrument->prog()) return pItem; } ++iter; } // Not found. return NULL; }
void KstDataManagerI::delete_I() { QListViewItem *qi = DataView->selectedItems().at(0); if (!qi) { return; } KstObjectItem *koi = static_cast<KstObjectItem*>(qi); if (koi->removable()) { if (qi->rtti() == RTTI_OBJ_OBJECT) { doc->removeDataObject(koi->tag().tag()); } else if (qi->rtti() == RTTI_OBJ_DATA_VECTOR) { KST::vectorList.lock().writeLock(); KST::vectorList.removeTag(koi->tag().tag()); KST::vectorList.lock().unlock(); doUpdates(); } else if (qi->rtti() == RTTI_OBJ_STATIC_VECTOR) { KST::vectorList.lock().writeLock(); KST::vectorList.removeTag(koi->tag().tag()); KST::vectorList.lock().unlock(); doUpdates(); } else if (qi->rtti() == RTTI_OBJ_DATA_MATRIX) { KST::matrixList.lock().writeLock(); KST::matrixList.removeTag(koi->tag().tag()); KST::matrixList.lock().unlock(); doUpdates(); } else if (qi->rtti() == RTTI_OBJ_STATIC_MATRIX) { KST::matrixList.lock().writeLock(); KST::matrixList.removeTag(koi->tag().tag()); KST::matrixList.lock().unlock(); doUpdates(); } 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->tag().tag())) == KMessageBox::Yes) { if (qi->rtti() == RTTI_OBJ_OBJECT) { koi->dataObject()->deleteDependents(); doc->removeDataObject(koi->tag().tag()); } else if (qi->rtti() == RTTI_OBJ_DATA_VECTOR) { KstRVectorPtr x = kst_cast<KstRVector>(*KST::vectorList.findTag(koi->tag().tag())); if (x) { x->deleteDependents(); x = 0L; KST::vectorList.lock().writeLock(); KST::vectorList.removeTag(koi->tag().tag()); 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->tag().tag())); if (x) { x->deleteDependents(); x = 0L; KST::vectorList.lock().writeLock(); KST::vectorList.removeTag(koi->tag().tag()); 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->tag().tag())); if (x) { x->deleteDependents(); x = 0L; KST::matrixList.lock().writeLock(); KST::matrixList.removeTag(koi->tag().tag()); 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->tag().tag())); if (x) { x->deleteDependents(); x = 0L; KST::matrixList.lock().writeLock(); KST::matrixList.removeTag(koi->tag().tag()); 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->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); } }
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); } }