Add search by RA and DEC point

This commit is contained in:
2022-06-14 22:46:40 +02:00
parent 08e70cdb52
commit 3e94aa0eda
+36 -4
View File
@@ -8,10 +8,34 @@
#include <QDebug>
#include <QMenu>
#include <QContextMenuEvent>
#include <QRegExp>
#include <iostream>
const QStringList DEFAULT_COLUMNS = {"EXPTIME", "OBJECT", "RA", "DEC"};
double RA(const QString &ra)
{
QRegularExpression reg("(\\d+)\\s*(\\d+)?\\s*(\\d+)?");
QRegularExpressionMatch match = reg.match(ra);
double h = match.captured(1).toDouble();
double m = match.captured(2).toDouble();
double s = match.captured(3).toDouble();
qDebug() << match.capturedTexts() << h << m << s;
return h*15 + m*0.25 + s*15/3600;
}
double DEC(const QString &dec)
{
QRegularExpression reg("([\\+\\-])?(\\d+)\\s*(\\d+)?\\s*(\\d+)?");
QRegularExpressionMatch match = reg.match(dec);
double sign = match.captured(1) == "-" ? -1 : 1;
double d = match.captured(2).toDouble();
double m = match.captured(3).toDouble();
double s = match.captured(4).toDouble();
qDebug() << match.capturedTexts() << sign << d << m << s;
return sign * (d + m/60 + s/3600);
}
SelectColumnsDialog::SelectColumnsDialog(QWidget *parent) : QDialog(parent)
{
m_listWidget = new QListWidget(this);
@@ -130,12 +154,16 @@ void FITSFileModel::prepareQuery()
{
QString cols;
QString join;
QString where;
QStringList where;
QString sql = "SELECT f.file,";
for(int i=0; i<m_value.size(); i++)
{
if(m_key[i] == "file")
where = QString(" WHERE f.file LIKE '%1'").arg(m_value[i]);
where.append(QString(" f.file LIKE '%1' ").arg(m_value[i]));
else if(m_key[i] == "RA pos")
where.append(QString(" %1 BETWEEN f.minRa AND f.maxRa ").arg(RA(m_value[i])));
else if(m_key[i] == "DEC pos")
where.append(QString(" %1 BETWEEN f.minDec AND f.maxDec ").arg(DEC(m_value[i])));
else
join += QString(" JOIN fits_headers AS s%1 ON f.id=s%1.id_file AND s%1.key='%2' AND s%1.value LIKE '%3'").arg(i).arg(m_key[i]).arg(m_value[i]);
}
@@ -150,7 +178,7 @@ void FITSFileModel::prepareQuery()
sql += cols;
sql += " FROM fits_files AS f";
sql += join;
sql += where;
if(!where.isEmpty())sql += " WHERE " + where.join("AND");
sql += " GROUP BY f.id" + m_sort;
setQuery(sql);
setHeaderData(0, Qt::Horizontal, tr("File name"));
@@ -232,11 +260,15 @@ DataBaseView::DataBaseView(Database *database, QWidget *parent) : QWidget(parent
m_model->filesUnmarked(indexes);
});
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]->addItems(m_database->getFitsKeywords());
m_filterKeyword[i]->addItem("RA pos");
m_filterKeyword[i]->addItem("DEC pos");
m_filterKeyword[i]->addItems(fitsKeywords);
m_search[i] = new QLineEdit(this);
m_search[i]->setPlaceholderText(tr("Text to search, you can % as wildcard"));
connect(m_search[i], &QLineEdit::returnPressed, this, &DataBaseView::applyFilter);