#include "ExportSqlDialog.h"#include "ui_ExportSqlDialog.h"#include "sqlitedb.h"#include "FileDialog.h"#include "Settings.h"#include <QFile>#include <QMessageBox>enum WhatComboEntries{ExportEverything,ExportSchemaOnly,ExportDataOnly,};ExportSqlDialog::ExportSqlDialog(DBBrowserDB* db, QWidget* parent, const QString& selection): QDialog(parent),ui(new Ui::ExportSqlDialog),pdb(db){// Create UIui->setupUi(this);// Load settingsui->checkColNames->setChecked(Settings::getValue("exportsql", "insertcolnames").toBool());ui->checkMultiple->setChecked(Settings::getValue("exportsql", "insertmultiple").toBool());ui->comboOldSchema->setCurrentIndex(Settings::getValue("exportsql", "oldschema").toInt());// Get list of tables to exportconst auto objects = pdb->schemata["main"].equal_range("table");for(auto it=objects.first;it!=objects.second;++it)ui->listTables->addItem(new QListWidgetItem(QIcon(QString(":icons/%1").arg(QString::fromStdString(sqlb::Object::typeToString(it->second->type())))), QString::fromStdString(it->second->name())));// Sort list of tables and select the table specified in the// selection parameter or all tables if table not specifiedui->listTables->model()->sort(0);if(selection.isEmpty()){for (int i = 0; i < ui->listTables->count(); ++i)ui->listTables->item(i)->setSelected(true);}else{QList<QListWidgetItem*> items = ui->listTables->findItems(selection, Qt::MatchExactly);ui->listTables->setCurrentItem(items.at(0));}ui->listTables->setFocus();}ExportSqlDialog::~ExportSqlDialog(){delete ui;}void ExportSqlDialog::doSelectAll(){for (int i = 0; i < ui->listTables->count(); ++i)ui->listTables->item(i)->setSelected(true);}void ExportSqlDialog::doDeselectAll(){for (int i = 0; i < ui->listTables->count(); ++i)ui->listTables->item(i)->setSelected(false);}void ExportSqlDialog::accept(){QList<QListWidgetItem*> selectedItems = ui->listTables->selectedItems();if(selectedItems.isEmpty()){QMessageBox::warning(this, QApplication::applicationName(),tr("Please select at least one table."));return;}// Try to find a default file nameQString defaultFileName;if(selectedItems.count() == 1) // One table -> Suggest table namedefaultFileName = selectedItems.at(0)->text() + FILE_EXT_SQL_DEFAULT;else if(selectedItems.count() == ui->listTables->count()) // All tables -> Suggest database namedefaultFileName = pdb->currentFile() + FILE_EXT_SQL_DEFAULT;;QString fileName = FileDialog::getSaveFileName(CreateSQLFile,this,tr("Choose a filename to export"),FILE_FILTER_SQL,defaultFileName);if(fileName.isEmpty())return;// Save settingsSettings::setValue("exportsql", "insertcolnames", ui->checkColNames->isChecked());Settings::setValue("exportsql", "insertmultiple", ui->checkMultiple->isChecked());Settings::setValue("exportsql", "oldschema", ui->comboOldSchema->currentIndex());QStringList tables;for(const QListWidgetItem* item : ui->listTables->selectedItems())tables.push_back(item->text());// Check what to export. The indices here depend on the order of the items in the combobox in the ui filebool exportSchema = ui->comboWhat->currentIndex() == ExportEverything || ui->comboWhat->currentIndex() == ExportSchemaOnly;bool exportData = ui->comboWhat->currentIndex() == ExportEverything || ui->comboWhat->currentIndex() == ExportDataOnly;bool keepSchema = ui->comboOldSchema->currentIndex() == 0;// Perform actual exportbool dumpOk = pdb->dump(fileName,tables,ui->checkColNames->isChecked(),ui->checkMultiple->isChecked(),exportSchema,exportData,keepSchema);if (dumpOk)QMessageBox::information(this, QApplication::applicationName(), tr("Export completed."));elseQMessageBox::warning(this, QApplication::applicationName(), tr("Export cancelled or failed."));QDialog::accept();}void ExportSqlDialog::whatChanged(int index){// Only show the combobox for deciding what to do with the old schema when importing into an existing database when we're// actually exporting the schema hereif(index != ExportDataOnly)ui->comboOldSchema->setVisible(true);elseui->comboOldSchema->setVisible(false);}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。