UI: Options: Schedule: Fix tasks saving

This commit is contained in:
Nodir Temirkhodjaev 2024-10-19 11:01:52 +05:00
parent fa2240b387
commit 0121104977
6 changed files with 33 additions and 22 deletions

View File

@ -96,21 +96,21 @@ const char *const sqlUpdateAppResetGroup = "UPDATE app"
const char *const sqlSelectTaskByName = "SELECT task_id, enabled,"
" run_on_startup, delay_startup,"
" interval_hours, max_retries, interval_hours,"
" max_retries, retry_seconds, interval_hours,"
" last_run, last_success, data"
" FROM task"
" WHERE name = ?1;";
const char *const sqlInsertTask = "INSERT INTO task(task_id, name, enabled,"
" run_on_startup, delay_startup,"
" max_retries, retry_minutes, interval_hours,"
" max_retries, retry_seconds, interval_hours,"
" last_run, last_success, data)"
" VALUES(?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11);";
const char *const sqlUpdateTask = "UPDATE task"
" SET name = ?2, enabled = ?3,"
" run_on_startup = ?4, delay_startup = ?5,"
" max_retries = ?6, retry_minutes = ?7, interval_hours = ?8,"
" max_retries = ?6, retry_seconds = ?7, interval_hours = ?8,"
" last_run = ?9, last_success = ?10,"
" data = ?11"
" WHERE task_id = ?1;";

View File

@ -185,6 +185,8 @@ void SchedulePage::setupTaskInterval()
connect(m_cscTaskInterval->checkBox(), &QCheckBox::toggled, this, [&](bool checked) {
auto &task = currentTaskRow();
if (task.enabled() == checked)
return;
task.setEnabled(checked);
setCurrentTaskRowEdited(Qt::CheckStateRole);
@ -193,6 +195,8 @@ void SchedulePage::setupTaskInterval()
connect(m_cscTaskInterval->spinBox(), QOverload<int>::of(&QSpinBox::valueChanged), this,
[&](int value) {
auto &task = currentTaskRow();
if (task.intervalHours() == value)
return;
task.setIntervalHours(value);
setCurrentTaskRowEdited();
@ -219,6 +223,8 @@ void SchedulePage::setupTaskStartup()
{
m_cbTaskRunOnStartup = ControlUtil::createCheckBox(false, [&](bool checked) {
auto &task = currentTaskRow();
if (task.runOnStartup() == checked)
return;
task.setRunOnStartup(checked);
setCurrentTaskRowEdited();
@ -226,6 +232,8 @@ void SchedulePage::setupTaskStartup()
m_cbTaskDelayStartup = ControlUtil::createCheckBox(false, [&](bool checked) {
auto &task = currentTaskRow();
if (task.delayStartup() == checked)
return;
task.setDelayStartup(checked);
setCurrentTaskRowEdited();
@ -240,6 +248,8 @@ void SchedulePage::setupTaskMaxRetries()
connect(m_lsTaskMaxRetries->spinBox(), QOverload<int>::of(&QSpinBox::valueChanged), this,
[&](int value) {
auto &task = currentTaskRow();
if (task.maxRetries() == value)
return;
task.setMaxRetries(value);
setCurrentTaskRowEdited();
@ -255,6 +265,8 @@ void SchedulePage::setupTaskRetrySeconds()
connect(m_lscTaskRetrySeconds->spinBox(), QOverload<int>::of(&QSpinBox::valueChanged), this,
[&](int value) {
auto &task = currentTaskRow();
if (task.retrySeconds() == value)
return;
task.setRetrySeconds(value);
setCurrentTaskRowEdited();
@ -282,6 +294,9 @@ void SchedulePage::setupTableTasksChanged()
m_cbTaskRunOnStartup->setChecked(task.runOnStartup());
m_cbTaskDelayStartup->setChecked(task.delayStartup());
m_lsTaskMaxRetries->spinBox()->setValue(task.maxRetries());
m_lscTaskRetrySeconds->spinBox()->setValue(task.retrySeconds());
const bool running = taskInfo->running();
m_btTaskRun->setEnabled(!running);
m_btTaskAbort->setEnabled(running);

View File

@ -2,12 +2,9 @@
#include "taskinfo.h"
TaskEditInfo::TaskEditInfo(bool enabled, bool runOnStartup, quint16 intervalHours) :
m_enabled(enabled), m_runOnStartup(runOnStartup), m_intervalHours(intervalHours)
{
}
static_assert(sizeof(TaskEditInfo) == sizeof(quint64), "TaskEditInfo size mismatch");
TaskEditInfo::TaskEditInfo(quint32 v) : m_value(v) { }
TaskEditInfo::TaskEditInfo(quint64 v) : m_value(v) { }
void TaskEditInfo::resetToDefault()
{

View File

@ -6,9 +6,7 @@
class TaskEditInfo
{
public:
explicit TaskEditInfo(
bool enabled = false, bool runOnStartup = false, quint16 intervalHours = 0);
explicit TaskEditInfo(quint32 v);
explicit TaskEditInfo(quint64 v = 0);
bool enabled() const { return m_enabled; }
void setEnabled(bool v) { m_enabled = v; }
@ -28,7 +26,7 @@ public:
int intervalHours() const { return m_intervalHours; }
void setIntervalHours(int v) { m_intervalHours = quint16(v); }
quint32 value() const { return m_value; }
quint64 value() const { return m_value; }
void resetToDefault();
@ -42,9 +40,10 @@ private:
quint8 m_maxRetries;
quint16 m_retrySeconds;
quint16 m_intervalHours;
quint16 m_reserved; // not used
};
quint32 m_value = 0;
quint64 m_value = 0;
};
};

View File

@ -49,14 +49,14 @@ QDateTime TaskInfo::plannedRun() const
void TaskInfo::editFromVariant(const QVariant &v)
{
const TaskEditInfo info(v.toUInt());
const TaskEditInfo task(v.toULongLong());
setEnabled(info.enabled());
setRunOnStartup(info.runOnStartup());
setDelayStartup(info.delayStartup());
setMaxRetries(info.maxRetries());
setRetrySeconds(info.retrySeconds());
setIntervalHours(info.intervalHours());
setEnabled(task.enabled());
setRunOnStartup(task.runOnStartup());
setDelayStartup(task.delayStartup());
setMaxRetries(task.maxRetries());
setRetrySeconds(task.retrySeconds());
setIntervalHours(task.intervalHours());
}
QString TaskInfo::typeToString(TaskInfo::TaskType type)

View File

@ -158,8 +158,8 @@ void TaskListModel::setupTaskRows()
QVariant TaskListModel::toVariant() const
{
QVariantList list;
for (const TaskEditInfo &info : std::as_const(m_taskRows)) {
list.append(info.value());
for (const TaskEditInfo &task : std::as_const(m_taskRows)) {
list.append(task.value());
}
return list;
}