| 796 | |
| 797 | |
| 798 | void NNotebookView::moveToNewStackRequested() { |
| 799 | QList<QTreeWidgetItem*> items = selectedItems(); |
| 800 | if (items.size() == 0) |
| 801 | return; |
| 802 | |
| 803 | QString newStackName = "New Stack"; |
| 804 | int i=1; |
| 805 | QString iStr; |
| 806 | QList<int> books; |
| 807 | NotebookTable table(global.db); |
| 808 | |
| 809 | while (i>=0) { |
| 810 | books.clear(); |
| 811 | table.findByStack(books, newStackName); |
| 812 | if (books.size() == 0) { |
| 813 | i=-1; |
| 814 | } else { |
| 815 | iStr = QVariant(i).toString(); |
| 816 | newStackName = tr("New Stack (") +iStr +tr(")"); |
| 817 | i++; |
| 818 | } |
| 819 | } |
| 820 | |
| 821 | // Create the new stack & move the child to it |
| 822 | NNotebookViewItem *newStack = new NNotebookViewItem(0); |
| 823 | newStack->setText(NAME_POSITION, newStackName); |
| 824 | newStack->setData(NAME_POSITION, Qt::UserRole, "STACK"); |
| 825 | stackStore.insert(newStackName, newStack); |
| 826 | topLevelItem(0)->addChild(newStack); |
| 827 | items[0]->parent()->removeChild(items[0]); |
| 828 | newStack->addChild(items[0]); |
| 829 | |
| 830 | // Create a new action item for the menu |
| 831 | QAction *newAction = stackMenu->addAction(newStackName); |
| 832 | connect(newAction, SIGNAL(triggered()), this, SLOT(moveToStackRequested())); |
| 833 | menuData.insert(newStackName, newAction); |
| 834 | sortStackMenu(); |
| 835 | |
| 836 | // Update the note in the database |
| 837 | qint32 lid = items[0]->data(NAME_POSITION, Qt::UserRole).toInt(); |
| 838 | Notebook book; |
| 839 | table.get(book, lid); |
| 840 | book.stack = newStackName; |
| 841 | table.update(book, true); |
| 842 | |
| 843 | this->sortItems(NAME_POSITION, Qt::AscendingOrder); |
| 844 | resetSize(); |
| 845 | this->sortByColumn(NAME_POSITION); |
| 846 | newStack->setExpanded(true); |
| 847 | emit(stackAdded(newStackName)); |
| 848 | } |
| 849 | |
| 850 | |
| 851 | void NNotebookView::removeFromStackRequested() { |