Export query results as JSON

The corresponding menu entry for exporting the query results to JSON was missing
although it was straight forward to add it with the same scheme as for CSV.

Related to issue #2607
This commit is contained in:
mgrojo
2021-03-05 23:57:34 +01:00
parent 36c5b1baf4
commit e225dc1e42
6 changed files with 36 additions and 0 deletions

View File

@@ -266,6 +266,7 @@ void MainWindow::init()
popupSaveSqlResultsMenu = new QMenu(this);
popupSaveSqlResultsMenu->addAction(ui->actionSqlResultsExportCsv);
popupSaveSqlResultsMenu->addAction(ui->actionSqlResultsExportJson);
popupSaveSqlResultsMenu->addAction(ui->actionSqlResultsSaveAsView);
ui->actionSqlResultsSave->setMenu(popupSaveSqlResultsMenu);
qobject_cast<QToolButton*>(ui->toolbarSql->widgetForAction(ui->actionSqlResultsSave))->setPopupMode(QToolButton::InstantPopup);
@@ -2212,6 +2213,11 @@ void MainWindow::saveSqlResultsAsCsv()
qobject_cast<SqlExecutionArea*>(ui->tabSqlAreas->currentWidget())->saveAsCsv();
}
void MainWindow::saveSqlResultsAsJson()
{
qobject_cast<SqlExecutionArea*>(ui->tabSqlAreas->currentWidget())->saveAsJson();
}
void MainWindow::saveSqlResultsAsView()
{
saveAsView(qobject_cast<SqlExecutionArea*>(ui->tabSqlAreas->currentWidget())->getModel()->query());

View File

@@ -198,6 +198,7 @@ private slots:
void saveSqlFile();
void saveSqlFileAs();
void saveSqlResultsAsCsv();
void saveSqlResultsAsJson();
void saveSqlResultsAsView();
void loadExtension();
void checkNewVersion(const QString& versionstring, const QString& url);

View File

@@ -1916,6 +1916,11 @@ You can drag SQL statements from the Schema column and drop them into the SQL ed
<string>Export to &amp;CSV</string>
</property>
</action>
<action name="actionSqlResultsExportJson">
<property name="text">
<string>Export to &amp;JSON</string>
</property>
</action>
<action name="actionSqlResultsSaveAsView">
<property name="text">
<string>Save as &amp;view</string>
@@ -3134,6 +3139,22 @@ You can drag SQL statements from the Schema column and drop them into the SQL ed
</hint>
</hints>
</connection>
<connection>
<sender>actionSqlResultsExportJson</sender>
<signal>triggered()</signal>
<receiver>MainWindow</receiver>
<slot>saveSqlResultsAsJson()</slot>
<hints>
<hint type="sourcelabel">
<x>-1</x>
<y>-1</y>
</hint>
<hint type="destinationlabel">
<x>518</x>
<y>314</y>
</hint>
</hints>
</connection>
<connection>
<sender>actionSqlResultsSaveAsView</sender>
<signal>triggered()</signal>

View File

@@ -131,6 +131,12 @@ void SqlExecutionArea::saveAsCsv()
dialog.exec();
}
void SqlExecutionArea::saveAsJson()
{
ExportDataDialog dialog(db, ExportDataDialog::ExportFormatJson, this, model->query());
dialog.exec();
}
void SqlExecutionArea::reloadSettings()
{
// Reload editor and table settings

View File

@@ -46,6 +46,7 @@ public:
public slots:
void finishExecution(const QString& result, const bool ok);
void saveAsCsv();
void saveAsJson();
void reloadSettings();
void fetchedData();
void setFindFrameVisibility(bool show);

View File

@@ -291,6 +291,7 @@
<connections/>
<slots>
<slot>saveAsCsv()</slot>
<slot>saveAsJson()</slot>
<slot>saveAsView()</slot>
</slots>
</ui>