// Delete an item from the tree. We really just hide it. void NTagView::deleteRequested() { QList<QTreeWidgetItem*> items = selectedItems(); if (global.confirmDeletes()) { QMessageBox msgBox; msgBox.setIcon(QMessageBox::Question); if (items.size() == 1) msgBox.setText(tr("Are you sure you want to delete this tag?")); else msgBox.setText(tr("Are you sure you want to delete all selected tags?")); msgBox.setWindowTitle(tr("Verify Delete")); msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No); msgBox.setDefaultButton(QMessageBox::No); int ret = msgBox.exec(); if (ret == QMessageBox::No) return; } for (int i=0; i<items.size(); i++) { // Delete from the DB qint32 lid = items[i]->data(NAME_POSITION, Qt::UserRole).toInt(); TagTable table(global.db); table.deleteTag(lid); // Now remove selected tags NTagViewItem *ptr = dataStore.take(items[i]->data(NAME_POSITION, Qt::UserRole).toInt()); QList<QTreeWidgetItem*> children = ptr->takeChildren(); ptr->parent()->addChildren(children); ptr->parent()->removeChild(ptr); emit(tagDeleted(lid, ptr->data(NAME_POSITION, Qt::DisplayRole).toString())); delete ptr; } }
// Delete an item from the tree. We really just hide it. void NTagView::deleteRequested() { QList<QTreeWidgetItem*> items = selectedItems(); qint32 lid = items[0]->data(NAME_POSITION, Qt::UserRole).toInt(); if (global.confirmDeletes()) { QMessageBox msgBox; msgBox.setIcon(QMessageBox::Question); msgBox.setText(tr("Are you sure you want to delete this tag?")); msgBox.setWindowTitle(tr("Verify Delete")); msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No); msgBox.setDefaultButton(QMessageBox::No); int ret = msgBox.exec(); if (ret == QMessageBox::No) return; } TagTable table(global.db); table.deleteTag(lid); // NTagViewItem *ptr = (NTagViewItem*)items[0]; // ptr->setHidden(true); // Now remove it in the datastore NTagViewItem *ptr = dataStore.take(items[0]->data(NAME_POSITION, Qt::UserRole).toInt()); emit(tagDeleted(lid, ptr->data(NAME_POSITION, Qt::DisplayRole).toString())); delete ptr; }
// Delete an item from the tree. We really just hide it. void NTagView::mergeRequested() { QList<QTreeWidgetItem*> items = selectedItems(); QMessageBox msgBox; msgBox.setIcon(QMessageBox::Question); msgBox.setText(tr("Are you sure you want to merge these tags?")); msgBox.setWindowTitle(tr("Verify Merge")); msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No); msgBox.setDefaultButton(QMessageBox::No); int ret = msgBox.exec(); if (ret == QMessageBox::No) return; qint32 lid = items[0]->data(NAME_POSITION, Qt::UserRole).toInt(); NoteTable ntable(global.db); QList<qint32> notes; for (int j=1; j<items.size(); j++) { ntable.findNotesByTag(notes, items[j]->data(NAME_POSITION, Qt::UserRole).toInt()); for (int i=0; i<notes.size(); i++) { if (!ntable.hasTag(notes[i], lid)) { ntable.addTag(notes[i], lid, true); QString tagString = ntable.getNoteListTags(notes[i]); emit(updateNoteList(notes[i], NOTE_TABLE_TAGS_POSITION, tagString)); // qint64 dt = QDateTime::currentMSecsSinceEpoch(); // ntable.updateDate(notes[i], dt, NOTE_UPDATED_DATE, true); // emit(updateNoteList(notes[i], NOTE_TABLE_DATE_UPDATED_POSITION, dt)); } } } // Now delete the old tags. for (int i=1; i<items.size(); i++) { qint32 lid = items[i]->data(NAME_POSITION, Qt::UserRole).toInt(); TagTable table(global.db); table.deleteTag(lid); // Now remove it in the datastore NTagViewItem *ptr = dataStore.take(items[i]->data(NAME_POSITION, Qt::UserRole).toInt()); emit(tagDeleted(lid, ptr->data(NAME_POSITION, Qt::DisplayRole).toString())); delete ptr; } }