Compare commits
2 Commits
2b56af27fe
...
305c1d1f55
| Author | SHA1 | Date | |
|---|---|---|---|
| 305c1d1f55 | |||
| 95808b094d |
+27
-7
@@ -157,13 +157,25 @@ void FITSFileModel::filesUnmarked(const QModelIndexList &indexes)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FITSFileModel::load()
|
||||||
|
{
|
||||||
|
if(!m_loaded)
|
||||||
|
{
|
||||||
|
m_loaded = true;
|
||||||
|
prepareQuery();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void FITSFileModel::prepareQuery()
|
void FITSFileModel::prepareQuery()
|
||||||
{
|
{
|
||||||
|
if(!m_loaded)return;
|
||||||
|
|
||||||
QString cols;
|
QString cols;
|
||||||
QString join;
|
QString join;
|
||||||
QStringList where;
|
QStringList where;
|
||||||
QString sql = m_columns.size() ? "SELECT f.file," : "SELECT f.file";
|
QString sql = m_columns.size() ? "SELECT f.file," : "SELECT f.file";
|
||||||
QVariantList bindValues;
|
QVariantList bindValues;
|
||||||
|
QVariantList bindValuesJoin;
|
||||||
for(int i=0; i<m_value.size(); i++)
|
for(int i=0; i<m_value.size(); i++)
|
||||||
{
|
{
|
||||||
if(m_key[i] == "file")
|
if(m_key[i] == "file")
|
||||||
@@ -195,9 +207,9 @@ void FITSFileModel::prepareQuery()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
join += QString(" JOIN fits_headers AS s%1 ON f.id=s%1.id_file AND s%1.key=? AND s%1.value LIKE ?").arg(i);
|
join += QString(" JOIN fits_headers AS s%1 ON f.id=s%1.id_file AND s%1.key=? AND s%1.value LIKE ? ").arg(i);
|
||||||
bindValues.append(m_key[i]);
|
bindValuesJoin.append(m_key[i]);
|
||||||
bindValues.append(m_value[i]);
|
bindValuesJoin.append(m_value[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int i=0;
|
int i=0;
|
||||||
@@ -205,7 +217,7 @@ void FITSFileModel::prepareQuery()
|
|||||||
{
|
{
|
||||||
cols += QString("GROUP_CONCAT(h%1.value) AS h%1_value,").arg(i);
|
cols += QString("GROUP_CONCAT(h%1.value) AS h%1_value,").arg(i);
|
||||||
join += QString(" LEFT JOIN fits_headers AS h%1 ON f.id=h%1.id_file AND h%1.key=?").arg(i);
|
join += QString(" LEFT JOIN fits_headers AS h%1 ON f.id=h%1.id_file AND h%1.key=?").arg(i);
|
||||||
bindValues.append(column);
|
bindValuesJoin.append(column);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
cols.chop(1);
|
cols.chop(1);
|
||||||
@@ -217,11 +229,13 @@ void FITSFileModel::prepareQuery()
|
|||||||
|
|
||||||
QSqlQuery query(m_database->db());
|
QSqlQuery query(m_database->db());
|
||||||
query.prepare(sql);
|
query.prepare(sql);
|
||||||
for(int i = 0; i < bindValues.size(); i++)
|
for(auto &val : bindValuesJoin)
|
||||||
query.bindValue(i, bindValues[i]);
|
query.addBindValue(val);
|
||||||
|
for(auto &val : bindValues)
|
||||||
|
query.addBindValue(val);
|
||||||
|
|
||||||
if(!query.exec())
|
if(!query.exec())
|
||||||
qWarning() << "Failed to exectute query" << query.lastQuery();
|
qWarning() << "Failed to exectute query" << query.lastQuery() << bindValuesJoin << bindValues;
|
||||||
setQuery(std::move(query));
|
setQuery(std::move(query));
|
||||||
|
|
||||||
setHeaderData(0, Qt::Horizontal, tr("File name"));
|
setHeaderData(0, Qt::Horizontal, tr("File name"));
|
||||||
@@ -424,6 +438,7 @@ bool DataBaseView::exportCSV(const QString &path)
|
|||||||
if(!csv.open(QIODevice::WriteOnly | QIODevice::Text))
|
if(!csv.open(QIODevice::WriteOnly | QIODevice::Text))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
m_model->load();
|
||||||
QSqlQuery sql(m_model->query().lastQuery());
|
QSqlQuery sql(m_model->query().lastQuery());
|
||||||
int colCount = m_model->columnCount();
|
int colCount = m_model->columnCount();
|
||||||
QStringList header;
|
QStringList header;
|
||||||
@@ -452,3 +467,8 @@ bool DataBaseView::exportCSV(const QString &path)
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DataBaseView::visible(bool visible)
|
||||||
|
{
|
||||||
|
if(visible)m_model->load();
|
||||||
|
}
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ class FITSFileModel : public QSqlQueryModel
|
|||||||
QStringList m_limit;
|
QStringList m_limit;
|
||||||
QSet<QString> m_markedFiles;
|
QSet<QString> m_markedFiles;
|
||||||
Database *m_database;
|
Database *m_database;
|
||||||
|
bool m_loaded = false;
|
||||||
public:
|
public:
|
||||||
explicit FITSFileModel(Database *database, QObject *parent = nullptr);
|
explicit FITSFileModel(Database *database, QObject *parent = nullptr);
|
||||||
void sort(int column, Qt::SortOrder order) override;
|
void sort(int column, Qt::SortOrder order) override;
|
||||||
@@ -38,6 +39,7 @@ public:
|
|||||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||||
void filesMarked(const QModelIndexList &indexes);
|
void filesMarked(const QModelIndexList &indexes);
|
||||||
void filesUnmarked(const QModelIndexList &indexes);
|
void filesUnmarked(const QModelIndexList &indexes);
|
||||||
|
void load();
|
||||||
protected:
|
protected:
|
||||||
void prepareQuery();
|
void prepareQuery();
|
||||||
};
|
};
|
||||||
@@ -74,6 +76,7 @@ public slots:
|
|||||||
void itemActivated(const QModelIndex &index);
|
void itemActivated(const QModelIndex &index);
|
||||||
void applyFilter();
|
void applyFilter();
|
||||||
bool exportCSV(const QString &path);
|
bool exportCSV(const QString &path);
|
||||||
|
void visible(bool visible);
|
||||||
signals:
|
signals:
|
||||||
void loadFile(QString file);
|
void loadFile(QString file);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user