adding custom list view item for project list

This commit is contained in:
Alister
2021-12-25 13:49:25 +00:00
parent 27b1b11349
commit f7498333ac
5 changed files with 230 additions and 73 deletions

View File

@@ -53,6 +53,65 @@ namespace Noggit::Project
std::shared_ptr<BlizzardArchive::ClientData> ClientData;
};
class ApplicationProjectReader
{
public:
ApplicationProjectReader() = default;
NoggitProject ReadProject(std::filesystem::path projectPath)
{
for (const auto& entry : std::filesystem::directory_iterator(projectPath))
{
if(entry.path().extension() == std::string(".noggitproj"))
{
QFile inputFile(QString::fromStdString(entry.path().generic_string()));
inputFile.open(QIODevice::ReadOnly);
auto document = QJsonDocument().fromJson(inputFile.readAll());
auto root = document.object();
auto project = NoggitProject();
if (root.contains("Project") && root["Project"].isObject())
{
auto projectConfiguration = root["Project"].toObject();
if (projectConfiguration.contains("ProjectName"))
project.ProjectName = projectConfiguration["ProjectName"].toString().toStdString();
if (projectConfiguration.contains("Client") && projectConfiguration["Client"].isObject())
{
auto projectClientConfiguration = projectConfiguration["Client"].toObject();
if (projectClientConfiguration.contains("ClientPath"))
{
project.ClientPath = projectClientConfiguration["ClientPath"].toString().toStdString();
}
if (projectClientConfiguration.contains("ClientVersion"))
{
auto clientVersion = projectClientConfiguration["ClientVersion"].toString().toStdString();
auto clientVersionEnum = Noggit::Project::ProjectVersion::WOTLK;
if (clientVersion == std::string("Shadowlands"))
{
clientVersionEnum = Noggit::Project::ProjectVersion::SL;
}
if (clientVersion == std::string("Wrath Of The Lich King"))
{
clientVersionEnum = Noggit::Project::ProjectVersion::WOTLK;
}
project.ProjectVersion = clientVersionEnum;
}
}
}
return project;
}
}
}
};
class ApplicationProject
{
std::shared_ptr<NoggitProject> _activeProject;
@@ -180,67 +239,37 @@ namespace Noggit::Project
}
}
std::shared_ptr<NoggitProject> LoadProject(std::filesystem::path projectPath, std::string projectName)
std::shared_ptr<NoggitProject> LoadProject(std::filesystem::path projectPath)
{
auto projectConfigurationFilePath = (projectPath / (projectName + std::string(".noggitproj")));
auto projectReader = ApplicationProjectReader();
auto project = projectReader.ReadProject(projectPath);
QFile inputFile(QString::fromStdString(projectConfigurationFilePath.generic_string()));
inputFile.open(QIODevice::ReadOnly);
std::string dbcFileDirectory = (projectPath / "workspace" / "DBFilesClient").generic_string();
std::string dbdFileDirectory = _configuration->ApplicationDatabaseDefinitionsPath;
auto document = QJsonDocument().fromJson(inputFile.readAll());
auto root = document.object();
auto project = NoggitProject();
if (root.contains("Project") && root["Project"].isObject())
auto clientBuild = BlizzardDatabaseLib::Structures::Build("3.3.5.12340");
auto clientArchiveVersion = BlizzardArchive::ClientVersion::WOTLK;
auto clientArchiveLocale = BlizzardArchive::Locale::AUTO;
if (project.ProjectVersion == ProjectVersion::SL)
{
auto projectConfiguration = root["Project"].toObject();
if (projectConfiguration.contains("ProjectName"))
project.ProjectName = projectConfiguration["ProjectName"].toString().toStdString();
if (projectConfiguration.contains("Client") && projectConfiguration["Client"].isObject())
{
auto projectClientConfiguration = projectConfiguration["Client"].toObject();
if (projectClientConfiguration.contains("ClientPath"))
{
project.ClientPath = projectClientConfiguration["ClientPath"].toString().toStdString();
}
if (projectClientConfiguration.contains("ClientVersion"))
{
auto clientVersion = projectClientConfiguration["ClientVersion"].toString().toStdString();
auto clientVersionEnum = Noggit::Project::ProjectVersion::WOTLK;
auto clientBuild = BlizzardDatabaseLib::Structures::Build("3.3.5.12340");
auto clientArchiveVersion = BlizzardArchive::ClientVersion::WOTLK;
auto clientArchiveLocale = BlizzardArchive::Locale::AUTO;
if (clientVersion == std::string("Shadowlands"))
{
clientVersionEnum = Noggit::Project::ProjectVersion::SL;
clientArchiveVersion = BlizzardArchive::ClientVersion::SL;
clientBuild = BlizzardDatabaseLib::Structures::Build("9.1.0.39584");
clientArchiveLocale = BlizzardArchive::Locale::enUS;
}
if (clientVersion == std::string("Wrath Of The Lich King"))
{
clientVersionEnum = Noggit::Project::ProjectVersion::WOTLK;
clientArchiveVersion = BlizzardArchive::ClientVersion::WOTLK;
clientBuild = BlizzardDatabaseLib::Structures::Build("3.3.5.12340");
clientArchiveLocale = BlizzardArchive::Locale::AUTO;
}
project.ProjectVersion = clientVersionEnum;
std::string dbcFileDirectory = (projectPath / "workspace" / "DBFilesClient").generic_string();
std::string dbdFileDirectory = _configuration->ApplicationDatabaseDefinitionsPath;
project.ClientDatabase = std::make_shared<BlizzardDatabaseLib::BlizzardDatabase>(dbcFileDirectory, dbdFileDirectory, clientBuild);
project.ClientData = std::make_shared<BlizzardArchive::ClientData>(project.ClientPath, clientArchiveVersion, clientArchiveLocale, std::string(""));
}
}
clientArchiveVersion = BlizzardArchive::ClientVersion::SL;
clientBuild = BlizzardDatabaseLib::Structures::Build("9.1.0.39584");
clientArchiveLocale = BlizzardArchive::Locale::enUS;
}
if (project.ProjectVersion == ProjectVersion::WOTLK)
{
clientArchiveVersion = BlizzardArchive::ClientVersion::WOTLK;
clientBuild = BlizzardDatabaseLib::Structures::Build("3.3.5.12340");
clientArchiveLocale = BlizzardArchive::Locale::AUTO;
}
project.ClientDatabase = std::make_shared<BlizzardDatabaseLib::BlizzardDatabase>(
dbcFileDirectory, dbdFileDirectory, clientBuild);
project.ClientData = std::make_shared<BlizzardArchive::ClientData>(
project.ClientPath, clientArchiveVersion, clientArchiveLocale, std::string(""));
return std::make_shared<NoggitProject>(project);
}
};

View File

@@ -357,7 +357,7 @@ namespace Noggit::Ui
if (e.areaType < 0 || e.areaType > 5 || !World::IsEditableWorld(record))
continue;
auto item(new QListWidgetItem(QString::number(e.mapID) + " - " + QString::fromUtf8(e.name.c_str()), type_to_table[e.areaType]));
auto item = new QListWidgetItem(QString::number(e.mapID) + " - " + QString::fromUtf8(e.name.c_str()), type_to_table[e.areaType]);
if (e.expansion == 0)
item->setIcon(QIcon(":/icon-classic"));
if (e.expansion == 1)
@@ -376,7 +376,8 @@ namespace Noggit::Ui
item->setIcon(QIcon(":/icon-battle"));
if (e.expansion == 8)
item->setIcon(QIcon(":/icon-shadow"));
item->setData(Qt::UserRole, QVariant(e.mapID));
item->setData(Qt::UserRole, QVariant(e.mapID));
}
_project->ClientDatabase->UnloadTable(table);
}

View File

@@ -11,6 +11,7 @@
#include <string>
#include <memory>
#include <unordered_set>
#include <QWidget>
class StackedWidget;
@@ -19,6 +20,7 @@ namespace Noggit
{
namespace Ui
{
class minimap_widget;
class settings;
class about;

View File

@@ -22,14 +22,7 @@ namespace Noggit::Ui::Windows
auto applicationProjectsFolderPath = std::filesystem::path(applicationConfiguration->ApplicationProjectPath);
auto existingProjects = _existingProjectEnumerationComponent->EnumerateExistingProjects(applicationProjectsFolderPath);
for (const auto& dirEntry : std::filesystem::directory_iterator(applicationConfiguration->ApplicationProjectPath))
{
auto item = new QListWidgetItem(QString::fromStdString(dirEntry.path().filename().generic_string()), ui->listView);
item->setData(Qt::UserRole, QVariant());
}
_projectListModel = new QStringListModel(this);
_projectListModel->setStringList(existingProjects);
BuildExistingProjectList();
QObject::connect(ui->button_create_new_project, &QPushButton::clicked
, [=]
@@ -46,7 +39,8 @@ namespace Noggit::Ui::Windows
}
auto existingProjects = _existingProjectEnumerationComponent->EnumerateExistingProjects(applicationProjectsFolderPath);
_projectListModel->setStringList(existingProjects);
BuildExistingProjectList();
}
);
@@ -61,10 +55,10 @@ namespace Noggit::Ui::Windows
, [=]
{
QModelIndex index = ui->listView->currentIndex();
auto projectName = index.data(Qt::DisplayRole).toString().toStdString();
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, projectName);
_selectedProject = applicationProjectService.LoadProject(projectPath);
//This to not be static, but its hard to remove
Noggit::Application::NoggitApplication::instance()->clientData(_selectedProject->ClientData);
@@ -74,12 +68,35 @@ namespace Noggit::Ui::Windows
projectSelectionPage->showMaximized();
}
);
//ui->listView->setModel(_projectListModel);
}
noggitRedProjectPage::~noggitRedProjectPage()
{
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 = 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 ProjectListItem(projectData, ui->listView);
item->setData(Qt::UserRole, QVariant(projectData.ProjectName));
item->setSizeHint(projectListItem->minimumSizeHint());
ui->listView->setItemWidget(item, projectListItem);
}
}
}

View File

@@ -5,7 +5,8 @@
#include <noggit/ui/windows/settingsPanel/SettingsPanel.h>
#include <QMenuBar>
#include <QAction>
#include <qstringlistmodel.h>
#include <qgraphicseffect.h>
#include <QString>
#include <noggit/application/NoggitApplication.hpp>
#include <noggit/ui/windows/mainWindow/main_window.hpp>
#include <noggit/ui/windows/projectCreation/projectcreationdialog.h>
@@ -22,6 +23,111 @@ namespace Noggit::Application {
namespace Noggit::Ui::Windows
{
struct ProjectListItemData
{
QString ProjectName;
QString ProjectDirectory;
QString ProjectLastEdited;
Project::ProjectVersion ProjectVersion;
};
class ProjectListItem : public QWidget
{
Q_OBJECT
private:
QLabel* project_version_icon;
QLabel* project_name_label;
QLabel* project_directory_label;
QLabel* project_version_label;
QLabel* project_last_edited_label;
public:
ProjectListItem(const ProjectListItemData& data, QWidget* parent = nullptr) : QWidget(parent)
{
auto layout = QGridLayout();
QIcon icon;
if(data.ProjectVersion == Project::ProjectVersion::WOTLK)
icon = QIcon(":/icon-wrath");
if (data.ProjectVersion == Project::ProjectVersion::SL)
icon = QIcon(":/icon-shadow");
project_version_icon = new QLabel("", parent);
project_version_icon->setPixmap(icon.pixmap(QSize(48, 48)));
project_version_icon->setGeometry(0, 0, 64, 48);
auto projectName = toCamelCase(QString(data.ProjectName));
project_name_label = new QLabel(projectName, parent);
project_name_label->setGeometry(45, 0, 125, 20);
project_name_label->setObjectName("project-title-label");
project_name_label->setStyleSheet("QLabel#project-title-label { font-size: 15px; }");
project_directory_label = new QLabel(data.ProjectDirectory, parent);
project_directory_label->setGeometry(48, 30, 125, 20);
project_directory_label->setObjectName("project-information");
project_directory_label->setStyleSheet("QLabel#project-information { font-size: 10px; }");
auto directoryEffect = new QGraphicsOpacityEffect(this);
directoryEffect->setOpacity(0.5);
project_directory_label->setGraphicsEffect(directoryEffect);
project_directory_label->setAutoFillBackground(true);
QString version;
if (data.ProjectVersion == Project::ProjectVersion::WOTLK)
version = "Wrath Of The Lich King";
if (data.ProjectVersion == Project::ProjectVersion::SL)
version = "Shadowlands";
project_version_label = new QLabel(version, parent);
project_version_label->setGeometry(48, 15, 125, 20);
project_version_label->setObjectName("project-information");
project_version_label->setStyleSheet("QLabel#project-information { font-size: 10px; }");
auto versionEffect = new QGraphicsOpacityEffect(this);
versionEffect->setOpacity(0.5);
project_version_label->setGraphicsEffect(versionEffect);
project_version_label->setAutoFillBackground(true);
auto width = parent->sizeHint().width();
project_last_edited_label = new QLabel(data.ProjectLastEdited, parent);
project_last_edited_label->setGeometry(width, 30, 125, 20);
project_last_edited_label->setAlignment(Qt::AlignRight | Qt::AlignTrailing | Qt::AlignVCenter);
project_last_edited_label->setObjectName("project-information");
project_last_edited_label->setStyleSheet("QLabel#project-information { font-size: 10px; }");
auto lastEditedEffect = new QGraphicsOpacityEffect(this);
lastEditedEffect->setOpacity(0.5);
project_last_edited_label->setGraphicsEffect(lastEditedEffect);
project_last_edited_label->setAutoFillBackground(true);
layout.addWidget(project_version_icon);
layout.addWidget(project_name_label);
layout.addWidget(project_directory_label);
layout.addWidget(project_version_label);
layout.addWidget(project_last_edited_label);
setLayout(layout.layout());
}
QSize minimumSizeHint() const override
{
return QSize(125, 48);
}
QString toCamelCase(const QString& s)
{
QStringList parts = s.split(' ', QString::SkipEmptyParts);
for (int i = 0; i < parts.size(); ++i)
parts[i].replace(0, 1, parts[i][0].toUpper());
return parts.join(" ");
}
};
class noggitRedProjectPage : public QMainWindow
{
Q_OBJECT
@@ -39,7 +145,9 @@ namespace Noggit::Ui::Windows
Noggit::Ui::settings* _settings;
std::unique_ptr<Noggit::Ui::main_window> projectSelectionPage;
QStringListModel* _projectListModel;
void BuildExistingProjectList();
};
}
#endif // NOGGITREDPROJECTPAGE_H
#endif // NOGGITREDPROJECTPAGE_H