Refres database table when indexing is done

This commit is contained in:
Dušan Poizl 2022-06-24 18:30:28 +02:00
parent 1d65eda490
commit 1bd48e8fb4
3 changed files with 28 additions and 6 deletions

@ -174,9 +174,14 @@ void Database::indexDir(const QDir &dir, QProgressDialog *progress)
QSqlDatabase database = QSqlDatabase::database();
database.transaction();
if(indexDir2(dir, progress))
{
database.commit();
emit databaseChanged();
}
else
{
database.rollback();
}
}
void Database::reindex(QProgressDialog *progress)

@ -41,6 +41,8 @@ protected:
bool indexFile(const QFileInfo &file);
bool checkError(QSqlQuery &query);
int checkVersion();
signals:
void databaseChanged();
};
#endif // DATABASE_H

@ -266,16 +266,23 @@ DataBaseView::DataBaseView(Database *database, QWidget *parent) : QWidget(parent
m_model->filesUnmarked(indexes);
});
auto addFilterItems = [](QComboBox *combobox, const QStringList &fitsKeywords)
{
combobox->clear();
combobox->addItem("file");
combobox->addItem("RA pos");
combobox->addItem("DEC pos");
combobox->addItem("RA range");
combobox->addItem("DEC range");
combobox->addItems(fitsKeywords);
};
QStringList fitsKeywords = m_database->getFitsKeywords();
for(int i=0; i<3; i++)
{
m_filterKeyword[i] = new QComboBox(this);
m_filterKeyword[i]->addItem("file");
m_filterKeyword[i]->addItem("RA pos");
m_filterKeyword[i]->addItem("DEC pos");
m_filterKeyword[i]->addItem("RA range");
m_filterKeyword[i]->addItem("DEC range");
m_filterKeyword[i]->addItems(fitsKeywords);
addFilterItems(m_filterKeyword[i], fitsKeywords);
m_search[i] = new QLineEdit(this);
m_search[i]->setPlaceholderText(tr("Text to search, you can % as wildcard"));
@ -297,6 +304,14 @@ DataBaseView::DataBaseView(Database *database, QWidget *parent) : QWidget(parent
QPushButton *filterButton = new QPushButton(tr("Filter"), this);
connect(filterButton, SIGNAL(pressed()), this, SLOT(applyFilter()));
hlayout->addWidget(filterButton);
connect(m_database, &Database::databaseChanged, [this, &addFilterItems](){
QStringList fitsKeywords = m_database->getFitsKeywords();
for(int i=0; i<3; i++)
addFilterItems(m_filterKeyword[i], fitsKeywords);
applyFilter();
});
}
DataBaseView::~DataBaseView()