diff --git a/src/CodeKeeper/keeperFunc/projectsFunc.cpp b/src/CodeKeeper/keeperFunc/projectsFunc.cpp index a2ca2a41..34c0c9da 100644 --- a/src/CodeKeeper/keeperFunc/projectsFunc.cpp +++ b/src/CodeKeeper/keeperFunc/projectsFunc.cpp @@ -54,17 +54,30 @@ void MainWindow::activateProjectContextMenu(const QPoint &pos, QListWidget *list void MainWindow::onMovingProjectFrom(QListWidgetItem *item, QListWidget *list) { - qDebug() << "Moving project: " << item->text() << " from: " << list->objectName(); + if (item && list) + { + qDebug() << "Moving project: " << item->text() << " from: " << list->objectName(); + } } void MainWindow::onMovingProjectTo(QListWidgetItem *item, QListWidget *list) { - qDebug() << "Moved project: " << item->text() << " to: " << list->objectName(); - QStringList data = item->text().split("\n"); - QString status = list->objectName(); - QString date = getCurrentDateTimeString(); + if (item && list) + { + qDebug() << "Moved project: " << item->text() << " to: " << list->objectName(); + QStringList data = item->text().split("\n"); + if (data.size() >= 3) // Check if data has at least 3 elements + { + QString status = list->objectName(); + QString date = getCurrentDateTimeString(); - updateProjectStatus(&status, &date, &data[2]); + updateProjectStatus(&status, &date, &data[2]); + } + else + { + qWarning() << "Invalid project data format"; + } + } } void MainWindow::createProject() @@ -87,7 +100,7 @@ void MainWindow::createProject() void MainWindow::removeProject() { - QListWidget *listWidgets[] = {notStartedProjects, startedProjects, finishlineProjects, finishedProjects}; + QList listWidgets = {notStartedProjects, startedProjects, finishlineProjects, finishedProjects}; for (QListWidget *listWidget : listWidgets) { @@ -97,7 +110,8 @@ void MainWindow::removeProject() QStringList data = item->text().split("\n"); QString status = listWidget->objectName(); - listWidget->takeItem(listWidget->row(item)); + int row = listWidget->row(item); + listWidget->takeItem(row); removeProjectFromDB(&data[1], &status, &data[2]); @@ -112,22 +126,23 @@ void MainWindow::getTotalProjects(QTabWidget *projectsTab, QListWidget *notStart QListWidget *startedProjects, QListWidget *finishedProjects, QListWidget *finishlineProjects) { - QThread *totalProjectsThread = new QThread; - QObject::connect(totalProjectsThread, &QThread::started, this, - [this, projectsTab, notStartedProjects, startedProjects, finishedProjects, finishlineProjects]() { - if (projectsTab->currentIndex() == 3) - { - QTimer *timer3 = new QTimer(this); - connect(timer3, &QTimer::timeout, [=]() { - int totalProjects = notStartedProjects->count() + finishlineProjects->count() + - startedProjects->count() + finishedProjects->count(); - - totalProjectsL->setText(tr("Total projects: ") + QString::number(totalProjects) + " "); - }); - timer3->start(500); - } - }); - totalProjectsThread->start(); + static QTimer *timer3 = new QTimer(this); + + connect(timer3, &QTimer::timeout, this, [=]() { + int totalProjects = notStartedProjects->count() + finishlineProjects->count() + startedProjects->count() + + finishedProjects->count(); + + totalProjectsL->setText(tr("Total projects: ") + QString::number(totalProjects) + " "); + }); + + if (projectsTab->currentIndex() == 3) + { + timer3->start(500); + } + else + { + timer3->stop(); + } } void MainWindow::selectFileInQTreeView(QTreeView *treeView, const QString &fileName) @@ -136,21 +151,19 @@ void MainWindow::selectFileInQTreeView(QTreeView *treeView, const QString &fileN void MainWindow::openGitProject() { - QListWidget *listWidgets[] = {notStartedProjects, startedProjects, finishlineProjects, finishedProjects}; + QList listWidgets = {notStartedProjects, startedProjects, finishlineProjects, finishedProjects}; for (QListWidget *listWidget : listWidgets) { QListWidgetItem *item = listWidget->currentItem(); if (item) { - QStringList data = item->text().split("\n"); - - QString git_url = data[1]; + QString git_url = item->text().split("\n").value(1); qDebug() << git_url; + QUrl url(git_url); QDesktopServices::openUrl(url); - - break; + return; } } } diff --git a/src/CodeKeeper/keeperFunc/tasksFunc.cpp b/src/CodeKeeper/keeperFunc/tasksFunc.cpp index 30453624..f6db95e0 100644 --- a/src/CodeKeeper/keeperFunc/tasksFunc.cpp +++ b/src/CodeKeeper/keeperFunc/tasksFunc.cpp @@ -37,22 +37,31 @@ void MainWindow::activateTasksContextMenu(const QPoint &pos, QListWidget *listWi void MainWindow::onMovingTaskFrom(QListWidgetItem *item, QListWidget *list) { - qDebug() << "Moving task: " << item->text() << " from: " << list->objectName(); - - QString task = item->text(); - QString status = list->objectName(); + if (item && list) + { + qDebug() << "Moving task: " << item->text() << " from: " << list->objectName(); + } } void MainWindow::onMovingTaskTo(QListWidgetItem *item, QListWidget *list) { - qDebug() << "Moved task: " << item->text() << " to: " << list->objectName(); + if (item && list) + { + qDebug() << "Moved task: " << item->text() << " to: " << list->objectName(); - QString task = item->text(); - QString status = list->objectName(); - QStringList data = task.split("\n"); - QString cT = data[1]; + QStringList data = item->text().split("\n"); + if (data.size() >= 2) // Check if data has at least 2 elements + { + QString status = list->objectName(); + QString cT = data[1]; - updateTaskStatus(&task, &status, &cT); + updateTaskStatus(&data[0], &status, &cT); + } + else + { + qWarning() << "Invalid task data format"; + } + } } void MainWindow::addNewTask() @@ -75,21 +84,20 @@ void MainWindow::addNewTask() void MainWindow::removeTask() { - QListWidget *listWidgets[] = {incompleteTasks, inprocessTasks, completeTasks}; + QList listWidgets = {incompleteTasks, inprocessTasks, completeTasks}; for (QListWidget *listWidget : listWidgets) { QListWidgetItem *item = listWidget->currentItem(); if (item) { - listWidget->takeItem(listWidget->row(item)); - qDebug() << "Removed task: " << item->text(); - QString task = item->text(); QString status = listWidget->objectName(); - removeTaskFromDB(&task, &status); + listWidget->takeItem(listWidget->row(item)); + qDebug() << "Removed task: " << task; + removeTaskFromDB(&task, &status); delete item; break; } diff --git a/src/CodeKeeper/sql_db/tasksDB.cpp b/src/CodeKeeper/sql_db/tasksDB.cpp index 63177a5e..24bdf2b6 100644 --- a/src/CodeKeeper/sql_db/tasksDB.cpp +++ b/src/CodeKeeper/sql_db/tasksDB.cpp @@ -136,7 +136,7 @@ void MainWindow::loadTasks() } else { - qDebug() << "🟠 Unknown status: " << status; + qDebug() << "Unknown status: " << status; } }