Skip to content
Snippets Groups Projects
Commit f72925d1 authored by Yann Boucher's avatar Yann Boucher
Browse files

Added support for automatically detecting new patterns in the pattern library directory

parent aa30c61e
Branches
No related tags found
No related merge requests found
Pipeline #78277 passed
......@@ -8,6 +8,7 @@
#include <QDir>
#include <QTreeWidgetItem>
#include <QFileSystemWatcher>
#include "structure.hpp"
......@@ -37,6 +38,7 @@ private slots:
private:
Ui::StructureLibraryView *ui;
QFileSystemWatcher m_watcher;
};
#endif // STRUCTURELIBRARYVIEW_HPP
......@@ -20,6 +20,10 @@ StructureLibraryView::StructureLibraryView(QWidget *parent) :
connect(ui->tree, &QTreeWidget::itemClicked, this, &StructureLibraryView::update_info);
connect(ui->button_copy, &QPushButton::pressed, this, &StructureLibraryView::copy_button_clicked);
connect(&m_watcher, &QFileSystemWatcher::directoryChanged, [this](const QString&)
{
load_structures();
});
}
StructureLibraryView::~StructureLibraryView()
......@@ -29,8 +33,12 @@ StructureLibraryView::~StructureLibraryView()
void StructureLibraryView::load_structures()
{
// clear the previously watched directories
m_watcher.removePaths(m_watcher.directories());
QTreeWidgetItem* pattern_list = add_directory_contents(QDir("patterns/"));
pattern_list->setText(0, "Patterns");
ui->tree->clear();
ui->tree->addTopLevelItem(pattern_list);
pattern_list->setExpanded(true);
}
......@@ -67,6 +75,9 @@ QTreeWidgetItem *StructureLibraryView::add_directory_contents(const QDir &dir)
root->addChild(child);
}
// register this directory for filesystem watching
m_watcher.addPath(dir.absolutePath());
return root;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment