CSV export
This commit is contained in:
parent
22e3b06fdd
commit
fd49ba9a44
@ -225,7 +225,6 @@ QStringList Database::getFitsKeywords()
|
|||||||
return keywords;
|
return keywords;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Database::indexDir2(const QDir &dir, QProgressDialog *progress)
|
bool Database::indexDir2(const QDir &dir, QProgressDialog *progress)
|
||||||
{
|
{
|
||||||
QFileInfoList files = dir.entryInfoList(nameFilters, QDir::Files);
|
QFileInfoList files = dir.entryInfoList(nameFilters, QDir::Files);
|
||||||
|
@ -362,3 +362,38 @@ void DataBaseView::applyFilter()
|
|||||||
}
|
}
|
||||||
m_model->setFilter(keys, values, limits);
|
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 loadDatabase();
|
||||||
void itemActivated(const QModelIndex &index);
|
void itemActivated(const QModelIndex &index);
|
||||||
void applyFilter();
|
void applyFilter();
|
||||||
|
bool exportCSV(const QString &path);
|
||||||
signals:
|
signals:
|
||||||
void loadFile(QString file);
|
void loadFile(QString file);
|
||||||
};
|
};
|
||||||
|
@ -137,6 +137,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
|
|||||||
fileMenu->addSeparator();
|
fileMenu->addSeparator();
|
||||||
fileMenu->addAction(tr("Index directory"), this, SLOT(indexDir()));
|
fileMenu->addAction(tr("Index directory"), this, SLOT(indexDir()));
|
||||||
fileMenu->addAction(tr("Reindex files"), this, SLOT(reindex()));
|
fileMenu->addAction(tr("Reindex files"), this, SLOT(reindex()));
|
||||||
|
fileMenu->addAction(tr("Export database to CSV"), this, &MainWindow::exportCSV);
|
||||||
fileMenu->addSeparator();
|
fileMenu->addSeparator();
|
||||||
QAction *liveModeAction = fileMenu->addAction(tr("Live mode"), this, SLOT(liveMode(bool)));
|
QAction *liveModeAction = fileMenu->addAction(tr("Live mode"), this, SLOT(liveMode(bool)));
|
||||||
liveModeAction->setCheckable(true);
|
liveModeAction->setCheckable(true);
|
||||||
@ -615,6 +616,19 @@ void MainWindow::showSettingsDialog()
|
|||||||
settingsDialog.exec();
|
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()
|
void MainWindow::updateWindowTitle()
|
||||||
{
|
{
|
||||||
ImagePtr ptr = m_ringList->currentImage();
|
ImagePtr ptr = m_ringList->currentImage();
|
||||||
|
@ -66,6 +66,7 @@ protected slots:
|
|||||||
void starFinder(bool findStars);
|
void starFinder(bool findStars);
|
||||||
void showMarkFilesDialog();
|
void showMarkFilesDialog();
|
||||||
void showSettingsDialog();
|
void showSettingsDialog();
|
||||||
|
void exportCSV();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MAINWINDOW_H
|
#endif // MAINWINDOW_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user