Do the alter. If the notebook is not found we create it. If a tag is not found for an add, we add it. If a tag is not found for a deleteTag, we just ignore it.
| 52 | // If a tag is not found for an add, we add it. If a tag is |
| 53 | // not found for a deleteTag, we just ignore it. |
| 54 | int AlterNote::alterNote() { |
| 55 | |
| 56 | // If a query is specified, we find the matching notes. |
| 57 | if (query != "") { |
| 58 | FilterCriteria *filter = new FilterCriteria(); |
| 59 | global.filterCriteria.append(filter); |
| 60 | global.filterPosition = 0; |
| 61 | FilterEngine engine; |
| 62 | filter->setSearchString(query); |
| 63 | QList<qint32> lids; |
| 64 | engine.filter(filter, &lids); |
| 65 | this->lids.append(lids); |
| 66 | } |
| 67 | |
| 68 | NotebookTable bookTable(global.db); |
| 69 | TagTable tagTable(global.db); |
| 70 | NoteTable noteTable(global.db); |
| 71 | |
| 72 | // Loop through each note requested. |
| 73 | for (int i=0; i<lids.size(); i++) { |
| 74 | qint32 lid = lids[i]; |
| 75 | |
| 76 | // Do the notebook request |
| 77 | if (notebook != "") { |
| 78 | qint32 notebookLid = bookTable.findByName(notebook); |
| 79 | if (notebookLid<0) { |
| 80 | Notebook book; |
| 81 | book.name = notebook; |
| 82 | NUuid uuid; |
| 83 | book.guid = uuid.create(); |
| 84 | notebookLid = bookTable.add(0,book,true); |
| 85 | } |
| 86 | if (noteTable.getNotebookLid(lid) != notebookLid) |
| 87 | noteTable.updateNotebook(lid, notebookLid, true); |
| 88 | } |
| 89 | |
| 90 | // Add the tags |
| 91 | for (int j=0; j<addTagNames.size(); j++) { |
| 92 | qint32 tagLid = tagTable.findByName(addTagNames[j],0); |
| 93 | if (tagLid <= 0) { |
| 94 | Tag t; |
| 95 | t.name = addTagNames[j]; |
| 96 | NUuid uuid; |
| 97 | t.guid = uuid.create(); |
| 98 | tagLid = tagTable.add(0,t,true,0); |
| 99 | } |
| 100 | if (!noteTable.hasTag(lid,tagLid)) |
| 101 | noteTable.addTag(lid, tagLid, true); |
| 102 | } |
| 103 | |
| 104 | // Remove any tags specified |
| 105 | for (int j=0; j<delTagNames.size(); j++) { |
| 106 | qint32 tagLid = tagTable.findByName(delTagNames[j],0); |
| 107 | if (tagLid > 0 && noteTable.hasTag(lid,tagLid)) { |
| 108 | noteTable.removeTag(lid, tagLid, true); |
| 109 | } |
| 110 | } |
| 111 |
no test coverage detected