summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLouie S <louie@example.com>2024-03-09 18:28:02 -0500
committerLouie S <louie@example.com>2024-03-09 18:28:02 -0500
commitddee95158867554825092b9c29d8278320b93c61 (patch)
tree9523c6ef4879017286360ba9efc9ce97056d3ba9
parent848cdae813648f0a2c39942dc01d8f991787b338 (diff)
Implemented remove group
-rw-r--r--src/backend/db_sqlite.cpp29
-rw-r--r--src/backend/db_sqlite.h2
-rw-r--r--src/groupLayout.cpp5
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 <QDebug>
#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();
}