auto determine board status, show board status
This commit is contained in:
@@ -25,6 +25,7 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
, ui(new Ui::MainWindow)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->boardStatus->setVisible(false);
|
||||
this->menuSelectedBoardItem = nullptr;
|
||||
this->menuSelectedFilterItem = nullptr;
|
||||
this->menuSelectedTaskItem = nullptr;
|
||||
@@ -245,6 +246,7 @@ void MainWindow::onEditTask(QTreeWidgetItem *item)
|
||||
t->update(editedTask);
|
||||
updateTaskRow(item, editedTask);
|
||||
save();
|
||||
redrawBoardStatus();
|
||||
if (selectedFilterIndex > -1)
|
||||
{
|
||||
redrawTaskTree();
|
||||
@@ -629,6 +631,13 @@ void MainWindow::redrawTaskTree()
|
||||
if (selectedBoardIndex > -1)
|
||||
{
|
||||
Board *b = boards[selectedBoardIndex];
|
||||
std::optional<Status> boardStatus = TaskStateService::getInstance()->getStatusByUUID(b->getStatus());
|
||||
if (boardStatus.has_value())
|
||||
{
|
||||
ui->boardStatus->setStyleSheet(Tools::getStatusLabelStylesheet(boardStatus.value()));
|
||||
ui->boardStatus->setText(boardStatus.value().getName());
|
||||
ui->boardStatus->setVisible(true);
|
||||
}
|
||||
foreach (Task *t, b->getTasks())
|
||||
{
|
||||
QTreeWidgetItem *item = new QTreeWidgetItem();
|
||||
@@ -647,6 +656,23 @@ void MainWindow::redrawTaskTree()
|
||||
ui->taskList->addTopLevelItem(item);
|
||||
}
|
||||
}
|
||||
redrawBoardStatus();
|
||||
}
|
||||
|
||||
void MainWindow::redrawBoardStatus()
|
||||
{
|
||||
ui->boardStatus->setVisible(false);
|
||||
if (selectedBoardIndex > -1)
|
||||
{
|
||||
Board *b = boards[selectedBoardIndex];
|
||||
std::optional<Status> boardStatus = TaskStateService::getInstance()->getStatusByUUID(b->getStatus());
|
||||
if (boardStatus.has_value())
|
||||
{
|
||||
ui->boardStatus->setStyleSheet(Tools::getStatusLabelStylesheet(boardStatus.value()));
|
||||
ui->boardStatus->setText(boardStatus.value().getName());
|
||||
ui->boardStatus->setVisible(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::save()
|
||||
|
||||
@@ -78,6 +78,7 @@ private:
|
||||
void redrawBoardList();
|
||||
void redrawFilterList();
|
||||
void redrawTaskTree();
|
||||
void redrawBoardStatus();
|
||||
void save();
|
||||
};
|
||||
#endif // MAINWINDOW_H
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
</property>
|
||||
<widget class="QWidget" name="centralwidget">
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<item row="4" column="0">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
@@ -87,6 +87,10 @@
|
||||
<property name="sizeConstraint">
|
||||
<enum>QLayout::SetMaximumSize</enum>
|
||||
</property>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="font">
|
||||
@@ -106,6 +110,39 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="boardStatus">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>100</width>
|
||||
<height>24</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>100</width>
|
||||
<height>24</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">border-color: rgb(87, 227, 137);
|
||||
border: solid;
|
||||
background-color: rgb(87, 227, 137);
|
||||
border-radius: 4px;
|
||||
color: white;</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>TextLabel</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTreeWidget" name="taskList">
|
||||
<property name="alternatingRowColors">
|
||||
|
||||
@@ -41,6 +41,8 @@ PrefDialog::PrefDialog(QWidget *parent) :
|
||||
connect(ui->namePriorityEdit, &QLineEdit::textEdited, this, &PrefDialog::onNameChange);
|
||||
connect(ui->removeStatusButton, &QPushButton::clicked, this, &PrefDialog::onRemoveStatusButtonClick);
|
||||
connect(ui->removePriorityButton, &QPushButton::clicked, this, &PrefDialog::onRemovePriorityButtonClick);
|
||||
connect(ui->upStatus, &QPushButton::clicked, this, &PrefDialog::onUpStatusButtonClick);
|
||||
connect(ui->downStatus, &QPushButton::clicked, this, &PrefDialog::onDownStatusButtonClick);
|
||||
}
|
||||
|
||||
PrefDialog::~PrefDialog()
|
||||
@@ -116,6 +118,16 @@ void PrefDialog::onItemSelectionChange(int index)
|
||||
colorBtn = ui->colorStatusButton;
|
||||
nameEdit = ui->nameStatusEdit;
|
||||
colorEdit = ui->colorStatusEdit;
|
||||
if (index > -1)
|
||||
{
|
||||
ui->downStatus->setEnabled((index > 0));
|
||||
ui->upStatus->setEnabled((index < statusUUIDRef.size()-1));
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->downStatus->setEnabled(false);
|
||||
ui->upStatus->setEnabled(false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -211,6 +223,46 @@ void PrefDialog::onRemovePriorityButtonClick()
|
||||
priorityUUIDRef.removeAt(index);
|
||||
}
|
||||
|
||||
void PrefDialog::onUpStatusButtonClick()
|
||||
{
|
||||
if (ui->statusListWidget->selectedItems().size() != 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int i = ui->statusListWidget->indexFromItem(ui->statusListWidget->selectedItems()[0]).row();
|
||||
if (i < statusUUIDRef.size())
|
||||
{
|
||||
QListWidgetItem *item = ui->statusListWidget->takeItem(i);
|
||||
i++;
|
||||
ui->statusListWidget->insertItem(i, item);
|
||||
statusUUIDRef.move(i-1, i);
|
||||
|
||||
ui->downStatus->setEnabled((i > 0));
|
||||
ui->upStatus->setEnabled((i < statusUUIDRef.size()-1));
|
||||
ui->statusListWidget->setCurrentRow(i);
|
||||
}
|
||||
}
|
||||
|
||||
void PrefDialog::onDownStatusButtonClick()
|
||||
{
|
||||
if (ui->statusListWidget->selectedItems().size() != 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int i = ui->statusListWidget->indexFromItem(ui->statusListWidget->selectedItems()[0]).row();
|
||||
if (i > 0)
|
||||
{
|
||||
QListWidgetItem *item = ui->statusListWidget->takeItem(i);
|
||||
i--;
|
||||
ui->statusListWidget->insertItem(i, item);
|
||||
statusUUIDRef.move(i+1, i);
|
||||
|
||||
ui->downStatus->setEnabled((i > 0));
|
||||
ui->upStatus->setEnabled((i < statusUUIDRef.size()-1));
|
||||
ui->statusListWidget->setCurrentRow(i);
|
||||
}
|
||||
}
|
||||
|
||||
void PrefDialog::setItemColor(QListWidgetItem *item, QColor bgColor)
|
||||
{
|
||||
QColor fgColor = Tools::getForegroundColor(bgColor);
|
||||
|
||||
@@ -31,7 +31,8 @@ private slots:
|
||||
void onNameChange();
|
||||
void onRemoveStatusButtonClick();
|
||||
void onRemovePriorityButtonClick();
|
||||
|
||||
void onUpStatusButtonClick();
|
||||
void onDownStatusButtonClick();
|
||||
private:
|
||||
Ui::PrefDialog *ui;
|
||||
|
||||
|
||||
@@ -150,7 +150,7 @@
|
||||
<x>570</x>
|
||||
<y>310</y>
|
||||
<width>41</width>
|
||||
<height>32</height>
|
||||
<height>21</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
@@ -166,13 +166,45 @@
|
||||
<x>520</x>
|
||||
<y>310</y>
|
||||
<width>41</width>
|
||||
<height>31</height>
|
||||
<height>21</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>-</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="downStatus">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>20</x>
|
||||
<y>310</y>
|
||||
<width>41</width>
|
||||
<height>21</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Down</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="upStatus">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>70</x>
|
||||
<y>310</y>
|
||||
<width>41</width>
|
||||
<height>21</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Up</string>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tab_2">
|
||||
<attribute name="title">
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
#include <QJsonValue>
|
||||
#include <QUuid>
|
||||
|
||||
#include "../services/taskstateservice.h"
|
||||
|
||||
Board::Board(QString name, QString description)
|
||||
{
|
||||
QUuid uuid = QUuid::createUuid();
|
||||
@@ -60,6 +62,22 @@ const QString Board::getDescription()
|
||||
|
||||
const QString Board::getStatus()
|
||||
{
|
||||
if (autoStatus)
|
||||
{
|
||||
TaskStateService *tss = TaskStateService::getInstance();
|
||||
int16_t h = -1;
|
||||
QString suuid = "";
|
||||
for (Task *t : tasks)
|
||||
{
|
||||
int16_t w = tss->getStatusWeight(t->getStatusUUID());
|
||||
if (w > -1 && h < w)
|
||||
{
|
||||
h = w;
|
||||
suuid = t->getStatusUUID();
|
||||
}
|
||||
}
|
||||
return suuid;
|
||||
}
|
||||
return statusUUID;
|
||||
}
|
||||
|
||||
|
||||
@@ -53,6 +53,20 @@ std::optional<Priority> TaskStateService::getPriorityByUUID(QString uuid)
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
int16_t TaskStateService::getStatusWeight(QString uuid)
|
||||
{
|
||||
int16_t weight = -1;
|
||||
for (uint16_t i = 0; i < statuses.count(); i++)
|
||||
{
|
||||
if (statuses[i].getUUID() == uuid)
|
||||
{
|
||||
weight = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return weight;
|
||||
}
|
||||
|
||||
TaskStateService::TaskStateService()
|
||||
{
|
||||
priorities.append(Priority(QUuid::createUuid().toString(QUuid::WithoutBraces), "None", QColor(217, 217, 217)));
|
||||
|
||||
@@ -19,6 +19,7 @@ public:
|
||||
|
||||
std::optional<Status> getStatusByUUID(QString);
|
||||
std::optional<Priority> getPriorityByUUID(QString);
|
||||
int16_t getStatusWeight(QString uuid);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
#include <QStandardPaths>
|
||||
#include <QDir>
|
||||
|
||||
#include "services/taskstateservice.h"
|
||||
|
||||
Tools::Tools()
|
||||
{
|
||||
|
||||
@@ -95,3 +97,14 @@ bool Tools::readSaveFile(QJsonDocument &doc) {
|
||||
doc = QJsonDocument::fromJson(json.toUtf8());
|
||||
return true;
|
||||
}
|
||||
|
||||
const QString Tools::getStatusLabelStylesheet(Status status)
|
||||
{
|
||||
QColor bg = status.getColor();
|
||||
QColor fg = Tools::getForegroundColor(bg);
|
||||
return QString("border-color: %1; \
|
||||
border: solid; \
|
||||
background-color: %1; \
|
||||
border-radius: 4px; \
|
||||
color: %2;").arg(bg.name(QColor::HexRgb), fg.name(QColor::HexRgb));
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
#include <QColor>
|
||||
#include <QJsonDocument>
|
||||
|
||||
#include "models/status.h"
|
||||
|
||||
class Tools
|
||||
{
|
||||
public:
|
||||
@@ -14,6 +16,7 @@ public:
|
||||
static bool isSaveFileExist();
|
||||
static bool writeSaveToFile(QJsonDocument doc);
|
||||
static bool readSaveFile(QJsonDocument &doc);
|
||||
static const QString getStatusLabelStylesheet(Status);
|
||||
|
||||
private:
|
||||
static const QString getSaveFilePath();
|
||||
|
||||
Reference in New Issue
Block a user