💄 Create TaskView (#6)
Fix #3 Co-authored-by: Alexis Drai <adrai@cikaba.com> Reviewed-on: #6pull/8/head
parent
69bb253d48
commit
32234af6fc
@ -0,0 +1,36 @@
|
||||
# Oh the things you'll do
|
||||
|
||||
## Model
|
||||
|
||||
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.
|
||||
|
||||
```mermaid
|
||||
classDiagram
|
||||
class Project {
|
||||
+String title
|
||||
+List<Task> tasks
|
||||
}
|
||||
class Task {
|
||||
+String title
|
||||
+String description
|
||||
+int priority
|
||||
}
|
||||
|
||||
Project --> "*" Task
|
||||
|
||||
```
|
||||
|
||||
## 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]
|
||||
```
|
||||
|
@ -1,9 +1,18 @@
|
||||
import QtQuick 2.0
|
||||
import Sailfish.Silica 1.0
|
||||
import "pages"
|
||||
import fr.uca.iut 1.0
|
||||
|
||||
ApplicationWindow {
|
||||
initialPage: Component { FirstPage { } }
|
||||
initialPage: Component {
|
||||
TaskView {
|
||||
taskModel: Task {
|
||||
title: "Example Task"
|
||||
description: "This is an example task."
|
||||
priority: 2
|
||||
}
|
||||
}
|
||||
}
|
||||
cover: Qt.resolvedUrl("cover/CoverPage.qml")
|
||||
allowedOrientations: defaultAllowedOrientations
|
||||
}
|
||||
|
@ -1,43 +0,0 @@
|
||||
import QtQuick 2.0
|
||||
import Sailfish.Silica 1.0
|
||||
|
||||
Page {
|
||||
id: page
|
||||
|
||||
// The effective value will be restricted by ApplicationWindow.allowedOrientations
|
||||
allowedOrientations: Orientation.All
|
||||
|
||||
// To enable PullDownMenu, place our content in a SilicaFlickable
|
||||
SilicaFlickable {
|
||||
anchors.fill: parent
|
||||
|
||||
// PullDownMenu and PushUpMenu must be declared in SilicaFlickable, SilicaListView or SilicaGridView
|
||||
PullDownMenu {
|
||||
MenuItem {
|
||||
text: qsTr("Show Page 2")
|
||||
onClicked: pageStack.animatorPush(Qt.resolvedUrl("SecondPage.qml"))
|
||||
}
|
||||
}
|
||||
|
||||
// Tell SilicaFlickable the height of its content.
|
||||
contentHeight: column.height
|
||||
|
||||
// Place our content in a Column. The PageHeader is always placed at the top
|
||||
// of the page, followed by our content.
|
||||
Column {
|
||||
id: column
|
||||
|
||||
width: page.width
|
||||
spacing: Theme.paddingLarge
|
||||
PageHeader {
|
||||
title: qsTr("UI Template")
|
||||
}
|
||||
Label {
|
||||
x: Theme.horizontalPageMargin
|
||||
text: qsTr("Hello Sailors")
|
||||
color: Theme.secondaryHighlightColor
|
||||
font.pixelSize: Theme.fontSizeExtraLarge
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
import QtQuick 2.0
|
||||
import Sailfish.Silica 1.0
|
||||
|
||||
Page {
|
||||
id: page
|
||||
|
||||
// The effective value will be restricted by ApplicationWindow.allowedOrientations
|
||||
allowedOrientations: Orientation.All
|
||||
|
||||
SilicaListView {
|
||||
id: listView
|
||||
model: 20
|
||||
anchors.fill: parent
|
||||
header: PageHeader {
|
||||
title: qsTr("Nested Page")
|
||||
}
|
||||
delegate: BackgroundItem {
|
||||
id: delegate
|
||||
|
||||
Label {
|
||||
x: Theme.horizontalPageMargin
|
||||
text: qsTr("Item") + " " + index
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
color: delegate.highlighted ? Theme.highlightColor : Theme.primaryColor
|
||||
}
|
||||
onClicked: console.log("Clicked " + index)
|
||||
}
|
||||
VerticalScrollDecorator {}
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
import QtQuick 2.0
|
||||
import Sailfish.Silica 1.0
|
||||
import fr.uca.iut 1.0
|
||||
|
||||
Page {
|
||||
id: taskView
|
||||
|
||||
property Task taskModel: Task {}
|
||||
|
||||
SilicaFlickable {
|
||||
anchors.fill: parent
|
||||
|
||||
Column {
|
||||
width: parent.width - 2 * Theme.paddingLarge
|
||||
spacing: Theme.paddingLarge
|
||||
anchors {
|
||||
horizontalCenter: parent.horizontalCenter
|
||||
margins: Theme.paddingLarge
|
||||
}
|
||||
|
||||
// this is to provide some top margin, to make the view easier to look at when a banner notification happens
|
||||
Item {
|
||||
width: parent.width
|
||||
height: 2 * Theme.paddingLarge
|
||||
}
|
||||
|
||||
Label {
|
||||
text: taskModel.title
|
||||
font.pixelSize: Theme.fontSizeExtraLarge
|
||||
}
|
||||
|
||||
Label {
|
||||
text: qsTr("Description")
|
||||
font.bold: true
|
||||
font.pixelSize: Theme.fontSizeLarge
|
||||
}
|
||||
|
||||
Label {
|
||||
text: taskModel.description
|
||||
font.pixelSize: Theme.fontSizeMedium
|
||||
}
|
||||
|
||||
Label {
|
||||
text: qsTr("Priority ") + taskModel.priority
|
||||
color: taskModel.priority === 0 ? "red" :
|
||||
taskModel.priority === 1 ? "orange" :
|
||||
taskModel.priority === 2 ? "blue" : Theme.primaryColor
|
||||
font.pixelSize: Theme.fontSizeLarge
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
#include "Project.h"
|
||||
|
||||
Project::Project(QObject *parent) : QObject(parent)
|
||||
{
|
||||
}
|
||||
|
||||
Project::Project(const QString &title, const QList<Task*> &tasks, QObject *parent)
|
||||
: QObject(parent), m_title(title), m_tasks(tasks)
|
||||
{
|
||||
}
|
||||
|
||||
QString Project::title() const
|
||||
{
|
||||
return m_title;
|
||||
}
|
||||
|
||||
void Project::setTitle(const QString &title)
|
||||
{
|
||||
if (m_title != title) {
|
||||
m_title = title;
|
||||
emit titleChanged();
|
||||
}
|
||||
}
|
||||
|
||||
const QList<Task*>& Project::tasks() const
|
||||
{
|
||||
return m_tasks;
|
||||
}
|
||||
|
||||
void Project::addTask(Task* task)
|
||||
{
|
||||
m_tasks.append(task);
|
||||
emit tasksChanged();
|
||||
}
|
||||
|
||||
void Project::updateTask(Task* task)
|
||||
{
|
||||
int index = m_tasks.indexOf(task);
|
||||
if (index != -1) {
|
||||
m_tasks[index] = task;
|
||||
emit tasksChanged();
|
||||
}
|
||||
}
|
||||
|
||||
void Project::removeTask(Task* task)
|
||||
{
|
||||
m_tasks.removeOne(task);
|
||||
emit tasksChanged();
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
#ifndef PROJECT_H
|
||||
#define PROJECT_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QList>
|
||||
#include "Task.h"
|
||||
|
||||
class Project : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged)
|
||||
Q_PROPERTY(QList<Task*> tasks READ tasks NOTIFY tasksChanged)
|
||||
|
||||
public:
|
||||
explicit Project(QObject *parent = nullptr);
|
||||
Project(const QString &title, const QList<Task*> &tasks, QObject *parent = nullptr);
|
||||
|
||||
QString title() const;
|
||||
void setTitle(const QString &title);
|
||||
|
||||
const QList<Task*>& tasks() const;
|
||||
|
||||
void addTask(Task* task);
|
||||
void updateTask(Task* task);
|
||||
void removeTask(Task* task);
|
||||
|
||||
signals:
|
||||
void titleChanged();
|
||||
void tasksChanged();
|
||||
|
||||
private:
|
||||
QString m_title;
|
||||
QList<Task*> m_tasks;
|
||||
};
|
||||
|
||||
#endif // PROJECT_H
|
@ -0,0 +1,50 @@
|
||||
#include "Task.h"
|
||||
|
||||
Task::Task(QObject *parent) : QObject(parent)
|
||||
{
|
||||
}
|
||||
|
||||
Task::Task(const QString &title, const QString &description, int priority, QObject *parent)
|
||||
: QObject(parent), m_title(title), m_description(description), m_priority(priority)
|
||||
{
|
||||
}
|
||||
|
||||
QString Task::title() const
|
||||
{
|
||||
return m_title;
|
||||
}
|
||||
|
||||
void Task::setTitle(const QString &title)
|
||||
{
|
||||
if (m_title != title) {
|
||||
m_title = title;
|
||||
emit titleChanged();
|
||||
}
|
||||
}
|
||||
|
||||
QString Task::description() const
|
||||
{
|
||||
return m_description;
|
||||
}
|
||||
|
||||
void Task::setDescription(const QString &description)
|
||||
{
|
||||
if (m_description != description) {
|
||||
m_description = description;
|
||||
emit descriptionChanged();
|
||||
}
|
||||
}
|
||||
|
||||
int Task::priority() const
|
||||
{
|
||||
return m_priority;
|
||||
}
|
||||
|
||||
void Task::setPriority(int priority)
|
||||
{
|
||||
if (priority >= 0 && priority <= MAX_PRIORITY && m_priority != priority) {
|
||||
m_priority = priority;
|
||||
emit priorityChanged();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,40 @@
|
||||
#ifndef TASK_H
|
||||
#define TASK_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class Task : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged)
|
||||
Q_PROPERTY(QString description READ description WRITE setDescription NOTIFY descriptionChanged)
|
||||
Q_PROPERTY(int priority READ priority WRITE setPriority NOTIFY priorityChanged)
|
||||
|
||||
public:
|
||||
explicit Task(QObject *parent = nullptr);
|
||||
Task(const QString &title, const QString &description, int priority, QObject *parent = nullptr);
|
||||
|
||||
QString title() const;
|
||||
void setTitle(const QString &title);
|
||||
|
||||
QString description() const;
|
||||
void setDescription(const QString &description);
|
||||
|
||||
int priority() const;
|
||||
void setPriority(int priority);
|
||||
|
||||
static const int MAX_PRIORITY = 3;
|
||||
|
||||
signals:
|
||||
void titleChanged();
|
||||
void descriptionChanged();
|
||||
void priorityChanged();
|
||||
|
||||
private:
|
||||
QString m_title;
|
||||
QString m_description;
|
||||
int m_priority;
|
||||
};
|
||||
|
||||
|
||||
#endif // TASK_H
|
Loading…
Reference in new issue