summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLouie S <louie@example.com>2024-02-28 18:39:48 -0500
committerLouie S <louie@example.com>2024-02-28 18:39:48 -0500
commit9c05cd5b5e9250f3cfd04a98370595db8ef8f697 (patch)
tree83e0841539708b3a3d6fbfd19369b11242e4a6c6 /src
parent34a6045e57a117b9035a12cfe107048e700fe8fd (diff)
Working add_group_form
Diffstat (limited to 'src')
-rw-r--r--src/add_group_form.cpp21
-rw-r--r--src/add_group_form.h2
-rw-r--r--src/backend/db_sqlite.cpp21
-rw-r--r--src/backend/db_sqlite.h8
4 files changed, 37 insertions, 15 deletions
diff --git a/src/add_group_form.cpp b/src/add_group_form.cpp
index 5662208..75ecd29 100644
--- a/src/add_group_form.cpp
+++ b/src/add_group_form.cpp
@@ -1,30 +1,33 @@
#include <QMessageBox>
+#include <QDebug>
+
#include "add_group_form.h"
+#include "backend/db_sqlite.h"
AddGroupForm::AddGroupForm() {
// load uic
ui.setupUi(this);
-
- // setup dialog button connections
- QObject::connect(ui.buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
- QObject::connect(ui.buttonBox, &QDialogButtonBox::accepted, this, &AddGroupForm::handleSubmit);
}
-void AddGroupForm::handleSubmit() {
+void AddGroupForm::accept() {
QString name_text = ui.new_group_name->text();
QString column_text = ui.new_group_column->currentText();
QString link_text = ui.new_group_link->text();
QMessageBox error_message;
+ 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");
- error_message.setParent(this);
- error_message.show();
+ error_message.exec();
+ return;
}
- // TODO insert into database
- this->close();
+ new_id = BackendDB::insertGroup(Group(0, name_text, column_text, link_text));
+ // TODO redraw the main window
+
+ QDialog::accept();
}
diff --git a/src/add_group_form.h b/src/add_group_form.h
index c3b3765..2206e34 100644
--- a/src/add_group_form.h
+++ b/src/add_group_form.h
@@ -13,7 +13,7 @@ class AddGroupForm : public QDialog {
Ui::Dialog ui;
private slots:
- void handleSubmit();
+ void accept();
};
#endif
diff --git a/src/backend/db_sqlite.cpp b/src/backend/db_sqlite.cpp
index 9cd73f5..4479b09 100644
--- a/src/backend/db_sqlite.cpp
+++ b/src/backend/db_sqlite.cpp
@@ -91,7 +91,7 @@ QList<Group *> BackendDB::loadGroups() {
}
// load entries
-QList<Entry *> loadEntries() {
+QList<Entry *> BackendDB::loadEntries() {
QSqlDatabase database = openDB();
QSqlQuery query;
QList<Entry *> output;
@@ -116,7 +116,7 @@ QList<Entry *> loadEntries() {
}
// load entries
-QList<Rule *> loadRules() {
+QList<Rule *> BackendDB::loadRules() {
QSqlDatabase database = openDB();
QSqlQuery query;
QList<Rule *> output;
@@ -135,3 +135,20 @@ QList<Rule *> loadRules() {
database.close();
return output;
}
+
+// insert group to the database (returns 0 if failed)
+int BackendDB::insertGroup(const Group &new_group) {
+ QSqlDatabase database = openDB();
+ QSqlQuery query;
+ int output;
+
+ query.prepare("INSERT INTO groups (name, column, link) VALUES (?, ?, ?)");
+ query.bindValue(0, new_group.name);
+ query.bindValue(1, new_group.column);
+ query.bindValue(2, new_group.link);
+ query.exec();
+
+ output = query.lastInsertId().toInt();
+ database.close();
+ return output;
+}
diff --git a/src/backend/db_sqlite.h b/src/backend/db_sqlite.h
index 6e94fdd..fb04c00 100644
--- a/src/backend/db_sqlite.h
+++ b/src/backend/db_sqlite.h
@@ -8,6 +8,8 @@
#include "../group.h"
#include "../rule.h"
+// TODO rewrite to be a class (see difference between ::addDatabase and ::database)
+
namespace BackendDB {
const QStringList create_table_queries = {
"CREATE TABLE groups ("
@@ -43,9 +45,9 @@ namespace BackendDB {
QList<Group *> loadGroups();
QList<Entry *> loadEntries();
QList<Rule *> loadRules();
- void insertGroup(int new_group); // param datatype TBD
- void insertEntry(int new_entry); // param datatype TBD
- void insertRule(int new_rule); // param datatype TBD
+ int insertGroup(const Group &new_group); // param datatype TBD
+ int insertEntry(int new_entry); // param datatype TBD
+ int insertRule(int new_rule); // param datatype TBD
void updateGroup(int group); // param datatype TBD
void updateEntry(int entry); // param datatype TBD
void updateRule(int rule); // param datatype TBD