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

@ -26,19 +26,18 @@ private:
int m_curSeverity;
FileInfoWindow* m_infoWindow;
QFileSystemModel* fmodel;
QStringList filters, dropDownDirList;
QFileSystemModel* m_fmodel;
QStringList m_filters;
// functions
private:
void setupWidgets();
void getAssetLibrary();
void setAsset(QString);
void setupAssetLibrary();
void updateAssetTree(QString);
void searchMeshFiles(QString path);
void openFile();
void openFileActual(QString);
void openFileDialog();
void openFile(QString);
void takeScreenShot();
void setDirList();
void aboutTool();
protected:

View File

@ -22,8 +22,8 @@ public:
// attributes
private:
QFile file;
QString listOfDirs;
QFile m_file;
QStringList m_listOfDirs;
QVector3D m_bgColorOn = { 5, 5, 5 };
QVector3D m_bgColorOff = { 128, 204, 255 };
@ -47,8 +47,7 @@ public:
bool isBfCulling() const;
bool isLight() const;
QString getListOfDirs();
void setListOfDirs(QString);
QStringList getListOfDirs();
int getLightType() const;
QVector3D getLightColor() const;
@ -72,4 +71,5 @@ public:
void setHeadlight(bool value);
void setAutoColor(int value);
void updateDirectories(QString path);
};

View File

@ -11,16 +11,11 @@ class SettingsWindow : public QWidget
public:
SettingsWindow(QWidget * parent = Q_NULLPTR);
~SettingsWindow();
QString getDirList();
private:
Ui::SettingsWindow* ui;
void setupConnections();
void updateDirList();
private:
QString dirList;
private slots:
void autoColorToggled();
@ -42,5 +37,6 @@ signals:
void sendBackfaceCulling(bool value);
void sendZommSpeed(int percent);
void changeLightType(int value);
void pathChanged(QString path);
};

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)

View File

@ -1,4 +1,5 @@
#include "..\Header\SettingsManager.h"
#include "qdebug.h"
/////////////////////////////////////////////////////////////////////////
@ -7,7 +8,7 @@
SettingsManager::SettingsManager(QObject *parent)
: QObject(parent)
{
file.setFileName("meshviewer.config");
m_file.setFileName("meshviewer.config");
readFromFile();
}
@ -28,24 +29,17 @@ SettingsManager* SettingsManager::getInstance(QObject *parent)
void SettingsManager::readFromFile()
{
if (file.open(QIODevice::ReadOnly))
if (m_file.open(QIODevice::ReadOnly))
{
QByteArray stream = file.readAll();
QByteArray stream = m_file.readAll();
QList<QByteArray> lines = stream.split('\n');
for (auto& it : lines)
{
if (it.startsWith("<qkList>"))
{
QList<QByteArray> values = it.right(it.size() - it.indexOf('>') - 1).split(';');
for (int i = 0; i < values.size(); i++)
{
if (i == values.size() - 1)
listOfDirs.append(values[i]);
else
listOfDirs.append(values[i] + ";");
}
m_listOfDirs = QString(it.right(it.size() - it.indexOf('>') - 1)).split(";");
}
else if (it.startsWith("<bgOn>"))
{
@ -98,44 +92,39 @@ void SettingsManager::readFromFile()
}
}
file.close();
m_file.close();
}
}
void SettingsManager::writeToFile()
{
file.open(QIODevice::WriteOnly);
m_file.open(QIODevice::WriteOnly);
file.write(QString("<bgOn>%1;%2;%3\n").arg(m_bgColorOn.x()).arg(m_bgColorOn.y()).arg(m_bgColorOn.z()).toUtf8());
file.write(QString("<bgOff>%1;%2;%3\n").arg(m_bgColorOff.x()).arg(m_bgColorOff.y()).arg(m_bgColorOff.z()).toUtf8());
file.write(QString("<liCo>%1;%2;%3\n").arg(m_lightColor.x()).arg(m_lightColor.y()).arg(m_lightColor.z()).toUtf8());
m_file.write(QString("<bgOn>%1;%2;%3\n").arg(m_bgColorOn.x()).arg(m_bgColorOn.y()).arg(m_bgColorOn.z()).toUtf8());
m_file.write(QString("<bgOff>%1;%2;%3\n").arg(m_bgColorOff.x()).arg(m_bgColorOff.y()).arg(m_bgColorOff.z()).toUtf8());
m_file.write(QString("<liCo>%1;%2;%3\n").arg(m_lightColor.x()).arg(m_lightColor.y()).arg(m_lightColor.z()).toUtf8());
file.write(QString("<bfCul>%1\n").arg(m_bfCulling).toUtf8());
file.write(QString("<liOn>%1\n").arg(m_light).toUtf8());
file.write(QString("<heLi>%1\n").arg(m_headlight).toUtf8());
file.write(QString("<auCo>%1\n").arg(m_autoColor).toUtf8());
m_file.write(QString("<bfCul>%1\n").arg(m_bfCulling).toUtf8());
m_file.write(QString("<liOn>%1\n").arg(m_light).toUtf8());
m_file.write(QString("<heLi>%1\n").arg(m_headlight).toUtf8());
m_file.write(QString("<auCo>%1\n").arg(m_autoColor).toUtf8());
file.write(QString("<liTy>%1\n").arg(m_lightType).toUtf8());
file.write(QString("<atFa>%1\n").arg(m_attenuation).toUtf8());
file.write(QString("<amCo>%1\n").arg(m_ambient).toUtf8());
file.write(QString("<qkList>%1\n").arg(listOfDirs).toUtf8());
m_file.write(QString("<liTy>%1\n").arg(m_lightType).toUtf8());
m_file.write(QString("<atFa>%1\n").arg(m_attenuation).toUtf8());
m_file.write(QString("<amCo>%1\n").arg(m_ambient).toUtf8());
if(!m_listOfDirs.isEmpty())
m_file.write(QString("<qkList>%1\n").arg(m_listOfDirs.join(";")).toUtf8());
file.close();
m_file.close();
}
// getter ///////////////////////////////////////////////////////////////
QString SettingsManager::getListOfDirs()
QStringList SettingsManager::getListOfDirs()
{
return listOfDirs;
return m_listOfDirs;
}
void SettingsManager::setListOfDirs(QString newDirSet)
{
listOfDirs = newDirSet;
}
QVector3D SettingsManager::getBgColorOn() const
{
return m_bgColorOn;
@ -243,3 +232,11 @@ void SettingsManager::setAutoColor(int value)
m_autoColor = true;
}
void SettingsManager::updateDirectories(QString path)
{
if (m_listOfDirs.contains(path))
m_listOfDirs.removeAll(path);
else
m_listOfDirs.append(path);
}

View File

@ -20,12 +20,9 @@ SettingsWindow::SettingsWindow(QWidget * parent)
SettingsManager* sm = SettingsManager::getInstance(this);
// set dirList for passing to Main and then fill settings manager dir list window
dirList = sm->getListOfDirs();
QStringList values;
values = dirList.split(';');
for (int i = 0; i < values.size(); i++) {
ui->dirListWidget->insertItem(0,values[i]);
}
QStringList tmp_directories = sm->getListOfDirs();
for (auto &it : tmp_directories)
ui->dirListWidget->insertItem(0, it);
ui->lightOff_R_SB->setValue((int)(sm->getBgColorOff()[0]));
ui->lightOff_G_SB->setValue((int)(sm->getBgColorOff()[1]));
@ -60,7 +57,7 @@ SettingsWindow::SettingsWindow(QWidget * parent)
connect(this, &SettingsWindow::sendBackfaceCulling, sm, &SettingsManager::setBfCulling);
connect(ui->checkAutoColor, &QCheckBox::stateChanged, sm, &SettingsManager::setAutoColor);
connect(this, &SettingsWindow::changeLightType, sm, &SettingsManager::setLightType);
connect(this, &SettingsWindow::pathChanged, sm, &SettingsManager::updateDirectories);
}
SettingsWindow::~SettingsWindow()
@ -72,11 +69,6 @@ SettingsWindow::~SettingsWindow()
/////////////////////////////////////////////////////////////////////////
// functions
QString SettingsWindow::getDirList()
{
return dirList;
}
void SettingsWindow::setupConnections()
{
// light off
@ -201,23 +193,16 @@ void SettingsWindow::on_addItem_clicked()
QString dirName = QFileDialog::getExistingDirectory(this, tr("Open Directory"), "/home",
QFileDialog::ShowDirsOnly |
QFileDialog::DontResolveSymlinks);
if (!SettingsManager::getInstance()->getListOfDirs().contains(dirName))
{
ui->dirListWidget->insertItem(0, dirName);
updateDirList();
emit pathChanged(dirName);
}
}
void SettingsWindow::on_removeItem_clicked()
{
qDeleteAll(ui->dirListWidget->selectedItems());
updateDirList();
}
void SettingsWindow::updateDirList()
{
int size = ui->dirListWidget->count();
QString dirs;
for (int i = 0; i < size; i++)
dirs += ui->dirListWidget->item(i)->text() + ";";
SettingsManager::getInstance()->setListOfDirs(dirs);
QListWidgetItem* tmp = ui->dirListWidget->takeItem(ui->dirListWidget->currentRow());
emit pathChanged(tmp->text());
delete tmp;
}