Пример #1
0
/**
 * Removes the tag, their children and its note link items
 */
bool Tag::remove() {
    QSqlDatabase db = QSqlDatabase::database("note_folder");
    QSqlQuery query(db);

    // remove the tag
    query.prepare("DELETE FROM tag WHERE id = :id");
    query.bindValue(":id", id);

    if (!query.exec()) {
        qWarning() << __func__ << ": " << query.lastError();
        return false;
    } else {
        // remove all children tags
        Q_FOREACH(Tag tag, fetchAllByParentId(id)) {
                tag.remove();
            }

        // remove the note tag links
        query.prepare("DELETE FROM noteTagLink WHERE tag_id = :id");
        query.bindValue(":id", id);

        if (!query.exec()) {
            qWarning() << __func__ << ": " << query.lastError();
            return false;
        } else {
            return true;
        }
    }
}
Пример #2
0
/**
 * Fetches a list of all ids recursively by a parent id
 * The parent id is included in the list
 *
 * @param parentId
 * @return
 */
QList<int> NoteSubFolder::fetchIdsRecursivelyByParentId(int parentId) {
    QList<int> idList = QList<int>() << parentId;

    Q_FOREACH(NoteSubFolder noteSubFolder, fetchAllByParentId(parentId)) {
            int id = noteSubFolder.getId();
            idList << fetchIdsRecursivelyByParentId(id);
        }