Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef EKZ_H
- #define EKZ_H
- #include <qmainwindow.h>
- #include <QInputDialog>
- #include <QMessageBox>
- #include "ui_ekz.h"
- class Action {
- protected:
- bool completed = false;
- QString name = "";
- public:
- Action(QString name)
- {
- this->name = name;
- }
- QString getName()
- {
- return name;
- }
- void setCompleted(bool isComplete)
- {
- this->completed = isComplete;
- }
- bool isComleted()
- {
- return completed;
- }
- };
- class Ekz: public QMainWindow {
- Q_OBJECT
- protected:
- QList<Action*> actions;
- public:
- Ekz(QWidget *parent = 0)
- {
- ui.setupUi(this);
- ui.tblActions->setEditTriggers(QAbstractItemView::NoEditTriggers);
- }
- ~Ekz()
- {
- }
- QTableWidgetItem* getTableItem(QTableWidget* table, int x, int y)
- {
- QTableWidgetItem* item = table->item(x, y);
- if (item == nullptr)
- {
- item = new QTableWidgetItem("");
- table->setItem(x, y, item);
- }
- return item;
- }
- void updateTable()
- {
- QTableWidget* table = ui.tblActions;
- table->setColumnCount(1);
- table->setRowCount(actions.size());
- Action* act = nullptr;
- for (int i1 = 0; i1 < table->rowCount(); i1 ++)
- {
- act = actions.at(i1);
- QTableWidgetItem* item = getTableItem(table, i1, 0);
- item->setText(act->getName());
- item->setBackground(QBrush(act->isComleted() ? Qt::green : Qt::red));
- }
- }
- Action* findAction(QString name)
- {
- for (int i1 = 0; i1 < actions.size(); i1 ++)
- {
- if (actions.at(i1)->getName() == name)
- {
- return actions.at(i1);
- }
- }
- return nullptr;
- }
- public slots:
- void on_actAdd_triggered()
- {
- QString name = QInputDialog::getText(nullptr, "Ввод", "Введите название дела");
- if (name.isEmpty())
- {
- return;
- }
- if (findAction(name) != nullptr)
- {
- QMessageBox::warning(nullptr, "Упс...", "В вашем списке уже существуе такое дело!");
- return;
- }
- actions.append(new Action(name));
- updateTable();
- }
- void on_actRemove_triggered()
- {
- int index = ui.tblActions->currentRow();
- Action* act = actions.at(index);
- actions.removeAt(index);
- updateTable();
- delete act;
- }
- void on_actComplete_triggered()
- {
- Action* act = actions.at(ui.tblActions->currentRow());
- act->setCompleted(true);
- updateTable();
- }
- void on_actUncomplete_triggered()
- {
- Action* act = actions.at(ui.tblActions->currentRow());
- act->setCompleted(false);
- updateTable();
- }
- private:
- Ui::EkzClass ui;
- };
- #endif // EKZ_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement