using signal slot to update the combobox entries

This commit is contained in:
Anakin 2017-06-20 11:41:10 +02:00
parent 3f2713bd16
commit 44732057b6
4 changed files with 33 additions and 23 deletions

View File

@ -31,7 +31,6 @@ private:
// functions // functions
private: private:
void setupWidgets(); void setupWidgets();
void setupAssetLibrary();
void updateAssetTree(QString); void updateAssetTree(QString);
void openFileDialog(); void openFileDialog();
void openFile(QString); void openFile(QString);
@ -46,12 +45,13 @@ public slots:
void printMessage(QString message, int severity); void printMessage(QString message, int severity);
void setFileInfo(QString name, QVector<Material>* materials, int vertices, int triangle); void setFileInfo(QString name, QVector<Material>* materials, int vertices, int triangle);
// private slots
private slots:
void setupAssetLibrary();
void on_fileListWidget_doubleClicked(const QModelIndex &index);
void on_dirDropDownList_currentTextChanged(const QString &arg1);
// signals // signals
signals: signals:
void loadFile(QString); void loadFile(QString);
// private slots
private slots:
void on_fileListWidget_doubleClicked(const QModelIndex &index);
void on_dirDropDownList_currentTextChanged(const QString &arg1);
}; };

View File

@ -72,4 +72,8 @@ public:
void setAutoColor(int value); void setAutoColor(int value);
void updateDirectories(QString path); void updateDirectories(QString path);
// signals
signals:
void dirsChanged();
}; };

View File

@ -58,6 +58,8 @@ MainWindow::MainWindow(QWidget *parent)
// setup dropdown // setup dropdown
setupAssetLibrary(); setupAssetLibrary();
connect(SettingsManager::getInstance(), &SettingsManager::dirsChanged, this, &MainWindow::setupAssetLibrary);
printMessage("MeshViewer by Anakin", 0); printMessage("MeshViewer by Anakin", 0);
} }
@ -167,29 +169,17 @@ void MainWindow::setupWidgets()
m_output->raise(); m_output->raise();
} }
void MainWindow::setupAssetLibrary()
{
// 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::updateAssetTree(QString path) void MainWindow::updateAssetTree(QString path)
{ {
ui->fileListWidget->clear(); ui->fileListWidget->clear();
m_Paths.clear(); m_Paths.clear();
QDirIterator itterator(path, QStringList() << "*.msh" << "*.MSH" << "*.mesh" << "*.MESH", QDirIterator itterator(path, QStringList() << "*.msh" << "*.MSH" << "*.mesh" << "*.MESH",
QDir::Files, QDirIterator::Subdirectories); QDir::Files, QDirIterator::Subdirectories);
while (itterator.hasNext()) { while (itterator.hasNext()) {
ui->fileListWidget->insertItem(0, new QListWidgetItem(itterator.fileName())); ui->fileListWidget->insertItem(0, new QListWidgetItem(itterator.fileName()));
m_Paths.prepend(itterator.fileInfo().absoluteFilePath()); m_Paths.prepend(itterator.fileInfo().absoluteFilePath());
itterator.next(); itterator.next();
} }
} }
@ -242,6 +232,21 @@ void MainWindow::resizeEvent(QResizeEvent * e)
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// slots // slots
void MainWindow::setupAssetLibrary()
{
// get all directories and put them in the dropdown.
while (ui->dirDropDownList->count() != 0)
ui->dirDropDownList->removeItem(0);
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::on_fileListWidget_doubleClicked(const QModelIndex &index) void MainWindow::on_fileListWidget_doubleClicked(const QModelIndex &index)
{ {
int slotVal = index.row(); int slotVal = index.row();

View File

@ -238,5 +238,6 @@ void SettingsManager::updateDirectories(QString path)
m_listOfDirs.removeAll(path); m_listOfDirs.removeAll(path);
else else
m_listOfDirs.append(path); m_listOfDirs.append(path);
}
emit dirsChanged();
}