diff --git a/src/core/management_layer/application_manager.cpp b/src/core/management_layer/application_manager.cpp index 1eafd484b..866f955bc 100644 --- a/src/core/management_layer/application_manager.cpp +++ b/src/core/management_layer/application_manager.cpp @@ -217,7 +217,7 @@ class ApplicationManager::Implementation /** * @brief Обновить заголовок приложения */ - void updateWindowTitle(); + void updateWindowTitle(const QString& _projectName = QString{}); /** * @brief Настроить состояние приложения сохранены ли все изменения или нет @@ -1219,7 +1219,7 @@ void ApplicationManager::Implementation::setDesignSystemDensity(int _density) QApplication::postEvent(q, new DesignSystemChangeEvent); } -void ApplicationManager::Implementation::updateWindowTitle() +void ApplicationManager::Implementation::updateWindowTitle(const QString& _projectName) { if (projectsManager->currentProject() == nullptr) { applicationView->setWindowTitle("Story Architect"); @@ -1236,7 +1236,7 @@ void ApplicationManager::Implementation::updateWindowTitle() "" #endif , - currentProject->name(), + _projectName.isEmpty() ? currentProject->name() : _projectName, (currentProject->isLocal() ? currentProject->path() : tr("in cloud")), (currentProject->isReadOnly() ? QString(" - %1").arg(tr("Read only")) : ""))); @@ -1345,6 +1345,13 @@ void ApplicationManager::Implementation::saveChanges() // markChangesSaved(true); + // + // Обновляем информацию в списке проектов + // + projectsManager->updateCurrentProject(projectManager->projectName(), + projectManager->projectLogline(), + projectManager->projectCover()); + // // И, если необходимо создадим резервную копию закрываемого файла // @@ -2766,9 +2773,8 @@ void ApplicationManager::initConnections() d->projectsManager.data(), &ProjectsManager::setCurrentProjectUuid); connect(d->projectManager.data(), &ProjectManager::projectNameChanged, this, [this](const QString& _name) { - d->projectsManager->setCurrentProjectName(_name); d->menuView->setProjectTitle(_name); - d->updateWindowTitle(); + d->updateWindowTitle(_name); }); connect(d->projectManager.data(), &ProjectManager::projectLoglineChanged, d->projectsManager.data(), &ProjectsManager::setCurrentProjectLogline); diff --git a/src/core/management_layer/content/project/project_manager.cpp b/src/core/management_layer/content/project/project_manager.cpp index a5306bae6..c68d620c0 100644 --- a/src/core/management_layer/content/project/project_manager.cpp +++ b/src/core/management_layer/content/project/project_manager.cpp @@ -2318,10 +2318,6 @@ ProjectManager::ProjectManager(QObject* _parent, QWidget* _parentWidget, }); connect(&d->modelsFacade, &ProjectModelsFacade::projectNameChanged, this, &ProjectManager::projectNameChanged); - connect(&d->modelsFacade, &ProjectModelsFacade::projectLoglineChanged, this, - &ProjectManager::projectLoglineChanged); - connect(&d->modelsFacade, &ProjectModelsFacade::projectCoverChanged, this, - &ProjectManager::projectCoverChanged); connect(&d->modelsFacade, &ProjectModelsFacade::projectCollaboratorInviteRequested, this, &ProjectManager::projectCollaboratorInviteRequested); connect(&d->modelsFacade, &ProjectModelsFacade::projectCollaboratorUpdateRequested, this, @@ -3173,9 +3169,15 @@ void ProjectManager::saveChanges() DataStorageLayer::StorageFacade::documentStorage()->saveDocument(document); } + + auto projectInformationModel = qobject_cast( + d->modelsFacade.modelFor(DataStorageLayer::StorageFacade::documentStorage()->document( + Domain::DocumentObjectType::Project))); + // // Сохраняем изображения // + projectInformationModel->saveCover(); d->documentImageStorage.saveChanges(); // @@ -4232,6 +4234,30 @@ void ProjectManager::setGeneratedImage(const QPixmap& _image) } } +QString ProjectManager::projectName() const +{ + auto projectInformationModel = qobject_cast( + d->modelsFacade.modelFor(DataStorageLayer::StorageFacade::documentStorage()->document( + Domain::DocumentObjectType::Project))); + return projectInformationModel->name(); +} + +QString ProjectManager::projectLogline() const +{ + auto projectInformationModel = qobject_cast( + d->modelsFacade.modelFor(DataStorageLayer::StorageFacade::documentStorage()->document( + Domain::DocumentObjectType::Project))); + return projectInformationModel->logline(); +} + +QPixmap ProjectManager::projectCover() const +{ + auto projectInformationModel = qobject_cast( + d->modelsFacade.modelFor(DataStorageLayer::StorageFacade::documentStorage()->document( + Domain::DocumentObjectType::Project))); + return projectInformationModel->cover(); +} + bool ProjectManager::event(QEvent* _event) { switch (static_cast(_event->type())) { diff --git a/src/core/management_layer/content/project/project_manager.h b/src/core/management_layer/content/project/project_manager.h index c24f71c11..051800bed 100644 --- a/src/core/management_layer/content/project/project_manager.h +++ b/src/core/management_layer/content/project/project_manager.h @@ -204,6 +204,13 @@ class ProjectManager : public QObject void setGeneratedText(const QString& _text); void setGeneratedImage(const QPixmap& _image); + /** + * @brief Получить информацию о проекте + */ + QString projectName() const; + QString projectLogline() const; + QPixmap projectCover() const; + signals: /** * @brief Запрос на отображение меню diff --git a/src/core/management_layer/content/project/project_models_facade.cpp b/src/core/management_layer/content/project/project_models_facade.cpp index bfb9135ce..489cac6c3 100644 --- a/src/core/management_layer/content/project/project_models_facade.cpp +++ b/src/core/management_layer/content/project/project_models_facade.cpp @@ -143,11 +143,6 @@ BusinessLayer::AbstractModel* ProjectModelsFacade::modelFor(Domain::DocumentObje auto projectInformationModel = new BusinessLayer::ProjectInformationModel; connect(projectInformationModel, &BusinessLayer::ProjectInformationModel::nameChanged, this, &ProjectModelsFacade::projectNameChanged, Qt::UniqueConnection); - connect(projectInformationModel, - &BusinessLayer::ProjectInformationModel::loglineChanged, this, - &ProjectModelsFacade::projectLoglineChanged, Qt::UniqueConnection); - connect(projectInformationModel, &BusinessLayer::ProjectInformationModel::coverChanged, - this, &ProjectModelsFacade::projectCoverChanged, Qt::UniqueConnection); connect(projectInformationModel, &BusinessLayer::ProjectInformationModel::collaboratorInviteRequested, this, &ProjectModelsFacade::projectCollaboratorInviteRequested, Qt::UniqueConnection); diff --git a/src/core/management_layer/content/projects/projects_manager.cpp b/src/core/management_layer/content/projects/projects_manager.cpp index 17ca64790..163e2d86f 100644 --- a/src/core/management_layer/content/projects/projects_manager.cpp +++ b/src/core/management_layer/content/projects/projects_manager.cpp @@ -1453,4 +1453,16 @@ BusinessLayer::ProjectsModelProjectItem* ProjectsManager::currentProject() const return d->currentProject; } +void ProjectsManager::updateCurrentProject(const QString& _name, const QString& _logline, + const QPixmap& _cover) +{ + if (d->currentProject->name() != _name) { + setCurrentProjectName(_name); + } + if (d->currentProject->logline() != _logline) { + setCurrentProjectLogline(_logline); + } + setCurrentProjectCover(_cover); +} + } // namespace ManagementLayer diff --git a/src/core/management_layer/content/projects/projects_manager.h b/src/core/management_layer/content/projects/projects_manager.h index 26abad52b..e08102806 100644 --- a/src/core/management_layer/content/projects/projects_manager.h +++ b/src/core/management_layer/content/projects/projects_manager.h @@ -171,6 +171,11 @@ class ProjectsManager : public QObject */ BusinessLayer::ProjectsModelProjectItem* currentProject() const; + /** + * @brief Обновить текущий проект + */ + void updateCurrentProject(const QString& _name, const QString& _logline, const QPixmap& _cover); + signals: /** * @brief Запрос на отображение меню diff --git a/src/core/management_layer/content/projects/projects_model_project_item.cpp b/src/core/management_layer/content/projects/projects_model_project_item.cpp index 68e22be89..2d0906325 100644 --- a/src/core/management_layer/content/projects/projects_model_project_item.cpp +++ b/src/core/management_layer/content/projects/projects_model_project_item.cpp @@ -146,13 +146,14 @@ void ProjectsModelProjectItem::setPosterPath(const QString& _path) return; } } - d->posterPath = _path; // // Обнуляем постер, чтобы он потом извлёкся по заданному пути // d->poster = {}; + + setChanged(true); } QUuid ProjectsModelProjectItem::uuid() const @@ -173,6 +174,7 @@ QString ProjectsModelProjectItem::name() const void ProjectsModelProjectItem::setName(const QString& _name) { d->name = _name; + setChanged(true); } QString ProjectsModelProjectItem::logline() const @@ -183,6 +185,7 @@ QString ProjectsModelProjectItem::logline() const void ProjectsModelProjectItem::setLogline(const QString& _logline) { d->logline = _logline; + setChanged(true); } QString ProjectsModelProjectItem::displayLastEditTime() const diff --git a/src/corelib/business_layer/model/project/project_information_model.cpp b/src/corelib/business_layer/model/project/project_information_model.cpp index 359eee37d..bf95e3380 100644 --- a/src/corelib/business_layer/model/project/project_information_model.cpp +++ b/src/corelib/business_layer/model/project/project_information_model.cpp @@ -24,9 +24,15 @@ const QString kCoverKey = QStringLiteral("cover"); class ProjectInformationModel::Implementation { public: + explicit Implementation(ProjectInformationModel* _q); + + + ProjectInformationModel* q = nullptr; + QString name; QString logline; Domain::DocumentImage cover; + QUuid oldCover; StructureModel* structureModel = nullptr; @@ -34,13 +40,18 @@ class ProjectInformationModel::Implementation QVector teammates; }; +ProjectInformationModel::Implementation::Implementation(ProjectInformationModel* _q) + : q(_q) +{ +} + // **** ProjectInformationModel::ProjectInformationModel(QObject* _parent) : AbstractModel({ kDocumentKey, kNameKey, kLoglineKey, kCoverKey }, _parent) - , d(new Implementation) + , d(new Implementation(this)) { connect(this, &ProjectInformationModel::nameChanged, this, &ProjectInformationModel::updateDocumentContent); @@ -109,10 +120,12 @@ void ProjectInformationModel::setCover(const QPixmap& _cover) } // - // Если ранее обложка была задана, то удалим её + // Если ранее обложка была задана, то очистим её // if (!d->cover.uuid.isNull()) { - imageWrapper()->remove(d->cover.uuid); + if (d->oldCover.isNull()) { + d->oldCover = d->cover.uuid; + } d->cover = {}; } @@ -120,7 +133,7 @@ void ProjectInformationModel::setCover(const QPixmap& _cover) // Если задана новая обложка, то добавляем её // if (!_cover.isNull()) { - d->cover.uuid = imageWrapper()->save(_cover); + d->cover.uuid = QUuid::createUuid(); d->cover.image = _cover; } @@ -140,6 +153,17 @@ void ProjectInformationModel::setCover(const QUuid& _uuid, const QPixmap& _cover emit coverChanged(d->cover.image); } +void ProjectInformationModel::saveCover() +{ + if (!d->cover.image.isNull() && !d->cover.uuid.isNull()) { + imageWrapper()->save(d->cover.uuid, d->cover.image); + } + if (!d->oldCover.isNull()) { + imageWrapper()->remove(d->oldCover); + d->oldCover = QUuid(); + } +} + StructureModel* ProjectInformationModel::structureModel() const { return d->structureModel; @@ -215,7 +239,7 @@ void ProjectInformationModel::clearDocument() // auto structureModel = d->structureModel; - d.reset(new Implementation); + d.reset(new Implementation(this)); d->structureModel = structureModel; } diff --git a/src/corelib/business_layer/model/project/project_information_model.h b/src/corelib/business_layer/model/project/project_information_model.h index c3b8c3bf9..c1b039716 100644 --- a/src/corelib/business_layer/model/project/project_information_model.h +++ b/src/corelib/business_layer/model/project/project_information_model.h @@ -32,6 +32,7 @@ class CORE_LIBRARY_EXPORT ProjectInformationModel : public AbstractModel const QPixmap& cover() const; void setCover(const QPixmap& _cover); void setCover(const QUuid& _uuid, const QPixmap& _cover); + void saveCover(); Q_SIGNAL void coverChanged(const QPixmap& _cover); BusinessLayer::StructureModel* structureModel() const;