Add progress bar for indexing
This commit is contained in:
+22
-6
@@ -108,11 +108,24 @@ bool Database::checkError()
|
||||
}
|
||||
}
|
||||
|
||||
void Database::indexDir(const QDir &dir)
|
||||
static QStringList nameFilters = {"*.fit", "*.fits"};
|
||||
|
||||
static int countFiles(const QDir &dir, int count = 0)
|
||||
{
|
||||
//m_database.exec("DROP TABLE fits_files");
|
||||
count += dir.entryList(nameFilters, QDir::Files).size();
|
||||
QStringList dirs = dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
|
||||
for(const QString &d : dirs)
|
||||
count += countFiles(dir.filePath(d));
|
||||
return count;
|
||||
}
|
||||
|
||||
void Database::indexDir(const QDir &dir, QProgressDialog *progress)
|
||||
{
|
||||
m_progress = 0;
|
||||
int count = countFiles(dir);
|
||||
progress->setMaximum(count);
|
||||
m_database.transaction();
|
||||
if(indexDir2(dir))
|
||||
if(indexDir2(dir, progress))
|
||||
m_database.commit();
|
||||
else
|
||||
m_database.rollback();
|
||||
@@ -129,19 +142,22 @@ QStringList Database::getFitsKeywords()
|
||||
return keywords;
|
||||
}
|
||||
|
||||
bool Database::indexDir2(const QDir &dir)
|
||||
|
||||
bool Database::indexDir2(const QDir &dir, QProgressDialog *progress)
|
||||
{
|
||||
static QStringList nameFilters = {"*.fit", "*.fits"};
|
||||
QFileInfoList files = dir.entryInfoList(nameFilters, QDir::Files);
|
||||
QStringList dirs = dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
|
||||
|
||||
for(const QString &d : dirs)
|
||||
{
|
||||
if(!indexDir2(dir.filePath(d)))
|
||||
if(!indexDir2(dir.filePath(d), progress))
|
||||
return false;
|
||||
}
|
||||
ImageInfoData info;
|
||||
for(const QFileInfo &file : files)
|
||||
{
|
||||
progress->setValue(m_progress++);
|
||||
if(progress->wasCanceled())return false;
|
||||
QString filePath = file.absoluteFilePath();
|
||||
QString mtime = file.fileTime(QFileDevice::FileModificationTime).toString(Qt::ISODate);
|
||||
m_checkFile.bindValue(0, filePath);
|
||||
|
||||
+5
-2
@@ -5,6 +5,7 @@
|
||||
#include <QSqlDatabase>
|
||||
#include <QSqlQuery>
|
||||
#include <QDir>
|
||||
#include <QProgressDialog>
|
||||
|
||||
class Database : public QObject
|
||||
{
|
||||
@@ -19,6 +20,8 @@ class Database : public QObject
|
||||
QSqlQuery m_checkFile;
|
||||
QSqlQuery m_headerKeywords;
|
||||
QSqlQuery m_deleteFile;
|
||||
|
||||
int m_progress;
|
||||
public:
|
||||
explicit Database(QObject *parent = 0);
|
||||
bool init();
|
||||
@@ -27,10 +30,10 @@ public:
|
||||
bool isMarked(const QString &filename);
|
||||
QStringList getMarkedFiles();
|
||||
|
||||
void indexDir(const QDir &dir);
|
||||
void indexDir(const QDir &dir, QProgressDialog *progress);
|
||||
QStringList getFitsKeywords();
|
||||
protected:
|
||||
bool indexDir2(const QDir &dir);
|
||||
bool indexDir2(const QDir &dir, QProgressDialog *progress);
|
||||
bool checkError();
|
||||
};
|
||||
|
||||
|
||||
+7
-1
@@ -53,6 +53,7 @@ DataBaseView::DataBaseView(Database *database, QWidget *parent) : QWidget(parent
|
||||
m_tableView = new QTableView(this);
|
||||
m_tableView->verticalHeader()->setDefaultSectionSize(1);
|
||||
layout->addWidget(m_tableView);
|
||||
connect(m_tableView, &QTableView::activated, this, &DataBaseView::itemActivated);
|
||||
|
||||
m_model = new QSqlQueryModel(this);
|
||||
|
||||
@@ -60,7 +61,7 @@ DataBaseView::DataBaseView(Database *database, QWidget *parent) : QWidget(parent
|
||||
m_tableView->setModel(m_model);
|
||||
m_tableView->horizontalHeader()->restoreState(settings.value("databaseview/header").toByteArray());
|
||||
|
||||
QHBoxLayout *hlayout = new QHBoxLayout(this);
|
||||
QHBoxLayout *hlayout = new QHBoxLayout();
|
||||
layout->addLayout(hlayout);
|
||||
|
||||
QPushButton *selectColumnsButton = new QPushButton(tr("Select columns"), this);
|
||||
@@ -98,6 +99,11 @@ void DataBaseView::loadDatabase()
|
||||
prepareQuery(settings.value("databaseview/selectedColumns", DEFAULT_COLUMNS).toStringList());
|
||||
}
|
||||
|
||||
void DataBaseView::itemActivated(const QModelIndex &index)
|
||||
{
|
||||
emit loadFile(m_model->data(index.siblingAtColumn(0)).toString());
|
||||
}
|
||||
|
||||
void DataBaseView::prepareQuery(const QStringList &columns)
|
||||
{
|
||||
QString sql = "SELECT file,";
|
||||
|
||||
@@ -30,8 +30,11 @@ public:
|
||||
public slots:
|
||||
void selectColumns();
|
||||
void loadDatabase();
|
||||
void itemActivated(const QModelIndex &index);
|
||||
protected:
|
||||
void prepareQuery(const QStringList &columns);
|
||||
signals:
|
||||
void loadFile(QString file);
|
||||
};
|
||||
|
||||
#endif // DATABASEVIEW_H
|
||||
|
||||
+7
-1
@@ -56,6 +56,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
|
||||
QMessageBox::critical(this, tr("Can't open DB"), tr("Can't open SQLITE database"));
|
||||
|
||||
m_databaseView = new DataBaseView(m_database, this);
|
||||
connect(m_databaseView, SIGNAL(loadFile(QString)), this, SLOT(loadFile(QString)));
|
||||
|
||||
QDockWidget *stretchDock = new QDockWidget(tr("Stretch"), this);
|
||||
stretchDock->setWidget(m_stretchPanel);
|
||||
@@ -84,6 +85,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
|
||||
fileMenu->addAction(tr("Open"), this, SLOT(loadFile()), QKeySequence("Ctrl+O"));
|
||||
fileMenu->addAction(tr("Copy marked files"), this, SLOT(copyMarked()));
|
||||
fileMenu->addAction(tr("Save as"), this, SLOT(saveAs()), QKeySequence("Ctrl+S"));
|
||||
fileMenu->addAction(tr("Index directory"), this, SLOT(indexDir()));
|
||||
QAction *liveModeAction = fileMenu->addAction(tr("Live mode"), this, SLOT(liveMode(bool)));
|
||||
liveModeAction->setCheckable(true);
|
||||
fileMenu->addAction(tr("Exit"), this, SLOT(close()));
|
||||
@@ -280,7 +282,11 @@ void MainWindow::indexDir()
|
||||
{
|
||||
QString dir = QFileDialog::getExistingDirectory(this, tr("Index directory"), _lastDir);
|
||||
if(!dir.isEmpty())
|
||||
m_database->indexDir(dir);
|
||||
{
|
||||
QProgressDialog progressDialog(tr("Indexing FITS files"), tr("Cancel"), 0, 1, this);
|
||||
progressDialog.setModal(true);
|
||||
m_database->indexDir(dir, &progressDialog);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::saveAs()
|
||||
|
||||
@@ -44,6 +44,7 @@ StretchPanel::StretchPanel(QWidget *parent) : QWidget(parent)
|
||||
QToolButton *superPixelButton = new QToolButton(this);
|
||||
superPixelButton->setIcon(QIcon(":/bayer.svg"));
|
||||
superPixelButton->setCheckable(true);
|
||||
superPixelButton->setToolTip(tr("Superpixel CFA draw 2x2 pixel as one"));
|
||||
connect(superPixelButton, SIGNAL(toggled(bool)), this, SIGNAL(superPixel(bool)));
|
||||
|
||||
layout->addWidget(autoStretchButton);
|
||||
|
||||
Reference in New Issue
Block a user