CSV export
This commit is contained in:
parent
22e3b06fdd
commit
fd49ba9a44
@ -225,7 +225,6 @@ QStringList Database::getFitsKeywords()
|
||||
return keywords;
|
||||
}
|
||||
|
||||
|
||||
bool Database::indexDir2(const QDir &dir, QProgressDialog *progress)
|
||||
{
|
||||
QFileInfoList files = dir.entryInfoList(nameFilters, QDir::Files);
|
||||
|
@ -362,3 +362,38 @@ void DataBaseView::applyFilter()
|
||||
}
|
||||
m_model->setFilter(keys, values, limits);
|
||||
}
|
||||
|
||||
bool DataBaseView::exportCSV(const QString &path)
|
||||
{
|
||||
QFile csv(path);
|
||||
if(!csv.open(QIODevice::WriteOnly | QIODevice::Text))
|
||||
return false;
|
||||
|
||||
QSqlQuery sql = m_model->query();
|
||||
int colCount = m_model->columnCount();
|
||||
QStringList header;
|
||||
for(int i=0; i<colCount; i++)
|
||||
header.append(m_model->headerData(i, Qt::Horizontal).toString());
|
||||
|
||||
csv.write(header.join(",").toUtf8());
|
||||
csv.write("\n");
|
||||
|
||||
while(sql.next())
|
||||
{
|
||||
QStringList columns;
|
||||
for(int i=0; i<colCount; i++)
|
||||
{
|
||||
QString val = sql.value(i).toString();
|
||||
val.replace("\"", "\"\"");
|
||||
if(val.contains('"') || val.contains(','))
|
||||
{
|
||||
val.prepend('"');
|
||||
val.append('"');
|
||||
}
|
||||
columns.append(val);
|
||||
}
|
||||
csv.write(columns.join(",").toUtf8());
|
||||
csv.write("\n");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -71,6 +71,7 @@ public slots:
|
||||
void loadDatabase();
|
||||
void itemActivated(const QModelIndex &index);
|
||||
void applyFilter();
|
||||
bool exportCSV(const QString &path);
|
||||
signals:
|
||||
void loadFile(QString file);
|
||||
};
|
||||
|
@ -137,6 +137,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
|
||||
fileMenu->addSeparator();
|
||||
fileMenu->addAction(tr("Index directory"), this, SLOT(indexDir()));
|
||||
fileMenu->addAction(tr("Reindex files"), this, SLOT(reindex()));
|
||||
fileMenu->addAction(tr("Export database to CSV"), this, &MainWindow::exportCSV);
|
||||
fileMenu->addSeparator();
|
||||
QAction *liveModeAction = fileMenu->addAction(tr("Live mode"), this, SLOT(liveMode(bool)));
|
||||
liveModeAction->setCheckable(true);
|
||||
@ -615,6 +616,19 @@ void MainWindow::showSettingsDialog()
|
||||
settingsDialog.exec();
|
||||
}
|
||||
|
||||
void MainWindow::exportCSV()
|
||||
{
|
||||
QStringList documentDir = QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation);
|
||||
if(documentDir.empty())documentDir.append("");
|
||||
QString file = QFileDialog::getSaveFileName(this,
|
||||
tr("Save as"),
|
||||
documentDir.first(),
|
||||
tr("CSV file (*.csv)"));
|
||||
|
||||
if(!file.isEmpty())
|
||||
m_databaseView->exportCSV(file);
|
||||
}
|
||||
|
||||
void MainWindow::updateWindowTitle()
|
||||
{
|
||||
ImagePtr ptr = m_ringList->currentImage();
|
||||
|
@ -66,6 +66,7 @@ protected slots:
|
||||
void starFinder(bool findStars);
|
||||
void showMarkFilesDialog();
|
||||
void showSettingsDialog();
|
||||
void exportCSV();
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user