pulling out project loading into a component

This commit is contained in:
Alister
2021-12-25 17:56:47 +00:00
parent 1759081f09
commit 3a51283a70
3 changed files with 22 additions and 28 deletions

View File

@@ -1,5 +1,5 @@
#ifndef NOGGIT_COMPONENT_PROJECT_LIST_ITEM_HPP
#define NOGGIT_COMPONENT_PROJECT_LIST_ITEM_HPP
#ifndef NOGGIT_COMPONENT_EXISTING_PROJECT_ENUMERATION_HPP
#define NOGGIT_COMPONENT_EXISTING_PROJECT_ENUMERATION_HPP
#include <noggit/project/ApplicationProject.h>
#include <noggit/ui/windows/projectSelection/widgets/ProjectListItem.hpp>
@@ -42,4 +42,4 @@ namespace Noggit::Ui::Component
};
}
#endif //NOGGIT_COMPONENT_PROJECT_LIST_ITEM_HPP
#endif //NOGGIT_COMPONENT_EXISTING_PROJECT_ENUMERATION_HPP

View File

@@ -1,10 +1,13 @@
#include <noggit/ui/windows/projectSelection/noggitredprojectpage.h>
#include <noggit/ui/windows/projectSelection/components/ExistingProjectEnumerationComponent.hpp>
#include <noggit/ui/windows/projectSelection/components/CreateProjectComponent.hpp>
#include "ui_noggit-red-project-page.h"
#include <filesystem>
#include <qstringlistmodel.h>
#include <QString>
#include "components/LoadProjectComponent.hpp"
namespace Noggit::Ui::Windows
{
noggitRedProjectPage::noggitRedProjectPage(Noggit::Application::NoggitApplication* noggitApplication, QWidget* parent)
@@ -16,12 +19,9 @@ namespace Noggit::Ui::Windows
ui->setupUi(this);
auto applicationConfiguration = _noggitApplication->GetConfiguration();
auto applicationProjectsFolderPath = std::filesystem::path(applicationConfiguration->ApplicationProjectPath);
_existingProjectEnumerationComponent = std::make_unique<Component::ExistingProjectEnumerationComponent>();
//_settings = new Noggit::Ui::settings(this);
_createProjectComponent = std::make_unique<Component::CreateProjectComponent>();
_loadProjectComponent = std::make_unique<Component::LoadProjectComponent>();
_existingProjectEnumerationComponent->BuildExistingProjectList(this);
@@ -32,13 +32,7 @@ namespace Noggit::Ui::Windows
auto projectCreationDialog = ProjectCreationDialog(projectReference);
projectCreationDialog.exec();
auto applicationProjectService = Noggit::Project::ApplicationProject(applicationConfiguration);
auto projectPath = std::filesystem::path(applicationProjectsFolderPath / projectReference.ProjectName);
if (!std::filesystem::exists(projectPath))
{
applicationProjectService.CreateProject(projectPath, projectReference.GameClientPath, projectReference.GameClientVersion, projectReference.ProjectName);
}
_createProjectComponent->CreateProject(this,projectReference);
_existingProjectEnumerationComponent->BuildExistingProjectList(this);
}
);
@@ -46,26 +40,19 @@ namespace Noggit::Ui::Windows
QObject::connect(ui->button_open_existing_project, &QPushButton::clicked
, [=]
{
//_settings->show();
return;
}
);
QObject::connect(ui->listView, &QListView::doubleClicked
, [=]
{
QModelIndex index = ui->listView->currentIndex();
auto projectName = index.data(Qt::UserRole).toString().toStdString();
auto applicationProjectService = Noggit::Project::ApplicationProject(applicationConfiguration);
auto projectPath = std::filesystem::path(applicationProjectsFolderPath / projectName);
auto selectedProject = applicationProjectService.LoadProject(projectPath);
//This to not be static, but its hard to remove
Noggit::Application::NoggitApplication::instance()->clientData(selectedProject->ClientData);
close();
auto selectedProject = _loadProjectComponent->LoadProject(this);
projectSelectionPage = std::make_unique<Noggit::Ui::main_window>(_noggitApplication->GetConfiguration(), selectedProject);
projectSelectionPage->showMaximized();
close();
}
);
}
@@ -74,4 +61,4 @@ namespace Noggit::Ui::Windows
{
delete ui;
}
}
}

View File

@@ -18,9 +18,12 @@ QT_END_NAMESPACE
namespace Noggit::Ui::Component
{
class ExistingProjectEnumerationComponent;
class CreateProjectComponent;
class LoadProjectComponent;
}
namespace Noggit::Application {
namespace Noggit::Application
{
class NoggitApplication;
}
@@ -30,6 +33,8 @@ namespace Noggit::Ui::Windows
{
Q_OBJECT
friend Component::ExistingProjectEnumerationComponent;
friend Component::CreateProjectComponent;
friend Component::LoadProjectComponent;
public:
noggitRedProjectPage(Noggit::Application::NoggitApplication* noggitApplication, QWidget* parent = nullptr);
~noggitRedProjectPage();
@@ -42,6 +47,8 @@ namespace Noggit::Ui::Windows
std::unique_ptr<Noggit::Ui::main_window> projectSelectionPage;
std::unique_ptr<Component::ExistingProjectEnumerationComponent> _existingProjectEnumerationComponent;
std::unique_ptr<Component::CreateProjectComponent> _createProjectComponent;
std::unique_ptr<Component::LoadProjectComponent> _loadProjectComponent;
};
}
#endif // NOGGITREDPROJECTPAGE_H