Skip to content

Commit

Permalink
Merge pull request #31 from Nighty3098/InDev
Browse files Browse the repository at this point in the history
In dev
  • Loading branch information
Nighty3098 authored Apr 19, 2024
2 parents 81e60b2 + d24ec8b commit 6ed2252
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 54 deletions.
1 change: 1 addition & 0 deletions clang_format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

find . -type f -name "*.cpp" | while read -r file; do
clang-format -i "$file"
echo "Formatted $file"
done
36 changes: 24 additions & 12 deletions src/CodeKeeper/keeperFunc/projectsFunc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ void MainWindow::createProject()
QString status = "NotStartedProjects";
QString title = "Teamplate";
QString git = "https://github.com/";
QString newProjectTeamplate = "New project\nGitHub\n" + date;
QString newProjectTeamplate = title + "\n" + git + "\n" + date;

qDebug() << "New project: " << newProjectTeamplate;

notStartedProjects->addItem(newProjectTeamplate);

saveProjectToDB(&title, &git, &status, &date);
Expand Down Expand Up @@ -75,22 +77,26 @@ void MainWindow::openProject(QListWidget *listWidget, QListWidgetItem *item)
QString data = item->text();
QStringList splitData = data.split("\n");

QStringList projectData = GetProjectData(&splitData[1], &splitData[2]);
QString PTitle = splitData[0];
QString PGit = splitData[1];
QString PCreatedTime = splitData[2];
QString PStatus = listWidget->objectName();

QStringList projectData = GetProjectData(&PTitle, &PStatus, &PGit);
qDebug() << "Open project: " << projectData[0] << " " << projectData[1] << " " << projectData[2] << " " << projectData[3] << " " << projectData[4] << " " << projectData[5];

QGridLayout mainLayout(&dialog);

QLineEdit *title = new QLineEdit();
title->setPlaceholderText(" Project name: ");
title->setStyleSheet("font-size: " + font_size + ";");
title->setFixedSize(380, 25);
title->setText(projectData[0]);
title->setFont(selectedFont);

QLineEdit *linkToGit = new QLineEdit();
linkToGit->setPlaceholderText(" Link to GIT");
linkToGit->setStyleSheet("font-size: " + font_size + ";");
linkToGit->setFixedSize(380, 25);
linkToGit->setText(projectData[2]);
linkToGit->setFont(selectedFont);

QComboBox *documentation = new QComboBox();
Expand All @@ -106,14 +112,12 @@ void MainWindow::openProject(QListWidget *listWidget, QListWidgetItem *item)
note->setLineWidth(font_size.toInt());
note->setHighlightingEnabled(true);
note->setFont(selectedFont);
note->setPlainText(projectData[4]);

QLabel *lastMod = new QLabel();
lastMod->setText("Last mod: ");
lastMod->setStyleSheet("font-size: " + font_size + ";");
lastMod->setFixedSize(380, 25);
lastMod->setAlignment(Qt::AlignCenter);
lastMod->setText("Last mod: " + projectData[6]);
lastMod->setFont(selectedFont);

QPushButton *saveDataBtn = new QPushButton();
Expand All @@ -132,6 +136,11 @@ void MainWindow::openProject(QListWidget *listWidget, QListWidgetItem *item)
cancelBtn->setIconSize(QSize(10, 10));
cancelBtn->setFont(selectedFont);

title->setText(projectData[0]);
linkToGit->setText(projectData[1]);
note->setPlainText(projectData[3]);
lastMod->setText("Last mod: " + projectData[5]);

mainLayout.addWidget(title, 0, 0, 1, 2);
mainLayout.addWidget(linkToGit, 1, 0, 1, 2);
mainLayout.addWidget(documentation, 2, 0, 1, 2);
Expand All @@ -141,17 +150,17 @@ void MainWindow::openProject(QListWidget *listWidget, QListWidgetItem *item)
mainLayout.addWidget(cancelBtn, 5, 1);

QObject::connect(saveDataBtn, &QPushButton::clicked, [&]() {
QString text1 = title->text();
QString text2 = linkToGit->text();
QString text3 = getCurrentDateTimeString();
QString doc = documentation->currentText();
QString projectTitle = title->text();
QString projectLink = linkToGit->text();
QString projectCreatedTime = getCurrentDateTimeString();
QString projectDocumentation = documentation->currentText();
QString noteT = note->toPlainText();

QString itemText = text1 + "\n" + text2 + "\n" + text3;
QString itemText = projectTitle + "\n" + projectLink + "\n" + projectCreatedTime;
item->setText(itemText);
qDebug() << itemText;

updateProjectData(&text1, &text2, &doc, &noteT, &text3, &splitData[2]);
updateProjectData(&projectTitle, &projectLink, &projectDocumentation, &noteT, &projectCreatedTime, &PCreatedTime, &PGit);

dialog.close();
});
Expand All @@ -160,6 +169,9 @@ void MainWindow::openProject(QListWidget *listWidget, QListWidgetItem *item)

dialog.exec();
}
else {
qDebug() << "Error";
}
}

void MainWindow::loadDocumentations(QDir path, QComboBox &comboBox)
Expand Down
11 changes: 0 additions & 11 deletions src/CodeKeeper/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,6 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
mainTitle->setAlignment(Qt::AlignCenter);
mainTitle->setStyleSheet("font-size: 46px;");

QPropertyAnimation *animation = new QPropertyAnimation(mainTitle, "background-color: ");
animation->setDuration(2000); // Set the duration of the animation to 2 seconds

QColor startColor("#aaff6a"); // Set the start color to red
QColor endColor("#ffea6a"); // Set the end color to green

animation->setStartValue(startColor);
animation->setEndValue(endColor);

// settings btn
QHBoxLayout *settingsBtnLayout = new QHBoxLayout;
openSettingsBtn = new QPushButton(QPixmap(":/settings.png"), " Settings");
Expand Down Expand Up @@ -789,8 +780,6 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
loadProjects();
setFontPr1();

animation->start();

qDebug() << path;
qDebug() << "Load time:" << startup.elapsed() << "ms";
}
Expand Down
4 changes: 2 additions & 2 deletions src/CodeKeeper/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,11 @@ class MainWindow : public QMainWindow {
void onMovingTaskFrom(QListWidgetItem *item, QListWidget *list);
void onMovingTaskTo(QListWidgetItem *item, QListWidget *list);

QStringList GetProjectData(QString *git_url, QString *createdTime);
QStringList GetProjectData(QString *title, QString *status, QString *git_url);
void updateProjectStatus(QString *status, QString *createdTime, QString *oldTime);
void removeProjectFromDB(QString *git_url, QString *status, QString *createdTime);
void saveProjectToDB(QString *title, QString *git_url, QString *status, QString *createdTime);
void updateProjectData(QString *title, QString *git_url, QString *doc, QString *note, QString *createdTime, QString *oldTime);
void updateProjectData(QString *title, QString *git_url, QString *doc, QString *note, QString *createdTime, QString *oldTime, QString *oldGit);
void onMovingProjectFrom(QListWidgetItem *item, QListWidget *list);
void onMovingProjectTo(QListWidgetItem *item, QListWidget *list);

Expand Down
44 changes: 20 additions & 24 deletions src/CodeKeeper/sql_db/projectsDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,38 +24,34 @@ void MainWindow::create_projects_connection()
}
}

QStringList MainWindow::GetProjectData(QString *git_url, QString *createdTime)
QStringList MainWindow::GetProjectData(QString *title, QString *status, QString *git_url)
{
QStringList projectData;
QSqlQuery query;

if (!query.exec("SELECT * FROM projects WHERE git_url = '" + git_url->arg("'") + "'")) {
qDebug() << "Error querying projects database:" << query.lastError();
return projectData;
if (query.exec("SELECT * FROM projects WHERE status = '" + *status + "' AND title = '" + *title + "' AND git_url = '" + *git_url + "'")) {
if (query.next()) {
projectData << query.value("title").toString();
projectData << query.value("git_url").toString();
projectData << query.value("projectDoc").toString();
projectData << query.value("note").toString();
projectData << query.value("status").toString();
projectData << query.value("createdTime").toString();
qDebug() << "Load project: " << projectData;
}
}

if (query.next()) {
qDebug() << query.value("id").toString();
qDebug() << query.value("title").toString();
qDebug() << query.value("git_url").toString();
qDebug() << query.value("project_doc").toString();
qDebug() << query.value("note").toString();
qDebug() << query.value("status").toString();
qDebug() << query.value("createdTime").toString();
else {
qDebug() << "Error querying projects database:" << query.lastError();
}

return projectData;
}

void MainWindow::updateProjectData(QString *title, QString *git_url, QString *doc, QString *note,
QString *createdTime, QString *oldTime)
QString *createdTime, QString *oldTime, QString *oldGit)
{
QSqlQuery query;

if (!query.exec("UPDATE projects SET title = '" + title->arg("'") + "', git_url = '"
+ git_url->arg("'") + "', projectDoc = '" + doc->arg("'") + "', note = '"
+ note->arg("'") + "', createdTime = '" + createdTime->arg("'")
+ "' WHERE createdTime = '" + oldTime->arg("'") + "'")) {
if (!query.exec("UPDATE projects SET title = '" + *title + "', git_url = '" + *git_url + "', projectDoc = '" + *doc + "', note = '" + *note + "', createdTime = '" + *createdTime + "' WHERE createdTime = '" + *oldTime + "' AND git_url = '" + oldGit + "'")) {
qDebug() << query.lastError();
} else {
qDebug() << "Sucsessfull updated";
Expand All @@ -70,8 +66,8 @@ void MainWindow::saveProjectToDB(QString *title, QString *git_url, QString *stat

if (!query.exec("INSERT INTO projects (title, git_url, projectDoc, note, status, createdTime) "
"VALUES('"
+ title->arg("'") + "', '" + git_url->arg("'") + "', ' ', '# New project', '"
+ status->arg("'") + "', '" + createdTime->arg("'") + "')")) {
+ *title + "', '" + *git_url + "', ' ', '# New project', '" + *status + "', '"
+ *createdTime + "')")) {
qDebug() << query.lastError();
} else {
qDebug() << "Sucsessfull saved";
Expand All @@ -82,8 +78,8 @@ void MainWindow::updateProjectStatus(QString *status, QString *createdTime, QStr
{
QSqlQuery query;

if (!query.exec("UPDATE projects SET status = '" + status->arg("'") + "' WHERE createdTime = '"
+ oldTime->arg("'") + "'")) {
if (!query.exec("UPDATE projects SET status = '" + *status + "' WHERE createdTime = '"
+ *oldTime + "'")) {
qDebug() << query.lastError();
} else {
qDebug() << "Sucsessfull updated";
Expand All @@ -94,7 +90,7 @@ void MainWindow::removeProjectFromDB(QString *git_url, QString *status, QString
{
QSqlQuery query;

if (!query.exec("DELETE FROM projects WHERE git_url = '" + git_url->arg("'") + "'")) {
if (!query.exec("DELETE FROM projects WHERE git_url = '" + *git_url + "'")) {
qDebug() << query.lastError();
} else {
qDebug() << "Sucsessfull removed";
Expand Down
11 changes: 6 additions & 5 deletions src/CodeKeeper/sql_db/tasksDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void MainWindow::updateTaskData(QString *task, QString *status, QString *cT)
QStringList taskText = task->split("\n");

if (!query.exec("UPDATE tasks SET task = '" + taskText[0] + "' WHERE createdTime = '" + cT
+ "'")) {
+ "' AND status = '" + *status + "'")) {
qDebug() << query.lastError();
}
}
Expand All @@ -39,8 +39,8 @@ void MainWindow::updateTaskStatus(QString *task, QString *status, QString *cT)

QStringList taskText = task->split("\n");

if (!query.exec("UPDATE tasks SET task = '" + taskText[0] + "', status = '" + status
+ "' WHERE createdTime = '" + cT + "'")) {
if (!query.exec("UPDATE tasks SET status = '" + *status + "' WHERE createdTime = '" + *cT
+ "' AND task = '" + taskText[0] + "'")) {
qDebug() << query.lastError();
}
}
Expand All @@ -52,7 +52,7 @@ void MainWindow::saveTaskToDB(QString *task, QString *status)
QStringList taskText = task->split("\n");

if (!query.exec("INSERT INTO tasks (task, status, createdTime) VALUES('" + taskText[0] + "', '"
+ status + "', '" + taskText[1] + "');")) {
+ *status + "', '" + taskText[1] + "');")) {
qDebug() << query.lastError();
} else {
qDebug() << taskText[0] << " was saved";
Expand All @@ -65,7 +65,8 @@ void MainWindow::removeTaskFromDB(QString *task, QString *status)

QStringList taskText = task->split("\n");

if (!query.exec("DELETE FROM tasks WHERE task = '" + taskText[0] + "'")) {
if (!query.exec("DELETE FROM tasks WHERE task = '" + taskText[0] + "' AND status = '" + *status
+ "' AND createdTime = '" + taskText[1] + "'")) {
qDebug() << query.lastError();
} else {
qDebug() << "Sucsessfull removed";
Expand Down

0 comments on commit 6ed2252

Please sign in to comment.