Deffered SQL query when database is visible
This commit is contained in:
@@ -157,8 +157,19 @@ 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;
|
||||||
@@ -427,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;
|
||||||
@@ -455,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