summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLouie S <louie@example.com>2024-03-15 16:12:05 -0400
committerLouie S <louie@example.com>2024-03-15 16:12:05 -0400
commit4c2c8bc81df55ab2f0112d16bfd1a9d236b51e6d (patch)
tree1b44d7e3cf55d22582bd697dce792f7994d3f616 /src
parentd732bd0f74225828455c5863444b0211faf586d0 (diff)
Load and apply rules to entries
Diffstat (limited to 'src')
-rw-r--r--src/assignmentList.cpp2
-rw-r--r--src/backend/db_sqlite.cpp4
-rw-r--r--src/entryLayout.cpp22
-rw-r--r--src/entryLayout.h4
4 files changed, 27 insertions, 5 deletions
diff --git a/src/assignmentList.cpp b/src/assignmentList.cpp
index 673e0b5..a883523 100644
--- a/src/assignmentList.cpp
+++ b/src/assignmentList.cpp
@@ -103,10 +103,10 @@ QVBoxLayout *AssignmentList::drawEntries(int parent_id) {
// styling
output->setContentsMargins(5, 0, 0, 0);
+ // TODO sort entries
for(i = 0; i < entries.size(); ++i) {
// skip if this entry is set to hidden
if(entries[i]->hidden) continue;
- // TODO set right click behavior
output->addLayout(new EntryLayout(*entries[i]));
}
diff --git a/src/backend/db_sqlite.cpp b/src/backend/db_sqlite.cpp
index f48089b..4e62153 100644
--- a/src/backend/db_sqlite.cpp
+++ b/src/backend/db_sqlite.cpp
@@ -358,7 +358,6 @@ int BackendDB::removeEntry(const Entry &entry) {
query.bindValue(0, entry.id);
query.exec();
- // FIXME not sure if this also needs to be called after the first query...
output = query.numRowsAffected();
}
@@ -378,7 +377,6 @@ int BackendDB::removeRule(const Rule &rule) {
query.bindValue(0, rule.id);
query.exec();
- // FIXME not sure if this also needs to be called after the first query...
output = query.numRowsAffected();
}
@@ -418,7 +416,7 @@ QSqlDatabase BackendDB::openDB() {
database.open();
if(database.isOpenError()) {
- // FIXME end-user friendly error message
+ // TODO end-user friendly error message
qDebug() << database.lastError();
std::exit(1);
}
diff --git a/src/entryLayout.cpp b/src/entryLayout.cpp
index 54aa5f8..349a102 100644
--- a/src/entryLayout.cpp
+++ b/src/entryLayout.cpp
@@ -14,6 +14,7 @@ EntryLayout::EntryLayout(const Entry &e) :
{
QLabel *bullet = new QLabel();
QLabel *body = new QLabel();
+ int i;
// set styling
this->setContentsMargins(2, 2, 2, 2);
@@ -34,7 +35,20 @@ EntryLayout::EntryLayout(const Entry &e) :
SLOT(showContextMenu()));
// Check rules
- // TODO
+ QList<Rule *> rules = this->loadRules();
+ for(i = 0; i < rules.size(); ++i) {
+ if(
+ (rules[i]->when == Rule::before &&
+ rules[i]->date > QDateTime::currentDateTime()) ||
+ (rules[i]->when == Rule::after &&
+ rules[i]->date <= QDateTime::currentDateTime())
+ ) {
+ if(!rules[i]->color.isEmpty())
+ this->entry.color = rules[i]->color;
+ if(!rules[i]->highlight.isEmpty())
+ this->entry.highlight = rules[i]->highlight;
+ }
+ }
// set conditional styling
if(this->entry.done) {
@@ -87,6 +101,12 @@ EntryLayout::EntryLayout(const Entry &e) :
this->addWidget(body);
}
+QList<Rule *> EntryLayout::loadRules() {
+ BackendDB database;
+
+ return database.loadRules(this->entry.id);
+}
+
void EntryLayout::showContextMenu() {
QMenu menu;
diff --git a/src/entryLayout.h b/src/entryLayout.h
index 1a4146b..df19a18 100644
--- a/src/entryLayout.h
+++ b/src/entryLayout.h
@@ -7,6 +7,7 @@
#include <QUrl>
#include "entry.h"
+#include "rule.h"
class EntryLayout : public QHBoxLayout {
Q_OBJECT
@@ -16,6 +17,9 @@ class EntryLayout : public QHBoxLayout {
EntryLayout(const Entry &e);
+ private:
+ QList<Rule *> loadRules();
+
private slots:
void showContextMenu();
void editEntry();