Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "ProgrammerWindow.h"
- #include "Task.h"
- #include <qformlayout.h>
- #include <qlabel.h>
- #include <qlineedit.h>
- #include <qpushbutton.h>
- #include <qlistwidget.h>
- #include <qmessagebox.h>
- ProgrammerWindow::ProgrammerWindow(TaskRepo &tasks, string name, int id,QWidget *parent)
- : QWidget(parent),name(name),id(id),tasks(tasks)
- {
- ui.setupUi(this);
- this->tasks.addObserver(this);
- this->setWindowTitle(this->getName().c_str());
- lw = new QListWidget();
- for (auto &elem : this->tasks.getTasks())
- lwItems.emplace_back(new QListWidgetItem(elem.toString().c_str(),lw));
- QFormLayout* layout = new QFormLayout{};
- taskList = new QListWidget{};
- taskList->setSelectionMode(QAbstractItemView::SingleSelection);
- for (auto t : this->getCtrl().getTasks())
- {
- QString itemInList = QString::fromStdString(t.getDescription() + " " + t.getStatus());
- QListWidgetItem* item = new QListWidgetItem{ itemInList };
- taskList->addItem(item);
- }
- layout->addWidget(taskList);
- QLabel* descrLabel = new QLabel{ "&Description: " };
- QLineEdit* descrTextBox = new QLineEdit{};
- descrLabel->setBuddy(descrTextBox);
- layout->addRow(descrLabel, descrTextBox);
- QPushButton* addButton = new QPushButton{ "Add" };
- layout->addWidget(addButton);
- QObject::connect(addButton, &QPushButton::clicked, [descrTextBox, this]() {
- string descr = descrTextBox->text().toUtf8().constData();
- Task t = Task(descr, string("open"));
- this->tasks.addTask(t);
- QString itemInList = QString::fromStdString(t.getDescription() + " " + t.getStatus());
- QListWidgetItem* item = new QListWidgetItem{ itemInList };
- taskList->addItem(item);
- this->getCtrl().writeToFile();
- });
- QPushButton* deleteButton = new QPushButton{ "Delete" };
- layout->addWidget(deleteButton);
- QObject::connect(deleteButton, &QPushButton::clicked, [this]() {
- auto t = this->getCtrl().getTasks()[this->getTLRow()];
- this->getCtrl().removeTask(t.getDescription());
- this->removeTask(t.getDescription());
- if (taskList->count() > 0)
- taskList->clear();
- for (auto t : this->getSortedTasks())
- {
- QString itemInList = QString::fromStdString(t.getDescription() + " " + t.getStatus());
- QListWidgetItem* item = new QListWidgetItem{ itemInList };
- taskList->addItem(item);
- }
- this->getCtrl().writeToFile();
- });
- QPushButton* startButton = new QPushButton{ "Start" };
- layout->addWidget(startButton);
- QObject::connect(startButton, &QPushButton::clicked, [this]() {
- auto t = this->getCtrl().getTasks()[this->getTLRow()];
- this->getCtrl().getTasks()[this->getTLRow()].setStarted(true);
- string name = "";
- try
- {
- this->getCtrl().startTask(t.getDescription());
- QString Qname = QWidget::windowTitle();
- name = Qname.toStdString();
- this->getCtrl().getTasks()[this->getTLRow()].setID(this->getCtrl().searchID(name));
- }
- catch (notOpenException& e)
- {
- QMessageBox::information(this, e.what(), e.what());
- }
- if (taskList->count() > 0)
- taskList->clear();
- for (auto t : this->getSortedTasks())
- {
- QString itemInList;
- if (t.getStarted())
- itemInList = QString::fromStdString(t.getDescription() + " " + t.getStatus() + " " + name);
- else
- itemInList = QString::fromStdString(t.getDescription() + " " + t.getStatus());
- QListWidgetItem* item = new QListWidgetItem{ itemInList };
- taskList->addItem(item);
- }
- this->getCtrl().writeToFile();
- });
- QPushButton* doneButton = new QPushButton{ "Done" };
- layout->addWidget(doneButton);
- QObject::connect(doneButton, &QPushButton::clicked, [this]() {
- auto t = this->getCtrl().getTasks()[this->getTLRow()];
- string name;
- try
- {
- this->getCtrl().doneTask(t.getDescription());
- QString Qname = QWidget::windowTitle();
- name = Qname.toStdString();
- }
- catch (notOpenException& e)
- {
- QMessageBox::information(this, e.what(), e.what());
- }
- if (taskList->count() > 0)
- taskList->clear();
- for (auto t : this->getSortedTasks())
- {
- QString itemInList;
- if (t.getStarted())
- itemInList = QString::fromStdString(t.getDescription() + " " + t.getStatus() + " " + name);
- else
- itemInList = QString::fromStdString(t.getDescription() + " " + t.getStatus());
- QListWidgetItem* item = new QListWidgetItem{ itemInList };
- taskList->addItem(item);
- }
- this->getCtrl().writeToFile();
- });
- this->setLayout(layout);
- }
- ProgrammerWindow::~ProgrammerWindow()
- {
- this->tasks.removeObserver(this);
- }
- void ProgrammerWindow::update() {
- taskList->clear();
- lwItems.clear();
- for (auto &q : tasks.getTasks())
- {
- lwItems.emplace_back(new QListWidgetItem(q.toString().c_str(), taskList));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement