/
ka_pie
/
PeakOff
Обзор
Документация
Войти
/
ka_pie
/
PeakOff
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/projecthistory.cpp
92 строки
3 KB
Viktoria
final version of PeakOff
14 июл 2026, 11:13
14 июл 2026, 11:13
a838933
Код
Авторство
О чём код?
#include "projecthistory.h" #include <QJsonDocument> #include <QJsonObject> #include <QJsonArray> #include <QFile> #include <QDateTime> #include <QStandardPaths> #include <QDebug> #include <QDir> ProjectHistory::ProjectHistory(QObject *parent) : QObject(parent) {} void ProjectHistory::saveProjectState(const QString &photoPath, const QString &stepsJson) { QString fileName = QString::number(QDateTime::currentMSecsSinceEpoch()) + ".json"; QString dirPath = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation); QDir dir(dirPath); if (!dir.exists()) { dir.mkpath("."); } QString fullPath = dir.absoluteFilePath(fileName); QJsonObject project; project["photoPath"] = photoPath; QJsonDocument doc = QJsonDocument::fromJson(stepsJson.toUtf8()); if (doc.isArray()) { project["steps"] = doc.array(); } else { project["steps"] = QJsonArray(); } QFile file(fullPath); if (file.open(QIODevice::WriteOnly)) { file.write(QJsonDocument(project).toJson()); file.close(); addProject(fullPath); } else { qWarning() << "[C++] Ошибка записи файла:" << fullPath; } } QVariantMap ProjectHistory::loadProjectState(const QString &jsonPath) { QVariantMap result; QFile file(jsonPath); if (file.open(QIODevice::ReadOnly)) { QJsonDocument doc = QJsonDocument::fromJson(file.readAll()); QJsonObject obj = doc.object(); result["photoPath"] = obj["photoPath"].toString(); result["steps"] = obj["steps"].toArray().toVariantList(); } return result; } void ProjectHistory::addProject(const QString &path) { if (path.isEmpty()) return; QSettings settings("ru.auroragirls", "PeakOff"); QStringList history = settings.value("recent_projects").toStringList(); history.removeAll(path); history.prepend(path); if (history.size() > 10) history.removeLast(); settings.setValue("recent_projects", history); emit historyUpdated(); } QStringList ProjectHistory::getRecentProjects() const { QSettings settings("ru.auroragirls", "PeakOff"); return settings.value("recent_projects").toStringList(); } void ProjectHistory::clear() { QSettings settings("ru.auroragirls", "PeakOff"); settings.remove("recent_projects"); emit historyUpdated(); } void ProjectHistory::removeProject(const QString &path) { QSettings settings("ru.auroragirls", "PeakOff"); QStringList history = settings.value("recent_projects").toStringList(); history.removeAll(path); settings.setValue("recent_projects", history); if (path.endsWith(".json")) { QFile::remove(path); } emit historyUpdated(); }