diff --git a/README.md b/README.md index 917bf9a..8417cc5 100644 --- a/README.md +++ b/README.md @@ -3,10 +3,19 @@ - [Model](#model) - [View](#view) -## Model +## Auteur -The model will include Projects and Tasks. A Project owns a collection of Tasks (but Tasks can exist outside of projects too), -and a Project has a title. A Task has a title, an optional description, and an integer priority level between 0 and 3, zero being critical. +- Alexis Drai + +## Descriptif + +*Oh the things you'll do* est une app the choses à faire. Elle affiche une liste de `tasks` qui appartiennent à un `project`. + +On peut faire des opérations CRUD sur les `tasks`. + +Un projet a un titre et des `tasks`. + +Une `task` a un titre, une description optionnelle, et un niveau de priorité entre 0 et 3, 0 étant le plus critique. ```mermaid classDiagram @@ -24,16 +33,3 @@ classDiagram ``` -## View - -There will be a collection of projects on the home page. Clicking on a project will navigate the user to the project detail page, -where they will find the project title on top and a collection of tasks. Clicking on a task will navigate the user to the task detail page, -where they will find the task title, the task description if any, and the task priority represented with a label of a certain color next to -the words 'priority X' where X is the priority level. - -```mermaid -graph TB - A[Home Page] --> B[Project Detail Page] - B --> C[Task Detail Page] -``` - diff --git a/docs/detail.png b/docs/detail.png new file mode 100644 index 0000000..f3b72a1 Binary files /dev/null and b/docs/detail.png differ diff --git a/docs/main.png b/docs/main.png new file mode 100644 index 0000000..c49bb3f Binary files /dev/null and b/docs/main.png differ diff --git a/oh_the_things_you_ll_do.pro b/oh_the_things_you_ll_do.pro index 8937763..bded058 100644 --- a/oh_the_things_you_ll_do.pro +++ b/oh_the_things_you_ll_do.pro @@ -15,9 +15,9 @@ TARGET = oh_the_things_you_ll_do CONFIG += sailfishapp SOURCES += src/oh_the_things_you_ll_do.cpp \ + src/ObservableTaskList.cpp \ src/Project.cpp \ - src/Task.cpp \ - src/TaskModel.cpp + src/Task.cpp DISTFILES += qml/oh_the_things_you_ll_do.qml \ qml/cover/CoverPage.qml \ @@ -42,6 +42,6 @@ CONFIG += sailfishapp_i18n TRANSLATIONS += translations/oh_the_things_you_ll_do-de.ts HEADERS += \ + src/ObservableTaskList.h \ src/Project.h \ - src/Task.h \ - src/TaskModel.h + src/Task.h diff --git a/qml/pages/ProjectView.qml b/qml/pages/ProjectView.qml index 9792273..4140fd5 100644 --- a/qml/pages/ProjectView.qml +++ b/qml/pages/ProjectView.qml @@ -8,49 +8,75 @@ Page { SilicaFlickable { anchors.fill: parent - Column { - width: parent.width - 2 * Theme.paddingLarge - spacing: Theme.paddingLarge + TextField { + id: titleField + text: projectModel.title + label: qsTr("Project Title") + font.pixelSize: Theme.fontSizeExtraLarge + onTextChanged: projectModel.title = text anchors { - horizontalCenter: parent.horizontalCenter - margins: Theme.paddingLarge + top: parent.top + left: parent.left } + } - TextField { - id: titleField - text: projectModel.title - label: qsTr("Project Title") - font.pixelSize: Theme.fontSizeExtraLarge - onTextChanged: projectModel.title = text + Button { + id: addButton + text: "Create" + onClicked: { + projectModel.tasks.insertRows(0, 1); + // FIXME this does insert a new task in the list, but the task title doesn't get displayed + } + anchors { + top: titleField.bottom + left: parent.left } + } - Button { - text: "+" - onClicked: { - projectModel.tasks.insertRows(0, 1); - } + SilicaListView { + id: tasksList + model: projectModel.tasks + anchors { + top: addButton.bottom + left: parent.left + bottom: parent.bottom } + delegate: ListItem { + width: ListView.view.width + height: Theme.itemSizeLarge - SilicaListView { - id: tasksList - model: projectModel.tasks - delegate: ListItem { - width: ListView.view.width - MouseArea { - anchors.fill: parent - onClicked: pageStack.push(Qt.resolvedUrl("TaskView.qml"), {taskModel: model}) - Label { - text: model.title - color: model.priority === 0 ? "red" : - model.priority === 1 ? "orange" : - model.priority === 2 ? "blue" : "transparent" - font.pixelSize: Theme.fontSizeLarge - } + Label { + id: label + text: model.title + color: model.priority === 0 ? "red" : + model.priority === 1 ? "orange" : + model.priority === 2 ? "blue" : Theme.primaryColor + font.pixelSize: Theme.fontSizeLarge + } + + Button { + id: navButton + anchors { + top: label.bottom + left: parent.left } - Button { - text: "Delete" - onClicked: projectModel.tasks.removeTask(index) + height: Theme.itemSizeSmall + text: "GoTo" + onClicked: pageStack.push(Qt.resolvedUrl("TaskView.qml"), {taskModel: model}) + } + + Button { + id: deleteButton + anchors { + top: label.bottom + left: navButton.right } + height: Theme.itemSizeSmall + text: "Delete" + onClicked: projectModel.tasks.removeRows(index, 1) + } + Component.onCompleted: { + console.log("New ListItem created. Task title: " + model.title + " -- Priority: " + model.priority); } } } diff --git a/qml/pages/TaskView.qml b/qml/pages/TaskView.qml index 6bc4a2f..1db2727 100644 --- a/qml/pages/TaskView.qml +++ b/qml/pages/TaskView.qml @@ -5,7 +5,7 @@ import fr.uca.iut 1.0 Page { id: taskView - property Task taskModel: Task {} + property var taskModel SilicaFlickable { anchors.fill: parent diff --git a/src/TaskModel.cpp b/src/ObservableTaskList.cpp similarity index 63% rename from src/TaskModel.cpp rename to src/ObservableTaskList.cpp index 53c3cd2..7c421e9 100644 --- a/src/TaskModel.cpp +++ b/src/ObservableTaskList.cpp @@ -1,36 +1,36 @@ -#include "TaskModel.h" +#include "ObservableTaskList.h" -TaskModel::TaskModel(QObject *parent) +ObservableTaskList::ObservableTaskList(QObject *parent) : QAbstractListModel(parent) { } -void TaskModel::addTask(Task* task) +void ObservableTaskList::addTask(Task* task) { beginInsertRows(QModelIndex(), rowCount(), rowCount()); m_tasks << task; endInsertRows(); } -void TaskModel::removeTask(int index) +void ObservableTaskList::removeTask(int index) { beginRemoveRows(QModelIndex(), index, index); m_tasks.removeAt(index); endRemoveRows(); } -void TaskModel::updateTask(int index, Task* task) +void ObservableTaskList::updateTask(int index, Task* task) { m_tasks[index] = task; emit dataChanged(this->index(index), this->index(index), {TitleRole, DescriptionRole, PriorityRole}); } -int TaskModel::rowCount(const QModelIndex &) const +int ObservableTaskList::rowCount(const QModelIndex &) const { return m_tasks.count(); } -QVariant TaskModel::data(const QModelIndex &index, int role) const +QVariant ObservableTaskList::data(const QModelIndex &index, int role) const { if (index.row() < 0 || index.row() >= m_tasks.count()) return QVariant(); @@ -46,7 +46,7 @@ QVariant TaskModel::data(const QModelIndex &index, int role) const return QVariant(); } -bool TaskModel::setData(const QModelIndex &index, const QVariant &value, int role) +bool ObservableTaskList::setData(const QModelIndex &index, const QVariant &value, int role) { if (index.row() < 0 || index.row() >= m_tasks.count()) return false; @@ -66,7 +66,7 @@ bool TaskModel::setData(const QModelIndex &index, const QVariant &value, int rol return true; } -Qt::ItemFlags TaskModel::flags(const QModelIndex& index) const +Qt::ItemFlags ObservableTaskList::flags(const QModelIndex& index) const { if (!index.isValid()) return Qt::NoItemFlags; @@ -74,23 +74,25 @@ Qt::ItemFlags TaskModel::flags(const QModelIndex& index) const return Qt::ItemIsEditable; } -bool TaskModel::insertRows(int row, int count, const QModelIndex &parent) +bool ObservableTaskList::insertRows(int row, int count, const QModelIndex &parent) { - beginInsertRows(parent, row, row + count-1); + beginInsertRows(parent, row, row + count - 1); for (int nb = 0; nb < count; ++nb) { - m_tasks.insert(row, new Task("no title", "no description", 3)); + Task* newTask = new Task("no title", "no description", 3); + m_tasks.insert(row, newTask); } endInsertRows(); return true; } -bool TaskModel::removeRows(int row, int count, const QModelIndex &parent) + +bool ObservableTaskList::removeRows(int row, int count, const QModelIndex &parent) { - if (row < 0 || row+count >= m_tasks.count()) + if (row < 0 || row + count > m_tasks.count()) return false; - beginRemoveRows(parent, row, row + count-1); + beginRemoveRows(parent, row, row + count - 1); for (int nb = 0; nb < count; ++nb) { m_tasks.removeAt(row); } @@ -99,7 +101,7 @@ bool TaskModel::removeRows(int row, int count, const QModelIndex &parent) return true; } -QHash TaskModel::roleNames() const +QHash ObservableTaskList::roleNames() const { QHash roles; roles[TitleRole] = "title"; diff --git a/src/TaskModel.h b/src/ObservableTaskList.h similarity index 82% rename from src/TaskModel.h rename to src/ObservableTaskList.h index 23e0968..f76c597 100644 --- a/src/TaskModel.h +++ b/src/ObservableTaskList.h @@ -1,10 +1,10 @@ -#ifndef TASKMODEL_H -#define TASKMODEL_H +#ifndef OBSERVABLETASKLIST_H +#define OBSERVABLETASKLIST_H #include #include "Task.h" -class TaskModel : public QAbstractListModel +class ObservableTaskList : public QAbstractListModel { Q_OBJECT @@ -15,7 +15,7 @@ public: PriorityRole }; - explicit TaskModel(QObject *parent = nullptr); + explicit ObservableTaskList(QObject *parent = nullptr); void addTask(Task* task); void removeTask(int index); @@ -36,4 +36,4 @@ private: QList m_tasks; }; -#endif // TASKMODEL_H +#endif // OBSERVABLETASKLIST_H diff --git a/src/Project.cpp b/src/Project.cpp index 54d252a..090900b 100644 --- a/src/Project.cpp +++ b/src/Project.cpp @@ -4,7 +4,7 @@ Project::Project(QObject *parent) : QObject(parent) { } -Project::Project(const QString &title, TaskModel* tasks, QObject *parent) +Project::Project(const QString &title, ObservableTaskList* tasks, QObject *parent) : QObject(parent), m_title(title), m_tasks(tasks) { } @@ -22,7 +22,7 @@ void Project::setTitle(const QString &title) } } -TaskModel* Project::tasks() const +ObservableTaskList* Project::tasks() const { return m_tasks; } diff --git a/src/Project.h b/src/Project.h index d100dab..09cd697 100644 --- a/src/Project.h +++ b/src/Project.h @@ -2,29 +2,29 @@ #define PROJECT_H #include -#include "TaskModel.h" +#include "ObservableTaskList.h" class Project : public QObject { Q_OBJECT Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged) - Q_PROPERTY(TaskModel* tasks READ tasks CONSTANT) + Q_PROPERTY(ObservableTaskList* tasks READ tasks CONSTANT) public: explicit Project(QObject *parent = nullptr); - Project(const QString &title, TaskModel* tasks, QObject *parent = nullptr); + Project(const QString &title, ObservableTaskList* tasks, QObject *parent = nullptr); QString title() const; void setTitle(const QString &title); - TaskModel* tasks() const; + ObservableTaskList* tasks() const; signals: void titleChanged(); private: QString m_title; - TaskModel* m_tasks; + ObservableTaskList* m_tasks; }; #endif // PROJECT_H diff --git a/src/Task.cpp b/src/Task.cpp index dca150d..889e466 100644 --- a/src/Task.cpp +++ b/src/Task.cpp @@ -42,7 +42,7 @@ int Task::priority() const void Task::setPriority(int priority) { - if (priority >= 0 && priority <= MAX_PRIORITY && m_priority != priority) { + if (priority >= 0 && priority <= LEAST_CRITICAL_PRIORITY && m_priority != priority) { m_priority = priority; emit priorityChanged(); } diff --git a/src/Task.h b/src/Task.h index 23470fe..612eb3d 100644 --- a/src/Task.h +++ b/src/Task.h @@ -23,7 +23,7 @@ public: int priority() const; void setPriority(int priority); - static const int MAX_PRIORITY = 3; + static const int LEAST_CRITICAL_PRIORITY = 3; signals: void titleChanged(); diff --git a/src/oh_the_things_you_ll_do.cpp b/src/oh_the_things_you_ll_do.cpp index f175086..25eccfc 100644 --- a/src/oh_the_things_you_ll_do.cpp +++ b/src/oh_the_things_you_ll_do.cpp @@ -7,15 +7,15 @@ #include #include "Task.h" #include "Project.h" -#include "TaskModel.h" +#include "ObservableTaskList.h" int main(int argc, char *argv[]) { qmlRegisterType("fr.uca.iut", 1, 0, "Task"); qmlRegisterType("fr.uca.iut", 1, 0, "Project"); - qmlRegisterType("fr.uca.iut", 1, 0, "TaskModel"); + qmlRegisterType("fr.uca.iut", 1, 0, "TaskModel"); - TaskModel model; + ObservableTaskList model; model.addTask(new Task("Example Task 1", "This is an example task.", 2)); model.addTask(new Task("Example Task 2", "This is another example task.", 1)); QGuiApplication *app = SailfishApp::application(argc,argv);