add events
This commit is contained in:
@@ -153,7 +153,13 @@ QString NoteService::update(QUuid listUuid, QUuid noteUuid, QString newValue)
|
||||
throw std::runtime_error("Note not found");
|
||||
}
|
||||
|
||||
Note n = Note(listUuid, noteUuid, newValue, false);
|
||||
std::optional<Note> note = getByUUID(noteUuid);
|
||||
|
||||
if (!note.has_value()) {
|
||||
throw std::runtime_error("database integrity corrupted");
|
||||
}
|
||||
|
||||
Note n = Note(listUuid, noteUuid, newValue, note.value().isFinished());
|
||||
emit onNoteUpdated(n);
|
||||
return newValue;
|
||||
}
|
||||
|
||||
@@ -10,6 +10,16 @@ InputDialog::InputDialog(QWidget *parent, QString title, QString headline, QStri
|
||||
ui->message->setText(message);
|
||||
}
|
||||
|
||||
InputDialog::InputDialog(QWidget *parent, QString title, QString headline, QString message, QString content) : QDialog(parent), ui(new Ui::InputDialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
this->setWindowTitle(title);
|
||||
ui->errorLabel->setVisible(false);
|
||||
ui->headline->setText(headline);
|
||||
ui->message->setText(message);
|
||||
ui->lineEdit->setText(content);
|
||||
}
|
||||
|
||||
InputDialog::~InputDialog()
|
||||
{
|
||||
delete ui;
|
||||
|
||||
@@ -14,6 +14,7 @@ class InputDialog : public QDialog
|
||||
|
||||
public:
|
||||
InputDialog(QWidget *parent, QString title, QString headline, QString message);
|
||||
InputDialog(QWidget *parent, QString title, QString headline, QString message, QString content);
|
||||
~InputDialog();
|
||||
|
||||
QString getInput();
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "src/core/noteservice.h"
|
||||
|
||||
#include <QDialogButtonBox>
|
||||
#include <QMenu>
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent)
|
||||
: QMainWindow(parent)
|
||||
@@ -20,12 +21,14 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
// ui
|
||||
connect(ui->addListButton, &QPushButton::clicked, this, &MainWindow::openCreateListDialog);
|
||||
connect(ui->lists, &QListWidget::currentRowChanged, this, &MainWindow::onListSelected);
|
||||
connect(ui->lists, &QWidget::customContextMenuRequested, this, &MainWindow::onListRightClick);
|
||||
connect(ui->saveNoteButton, &QPushButton::clicked, this, &MainWindow::onSaveNoteButtonClicked);
|
||||
connect(ui->notes, &QListWidget::itemChanged, this, &MainWindow::onNoteChanged);
|
||||
|
||||
// services
|
||||
connect(ListService::getInstance(), &ListService::onListCreated, this, &MainWindow::onListCreated);
|
||||
connect(ListService::getInstance(), &ListService::onListUpdated, this, &MainWindow::onListCreated);
|
||||
connect(ListService::getInstance(), &ListService::onListUpdated, this, &MainWindow::onListUpdate);
|
||||
connect(ListService::getInstance(), &ListService::onListDeleted, this, &MainWindow::onListDeleted);
|
||||
connect(NoteService::getInstance(), &NoteService::onNoteCreated, this, &MainWindow::onNoteCreated);
|
||||
|
||||
preload();
|
||||
@@ -63,7 +66,7 @@ void MainWindow::onListCreated(List value)
|
||||
void MainWindow::onListUpdate(List value)
|
||||
{
|
||||
QListWidgetItem *item = nullptr;
|
||||
for (int i = 0; i > ui->lists->count(); i++) {
|
||||
for (int i = 0; i < ui->lists->count(); i++) {
|
||||
item = ui->lists->item(i);
|
||||
|
||||
if (item->data(Qt::UserRole).toUuid() == value.getUUID()) {
|
||||
@@ -73,6 +76,20 @@ void MainWindow::onListUpdate(List value)
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::onListDeleted(QUuid uuid)
|
||||
{
|
||||
QListWidgetItem *item = nullptr;
|
||||
for (int i = 0; i < ui->lists->count(); i++) {
|
||||
item = ui->lists->item(i);
|
||||
|
||||
if (item->data(Qt::UserRole).toUuid() == uuid) {
|
||||
ui->lists->removeItemWidget(item);
|
||||
delete item;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::onNoteCreated(Note value)
|
||||
{
|
||||
QListWidgetItem* item = new QListWidgetItem();
|
||||
@@ -97,7 +114,7 @@ void MainWindow::onNoteUpdated(Note value)
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i > ui->notes->count(); i++) {
|
||||
for (int i = 0; i < ui->notes->count(); i++) {
|
||||
item = ui->notes->item(i);
|
||||
|
||||
if (item->data(Qt::UserRole).toUuid() == value.getUUID()) {
|
||||
@@ -169,6 +186,48 @@ void MainWindow::onNoteChanged(QListWidgetItem *item)
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::onListRightClick(const QPoint &pos)
|
||||
{
|
||||
if (ui->lists->selectedItems().length() == 1) {
|
||||
QMenu menu(this);
|
||||
|
||||
QAction *renameAction = new QAction(tr("Rename"), this);
|
||||
connect(renameAction, &QAction::triggered, this, &MainWindow::onListContextMenuRename);
|
||||
menu.addAction(renameAction);
|
||||
|
||||
menu.addSeparator();
|
||||
|
||||
QAction *deleteAction = new QAction(tr("Delete"), this);
|
||||
connect(deleteAction, &QAction::triggered, this, &MainWindow::onListContextMenuDelete);
|
||||
menu.addAction(deleteAction);
|
||||
|
||||
menu.exec(ui->lists->mapToGlobal(pos));
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::onListContextMenuDelete(bool _)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void MainWindow::onListContextMenuRename(bool)
|
||||
{
|
||||
if (ui->lists->selectedItems().length() == 1) {
|
||||
QListWidgetItem *item = ui->lists->selectedItems()[0];
|
||||
|
||||
InputDialog d = InputDialog(this, "Edit", "Edit", "Edit the list's name", item->text());
|
||||
auto res = d.exec();
|
||||
|
||||
// execute, ignore if not saved
|
||||
if (res != QDialog::Accepted) {
|
||||
return;
|
||||
}
|
||||
|
||||
QString newListName = d.getInput();
|
||||
ListService::getInstance()->update(item->data(Qt::UserRole).toUuid(), newListName);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::preload()
|
||||
{
|
||||
QList<List> lists = ListService::getInstance()->getAll();
|
||||
|
||||
@@ -25,11 +25,15 @@ private slots:
|
||||
void openCreateListDialog(bool);
|
||||
void onListCreated(List value);
|
||||
void onListUpdate(List value);
|
||||
void onListDeleted(QUuid uuid);
|
||||
void onNoteCreated(Note value);
|
||||
void onNoteUpdated(Note value);
|
||||
void onListSelected(int i);
|
||||
void onSaveNoteButtonClicked(bool);
|
||||
void onNoteChanged(QListWidgetItem*);
|
||||
void onListRightClick(const QPoint &pos);
|
||||
void onListContextMenuDelete(bool);
|
||||
void onListContextMenuRename(bool);
|
||||
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
|
||||
@@ -109,6 +109,9 @@ border-bottom: 2px solid rgb(242, 242, 242)</string>
|
||||
<fontweight>Light</fontweight>
|
||||
</font>
|
||||
</property>
|
||||
<property name="contextMenuPolicy">
|
||||
<enum>Qt::ContextMenuPolicy::CustomContextMenu</enum>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">QListView {
|
||||
show-decoration-selected: 1; /* make the selection span the entire width of the view */
|
||||
|
||||
Reference in New Issue
Block a user