Adding filters
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
#define PRIORITIES_KEY "priorities"
|
||||
#define STATUS_KEY "status"
|
||||
#define BOARDS_KEY "boards"
|
||||
#define FILTERS_KEY "filters"
|
||||
|
||||
#include <QUuid>
|
||||
#include <QColor>
|
||||
@@ -36,10 +37,13 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
connect(ui->actionNew_filter, &QAction::triggered, this, &MainWindow::onNewFilterClick);
|
||||
connect(ui->boardList, &QListWidget::currentRowChanged, this, &MainWindow::onBoardSelected);
|
||||
connect(ui->boardList, &QListWidget::customContextMenuRequested, this, &MainWindow::prepareBoardMenu);
|
||||
connect(ui->filterListWidget, &QListWidget::currentRowChanged, this, &MainWindow::onFilterSelected);
|
||||
connect(ui->filterListWidget, &QListWidget::customContextMenuRequested, this, &MainWindow::prepareFilterMenu);
|
||||
connect(ui->taskList, &QTreeWidget::itemDoubleClicked, this, &MainWindow::onEditTask);
|
||||
connect(ui->taskList, &QTreeWidget::customContextMenuRequested, this, &MainWindow::prepareTaskMenu);
|
||||
ui->boardList->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
ui->taskList->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
ui->filterListWidget->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
@@ -93,8 +97,10 @@ void MainWindow::prepareBoardMenu(const QPoint &pos)
|
||||
|
||||
void MainWindow::prepareTaskMenu(const QPoint &pos)
|
||||
{
|
||||
bool show = false;
|
||||
QMenu menu(this);
|
||||
if (ui->taskList->selectedItems().length() == 1) {
|
||||
show = true;
|
||||
QAction *renameAction = new QAction(tr("Edit the task"), this);
|
||||
connect(renameAction, &QAction::triggered, this, &MainWindow::onEditNameTaskMenu);
|
||||
menu.addAction(renameAction);
|
||||
@@ -105,11 +111,18 @@ void MainWindow::prepareTaskMenu(const QPoint &pos)
|
||||
|
||||
menu.addSeparator();
|
||||
}
|
||||
QAction *addAction = new QAction(tr("New task"), this);
|
||||
connect(addAction, &QAction::triggered, this, &MainWindow::onNewTaskClick);
|
||||
menu.addAction(addAction);
|
||||
if (selectedBoardIndex > -1)
|
||||
{
|
||||
show = true;
|
||||
QAction *addAction = new QAction(tr("New task"), this);
|
||||
connect(addAction, &QAction::triggered, this, &MainWindow::onNewTaskClick);
|
||||
menu.addAction(addAction);
|
||||
}
|
||||
|
||||
menu.exec(ui->taskList->mapToGlobal(pos));
|
||||
if (show)
|
||||
{
|
||||
menu.exec(ui->taskList->mapToGlobal(pos));
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::onNewBoardClick()
|
||||
@@ -152,14 +165,24 @@ void MainWindow::onNewFilterClick()
|
||||
if (dialog.exec() == QDialog::DialogCode::Accepted)
|
||||
{
|
||||
Filter f = dialog.getFilter();
|
||||
filters.append(f);
|
||||
QListWidgetItem *item = new QListWidgetItem(f.getName());
|
||||
item->setToolTip(f.getDescription());
|
||||
ui->filterListWidget->addItem(item);
|
||||
save();
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::onBoardSelected(int i)
|
||||
{
|
||||
selectedBoardIndex = i;
|
||||
selectedFilterIndex = -1;
|
||||
|
||||
ui->filterListWidget->blockSignals(true);
|
||||
ui->filterListWidget->setCurrentIndex(ui->filterListWidget->currentIndex().sibling(-1, -1));
|
||||
ui->filterListWidget->blockSignals(false);
|
||||
|
||||
filterResult.clear();
|
||||
if (selectedBoardIndex > -1)
|
||||
{
|
||||
Board *b = boards[selectedBoardIndex];
|
||||
@@ -176,22 +199,46 @@ void MainWindow::onBoardSelected(int i)
|
||||
redrawTaskTree();
|
||||
}
|
||||
|
||||
void MainWindow::onFilterSelected(int i)
|
||||
{
|
||||
selectedFilterIndex = i;
|
||||
selectedBoardIndex = -1;
|
||||
|
||||
ui->boardList->blockSignals(true);
|
||||
ui->boardList->setCurrentIndex(ui->boardList->currentIndex().sibling(-1, -1));
|
||||
ui->boardList->blockSignals(false);
|
||||
|
||||
filterResult.clear();
|
||||
ui->actionNew_task->setDisabled(true);
|
||||
if (selectedFilterIndex > -1)
|
||||
{
|
||||
Filter f = filters[selectedFilterIndex];
|
||||
ui->label->setText(f.getName());
|
||||
ui->boardDescription->setText(f.getDescription());
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->label->setText("No board selected");
|
||||
ui->boardDescription->clear();
|
||||
}
|
||||
redrawTaskTree();
|
||||
}
|
||||
|
||||
void MainWindow::onEditTask(QTreeWidgetItem *item)
|
||||
{
|
||||
if (item != nullptr && selectedBoardIndex > -1)
|
||||
Task *t = getSelectedTask();
|
||||
if (t != nullptr)
|
||||
{
|
||||
Board *b = boards[selectedBoardIndex];
|
||||
int row = ui->taskList->indexOfTopLevelItem(item);
|
||||
Task *t = b->taskAt(row);
|
||||
if (t != nullptr)
|
||||
TaskDialog dialog(t, status, priorities, this);
|
||||
if (dialog.exec() == QDialog::DialogCode::Accepted)
|
||||
{
|
||||
TaskDialog dialog(t, status, priorities, this);
|
||||
if (dialog.exec() == QDialog::DialogCode::Accepted)
|
||||
Task editedTask = dialog.getTask();
|
||||
t->update(editedTask);
|
||||
updateTaskRow(item, editedTask);
|
||||
save();
|
||||
if (selectedFilterIndex > -1)
|
||||
{
|
||||
Task editedTask = dialog.getTask();
|
||||
t->update(editedTask);
|
||||
updateTaskRow(item, editedTask);
|
||||
save();
|
||||
redrawTaskTree();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -229,6 +276,22 @@ void MainWindow::onRemoveTaskMenu()
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::onRemoveFilterMenu()
|
||||
{
|
||||
if (selectedFilterIndex > -1)
|
||||
{
|
||||
QMessageBox::StandardButton result = QMessageBox::question(this, "Delete a filter", "Do you want to delete this filter?");
|
||||
if (result == QMessageBox::Yes)
|
||||
{
|
||||
filters.removeAt(selectedFilterIndex);
|
||||
delete ui->filterListWidget->takeItem(selectedFilterIndex);
|
||||
selectedFilterIndex = -1;
|
||||
redrawTaskTree();
|
||||
save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::onEditNameBoardMenu()
|
||||
{
|
||||
if (selectedBoardIndex > -1)
|
||||
@@ -253,12 +316,55 @@ void MainWindow::onEditNameBoardMenu()
|
||||
|
||||
void MainWindow::onEditNameTaskMenu()
|
||||
{
|
||||
if (selectedBoardIndex > -1 && ui->taskList->selectedItems().length() == 1)
|
||||
Task *t = getSelectedTask();
|
||||
if (t != nullptr)
|
||||
{
|
||||
onEditTask(ui->taskList->currentItem());
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::onEditFilterMenu()
|
||||
{
|
||||
if (selectedFilterIndex > -1)
|
||||
{
|
||||
Filter f = filters[selectedFilterIndex];
|
||||
FilterDialog dialog("Edit the filter", f, boards, status, priorities, this);
|
||||
if (dialog.exec() == QDialog::DialogCode::Accepted)
|
||||
{
|
||||
Filter f = dialog.getFilter();
|
||||
filters[selectedFilterIndex] = f;
|
||||
QListWidgetItem *item = ui->filterListWidget->item(selectedFilterIndex);
|
||||
item->setText(f.getName());
|
||||
item->setToolTip(f.getDescription());
|
||||
ui->label->setText(f.getName());
|
||||
ui->boardDescription->setText(f.getDescription());
|
||||
redrawTaskTree();
|
||||
save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::prepareFilterMenu(const QPoint &pos)
|
||||
{
|
||||
QMenu menu(this);
|
||||
if (ui->filterListWidget->selectedItems().length() == 1) {
|
||||
QAction *renameAction = new QAction(tr("Edit the filter"), this);
|
||||
connect(renameAction, &QAction::triggered, this, &MainWindow::onEditFilterMenu);
|
||||
menu.addAction(renameAction);
|
||||
|
||||
QAction *deleteAction = new QAction(tr("Delete"), this);
|
||||
connect(deleteAction, &QAction::triggered, this, &MainWindow::onRemoveFilterMenu);
|
||||
menu.addAction(deleteAction);
|
||||
|
||||
menu.addSeparator();
|
||||
}
|
||||
QAction *addAction = new QAction(tr("New filter"), this);
|
||||
connect(addAction, &QAction::triggered, this, &MainWindow::onNewFilterClick);
|
||||
menu.addAction(addAction);
|
||||
|
||||
menu.exec(ui->filterListWidget->mapToGlobal(pos));
|
||||
}
|
||||
|
||||
void MainWindow::init()
|
||||
{
|
||||
if (Tools::isSaveFileExist())
|
||||
@@ -270,15 +376,24 @@ void MainWindow::init()
|
||||
QJsonArray jsonPriorities = save[PRIORITIES_KEY].toArray();
|
||||
QJsonArray jsonStatus = save[STATUS_KEY].toArray();
|
||||
QJsonArray jsonBoards = save[BOARDS_KEY].toArray();
|
||||
for (QJsonValueRef value : jsonPriorities) {
|
||||
QJsonArray jsonFilters = save[FILTERS_KEY].toArray();
|
||||
for (QJsonValueRef value : jsonPriorities)
|
||||
{
|
||||
priorities.append(Priority(value.toObject()));
|
||||
}
|
||||
for (QJsonValueRef value : jsonStatus) {
|
||||
for (QJsonValueRef value : jsonStatus)
|
||||
{
|
||||
status.append(Status(value.toObject()));
|
||||
}
|
||||
for (QJsonValueRef value : jsonBoards) {
|
||||
for (QJsonValueRef value : jsonBoards)
|
||||
{
|
||||
boards.append(new Board(value.toObject()));
|
||||
}
|
||||
for (QJsonValueRef value : jsonFilters)
|
||||
{
|
||||
filters.append(Filter(value.toObject()));
|
||||
}
|
||||
redrawFilterList();
|
||||
redrawBoardList();
|
||||
return;
|
||||
}
|
||||
@@ -381,13 +496,46 @@ const QJsonDocument MainWindow::getJsonSave()
|
||||
foreach (Board *b, this->boards) {
|
||||
jsonBoards.append(b->toJson());
|
||||
}
|
||||
QJsonArray jsonFilters;
|
||||
foreach (Filter f, this->filters)
|
||||
{
|
||||
jsonFilters.append(f.toJson());
|
||||
}
|
||||
obj[PRIORITIES_KEY] = jsonPriorities;
|
||||
obj[STATUS_KEY] = jsonStatus;
|
||||
obj[BOARDS_KEY] = jsonBoards;
|
||||
obj[FILTERS_KEY] = jsonFilters;
|
||||
doc.setObject(obj);
|
||||
return doc;
|
||||
}
|
||||
|
||||
Task *MainWindow::getSelectedTask()
|
||||
{
|
||||
if (selectedBoardIndex > -1)
|
||||
{
|
||||
Board *b = boards[selectedBoardIndex];
|
||||
QList<QTreeWidgetItem*> items = ui->taskList->selectedItems();
|
||||
if (items.count() == 1)
|
||||
{
|
||||
int16_t i = ui->taskList->indexOfTopLevelItem(items[0]);
|
||||
return b->taskAt(i);
|
||||
}
|
||||
}
|
||||
else if (selectedFilterIndex > -1)
|
||||
{
|
||||
if (!filterResult.empty())
|
||||
{
|
||||
QList<QTreeWidgetItem*> items = ui->taskList->selectedItems();
|
||||
if (items.count() == 1)
|
||||
{
|
||||
int16_t i = ui->taskList->indexOfTopLevelItem(items[0]);
|
||||
return filterResult[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void MainWindow::updateTaskRow(QTreeWidgetItem *item, Task t)
|
||||
{
|
||||
item->setText(0, t.getTitle());
|
||||
@@ -453,6 +601,22 @@ void MainWindow::redrawBoardList()
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::redrawFilterList()
|
||||
{
|
||||
QListWidget *l = ui->filterListWidget;
|
||||
uint16_t itemCount = l->count();
|
||||
for (int16_t i = itemCount; i >= 0; i--)
|
||||
{
|
||||
delete l->takeItem(i);
|
||||
}
|
||||
foreach (Filter f, filters)
|
||||
{
|
||||
QListWidgetItem *item = new QListWidgetItem(f.getName());
|
||||
item->setToolTip(f.getDescription());
|
||||
l->addItem(item);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::redrawTaskTree()
|
||||
{
|
||||
QTreeWidget *l = ui->taskList;
|
||||
@@ -471,7 +635,17 @@ void MainWindow::redrawTaskTree()
|
||||
ui->taskList->addTopLevelItem(item);
|
||||
}
|
||||
}
|
||||
|
||||
else if (selectedFilterIndex > -1)
|
||||
{
|
||||
Filter f = filters[selectedFilterIndex];
|
||||
filterResult = f.filter(boards);
|
||||
foreach (Task *t, filterResult)
|
||||
{
|
||||
QTreeWidgetItem *item = new QTreeWidgetItem();
|
||||
updateTaskRow(item, *t);
|
||||
ui->taskList->addTopLevelItem(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::save()
|
||||
|
||||
Reference in New Issue
Block a user