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