mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-20 02:50:46 -06:00
Add basic JSON export feature
This adds some basic functionality for exporting JSON files by extending the CSV export dialog. There is still a bit of work required for fine-tuning the JSON export feature though. But a standard export of a table s working well already. See issue #688.
This commit is contained in:
@@ -9,27 +9,31 @@
|
||||
#include <QFile>
|
||||
#include <QTextStream>
|
||||
#include <QMessageBox>
|
||||
#if QT_VERSION_MAJOR >= 5
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonArray>
|
||||
#include <QJsonObject>
|
||||
#endif
|
||||
|
||||
ExportCsvDialog::ExportCsvDialog(DBBrowserDB* db, QWidget* parent, const QString& query, const QString& selection)
|
||||
ExportCsvDialog::ExportCsvDialog(DBBrowserDB* db, ExportFormats format, QWidget* parent, const QString& query, const QString& selection)
|
||||
: QDialog(parent),
|
||||
ui(new Ui::ExportCsvDialog),
|
||||
pdb(db),
|
||||
m_format(format),
|
||||
m_sQuery(query)
|
||||
{
|
||||
// Create UI
|
||||
ui->setupUi(this);
|
||||
|
||||
// Retrieve the saved dialog preferences
|
||||
bool firstRow = PreferencesDialog::getSettingsValue("exportcsv", "firstrowheader").toBool();
|
||||
int separatorChar = PreferencesDialog::getSettingsValue("exportcsv", "separator").toInt();
|
||||
int quoteChar = PreferencesDialog::getSettingsValue("exportcsv", "quotecharacter").toInt();
|
||||
QString newLineString = PreferencesDialog::getSettingsValue("exportcsv", "newlinecharacters").toString();
|
||||
// Show different option widgets depending on the export format
|
||||
ui->stackFormat->setCurrentIndex(format);
|
||||
|
||||
// Set the widget values using the retrieved preferences
|
||||
ui->checkHeader->setChecked(firstRow);
|
||||
setSeparatorChar(separatorChar);
|
||||
setQuoteChar(quoteChar);
|
||||
setNewLineString(newLineString);
|
||||
// Retrieve the saved dialog preferences
|
||||
ui->checkHeader->setChecked(PreferencesDialog::getSettingsValue("exportcsv", "firstrowheader").toBool());
|
||||
setSeparatorChar(PreferencesDialog::getSettingsValue("exportcsv", "separator").toInt());
|
||||
setQuoteChar(PreferencesDialog::getSettingsValue("exportcsv", "quotecharacter").toInt());
|
||||
setNewLineString(PreferencesDialog::getSettingsValue("exportcsv", "newlinecharacters").toString());
|
||||
ui->checkPrettyPrint->setChecked(PreferencesDialog::getSettingsValue("exportjson", "prettyprint").toBool());
|
||||
|
||||
// Update the visible/hidden status of the "Other" line edit fields
|
||||
showCustomCharEdits();
|
||||
@@ -39,21 +43,17 @@ ExportCsvDialog::ExportCsvDialog(DBBrowserDB* db, QWidget* parent, const QString
|
||||
{
|
||||
// Get list of tables to export
|
||||
objectMap objects = pdb->getBrowsableObjects();
|
||||
for(objectMap::ConstIterator i=objects.begin();i!=objects.end();++i)
|
||||
{
|
||||
ui->listTables->addItem(new QListWidgetItem(QIcon(QString(":icons/%1").arg(i.value().gettype())), i.value().getname()));
|
||||
}
|
||||
foreach(const DBBrowserObject& obj, objects)
|
||||
ui->listTables->addItem(new QListWidgetItem(QIcon(QString(":icons/%1").arg(obj.gettype())), obj.getname()));
|
||||
|
||||
// Sort list of tables and select the table specified in the selection parameter or alternatively the first one
|
||||
ui->listTables->model()->sort(0);
|
||||
if(selection.isEmpty())
|
||||
{
|
||||
ui->listTables->setCurrentItem(ui->listTables->item(0));
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
QList<QListWidgetItem*> items = ui->listTables->findItems(selection, Qt::MatchExactly);
|
||||
if (!items.isEmpty())
|
||||
if(!items.isEmpty())
|
||||
ui->listTables->setCurrentItem(items.first());
|
||||
}
|
||||
} else {
|
||||
@@ -70,6 +70,19 @@ ExportCsvDialog::~ExportCsvDialog()
|
||||
}
|
||||
|
||||
bool ExportCsvDialog::exportQuery(const QString& sQuery, const QString& sFilename)
|
||||
{
|
||||
switch(m_format)
|
||||
{
|
||||
case ExportFormatCsv:
|
||||
return exportQueryCsv(sQuery, sFilename);
|
||||
case ExportFormatJson:
|
||||
return exportQueryJson(sQuery, sFilename);
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool ExportCsvDialog::exportQueryCsv(const QString& sQuery, const QString& sFilename)
|
||||
{
|
||||
// Prepare the quote and separating characters
|
||||
QChar quoteChar = currentQuoteChar();
|
||||
@@ -158,15 +171,97 @@ bool ExportCsvDialog::exportQuery(const QString& sQuery, const QString& sFilenam
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ExportCsvDialog::exportQueryJson(const QString& sQuery, const QString& sFilename)
|
||||
{
|
||||
#if QT_VERSION_MAJOR < 5
|
||||
return false;
|
||||
#else
|
||||
// Open file
|
||||
QFile file(sFilename);
|
||||
if(file.open(QIODevice::WriteOnly))
|
||||
{
|
||||
QByteArray utf8Query = sQuery.toUtf8();
|
||||
sqlite3_stmt *stmt;
|
||||
int status = sqlite3_prepare_v2(pdb->_db, utf8Query.data(), utf8Query.size(), &stmt, NULL);
|
||||
|
||||
QJsonArray json_table;
|
||||
|
||||
if(SQLITE_OK == status)
|
||||
{
|
||||
QApplication::setOverrideCursor(Qt::WaitCursor);
|
||||
int columns = sqlite3_column_count(stmt);
|
||||
size_t counter = 0;
|
||||
QList<QString> column_names;
|
||||
while(sqlite3_step(stmt) == SQLITE_ROW)
|
||||
{
|
||||
// Get column names if we didn't do so before
|
||||
if(!column_names.size())
|
||||
{
|
||||
for(int i=0;i<columns;++i)
|
||||
column_names.push_back(QString::fromUtf8(sqlite3_column_name(stmt, i)));
|
||||
}
|
||||
|
||||
QJsonObject json_row;
|
||||
for(int i=0;i<columns;++i)
|
||||
{
|
||||
QString content = QString::fromUtf8(
|
||||
(const char*)sqlite3_column_blob(stmt, i),
|
||||
sqlite3_column_bytes(stmt, i));
|
||||
json_row.insert(column_names[i], content);
|
||||
}
|
||||
json_table.push_back(json_row);
|
||||
|
||||
if(counter % 1000 == 0)
|
||||
qApp->processEvents();
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
|
||||
sqlite3_finalize(stmt);
|
||||
|
||||
// Create JSON document
|
||||
QJsonDocument json_doc;
|
||||
json_doc.setArray(json_table);
|
||||
file.write(json_doc.toJson(ui->checkPrettyPrint->isChecked() ? QJsonDocument::Indented : QJsonDocument::Compact));
|
||||
|
||||
QApplication::restoreOverrideCursor();
|
||||
qApp->processEvents();
|
||||
|
||||
// Done writing the file
|
||||
file.close();
|
||||
} else {
|
||||
QMessageBox::warning(this, QApplication::applicationName(),
|
||||
tr("Could not open output file: %1").arg(sFilename));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
void ExportCsvDialog::accept()
|
||||
{
|
||||
QString file_dialog_filter;
|
||||
QString default_file_extension;
|
||||
switch(m_format)
|
||||
{
|
||||
case ExportFormatCsv:
|
||||
file_dialog_filter = tr("Text files(*.csv *.txt)");
|
||||
default_file_extension = ".csv";
|
||||
break;
|
||||
case ExportFormatJson:
|
||||
file_dialog_filter = tr("Text files(*.json *.js *.txt)");
|
||||
default_file_extension = ".json";
|
||||
break;
|
||||
}
|
||||
|
||||
if(!m_sQuery.isEmpty())
|
||||
{
|
||||
// called from sqlexecute query tab
|
||||
QString sFilename = FileDialog::getSaveFileName(
|
||||
this,
|
||||
tr("Choose a filename to export data"),
|
||||
tr("Text files(*.csv *.txt)"));
|
||||
file_dialog_filter);
|
||||
if(sFilename.isEmpty())
|
||||
{
|
||||
close();
|
||||
@@ -174,9 +269,7 @@ void ExportCsvDialog::accept()
|
||||
}
|
||||
|
||||
exportQuery(m_sQuery, sFilename);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// called from the File export menu
|
||||
QList<QListWidgetItem*> selectedItems = ui->listTables->selectedItems();
|
||||
|
||||
@@ -194,8 +287,8 @@ void ExportCsvDialog::accept()
|
||||
QString fileName = FileDialog::getSaveFileName(
|
||||
this,
|
||||
tr("Choose a filename to export data"),
|
||||
tr("Text files(*.csv *.txt)"),
|
||||
selectedItems.at(0)->text() + ".csv");
|
||||
file_dialog_filter,
|
||||
selectedItems.at(0)->text() + default_file_extension);
|
||||
if(fileName.isEmpty())
|
||||
{
|
||||
close();
|
||||
@@ -203,25 +296,21 @@ void ExportCsvDialog::accept()
|
||||
}
|
||||
|
||||
filenames << fileName;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// ask for folder
|
||||
QString csvfolder = FileDialog::getExistingDirectory(
|
||||
QString exportfolder = FileDialog::getExistingDirectory(
|
||||
this,
|
||||
tr("Choose a directory"),
|
||||
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
|
||||
|
||||
if(csvfolder.isEmpty())
|
||||
if(exportfolder.isEmpty())
|
||||
{
|
||||
close();
|
||||
return;
|
||||
}
|
||||
|
||||
for(QList<QListWidgetItem*>::iterator it = selectedItems.begin(); it != selectedItems.end(); ++it)
|
||||
{
|
||||
filenames << QDir(csvfolder).filePath((*it)->text() + ".csv");
|
||||
}
|
||||
foreach(QListWidgetItem* item, selectedItems)
|
||||
filenames << QDir(exportfolder).filePath(item->text() + default_file_extension);
|
||||
}
|
||||
|
||||
// Only if the user hasn't clicked the cancel button
|
||||
@@ -236,10 +325,11 @@ void ExportCsvDialog::accept()
|
||||
}
|
||||
|
||||
// Save the dialog preferences for future use
|
||||
PreferencesDialog::setSettingsValue("exportcsv", "firstrowheader", ui->checkHeader->isChecked(), false);
|
||||
PreferencesDialog::setSettingsValue("exportcsv", "separator", currentSeparatorChar(), false);
|
||||
PreferencesDialog::setSettingsValue("exportcsv", "quotecharacter", currentQuoteChar(), false);
|
||||
PreferencesDialog::setSettingsValue("exportcsv", "newlinecharacters", currentNewLineString(), false);
|
||||
PreferencesDialog::setSettingsValue("exportcsv", "firstrowheader", ui->checkHeader->isChecked());
|
||||
PreferencesDialog::setSettingsValue("exportjson", "prettyprint", ui->checkPrettyPrint->isChecked());
|
||||
PreferencesDialog::setSettingsValue("exportcsv", "separator", currentSeparatorChar());
|
||||
PreferencesDialog::setSettingsValue("exportcsv", "quotecharacter", currentQuoteChar());
|
||||
PreferencesDialog::setSettingsValue("exportcsv", "newlinecharacters", currentNewLineString());
|
||||
|
||||
// Notify the user the export has completed
|
||||
QMessageBox::information(this, QApplication::applicationName(), tr("Export completed."));
|
||||
|
||||
@@ -14,7 +14,13 @@ class ExportCsvDialog : public QDialog
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ExportCsvDialog(DBBrowserDB* db, QWidget* parent = 0, const QString& query = "", const QString& selection = "");
|
||||
enum ExportFormats
|
||||
{
|
||||
ExportFormatCsv,
|
||||
ExportFormatJson,
|
||||
};
|
||||
|
||||
explicit ExportCsvDialog(DBBrowserDB* db, ExportFormats format, QWidget* parent = 0, const QString& query = "", const QString& selection = "");
|
||||
~ExportCsvDialog();
|
||||
|
||||
private slots:
|
||||
@@ -32,11 +38,15 @@ private:
|
||||
QString currentNewLineString() const;
|
||||
|
||||
bool exportQuery(const QString& sQuery, const QString& sFilename);
|
||||
bool exportQueryCsv(const QString& sQuery, const QString& sFilename);
|
||||
bool exportQueryJson(const QString& sQuery, const QString& sFilename);
|
||||
|
||||
private:
|
||||
Ui::ExportCsvDialog* ui;
|
||||
DBBrowserDB* pdb;
|
||||
|
||||
ExportFormats m_format;
|
||||
|
||||
QString m_sQuery;
|
||||
};
|
||||
|
||||
|
||||
@@ -6,20 +6,20 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>579</width>
|
||||
<height>403</height>
|
||||
<width>527</width>
|
||||
<height>381</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Export data as CSV</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="0" column="0">
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QFormLayout" name="formLayout_3">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="labelTable">
|
||||
<property name="text">
|
||||
<string>&Table(s)</string>
|
||||
<string>Tab&le(s)</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>listTables</cstring>
|
||||
@@ -42,236 +42,264 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="labelHeader">
|
||||
<property name="text">
|
||||
<string>&Column names in first line</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>checkHeader</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QCheckBox" name="checkHeader">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="labelFieldSeparator">
|
||||
<property name="text">
|
||||
<string>Field &separator</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>comboFieldSeparator</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QComboBox" name="comboFieldSeparator">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>180</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>180</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>,</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>;</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Tab</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>|</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Other</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="editCustomSeparator">
|
||||
<property name="maxLength">
|
||||
<number>1</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="labelQuoteCharacter">
|
||||
<property name="text">
|
||||
<string>&Quote character</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>comboQuoteCharacter</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QComboBox" name="comboQuoteCharacter">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>180</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>180</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>"</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>'</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Other</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="editCustomQuote">
|
||||
<property name="maxLength">
|
||||
<number>1</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="labelNewLineCharacters">
|
||||
<property name="text">
|
||||
<string>New line characters</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3" stretch="0,0,0">
|
||||
<item>
|
||||
<widget class="QComboBox" name="comboNewLineString">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>180</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>180</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Windows: CR+LF (\r\n)</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Unix: LF (\n)</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Other</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="editCustomNewLine">
|
||||
<property name="maxLength">
|
||||
<number>5</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_3">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<item>
|
||||
<widget class="QStackedWidget" name="stackFormat">
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="csv">
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="labelHeader">
|
||||
<property name="text">
|
||||
<string>Colu&mn names in first line</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>checkHeader</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QCheckBox" name="checkHeader">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="labelFieldSeparator">
|
||||
<property name="text">
|
||||
<string>Fie&ld separator</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>comboFieldSeparator</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QComboBox" name="comboFieldSeparator">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>180</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>180</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>,</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>;</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Tab</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>|</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Other</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="editCustomSeparator">
|
||||
<property name="maxLength">
|
||||
<number>1</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="labelQuoteCharacter">
|
||||
<property name="text">
|
||||
<string>&Quote character</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>comboQuoteCharacter</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QComboBox" name="comboQuoteCharacter">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>180</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>180</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>"</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>'</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Other</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="editCustomQuote">
|
||||
<property name="maxLength">
|
||||
<number>1</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="labelNewLineCharacters">
|
||||
<property name="text">
|
||||
<string>New line characters</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3" stretch="0,0,0">
|
||||
<item>
|
||||
<widget class="QComboBox" name="comboNewLineString">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>180</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>180</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Windows: CR+LF (\r\n)</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Unix: LF (\n)</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Other</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="editCustomNewLine">
|
||||
<property name="maxLength">
|
||||
<number>5</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_3">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="json">
|
||||
<layout class="QFormLayout" name="formLayout_2">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Pretty print</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>checkPrettyPrint</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QCheckBox" name="checkPrettyPrint"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
@@ -300,8 +328,8 @@
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>252</x>
|
||||
<y>136</y>
|
||||
<x>263</x>
|
||||
<y>612</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
@@ -316,8 +344,8 @@
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>320</x>
|
||||
<y>136</y>
|
||||
<x>263</x>
|
||||
<y>612</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
@@ -332,8 +360,8 @@
|
||||
<slot>showCustomCharEdits()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>210</x>
|
||||
<y>64</y>
|
||||
<x>390</x>
|
||||
<y>293</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>264</x>
|
||||
@@ -348,8 +376,8 @@
|
||||
<slot>showCustomCharEdits()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>197</x>
|
||||
<y>93</y>
|
||||
<x>390</x>
|
||||
<y>332</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>270</x>
|
||||
@@ -364,8 +392,8 @@
|
||||
<slot>showCustomCharEdits()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>231</x>
|
||||
<y>327</y>
|
||||
<x>390</x>
|
||||
<y>371</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>296</x>
|
||||
|
||||
@@ -1053,7 +1053,24 @@ void MainWindow::exportTableToCSV()
|
||||
current_table = ui->comboBrowseTable->currentText();
|
||||
|
||||
// Open dialog
|
||||
ExportCsvDialog dialog(&db, this, "", current_table);
|
||||
ExportCsvDialog dialog(&db, ExportCsvDialog::ExportFormatCsv, this, "", current_table);
|
||||
dialog.exec();
|
||||
}
|
||||
|
||||
void MainWindow::exportTableToJson()
|
||||
{
|
||||
// Get the current table name if we are in the Browse Data tab
|
||||
QString current_table;
|
||||
if(ui->mainTab->currentIndex() == StructureTab) {
|
||||
QString type = ui->dbTreeWidget->model()->data(ui->dbTreeWidget->currentIndex().sibling(ui->dbTreeWidget->currentIndex().row(), 1)).toString();
|
||||
if(type == "table" || type == "view")
|
||||
current_table = ui->dbTreeWidget->model()->data(ui->dbTreeWidget->currentIndex().sibling(ui->dbTreeWidget->currentIndex().row(), 0)).toString();
|
||||
}
|
||||
else if(ui->mainTab->currentIndex() == BrowseTab)
|
||||
current_table = ui->comboBrowseTable->currentText();
|
||||
|
||||
// Open dialog
|
||||
ExportCsvDialog dialog(&db, ExportCsvDialog::ExportFormatJson, this, "", current_table);
|
||||
dialog.exec();
|
||||
}
|
||||
|
||||
|
||||
@@ -195,6 +195,7 @@ private slots:
|
||||
void executeQuery();
|
||||
void importTableFromCSV();
|
||||
void exportTableToCSV();
|
||||
void exportTableToJson();
|
||||
void fileSave();
|
||||
void fileRevert();
|
||||
void exportDatabaseToSQL();
|
||||
|
||||
@@ -337,8 +337,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>552</width>
|
||||
<height>423</height>
|
||||
<width>473</width>
|
||||
<height>558</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
@@ -823,7 +823,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>1037</width>
|
||||
<height>21</height>
|
||||
<height>29</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QMenu" name="fileMenu">
|
||||
@@ -843,6 +843,7 @@
|
||||
</property>
|
||||
<addaction name="fileExportSQLAction"/>
|
||||
<addaction name="fileExportCSVAction"/>
|
||||
<addaction name="fileExportJsonAction"/>
|
||||
</widget>
|
||||
<addaction name="fileNewAction"/>
|
||||
<addaction name="fileOpenAction"/>
|
||||
@@ -919,7 +920,7 @@
|
||||
</widget>
|
||||
<widget class="QDockWidget" name="dockEdit">
|
||||
<property name="windowTitle">
|
||||
<string>Edit Database Cell</string>
|
||||
<string>Edit Database &Cell</string>
|
||||
</property>
|
||||
<attribute name="dockWidgetArea">
|
||||
<number>2</number>
|
||||
@@ -1306,7 +1307,7 @@
|
||||
</widget>
|
||||
<widget class="QDockWidget" name="dockSchema">
|
||||
<property name="windowTitle">
|
||||
<string>DB Schema</string>
|
||||
<string>DB Sche&ma</string>
|
||||
</property>
|
||||
<attribute name="dockWidgetArea">
|
||||
<number>2</number>
|
||||
@@ -1643,7 +1644,7 @@
|
||||
<normaloff>:/icons/whatis</normaloff>:/icons/whatis</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>W&hat's This?</string>
|
||||
<string>W&hat's This?</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Shift+F1</string>
|
||||
@@ -1940,12 +1941,23 @@
|
||||
<normaloff>:/icons/browser_open</normaloff>:/icons/browser_open</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>SQLCipher FAQ...</string>
|
||||
<string>SQLCipher &FAQ...</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Opens the SQLCipher FAQ in a browser window</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="fileExportJsonAction">
|
||||
<property name="text">
|
||||
<string>Table(s) to JSON...</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Export one or more table(s) to a JSON file</string>
|
||||
</property>
|
||||
<property name="menuRole">
|
||||
<enum>QAction::NoRole</enum>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
@@ -2976,6 +2988,22 @@
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>fileExportJsonAction</sender>
|
||||
<signal>triggered()</signal>
|
||||
<receiver>MainWindow</receiver>
|
||||
<slot>exportTableToJson()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>-1</x>
|
||||
<y>-1</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>518</x>
|
||||
<y>314</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
<slots>
|
||||
<slot>fileOpen()</slot>
|
||||
@@ -3038,5 +3066,6 @@
|
||||
<slot>browseDataSetDefaultTableEncoding()</slot>
|
||||
<slot>browseDataFetchAllData()</slot>
|
||||
<slot>dittoRecord()</slot>
|
||||
<slot>exportTableToJson()</slot>
|
||||
</slots>
|
||||
</ui>
|
||||
|
||||
@@ -254,6 +254,10 @@ QVariant PreferencesDialog::getSettingsDefaultValue(const QString& group, const
|
||||
if(group == "exportcsv" && name == "quotecharacter")
|
||||
return '"';
|
||||
|
||||
// exportjson/prettyprint?
|
||||
if(group == "exportjson" && name == "prettyprint")
|
||||
return true;
|
||||
|
||||
// MainWindow/geometry?
|
||||
if(group == "MainWindow" && name == "geometry")
|
||||
return "";
|
||||
|
||||
@@ -84,7 +84,7 @@ void SqlExecutionArea::enableSaveButton(bool enable)
|
||||
|
||||
void SqlExecutionArea::saveAsCsv()
|
||||
{
|
||||
ExportCsvDialog dialog(db, this, model->query());
|
||||
ExportCsvDialog dialog(db, ExportCsvDialog::ExportFormatCsv, this, model->query());
|
||||
dialog.exec();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user