Go to the documentation of this file.00001 #include "exporttable.h"
00002 #include "ui_exporttable.h"
00003
00004 ExportTable::ExportTable(QWidget *parent) :
00005 QDialog(parent),
00006 ui(new Ui::ExportTable)
00007 {
00008 ui->setupUi(this);
00009 connect (ui->cmdExport, SIGNAL(clicked()), this, SLOT(startExport()));
00010 connect (ui->cmdSetFileName, SIGNAL(clicked()), this, SLOT(selectFile()));
00011 }
00012
00013 ExportTable::~ExportTable()
00014 {
00015 delete ui;
00016 }
00017
00018 void ExportTable::selectFile() {
00019 QString fileName;
00020
00021 if (ui->optCSV->isChecked()) {
00022 fileName = QFileDialog::getSaveFileName(this, "Enter the CSV file to dump to.", QString(),"CSV Files (*.csv)");
00023 } else if (ui->optHTML->isChecked()) {
00024 fileName = QFileDialog::getSaveFileName(this, "Enter the HTML file to dump to.", QString(),"Web Files (*.htm)");
00025 } else if (ui->optXML->isChecked()) {
00026 fileName = QFileDialog::getSaveFileName(this, "Enter the XML file to dump to.", QString(),"XML Files (*.xml)");
00027 } else if (ui->optExcel->isChecked()) {
00028 fileName = QFileDialog::getSaveFileName(this, "Enter the Excel file to dump to.", QString(),"Excel XML Files (*.xml)");
00029 }
00030
00031 if (fileName != "") {
00032 ui->txtFileName->setText(fileName);
00033 }
00034 }
00035
00036 void ExportTable::showColumns() {
00037 if (db.open()) { }
00038 if (db.isOpen()) {
00039 QSqlQuery qu = QSqlQuery(db);
00040 qu.exec(tr("use `%1`").arg(dbName));
00041 qu.clear();
00042 if (qu.exec(query)) {
00043 qu.first();
00044 QSqlRecord rec = qu.record();
00045 for (int i = 0; i < rec.count(); i++) {
00046 QString colName = rec.fieldName(i);
00047 ui->lstColumns->insertItem(ui->lstColumns->count(), colName);
00048 ui->lstColumns->item(ui->lstColumns->count() - 1)->setCheckState(Qt::Checked);
00049 }
00050 }
00051 qu.clear();
00052 }
00053 }
00054
00055 void ExportTable::startExport() {
00056 if (ui->txtFileName->text() != "") {
00057 expThread = new ExportTableThread(this);
00058 connect(expThread, SIGNAL(completed(bool)), this, SLOT(exportFinished(bool)));
00059 expThread->strQuery = query;
00060 QStringList columnList;
00061 for (int i = 0; i < ui->lstColumns->count(); i++) {
00062 if (ui->lstColumns->item(i)->checkState()== Qt::Checked) {
00063 columnList << ui->lstColumns->item(i)->text();
00064 }
00065 }
00066 expThread->columnList = columnList;
00067 expThread->run(db, dbName, tableName, ui->txtFileName->text(), ",", "\"", "\n", true,
00068 ui->optCSV->isChecked(),
00069 ui->optHTML->isChecked(), ui->optXML->isChecked(), ui->optExcel->isChecked());
00070 } else {
00071 QMessageBox::warning(this, "Error", "Export failed!\n\nPlease enter the file name.");
00072 }
00073 }
00074
00075 void ExportTable::exportFinished(bool succ) {
00076 if (succ) {
00077 QMessageBox::information(this, "Success", "Export succeeded");
00078 }else {
00079 QMessageBox::warning(this, "Error", "Export failed!");
00080 }
00081 }
00082
00083 void ExportTable::updateDisplay() {
00084
00085 }