School Commit Init
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
# Prerequisites
|
||||
*.d
|
||||
|
||||
# Compiled Object files
|
||||
*.slo
|
||||
*.lo
|
||||
*.o
|
||||
*.obj
|
||||
|
||||
# Precompiled Headers
|
||||
*.gch
|
||||
*.pch
|
||||
|
||||
# Compiled Dynamic libraries
|
||||
*.so
|
||||
*.dylib
|
||||
*.dll
|
||||
|
||||
# Fortran module files
|
||||
*.mod
|
||||
*.smod
|
||||
|
||||
# Compiled Static libraries
|
||||
*.lai
|
||||
*.la
|
||||
*.a
|
||||
*.lib
|
||||
|
||||
# Executables
|
||||
*.exe
|
||||
*.out
|
||||
*.app
|
||||
@@ -0,0 +1,56 @@
|
||||
#include "GUI.h"
|
||||
|
||||
GUI::GUI()
|
||||
{
|
||||
this->mainWindow = new QWidget;
|
||||
this->sideWindow = new QWidget;
|
||||
this->showBtn = new QPushButton("Show for current day");
|
||||
this->dateEdit = new QLineEdit;
|
||||
this->allTaskList = new QListWidget;
|
||||
this->dateTaskList = new QListWidget;
|
||||
this->mainLayout = new QVBoxLayout;
|
||||
this->sideLayout = new QVBoxLayout;
|
||||
this->durationLabel = new QLabel;
|
||||
this->mainLayout->addWidget(this->allTaskList);
|
||||
for (auto task : this->service.getTasks()) {
|
||||
this->allTaskList->addItem(QString::fromStdString(task.getDescription() + " | " + std::to_string(task.getDuration()) + " | " + task.getDate()));
|
||||
if (task.getDate() < "2023.05.22") {
|
||||
this->allTaskList->item(this->allTaskList->count() - 1)->setForeground(Qt::red);
|
||||
}
|
||||
}
|
||||
this->mainLayout->addWidget(this->dateEdit);
|
||||
this->mainLayout->addWidget(this->showBtn);
|
||||
this->mainWindow->setLayout(this->mainLayout);
|
||||
|
||||
this->sideLayout->addWidget(this->dateTaskList);
|
||||
this->sideLayout->addWidget(this->durationLabel);
|
||||
this->sideWindow->setLayout(this->sideLayout);
|
||||
|
||||
QObject::connect(this->showBtn, &QPushButton::clicked, [&]() {
|
||||
std::string date = this->dateEdit->text().toStdString();
|
||||
int duration = 0;
|
||||
this->dateTaskList->clear();
|
||||
std::vector<Task> tasks = this->service.getTasksForDate(date);
|
||||
if (tasks.size() == 0) {
|
||||
QMessageBox::warning(this->mainWindow, "Warning", "No tasks for this date!");
|
||||
return;
|
||||
}
|
||||
for (auto task : tasks) {
|
||||
this->dateTaskList->addItem(QString::fromStdString(task.getDescription() + " | " + std::to_string(task.getDuration()) + " | " + task.getDate()));
|
||||
duration += task.getDuration();
|
||||
}
|
||||
this->durationLabel->setText(QString::fromStdString("Duration: " + std::to_string(duration)));
|
||||
this->sideWindow->show();
|
||||
});
|
||||
}
|
||||
|
||||
GUI::~GUI()
|
||||
{
|
||||
delete this->mainWindow;
|
||||
delete this->sideWindow;
|
||||
}
|
||||
|
||||
void GUI::show()
|
||||
{
|
||||
this->mainWindow->show();
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
#include "service.h"
|
||||
#include <QWidget>
|
||||
#include <QPushButton>
|
||||
#include <QListWidget>
|
||||
#include <Qlabel>
|
||||
#include <QLineEdit>
|
||||
#include <QVBoxLayout>
|
||||
#include <QMessageBox>
|
||||
|
||||
|
||||
class GUI {
|
||||
private:
|
||||
Service service;
|
||||
QWidget* mainWindow;
|
||||
QWidget* sideWindow;
|
||||
QPushButton* showBtn;
|
||||
QLineEdit* dateEdit;
|
||||
QListWidget* allTaskList;
|
||||
QListWidget* dateTaskList;
|
||||
QVBoxLayout* mainLayout;
|
||||
QVBoxLayout* sideLayout;
|
||||
QLabel* durationLabel;
|
||||
public:
|
||||
GUI();
|
||||
~GUI();
|
||||
void show();
|
||||
|
||||
};
|
||||
@@ -0,0 +1,16 @@
|
||||
# Lab Test 3
|
||||
|
||||
Solve the provided problem, using object oriented programming, C++ and Qt (for the GUI). No score is awarded for a console-based user interface.
|
||||
|
||||
The application must use layered architecture in order for functionalities to be graded.
|
||||
|
||||
In case reading from a file is required: if the data are not read from the file, 0.5 points are subtracted from the indicated score for each functionality.
|
||||
|
||||
Using existing code is forbidden, you must start your application from scratch.
|
||||
|
||||
You may use Qt Designer, as well as the following sites for documentation:
|
||||
- http://doc.qt.io/qt-6/
|
||||
- http://en.cppreference.com/w/
|
||||
- http://www.cplusplus.com/
|
||||
|
||||
Time: 60 minutes.
|
||||
@@ -0,0 +1,45 @@
|
||||
#include "domain.h"
|
||||
|
||||
Task::Task()
|
||||
{
|
||||
this->description = "";
|
||||
this->duration = 0;
|
||||
this->date = "";
|
||||
}
|
||||
|
||||
Task::Task(std::string description, int duration, std::string date)
|
||||
{
|
||||
this->description = description;
|
||||
this->duration = duration;
|
||||
this->date = date;
|
||||
}
|
||||
|
||||
std::string Task::getDescription()
|
||||
{
|
||||
return this->description;
|
||||
}
|
||||
|
||||
int Task::getDuration()
|
||||
{
|
||||
return this->duration;
|
||||
}
|
||||
|
||||
std::string Task::getDate()
|
||||
{
|
||||
return this->date;
|
||||
}
|
||||
|
||||
void Task::setDescription(std::string description)
|
||||
{
|
||||
this->description = description;
|
||||
}
|
||||
|
||||
void Task::setDuration(int duration)
|
||||
{
|
||||
this->duration = duration;
|
||||
}
|
||||
|
||||
void Task::setDate(std::string date)
|
||||
{
|
||||
this->date = date;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
#include<string>
|
||||
#include<iostream>
|
||||
|
||||
|
||||
class Task {
|
||||
private:
|
||||
std::string description;
|
||||
int duration;
|
||||
std::string date;
|
||||
public:
|
||||
Task();
|
||||
Task(std::string description, int duration, std::string date);
|
||||
std::string getDescription();
|
||||
int getDuration();
|
||||
std::string getDate();
|
||||
void setDescription(std::string description);
|
||||
void setDuration(int duration);
|
||||
void setDate(std::string date);
|
||||
};
|
||||
@@ -0,0 +1,10 @@
|
||||
#include <QtWidgets/QApplication>
|
||||
#include "GUI.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
GUI g;
|
||||
g.show();
|
||||
return a.exec();
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
#include "repo.h"
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
|
||||
Repo::Repo()
|
||||
{
|
||||
this->readFromFile();
|
||||
}
|
||||
|
||||
Repo::~Repo()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Repo::addTask(Task task)
|
||||
{
|
||||
this->tasks.push_back(task);
|
||||
}
|
||||
|
||||
std::vector<Task> Repo::getTasks()
|
||||
{
|
||||
return this->tasks;
|
||||
}
|
||||
|
||||
void Repo::readFromFile()
|
||||
{
|
||||
std::ifstream file("tasks.txt");
|
||||
std::string line;
|
||||
while (std::getline(file, line)) {
|
||||
std::string description = line.substr(0, line.find("|"));
|
||||
line.erase(0, line.find("|") + 1);
|
||||
int duration = std::stoi(line.substr(0, line.find("|")));
|
||||
line.erase(0, line.find("|") + 1);
|
||||
std::string date = line.substr(0, line.find("|"));
|
||||
Task task(description, duration, date);
|
||||
this->addTask(task);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include<string>
|
||||
#include "domain.h"
|
||||
#include<vector>
|
||||
|
||||
class Repo {
|
||||
private:
|
||||
std::vector<Task> tasks;
|
||||
public:
|
||||
Repo();
|
||||
~Repo();
|
||||
void addTask(Task task);
|
||||
std::vector<Task> getTasks();
|
||||
void readFromFile();
|
||||
};
|
||||
@@ -0,0 +1,40 @@
|
||||
#include "service.h"
|
||||
#include <algorithm>
|
||||
|
||||
Service::Service()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Service::~Service()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Service::addTask(std::string description, int duration, std::string date)
|
||||
{
|
||||
Task task(description, duration, date);
|
||||
this->repo.addTask(task);
|
||||
}
|
||||
|
||||
std::vector<Task> Service::getTasks()
|
||||
{
|
||||
auto tasks = this->repo.getTasks();
|
||||
std::sort(tasks.begin(), tasks.end(), [](Task task1, Task task2) {
|
||||
if(task1.getDate() == task2.getDate())
|
||||
return task1.getDuration() > task2.getDuration();
|
||||
return task1.getDate() > task2.getDate();
|
||||
});
|
||||
return tasks;
|
||||
}
|
||||
|
||||
std::vector<Task> Service::getTasksForDate(std::string date)
|
||||
{
|
||||
auto tasks = this->repo.getTasks();
|
||||
std::vector<Task> filteredTasks;
|
||||
for (auto task : tasks) {
|
||||
if(task.getDate() == date)
|
||||
filteredTasks.push_back(task);
|
||||
}
|
||||
return filteredTasks;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include "repo.h"
|
||||
|
||||
class Service {
|
||||
private:
|
||||
Repo repo;
|
||||
public:
|
||||
Service();
|
||||
~Service();
|
||||
void addTask(std::string description, int duration, std::string date);
|
||||
std::vector<Task> getTasks();
|
||||
std::vector<Task> getTasksForDate(std::string date);
|
||||
};
|
||||
Reference in New Issue
Block a user