Add recursive directory
This commit is contained in:
+21
-5
@@ -1,4 +1,5 @@
|
|||||||
#include "imageringlist.h"
|
#include "imageringlist.h"
|
||||||
|
#include <functional>
|
||||||
#include <QThreadPool>
|
#include <QThreadPool>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
@@ -124,21 +125,36 @@ ImageRingList::~ImageRingList()
|
|||||||
m_thumbPool->waitForDone();
|
m_thumbPool->waitForDone();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ImageRingList::setDir(const QString path, const QString ¤tFile)
|
bool ImageRingList::setDir(const QString path, const QString ¤tFile, bool recursive)
|
||||||
{
|
{
|
||||||
QDir dir(path);
|
QDir dir(path);
|
||||||
|
|
||||||
if(dir.exists())
|
if(dir.exists())
|
||||||
{
|
{
|
||||||
|
QStringList absolutePaths;
|
||||||
|
std::function<void(const QString&)> scanDir = [&](const QString &path)
|
||||||
|
{
|
||||||
|
QDir dir(path);
|
||||||
QDir::SortFlags sortFlags = m_liveMode ? QDir::Time : m_sort | QDir::IgnoreCase;
|
QDir::SortFlags sortFlags = m_liveMode ? QDir::Time : m_sort | QDir::IgnoreCase;
|
||||||
if(m_reversed)sortFlags |= QDir::Reversed;
|
if(m_reversed)sortFlags |= QDir::Reversed;
|
||||||
|
|
||||||
|
if(recursive)
|
||||||
|
{
|
||||||
|
QStringList dirs = dir.entryList(QDir::Readable | QDir::Dirs | QDir::NoDotAndDotDot, sortFlags);
|
||||||
|
for(const QString &subdir : dirs)
|
||||||
|
scanDir(dir.absoluteFilePath(subdir));
|
||||||
|
}
|
||||||
|
|
||||||
QStringList list = dir.entryList(m_nameFilter, QDir::Files | QDir::Readable, sortFlags);
|
QStringList list = dir.entryList(m_nameFilter, QDir::Files | QDir::Readable, sortFlags);
|
||||||
QStringList absolutePaths;
|
for(const QString &file : list)
|
||||||
foreach(const QString &file, list)
|
|
||||||
{
|
{
|
||||||
absolutePaths.append(dir.absoluteFilePath(file));
|
absolutePaths.append(dir.absoluteFilePath(file));
|
||||||
}
|
}
|
||||||
setFiles(absolutePaths, m_liveMode ? list.first() : currentFile);
|
};
|
||||||
|
|
||||||
|
scanDir(path);
|
||||||
|
qDebug() << absolutePaths.size();
|
||||||
|
setFiles(absolutePaths, m_liveMode ? absolutePaths.first() : currentFile);
|
||||||
|
|
||||||
m_fileSystemWatcher.removePaths(m_fileSystemWatcher.directories());
|
m_fileSystemWatcher.removePaths(m_fileSystemWatcher.directories());
|
||||||
m_fileSystemWatcher.addPath(path);
|
m_fileSystemWatcher.addPath(path);
|
||||||
@@ -151,7 +167,7 @@ void ImageRingList::setFile(const QString &file)
|
|||||||
{
|
{
|
||||||
QFileInfo info(file);
|
QFileInfo info(file);
|
||||||
if(info.isDir())
|
if(info.isDir())
|
||||||
setDir(file);
|
setDir(file, QString(), true);
|
||||||
else
|
else
|
||||||
setDir(info.absolutePath(), file);
|
setDir(info.absolutePath(), file);
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -69,7 +69,7 @@ class ImageRingList : public QAbstractItemModel
|
|||||||
public:
|
public:
|
||||||
explicit ImageRingList(Database *database, const QStringList &nameFilter, QObject *parent = 0);
|
explicit ImageRingList(Database *database, const QStringList &nameFilter, QObject *parent = 0);
|
||||||
~ImageRingList() override;
|
~ImageRingList() override;
|
||||||
bool setDir(const QString path, const QString ¤tFile = QString());
|
bool setDir(const QString path, const QString ¤tFile = QString(), bool recursive = false);
|
||||||
void setFile(const QString &file);
|
void setFile(const QString &file);
|
||||||
ImagePtr currentImage();
|
ImagePtr currentImage();
|
||||||
void setLiveMode(bool live);
|
void setLiveMode(bool live);
|
||||||
|
|||||||
@@ -211,7 +211,7 @@ void ImageWidget::allocateThumbnails(const QStringList &paths)
|
|||||||
m_thumbnailTexture->create();
|
m_thumbnailTexture->create();
|
||||||
m_thumbnailTexture->setFormat(QOpenGLTexture::RGB16_UNorm);
|
m_thumbnailTexture->setFormat(QOpenGLTexture::RGB16_UNorm);
|
||||||
m_thumbnailTexture->setSize(THUMB_SIZE, THUMB_SIZE);
|
m_thumbnailTexture->setSize(THUMB_SIZE, THUMB_SIZE);
|
||||||
m_thumbnailTexture->setLayers(paths.size());
|
m_thumbnailTexture->setLayers(std::min((int)paths.size(), m_maxArrayLayers));
|
||||||
m_thumbnailTexture->allocateStorage();
|
m_thumbnailTexture->allocateStorage();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -301,6 +301,9 @@ QImage ImageWidget::renderToImage()
|
|||||||
|
|
||||||
void ImageWidget::thumbnailLoaded(const Image *image)
|
void ImageWidget::thumbnailLoaded(const Image *image)
|
||||||
{
|
{
|
||||||
|
if(image->number() >= m_maxArrayLayers)
|
||||||
|
return;
|
||||||
|
|
||||||
makeCurrent();
|
makeCurrent();
|
||||||
const RawImage *raw = image->thumbnail();
|
const RawImage *raw = image->thumbnail();
|
||||||
if(!raw || !raw->valid())return;
|
if(!raw || !raw->valid())return;
|
||||||
|
|||||||
@@ -144,6 +144,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
|
|||||||
|
|
||||||
QMenu *fileMenu = new QMenu(tr("File"), this);
|
QMenu *fileMenu = new QMenu(tr("File"), this);
|
||||||
fileMenu->addAction(tr("Open"), this, SLOT(loadFile()), QKeySequence::Open);
|
fileMenu->addAction(tr("Open"), this, SLOT(loadFile()), QKeySequence::Open);
|
||||||
|
fileMenu->addAction(tr("Open directory recursively"), this, &MainWindow::loadDir);
|
||||||
fileMenu->addAction(tr("Save as"), this, SLOT(saveAs()), QKeySequence::Save);
|
fileMenu->addAction(tr("Save as"), this, SLOT(saveAs()), QKeySequence::Save);
|
||||||
fileMenu->addSeparator();
|
fileMenu->addSeparator();
|
||||||
fileMenu->addAction(tr("Copy marked files"), this, SLOT(copyMarked()), Qt::Key_F5);
|
fileMenu->addAction(tr("Copy marked files"), this, SLOT(copyMarked()), Qt::Key_F5);
|
||||||
@@ -487,6 +488,20 @@ void MainWindow::loadFile(int row)
|
|||||||
m_ringList->loadFile(row);
|
m_ringList->loadFile(row);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::loadDir()
|
||||||
|
{
|
||||||
|
QString dir = QFileDialog::getExistingDirectory(this,
|
||||||
|
tr("Open directory recursively"),
|
||||||
|
_lastDir);
|
||||||
|
if(!dir.isEmpty())
|
||||||
|
{
|
||||||
|
_lastDir = dir;
|
||||||
|
m_ringList->setDir(dir, QString(), true);
|
||||||
|
QSettings settings;
|
||||||
|
settings.setValue("mainwindow/lastdir", _lastDir);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::indexDir()
|
void MainWindow::indexDir()
|
||||||
{
|
{
|
||||||
QString dir = QFileDialog::getExistingDirectory(this, tr("Index directory"), _lastDir, QFileDialog::ShowDirsOnly);
|
QString dir = QFileDialog::getExistingDirectory(this, tr("Index directory"), _lastDir, QFileDialog::ShowDirsOnly);
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ protected slots:
|
|||||||
void loadFile();
|
void loadFile();
|
||||||
void loadFile(const QString &path);
|
void loadFile(const QString &path);
|
||||||
void loadFile(int row);
|
void loadFile(int row);
|
||||||
|
void loadDir();
|
||||||
void indexDir();
|
void indexDir();
|
||||||
void indexDir(const QString &dir);
|
void indexDir(const QString &dir);
|
||||||
void reindex();
|
void reindex();
|
||||||
|
|||||||
Reference in New Issue
Block a user