Skip to content

Commit

Permalink
Fix an updating of the start page
Browse files Browse the repository at this point in the history
  • Loading branch information
iljukhaput committed Nov 20, 2024
1 parent 3e914ac commit ad541c2
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 20 deletions.
16 changes: 11 additions & 5 deletions src/core/management_layer/application_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ class ApplicationManager::Implementation
/**
* @brief Обновить заголовок приложения
*/
void updateWindowTitle();
void updateWindowTitle(const QString& _projectName = QString{});

/**
* @brief Настроить состояние приложения сохранены ли все изменения или нет
Expand Down Expand Up @@ -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");
Expand All @@ -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")) : "")));

Expand Down Expand Up @@ -1345,6 +1345,13 @@ void ApplicationManager::Implementation::saveChanges()
//
markChangesSaved(true);

//
// Обновляем информацию в списке проектов
//
projectsManager->updateCurrentProject(projectManager->projectName(),
projectManager->projectLogline(),
projectManager->projectCover());

//
// И, если необходимо создадим резервную копию закрываемого файла
//
Expand Down Expand Up @@ -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);
Expand Down
34 changes: 30 additions & 4 deletions src/core/management_layer/content/project/project_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -3173,9 +3169,15 @@ void ProjectManager::saveChanges()
DataStorageLayer::StorageFacade::documentStorage()->saveDocument(document);
}


auto projectInformationModel = qobject_cast<BusinessLayer::ProjectInformationModel*>(
d->modelsFacade.modelFor(DataStorageLayer::StorageFacade::documentStorage()->document(
Domain::DocumentObjectType::Project)));

//
// Сохраняем изображения
//
projectInformationModel->saveCover();
d->documentImageStorage.saveChanges();

//
Expand Down Expand Up @@ -4232,6 +4234,30 @@ void ProjectManager::setGeneratedImage(const QPixmap& _image)
}
}

QString ProjectManager::projectName() const
{
auto projectInformationModel = qobject_cast<BusinessLayer::ProjectInformationModel*>(
d->modelsFacade.modelFor(DataStorageLayer::StorageFacade::documentStorage()->document(
Domain::DocumentObjectType::Project)));
return projectInformationModel->name();
}

QString ProjectManager::projectLogline() const
{
auto projectInformationModel = qobject_cast<BusinessLayer::ProjectInformationModel*>(
d->modelsFacade.modelFor(DataStorageLayer::StorageFacade::documentStorage()->document(
Domain::DocumentObjectType::Project)));
return projectInformationModel->logline();
}

QPixmap ProjectManager::projectCover() const
{
auto projectInformationModel = qobject_cast<BusinessLayer::ProjectInformationModel*>(
d->modelsFacade.modelFor(DataStorageLayer::StorageFacade::documentStorage()->document(
Domain::DocumentObjectType::Project)));
return projectInformationModel->cover();
}

bool ProjectManager::event(QEvent* _event)
{
switch (static_cast<int>(_event->type())) {
Expand Down
7 changes: 7 additions & 0 deletions src/core/management_layer/content/project/project_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 Запрос на отображение меню
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 12 additions & 0 deletions src/core/management_layer/content/projects/projects_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 5 additions & 0 deletions src/core/management_layer/content/projects/projects_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 Запрос на отображение меню
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,14 @@ void ProjectsModelProjectItem::setPosterPath(const QString& _path)
return;
}
}

d->posterPath = _path;

//
// Обнуляем постер, чтобы он потом извлёкся по заданному пути
//
d->poster = {};

setChanged(true);
}

QUuid ProjectsModelProjectItem::uuid() const
Expand All @@ -173,6 +174,7 @@ QString ProjectsModelProjectItem::name() const
void ProjectsModelProjectItem::setName(const QString& _name)
{
d->name = _name;
setChanged(true);
}

QString ProjectsModelProjectItem::logline() const
Expand All @@ -183,6 +185,7 @@ QString ProjectsModelProjectItem::logline() const
void ProjectsModelProjectItem::setLogline(const QString& _logline)
{
d->logline = _logline;
setChanged(true);
}

QString ProjectsModelProjectItem::displayLastEditTime() const
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,34 @@ 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;

QVector<Domain::ProjectCollaboratorInfo> collaborators;
QVector<Domain::TeamMemberInfo> 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);
Expand Down Expand Up @@ -109,18 +120,20 @@ 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 = {};
}

//
// Если задана новая обложка, то добавляем её
//
if (!_cover.isNull()) {
d->cover.uuid = imageWrapper()->save(_cover);
d->cover.uuid = QUuid::createUuid();
d->cover.image = _cover;
}

Expand All @@ -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;
Expand Down Expand Up @@ -215,7 +239,7 @@ void ProjectInformationModel::clearDocument()
//
auto structureModel = d->structureModel;

d.reset(new Implementation);
d.reset(new Implementation(this));

d->structureModel = structureModel;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit ad541c2

Please sign in to comment.