removed unused or useless stuff,

renamed some functions for better description,
repaired the SettingsManager usage,
ToDo:
Dropdown list is not updated, it needs a restart,
display names for the directories instead of the path,
This commit is contained in:
Anakin
2017-06-17 15:42:43 +02:00
parent 6141263f45
commit 33fafb29a8
6 changed files with 89 additions and 108 deletions

View File

@@ -2,6 +2,7 @@
#include "..\Header\OglViewerWidget.h"
#include "..\Header\FileInterface.h"
#include "..\Header\OutputDevice.h"
#include "..\Header\SettingsManager.h"
#include <QSurfaceFormat>
#include <QSignalMapper>
#include <QToolButton>
@@ -42,23 +43,17 @@ MainWindow::MainWindow(QWidget *parent)
m_fileInfo = "Filename: -\nMaterials: -\nVertices: -\nTriangle: -<detail>No file is open";
// set filter and apply drop down tabs/links
filters << "*.msh" << "*.MSH" << "*.mesh" << "*.MESH";
fmodel = new QFileSystemModel(this);
fmodel->setNameFilters(filters);
fmodel->setFilter(QDir::NoDotAndDotDot | QDir::Files);
fmodel->setNameFilterDisables(false);
m_filters << "*.msh" << "*.MSH" << "*.mesh" << "*.MESH";
m_fmodel = new QFileSystemModel(this);
m_fmodel->setNameFilters(m_filters);
m_fmodel->setFilter(QDir::NoDotAndDotDot | QDir::Files);
m_fmodel->setNameFilterDisables(false);
ui->dirDropDownList->addItem("BF1_ModTools", "C:/BF1_ModTools/Assets/Shipped Worlds/"); // temp here
ui->dirDropDownList->addItem("BF2_ModTools", "C:/BF2_ModTools/assets/Sides/"); // temp here
// get the list of dirs from settimgs or rather settings window
SettingsWindow obj;
QString tmp = obj.getDirList();
dropDownDirList = tmp.split(";");
for (int i = 0; i < dropDownDirList.size(); i++)
ui->dirDropDownList->addItem(dropDownDirList[i], dropDownDirList[i]); // temp here
// add widgets to the window
// the settingsmanger is alive now. So use it ;)
setupWidgets();
// load stylesheet
@@ -66,7 +61,7 @@ MainWindow::MainWindow(QWidget *parent)
styleSheet.open(QIODevice::ReadOnly);
this->setStyleSheet(styleSheet.readAll());
getAssetLibrary();
setupAssetLibrary();
printMessage("MeshViewer by Anakin", 0);
}
@@ -87,11 +82,11 @@ void MainWindow::setupWidgets()
connect(this, &MainWindow::loadFile, viewer, &OglViewerWidget::loadFile);
// open file
QToolButton *openFile = new QToolButton(this);
openFile->setObjectName("openFile");
openFile->setToolTip("open file");
connect(openFile, &QToolButton::pressed, this, &MainWindow::openFile);
ui->mainToolBar->addWidget(openFile);
QToolButton *openFileDialog = new QToolButton(this);
openFileDialog->setObjectName("openFile");
openFileDialog->setToolTip("open file");
connect(openFileDialog, &QToolButton::pressed, this, &MainWindow::openFileDialog);
ui->mainToolBar->addWidget(openFileDialog);
// screenshot
QToolButton *screenshot = new QToolButton(this);
@@ -176,18 +171,27 @@ void MainWindow::setupWidgets()
m_output->raise();
}
void MainWindow::getAssetLibrary()
void MainWindow::setupAssetLibrary()
{
QString path;
path = "C:/BF2_ModTools/data_MAX/Worlds/MAX/msh"; // temp path setting
setAsset(path);
// get all directories and put them in the dropdown.
QStringList tmp_list = SettingsManager::getInstance()->getListOfDirs();
for (QString &it : tmp_list)
ui->dirDropDownList->addItem(it, it);
// choose the current path and display it.
if (ui->dirDropDownList->currentData().isValid())
updateAssetTree(ui->dirDropDownList->currentData().toString());
}
void MainWindow::setAsset(QString path)
void MainWindow::updateAssetTree(QString path)
{
fmodel->setRootPath(path);
ui->fileListView->setModel(fmodel);
ui->fileListView->setRootIndex(fmodel->index(path));
// TODO: deep search seams to be missing.
// take a look at the search MeshFiles function. I already implemented something like
// that but never finsihed. But you can use this function. Just adjust it as it fits
// to the m_fmodel. I never used those model based trees before.
m_fmodel->setRootPath(path);
ui->fileListView->setModel(m_fmodel);
ui->fileListView->setRootIndex(m_fmodel->index(path));
}
void MainWindow::searchMeshFiles(QString path)
@@ -207,13 +211,13 @@ void MainWindow::searchMeshFiles(QString path)
}
void MainWindow::openFile()
void MainWindow::openFileDialog()
{
QString fileName = QFileDialog::getOpenFileName(this, "Open File", "", "Mesh (*.msh)");
openFileActual(fileName);
openFile(fileName);
}
void MainWindow::openFileActual(QString fileName)
void MainWindow::openFile(QString fileName)
{
if(!fileName.isEmpty())
emit loadFile(fileName);
@@ -258,8 +262,8 @@ void MainWindow::resizeEvent(QResizeEvent * e)
void MainWindow::on_fileListView_doubleClicked(const QModelIndex &index)
{
QString clickedFile = fmodel->fileInfo(index).absoluteFilePath();
openFileActual(clickedFile);
QString clickedFile = m_fmodel->fileInfo(index).absoluteFilePath();
openFile(clickedFile);
}
void MainWindow::on_dirDropDownList_currentTextChanged(const QString &arg1)
@@ -267,7 +271,7 @@ void MainWindow::on_dirDropDownList_currentTextChanged(const QString &arg1)
QString selectedDir;
selectedDir = ui->dirDropDownList->itemData(ui->dirDropDownList->currentIndex()).toString();
printMessage(arg1 + " : " + selectedDir, 0);
setAsset(selectedDir);
updateAssetTree(selectedDir);
}
void MainWindow::printMessage(QString message, int severity)