💄 Create TaskView (#6)

Fix #3

Co-authored-by: Alexis Drai <adrai@cikaba.com>
Reviewed-on: #6
pull/8/head
Alexis Drai 2 years ago
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]
```

@ -14,12 +14,13 @@ TARGET = oh_the_things_you_ll_do
CONFIG += sailfishapp
SOURCES += src/oh_the_things_you_ll_do.cpp
SOURCES += src/oh_the_things_you_ll_do.cpp \
src/Project.cpp \
src/Task.cpp
DISTFILES += qml/oh_the_things_you_ll_do.qml \
qml/cover/CoverPage.qml \
qml/pages/FirstPage.qml \
qml/pages/SecondPage.qml \
qml/pages/TaskView.qml \
rpm/oh_the_things_you_ll_do.changes.in \
rpm/oh_the_things_you_ll_do.changes.run.in \
rpm/oh_the_things_you_ll_do.spec \
@ -37,3 +38,7 @@ CONFIG += sailfishapp_i18n
# following TRANSLATIONS line. And also do not forget to
# modify the localized app name in the the .desktop file.
TRANSLATIONS += translations/oh_the_things_you_ll_do-de.ts
HEADERS += \
src/Project.h \
src/Task.h

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

@ -3,18 +3,13 @@
#endif
#include <sailfishapp.h>
#include <QQmlContext>
#include <QQmlEngine>
#include "Task.h"
int main(int argc, char *argv[])
{
// SailfishApp::main() will display "qml/oh_the_things_you_ll_do.qml", if you need more
// control over initialization, you can use:
//
// - SailfishApp::application(int, char *[]) to get the QGuiApplication *
// - SailfishApp::createView() to get a new QQuickView * instance
// - SailfishApp::pathTo(QString) to get a QUrl to a resource file
// - SailfishApp::pathToMainQml() to get a QUrl to the main QML file
//
// To display the view, call "show()" (will show fullscreen on device).
qmlRegisterType<Task>("fr.uca.iut", 1, 0, "Task");
return SailfishApp::main(argc, argv);
}

@ -9,29 +9,14 @@
</message>
</context>
<context>
<name>FirstPage</name>
<name>TaskView</name>
<message>
<source>Show Page 2</source>
<translation>Zur Seite 2</translation>
<source>Description</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>UI Template</source>
<translation>UI-Vorlage</translation>
</message>
<message>
<source>Hello Sailors</source>
<translation>Hallo Matrosen</translation>
</message>
</context>
<context>
<name>SecondPage</name>
<message>
<source>Nested Page</source>
<translation>Unterseite</translation>
</message>
<message>
<source>Item</source>
<translation>Element</translation>
<source>Priority </source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>

@ -9,28 +9,13 @@
</message>
</context>
<context>
<name>FirstPage</name>
<name>TaskView</name>
<message>
<source>Show Page 2</source>
<source>Description</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>UI Template</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Hello Sailors</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>SecondPage</name>
<message>
<source>Nested Page</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Item</source>
<source>Priority </source>
<translation type="unfinished"></translation>
</message>
</context>

Loading…
Cancel
Save