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; int m_curSeverity;
FileInfoWindow* m_infoWindow; FileInfoWindow* m_infoWindow;
QFileSystemModel* fmodel; QFileSystemModel* m_fmodel;
QStringList filters, dropDownDirList; QStringList m_filters;
// functions // functions
private: private:
void setupWidgets(); void setupWidgets();
void getAssetLibrary(); void setupAssetLibrary();
void setAsset(QString); void updateAssetTree(QString);
void searchMeshFiles(QString path); void searchMeshFiles(QString path);
void openFile(); void openFileDialog();
void openFileActual(QString); void openFile(QString);
void takeScreenShot(); void takeScreenShot();
void setDirList();
void aboutTool(); void aboutTool();
protected: protected:

View File

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

View File

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

View File

@ -2,6 +2,7 @@
#include "..\Header\OglViewerWidget.h" #include "..\Header\OglViewerWidget.h"
#include "..\Header\FileInterface.h" #include "..\Header\FileInterface.h"
#include "..\Header\OutputDevice.h" #include "..\Header\OutputDevice.h"
#include "..\Header\SettingsManager.h"
#include <QSurfaceFormat> #include <QSurfaceFormat>
#include <QSignalMapper> #include <QSignalMapper>
#include <QToolButton> #include <QToolButton>
@ -42,23 +43,17 @@ MainWindow::MainWindow(QWidget *parent)
m_fileInfo = "Filename: -\nMaterials: -\nVertices: -\nTriangle: -<detail>No file is open"; m_fileInfo = "Filename: -\nMaterials: -\nVertices: -\nTriangle: -<detail>No file is open";
// set filter and apply drop down tabs/links // set filter and apply drop down tabs/links
filters << "*.msh" << "*.MSH" << "*.mesh" << "*.MESH"; m_filters << "*.msh" << "*.MSH" << "*.mesh" << "*.MESH";
fmodel = new QFileSystemModel(this); m_fmodel = new QFileSystemModel(this);
fmodel->setNameFilters(filters); m_fmodel->setNameFilters(m_filters);
fmodel->setFilter(QDir::NoDotAndDotDot | QDir::Files); m_fmodel->setFilter(QDir::NoDotAndDotDot | QDir::Files);
fmodel->setNameFilterDisables(false); m_fmodel->setNameFilterDisables(false);
ui->dirDropDownList->addItem("BF1_ModTools", "C:/BF1_ModTools/Assets/Shipped Worlds/"); // temp here 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 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 // add widgets to the window
// the settingsmanger is alive now. So use it ;)
setupWidgets(); setupWidgets();
// load stylesheet // load stylesheet
@ -66,7 +61,7 @@ MainWindow::MainWindow(QWidget *parent)
styleSheet.open(QIODevice::ReadOnly); styleSheet.open(QIODevice::ReadOnly);
this->setStyleSheet(styleSheet.readAll()); this->setStyleSheet(styleSheet.readAll());
getAssetLibrary(); setupAssetLibrary();
printMessage("MeshViewer by Anakin", 0); printMessage("MeshViewer by Anakin", 0);
} }
@ -87,11 +82,11 @@ void MainWindow::setupWidgets()
connect(this, &MainWindow::loadFile, viewer, &OglViewerWidget::loadFile); connect(this, &MainWindow::loadFile, viewer, &OglViewerWidget::loadFile);
// open file // open file
QToolButton *openFile = new QToolButton(this); QToolButton *openFileDialog = new QToolButton(this);
openFile->setObjectName("openFile"); openFileDialog->setObjectName("openFile");
openFile->setToolTip("open file"); openFileDialog->setToolTip("open file");
connect(openFile, &QToolButton::pressed, this, &MainWindow::openFile); connect(openFileDialog, &QToolButton::pressed, this, &MainWindow::openFileDialog);
ui->mainToolBar->addWidget(openFile); ui->mainToolBar->addWidget(openFileDialog);
// screenshot // screenshot
QToolButton *screenshot = new QToolButton(this); QToolButton *screenshot = new QToolButton(this);
@ -176,18 +171,27 @@ void MainWindow::setupWidgets()
m_output->raise(); m_output->raise();
} }
void MainWindow::getAssetLibrary() void MainWindow::setupAssetLibrary()
{ {
QString path; // get all directories and put them in the dropdown.
path = "C:/BF2_ModTools/data_MAX/Worlds/MAX/msh"; // temp path setting QStringList tmp_list = SettingsManager::getInstance()->getListOfDirs();
setAsset(path); 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); // TODO: deep search seams to be missing.
ui->fileListView->setModel(fmodel); // take a look at the search MeshFiles function. I already implemented something like
ui->fileListView->setRootIndex(fmodel->index(path)); // 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) 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)"); 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()) if(!fileName.isEmpty())
emit loadFile(fileName); emit loadFile(fileName);
@ -258,8 +262,8 @@ void MainWindow::resizeEvent(QResizeEvent * e)
void MainWindow::on_fileListView_doubleClicked(const QModelIndex &index) void MainWindow::on_fileListView_doubleClicked(const QModelIndex &index)
{ {
QString clickedFile = fmodel->fileInfo(index).absoluteFilePath(); QString clickedFile = m_fmodel->fileInfo(index).absoluteFilePath();
openFileActual(clickedFile); openFile(clickedFile);
} }
void MainWindow::on_dirDropDownList_currentTextChanged(const QString &arg1) void MainWindow::on_dirDropDownList_currentTextChanged(const QString &arg1)
@ -267,7 +271,7 @@ void MainWindow::on_dirDropDownList_currentTextChanged(const QString &arg1)
QString selectedDir; QString selectedDir;
selectedDir = ui->dirDropDownList->itemData(ui->dirDropDownList->currentIndex()).toString(); selectedDir = ui->dirDropDownList->itemData(ui->dirDropDownList->currentIndex()).toString();
printMessage(arg1 + " : " + selectedDir, 0); printMessage(arg1 + " : " + selectedDir, 0);
setAsset(selectedDir); updateAssetTree(selectedDir);
} }
void MainWindow::printMessage(QString message, int severity) void MainWindow::printMessage(QString message, int severity)

View File

@ -1,4 +1,5 @@
#include "..\Header\SettingsManager.h" #include "..\Header\SettingsManager.h"
#include "qdebug.h"
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
@ -7,7 +8,7 @@
SettingsManager::SettingsManager(QObject *parent) SettingsManager::SettingsManager(QObject *parent)
: QObject(parent) : QObject(parent)
{ {
file.setFileName("meshviewer.config"); m_file.setFileName("meshviewer.config");
readFromFile(); readFromFile();
} }
@ -28,24 +29,17 @@ SettingsManager* SettingsManager::getInstance(QObject *parent)
void SettingsManager::readFromFile() 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'); QList<QByteArray> lines = stream.split('\n');
for (auto& it : lines) for (auto& it : lines)
{ {
if (it.startsWith("<qkList>")) if (it.startsWith("<qkList>"))
{ {
QList<QByteArray> values = it.right(it.size() - it.indexOf('>') - 1).split(';'); m_listOfDirs = QString(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] + ";");
}
} }
else if (it.startsWith("<bgOn>")) else if (it.startsWith("<bgOn>"))
{ {
@ -98,44 +92,39 @@ void SettingsManager::readFromFile()
} }
} }
file.close(); m_file.close();
} }
} }
void SettingsManager::writeToFile() 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()); m_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()); m_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("<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()); m_file.write(QString("<bfCul>%1\n").arg(m_bfCulling).toUtf8());
file.write(QString("<liOn>%1\n").arg(m_light).toUtf8()); m_file.write(QString("<liOn>%1\n").arg(m_light).toUtf8());
file.write(QString("<heLi>%1\n").arg(m_headlight).toUtf8()); m_file.write(QString("<heLi>%1\n").arg(m_headlight).toUtf8());
file.write(QString("<auCo>%1\n").arg(m_autoColor).toUtf8()); m_file.write(QString("<auCo>%1\n").arg(m_autoColor).toUtf8());
file.write(QString("<liTy>%1\n").arg(m_lightType).toUtf8()); m_file.write(QString("<liTy>%1\n").arg(m_lightType).toUtf8());
file.write(QString("<atFa>%1\n").arg(m_attenuation).toUtf8()); m_file.write(QString("<atFa>%1\n").arg(m_attenuation).toUtf8());
file.write(QString("<amCo>%1\n").arg(m_ambient).toUtf8()); m_file.write(QString("<amCo>%1\n").arg(m_ambient).toUtf8());
file.write(QString("<qkList>%1\n").arg(listOfDirs).toUtf8()); if(!m_listOfDirs.isEmpty())
m_file.write(QString("<qkList>%1\n").arg(m_listOfDirs.join(";")).toUtf8());
file.close(); m_file.close();
} }
// getter /////////////////////////////////////////////////////////////// // getter ///////////////////////////////////////////////////////////////
QString SettingsManager::getListOfDirs() QStringList SettingsManager::getListOfDirs()
{ {
return listOfDirs; return m_listOfDirs;
} }
void SettingsManager::setListOfDirs(QString newDirSet)
{
listOfDirs = newDirSet;
}
QVector3D SettingsManager::getBgColorOn() const QVector3D SettingsManager::getBgColorOn() const
{ {
return m_bgColorOn; return m_bgColorOn;
@ -243,3 +232,11 @@ void SettingsManager::setAutoColor(int value)
m_autoColor = true; 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); SettingsManager* sm = SettingsManager::getInstance(this);
// set dirList for passing to Main and then fill settings manager dir list window // set dirList for passing to Main and then fill settings manager dir list window
dirList = sm->getListOfDirs(); QStringList tmp_directories = sm->getListOfDirs();
QStringList values; for (auto &it : tmp_directories)
values = dirList.split(';'); ui->dirListWidget->insertItem(0, it);
for (int i = 0; i < values.size(); i++) {
ui->dirListWidget->insertItem(0,values[i]);
}
ui->lightOff_R_SB->setValue((int)(sm->getBgColorOff()[0])); ui->lightOff_R_SB->setValue((int)(sm->getBgColorOff()[0]));
ui->lightOff_G_SB->setValue((int)(sm->getBgColorOff()[1])); 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(this, &SettingsWindow::sendBackfaceCulling, sm, &SettingsManager::setBfCulling);
connect(ui->checkAutoColor, &QCheckBox::stateChanged, sm, &SettingsManager::setAutoColor); connect(ui->checkAutoColor, &QCheckBox::stateChanged, sm, &SettingsManager::setAutoColor);
connect(this, &SettingsWindow::changeLightType, sm, &SettingsManager::setLightType); connect(this, &SettingsWindow::changeLightType, sm, &SettingsManager::setLightType);
connect(this, &SettingsWindow::pathChanged, sm, &SettingsManager::updateDirectories);
} }
SettingsWindow::~SettingsWindow() SettingsWindow::~SettingsWindow()
@ -72,11 +69,6 @@ SettingsWindow::~SettingsWindow()
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// functions // functions
QString SettingsWindow::getDirList()
{
return dirList;
}
void SettingsWindow::setupConnections() void SettingsWindow::setupConnections()
{ {
// light off // light off
@ -201,23 +193,16 @@ void SettingsWindow::on_addItem_clicked()
QString dirName = QFileDialog::getExistingDirectory(this, tr("Open Directory"), "/home", QString dirName = QFileDialog::getExistingDirectory(this, tr("Open Directory"), "/home",
QFileDialog::ShowDirsOnly | QFileDialog::ShowDirsOnly |
QFileDialog::DontResolveSymlinks); QFileDialog::DontResolveSymlinks);
if (!SettingsManager::getInstance()->getListOfDirs().contains(dirName))
{
ui->dirListWidget->insertItem(0, dirName); ui->dirListWidget->insertItem(0, dirName);
updateDirList(); emit pathChanged(dirName);
}
} }
void SettingsWindow::on_removeItem_clicked() void SettingsWindow::on_removeItem_clicked()
{ {
qDeleteAll(ui->dirListWidget->selectedItems()); QListWidgetItem* tmp = ui->dirListWidget->takeItem(ui->dirListWidget->currentRow());
updateDirList(); emit pathChanged(tmp->text());
} delete tmp;
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);
} }