From a276acd4e0c8031fdef41f11a4fa2285b671207d Mon Sep 17 00:00:00 2001 From: Louie S Date: Mon, 19 Feb 2024 15:58:23 -0500 Subject: Set config creation --- src/assignmentList.cpp | 24 +++++- src/assignmentList.h | 7 +- src/assignmentList.ui | 207 ++++++++++++++++++++++++++++++++++++++++++++++++ src/backend/db_sqlite.h | 53 +++++++++++++ src/main.ui | 207 ------------------------------------------------ src/settings.cpp | 14 ++++ src/settings.h | 8 ++ 7 files changed, 309 insertions(+), 211 deletions(-) create mode 100644 src/assignmentList.ui create mode 100644 src/backend/db_sqlite.h delete mode 100644 src/main.ui create mode 100644 src/settings.cpp create mode 100644 src/settings.h (limited to 'src') diff --git a/src/assignmentList.cpp b/src/assignmentList.cpp index c8da5c3..91c4716 100644 --- a/src/assignmentList.cpp +++ b/src/assignmentList.cpp @@ -1,25 +1,43 @@ #include #include +#include #include #include #include #include +#include #include #include +#include #include "assignmentList.h" +#include "settings.h" AssignmentList::AssignmentList() { + // set QSettings information + QCoreApplication::setOrganizationName("assignment-list-qt"); // TODO grab this from a config.h type file + QCoreApplication::setApplicationName("assignment-list-qt"); // TODO grab this from a config.h type file + + // ensure QSettings location exists + this->initializeSettings(); + // load uic - QFile file("/home/louie/Development/projects/assignment-list-qt/src/main.ui"); - file.open(QIODevice::ReadOnly); - QUiLoader loader; ui.setupUi(this); this->initializeUI(); } +void AssignmentList::initializeSettings() { + QSettings settings; + QFile path = settings.fileName(); + + if(!path.exists()) { + qDebug() << "Creating Config"; + Settings::createConfig(); + } +} + void AssignmentList::initializeUI() { // create menu connections QObject::connect(ui.actionPreferences, &QAction::triggered, this, &AssignmentList::preferences); diff --git a/src/assignmentList.h b/src/assignmentList.h index 8171d73..5df18e9 100644 --- a/src/assignmentList.h +++ b/src/assignmentList.h @@ -2,17 +2,22 @@ #define ASSIGNMENTLIST_H #include -#include "ui_main.h" +#include + +#include "ui_assignmentList.h" class AssignmentList : public QMainWindow { Q_OBJECT public: + QSettings configuration; + AssignmentList(); private: Ui::MainWindow ui; + void initializeSettings(); void initializeUI(); void setupDB(); void displayWidgets(); diff --git a/src/assignmentList.ui b/src/assignmentList.ui new file mode 100644 index 0000000..bc3c0fb --- /dev/null +++ b/src/assignmentList.ui @@ -0,0 +1,207 @@ + + + MainWindow + + + + 0 + 0 + 640 + 480 + + + + Assignment List + + + + + + + true + + + + + 0 + 0 + 620 + 421 + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + Arial + 17 + + + + [DATE] + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + 20 + + + 5 + + + 20 + + + 5 + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + + + + + 0 + 0 + 640 + 22 + + + + + File + + + + + + + + + Edit + + + + + + + + Help + + + + + + + + + + toolBar + + + TopToolBarArea + + + false + + + + + Preferences + + + Alt+Return + + + + + Reload + + + F5 + + + + + Exit + + + Ctrl+Q + + + + + Add Group + + + + + Permanently Delete Removed Groups and Entries + + + + + About + + + + + + diff --git a/src/backend/db_sqlite.h b/src/backend/db_sqlite.h new file mode 100644 index 0000000..5c55fef --- /dev/null +++ b/src/backend/db_sqlite.h @@ -0,0 +1,53 @@ +#ifndef BACKEND_DB_SQLITE_H +#define BACKEND_DB_SQLITE_H + +#include + +class BackendDB { + public: + void init(); + void load(); + void insertGroup(int new_group); // param datatype TBD + void insertEntry(int new_entry); // param datatype TBD + void 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 + void removeGroup(int group); // param datatype TBD + void removeEntry(int entry); // param datatype TBD + void removeRule(int rule); // param datatype TBD + void cleanHidden(); + + private: + const QStringList create_table_queries = { + "CREATE TABLE groups (" + "id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE NOT NULL," + "name VARCHAR(255) NOT NULL," + "column TINYINT(1) DEFAULT FALSE," + "link VARCHAR(255) NOT NULL," + "hidden TINYINT(1) DEFAULT FALSE" + ")", + "CREATE TABLE entries (" + "id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE NOT NULL," + "parent_id REFERENCES groups (id)," + "description VARCHAR(255) NOT NULL," + "due_date TEXT DEFAULT NULL," + "alt_due_date VARCHAR(255) DEFAULT NULL," + "link VARCHAR(255) DEFAULT NULL," + "color VARCHAR(255) DEFAULT NULL," + "highlight VARCHAR(255) DEFAULT NULL," + "done TINYINT(1) DEFAULT FALSE," + "hidden TINYINT(1) DEFAULT FALSE" + ")", + "CREATE TABLE rules (" + "id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE NOT NULL," + "entry_id REFERENCES entries (id)," + "before_after TINYINT(1) DEFAULT TRUE," + "date TEXT NOT NULL," + "color VARCHAR(255) DEFAULT NULL," + "highlight VARCHAR(255) DEFAULT NULL" + ")" + }; +}; + +#endif diff --git a/src/main.ui b/src/main.ui deleted file mode 100644 index bc3c0fb..0000000 --- a/src/main.ui +++ /dev/null @@ -1,207 +0,0 @@ - - - MainWindow - - - - 0 - 0 - 640 - 480 - - - - Assignment List - - - - - - - true - - - - - 0 - 0 - 620 - 421 - - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - Arial - 17 - - - - [DATE] - - - Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - 20 - - - 5 - - - 20 - - - 5 - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - - - - - - - 0 - 0 - 640 - 22 - - - - - File - - - - - - - - - Edit - - - - - - - - Help - - - - - - - - - - toolBar - - - TopToolBarArea - - - false - - - - - Preferences - - - Alt+Return - - - - - Reload - - - F5 - - - - - Exit - - - Ctrl+Q - - - - - Add Group - - - - - Permanently Delete Removed Groups and Entries - - - - - About - - - - - - diff --git a/src/settings.cpp b/src/settings.cpp new file mode 100644 index 0000000..4fe67d1 --- /dev/null +++ b/src/settings.cpp @@ -0,0 +1,14 @@ +#include +#include +#include + +#include "settings.h" + +void Settings::createConfig() { + QSettings settings; + QDir local_data_dir(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation)); + + settings.beginGroup("paths"); + settings.setValue("db_path", local_data_dir.filePath("data.db")); + settings.endGroup(); +} diff --git a/src/settings.h b/src/settings.h new file mode 100644 index 0000000..bec3c22 --- /dev/null +++ b/src/settings.h @@ -0,0 +1,8 @@ +#ifndef SETTINGS_H +#define SETTINGS_H + +namespace Settings { + void createConfig(); +}; + +#endif -- cgit