fernandotonon/QtMeshEditor

View on GitHub
src/material.cpp

Summary

Maintainability
Test Coverage
F
17%
#include "material.h"
#include "materialeditor.h"
#include "ui_material.h"
#include <QDebug>
#include <QFileDialog>
#include <OgreMaterialManager.h>
#include <OgreMaterialSerializer.h>
#include <OgreTechnique.h>
 
Material::Material(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::Material)
{
ui->setupUi(this);
}
 
Material::~Material()
{
delete ui;
}
 
void Material::UpdateMaterialList()
{
QStringList List;
Ogre::ResourceManager::ResourceMapIterator materialIterator = Ogre::MaterialManager::getSingleton().getResourceIterator();
while (materialIterator.hasMoreElements())
{
List.append(Ogre::static_pointer_cast<Ogre::Material>(materialIterator.peekNextValue())->getName().data());
materialIterator.moveNext();
}
SetMaterialList(List);
}
 
void Material::SetMaterialList(const QStringList &_list)
{
ui->listMaterial->clear();
ui->listMaterial->addItems(_list);
}
 
The function `on_listMaterial_itemSelectionChanged` is never used.
void Material::on_listMaterial_itemSelectionChanged()
{
ui->buttonEdit->setEnabled(true);
ui->buttonExport->setEnabled(true);
}
 
The function `on_buttonEdit_clicked` is never used.
void Material::on_buttonEdit_clicked()
{
MaterialEditor *ME = new MaterialEditor(this);
ME->setMaterial(ui->listMaterial->selectedItems()[0]->text());
ME->show();
}
 
The function `on_buttonExport_clicked` is never used.
void Material::on_buttonExport_clicked()
{
QString fileName = QFileDialog::getSaveFileName(this, tr("Export material"),
"",
tr("Ogre Mesh (*.material)"),
nullptr, QFileDialog::DontUseNativeDialog);
if(fileName.size())
{
 
Ogre::MaterialPtr material = Ogre::static_pointer_cast<Ogre::Material>(Ogre::MaterialManager::getSingleton().getByName(ui->listMaterial->selectedItems()[0]->text().toStdString().data()));
Ogre::MaterialSerializer ms;
ms.exportMaterial(material,fileName.toStdString().data());
}
}
 
The function `on_buttonNew_clicked` is never used.
void Material::on_buttonNew_clicked()
{
MaterialEditor *ME = new MaterialEditor(this);
ME->setMaterial("");
ME->show();
}
 
The function `on_pushButton_clicked` is never used.
void Material::on_pushButton_clicked()
{
QStringList filePaths = QFileDialog::getOpenFileNames(this, tr("Select the materials"),
"",
tr("Ogre Material (*.material)"),
nullptr, QFileDialog::DontUseNativeDialog);
 
foreach(const QString &filePath, filePaths)
{
if(filePath.size())
{
QFileInfo file;
file.setFile(filePath);
 
Ogre::ResourceGroupManager::getSingleton().addResourceLocation(file.path().toStdString().data(),"FileSystem",file.filePath().toStdString().data(),true);
Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
 
Ogre::MaterialManager::getSingleton().reloadAll(true);
Ogre::MeshManager::getSingleton().reloadAll(true);
 
UpdateMaterialList();
}
}
}
 
The function `on_listMaterial_itemDoubleClicked` is never used.
void Material::on_listMaterial_itemDoubleClicked(QListWidgetItem *item)
{
auto ME = new MaterialEditor(this);
ME->setMaterial(item->text());
ME->show();
}