pulling out project lookup to friended component
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
#ifndef NOGGIT_COMPONENT_PROJECT_LIST_ITEM_HPP
|
||||
#define NOGGIT_COMPONENT_PROJECT_LIST_ITEM_HPP
|
||||
|
||||
#include <noggit/project/ApplicationProject.h>
|
||||
#include <noggit/ui/windows/projectSelection/widgets/ProjectListItem.hpp>
|
||||
#include <noggit/ui/windows/projectSelection/noggitredprojectpage.h>
|
||||
#include "ui_noggit-red-project-page.h"
|
||||
|
||||
namespace Noggit::Ui::Component
|
||||
{
|
||||
class ExistingProjectEnumerationComponent
|
||||
{
|
||||
friend Windows::noggitRedProjectPage;
|
||||
public:
|
||||
void BuildExistingProjectList(Noggit::Ui::Windows::noggitRedProjectPage* parent)
|
||||
{
|
||||
parent->ui->listView->clear();
|
||||
|
||||
auto applicationConfiguration = parent->_noggitApplication->GetConfiguration();
|
||||
for (const auto& dirEntry : std::filesystem::directory_iterator(applicationConfiguration->ApplicationProjectPath))
|
||||
{
|
||||
auto item = new QListWidgetItem(parent->ui->listView);
|
||||
auto projectReader = Noggit::Project::ApplicationProjectReader();
|
||||
auto project = projectReader.ReadProject(dirEntry);
|
||||
|
||||
auto projectData = Noggit::Ui::Widget::ProjectListItemData();
|
||||
projectData.ProjectVersion = project.ProjectVersion;
|
||||
projectData.ProjectDirectory = QString::fromStdString(dirEntry.path().generic_string());
|
||||
projectData.ProjectName = QString::fromStdString(project.ProjectName);
|
||||
projectData.ProjectLastEdited = QDateTime::currentDateTime().date().toString();
|
||||
|
||||
auto projectListItem = new Noggit::Ui::Widget::ProjectListItem(projectData, parent->ui->listView);
|
||||
|
||||
item->setData(Qt::UserRole, QVariant(projectData.ProjectName));
|
||||
item->setSizeHint(projectListItem->minimumSizeHint());
|
||||
parent->ui->listView->setItemWidget(item, projectListItem);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif //NOGGIT_COMPONENT_PROJECT_LIST_ITEM_HPP
|
||||
@@ -1,23 +0,0 @@
|
||||
#include <QStringList>
|
||||
|
||||
namespace Noggit::Ui::Component
|
||||
{
|
||||
class ExistingProjectEnumerationComponent
|
||||
{
|
||||
public:
|
||||
QStringList EnumerateExistingProjects(std::filesystem::path projectDirectory)
|
||||
{
|
||||
auto stringList = QStringList();
|
||||
for (const auto& dirEntry : std::filesystem::directory_iterator(projectDirectory))
|
||||
{
|
||||
//uto item(new QListWidgetItem(QString::number(e.mapID) + " - " + QString::fromUtf8(e.name.c_str()),type_to_table[e.areaType]));
|
||||
//tem->setData(Qt::UserRole, QVariant(e.mapID));
|
||||
|
||||
|
||||
stringList << QString::fromStdString(dirEntry.path().filename().generic_string());
|
||||
}
|
||||
|
||||
return stringList;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
#include <noggit/ui/windows/projectSelection/noggitredprojectpage.h>
|
||||
#include <noggit/ui/windows/projectSelection/components/ExistingProjectEnumerationComponent.hpp>
|
||||
#include "ui_noggit-red-project-page.h"
|
||||
#include <filesystem>
|
||||
#include <qstringlistmodel.h>
|
||||
#include <QString>
|
||||
#include <noggit/project/ApplicationProject.h>
|
||||
|
||||
namespace Noggit::Ui::Windows
|
||||
{
|
||||
@@ -16,15 +16,17 @@ namespace Noggit::Ui::Windows
|
||||
|
||||
ui->setupUi(this);
|
||||
|
||||
_settings = new Noggit::Ui::settings(this);
|
||||
|
||||
auto applicationConfiguration = _noggitApplication->GetConfiguration();
|
||||
auto applicationConfiguration = _noggitApplication->GetConfiguration();
|
||||
auto applicationProjectsFolderPath = std::filesystem::path(applicationConfiguration->ApplicationProjectPath);
|
||||
|
||||
BuildExistingProjectList();
|
||||
|
||||
_existingProjectEnumerationComponent = std::make_unique<Component::ExistingProjectEnumerationComponent>();
|
||||
|
||||
//_settings = new Noggit::Ui::settings(this);
|
||||
|
||||
_existingProjectEnumerationComponent->BuildExistingProjectList(this);
|
||||
|
||||
QObject::connect(ui->button_create_new_project, &QPushButton::clicked
|
||||
, [=]
|
||||
, [=,this]
|
||||
{
|
||||
auto projectReference = ProjectInformation();
|
||||
auto projectCreationDialog = ProjectCreationDialog(projectReference);
|
||||
@@ -37,15 +39,14 @@ namespace Noggit::Ui::Windows
|
||||
applicationProjectService.CreateProject(projectPath, projectReference.GameClientPath, projectReference.GameClientVersion, projectReference.ProjectName);
|
||||
}
|
||||
|
||||
BuildExistingProjectList();
|
||||
_existingProjectEnumerationComponent->BuildExistingProjectList(this);
|
||||
}
|
||||
);
|
||||
|
||||
QObject::connect(ui->button_open_existing_project, &QPushButton::clicked
|
||||
, [=]
|
||||
{
|
||||
_settings->show();
|
||||
return;
|
||||
//_settings->show();
|
||||
}
|
||||
);
|
||||
|
||||
@@ -56,14 +57,14 @@ namespace Noggit::Ui::Windows
|
||||
auto projectName = index.data(Qt::UserRole).toString().toStdString();
|
||||
auto applicationProjectService = Noggit::Project::ApplicationProject(applicationConfiguration);
|
||||
auto projectPath = std::filesystem::path(applicationProjectsFolderPath / projectName);
|
||||
_selectedProject = applicationProjectService.LoadProject(projectPath);
|
||||
auto selectedProject = applicationProjectService.LoadProject(projectPath);
|
||||
|
||||
//This to not be static, but its hard to remove
|
||||
Noggit::Application::NoggitApplication::instance()->clientData(_selectedProject->ClientData);
|
||||
Noggit::Application::NoggitApplication::instance()->clientData(selectedProject->ClientData);
|
||||
|
||||
close();
|
||||
|
||||
projectSelectionPage = std::make_unique<Noggit::Ui::main_window>(_noggitApplication->GetConfiguration(), _selectedProject);
|
||||
projectSelectionPage = std::make_unique<Noggit::Ui::main_window>(_noggitApplication->GetConfiguration(), selectedProject);
|
||||
projectSelectionPage->showMaximized();
|
||||
}
|
||||
);
|
||||
@@ -73,29 +74,4 @@ namespace Noggit::Ui::Windows
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void noggitRedProjectPage::BuildExistingProjectList()
|
||||
{
|
||||
ui->listView->clear();
|
||||
|
||||
auto applicationConfiguration = _noggitApplication->GetConfiguration();
|
||||
for (const auto& dirEntry : std::filesystem::directory_iterator(applicationConfiguration->ApplicationProjectPath))
|
||||
{
|
||||
auto item = new QListWidgetItem(ui->listView);
|
||||
auto projectReader = Noggit::Project::ApplicationProjectReader();
|
||||
auto project = projectReader.ReadProject(dirEntry);
|
||||
|
||||
auto projectData = Noggit::Ui::Component::ProjectListItemData();
|
||||
projectData.ProjectVersion = project.ProjectVersion;
|
||||
projectData.ProjectDirectory = QString::fromStdString(dirEntry.path().generic_string());
|
||||
projectData.ProjectName = QString::fromStdString(project.ProjectName);
|
||||
projectData.ProjectLastEdited = QDateTime::currentDateTime().date().toString();
|
||||
|
||||
auto projectListItem = new Noggit::Ui::Component::ProjectListItem(projectData, ui->listView);
|
||||
|
||||
item->setData(Qt::UserRole, QVariant(projectData.ProjectName));
|
||||
item->setSizeHint(projectListItem->minimumSizeHint());
|
||||
ui->listView->setItemWidget(item, projectListItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,12 +10,16 @@
|
||||
#include <noggit/application/NoggitApplication.hpp>
|
||||
#include <noggit/ui/windows/mainWindow/main_window.hpp>
|
||||
#include <noggit/ui/windows/projectCreation/projectcreationdialog.h>
|
||||
#include <noggit/ui/windows/projectSelection/widgets/ProjectListItem.hpp>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Ui { class noggitRedProjectPage; }
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace Noggit::Ui::Component
|
||||
{
|
||||
class ExistingProjectEnumerationComponent;
|
||||
}
|
||||
|
||||
namespace Noggit::Application {
|
||||
class NoggitApplication;
|
||||
}
|
||||
@@ -25,7 +29,7 @@ namespace Noggit::Ui::Windows
|
||||
class noggitRedProjectPage : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
friend Component::ExistingProjectEnumerationComponent;
|
||||
public:
|
||||
noggitRedProjectPage(Noggit::Application::NoggitApplication* noggitApplication, QWidget* parent = nullptr);
|
||||
~noggitRedProjectPage();
|
||||
@@ -35,10 +39,9 @@ namespace Noggit::Ui::Windows
|
||||
::Ui::noggitRedProjectPage* ui;
|
||||
Noggit::Ui::settings* _settings;
|
||||
|
||||
std::shared_ptr<Noggit::Project::NoggitProject> _selectedProject;
|
||||
std::unique_ptr<Noggit::Ui::main_window> projectSelectionPage;
|
||||
|
||||
void BuildExistingProjectList();
|
||||
std::unique_ptr<Component::ExistingProjectEnumerationComponent> _existingProjectEnumerationComponent;
|
||||
};
|
||||
}
|
||||
#endif // NOGGITREDPROJECTPAGE_H
|
||||
@@ -1,6 +1,6 @@
|
||||
#include <noggit/ui/windows/projectSelection/widgets/ProjectListItem.hpp>
|
||||
|
||||
namespace Noggit::Ui::Component
|
||||
namespace Noggit::Ui::Widget
|
||||
{
|
||||
ProjectListItem::ProjectListItem(const ProjectListItemData& data, QWidget* parent = nullptr) : QWidget(parent)
|
||||
{
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
#ifndef NOGGIT_COMPONENT_PROJECT_LIST_ITEM_HPP
|
||||
#define NOGGIT_COMPONENT_PROJECT_LIST_ITEM_HPP
|
||||
#ifndef NOGGIT_WIGDET_PROJECT_LIST_ITEM_HPP
|
||||
#define NOGGIT_WIGDET_PROJECT_LIST_ITEM_HPP
|
||||
|
||||
#include <QMenuBar>
|
||||
#include <QAction>
|
||||
#include <qgraphicseffect.h>
|
||||
#include <QGridLayout>
|
||||
#include <QString>
|
||||
#include <QWidget>
|
||||
#include <noggit/application/NoggitApplication.hpp>
|
||||
#include <noggit/ui/windows/mainWindow/main_window.hpp>
|
||||
#include <noggit/project/ApplicationProject.h>
|
||||
|
||||
namespace Noggit::Ui::Component
|
||||
namespace Noggit::Ui::Widget
|
||||
{
|
||||
struct ProjectListItemData
|
||||
{
|
||||
@@ -36,4 +36,4 @@ namespace Noggit::Ui::Component
|
||||
};
|
||||
}
|
||||
|
||||
#endif //NOGGIT_COMPONENT_PROJECT_LIST_ITEM_HPP
|
||||
#endif //NOGGIT_WIGDET_PROJECT_LIST_ITEM_HPP
|
||||
Reference in New Issue
Block a user