parent
63b3e936a3
commit
f9a5aa14c2
@ -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