summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLouie S <louie@example.com>2024-03-12 18:37:06 -0400
committerLouie S <louie@example.com>2024-03-12 18:37:06 -0400
commitc96d1c12f1fd2a34105305cb560792936c246259 (patch)
treec992dc60f8303a0c77cbbdec3b4ded932eba2c3e
parente9c68303aaa353f003a0c68d11d04b9c6062104b (diff)
Implement editEntryForm
-rw-r--r--CMakeLists.txt2
-rw-r--r--src/backend/db_sqlite.cpp30
-rw-r--r--src/backend/db_sqlite.h2
-rw-r--r--src/editEntryForm.cpp42
-rw-r--r--src/editGroupForm.cpp8
-rw-r--r--src/entryLayout.cpp55
-rw-r--r--src/entryLayout.h7
7 files changed, 140 insertions, 6 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 44b4646..077981d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -43,6 +43,8 @@ set(project_sources
"src/assignmentList.ui"
"src/editGroupForm.cpp"
"src/editGroupForm.h"
+ "src/editEntryForm.cpp"
+ "src/editEntryForm.h"
"src/entry.cpp"
"src/entry.h"
"src/entryLayout.cpp"
diff --git a/src/backend/db_sqlite.cpp b/src/backend/db_sqlite.cpp
index 763fba5..0d21a05 100644
--- a/src/backend/db_sqlite.cpp
+++ b/src/backend/db_sqlite.cpp
@@ -218,6 +218,36 @@ void BackendDB::updateGroup(const Group &group) {
QSqlDatabase::removeDatabase("qt_sql_default_connection");
}
+void BackendDB::updateEntry(const Entry &entry) {
+ {
+ QSqlDatabase database(this->openDB());
+ QSqlQuery query;
+
+ query.prepare("UPDATE entries SET "
+ "description = :desc, "
+ "due_date = :due, "
+ "alt_due_date = :alt_due, "
+ "link = :link, "
+ "color = :color, "
+ "highlight = :highlight, "
+ "done = :done, "
+ "hidden = :hidden "
+ "WHERE id = :id");
+ query.bindValue(":desc", entry.desc);
+ query.bindValue(":due", entry.due.toString("yyyy-MM-dd"));
+ query.bindValue(":alt_due", entry.due_alt);
+ query.bindValue(":link", entry.link);
+ query.bindValue(":color", entry.color);
+ query.bindValue(":highlight", entry.highlight);
+ query.bindValue(":done", entry.done);
+ query.bindValue(":hidden", entry.hidden);
+ query.bindValue(":id", entry.id);
+ query.exec();
+ }
+
+ 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) {
diff --git a/src/backend/db_sqlite.h b/src/backend/db_sqlite.h
index c2e8ac7..83b36f9 100644
--- a/src/backend/db_sqlite.h
+++ b/src/backend/db_sqlite.h
@@ -20,7 +20,7 @@ class BackendDB : QSqlDatabase {
int insertEntry(const Entry &new_entry);
int insertRule(int new_rule); // param datatype TBD
void updateGroup(const Group &group);
- void updateEntry(int entry); // param datatype TBD
+ void updateEntry(const Entry &entry); // param datatype TBD
void updateRule(int rule); // param datatype TBD
int removeGroup(const Group &group);
void removeEntry(int entry); // param datatype TBD
diff --git a/src/editEntryForm.cpp b/src/editEntryForm.cpp
index 68a29fe..a36afa7 100644
--- a/src/editEntryForm.cpp
+++ b/src/editEntryForm.cpp
@@ -1,5 +1,7 @@
+#include <QMessageBox>
+
#include "backend/db_sqlite.h"
-#include "edit_entry_form.h"
+#include "editEntryForm.h"
EditEntryForm::EditEntryForm(const Entry &e) :
entry(e)
@@ -12,4 +14,42 @@ EditEntryForm::EditEntryForm(const Entry &e) :
ui.title->setText("Edit Entry");
// widgets setup
+ ui.entry_desc->setText(this->entry.desc);
+ ui.entry_due->setDate(QDate::currentDate());
+ if(this->entry.due.isValid()) {
+ ui.entry_due->setDate(entry.due.date());
+ ui.entry_due_checkbox->setChecked(true);
+ }
+ else
+ ui.entry_due_checkbox->setChecked(false);
+ ui.entry_due_alt->setText(this->entry.due_alt);
+ ui.entry_link->setText(this->entry.link.toString());
+ ui.entry_color->setText(this->entry.color);
+ ui.entry_highlight->setText(this->entry.highlight);
+}
+
+void EditEntryForm::accept() {
+ this->entry.desc = ui.entry_desc->text();
+ if(ui.entry_due_checkbox->isChecked())
+ this->entry.due = ui.entry_due->dateTime();
+ else
+ this->entry.due = QDateTime();
+ this->entry.due_alt = ui.entry_due_alt->text();
+ this->entry.link = ui.entry_link->text();
+ this->entry.color = ui.entry_color->text();
+ this->entry.highlight = ui.entry_highlight->text();
+ QMessageBox error_message;
+ BackendDB database;
+
+ if(this->entry.desc.isEmpty()) {
+ error_message.setIcon(QMessageBox::Warning);
+ error_message.setWindowTitle("Error Message");
+ error_message.setText("Name cannot be blank");
+ error_message.exec();
+ return;
+ }
+
+ database.updateEntry(this->entry);
+
+ QDialog::accept();
}
diff --git a/src/editGroupForm.cpp b/src/editGroupForm.cpp
index 351fddd..52c45ac 100644
--- a/src/editGroupForm.cpp
+++ b/src/editGroupForm.cpp
@@ -20,13 +20,13 @@ 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();
+ this->group.name = ui.group_name->text();
+ this->group.column = Group::Column(ui.group_column->currentIndex());
+ this->group.link = ui.group_link->text();
QMessageBox error_message;
BackendDB database;
- if(group.name.isEmpty()) {
+ if(this->group.name.isEmpty()) {
error_message.setIcon(QMessageBox::Warning);
error_message.setWindowTitle("Error Message");
error_message.setText("Name cannot be blank");
diff --git a/src/entryLayout.cpp b/src/entryLayout.cpp
index 37f09a9..3bf09e6 100644
--- a/src/entryLayout.cpp
+++ b/src/entryLayout.cpp
@@ -1,6 +1,11 @@
#include <QLabel>
+#include <QMenu>
+#include <QDebug>
+
+#include "editEntryForm.h"
#include "entryLayout.h"
+#include "lib.h"
EntryLayout::EntryLayout(const Entry &e) :
entry(e)
@@ -18,6 +23,13 @@ EntryLayout::EntryLayout(const Entry &e) :
body->setFont(QFont("Arial", 11));
body->setWordWrap(true);
body->setToolTip("Right-Click for actions");
+ body->setContextMenuPolicy(Qt::CustomContextMenu);
+
+ // set context menu
+ body->setContextMenuPolicy(Qt::CustomContextMenu);
+ QObject::connect(body,
+ SIGNAL(customContextMenuRequested(const QPoint &)),
+ SLOT(showContextMenu()));
// Check rules
// TODO
@@ -75,5 +87,48 @@ EntryLayout::EntryLayout(const Entry &e) :
);
*/
}
+
this->addWidget(body);
}
+
+void EntryLayout::showContextMenu() {
+ QMenu menu;
+
+ QAction *edit_entry_act = new QAction("Edit Entry");
+ QObject::connect(edit_entry_act, &QAction::triggered, this, &EntryLayout::editEntry);
+ menu.addAction(edit_entry_act);
+
+ QAction *set_rules_act = new QAction("Rules");
+ QObject::connect(edit_entry_act, &QAction::triggered, this, &EntryLayout::setRules);
+ menu.addAction(set_rules_act);
+
+ QAction *toggle_done_act = new QAction("Done");
+ toggle_done_act->setCheckable(true);
+ if(this->entry.done) toggle_done_act->setChecked(true);
+ QObject::connect(toggle_done_act, &QAction::triggered, this, &EntryLayout::toggleDone);
+ menu.addAction(toggle_done_act);
+
+ QAction *del_entry_act = new QAction("Remove Entry");
+ QObject::connect(del_entry_act, &QAction::triggered, this, &EntryLayout::removeEntry);
+ menu.addAction(del_entry_act);
+
+ menu.exec(QCursor::pos());
+}
+
+void EntryLayout::editEntry() {
+ EditEntryForm edit_entry_dialog(this->entry);
+ if(edit_entry_dialog.exec() == QDialog::Accepted)
+ getMainWindow()->displayWidgets();
+}
+
+void EntryLayout::setRules() {
+ qDebug() << "WIP";
+}
+
+void EntryLayout::toggleDone() {
+ qDebug() << "WIP";
+}
+
+void EntryLayout::removeEntry() {
+ qDebug() << "WIP";
+}
diff --git a/src/entryLayout.h b/src/entryLayout.h
index fb4902b..1a4146b 100644
--- a/src/entryLayout.h
+++ b/src/entryLayout.h
@@ -15,6 +15,13 @@ class EntryLayout : public QHBoxLayout {
Entry entry;
EntryLayout(const Entry &e);
+
+ private slots:
+ void showContextMenu();
+ void editEntry();
+ void setRules();
+ void toggleDone();
+ void removeEntry();
};
#endif