mirror of
https://github.com/Quill-OS/quill.git
synced 2024-10-31 21:33:22 -07:00
To-Do app: Progress
This commit is contained in:
parent
32b051b3c7
commit
e94de73eb3
3 changed files with 107 additions and 16 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#define TODO_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QListWidgetItem>
|
||||
|
||||
#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;
|
||||
|
|
|
@ -115,6 +115,9 @@
|
|||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QStackedWidget" name="stackedWidget">
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="page_3">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||
<property name="leftMargin">
|
||||
|
@ -159,13 +162,65 @@
|
|||
<item>
|
||||
<widget class="QListWidget" name="listWidget"/>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QPushButton" name="deleteBtn">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Line" name="line_3">
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Plain</enum>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="setupBtn">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="page_4"/>
|
||||
<widget class="QWidget" name="page_4">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_6">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_5"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
|
|
Loading…
Reference in a new issue