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

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

View File

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