From ddee95158867554825092b9c29d8278320b93c61 Mon Sep 17 00:00:00 2001 From: Louie S Date: Sat, 9 Mar 2024 18:28:02 -0500 Subject: Implemented remove group --- src/backend/db_sqlite.cpp | 29 +++++++++++++++++++++++++++-- src/backend/db_sqlite.h | 2 +- src/groupLayout.cpp | 5 ++++- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/backend/db_sqlite.cpp b/src/backend/db_sqlite.cpp index 6490bb1..91bb3e5 100644 --- a/src/backend/db_sqlite.cpp +++ b/src/backend/db_sqlite.cpp @@ -201,8 +201,6 @@ void BackendDB::updateGroup(const Group &group) { QSqlDatabase database(this->openDB()); QSqlQuery query; - qDebug() << group.name; - query.prepare("UPDATE groups SET " "name = :name, " "column = :column, " @@ -220,6 +218,33 @@ void BackendDB::updateGroup(const Group &group) { QSqlDatabase::removeDatabase("qt_sql_default_connection"); } +// hide group and entries belonging to group +// return value: number of affected rows +int BackendDB::removeGroup(const Group &group) { + int output; + + { + QSqlDatabase database(this->openDB()); + QSqlQuery query; + + // First, set entries to hidden + query.prepare("UPDATE entries SET hidden = 1 WHERE parent_id = ?"); + query.bindValue(0, group.id); + query.exec(); + + // Now, set the group to hidden + query.prepare("UPDATE groups SET hidden = 1 WHERE id = ?"); + query.bindValue(0, group.id); + query.exec(); + + // FIXME not sure if this also needs to be called after the first query... + output = query.numRowsAffected(); + } + + QSqlDatabase::removeDatabase("qt_sql_default_connection"); + return output; +} + QString BackendDB::getDBPath() { QSettings settings; settings.beginGroup("paths"); diff --git a/src/backend/db_sqlite.h b/src/backend/db_sqlite.h index b138dc6..c2e8ac7 100644 --- a/src/backend/db_sqlite.h +++ b/src/backend/db_sqlite.h @@ -22,7 +22,7 @@ class BackendDB : QSqlDatabase { void updateGroup(const Group &group); void updateEntry(int entry); // param datatype TBD void updateRule(int rule); // param datatype TBD - void removeGroup(int group); // param datatype TBD + int removeGroup(const Group &group); void removeEntry(int entry); // param datatype TBD void removeRule(int rule); // param datatype TBD void cleanHidden(); diff --git a/src/groupLayout.cpp b/src/groupLayout.cpp index 11dea2a..e99ddf6 100644 --- a/src/groupLayout.cpp +++ b/src/groupLayout.cpp @@ -5,6 +5,7 @@ #include #include "addEntryForm.h" +#include "backend/db_sqlite.h" #include "editGroupForm.h" #include "groupLayout.h" #include "lib.h" @@ -61,5 +62,7 @@ void GroupLayout::editGroup() { } void GroupLayout::removeGroup() { - qDebug() << "WIP"; + BackendDB database; + if(database.removeGroup(this->group) > 0) + getMainWindow()->displayWidgets(); } -- cgit