pull/9/head
Alexis Drai 2 years ago
parent c739d58eb5
commit 4f85b8d669

@ -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]
```

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 78 KiB

@ -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

@ -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);
}
}
}

@ -5,7 +5,7 @@ import fr.uca.iut 1.0
Page {
id: taskView
property Task taskModel: Task {}
property var taskModel
SilicaFlickable {
anchors.fill: parent

@ -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<int, QByteArray> TaskModel::roleNames() const
QHash<int, QByteArray> ObservableTaskList::roleNames() const
{
QHash<int, QByteArray> roles;
roles[TitleRole] = "title";

@ -1,10 +1,10 @@
#ifndef TASKMODEL_H
#define TASKMODEL_H
#ifndef OBSERVABLETASKLIST_H
#define OBSERVABLETASKLIST_H
#include <QAbstractListModel>
#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<Task*> m_tasks;
};
#endif // TASKMODEL_H
#endif // OBSERVABLETASKLIST_H

@ -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;
}

@ -2,29 +2,29 @@
#define PROJECT_H
#include <QObject>
#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

@ -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();
}

@ -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();

@ -7,15 +7,15 @@
#include <QQmlEngine>
#include "Task.h"
#include "Project.h"
#include "TaskModel.h"
#include "ObservableTaskList.h"
int main(int argc, char *argv[])
{
qmlRegisterType<Task>("fr.uca.iut", 1, 0, "Task");
qmlRegisterType<Project>("fr.uca.iut", 1, 0, "Project");
qmlRegisterType<TaskModel>("fr.uca.iut", 1, 0, "TaskModel");
qmlRegisterType<ObservableTaskList>("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);

Loading…
Cancel
Save