summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLouie S <louie@example.com>2024-03-09 18:15:46 -0500
committerLouie S <louie@example.com>2024-03-09 18:15:46 -0500
commit848cdae813648f0a2c39942dc01d8f991787b338 (patch)
treed886cf963496d916ae06045faea5bda21ddb8122 /src
parentfc00cab0368a6f76a2b1f276f3a3d8573b1fba82 (diff)
accept for edit group form
Diffstat (limited to 'src')
-rw-r--r--src/addGroupForm.cpp3
-rw-r--r--src/backend/db_sqlite.cpp24
-rw-r--r--src/backend/db_sqlite.h2
-rw-r--r--src/editGroupForm.cpp20
4 files changed, 45 insertions, 4 deletions
diff --git a/src/addGroupForm.cpp b/src/addGroupForm.cpp
index d3fa72f..06e1f7c 100644
--- a/src/addGroupForm.cpp
+++ b/src/addGroupForm.cpp
@@ -1,7 +1,5 @@
#include <QMessageBox>
-#include <QDebug>
-
#include "addGroupForm.h"
#include "backend/db_sqlite.h"
@@ -23,7 +21,6 @@ void AddGroupForm::accept() {
int new_id;
if(name_text.isEmpty()) {
- qDebug() << "Gets here";
error_message.setIcon(QMessageBox::Warning);
error_message.setWindowTitle("Error Message");
error_message.setText("Name cannot be blank");
diff --git a/src/backend/db_sqlite.cpp b/src/backend/db_sqlite.cpp
index 8a612a0..6490bb1 100644
--- a/src/backend/db_sqlite.cpp
+++ b/src/backend/db_sqlite.cpp
@@ -196,6 +196,30 @@ int BackendDB::insertEntry(const Entry &new_entry) {
return output;
}
+void BackendDB::updateGroup(const Group &group) {
+ {
+ QSqlDatabase database(this->openDB());
+ QSqlQuery query;
+
+ qDebug() << group.name;
+
+ query.prepare("UPDATE groups SET "
+ "name = :name, "
+ "column = :column, "
+ "link = :link, "
+ "hidden = :hidden "
+ "WHERE id = :id");
+ query.bindValue(":name", group.name);
+ query.bindValue(":column", group.column);
+ query.bindValue(":link", group.link);
+ query.bindValue(":hidden", group.hidden);
+ query.bindValue(":id", group.id);
+ query.exec();
+ }
+
+ QSqlDatabase::removeDatabase("qt_sql_default_connection");
+}
+
QString BackendDB::getDBPath() {
QSettings settings;
settings.beginGroup("paths");
diff --git a/src/backend/db_sqlite.h b/src/backend/db_sqlite.h
index afaac8d..b138dc6 100644
--- a/src/backend/db_sqlite.h
+++ b/src/backend/db_sqlite.h
@@ -19,7 +19,7 @@ class BackendDB : QSqlDatabase {
int insertGroup(const Group &new_group);
int insertEntry(const Entry &new_entry);
int insertRule(int new_rule); // param datatype TBD
- void updateGroup(int group); // param datatype TBD
+ 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
diff --git a/src/editGroupForm.cpp b/src/editGroupForm.cpp
index af22e78..351fddd 100644
--- a/src/editGroupForm.cpp
+++ b/src/editGroupForm.cpp
@@ -1,3 +1,6 @@
+#include <QMessageBox>
+
+#include "backend/db_sqlite.h"
#include "editGroupForm.h"
EditGroupForm::EditGroupForm(const Group &g) :
@@ -17,4 +20,21 @@ EditGroupForm::EditGroupForm(const Group &g) :
}
void EditGroupForm::accept() {
+ group.name = ui.group_name->text();
+ group.column = Group::Column(ui.group_column->currentIndex());
+ group.link = ui.group_link->text();
+ QMessageBox error_message;
+ BackendDB database;
+
+ if(group.name.isEmpty()) {
+ error_message.setIcon(QMessageBox::Warning);
+ error_message.setWindowTitle("Error Message");
+ error_message.setText("Name cannot be blank");
+ error_message.exec();
+ return;
+ }
+
+ database.updateGroup(this->group);
+
+ QDialog::accept();
}