diff options
author | Louie S <louie@example.com> | 2024-03-09 16:53:38 -0500 |
---|---|---|
committer | Louie S <louie@example.com> | 2024-03-09 16:53:38 -0500 |
commit | afcae23cbf63b31a7ce111ffcd76c027b332bdf9 (patch) | |
tree | e86001041d05e13cb778ada13c5a3addccf93a8d | |
parent | 312ea44966ca5ee65185fc837d15143e7dd59761 (diff) |
Break entry/group/rule into sub-classes
-rw-r--r-- | CMakeLists.txt | 6 | ||||
-rw-r--r-- | src/assignmentList.cpp | 12 | ||||
-rw-r--r-- | src/edit_entry_form.cpp | 15 | ||||
-rw-r--r-- | src/edit_entry_form.h | 25 | ||||
-rw-r--r-- | src/entry.cpp | 73 | ||||
-rw-r--r-- | src/entry.h | 48 | ||||
-rw-r--r-- | src/entryLayout.cpp | 79 | ||||
-rw-r--r-- | src/entryLayout.h | 20 | ||||
-rw-r--r-- | src/group.cpp | 56 | ||||
-rw-r--r-- | src/group.h | 36 | ||||
-rw-r--r-- | src/groupLayout.cpp | 62 | ||||
-rw-r--r-- | src/groupLayout.h | 23 | ||||
-rw-r--r-- | src/rule.cpp | 32 | ||||
-rw-r--r-- | src/rule.h | 37 | ||||
-rw-r--r-- | src/ruleLayout.cpp | 38 | ||||
-rw-r--r-- | src/ruleLayout.h | 16 |
16 files changed, 344 insertions, 234 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index a8fd55c..2739256 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,9 +43,13 @@ set(project_sources "src/assignmentList.ui" "src/entry.cpp" "src/entry.h" + "src/entryLayout.cpp" + "src/entryLayout.h" "src/entry_form.ui" "src/group.cpp" "src/group.h" + "src/groupLayout.cpp" + "src/groupLayout.h" "src/group_form.ui" "src/lib.cpp" "src/lib.h" @@ -53,6 +57,8 @@ set(project_sources "src/preferences_dialog.ui" "src/rule.cpp" "src/rule.h" + "src/ruleLayout.cpp" + "src/ruleLayout.h" "src/settings.cpp" "src/settings.h" ) diff --git a/src/assignmentList.cpp b/src/assignmentList.cpp index 4e6dff9..15e6b47 100644 --- a/src/assignmentList.cpp +++ b/src/assignmentList.cpp @@ -15,6 +15,8 @@ #include "add_group_form.h" #include "assignmentList.h" #include "backend/db_sqlite.h" +#include "entryLayout.h" +#include "groupLayout.h" #include "settings.h" AssignmentList::AssignmentList() { @@ -67,6 +69,7 @@ void AssignmentList::displayWidgets() { QVBoxLayout *column_right = new QVBoxLayout(); BackendDB database; QList<Group *> groups = database.loadGroups(); + GroupLayout *new_group_layout; int i; // clear out old layouts if they exist @@ -74,9 +77,10 @@ void AssignmentList::displayWidgets() { for(i = 0; i < groups.size(); ++i) { if(groups[i]->hidden) continue; - groups[i]->addLayout(this->drawEntries(groups[i]->id)); // add entries to layout - if(groups[i]->column.toLower() == "left") column_left->addLayout(groups[i]); - else column_right->addLayout(groups[i]); + new_group_layout = new GroupLayout(*groups[i]); + new_group_layout->addLayout(this->drawEntries(groups[i]->id)); // add entries to layout + if(groups[i]->column.toLower() == "left") column_left->addLayout(new_group_layout); + else column_right->addLayout(new_group_layout); } column_left->addStretch(); @@ -99,7 +103,7 @@ QVBoxLayout *AssignmentList::drawEntries(int parent_id) { // skip if this entry is set to hidden if(entries[i]->hidden) continue; // TODO set right click behavior - output->addLayout(entries[i]); + output->addLayout(new EntryLayout(*entries[i])); } return output; diff --git a/src/edit_entry_form.cpp b/src/edit_entry_form.cpp new file mode 100644 index 0000000..6a28b6f --- /dev/null +++ b/src/edit_entry_form.cpp @@ -0,0 +1,15 @@ +#include "backend/db_sqlite.h" +#include "edit_entry_form.h" + +EditEntryForm::EditEntryForm(const Entry &e) : + e(e) +{ + // load uic + ui.setupUi(this); + + // set titles + this->setWindowTitle("Edit Entry"); + ui.title->setText("Edit Entry"); + + // widgets setup +} diff --git a/src/edit_entry_form.h b/src/edit_entry_form.h new file mode 100644 index 0000000..e038175 --- /dev/null +++ b/src/edit_entry_form.h @@ -0,0 +1,25 @@ +#ifndef EDITENTRYFORM_H +#define EDITENTRYFORM_H + +#include <QDialog> + +#include "entry.h" +#include "ui_entry_form.h" + +// form to edit/update an entry +class EditEntryForm : public QDialog { + Q_OBJECT + + public: + EditEntryForm(const Entry &e); + + private: + Ui::entryDialog ui; + + Entry e; + + private slots: + void accept(); +}; + +#endif diff --git a/src/entry.cpp b/src/entry.cpp index cdaa69a..4876641 100644 --- a/src/entry.cpp +++ b/src/entry.cpp @@ -1,5 +1,3 @@ -#include <QLabel> - #include "entry.h" Entry::Entry(int id, int parent_id, QString desc, QDateTime due, QString due_alt, QUrl link, QString color, QString highlight, bool done, bool hidden) : @@ -14,75 +12,4 @@ Entry::Entry(int id, int parent_id, QString desc, QDateTime due, QString due_alt done(done), hidden(hidden) { - QLabel *bullet = new QLabel(); - QLabel *body = new QLabel(); - - // set styling - this->setContentsMargins(2, 2, 2, 2); - - bullet->setFont(QFont("Arial", 11)); - bullet->setMaximumWidth(15); - - body->setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::LinksAccessibleByMouse); - body->setFont(QFont("Arial", 11)); - body->setWordWrap(true); - body->setToolTip("Right-Click for actions"); - - // Check rules - // TODO - - // set conditional styling - if(this->done) { - bullet->setText("\u2713"); - /* - bullet->setStyleSheet( - "QLabel {" - " color: green;" - "}" - ); - */ - } - else - bullet->setText("- "); - this->addWidget(bullet); - - if(!this->due.isNull()) - body->setText(this->due.toString("MM/dd/yyyy: ")); - else if(!this->due_alt.isEmpty()) - body->setText(this->due_alt + ": "); - - if(!this->link.isEmpty()) { - body->setOpenExternalLinks(true); - body->setText(body->text() + "<a href=\"" + this->link.toString() + "\" " "style=\"color: " + (this->color.isEmpty() ? "default" : this->color ) + ";\">"); - } - body->setText(body->text() + this->desc); - if(!this->link.isEmpty()) { - body->setText(body->text() + "</a>"); - body->setToolTip(this->link.toString()); - } - - if(this->done) { - QFont body_font = body->font(); - body_font.setStrikeOut(true); - body->setFont(body_font); - /* - body->setStyleSheet( - "QLabel {" - " color: green" - "}" - ); - */ - } - else { - /* - body->setStyleSheet( - "QLabel {" - " color: " + (this->color.isEmpty() ? "default" : this->color) + ";" - " background-color: " + (this->highlight.isEmpty() ? "none" : this->highlight) + ";" - " font-weight: " + (this->due.isValid() && this->due <= QDateTime::currentDateTime() ? "bold" : "normal") + ";" - ";" - ); - */ - } - this->addWidget(body); } diff --git a/src/entry.h b/src/entry.h index 32cfd1a..8f632f3 100644 --- a/src/entry.h +++ b/src/entry.h @@ -2,35 +2,33 @@ #define ENTRY_H #include <QDateTime> -#include <QHBoxLayout> #include <QString> #include <QUrl> -class Entry : public QHBoxLayout { - public: - int id; - int parent_id; - QString desc; - QDateTime due; - QString due_alt; - QUrl link; - QString color; // consider making this a QColor instead - QString highlight; // see color comment - bool done; - bool hidden; +struct Entry { + int id; + int parent_id; + QString desc; + QDateTime due; + QString due_alt; + QUrl link; + QString color; // consider making this a QColor instead + QString highlight; // see color comment + bool done; + bool hidden; - Entry( - int id, - int parent_id, - QString desc, - QDateTime due = QDateTime(), - QString due_alt = "", - QUrl link = QUrl(), - QString color = "", - QString highlight = "", - bool done = false, - bool hidden = false - ); + Entry( + int id, + int parent_id, + QString desc, + QDateTime due = QDateTime(), + QString due_alt = "", + QUrl link = QUrl(), + QString color = "", + QString highlight = "", + bool done = false, + bool hidden = false + ); }; #endif diff --git a/src/entryLayout.cpp b/src/entryLayout.cpp new file mode 100644 index 0000000..37f09a9 --- /dev/null +++ b/src/entryLayout.cpp @@ -0,0 +1,79 @@ +#include <QLabel> + +#include "entryLayout.h" + +EntryLayout::EntryLayout(const Entry &e) : + entry(e) +{ + QLabel *bullet = new QLabel(); + QLabel *body = new QLabel(); + + // set styling + this->setContentsMargins(2, 2, 2, 2); + + bullet->setFont(QFont("Arial", 11)); + bullet->setMaximumWidth(15); + + body->setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::LinksAccessibleByMouse); + body->setFont(QFont("Arial", 11)); + body->setWordWrap(true); + body->setToolTip("Right-Click for actions"); + + // Check rules + // TODO + + // set conditional styling + if(this->entry.done) { + bullet->setText("\u2713"); + /* + bullet->setStyleSheet( + "QLabel {" + " color: green;" + "}" + ); + */ + } + else + bullet->setText("- "); + this->addWidget(bullet); + + if(!this->entry.due.isNull()) + body->setText(this->entry.due.toString("MM/dd/yyyy: ")); + else if(!this->entry.due_alt.isEmpty()) + body->setText(this->entry.due_alt + ": "); + + if(!this->entry.link.isEmpty()) { + body->setOpenExternalLinks(true); + body->setText(body->text() + "<a href=\"" + this->entry.link.toString() + "\" " "style=\"color: " + (this->entry.color.isEmpty() ? "default" : this->entry.color ) + ";\">"); + } + body->setText(body->text() + this->entry.desc); + if(!this->entry.link.isEmpty()) { + body->setText(body->text() + "</a>"); + body->setToolTip(this->entry.link.toString()); + } + + if(this->entry.done) { + QFont body_font = body->font(); + body_font.setStrikeOut(true); + body->setFont(body_font); + /* + body->setStyleSheet( + "QLabel {" + " color: green" + "}" + ); + */ + } + else { + /* + body->setStyleSheet( + "QLabel {" + " color: " + (this->color.isEmpty() ? "default" : this->color) + ";" + " background-color: " + (this->highlight.isEmpty() ? "none" : this->highlight) + ";" + " font-weight: " + (this->due.isValid() && this->due <= QDateTime::currentDateTime() ? "bold" : "normal") + ";" + ";" + ); + */ + } + this->addWidget(body); +} diff --git a/src/entryLayout.h b/src/entryLayout.h new file mode 100644 index 0000000..fb4902b --- /dev/null +++ b/src/entryLayout.h @@ -0,0 +1,20 @@ +#ifndef ENTRYLAYOUT_H +#define ENTRYLAYOUT_H + +#include <QDateTime> +#include <QHBoxLayout> +#include <QString> +#include <QUrl> + +#include "entry.h" + +class EntryLayout : public QHBoxLayout { + Q_OBJECT + + public: + Entry entry; + + EntryLayout(const Entry &e); +}; + +#endif diff --git a/src/group.cpp b/src/group.cpp index 1757753..d1c257f 100644 --- a/src/group.cpp +++ b/src/group.cpp @@ -1,12 +1,4 @@ -#include <QLabel> -#include <QMenu> -#include <QString> - -#include <QDebug> - -#include "add_entry_form.h" #include "group.h" -#include "lib.h" Group::Group(int id, QString name, QString column, QString link, bool hidden) : id(id), @@ -15,52 +7,4 @@ Group::Group(int id, QString name, QString column, QString link, bool hidden) : link(link), hidden(hidden) { - this->setContentsMargins(0, 10, 0, 10); - - QLabel *name_label = new QLabel(this->name); - name_label->setTextInteractionFlags(Qt::TextSelectableByMouse); - name_label->setToolTip("Right-Click for actions"); - name_label->setContextMenuPolicy(Qt::CustomContextMenu); - //name_label->customContextMenuRequested(const QPoint &pos) - QObject::connect(name_label, - SIGNAL(customContextMenuRequested(const QPoint &)), - SLOT(showContextMenu())); - - QFont name_font = QFont("Arial", 13); - name_font.setUnderline(true); - name_label->setFont(name_font); - - this->addWidget(name_label); -} - -void Group::showContextMenu() { - QMenu menu; - - QAction *add_entry_act = new QAction("Add Entry"); - QObject::connect(add_entry_act, &QAction::triggered, this, &Group::addEntry); - menu.addAction(add_entry_act); - - QAction *edit_group_act = new QAction("Edit Group"); - QObject::connect(edit_group_act, &QAction::triggered, this, &Group::editGroup); - menu.addAction(edit_group_act); - - QAction *del_group_act = new QAction("Remove Group"); - QObject::connect(del_group_act, &QAction::triggered, this, &Group::removeGroup); - menu.addAction(del_group_act); - - menu.exec(QCursor::pos()); -} - -void Group::addEntry() { - AddEntryForm create_new_entry_dialog(this->id); - if(create_new_entry_dialog.exec() == QDialog::Accepted) - getMainWindow()->displayWidgets(); -} - -void Group::editGroup() { - qDebug() << "WIP"; -} - -void Group::removeGroup() { - qDebug() << "WIP"; } diff --git a/src/group.h b/src/group.h index 370cbb2..ef23320 100644 --- a/src/group.h +++ b/src/group.h @@ -2,31 +2,21 @@ #define GROUP_H #include <QString> -#include <QVBoxLayout> -class Group : public QVBoxLayout { - Q_OBJECT +struct Group { + int id; + QString name; + QString column; + QString link; + bool hidden; - public: - int id; - QString name; - QString column; - QString link; - bool hidden; - - Group( - int id, - QString name, - QString column = "left", - QString link = "", - bool hidden = false - ); - - private slots: - void showContextMenu(); - void addEntry(); - void editGroup(); - void removeGroup(); + Group( + int id, + QString name, + QString column = "left", + QString link = "", + bool hidden = false + ); }; #endif diff --git a/src/groupLayout.cpp b/src/groupLayout.cpp new file mode 100644 index 0000000..d2bc82a --- /dev/null +++ b/src/groupLayout.cpp @@ -0,0 +1,62 @@ +#include <QLabel> +#include <QMenu> +#include <QString> + +#include <QDebug> + +#include "add_entry_form.h" +#include "groupLayout.h" +#include "lib.h" + +GroupLayout::GroupLayout(const Group &g) : + group(g) +{ + this->setContentsMargins(0, 10, 0, 10); + + QLabel *name_label = new QLabel(this->group.name); + name_label->setTextInteractionFlags(Qt::TextSelectableByMouse); + name_label->setToolTip("Right-Click for actions"); + name_label->setContextMenuPolicy(Qt::CustomContextMenu); + //name_label->customContextMenuRequested(const QPoint &pos) + QObject::connect(name_label, + SIGNAL(customContextMenuRequested(const QPoint &)), + SLOT(showContextMenu())); + + QFont name_font = QFont("Arial", 13); + name_font.setUnderline(true); + name_label->setFont(name_font); + + this->addWidget(name_label); +} + +void GroupLayout::showContextMenu() { + QMenu menu; + + QAction *add_entry_act = new QAction("Add Entry"); + QObject::connect(add_entry_act, &QAction::triggered, this, &GroupLayout::addEntry); + menu.addAction(add_entry_act); + + QAction *edit_group_act = new QAction("Edit Group"); + QObject::connect(edit_group_act, &QAction::triggered, this, &GroupLayout::editGroup); + menu.addAction(edit_group_act); + + QAction *del_group_act = new QAction("Remove Group"); + QObject::connect(del_group_act, &QAction::triggered, this, &GroupLayout::removeGroup); + menu.addAction(del_group_act); + + menu.exec(QCursor::pos()); +} + +void GroupLayout::addEntry() { + AddEntryForm create_new_entry_dialog(this->group.id); + if(create_new_entry_dialog.exec() == QDialog::Accepted) + getMainWindow()->displayWidgets(); +} + +void GroupLayout::editGroup() { + qDebug() << "WIP"; +} + +void GroupLayout::removeGroup() { + qDebug() << "WIP"; +} diff --git a/src/groupLayout.h b/src/groupLayout.h new file mode 100644 index 0000000..cfd33cf --- /dev/null +++ b/src/groupLayout.h @@ -0,0 +1,23 @@ +#ifndef GROUPLAYOUT_H +#define GROUPLAYOUT_H + +#include <QVBoxLayout> + +#include "group.h" + +class GroupLayout : public QVBoxLayout { + Q_OBJECT + + public: + Group group; + + GroupLayout(const Group &g); + + private slots: + void showContextMenu(); + void addEntry(); + void editGroup(); + void removeGroup(); +}; + +#endif diff --git a/src/rule.cpp b/src/rule.cpp index 7cfcff2..d90a0db 100644 --- a/src/rule.cpp +++ b/src/rule.cpp @@ -1,8 +1,3 @@ -#include <QComboBox> -#include <QDate> -#include <QDateTimeEdit> -#include <QLineEdit> - #include "rule.h" Rule::Rule(int id, int entry_id, When when, QDateTime date, QString color, QString highlight) : @@ -13,31 +8,4 @@ Rule::Rule(int id, int entry_id, When when, QDateTime date, QString color, QStri color(color), highlight(highlight) { - QComboBox *when_widget = new QComboBox; - QDateTimeEdit *date_widget = new QDateTimeEdit(QDate::currentDate()); - QLineEdit *color_widget = new QLineEdit; // TODO consider making this a color selector widget - QLineEdit *highlight_widget = new QLineEdit; // TODO consider making this a color selector widget - - QStringList when_options; - when_options.append("Before"); - when_options.append("After"); - when_widget->addItems(when_options); - when_widget->setCurrentIndex(this->when); - this->addWidget(when_widget); - - date_widget->setDisplayFormat("MM/dd/yyyy"); - date_widget->setDateTime(this->date); - this->addWidget(date_widget); - - this->addStretch(); - - color_widget->setPlaceholderText("Color"); - if(!this->color.isEmpty()) - color_widget->setText(this->color); - this->addWidget(color_widget); - - highlight_widget->setPlaceholderText("Highlight"); - if(!this->highlight.isEmpty()) - highlight_widget->setText(this->highlight); - this->addWidget(highlight_widget); } @@ -2,30 +2,25 @@ #define RULE_H #include <QDateTime> -#include <QHBoxLayout> #include <QString> -// rule's widgets will always be allocated, even though they are only rendered when options are open -// TODO determine whether an alternative approach is better (same goes for group and entry) +struct Rule { + enum When { before, after }; + int id; + int entry_id; + When when; + QDateTime date; + QString color = ""; + QString highlight = ""; -class Rule : QHBoxLayout { - public: - enum When { before, after }; - int id; - int entry_id; - When when; - QDateTime date; - QString color = ""; - QString highlight = ""; - - Rule( - int id, - int entry_id, - When when, - QDateTime date, - QString color, - QString highlight - ); + Rule( + int id, + int entry_id, + When when, + QDateTime date, + QString color, + QString highlight + ); }; #endif diff --git a/src/ruleLayout.cpp b/src/ruleLayout.cpp new file mode 100644 index 0000000..f922f1a --- /dev/null +++ b/src/ruleLayout.cpp @@ -0,0 +1,38 @@ +#include <QComboBox> +#include <QDate> +#include <QDateTimeEdit> +#include <QLineEdit> + +#include "ruleLayout.h" + +RuleLayout::RuleLayout(const Rule &r) : + rule(r) +{ + QComboBox *when_widget = new QComboBox; + QDateTimeEdit *date_widget = new QDateTimeEdit(QDate::currentDate()); + QLineEdit *color_widget = new QLineEdit; // TODO consider making this a color selector widget + QLineEdit *highlight_widget = new QLineEdit; // TODO consider making this a color selector widget + + QStringList when_options; + when_options.append("Before"); + when_options.append("After"); + when_widget->addItems(when_options); + when_widget->setCurrentIndex(this->rule.when); + this->addWidget(when_widget); + + date_widget->setDisplayFormat("MM/dd/yyyy"); + date_widget->setDateTime(this->rule.date); + this->addWidget(date_widget); + + this->addStretch(); + + color_widget->setPlaceholderText("Color"); + if(!this->rule.color.isEmpty()) + color_widget->setText(this->rule.color); + this->addWidget(color_widget); + + highlight_widget->setPlaceholderText("Highlight"); + if(!this->rule.highlight.isEmpty()) + highlight_widget->setText(this->rule.highlight); + this->addWidget(highlight_widget); +} diff --git a/src/ruleLayout.h b/src/ruleLayout.h new file mode 100644 index 0000000..45aafc1 --- /dev/null +++ b/src/ruleLayout.h @@ -0,0 +1,16 @@ +#ifndef RULELAYOUT_H +#define RULELAYOUT_H + +#include <QHBoxLayout> + +#include "rule.h" + +// TODO consider getting rid of this class (unneccesary) +class RuleLayout : QHBoxLayout { + public: + Rule rule; + + RuleLayout(const Rule &r); +}; + +#endif |