From e94de73eb381eac6880998bcf602f8b60010c8f9 Mon Sep 17 00:00:00 2001 From: Nicolas Mailloux Date: Tue, 13 Sep 2022 23:03:51 -0400 Subject: [PATCH] To-Do app: Progress --- src/apps/todo.cpp | 62 +++++++++++++++++++++++++++++++++++------------ src/apps/todo.h | 4 +++ src/apps/todo.ui | 57 ++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 107 insertions(+), 16 deletions(-) diff --git a/src/apps/todo.cpp b/src/apps/todo.cpp index 035df60..8f74179 100644 --- a/src/apps/todo.cpp +++ b/src/apps/todo.cpp @@ -13,8 +13,14 @@ todo::todo(QWidget *parent) : ui->closeBtn->setProperty("type", "borderless"); ui->newListBtn->setProperty("type", "borderless"); + ui->deleteBtn->setProperty("type", "borderless"); + ui->setupBtn->setProperty("type", "borderless"); + ui->deleteBtn->setStyleSheet("padding: 10px"); + ui->setupBtn->setStyleSheet("padding: 10px"); ui->closeBtn->setIcon(QIcon(":/resources/close.png")); ui->newListBtn->setIcon(QIcon(":/resources/new.png")); + ui->deleteBtn->setIcon(QIcon(":/resources/x-circle.png")); + ui->setupBtn->setIcon(QIcon(":/resources/arrow-right.png")); refreshList(); } @@ -43,23 +49,20 @@ void todo::on_newListBtn_clicked() void todo::createNewList(QString listName) { log("Initializing new To-Do list with name '" + listName + "'", className); QJsonDocument document; - int index = 0; + QJsonArray mainArray; + QJsonArray listArray; + QJsonObject object; if(QFile::exists(global::localLibrary::todoDatabasePath)) { document = readTodoDatabase(); - QJsonObject object = document.object(); - index = object.length(); - if(!(index <= object[QString::number(index)].toObject().value("Name").toInt())) { - // TODO - index++; - } + object = document.object(); + mainArray = object["List"].toArray(); } - QJsonObject mainObject = document.object(); - QJsonObject listObject; + listArray.append(listName); - listObject.insert("Name", listName); - mainObject.insert(QString::number(index), listObject); + mainArray.push_back(listArray); + object["List"] = mainArray; - document.setObject(mainObject); + document.setObject(object); writeTodoDatabase(document); ui->statusLabel->setText("Select or create a new list"); @@ -69,12 +72,41 @@ void todo::createNewList(QString listName) { void todo::refreshList() { if(QFile::exists(global::localLibrary::todoDatabasePath)) { ui->listWidget->clear(); - QJsonObject mainObject = readTodoDatabase().object(); - for(int i = 0; i < mainObject.length(); i++) { - QString name = mainObject[QString::number(i)].toObject().value("Name").toString(); + QJsonArray array = readTodoDatabase().object()["List"].toArray(); + for(int i = 0; i < array.count(); i++) { + QString name = array.at(i).toArray().at(0).toString(); if(!name.isEmpty()) { ui->listWidget->addItem(name); } } } } + +void todo::setupList(QString listName) { + log("Setting up list with name '" + listName + "'", className); + QJsonArray array = readTodoDatabase().object()["List"].toArray(); + int index; + for(int i = 0; i < array.count(); i++) { + QString name = array.at(i).toArray().at(0).toString(); + log("name is " + name); + if(name == listName) { + index = i; + break; + } + } + log("List index is " + QString::number(index), className); +} + +void todo::on_setupBtn_clicked() +{ + ui->deleteBtn->setEnabled(false); + ui->setupBtn->setEnabled(false); + setupList(ui->listWidget->currentItem()->text()); +} + + +void todo::on_listWidget_itemClicked(QListWidgetItem *item) +{ + ui->deleteBtn->setEnabled(true); + ui->setupBtn->setEnabled(true); +} diff --git a/src/apps/todo.h b/src/apps/todo.h index b7089be..1ee9244 100644 --- a/src/apps/todo.h +++ b/src/apps/todo.h @@ -2,6 +2,7 @@ #define TODO_H #include +#include #include "virtualkeyboard.h" @@ -23,6 +24,9 @@ private slots: void on_newListBtn_clicked(); void createNewList(QString listName); void refreshList(); + void setupList(QString listName); + void on_setupBtn_clicked(); + void on_listWidget_itemClicked(QListWidgetItem *item); private: Ui::todo *ui; diff --git a/src/apps/todo.ui b/src/apps/todo.ui index 222a2af..55b80c7 100644 --- a/src/apps/todo.ui +++ b/src/apps/todo.ui @@ -115,6 +115,9 @@ + + 0 + @@ -159,13 +162,65 @@ + + + + 0 + + + 0 + + + + + + + + + + + + QFrame::Plain + + + Qt::Vertical + + + + + + + + + + + + - + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + +