From 3ab61d2241adc94873301da766353c95e98202d8 Mon Sep 17 00:00:00 2001 From: mxrcode <123785508+mxrcode@users.noreply.github.com> Date: Sun, 27 Oct 2024 16:57:43 +0200 Subject: [PATCH 1/6] Update .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index f147edf..2971263 100644 --- a/.gitignore +++ b/.gitignore @@ -31,6 +31,7 @@ Makefile* *build-* *.qm *.prl +build # Qt unit tests target_wrapper.* From b626e15ac60a4b746b3a0c0145cbdd77cd478682 Mon Sep 17 00:00:00 2001 From: mxrcode <123785508+mxrcode@users.noreply.github.com> Date: Fri, 1 Nov 2024 03:47:09 +0200 Subject: [PATCH 2/6] Update about_qt_window.ui --- src/about_qt_window.ui | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/about_qt_window.ui b/src/about_qt_window.ui index 8158f41..2b604ce 100644 --- a/src/about_qt_window.ui +++ b/src/about_qt_window.ui @@ -30,7 +30,7 @@ li.checked::marker { content: "\2612"; } </style></head><body style=" font-family:'Segoe UI'; font-size:9pt; font-weight:400; font-style:normal;"> <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:10pt; font-weight:700;">About Qt</span></p> <p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">This program uses Qt version 6.5.</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">This program uses Qt version 6.8.</p> <p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Qt is a C++ toolkit for cross-platform application development.</p> <p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> @@ -49,7 +49,7 @@ li.checked::marker { content: "\2612"; } <p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Please see <a href="qt.io/licensing"><span style=" text-decoration: underline; color:#007af4;">qt.io/licensing</span></a> for an overview of Qt licensing.</p> <p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Copyright (C) 2023 The Qt Company Ltd and other contributors.</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Copyright (C) 2024 The Qt Company Ltd and other contributors.</p> <p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Qt and the Qt logo are trademarks of The Qt Company Ltd.</p> <p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> @@ -65,7 +65,7 @@ li.checked::marker { content: "\2612"; } - Qt::Horizontal + Qt::Orientation::Horizontal From 2dae85f84db2c4721e3df1dfea7b41bfff26608b Mon Sep 17 00:00:00 2001 From: mxrcode <123785508+mxrcode@users.noreply.github.com> Date: Fri, 1 Nov 2024 03:48:10 +0200 Subject: [PATCH 3/6] Update version to 1.3.0 --- CMakeLists.txt | 2 +- src/version.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f8f12e9..4d772cc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.5) -project(TaskGuard VERSION 1.2.1 LANGUAGES CXX) +project(TaskGuard VERSION 1.3.0 LANGUAGES CXX) set(CMAKE_AUTOUIC ON) set(CMAKE_AUTOMOC ON) diff --git a/src/version.h b/src/version.h index 2d3cfcf..bd53fe6 100644 --- a/src/version.h +++ b/src/version.h @@ -6,10 +6,10 @@ #include const QString SOFT_NAME = "TaskGuard"; -const QString SOFT_VERSION = "1.2.1"; +const QString SOFT_VERSION = "1.3.0"; // Used to encrypt various data in the application, we recommend that you change this value "QString(value)" for private use. -const QString MAGIC = QCryptographicHash::hash(QString("e@txAaCLhYnlmwFSuG3#ADJaGdF3HElOWr1bC8FOlxD1lS25HjgDHS5oQL8BNDUuHKr&WTfEfRh#zzsd6jid9vEFEEVAwurqI2zy1dKed35uswIqhn7WmHCN4BGpo2lg").toUtf8() + QSysInfo::machineUniqueId(), QCryptographicHash::Blake2b_512).toHex(); +const QString MAGIC = QCryptographicHash::hash(QString("NfxjiNNSCy2ZIgQUT5V8ZF5qKchadALUpeE5NvFHSlJAbW2t9nqzhF%tToP11bWQODaakdGRRQckcmmPzy1cbWVd7N6ZMVH1Tyq4G#TcdzOmS249oS9eo8YNa6dTWLz3").toUtf8() + QSysInfo::machineUniqueId(), QCryptographicHash::Blake2b_512).toHex(); // Settings void save_settings(QString name, QString data); From 88eaba507c0fd7bd7674ec3d80b00283c9678c90 Mon Sep 17 00:00:00 2001 From: mxrcode <123785508+mxrcode@users.noreply.github.com> Date: Fri, 1 Nov 2024 04:28:46 +0200 Subject: [PATCH 4/6] Format log timestamp with brackets in message_handler() --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index b24d2a8..ebacea6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6,7 +6,7 @@ void message_handler(QtMsgType type, const QMessageLogContext &context, const QS QFile log_file("qInfo.log"); if (log_file.open(QIODevice::WriteOnly | QIODevice::Append)) { QTextStream stream(&log_file); - QString t_msg = QDateTime::currentDateTime().toString() + " : " + msg; + QString t_msg = "[" + QDateTime::currentDateTime().toString() + "] : " + msg; stream << t_msg << Qt::endl; } } From 72a7991f780d8be73db7b70c46af9983acc80362 Mon Sep 17 00:00:00 2001 From: mxrcode <123785508+mxrcode@users.noreply.github.com> Date: Fri, 1 Nov 2024 05:11:14 +0200 Subject: [PATCH 5/6] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bcf65bb..11495d1 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ TaskGuard is a to-do list application that helps you manage your tasks in a simp ![image](https://user-images.githubusercontent.com/123785508/234422735-0a73b366-f11b-410c-828f-7b2de99d8683.png) -****To encrypt the database, we use the [QtCipherSqlitePlugin(v1.3, LGPL-2.1)](https://github.com/devbean/QtCipherSqlitePlugin).*** +**To encrypt the database, we use the [QtCipherSqlitePlugin](https://github.com/mxrcode/QtCipherSqlitePlugin).* ## Features - **Task management**: Create, edit, and delete tasks with ease. From a312d9e8d711bdafd00896e6127e71ccac978890 Mon Sep 17 00:00:00 2001 From: mxrcode <123785508+mxrcode@users.noreply.github.com> Date: Fri, 1 Nov 2024 05:12:37 +0200 Subject: [PATCH 6/6] Refactor: auto-save logic and improve code readability --- src/mainwindow.cpp | 126 +++++++++++++++++---------------------------- src/mainwindow.h | 6 ++- 2 files changed, 53 insertions(+), 79 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 0576327..c9715e0 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1073,100 +1073,70 @@ void MainWindow::on_group_item_clicked(QListWidgetItem *item) { } void MainWindow::on_task_item_clicked(QListWidgetItem *item) { + if (item != nullptr) { + unsigned int task_id = item->data(Qt::UserRole).toUInt(); - unsigned int task_id; - - if (item != 0x0) { - task_id = item->data(Qt::UserRole).toUInt(); - } else { - task_id = 0; - } - - if (task_id > 0) { - m_task_current_id = 0; + if (task_id > 0) { + m_task_current_id = 0; - if (db_show_task(task_id)) { - m_task_current_id = task_id; + if (db_show_task(task_id)) { + m_task_current_id = task_id; - if (auto_save_status == false) auto_save(); + if (auto_save_status == false) { + setup_auto_save(); + auto_save_status = true; + } - ui->task_title->setCursorPosition(0); - ui->task_view_frame->show(); + ui->task_title->setCursorPosition(0); + ui->task_view_frame->show(); + } } } - } -void MainWindow::auto_save() { - - connect(ui->task_title, &QLineEdit::textChanged, [this]() { - - if (m_task_current_id == 0) { - return; - } - - QDateTime data_time = QDateTime::currentDateTime(); - int timestamp = data_time.toSecsSinceEpoch(); - - // Auto save QTextEdit - QSqlQuery db_query; - - db_query.prepare("UPDATE task_list SET title = :title, update_time = :update_time WHERE id = :id"); - db_query.bindValue(":id", m_task_current_id); - db_query.bindValue(":title", ui->task_title->text()); - db_query.bindValue(":update_time", timestamp); - - if (!db_query.exec()) - { - qInfo() << "An error occurred when executing the query related to autosave task title!"; - } else { - window_update(); - - QDateTime t_update_time; - t_update_time.setSecsSinceEpoch(timestamp); - QString format_update_time = t_update_time.toString("dd/MM/yyyy hh:mm"); - ui->updated_data->setText(format_update_time); - - ui->updated_text->show(); - ui->updated_data->show(); - } - - }); - - connect(ui->task_edit, &QTextEdit::textChanged, [this]() { - - if (m_task_current_id == 0) { - return; - } +void MainWindow::setup_auto_save() { + connect(ui->task_title, &QLineEdit::textChanged, this, &MainWindow::save_task_title); + connect(ui->task_edit, &QTextEdit::textChanged, this, &MainWindow::save_task_text); +} - QDateTime data_time = QDateTime::currentDateTime(); - int timestamp = data_time.toSecsSinceEpoch(); +void MainWindow::save_task_title() { + if (m_task_current_id == 0) return; + save_task_data("title", ui->task_title->text()); +} - // Auto save QTextEdit - QSqlQuery db_query; +void MainWindow::save_task_text() { + if (m_task_current_id == 0) return; + save_task_data("text", ui->task_edit->toPlainText()); +} - db_query.prepare("UPDATE task_list SET text = :text, update_time = :update_time WHERE id = :id"); - db_query.bindValue(":id", m_task_current_id); - db_query.bindValue(":text", ui->task_edit->toPlainText()); - db_query.bindValue(":update_time", timestamp); +void MainWindow::save_task_data(const QString& column, const QString& value) { + QDateTime data_time = QDateTime::currentDateTime(); + int timestamp = data_time.toSecsSinceEpoch(); - if (!db_query.exec()) - { - qInfo() << "An error occurred when executing the query related to autosave task text!"; - } else { - QDateTime t_update_time; - t_update_time.setSecsSinceEpoch(timestamp); - QString format_update_time = t_update_time.toString("dd/MM/yyyy hh:mm"); - ui->updated_data->setText(format_update_time); + QSqlQuery db_query; + QString queryStr = QString("UPDATE task_list SET %1 = :value, update_time = :update_time WHERE id = :id").arg(column); + db_query.prepare(queryStr); + db_query.bindValue(":id", m_task_current_id); + db_query.bindValue(":value", value); + db_query.bindValue(":update_time", timestamp); - ui->updated_text->show(); - ui->updated_data->show(); - } + if (db_query.exec()) { + update_task_ui_after_save(timestamp); + } else { + qWarning() << "An error occurred when executing the query related to autosave task" << column << "!"; + } +} - }); +void MainWindow::update_task_ui_after_save(int timestamp) { + window_update(); - auto_save_status = true; + QDateTime t_update_time; + t_update_time.setSecsSinceEpoch(timestamp); + QString format_update_time = t_update_time.toString("dd/MM/yyyy hh:mm"); + ui->updated_data->setText(format_update_time); + ui->updated_text->show(); + ui->updated_data->show(); } QVector> MainWindow::get_task_data_by_id(unsigned int task_id) { diff --git a/src/mainwindow.h b/src/mainwindow.h index 89739c2..1801242 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -106,7 +106,11 @@ class MainWindow : public QMainWindow void on_group_item_clicked(QListWidgetItem *item); void on_task_item_clicked(QListWidgetItem *item); - void auto_save(); + void setup_auto_save(); + void save_task_title(); + void save_task_text(); + void save_task_data(const QString& column, const QString& value); + void update_task_ui_after_save(int timestamp); void groups_update(); void tasks_update();