From 32234af6fc9844c05a4c2882e9aceea611b802bc Mon Sep 17 00:00:00 2001 From: Alexis Drai Date: Mon, 12 Jun 2023 11:50:45 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=84=20Create=20TaskView=20(#6)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix #3 Co-authored-by: Alexis Drai Reviewed-on: https://codefirst.iut.uca.fr/git/alexis.drai/oh_the_things_you_ll_do/pulls/6 --- README.md | 36 +++++++++++++++ oh_the_things_you_ll_do.pro | 11 +++-- qml/oh_the_things_you_ll_do.qml | 11 ++++- qml/pages/FirstPage.qml | 43 ------------------ qml/pages/SecondPage.qml | 30 ------------- qml/pages/TaskView.qml | 52 ++++++++++++++++++++++ src/Project.cpp | 49 ++++++++++++++++++++ src/Project.h | 36 +++++++++++++++ src/Task.cpp | 50 +++++++++++++++++++++ src/Task.h | 40 +++++++++++++++++ src/oh_the_things_you_ll_do.cpp | 13 ++---- translations/oh_the_things_you_ll_do-de.ts | 25 +++-------- translations/oh_the_things_you_ll_do.ts | 21 ++------- 13 files changed, 293 insertions(+), 124 deletions(-) create mode 100644 README.md delete mode 100644 qml/pages/FirstPage.qml delete mode 100644 qml/pages/SecondPage.qml create mode 100644 qml/pages/TaskView.qml create mode 100644 src/Project.cpp create mode 100644 src/Project.h create mode 100644 src/Task.cpp create mode 100644 src/Task.h diff --git a/README.md b/README.md new file mode 100644 index 0000000..9370d4c --- /dev/null +++ b/README.md @@ -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 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] +``` + diff --git a/oh_the_things_you_ll_do.pro b/oh_the_things_you_ll_do.pro index 267418c..fbc3f6d 100644 --- a/oh_the_things_you_ll_do.pro +++ b/oh_the_things_you_ll_do.pro @@ -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 diff --git a/qml/oh_the_things_you_ll_do.qml b/qml/oh_the_things_you_ll_do.qml index 5709adc..0ab89be 100644 --- a/qml/oh_the_things_you_ll_do.qml +++ b/qml/oh_the_things_you_ll_do.qml @@ -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 } diff --git a/qml/pages/FirstPage.qml b/qml/pages/FirstPage.qml deleted file mode 100644 index 9a00fc3..0000000 --- a/qml/pages/FirstPage.qml +++ /dev/null @@ -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 - } - } - } -} diff --git a/qml/pages/SecondPage.qml b/qml/pages/SecondPage.qml deleted file mode 100644 index 6dbadf4..0000000 --- a/qml/pages/SecondPage.qml +++ /dev/null @@ -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 {} - } -} diff --git a/qml/pages/TaskView.qml b/qml/pages/TaskView.qml new file mode 100644 index 0000000..29dd465 --- /dev/null +++ b/qml/pages/TaskView.qml @@ -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 + } + } + } +} diff --git a/src/Project.cpp b/src/Project.cpp new file mode 100644 index 0000000..371c203 --- /dev/null +++ b/src/Project.cpp @@ -0,0 +1,49 @@ +#include "Project.h" + +Project::Project(QObject *parent) : QObject(parent) +{ +} + +Project::Project(const QString &title, const QList &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& 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(); +} diff --git a/src/Project.h b/src/Project.h new file mode 100644 index 0000000..7a9f582 --- /dev/null +++ b/src/Project.h @@ -0,0 +1,36 @@ +#ifndef PROJECT_H +#define PROJECT_H + +#include +#include +#include "Task.h" + +class Project : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged) + Q_PROPERTY(QList tasks READ tasks NOTIFY tasksChanged) + +public: + explicit Project(QObject *parent = nullptr); + Project(const QString &title, const QList &tasks, QObject *parent = nullptr); + + QString title() const; + void setTitle(const QString &title); + + const QList& tasks() const; + + void addTask(Task* task); + void updateTask(Task* task); + void removeTask(Task* task); + +signals: + void titleChanged(); + void tasksChanged(); + +private: + QString m_title; + QList m_tasks; +}; + +#endif // PROJECT_H diff --git a/src/Task.cpp b/src/Task.cpp new file mode 100644 index 0000000..dca150d --- /dev/null +++ b/src/Task.cpp @@ -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(); + } +} + diff --git a/src/Task.h b/src/Task.h new file mode 100644 index 0000000..23470fe --- /dev/null +++ b/src/Task.h @@ -0,0 +1,40 @@ +#ifndef TASK_H +#define TASK_H + +#include + +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 diff --git a/src/oh_the_things_you_ll_do.cpp b/src/oh_the_things_you_ll_do.cpp index a866a1a..eddd199 100644 --- a/src/oh_the_things_you_ll_do.cpp +++ b/src/oh_the_things_you_ll_do.cpp @@ -3,18 +3,13 @@ #endif #include +#include +#include +#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("fr.uca.iut", 1, 0, "Task"); return SailfishApp::main(argc, argv); } diff --git a/translations/oh_the_things_you_ll_do-de.ts b/translations/oh_the_things_you_ll_do-de.ts index 8f39883..8a3a687 100644 --- a/translations/oh_the_things_you_ll_do-de.ts +++ b/translations/oh_the_things_you_ll_do-de.ts @@ -9,29 +9,14 @@ - FirstPage + TaskView - Show Page 2 - Zur Seite 2 + Description + - UI Template - UI-Vorlage - - - Hello Sailors - Hallo Matrosen - - - - SecondPage - - Nested Page - Unterseite - - - Item - Element + Priority + diff --git a/translations/oh_the_things_you_ll_do.ts b/translations/oh_the_things_you_ll_do.ts index 7fc118e..e14f753 100644 --- a/translations/oh_the_things_you_ll_do.ts +++ b/translations/oh_the_things_you_ll_do.ts @@ -9,28 +9,13 @@ - FirstPage + TaskView - Show Page 2 + Description - UI Template - - - - Hello Sailors - - - - - SecondPage - - Nested Page - - - - Item + Priority