To-Do app: Improvements

This commit is contained in:
Nicolas Mailloux 2022-09-15 08:28:03 -04:00
parent 377cbe31f1
commit 621dca8c41
5 changed files with 94 additions and 15 deletions

View file

@ -398,6 +398,7 @@ void apps::showFailedToParseMainUserAppsJsonFile() {
void apps::on_todoLaunchBtn_clicked() void apps::on_todoLaunchBtn_clicked()
{ {
todo * todoWindow = new todo(); todo * todoWindow = new todo();
QObject::connect(todoWindow, &todo::showToast, this, &apps::showToast);
todoWindow->setAttribute(Qt::WA_DeleteOnClose); todoWindow->setAttribute(Qt::WA_DeleteOnClose);
todoWindow->setGeometry(QRect(QPoint(0,0), qApp->primaryScreen()->geometry().size())); todoWindow->setGeometry(QRect(QPoint(0,0), qApp->primaryScreen()->geometry().size()));
todoWindow->show(); todoWindow->show();

View file

@ -24,12 +24,16 @@ todo::todo(QWidget *parent) :
ui->deleteItemBtn->setProperty("type", "borderless"); ui->deleteItemBtn->setProperty("type", "borderless");
ui->selectAllItemsBtn->setProperty("type", "borderless"); ui->selectAllItemsBtn->setProperty("type", "borderless");
ui->selectItemsModeBtn->setProperty("type", "borderless"); ui->selectItemsModeBtn->setProperty("type", "borderless");
ui->deselectAllItemsBtn->setProperty("type", "borderless");
ui->saveCurrentListViewBtn->setProperty("type", "borderless");
ui->deleteBtn->setStyleSheet("padding: 10px"); ui->deleteBtn->setStyleSheet("padding: 10px");
ui->setupBtn->setStyleSheet("padding: 10px"); ui->setupBtn->setStyleSheet("padding: 10px");
ui->newItemBtn->setStyleSheet("padding: 10px"); ui->newItemBtn->setStyleSheet("padding: 10px");
ui->deleteItemBtn->setStyleSheet("padding: 10px"); ui->deleteItemBtn->setStyleSheet("padding: 10px");
ui->selectAllItemsBtn->setStyleSheet("padding: 10px"); ui->selectAllItemsBtn->setStyleSheet("padding: 10px");
ui->selectItemsModeBtn->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->closeBtn->setIcon(QIcon(":/resources/close.png"));
ui->newBtn->setIcon(QIcon(":/resources/new.png")); ui->newBtn->setIcon(QIcon(":/resources/new.png"));
ui->newItemBtn->setIcon(QIcon(":/resources/plus.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->deleteItemBtn->setIcon(QIcon(":/resources/x-circle.png"));
ui->selectAllItemsBtn->setIcon(QIcon(":/resources/checkbox-checked-small.png")); ui->selectAllItemsBtn->setIcon(QIcon(":/resources/checkbox-checked-small.png"));
ui->selectItemsModeBtn->setIcon(QIcon(":/resources/checkbox-unchecked-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->setStyleSheet("font-size: 10pt");
ui->listWidget->setWordWrap(true); ui->listWidget->setWordWrap(true);
ui->itemsListWidget->setStyleSheet("font-size: 10pt"); ui->itemsListWidget->setStyleSheet("font-size: 10pt");
@ -290,27 +296,44 @@ void todo::switchItemsSelectionMode(bool selectionMode) {
void todo::on_deleteItemBtn_clicked() void todo::on_deleteItemBtn_clicked()
{ {
log("Deleting list item(s)", className); QList<int> itemsToDelete;
QJsonDocument document = readTodoDatabase();
QJsonObject object = document.object();
QJsonArray mainArray = object["List"].toArray();
QJsonArray listArray = mainArray.at(listIndex).toArray();
int itemsRemoved = 0;
for(int i = 1; i < ui->itemsListWidget->count() + 1; i++) { for(int i = 1; i < ui->itemsListWidget->count() + 1; i++) {
if(ui->itemsListWidget->item(i - 1)->checkState() == Qt::Checked) { if(ui->itemsListWidget->item(i - 1)->checkState() == Qt::Checked) {
listArray.removeAt(i - itemsRemoved); itemsToDelete.append(i);
itemsRemoved++;
} }
} }
// Adding item array to list array if(!itemsToDelete.isEmpty()) {
mainArray.replace(listIndex, listArray); QString itemsToDeleteString;
object["List"] = mainArray; 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); // Adding item array to list array
writeTodoDatabase(document); 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() void todo::on_selectAllItemsBtn_clicked()
@ -328,3 +351,17 @@ void todo::setDefaultHomePageStatusText() {
void todo::setDefaultListPageStatusText() { void todo::setDefaultListPageStatusText() {
ui->statusLabel->setText("Select or create a new item"); 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);
}

View file

@ -45,6 +45,11 @@ private slots:
void on_selectItemsModeBtn_clicked(); void on_selectItemsModeBtn_clicked();
void on_deleteItemBtn_clicked(); void on_deleteItemBtn_clicked();
void on_selectAllItemsBtn_clicked(); void on_selectAllItemsBtn_clicked();
void on_deselectAllItemsBtn_clicked();
void on_saveCurrentListViewBtn_clicked();
signals:
void showToast(QString messageToDisplay);
private: private:
Ui::todo *ui; Ui::todo *ui;

View file

@ -6,7 +6,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>400</width> <width>483</width>
<height>300</height> <height>300</height>
</rect> </rect>
</property> </property>
@ -309,6 +309,40 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="Line" name="line_9">
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="deselectAllItemsBtn">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="Line" name="line_10">
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="saveCurrentListViewBtn">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout> </layout>
</item> </item>
</layout> </layout>

View file

@ -101,5 +101,7 @@
<file>resources/new.png</file> <file>resources/new.png</file>
<file>resources/checkbox-unchecked-small.png</file> <file>resources/checkbox-unchecked-small.png</file>
<file>resources/checkbox-checked-small.png</file> <file>resources/checkbox-checked-small.png</file>
<file>resources/checkbox-x-small.png</file>
<file>resources/checkbox-x.png</file>
</qresource> </qresource>
</RCC> </RCC>