void NoteHistory::add(Note note, int cursorPosition) { if (!note.exists()) { return; } NoteHistoryItem item(¬e, cursorPosition); if (noteHistory->contains(item)) { // decrease current index if we are going to remove an item before it if (noteHistory->indexOf(item) < currentIndex) { currentIndex--; } // remove found item noteHistory->removeAll(item); } noteHistory->prepend(item); if (currentIndex < lastIndex()) { // increase current index currentIndex++; } noteHistory->move(0, currentIndex); currentIndex = noteHistory->indexOf(item); qDebug() << " added to history: " << item; }
/** * Removes a tag from the note * * @param tagName * @return true if the tag was removed from the note */ bool NoteApi::removeTag(QString tagName) { Tag tag = Tag::fetchByName(tagName); if (!tag.exists()) { return false; } Note note = Note::fetch(id); if (!note.exists()) { return false; } return tag.removeLinkToNote(note); }
/** * Adds a tag to the note * * @param tagName * @return true if the note was tagged */ bool NoteApi::addTag(QString tagName) { if (tagName.isEmpty()) { return false; } Note note = Note::fetch(id); if (!note.exists()) { return false; } // create a new tag if it doesn't exist Tag tag = Tag::fetchByName(tagName); if (!tag.isFetched()) { tag.setName(tagName); tag.store(); } return tag.linkToNote(note); }
bool NoteHistoryItem::isNoteValid() { Note note = getNote(); return note.exists(); }