From 621dca8c41921950d2c24eb83d848cd7965a7209 Mon Sep 17 00:00:00 2001 From: Nicolas Mailloux Date: Thu, 15 Sep 2022 08:28:03 -0400 Subject: [PATCH] To-Do app: Improvements --- src/apps/apps.cpp | 1 + src/apps/todo.cpp | 65 +++++++++++++++++++++++++++++++++++++---------- src/apps/todo.h | 5 ++++ src/apps/todo.ui | 36 +++++++++++++++++++++++++- src/eink.qrc | 2 ++ 5 files changed, 94 insertions(+), 15 deletions(-) diff --git a/src/apps/apps.cpp b/src/apps/apps.cpp index 669391a..4af96f7 100644 --- a/src/apps/apps.cpp +++ b/src/apps/apps.cpp @@ -398,6 +398,7 @@ void apps::showFailedToParseMainUserAppsJsonFile() { void apps::on_todoLaunchBtn_clicked() { todo * todoWindow = new todo(); + QObject::connect(todoWindow, &todo::showToast, this, &apps::showToast); todoWindow->setAttribute(Qt::WA_DeleteOnClose); todoWindow->setGeometry(QRect(QPoint(0,0), qApp->primaryScreen()->geometry().size())); todoWindow->show(); diff --git a/src/apps/todo.cpp b/src/apps/todo.cpp index 48e0a75..77cc74c 100644 --- a/src/apps/todo.cpp +++ b/src/apps/todo.cpp @@ -24,12 +24,16 @@ todo::todo(QWidget *parent) : ui->deleteItemBtn->setProperty("type", "borderless"); ui->selectAllItemsBtn->setProperty("type", "borderless"); ui->selectItemsModeBtn->setProperty("type", "borderless"); + ui->deselectAllItemsBtn->setProperty("type", "borderless"); + ui->saveCurrentListViewBtn->setProperty("type", "borderless"); ui->deleteBtn->setStyleSheet("padding: 10px"); ui->setupBtn->setStyleSheet("padding: 10px"); ui->newItemBtn->setStyleSheet("padding: 10px"); ui->deleteItemBtn->setStyleSheet("padding: 10px"); ui->selectAllItemsBtn->setStyleSheet("padding: 10px"); ui->selectItemsModeBtn->setStyleSheet("padding: 10px"); + ui->deselectAllItemsBtn->setStyleSheet("padding: 10px"); + ui->saveCurrentListViewBtn->setStyleSheet("padding: 10px"); ui->closeBtn->setIcon(QIcon(":/resources/close.png")); ui->newBtn->setIcon(QIcon(":/resources/new.png")); ui->newItemBtn->setIcon(QIcon(":/resources/plus.png")); @@ -38,6 +42,8 @@ todo::todo(QWidget *parent) : ui->deleteItemBtn->setIcon(QIcon(":/resources/x-circle.png")); ui->selectAllItemsBtn->setIcon(QIcon(":/resources/checkbox-checked-small.png")); ui->selectItemsModeBtn->setIcon(QIcon(":/resources/checkbox-unchecked-small.png")); + ui->deselectAllItemsBtn->setIcon(QIcon(":/resources/checkbox-x-small.png")); + ui->saveCurrentListViewBtn->setIcon(QIcon(":/resources/save.png")); ui->listWidget->setStyleSheet("font-size: 10pt"); ui->listWidget->setWordWrap(true); ui->itemsListWidget->setStyleSheet("font-size: 10pt"); @@ -290,27 +296,44 @@ void todo::switchItemsSelectionMode(bool selectionMode) { void todo::on_deleteItemBtn_clicked() { - log("Deleting list item(s)", className); - QJsonDocument document = readTodoDatabase(); - QJsonObject object = document.object(); - QJsonArray mainArray = object["List"].toArray(); - QJsonArray listArray = mainArray.at(listIndex).toArray(); - int itemsRemoved = 0; + QList itemsToDelete; for(int i = 1; i < ui->itemsListWidget->count() + 1; i++) { if(ui->itemsListWidget->item(i - 1)->checkState() == Qt::Checked) { - listArray.removeAt(i - itemsRemoved); - itemsRemoved++; + itemsToDelete.append(i); } } - // Adding item array to list array - mainArray.replace(listIndex, listArray); - object["List"] = mainArray; + if(!itemsToDelete.isEmpty()) { + QString itemsToDeleteString; + for(int i = 0; i < itemsToDelete.count(); i++) { + itemsToDeleteString.append(QString::number(itemsToDelete[i])); + if(i < itemsToDelete.count() - 1) { + itemsToDeleteString.append(", "); + } + } + log("Deleting list item(s) " + itemsToDeleteString, className); + QJsonDocument document = readTodoDatabase(); + QJsonObject object = document.object(); + QJsonArray mainArray = object["List"].toArray(); + QJsonArray listArray = mainArray.at(listIndex).toArray(); + int itemsRemoved = 0; + for(int i = 0; i < itemsToDelete.count(); i++) { + listArray.removeAt(itemsToDelete.at(i) - itemsRemoved); + itemsRemoved++; + } - document.setObject(object); - writeTodoDatabase(document); + // Adding item array to list array + mainArray.replace(listIndex, listArray); + object["List"] = mainArray; - setupList(listArray.at(0).toString()); + document.setObject(object); + writeTodoDatabase(document); + + setupList(listArray.at(0).toString()); + } + else { + emit showToast("No item(s) selected"); + } } void todo::on_selectAllItemsBtn_clicked() @@ -328,3 +351,17 @@ void todo::setDefaultHomePageStatusText() { void todo::setDefaultListPageStatusText() { ui->statusLabel->setText("Select or create a new item"); } + +void todo::on_deselectAllItemsBtn_clicked() +{ + int range = ui->itemsListWidget->count(); + for(int i = 0; i < range; i++) { + ui->itemsListWidget->item(i)->setCheckState(Qt::Unchecked); + } +} + +void todo::on_saveCurrentListViewBtn_clicked() +{ + saveCurrentList(); + switchItemsSelectionMode(false); +} diff --git a/src/apps/todo.h b/src/apps/todo.h index b8d38e1..f4a4881 100644 --- a/src/apps/todo.h +++ b/src/apps/todo.h @@ -45,6 +45,11 @@ private slots: void on_selectItemsModeBtn_clicked(); void on_deleteItemBtn_clicked(); void on_selectAllItemsBtn_clicked(); + void on_deselectAllItemsBtn_clicked(); + void on_saveCurrentListViewBtn_clicked(); + +signals: + void showToast(QString messageToDisplay); private: Ui::todo *ui; diff --git a/src/apps/todo.ui b/src/apps/todo.ui index 568282d..67c5f40 100644 --- a/src/apps/todo.ui +++ b/src/apps/todo.ui @@ -6,7 +6,7 @@ 0 0 - 400 + 483 300 @@ -309,6 +309,40 @@ + + + + QFrame::Plain + + + Qt::Vertical + + + + + + + + + + + + + + QFrame::Plain + + + Qt::Vertical + + + + + + + + + + diff --git a/src/eink.qrc b/src/eink.qrc index 358328c..50965c7 100644 --- a/src/eink.qrc +++ b/src/eink.qrc @@ -101,5 +101,7 @@ resources/new.png resources/checkbox-unchecked-small.png resources/checkbox-checked-small.png + resources/checkbox-x-small.png + resources/checkbox-x.png