summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLouie S <louie@example.com>2024-02-21 20:43:58 -0500
committerLouie S <louie@example.com>2024-02-21 20:43:58 -0500
commite659d5be0974fab8c1cbfad4dbe9c680dfa6f374 (patch)
treef9084777019e4d8a3ad4b4293b652dc2f2919f49
parent5d1fbe2c839aa33d3855a29efc628e49a17b95f4 (diff)
Create rule class
-rw-r--r--CMakeLists.txt2
-rw-r--r--src/rule.cpp40
-rw-r--r--src/rule.h32
3 files changed, 74 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index c623193..feec929 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -42,6 +42,8 @@ set(project_sources
"src/group.h"
"src/main.cpp"
"src/preferences_dialog.ui"
+ "src/rule.cpp"
+ "src/rule.h"
"src/settings.cpp"
"src/settings.h"
)
diff --git a/src/rule.cpp b/src/rule.cpp
new file mode 100644
index 0000000..93c33d6
--- /dev/null
+++ b/src/rule.cpp
@@ -0,0 +1,40 @@
+#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) :
+ id(id),
+ entry_id(entry_id),
+ when(when),
+ date(date),
+ color(color),
+ highlight(highlight)
+{
+ QComboBox *when_widget;
+ QDateTimeEdit *date_widget = new QDateTimeEdit(QDate::currentDate());
+ QLineEdit *color_widget; // TODO consider making this a color selector widget
+ QLineEdit *highlight_widget; // TODO consider making this a color selector widget
+
+ when_widget->addItems(QStringList("Before", "After"));
+ 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);
+}
diff --git a/src/rule.h b/src/rule.h
new file mode 100644
index 0000000..ecd2285
--- /dev/null
+++ b/src/rule.h
@@ -0,0 +1,32 @@
+#ifndef RULE_H
+#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)
+
+class Rule : QHBoxLayout {
+ enum When { before, after };
+
+ public:
+ 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